:root {
  /* ── Typography ─────────────────────────────────────────────────────────── */
  --font-heading: 'Baloo 2', 'Nunito', sans-serif;
  --font-main: 'Nunito', sans-serif;
  --font-secondary: 'Nunito', sans-serif;

  /* ── Spacing ─────────────────────────────────────────────────────────────── */
  --site-header-height: 0px;
  --game-height: calc(100vh - var(--site-header-height));
  --game-height: calc(100dvh - var(--site-header-height));
  --safe-bottom: max(env(safe-area-inset-bottom), 0px);

  /* ── Pill / capsule sizing ───────────────────────────────────────────────── */
  --pill-scale: 1;
  --pill-min-width: 152px;
  --pill-max-width: 304px;
  --pill-min-height: 72px;
  --pile-pill-min-height: 64px;
  --pill-padding-y: 15px;
  --pill-padding-x: 23px;
  --pill-radius: 40px;
  --pill-font-min: 27px;
  --pill-font-max: 36px;

  /* ── Warm Catalan color system ───────────────────────────────────────────── */
  --clr-navy:        #0E1F3A;
  --clr-orange:      #F08A1A;
  --clr-warm-yellow: #F4D68F;
  --clr-tile:        #F6ECDC;
  --clr-card:        #EDE0CA;
  --clr-card-warm:   #E9D9B7;
  --clr-brown:       #8B5A2B;

  /* ── Semantic aliases ────────────────────────────────────────────────────── */
  --ink:     #0E1F3A;
  --muted:   #5a6a82;
  --card:    #EDE0CA;
  --sky:     #cceeff;
  --sky-deep:#8ed0f2;
  --purple:  #6d3fb1;
  --blue:    #2d82dd;
  --green:   #2f9d72;
  --magenta: #c0266f;

  /* ── Shadows ─────────────────────────────────────────────────────────────── */
  --shadow:      0 6px 20px rgba(14, 31, 58, 0.13);
  --soft-shadow: 0 3px 10px rgba(14, 31, 58, 0.09);

  /* ── Pill accessibility system ───────────────────────────────────────────── */
  /* All five pill backgrounds are dark enough for white text (WCAG AA ≥ 5:1).
     Unified text color removes per-pill text-color logic entirely.
     Shapes: every color has a distinct silhouette — identifiable in grayscale.
     Hitboxes stay larger and simpler than the decorative clip-path edges.     */
  --pill-highlight: rgba(255, 255, 255, 0.26); /* top-edge lightening          */
  --pill-depth:     rgba(0,   0,   0,   0.20); /* bottom-edge darkening        */
  --pill-rim:       rgba(0,   0,   0,   0.28); /* perimeter gradient rim       */
  --pill-outline:   #143c9a;                    /* per-pill darker edge stroke  */
  --pill-outline-width: 3px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  overscroll-behavior: none;
}

body {
  margin: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  background: var(--clr-tile);
  color: var(--ink);
  font-family: var(--font-main);
  overflow: hidden;
  overscroll-behavior: none;
}

input,
button,
select,
textarea {
  font-family: var(--font-main);
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
}

.game-shell {
  width: 100vw;
  /* Height matches exactly what .phone can fill — eliminates black-bar centering gaps.
     JS sets --vp-safe-height from visualViewport.height so this stays pixel-perfect
     as browser chrome shows/hides. Falls back to 100dvh before JS runs. */
  height: calc(100vh - var(--site-header-height));
  height: calc(100dvh - var(--site-header-height));
  height: calc(var(--vp-safe-height, 100dvh) - var(--site-header-height) - var(--safe-bottom));
  display: grid;
  place-items: center;
  padding: 0;
}

.phone {
  position: relative;
  width: 100vw;
  max-width: none;
  height: calc(100vh - var(--site-header-height));
  height: calc(100dvh - var(--site-header-height));
  height: min(var(--game-height), 920px);
  /* Safe viewport: JS sets --vp-safe-height from visualViewport.height (handles Android
     browser chrome + keyboard), --safe-bottom covers iOS home bar and Android nav bar. */
  height: min(calc(var(--vp-safe-height, 100dvh) - var(--site-header-height) - var(--safe-bottom)), 920px);
  max-height: 920px;
  overflow: hidden;
  background: var(--level-background, url('./img/backgrounds/1st.png')) center / cover no-repeat;
  box-shadow: 0 0 0 1px rgba(16, 25, 79, 0.08);
  isolation: isolate;
}

.phone[data-level-theme="simple"] {
  background: var(--level-background, url('./img/backgrounds/1st.png')) center / cover no-repeat;
}

.phone[data-level-theme] .sky-details { background: none; }

.hud {
  position: relative;
  z-index: 20;
  height: calc(clamp(48px, 10vw, 56px) + env(safe-area-inset-top));
  padding: calc(6px + env(safe-area-inset-top)) clamp(10px, 2.8vw, 14px) 6px;
  display: grid;
  grid-template-columns: minmax(78px, 1fr) auto minmax(34px, 1fr);
  gap: clamp(7px, 2vw, 12px);
  align-items: center;
  background: var(--clr-navy);
  color: #fff;
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.08);
}

.mascot {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #ffc928;
  box-shadow: 0 0 0 1px rgba(255, 201, 40, 0.28), 0 3px 7px rgba(0, 0, 0, 0.22);
  transition: transform 180ms ease;
  overflow: hidden;
}

