*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --text: #ffffff;
  --sky-deep: #087fe7;
  --sky-mid: #08aeee;
  --sky-light: #6edaf4;
  --lime: #d4ff62;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  min-height: -webkit-fill-available;
  overflow: hidden;
  background: linear-gradient(180deg, #087ee8 0%, var(--sky-mid) 50%, var(--sky-light) 100%);
  color: var(--text);
  font-family: var(--font);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#sky-decor {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0, 80, 192, 0.1), transparent 28%);
}

.cloud {
  position: absolute;
  width: clamp(210px, 36vw, 430px);
  aspect-ratio: 2.4 / 1;
  opacity: 0.9;
  filter: drop-shadow(0 14px 12px rgba(0, 100, 188, 0.22));
  background: var(--cloud-image, url('assets/cloud-3d.png?v=reference-sky-05')) center / contain no-repeat;
  animation: cloudDrift 24s ease-in-out infinite alternate;
}

.cloud::after {
  content: none;
}

.cloud-a { top: 8%; left: -13%; transform: scale(1.1); }
.cloud-b { top: 22%; right: -15%; transform: scale(0.98); animation-delay: -5s; opacity: 0.88; }
.cloud-c { top: 45%; left: 4%; transform: scale(0.58); animation-delay: -10s; opacity: 0.78; }
.cloud-d { top: 61%; right: -16%; transform: scale(0.9); animation-delay: -14s; opacity: 0.84; }
.cloud-e { top: 75%; left: -16%; transform: scale(0.94); animation-delay: -8s; opacity: 0.82; }

@keyframes cloudDrift {
  from { margin-left: -10px; }
  to { margin-left: 18px; }
}

.flight-streaks {
  position: absolute;
  left: 3%;
  top: 43%;
  width: 24%;
  height: 80px;
  opacity: 0.58;
  transform: rotate(-3deg);
}

.flight-streaks i {
  position: absolute;
  right: 0;
  display: block;
  height: 3px;
  border-radius: 99px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.88));
  animation: streakPulse 1.8s ease-in-out infinite alternate;
}

.flight-streaks i:nth-child(1) { top: 15%; width: 92%; }
.flight-streaks i:nth-child(2) { top: 49%; width: 68%; animation-delay: -0.5s; }
.flight-streaks i:nth-child(3) { top: 76%; width: 76%; animation-delay: -1s; }

@keyframes streakPulse {
  from { transform: translateX(-8px); opacity: 0.35; }
  to { transform: translateX(8px); opacity: 0.9; }
}

.sparkle {
  position: absolute;
  width: 26px;
  height: 26px;
  opacity: 0.9;
  filter: drop-shadow(0 0 7px rgba(255, 255, 255, 0.95));
  animation: sparkleTwinkle 2.8s ease-in-out infinite;
}

.sparkle::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, #fff 0 12%, #f9ffff 28%, rgba(255,255,255,0.94) 54%, transparent 56%);
  clip-path: polygon(50% 0%, 58% 39%, 100% 50%, 58% 61%, 50% 100%, 42% 61%, 0% 50%, 42% 39%);
}

.sparkle::after {
  content: '';
  position: absolute;
  inset: 37%;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 13px 5px rgba(255,255,255,0.7);
}

.sparkle-a { top: 8%; left: 24%; transform: scale(0.9); }
.sparkle-b { top: 19%; right: 16%; transform: scale(0.62); animation-delay: -0.8s; }
.sparkle-c { top: 39%; left: 54%; transform: scale(1.05); animation-delay: -1.7s; }
.sparkle-d { top: 56%; right: 25%; transform: scale(0.64); animation-delay: -2.2s; }
.sparkle-e { top: 25%; left: 5%; transform: scale(0.58); animation-delay: -1.1s; }
.sparkle-f { top: 69%; right: 8%; transform: scale(0.82); animation-delay: -2.5s; }
.sparkle-g { top: 78%; left: 18%; transform: scale(0.52); animation-delay: -0.4s; }
.sparkle-h { top: 85%; right: 38%; transform: scale(0.7); animation-delay: -1.9s; }

@keyframes sparkleTwinkle {
  0%, 100% { opacity: 0.42; filter: drop-shadow(0 0 4px rgba(255,255,255,0.6)); }
  45% { opacity: 1; filter: drop-shadow(0 0 10px rgba(255,255,255,1)); }
}

/* Full-viewport canvas: do not nest under a %height wrapper (rect often stays 0). */
#game-canvas {
  position: fixed;
  left: 0;
  top: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-height: -webkit-fill-available;
  display: block;
  z-index: 1;
  touch-action: none;
}

#wrap {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.score-kicker {
  font-size: 0.58rem;
  font-weight: 900;
  letter-spacing: 0.2em;
  line-height: 1;
  opacity: 0.88;
}

