/* ==========================================================================
   Aviator UI — stage visuals, state machine & animations
   The original draws the stage on <canvas>; everything here is CSS/SVG.
   ========================================================================== */

@property --ray-angle {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}

:root {
  --ray-step: 7.5deg;
  --ray-dark: #000;
  --ray-light: #161616;
  --glow-low: rgba(22, 96, 160, .85);
  --glow-mid: rgba(86, 44, 176, .85);
  --glow-high: rgba(170, 20, 150, .85);
  --crash-red: #d0021b;
}

/* ==========================================================================
   LoadingScreen + red ellipsis spinner (keyframes match the original)
   ========================================================================== */
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: #000;
  transition: opacity .4s ease, visibility .4s;
}

.loading-screen.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-screen__brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.loading-screen__powered {
  color: #7b7b7b;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: .4px;
  text-transform: uppercase;
}

.loading-screen__logo {
  color: #fff;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -.5px;
  line-height: 1;
}

.dot-spinner {
  position: relative;
  display: flex;
  align-items: center;
  width: 36px;
  height: 36px;
}

.dot-spinner div {
  position: absolute;
  top: 50%;
  left: 0;
  width: 14px;
  height: 14px;
  margin-top: -7px;
  background: #f01d14;
  border-radius: 50%;
}

.dot-spinner div:nth-child(1) { opacity: 0;  animation: spinner-ellipsis1 .9s ease-in-out infinite; }
.dot-spinner div:nth-child(2) { opacity: 0;  animation: spinner-ellipsis2 .9s ease-in-out infinite; }
.dot-spinner div:nth-child(3) { opacity: .5; animation: spinner-ellipsis3 .9s ease-in-out infinite; }

@keyframes spinner-ellipsis1 {
  0%, 33% { transform: translateX(-4px) scale(.33); opacity: .5; }
  100%    { transform: translateX(11px) scale(1);   opacity: 1; }
}

@keyframes spinner-ellipsis2 {
  0%, 33% { transform: translateX(11px) scale(1);   opacity: 1; }
  100%    { transform: translateX(26px) scale(.33); opacity: .5; }
}

@keyframes spinner-ellipsis3 {
  0%, 33% { transform: translateX(26px) scale(.33); }
  100%    { transform: translateX(-4px) scale(.33); }
}

/* ==========================================================================
   Stage background: sunburst rays from the bottom-left corner
   ========================================================================== */
.stage__rays {
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(circle at 0 100%, rgba(0, 0, 0, .95) 0, rgba(0, 0, 0, .55) 18%, transparent 45%),
    repeating-conic-gradient(
      from var(--ray-angle) at 0% 100%,
      var(--ray-dark) 0deg calc(var(--ray-step) / 2),
      var(--ray-light) calc(var(--ray-step) / 2) var(--ray-step)
    );
  animation: rays-rotate 4s linear infinite;
}

/* Rotating by exactly one ray period makes the loop seamless (keep = --ray-step). */
@keyframes rays-rotate {
  to { --ray-angle: 7.5deg; }
}

/* ==========================================================================
   Glow behind the multiplier (colour follows the multiplier tier)
   ========================================================================== */
.stage__glow {
  --glow: var(--glow-low);
  position: absolute;
  inset: 0;
  z-index: 1;
  background: radial-gradient(ellipse 38% 45% at 55% 48%, var(--glow) 0%, transparent 100%);
  transition: opacity .3s ease, background .6s ease;
  animation: glow-breathe 3s ease-in-out infinite alternate;
}

.stage[data-tier="mid"]  .stage__glow { --glow: var(--glow-mid); }
.stage[data-tier="high"] .stage__glow { --glow: var(--glow-high); }

@keyframes glow-breathe {
  from { opacity: .85; transform: scale(1); }
  to   { opacity: 1;   transform: scale(1.06); }
}

/* ==========================================================================
   Flight curve (SVG, stretched to the stage)
   ========================================================================== */
.stage__curve {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  overflow: visible;
  transition: opacity .2s ease;
}

.stage__curve-line { filter: drop-shadow(0 0 6px rgba(229, 5, 57, .45)); }

/* ==========================================================================
   Plane (Spribe sprite frames)
   --plane-x / --plane-y (0–100) put the tail on the curve tip.
   ========================================================================== */
.plane {
  position: absolute;
  z-index: 3;
  left: calc(var(--plane-x, 0) * 1%);
  top: calc(var(--plane-y, 100) * 1%);
  width: clamp(88px, 11.5cqw, 180px);
  transform: translate(-6%, -62%);
  pointer-events: none;
}

.stage[data-state="flying"] .plane { transition: left .05s linear, top .05s linear; }

.plane__sprite {
  position: relative;
  width: 100%;
  aspect-ratio: 150 / 74;
  filter: drop-shadow(0 3px 8px rgba(229, 5, 57, .45));
  transform-origin: 12% 58%;
  animation: plane-bob 1.5s ease-in-out infinite alternate;
}

.plane__frame {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  animation: plane-frame .28s steps(1, end) infinite;
}