.mascot img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.score-box {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-self: center;
  justify-content: center;
  gap: clamp(5px, 1.4vw, 8px);
  max-width: min(58vw, 220px);
  padding: 4px clamp(10px, 2.6vw, 14px) 5px;
  border-radius: 999px;
  background: rgba(5, 13, 31, 0.36);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 3px 8px rgba(0, 0, 0, 0.16);
  text-align: left;
  line-height: 1;
  white-space: nowrap;
}

.score-box span {
  display: block;
  font-family: var(--font-secondary);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.92;
}

.score-box strong {
  display: block;
  margin-top: 0;
  color: #ffc928;
  font-size: clamp(29px, 8vw, 38px);
  font-weight: 900;
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
  text-align: center;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.24);
}

.score-box strong::after {
  content: "·";
  display: inline-block;
  margin-left: clamp(5px, 1.4vw, 8px);
  color: rgba(255, 255, 255, 0.68);
  font-size: 0.5em;
  line-height: 1;
  text-shadow: none;
  vertical-align: 0.12em;
}

.score-box em {
  display: inline-block;
  margin-top: 0;
  color: #fff;
  font-family: var(--font-secondary);
  font-size: clamp(15px, 4vw, 18px);
  font-style: normal;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

#pauseBtn {
  justify-self: end;
}

.icon-btn {
  justify-self: end;
  width: clamp(32px, 8vw, 40px);
  height: clamp(32px, 8vw, 40px);
  border-radius: 12px;
  border: none;
  background: #FEFAF3;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  box-shadow:
    inset 0 -2px 0 rgba(240, 138, 26, 0.12),
    0 3px 8px rgba(0, 0, 0, 0.2);
}

.icon-btn span {
  width: 4px;
  height: clamp(13px, 3.5vw, 17px);
  border-radius: 3px;
  background: #10213e;
}

.question-card {
  position: relative;
  z-index: 18;
  margin: clamp(6px, 1.5vw, 8px) clamp(10px, 2.8vw, 16px) 0;
  min-height: fit-content;
  height: auto;
  display: block;
  padding: clamp(10px, 2.6vw, 14px) clamp(12px, 3.4vw, 18px) clamp(12px, 3vw, 16px);
  border: 2px solid #F4D4B2;
  border-radius: clamp(16px, 4vw, 22px);
  background: #FEFAF3;
  box-shadow: 0 8px 18px rgba(14, 31, 58, 0.14);
  transition: transform 160ms ease;
  cursor: pointer;
  user-select: none;
}

.q-icon {
  display: none;
}

.question-card::before {
  content: "";
  position: absolute;
  inset: -4px;
  border: 3px solid rgba(255, 203, 48, 0.72);
  border-radius: calc(clamp(16px, 4vw, 22px) + 4px);
  opacity: 0;
  pointer-events: none;
}

.question-card::after {
  content: none;
}


.question-card h1 {
  position: relative;
  z-index: 2;
  flex: 1;
  margin: 0;
  max-width: 100%;
  display: grid;
  gap: clamp(6px, 1.6vw, 9px);
  font-family: var(--font-heading);
  font-size: clamp(22px, 6vw, 32px);
  font-weight: 900;
  line-height: 1.08;
  text-align: center;
  letter-spacing: 0;
  color: var(--clr-navy);
}

.prompt-source,
.prompt-frame {
  display: block;
  min-width: 0;
}

.prompt-source {
  color: var(--clr-navy);
  font-size: var(--prompt-source-size, clamp(22px, 6.6vw, 36px));
  font-weight: 900;
  line-height: 1.06;
  padding: 0 clamp(2px, 1vw, 6px);
  text-wrap: balance;
  word-break: normal;
  overflow-wrap: normal;
}

.prompt-source--logo {
  display: flex;
  justify-content: center;
  align-items: center;
  background: none;
  padding: 0;
}

.prompt-logo {
  display: block;
  width: clamp(70px, 20vw, 96px);
  max-width: 100%;
  height: auto;
  max-height: 24px;
  object-fit: contain;
}

.prompt-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  gap: clamp(5px, 0.34em, 12px);
  padding: clamp(7px, 1.8vw, 10px) 0 0;
  border-top: 2px solid rgba(240, 138, 26, 0.16);
  border-radius: 0;
  background: transparent;
  color: var(--clr-navy);
  font-size: var(--prompt-frame-size, clamp(22px, 6.4vw, 36px));
  font-weight: 900;
  line-height: 1.05;
  white-space: nowrap;
  box-shadow: none;
}

.prompt-arrow {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: clamp(22px, 1.18em, 38px);
  height: clamp(18px, 0.98em, 32px);
  border: clamp(1px, 0.06em, 2px) solid rgba(240, 138, 26, 0.18);
  border-radius: 999px;
  background: #F4E0C9;
  color: var(--clr-navy);
  font-size: clamp(15px, 0.72em, 24px);
  line-height: 1;
}

.prompt-answer {
  min-width: 0;
  text-align: left;
  white-space: nowrap;
}

.question-card h1 .prompt-blank {
  display: inline-block;
  width: var(--prompt-blank-width, clamp(62px, 18vw, 118px));
  height: 0.64em;
  margin: 0 0.07em;
  border-bottom: 2px solid currentColor;
  vertical-align: -0.05em;
}

