*,
*::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('../flying-bee/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: 0;
  padding: 10px 15px 11px;
  border: 1px solid rgba(255, 255, 255, 0.48);
  border-radius: 18px;
  background: rgba(0, 62, 136, 0.24);
  box-shadow: 0 5px 16px rgba(0, 57, 109, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: row;
  align-items: baseline;
  gap: 8px;
  font-size: clamp(2.2rem, 8vw, 4rem);
  line-height: 0.9;
  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.78rem, 2.4vw, 0.98rem);
  letter-spacing: 0.16em;
  line-height: 1;
  opacity: 0.96;
}

#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-level {
  display: inline-block;
}

.campaign-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 55, 120, 0.24);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.campaign-overlay[hidden] {
  display: none;
}

.update-wall {
  z-index: 80;
}

.update-wall-eyebrow {
  margin: 0;
  color: rgba(6, 74, 132, 0.62);
  font-size: 0.76rem;
  font-weight: 950;
  letter-spacing: 0.14em;
}

.update-wall-title {
  margin: 12px 0 10px;
  color: #064a84;
  font-size: clamp(1.4rem, 6vw, 1.85rem);
  font-weight: 950;
  letter-spacing: 0.01em;
}

.update-wall-copy {
  margin: 0 0 22px;
  color: rgba(6, 74, 132, 0.72);
  font-size: 0.82rem;
  font-weight: 750;
  line-height: 1.45;
}

.update-app-link {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.campaign-overlay.victory-ready .campaign-card {
  animation: victoryCardPop 620ms cubic-bezier(0.2, 0.9, 0.25, 1.2) both;
}

.campaign-overlay.victory-ready .campaign-stars {
  animation: victoryStarsPop 720ms 80ms cubic-bezier(0.2, 0.9, 0.25, 1.25) both;
}

@keyframes victoryCardPop {
  0% { opacity: 0; transform: translateY(18px) scale(0.88); }
  68% { opacity: 1; transform: translateY(-3px) scale(1.035); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes victoryStarsPop {
  0% { opacity: 0; transform: scale(0.45) rotate(-8deg); }
  48% { opacity: 1; transform: scale(1.18) rotate(3deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

.victory-confetti {
  position: fixed;
  inset: 0;
  z-index: 50;
  overflow: hidden;
  pointer-events: none;
}

.victory-confetti[hidden] {
  display: none;
}

.victory-confetti span {
  position: absolute;
  top: -10%;
  width: 9px;
  height: 16px;
  border-radius: 2px;
  opacity: 0;
  animation: victoryConfettiFall 1100ms cubic-bezier(0.2, 0.75, 0.3, 1) forwards;
}

@keyframes victoryConfettiFall {
  0% {
    opacity: 0;
    transform: translate3d(0, -12vh, 0) rotate(0deg) scale(0.7);
  }
  16% {
    opacity: 1;
  }
  100% {
    opacity: 0.12;
    transform: translate3d(var(--victory-drift), 120vh, 0) rotate(680deg) scale(1);
  }
}

.campaign-card {
  width: min(88vw, 360px);
  padding: 28px 24px 24px;
  border: 2px solid rgba(255, 255, 255, 0.78);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.97), rgba(231, 249, 255, 0.96));
  color: #064a84;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0, 53, 117, 0.3), inset 0 2px 0 rgba(255, 255, 255, 0.96);
}

.campaign-eyebrow {
  margin: 0;
  font-size: clamp(1rem, 4vw, 1.25rem);
  font-weight: 950;
  letter-spacing: 0.16em;
}

.campaign-copy {
  margin: 12px 0 24px;
  color: rgba(6, 74, 132, 0.72);
  font-size: 0.95rem;
  font-weight: 700;
}

.campaign-copy[hidden] {
  display: none;
}

.campaign-stars {
  margin: 12px 0 8px;
  color: #ffb900;
  font-size: clamp(1.65rem, 8vw, 2.4rem);
  letter-spacing: 0.08em;
  text-shadow: 0 3px 0 rgba(163, 95, 0, 0.14);
}

.campaign-total {
  margin: 0 0 22px;
  color: rgba(6, 74, 132, 0.65);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.16em;
}

.campaign-total span {
  color: #064a84;
  font-size: 1rem;
  letter-spacing: 0;
}

.campaign-button {
  width: 100%;
  min-height: 54px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(180deg, #d6ff54, #a4e62c);
  color: #174d16;
  box-shadow: 0 5px 0 #72ae1e, 0 10px 22px rgba(54, 116, 12, 0.2), inset 0 2px 0 rgba(255, 255, 255, 0.7);
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 950;
  letter-spacing: 0.14em;
  touch-action: manipulation;
}

.campaign-button-secondary {
  margin-top: 10px;
  background: linear-gradient(180deg, #4da7e8, #2478c5);
  color: #fff;
  box-shadow: 0 5px 0 #155796, 0 10px 22px rgba(17, 76, 135, 0.2), inset 0 2px 0 rgba(255, 255, 255, 0.42);
}

.campaign-button-secondary:active {
  box-shadow: 0 2px 0 #155796, 0 6px 13px rgba(17, 76, 135, 0.18);
}

.campaign-button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #72ae1e, 0 6px 13px rgba(54, 116, 12, 0.18);
}

#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)); }
  #score-wrap { padding: 8px 12px 9px; border-radius: 16px; gap: 7px; }
  .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));
  }
}