.plane__frame--0 { animation-delay: 0s; }
.plane__frame--1 { animation-delay: .07s; }
.plane__frame--2 { animation-delay: .14s; }
.plane__frame--3 { animation-delay: .21s; }

@keyframes plane-frame {
  0%,
  24.999% { opacity: 1; }
  25%,
  100% { opacity: 0; }
}

@keyframes plane-bob {
  from { transform: translateY(0) rotate(-1.5deg); }
  to   { transform: translateY(-3%) rotate(1deg); }
}

@media (prefers-reduced-motion: reduce) {
  .plane__sprite { animation: none; }
  .plane__frame { animation: none; opacity: 0; }
  .plane__frame--0 { opacity: 1; }
}

/* ==========================================================================
   Waiting indicator
   ========================================================================== */
.waiting {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.waiting__spinner svg { display: block; }

.waiting__blades {
  transform-origin: 32px 32px;
  animation: blades-spin 1s linear infinite;
}

.waiting__label {
  color: #fff;
  font-size: clamp(13px, 1.6cqw, 22px);
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
}

.waiting__progress {
  width: clamp(120px, 15cqw, 230px);
  height: 5px;
  overflow: hidden;
  background: #2a2b2e;
  border-radius: 3px;
}

.waiting__progress-bar {
  width: 100%;
  height: 100%;
  background: var(--c-brand, #e50539);
  border-radius: inherit;
  transform-origin: left center;
}

@keyframes blades-spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Stage state machine
   ========================================================================== */

/* --- crashed ("FLEW AWAY!") --- */
.stage[data-state="crashed"] .stage__rays { animation-play-state: paused; }
.stage[data-state="crashed"] .stage__glow,
.stage[data-state="crashed"] .stage__curve { opacity: 0; animation: none; }

.stage[data-state="crashed"] .plane {
  animation: fly-away .7s cubic-bezier(.5, 0, .9, .4) forwards;
}

.stage[data-state="crashed"] .multiplier__flew { display: block; animation: fade-up .25s ease-out both; }
.stage[data-state="crashed"] .multiplier__value { color: var(--crash-red); }

@keyframes fly-away {
  to { transform: translate(120vw, -70vh); }
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* --- waiting (between rounds) --- */
.stage[data-state="waiting"] .stage__glow,
.stage[data-state="waiting"] .stage__curve,
.stage[data-state="waiting"] .multiplier { display: none; }

.stage[data-state="waiting"] .waiting { display: flex; }

.stage[data-state="waiting"] .plane {
  left: 0;
  top: 100%;
  transform: translate(0, -100%);
  transition: none;
}

/* ==========================================================================
   Toasts
   ========================================================================== */
.toasts {
  position: absolute;
  top: 34px;
  left: 50%;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: max-content;
  max-width: calc(100% - 16px);
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 52px;
  padding: 4px 6px 4px 18px;
  border: 1px solid #5fd12c;
  border-radius: 26px;
  background: linear-gradient(180deg, #1f6b0a 0%, #134805 100%);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .45);
  color: #fff;
  pointer-events: auto;
  animation: toast-in .25s cubic-bezier(.2, .8, .3, 1.2) both;
}

.toast--error {
  min-height: 40px;
  border-color: var(--c-red-border, #ff7171);
  background: linear-gradient(180deg, #7a0716 0%, #4d040d 100%);
}

.toast.is-leaving { animation: toast-out .2s ease-in forwards; }

.toast__info {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.2;
}

.toast__title { color: #e3f8d8; font-size: 13px; }
.toast--error .toast__title { color: #ffe1e4; font-weight: 500; }
.toast__mult { font-size: 20px; font-weight: 700; }

.toast__win {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 96px;
  padding: 5px 16px;
  border-radius: 22px;
  background: var(--c-green, #28a909);
  line-height: 1.15;
}

.toast__win-label { font-size: 11px; opacity: .85; }
.toast__win-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }

.toast__close {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: rgba(255, 255, 255, .7);
  font-size: 16px;
  line-height: 24px;
}

.toast__close:hover { background: rgba(255, 255, 255, .12); color: #fff; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-12px) scale(.9); }
  to   { opacity: 1; transform: none; }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(-8px) scale(.95); }
}

/* ==========================================================================
   Micro-interactions
   ========================================================================== */
.bet-btn.is-shaking { animation: shake .4s ease-in-out; }

@keyframes shake {
  20%, 60% { transform: translateX(-4px); }
  40%, 80% { transform: translateX(4px); }
}

.history__item.is-new { animation: history-in .35s cubic-bezier(.2, .8, .3, 1.2) both; }

@keyframes history-in {
  from { opacity: 0; transform: translateX(-12px) scale(.8); }
  to   { opacity: 1; transform: none; }
}

.bet-row.is-cashout { animation: row-win .5s ease-out; }

@keyframes row-win {
  from { box-shadow: inset 0 0 0 1px rgba(66, 127, 0, .9); }
  to   { box-shadow: inset 0 0 0 1px rgba(66, 127, 0, 0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