.playfield {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: manipulation;
  z-index: 5;
}

.playfield::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 80;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.92), rgba(255, 242, 160, 0.52) 18%, transparent 48%),
    linear-gradient(180deg, rgba(255, 245, 172, 0.42), transparent 48%);
}

.sky-details {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 7% 20%, rgba(255, 255, 255, 0.72) 0 20px, transparent 21px),
    radial-gradient(circle at 101% 18%, rgba(255, 255, 255, 0.62) 0 27px, transparent 28px),
    radial-gradient(circle at 18% 74%, rgba(78, 151, 92, 0.44) 0 58px, transparent 59px),
    radial-gradient(circle at 88% 72%, rgba(76, 159, 91, 0.5) 0 66px, transparent 67px);
  opacity: 0.8;
}


.fall-layer,
.pile-layer,
.relief-layer,
.physics-debug-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.physics-debug-layer {
  z-index: 80;
  display: none;
  mix-blend-mode: screen;
}

.physics-debug-on .physics-debug-layer {
  display: block;
}

.capsule {
  box-sizing: border-box;
  position: absolute;
  left: 0;
  top: 0;
  min-width: var(--pill-min-width);
  max-width: min(var(--pill-max-width), 60vw);
  min-height: var(--pill-min-height);
  padding: var(--pill-padding-y) var(--pill-padding-x);
  display: grid;
  place-items: center;
  text-align: center;
  color: #fff;
  font-size: clamp(var(--pill-font-min), 4.5vw, var(--pill-font-max));
  font-weight: 800;
  line-height: 1.08;
  overflow-wrap: normal;
  word-break: keep-all;
  white-space: nowrap;
  hyphens: none;
  font-family: var(--font-main);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  background: var(--pill-outline);
  border-radius: 14px;
  clip-path: var(--pill-shape, none);
  filter: drop-shadow(0 6px 10px rgba(14, 36, 88, 0.28));
  pointer-events: auto;
  user-select: none;
  will-change: transform, opacity;
  transform-origin: 50% 72%;
}

