/* ============================================================
   Flappy Bird — Golden Hour
   Design tokens: warm cream surfaces, gold CTA (role-locked),
   chunky game buttons, Fredoka display face.
   All UI sizes are in em; #stage font-size is set by JS so the
   whole interface scales with the letterboxed canvas.
   ============================================================ */

:root {
  /* Motion tokens */
  --dur-fast: 120ms;
  --dur: 200ms;
  --dur-slow: 320ms;
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --ease-pop: cubic-bezier(0.2, 1.4, 0.4, 1);

  /* Palette — warm, role-locked */
  --cream: #fff6e6;
  --cream-2: #ffe9c7;
  --ink: #3b2a1a;
  --ink-soft: #8a6d4d;
  --gold-1: #ffd75e;
  --gold-2: #f7a92b;
  --gold-edge: #b9721a;
  --gold-ink: #5b3a0e;
  --logo-edge: #43290f;

  --font: "Fredoka", "Baloo 2", "Trebuchet MS", system-ui, sans-serif;
  color-scheme: dark;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  background:
    radial-gradient(130% 110% at 50% -10%, #2b3a58 0%, #171f33 52%, #0c1120 100%);
  display: grid;
  place-items: center;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

/* ---------- Stage (letterboxed game frame) ---------- */

#stage {
  position: relative;
  width: 480px;
  height: 800px;
  font-size: 17px; /* rescaled by JS */
  border-radius: 1.05em;
  overflow: hidden;
  box-shadow:
    0 2.2em 5em rgba(0, 0, 0, 0.6),
    0 0 7em rgba(255, 176, 92, 0.09),
    0 0 0 1px rgba(255, 255, 255, 0.07);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
}

#ui {
  position: absolute;
  inset: 0;
  pointer-events: none; /* screens re-enable it */
}

#ui .screen,
#ui .icon-btn { pointer-events: auto; }

/* ---------- Icon buttons (mute / pause) ---------- */

.icon-btn {
  position: absolute;
  top: 0.9em;
  width: 2.5em;
  height: 2.5em;
  display: none;
  place-items: center;
  border: none;
  border-radius: 50%;
  background: rgba(24, 16, 8, 0.38);
  color: var(--cream);
  cursor: pointer;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    transform 90ms var(--ease-out);
}
.icon-btn:hover { background: rgba(24, 16, 8, 0.55); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn .ic { width: 1.25em; height: 1.25em; }

#muteBtn { right: 0.9em; display: grid; }
#pauseBtn { right: 3.8em; }

#stage[data-state="ready"] #pauseBtn,
#stage[data-state="play"] #pauseBtn { display: grid; }

#muteBtn .ic-sound-off { display: none; }
#muteBtn[data-muted="true"] .ic-sound-on { display: none; }
#muteBtn[data-muted="true"] .ic-sound-off { display: block; }
#muteBtn[data-muted="true"] { color: rgba(255, 246, 230, 0.55); }

/* ---------- Screens ---------- */

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--dur) var(--ease-out),
    visibility 0s linear var(--dur);
}
.screen.show {
  opacity: 1;
  visibility: visible;
  transition:
    opacity var(--dur) var(--ease-out),
    visibility 0s;
}

.screen-dim {
  background: rgba(14, 9, 4, 0.55);
  backdrop-filter: blur(0.25em);
  -webkit-backdrop-filter: blur(0.25em);
}

/* ---------- Menu ---------- */

.menu-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 13% 1.5em 8%;
  text-align: center;
}

.logo {
  transform: rotate(-2deg);
  line-height: 0.94;
  margin-bottom: 0.9em;
  opacity: 0;
  transition: opacity var(--dur-slow) var(--ease-out);
}
.show .logo { opacity: 1; }

.logo span {
  display: block;
  font-weight: 700;
  letter-spacing: 0.02em;
  -webkit-text-stroke: 0.065em var(--logo-edge);
}
.logo .l1 {
  font-size: 3.3em;
  color: var(--cream);
  text-shadow:
    0 0.07em 0 rgba(67, 41, 15, 0.9),
    0 0.16em 0.3em rgba(0, 0, 0, 0.35);
}
.logo .l2 {
  font-size: 4.4em;
  color: var(--gold-1);
  margin-top: -0.06em;
  text-shadow:
    0 0.06em 0 rgba(67, 41, 15, 0.9),
    0 0.2em 0.4em rgba(0, 0, 0, 0.4);
}

.best-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  padding: 0.5em 1.1em;
  border-radius: 999px;
  background: rgba(22, 14, 6, 0.38);
  color: var(--cream);
  font-size: 0.95em;
  font-weight: 500;
  letter-spacing: 0.08em;
  margin-bottom: auto; /* pushes play button toward lower third */
}
.best-chip b { font-weight: 700; }
.best-chip .ic-star {
  width: 1.05em;
  height: 1.05em;
  color: var(--gold-1);
}

.menu-wrap .btn-xl { margin-bottom: 1.1em; }

.hint {
  font-size: 0.72em;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 246, 230, 0.72);
  background: rgba(22, 14, 6, 0.3);
  padding: 0.65em 1.2em;
  border-radius: 999px;
}

/* ---------- Buttons ---------- */

.btn {
  font-family: var(--font);
  font-weight: 600;
  font-size: 1.05em;
  letter-spacing: 0.06em;
  border-radius: 999px;
  padding: 0.72em 2em;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out),
    transform 90ms var(--ease-out);
}
.btn .ic { width: 1.1em; height: 1.1em; }