#status-label {
  position: absolute;
  left: 50%;
  top: calc(47% + env(safe-area-inset-top, 0px));
  transform: translate(-50%, -50%);
  color: rgba(255, 255, 255, 0.92);
  font-size: clamp(0.65rem, 2.2vw, 0.85rem);
  font-weight: 900;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  text-shadow: 0 2px 10px rgba(0, 61, 120, 0.38);
  opacity: 0;
  transition: opacity 180ms ease, transform 180ms ease;
}

body:not(.is-playing) #status-label { opacity: 0.86; }
body.is-playing #status-label,
body.is-over #status-label { opacity: 0; transform: translate(-50%, -50%) translateY(-8px); }

/* Keep the score centered while the brand anchors the composition on the left. */
#hud {
  position: absolute;
  top: calc(24px + env(safe-area-inset-top, 0px));
  left: calc(20px + env(safe-area-inset-left, 0px));
  right: calc(20px + env(safe-area-inset-right, 0px));
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-rows: auto;
  align-items: center;
  z-index: 10;
  pointer-events: none;
}

#hud-center {
  grid-column: 2;
  grid-row: 1;
  justify-self: center;
  align-self: center;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#score-wrap {
  min-width: 5ch;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  font-size: clamp(2.2rem, 8vw, 4rem);
  line-height: 0.8;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--text);
  text-shadow: 0 3px 0 rgba(0, 47, 107, 0.25), 0 5px 16px rgba(0, 57, 109, 0.42);
}

.score-kicker {
  font-size: clamp(0.52rem, 1.7vw, 0.68rem);
  letter-spacing: 0.3em;
}

#score-wrap.pulse {
  animation: scoreBounce 0.28s cubic-bezier(0.34, 1.45, 0.64, 1);
}

@keyframes scoreBounce {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.14);
  }
  100% {
    transform: scale(1);
  }
}

#current-score {
  display: inline-block;
}

#perfect-combo {
  position: absolute;
  top: calc(100% + 12px);
  left: 50%;
  transform: translate(-50%, -5px) scale(0.94);
  width: max-content;
  color: #fff3a6;
  font-size: clamp(0.66rem, 2vw, 0.82rem);
  font-weight: 950;
  letter-spacing: 0.14em;
  text-shadow: 0 2px 9px rgba(101, 56, 0, 0.55);
  opacity: 0;
  transition: opacity 160ms ease, transform 220ms cubic-bezier(0.2, 0.9, 0.3, 1.25);
}

#perfect-combo.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

#flight-feedback {
  position: absolute;
  left: 50%;
  top: calc(31% + env(safe-area-inset-top, 0px));
  transform: translate(-50%, 12px) scale(0.82);
  color: #fff3a6;
  font-size: clamp(1rem, 4.8vw, 1.65rem);
  font-weight: 950;
  font-style: italic;
  letter-spacing: 0.12em;
  text-shadow: 0 3px 0 rgba(119, 63, 0, 0.28), 0 7px 18px rgba(56, 40, 0, 0.34);
  opacity: 0;
  will-change: transform, opacity;
}

#flight-feedback.show {
  animation: flightFeedbackPop 720ms cubic-bezier(0.2, 0.85, 0.25, 1) both;
}

#flight-feedback.speed-up {
  color: #ffffff;
  font-size: clamp(0.78rem, 3.3vw, 1.05rem);
  letter-spacing: 0.18em;
}

@keyframes flightFeedbackPop {
  0% { opacity: 0; transform: translate(-50%, 12px) scale(0.82); }
  22% { opacity: 1; transform: translate(-50%, 0) scale(1.08); }
  68% { opacity: 1; transform: translate(-50%, -3px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -13px) scale(0.96); }
}

.hint {
  position: absolute;
  left: 50%;
  bottom: calc(17% + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  margin: 0;
  max-width: min(92vw, 420px);
  padding: 8px 14px;
  text-align: center;
  font-size: clamp(0.86rem, 3.4vw, 1.05rem);
  font-weight: 700;
  line-height: 1.35;
  opacity: 0.96;
  text-shadow: 0 2px 7px rgba(0, 59, 111, 0.72);
}

.hint span { color: var(--lime); padding: 0 4px; }

.hint.hidden {
  display: none;
}

body.is-over .hint { display: block; font-size: 0; }
body.is-over .hint::before { content: 'Tap to retry'; color: #fff; font-size: clamp(0.86rem, 3.4vw, 1.05rem); }
body.is-over .hint::after { content: none; }
body.is-over .hint span { display: none; }

@media (max-width: 520px) {
  #hud { top: calc(18px + env(safe-area-inset-top, 0px)); right: calc(14px + env(safe-area-inset-right, 0px)); }
  .hint { bottom: calc(17% + env(safe-area-inset-bottom, 0px)); padding: 8px 12px; font-size: 0.88rem; }
  .flight-streaks { top: 42%; width: 34%; left: -2%; }
  .cloud-a { top: 14%; }
  .cloud-b { top: 30%; }
}

/* Keep WebKit's compositor budget modest on compact, lower-memory iPhones. */
@media (max-width: 390px) {
  .cloud {
    filter: drop-shadow(0 8px 7px rgba(0, 100, 188, 0.18));
  }
}