.capsule::before {
  content: "";
  position: absolute;
  inset: var(--pill-outline-width);
  z-index: 0;
  border-radius: inherit;
  clip-path: var(--pill-shape, none);
  background:
    linear-gradient(180deg, var(--pill-highlight) 0%, transparent 32%, var(--pill-depth) 100%),
    radial-gradient(ellipse 95% 88% at 50% 50%, transparent 76%, var(--pill-rim) 100%),
    var(--pill-color, #1d4ed8);
  box-shadow: inset 0 2px 8px rgba(255,255,255,0.12);
  pointer-events: none;
}

.capsule-label {
  position: relative;
  z-index: 1;
  pointer-events: none;
}

/* ── Pill shapes — color-blind accessible silhouette system ─────────────── */
/* All five backgrounds are dark enough for white text (WCAG AA ≥ 5.2:1).
   Each color also has a distinct silhouette identifiable in grayscale:
     Red    (#b91c1c, 6.4:1) → oval / stadium
     Blue   (#1d4ed8, 6.7:1) → rounded rectangle
     Orange (#a16207, 4.9:1) → hexagon (sides OUT — convex waist)
     Green  (#166534, 7.1:1) → octagon (45° beveled corners)
     Purple (#6d28d9, 7.1:1) → notched rectangle (sides IN — concave waist)
   The outline is a real shaped layer behind an inset fill layer, so every
   polygon edge receives the same continuous stroke.                         */

.capsule.red {
  --pill-color: #b91c1c;
  --pill-outline: #7f1212;
  border-radius: 999px;
}

.capsule.blue {
  --pill-color: #1d4ed8;
  --pill-outline: #143c9a;
  border-radius: 14px;
}

/* Orange — hexagon: sides point OUT. Opposite silhouette to purple. */
.capsule.orange {
  --pill-color: #a16207;
  --pill-outline: #6f4204;
  --pill-shape: polygon(0% 50%, 9px 0%, calc(100% - 9px) 0%, 100% 50%, calc(100% - 9px) 100%, 9px 100%);
  border-radius: 0;
}

/* Green — octagon: 45° beveled corners. */
.capsule.green {
  --pill-color: #166534;
  --pill-outline: #0b3f20;
  --pill-shape: polygon(
    18px 0%,               calc(100% - 18px) 0%,
    100% 18px,             100% calc(100% - 18px),
    calc(100% - 18px) 100%, 18px 100%,
    0%   calc(100% - 18px), 0%   18px
  );
  border-radius: 0;
}

/* Purple — notched rectangle: sides dip IN. Opposite silhouette to orange.
   Notch is 10 px; pill padding is 23 px, so text area is fully clear. */
.capsule.purple {
  --pill-color: #6d28d9;
  --pill-outline: #43138f;
  --pill-shape: polygon(
    0%                0%,
    100%              0%,
    100%              calc(50% - 16px),
    calc(100% - 10px) 50%,
    100%              calc(50% + 16px),
    100%              100%,
    0%                100%,
    0%                calc(50% + 16px),
    10px              50%,
    0%                calc(50% - 16px)
  );
  border-radius: 0;
}

.capsule.pile {
  min-height: var(--pile-pill-min-height);
  filter: drop-shadow(0 4px 6px rgba(6, 14, 34, 0.24));
  transition: transform 360ms cubic-bezier(.16,.95,.22,1.16), opacity 220ms ease, filter 220ms ease;
}

.capsule.pile.is-settling {
  filter:
    drop-shadow(0 4px 6px rgba(6, 14, 34, 0.24))
    brightness(1.04) saturate(1.04);
}

.capsule.pile.is-physics-settling {
  transition: none;
  will-change: transform;
}

.capsule.pile.is-physics-unsupported {
  outline: 2px solid rgba(248, 113, 113, 0.95);
  outline-offset: 2px;
}

.capsule.falling {
  transition: filter 120ms ease;
}

.capsule.is-correct {
  animation: pop 330ms ease forwards;
}

.capsule.is-wrong {
  animation: no 260ms ease;
}

.capsule.is-cleared {
  animation: clearAway 360ms ease forwards;
}

.capsule.is-dropping {
  z-index: 18;
  transition: transform 340ms cubic-bezier(.2,.86,.18,1), filter 160ms ease;
  filter:
    drop-shadow(0 6px 10px rgba(14, 36, 88, 0.24))
    brightness(0.92) saturate(0.9);
}

.capsule.is-rescue {
  animation: hang 320ms ease;
}

.capsule.is-glowing {
  z-index: 9;
  animation: glow 620ms ease both;
}

.capsule.is-glowing.is-correct {
  animation: glowPop 520ms ease forwards;
}

.capsule.is-chain-reacting {
  z-index: 24;
  animation: chainPulse 260ms ease-out both;
}

.capsule.is-color-burst {
  z-index: 30;
  animation: colorBurst 420ms cubic-bezier(.16,.86,.2,1) forwards;
}

@keyframes pop {
  to { transform: translate(var(--x), var(--y)) rotate(var(--r)) scale(1.22); opacity: 0; filter: brightness(1.35); }
}

@keyframes clearAway {
  45% { opacity: 0.8; filter: saturate(0.8) brightness(1.12); }
  to { transform: translate(var(--x), calc(var(--y) - 26px)) rotate(var(--r)) scale(0.88); opacity: 0; filter: saturate(0.45) blur(1px); }
}

@keyframes no {
  30% { filter: saturate(1.3) brightness(0.9); }
  50% { transform: translate(calc(var(--x) - 8px), var(--y)) rotate(var(--r)); }
  80% { transform: translate(calc(var(--x) + 8px), var(--y)) rotate(var(--r)); }
}

@keyframes hang {
  0%, 100% { filter: brightness(1); }
  45% { filter: brightness(1.35); transform: translate(var(--x), calc(var(--y) - 22px)) rotate(var(--r)) scale(1.05); }
}

@keyframes glow {
  30% { filter: brightness(1.6) drop-shadow(0 0 4px rgba(255, 221, 72, 0.7)) drop-shadow(0 0 14px rgba(255, 221, 72, 0.9)); }
  100% { filter: brightness(1); }
}

@keyframes glowPop {
  28% {
    transform: translate(var(--x), var(--y)) rotate(var(--r)) scale(1.08);
    filter: brightness(1.7) drop-shadow(0 0 5px rgba(255, 221, 72, 0.7)) drop-shadow(0 0 15px rgba(255, 221, 72, 0.9));
  }
  to {
    transform: translate(var(--x), calc(var(--y) - 16px)) rotate(var(--r)) scale(1.18);
    opacity: 0;
    filter: brightness(1.35);
  }
}

@keyframes chainPulse {
  0% {
    transform: translate(var(--x), var(--y)) rotate(var(--r)) scale(1);
    filter: brightness(1);
  }
  55% {
    transform: translate(var(--x), var(--y)) rotate(var(--r)) scale(1.08);
    filter: brightness(1.55) saturate(1.24)
      drop-shadow(0 0 5px color-mix(in srgb, var(--chain-color), transparent 58%))
      drop-shadow(0 0 15px color-mix(in srgb, var(--chain-color), white 10%));
  }
  100% {
    transform: translate(var(--x), var(--y)) rotate(var(--r)) scale(1.03);
    filter: brightness(1.18) saturate(1.14);
  }
}

@keyframes colorBurst {
  0% {
    transform: translate(var(--x), var(--y)) rotate(var(--r)) scale(1.04);
    opacity: 1;
    filter: brightness(1.45) saturate(1.3)
      drop-shadow(0 0 6px color-mix(in srgb, var(--chain-color), transparent 52%))
      drop-shadow(0 0 17px var(--chain-color));
  }
  100% {
    transform: translate(var(--x), calc(var(--y) - 20px)) rotate(var(--r)) scale(1.32);
    opacity: 0;
    filter: brightness(1.65) blur(1px);
  }
}

/* ── Reduced motion — decorative pill animations only; physics/falling kept ── */
@media (prefers-reduced-motion: reduce) {
  .capsule.is-correct,
  .capsule.is-wrong,
  .capsule.is-cleared,
  .capsule.is-rescue,
  .capsule.is-glowing,
  .capsule.is-chain-reacting,
  .capsule.is-color-burst {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
  .capsule.pile {
    transition-duration: 0.01ms !important;
  }
}

/* ── Developer pill preview ──────────────────────────────────────────────── */
/* Enable by adding class="pill-debug" to <body>.
   Shows all 5 pill shapes with their actual colors, grayscale-testable.
   Not visible in normal gameplay.                                            */
#pill-debug-preview {
  display: none;
}
body.pill-debug #pill-debug-preview {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 20px 24px;
  background: rgba(14, 31, 58, 0.92);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  backdrop-filter: blur(6px);
}
body.pill-debug #pill-debug-preview .capsule {
  position: static;
  transform: none !important;
  animation: none !important;
  transition: none !important;
}