.btn-primary {
  background: linear-gradient(180deg, var(--gold-1) 0%, var(--gold-2) 100%);
  color: var(--gold-ink);
  box-shadow:
    0 0.22em 0 var(--gold-edge),
    0 0.6em 1.4em rgba(247, 169, 43, 0.35);
}
.btn-primary:hover {
  background: linear-gradient(180deg, #ffde77 0%, #ffb43a 100%);
}
.btn-primary:active {
  transform: translateY(0.16em);
  box-shadow:
    0 0.06em 0 var(--gold-edge),
    0 0.3em 0.8em rgba(247, 169, 43, 0.3);
}

.btn-xl {
  font-size: 1.45em;
  padding: 0.7em 3.2em;
}

.btn-ghost {
  background: rgba(255, 246, 230, 0.08);
  color: var(--ink);
  border: 0.14em solid rgba(59, 42, 26, 0.3);
  padding: 0.62em 1.6em;
}
.btn-ghost:hover { background: rgba(59, 42, 26, 0.08); }
.btn-ghost:active { transform: scale(0.97); }

.btn:focus-visible,
.icon-btn:focus-visible {
  outline: 0.18em solid var(--gold-1);
  outline-offset: 0.15em;
}

/* ---------- Cards ---------- */

.card {
  position: relative;
  width: 80%;
  max-width: 22em;
  background: linear-gradient(180deg, var(--cream) 0%, var(--cream-2) 100%);
  border-radius: 1.3em;
  border: 0.16em solid rgba(67, 41, 15, 0.14);
  box-shadow:
    0 1.2em 3em rgba(0, 0, 0, 0.45),
    inset 0 0.1em 0 rgba(255, 255, 255, 0.7);
  padding: 1.6em 1.5em 1.5em;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  transform: scale(0.92) translateY(0.8em);
  opacity: 0;
  transition:
    transform var(--dur-slow) var(--ease-out),
    opacity var(--dur-slow) var(--ease-out);
}
.screen.show .card {
  transform: scale(1) translateY(0);
  opacity: 1;
}

.card-sm { width: 68%; padding: 1.5em 1.4em; }

.card-title {
  font-size: 1.7em;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--ink);
  margin-bottom: 0.7em;
}

.btn-col {
  display: flex;
  flex-direction: column;
  gap: 0.7em;
  width: 100%;
}
.btn-col .btn { width: 100%; }

.btn-row {
  display: flex;
  flex-direction: column;
  gap: 0.7em;
  width: 100%;
  margin-top: 1.4em;
}

/* ---------- Medal ---------- */

.medal-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4em;
  margin-bottom: 1.1em;
}
.medal-wrap.hidden { display: none; }

.medal {
  width: 4.4em;
  height: 4.4em;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: rgba(59, 42, 26, 0.55);
  border: 0.26em solid rgba(67, 41, 15, 0.16);
  box-shadow:
    inset 0 -0.25em 0.5em rgba(0, 0, 0, 0.25),
    inset 0 0.2em 0.4em rgba(255, 255, 255, 0.55),
    0 0.4em 1em rgba(0, 0, 0, 0.25);
  opacity: 0;
  transform: scale(1.9) rotate(-14deg);
}
.show .medal.earned {
  opacity: 1;
  transform: scale(1) rotate(0deg);
  transition:
    transform 420ms var(--ease-pop) 220ms,
    opacity 180ms var(--ease-out) 220ms;
}
.medal .ic-star { width: 55%; height: 55%; }

.medal-bronze   { background: radial-gradient(circle at 32% 28%, #f2b98e, #b96f3e 72%); }
.medal-silver   { background: radial-gradient(circle at 32% 28%, #fbfdff, #96a4b3 72%); }
.medal-gold     { background: radial-gradient(circle at 32% 28%, #ffed9e, #dd9f26 72%); }
.medal-platinum { background: radial-gradient(circle at 32% 28%, #e6f9ff, #79c2dd 72%); }

.medal-name {
  font-size: 0.78em;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--ink-soft);
}

/* ---------- Score grid ---------- */

.score-grid {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 1.4em;
  width: 100%;
  background: rgba(59, 42, 26, 0.06);
  border-radius: 0.9em;
  padding: 0.85em 1em;
}

.score-cell {
  display: flex;
  flex-direction: column;
  gap: 0.15em;
  min-width: 4.5em;
}

.score-divider {
  width: 0.1em;
  border-radius: 1px;
  background: rgba(59, 42, 26, 0.14);
}

.score-label {
  font-size: 0.72em;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--ink-soft);
}

.score-value {
  font-size: 2em;
  font-weight: 700;
  line-height: 1.1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* ---------- New best badge ---------- */

.new-best {
  position: absolute;
  top: -0.9em;
  right: -0.5em;
  transform: rotate(8deg) scale(0);
  background: linear-gradient(180deg, var(--gold-1), var(--gold-2));
  color: var(--gold-ink);
  font-size: 0.85em;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 0.45em 1em;
  border-radius: 999px;
  box-shadow:
    0 0.25em 0.7em rgba(0, 0, 0, 0.35),
    inset 0 0.1em 0 rgba(255, 255, 255, 0.5);
}
.new-best.show {
  transform: rotate(8deg) scale(1);
  transition: transform 380ms var(--ease-pop) 520ms;
}

/* ---------- Reduced motion ---------- */

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