.particle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--particle-color, #ffe15d);
  box-shadow: 0 0 12px var(--particle-color, #ffe15d);
  pointer-events: none;
  animation: burst 640ms ease-out forwards;
}

.particle.is-dust {
  width: 10px;
  height: 7px;
  background: rgba(176, 153, 118, 0.72);
  box-shadow: 0 0 10px rgba(126, 104, 76, 0.2);
  filter: blur(0.4px);
  animation: dustPuff 720ms ease-out forwards;
}

@keyframes burst {
  to {
    transform: translate(var(--dx), var(--dy)) scale(0);
    opacity: 0;
  }
}

@keyframes dustPuff {
  0% {
    transform: translate(0, 0) scale(0.35);
    opacity: 0;
  }
  18% {
    opacity: 0.62;
  }
  100% {
    transform: translate(var(--dx), var(--dy)) scale(1.9);
    opacity: 0;
  }
}

.color-wave {
  position: absolute;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  border: 3px solid var(--chain-color, #4f6fe8);
  box-shadow: 0 0 22px var(--chain-color, #4f6fe8);
  pointer-events: none;
  animation: colorWave 680ms ease-out forwards;
}

@keyframes colorWave {
  0% {
    opacity: 0.8;
    transform: scale(0.35);
  }
  100% {
    opacity: 0;
    transform: scale(10);
  }
}

.relief {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  width: max-content;
  max-width: calc(100% - 28px);
  text-align: center;
  color: var(--relief-color, #208961);
  font-weight: 900;
  font-size: 26px;
  text-shadow: 0 2px 0 #fff;
  animation: relief 850ms ease forwards;
  pointer-events: none;
}

.relief.is-negative {
  color: #c0342b;
}

.relief.is-chain {
  font-size: clamp(20px, 5.7vw, 26px);
  line-height: 1.04;
  text-transform: uppercase;
  text-shadow:
    0 2px 0 #fff,
    0 0 18px color-mix(in srgb, var(--relief-color), transparent 40%);
}

@keyframes relief {
  0% { opacity: 0; transform: translate(-50%, -22%) scale(0.84); }
  24% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -92%) scale(1.05); }
}

.phone.tense {
  animation: pulse 1.3s ease-in-out infinite;
}

.phone.is-jolted {
  animation: gameJolt 360ms cubic-bezier(.2,.9,.2,1) both;
}

.phone.critical .mascot {
  transform: scale(1.08) rotate(-3deg);
}

.phone .question-card.is-changing {
  animation: questionReveal 440ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.question-card.is-changing::before {
  animation: questionGlow 440ms ease-out both;
}

.question-card.is-changing h1 {
  animation: questionTextReveal 400ms ease-out both;
}

@keyframes pulse {
  50% { filter: saturate(1.07) contrast(1.02); }
}

@keyframes gameJolt {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  12% { transform: translate(-5px, 2px) rotate(-0.5deg); }
  26% { transform: translate(6px, -2px) rotate(0.5deg); }
  42% { transform: translate(-4px, 1px) rotate(-0.35deg); }
  58% { transform: translate(3px, 0) rotate(0.25deg); }
  76% { transform: translate(-1px, 0) rotate(-0.1deg); }
}

/* Card expands and glows when a new question arrives */
@keyframes questionReveal {
  0%   { transform: scale(0.965);
         box-shadow: 0 6px 20px rgba(14,31,58,0.16), 0 0 0 rgba(255,203,48,0); }
  38%  { transform: scale(1.028);
         box-shadow: 0 6px 24px rgba(14,31,58,0.22), 0 0 30px rgba(255,203,48,0.52), 0 0 64px rgba(255,203,48,0.18); }
  100% { transform: scale(1);
         box-shadow: 0 6px 20px rgba(14,31,58,0.16), 0 0 0 rgba(255,203,48,0); }
}

/* Amber ring brightens and fades */
@keyframes questionGlow {
  0%   { opacity: 0; }
  28%  { opacity: 1; }
  100% { opacity: 0; }
}

/* Text fades in with a quick brightness flash */
@keyframes questionTextReveal {
  0%   { opacity: 0.15; filter: brightness(1); }
  26%  { opacity: 1;    filter: brightness(1.35); }
  100% { opacity: 1;    filter: brightness(1); }
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: none;
  place-items: center;
  padding: 12px;
  background: rgba(14, 31, 58, 0.22);
  backdrop-filter: blur(4px);
  overflow-y: auto;
}

.overlay.is-visible {
  display: grid;
}

.overlay-panel {
  position: relative;
  z-index: 2;
  width: min(calc(100vw - 24px), 300px);
  max-width: 100%;
  padding: 20px 18px;
  border-radius: 20px;
  background: var(--clr-tile);
  border: 1px solid rgba(139, 90, 43, 0.15);
  box-shadow: 0 12px 40px rgba(14, 31, 58, 0.18);
  text-align: center;
}

.start-overlay {
  background: rgba(14, 31, 58, 0.18);
  backdrop-filter: blur(3px);
}

.start-overlay::before {
  content: none;
}

.start-overlay::after {
  content: none;
}

.start-overlay .overlay-panel {
  background: var(--clr-tile);
}

.overlay-panel h2 {
  margin: 0 0 10px;
  font-family: var(--font-heading);
  font-size: 34px;
  font-weight: 900;
  line-height: 1;
  color: var(--clr-navy);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--clr-brown);
  font-family: var(--font-main);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.overlay-logo-eyebrow {
  display: flex;
  justify-content: center;
  line-height: 1;
}

.overlay-logo {
  display: block;
  width: clamp(78px, 22vw, 108px);
  max-width: 100%;
  height: auto;
  max-height: 24px;
  object-fit: contain;
}

.intro {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.4;
  font-family: var(--font-main);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.primary-btn,
.secondary-btn {
  width: 100%;
  min-height: 50px;
  margin-top: 8px;
  border-radius: 14px;
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 16px;
  line-height: 1.15;
  transition: transform 0.1s ease, opacity 0.1s ease;
}

.primary-btn:active { transform: scale(0.97); opacity: 0.9; }
.secondary-btn:active { opacity: 0.75; }

.primary-btn {
  color: var(--clr-navy);
  background: var(--clr-warm-yellow);
  border: 2px solid var(--clr-orange);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.55),
    0 5px 16px rgba(240, 138, 26, 0.28);
}

.secondary-btn {
  color: var(--clr-navy);
  background: var(--clr-card);
  border: 1.5px solid rgba(14, 31, 58, 0.15);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.5),
    0 3px 10px rgba(14, 31, 58, 0.08);
}

.mode-grid {
  display: grid;
  grid-template-columns: minmax(180px, 240px);
  justify-content: center;
  gap: 10px;
  margin-top: 4px;
}

.mode-btn {
  display: grid;
  place-items: center;
  gap: 2px;
}

.battle-link-btn {
  width: 100%;
  min-height: 56px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: var(--clr-navy);
  background: var(--clr-warm-yellow);
  border: 2px solid var(--clr-orange);
  box-shadow: 0 5px 16px rgba(240, 138, 26, 0.28);
  font-family: var(--font-heading);
  font-weight: 800;
  line-height: 1.15;
  text-decoration: none;
}


.mode-btn span {
  font-size: 17px;
}

.mode-btn small {
  font-family: var(--font-secondary);
  font-size: 12px;
  font-weight: 500;
  opacity: 0.76;
}

.final-score {
  margin: 2px 0 4px;
  color: var(--clr-navy);
  font-family: var(--font-heading);
  font-size: 32px;
  line-height: 1;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.final-score::before {
  content: "PUNTS ";
  display: block;
  margin-bottom: 2px;
  color: var(--clr-brown);
  font-family: var(--font-main);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.final-level {
  margin: 0 0 4px;
  color: var(--clr-navy);
  font-family: var(--font-heading);
  font-size: 48px;
  line-height: 0.95;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.final-difficulty {
  margin: 0 0 8px;
  color: var(--muted);
  font-family: var(--font-main);
  font-size: 15px;
  font-weight: 600;
}

.profile-summary {
  display: grid;
  gap: 3px;
  margin: 5px 0 6px;
  color: var(--clr-navy);
  font-family: var(--font-main);
  font-size: 12px;
  line-height: 1.35;
  text-align: left;
}

.profile-summary p {
  margin: 0;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--clr-card);
  border: 1px solid rgba(139, 90, 43, 0.1);
}

.missed-panel {
  margin: 6px 0 5px;
  text-align: left;
}

.missed-panel h3 {
  margin: 0 0 5px;
  color: var(--clr-brown);
  font-family: var(--font-main);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.missed-list {
  display: grid;
  gap: 5px;
  max-height: min(26vh, 180px);
  overflow: auto;
  padding-right: 3px;
}

.missed-item {
  position: relative;
  display: grid;
  gap: 2px;
  padding: 6px 10px 6px 34px;
  border-radius: 10px;
  background: var(--clr-card);
  border: 1px solid rgba(139, 90, 43, 0.12);
  color: var(--clr-navy);
  font-size: 13px;
  line-height: 1.2;
}

.missed-count {
  position: absolute;
  left: 9px;
  top: 9px;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(240, 138, 26, 0.2);
  color: var(--clr-brown);
  font-family: var(--font-main);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.missed-item strong,
.missed-frame {
  font-size: 13px;
}

.missed-frame {
  color: var(--clr-navy);
  font-weight: 800;
}

.missed-correct {
  color: #15803d;
}

.missed-chosen {
  color: #b91c1c;
}

.missed-item em {
  margin-top: 3px;
  color: var(--muted);
  font-family: var(--font-main);
  font-size: 12px;
  font-style: normal;
  line-height: 1.35;
}

.level-up-splash {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  pointer-events: none;
  animation: lvlSplashBg 1700ms ease-out forwards;
}

.level-up-splash-inner {
  color: #fff;
  font-size: clamp(38px, 10vw, 58px);
  font-weight: 900;
  letter-spacing: 0.06em;
  text-align: center;
  text-shadow:
    0 0 28px rgba(255, 220, 60, 0.95),
    0 0 60px rgba(255, 180, 0, 0.6),
    0 4px 0 rgba(0, 0, 0, 0.35);
  animation: lvlSplashText 1700ms ease-out forwards;
}

@keyframes lvlSplashBg {
  0%   { background: rgba(255, 200, 0, 0); }
  12%  { background: rgba(255, 200, 0, 0.22); }
  100% { background: rgba(255, 200, 0, 0); }
}

@keyframes lvlSplashText {
  0%   { opacity: 0; transform: scale(0.42); }
  16%  { opacity: 1; transform: scale(1.22); }
  30%  { transform: scale(1); }
  70%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.92) translateY(-28px); }
}

@media (min-width: 560px) {
  :root {
    --site-header-height: 0px;
  }

  body {
    background: var(--clr-tile);
  }

  .phone {
    width: min(100vw, 470px);
    max-width: 470px;
    height: min(calc(100vh - var(--site-header-height)), 920px);
    height: min(calc(100dvh - var(--site-header-height)), 920px);
    height: min(var(--game-height), 920px);
    height: min(calc(var(--vp-safe-height, 100dvh) - var(--site-header-height) - var(--safe-bottom)), 920px);
    border-radius: 34px;
    border: 8px solid #111827;
    box-shadow: 0 18px 50px rgba(16, 25, 79, 0.25);
  }
}

@media (max-height: 690px) {
  .hud {
    height: calc(44px + env(safe-area-inset-top));
    padding: calc(5px + env(safe-area-inset-top)) 9px 5px;
  }

  .mascot,
  .icon-btn {
    width: 30px;
    height: 30px;
  }

  .score-box strong {
    font-size: 28px;
  }

  .question-card {
    min-height: fit-content;
    margin-top: 5px;
    padding: 8px 11px 10px;
  }

  .question-card h1 {
    font-size: clamp(21px, 5.6vw, 29px);
    gap: 5px;
  }

  .prompt-source {
    font-size: clamp(21px, 6vw, 31px);
  }

  .prompt-frame {
    padding-top: 6px;
    font-size: clamp(21px, 5.8vw, 30px);
  }

  .capsule {
    min-height: var(--pile-pill-min-height);
    padding: var(--pill-padding-y) var(--pill-padding-x);
  }
}

/* ── Compact HUD brand and sound ───────────────────────────────────────────── */

body {
  padding-top: var(--site-header-height);
}

.hud-brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-self: start;
  background: rgba(254, 250, 243, 0.94);
  border: 1px solid rgba(244, 212, 178, 0.28);
  border-radius: 10px;
  padding: 4px clamp(6px, 1.6vw, 8px);
  box-shadow:
    inset 0 -1px 0 rgba(240, 138, 26, 0.1),
    0 3px 8px rgba(0, 0, 0, 0.16);
}

.brand-link {
  text-decoration: none;
  line-height: 1;
}

.top-img-btn {
  appearance: none;
  border: none;
  background: transparent;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  justify-self: end;
  cursor: pointer;
  user-select: none;
}

.brand-name {
  display: block;
  color: #fff;
  font-size: clamp(14px, 3.8vw, 18px);
  font-weight: 900;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.brand-logo {
  display: block;
  width: clamp(74px, 18vw, 98px);
  max-width: 100%;
  height: auto;
  max-height: 25px;
  object-fit: contain;
}

.sound-icon {
  width: 28px;
  height: 28px;
  object-fit: contain;
  display: block;
}

/* ── Leaderboard — submit modal & panel ──────────────────────────────────────
   Both live outside .phone so they use position:fixed and sit above everything.
   z-index 200 clears the .phone z-index (40) and battle overlays.
   ──────────────────────────────────────────────────────────────────────────── */

.ldb-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(14, 31, 58, 0.46);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  overflow-y: auto;
  animation: ldb-fade-in 0.18s ease;
}

@keyframes ldb-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Submit modal ─────────────────────────────────────────────────────────── */

.ldb-modal-panel {
  width: min(calc(100vw - 32px), 340px);
  max-width: 100%;
  padding: 24px 22px 20px;
  border-radius: 22px;
  background: var(--clr-tile);
  border: 1px solid rgba(139, 90, 43, 0.18);
  box-shadow: 0 16px 48px rgba(14, 31, 58, 0.22);
  animation: ldb-slide-up 0.22s ease;
}

@keyframes ldb-slide-up {
  from { transform: translateY(18px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.ldb-modal-eyebrow {
  margin: 0 0 4px;
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--clr-orange);
  text-align: center;
}

.ldb-modal-score {
  margin: 0 0 18px;
  font-family: var(--font-heading);
  font-size: 30px;
  font-weight: 900;
  color: var(--clr-navy);
  text-align: center;
  line-height: 1;
}

.ldb-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 14px;
}

.ldb-label {
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 700;
  color: var(--clr-brown);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ldb-input,
.ldb-select {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1.5px solid rgba(14, 31, 58, 0.18);
  background: #fff;
  color: var(--clr-navy);
  font-family: var(--font-main);
  font-size: 16px;
  font-weight: 600;
  appearance: auto;
  box-shadow: var(--soft-shadow);
  box-sizing: border-box;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ldb-input:focus,
.ldb-select:focus {
  outline: none;
  border-color: var(--clr-orange);
  box-shadow: 0 0 0 3px rgba(240, 138, 26, 0.22);
}

/* Larger tap-target for the select on mobile */
.ldb-select {
  padding-right: 32px;
  cursor: pointer;
}

.ldb-field-err {
  margin: 0;
  min-height: 1em;
  font-family: var(--font-main);
  font-size: 12px;
  font-weight: 700;
  color: #c0266f;
}

.ldb-form-err {
  margin-bottom: 8px;
}

.ldb-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

/* ── Leaderboard panel ────────────────────────────────────────────────────── */

.ldb-panel-inner {
  width: min(calc(100vw - 32px), 480px);
  max-width: 100%;
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  border-radius: 22px;
  background: var(--clr-tile);
  border: 1px solid rgba(139, 90, 43, 0.18);
  box-shadow: 0 16px 48px rgba(14, 31, 58, 0.22);
  overflow: hidden;
  animation: ldb-slide-up 0.22s ease;
}

.ldb-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 12px;
  border-bottom: 1px solid rgba(139, 90, 43, 0.12);
  flex-shrink: 0;
}

.ldb-panel-title {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 22px;
  font-weight: 900;
  color: var(--clr-navy);
  display: flex;
  align-items: center;
  gap: 8px;
}

.ldb-title-logo {
  height: 26px;
  width: auto;
  display: inline-block;
  vertical-align: middle;
}

.ldb-close-btn {
  appearance: none;
  border: none;
  background: var(--clr-card);
  color: var(--clr-navy);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s ease;
  flex-shrink: 0;
}

.ldb-close-btn:hover   { background: var(--clr-card-warm); }
.ldb-close-btn:focus   { outline: 2px solid var(--clr-orange); outline-offset: 2px; }
.ldb-close-btn:active  { transform: scale(0.94); }

/* Filter tabs — hidden for now; remove display:none to re-enable Global/Week/Day switching */

.ldb-tabs {
  display: none; /* TODO: set to flex to restore tab switching */
  gap: 6px;
  padding: 12px 20px 8px;
  flex-shrink: 0;
}

.ldb-tab {
  appearance: none;
  border: 1.5px solid rgba(14, 31, 58, 0.14);
  background: var(--clr-card);
  color: var(--muted);
  border-radius: 20px;
  padding: 5px 14px;
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.ldb-tab:hover { background: var(--clr-card-warm); }

.ldb-tab.is-active {
  background: var(--clr-navy);
  color: var(--clr-warm-yellow);
  border-color: var(--clr-navy);
}

/* Entries area */

.ldb-entries {
  overflow-y: auto;
  flex: 1;
  padding: 4px 0 12px;
  -webkit-overflow-scrolling: touch;
}

.ldb-status {
  padding: 24px 20px;
  text-align: center;
  color: var(--muted);
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 600;
  margin: 0;
}

.ldb-status--error { color: #c0266f; }

/* Table */

.ldb-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-main);
  font-size: 13px;
}

.ldb-table thead th {
  padding: 6px 10px 6px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--clr-brown);
  text-align: left;
  white-space: nowrap;
  border-bottom: 1.5px solid rgba(139, 90, 43, 0.12);
}

.ldb-th-rank { width: 36px; text-align: center; }

.ldb-table tbody tr {
  border-bottom: 1px solid rgba(14, 31, 58, 0.06);
  transition: background 0.1s ease;
}

.ldb-table tbody tr:last-child { border-bottom: none; }
.ldb-table tbody tr:hover { background: rgba(139, 90, 43, 0.05); }

.ldb-table td {
  padding: 9px 10px;
  vertical-align: middle;
  color: var(--clr-navy);
  font-weight: 600;
}

.ldb-cell-rank {
  text-align: center;
  font-weight: 800;
  font-size: 12px;
  color: var(--muted);
  width: 36px;
}

.ldb-cell-name  { font-weight: 700; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ldb-cell-score { font-weight: 800; font-size: 14px; white-space: nowrap; }
.ldb-cell-loc   { color: var(--muted); font-size: 12px; max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ldb-cell-num   { text-align: center; color: var(--muted); font-size: 12px; }
/* TODO: remove display:none on both rules below to restore the date column */
.ldb-cell-date  { display: none; color: var(--muted); font-size: 11px; white-space: nowrap; }
.ldb-table thead th:last-child { display: none; }

/* Top-3 row highlights */

.ldb-row--top1 .ldb-cell-rank { color: #b8860b; font-size: 15px; }
.ldb-row--top2 .ldb-cell-rank { color: #7a8a99; font-size: 14px; }
.ldb-row--top3 .ldb-cell-rank { color: #8b5a2b; font-size: 13px; }

.ldb-row--top1 { background: rgba(248, 212, 80, 0.12); }
.ldb-row--top2 { background: rgba(180, 195, 210, 0.10); }
.ldb-row--top3 { background: rgba(200, 160, 100, 0.08); }

/* Responsive: hide less-important columns on very small screens */
@media (max-width: 360px) {
  .ldb-cell-num,
  .ldb-cell-date { display: none; }
  .ldb-table thead th:nth-child(5),
  .ldb-table thead th:nth-child(6),
  .ldb-table thead th:nth-child(7) { display: none; }
}
