/* ===== FactFall — Candy Pop visual system (build 8) =========================
   Bright candy gradient world, fat rounded type (Fredoka display + Nunito body),
   glossy 3D candy buttons, cream fact cards with dark readable text, heavy juice.
   All structural selectors/layout preserved from the prior build so the game's
   JS class toggles (.is-enter/.is-correct/.is-pulse/.is-armed/data-mode/...) keep
   working. ========================================================= */

@font-face { font-family: 'Fredoka'; font-style: normal; font-weight: 500; font-display: swap; src: url('./assets/fonts/fredoka-500.woff2') format('woff2'); }
@font-face { font-family: 'Fredoka'; font-style: normal; font-weight: 600; font-display: swap; src: url('./assets/fonts/fredoka-600.woff2') format('woff2'); }
@font-face { font-family: 'Fredoka'; font-style: normal; font-weight: 700; font-display: swap; src: url('./assets/fonts/fredoka-700.woff2') format('woff2'); }
@font-face { font-family: 'Nunito'; font-style: normal; font-weight: 400; font-display: swap; src: url('./assets/fonts/nunito-400.woff2') format('woff2'); }
@font-face { font-family: 'Nunito'; font-style: normal; font-weight: 700; font-display: swap; src: url('./assets/fonts/nunito-700.woff2') format('woff2'); }
@font-face { font-family: 'Nunito'; font-style: normal; font-weight: 800; font-display: swap; src: url('./assets/fonts/nunito-800.woff2') format('woff2'); }

:root {
  color-scheme: light;
  /* candy palette */
  --grape: #7B5BE8;
  --grape-deep: #5b3fd0;
  --pink: #ff4d8d;
  --pink-deep: #e5377a;
  --tangerine: #ff8a3d;
  --tangerine-deep: #f76d2c;
  --yellow: #ffc93c;
  --green: #2fd08a;
  --green-deep: #14b274;
  --green-lite: #b7ffe0;
  --rose: #ff5e7e;
  --rose-deep: #ea3f63;
  --rose-lite: #ffd0da;
  --violet: #8b5cf6;
  /* surfaces + text */
  --card: #fffdf8;
  --ink: #2c1a55;          /* dark text on light surfaces */
  --ink-soft: #7c6aa8;     /* muted dark text */
  --text: #ffffff;         /* text directly on the candy gradient */
  --muted: rgba(255, 255, 255, 0.9);
  --line: rgba(255, 255, 255, 0.6);
  --line-ink: rgba(44, 26, 85, 0.12);
  --shadow: rgba(78, 22, 92, 0.26);
  --shadow-strong: rgba(60, 14, 74, 0.4);
  /* frosted white glass panel */
  --glass: linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(255, 255, 255, 0.78));
  --glass-soft: linear-gradient(180deg, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0.2));
  font-family: Nunito, ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: linear-gradient(165deg, #7b5be8 0%, #ff4d8d 54%, #ff8a3d 100%);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  font-weight: 700;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  -webkit-tap-highlight-color: transparent;
}

/* Bright candy-bokeh world: soft light + saturated orbs over a grape→pink→tangerine wash. */
.app-shell {
  height: 100dvh;
  overflow: hidden;
  width: 100%;
  background:
    radial-gradient(circle at 50% 5%, rgba(255, 255, 255, 0.2), transparent 32%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(60, 14, 74, 0.12)),
    url("game/art/candy-bg.png") center top / cover no-repeat,
    linear-gradient(165deg, #7b5be8 0%, #ff4d8d 54%, #ff8a3d 100%);
  background-attachment: fixed;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
}

.screen {
  display: none;
  width: min(100%, 520px);
  height: calc(100dvh - max(14px, env(safe-area-inset-top)) - max(14px, env(safe-area-inset-bottom)));
  margin: 0 auto;
  overflow: hidden;
}

.screen.is-active {
  display: flex;
  flex-direction: column;
}

#screen-game {
  min-height: 0;
  height: calc(100dvh - max(14px, env(safe-area-inset-top)) - max(14px, env(safe-area-inset-bottom)));
  position: relative;
  isolation: isolate;
}

#screen-game::before {
  content: "";
  position: absolute;
  inset: -14px;
  z-index: -2;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(60, 14, 74, 0.18)),
    url("game/art/candy-bg.png") center center / cover no-repeat,
    linear-gradient(170deg, #7d5ee9 0%, #ff4d8d 56%, #ff8a3d 100%);
}

#screen-game::after {
  content: "";
  position: absolute;
  inset: -14px;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 16%, rgba(255, 255, 255, 0.22), transparent 30%),
    linear-gradient(180deg, transparent 40%, rgba(80, 20, 90, 0.16));
}

.topbar,
.game-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 60px;
}

.eyebrow,
.stat-label,
.hud-stat span,
.fact-category {
  margin: 0;
  color: var(--muted);
  font-family: Fredoka, Nunito, sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* labels that sit on a frosted-white panel switch to dark ink for crispness */
.stat-label,
.hud-stat span {
  color: var(--ink-soft);
}

.eyebrow {
  text-shadow: 0 2px 6px rgba(70, 14, 80, 0.3);
}

.fact-category {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 7px 13px;
  border-radius: 999px;
  color: var(--grape-deep);
  background: rgba(255, 255, 255, 0.92);
  border: 0;
  box-shadow: 0 6px 14px rgba(70, 16, 84, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.9);
  letter-spacing: 0.06em;
}

h1,
h2,
p { margin-top: 0; }

h1 {
  margin-bottom: 0;
  font-family: Fredoka, sans-serif;
  font-weight: 700;
  font-size: clamp(2.2rem, 12vw, 3.9rem);
  line-height: 0.92;
  letter-spacing: -0.01em;
  color: #fff;
  text-shadow:
    0 2px 0 #ffd9ec,
    0 5px 0 var(--grape-deep),
    0 6px 2px rgba(50, 10, 60, 0.2),
    0 14px 26px rgba(50, 10, 60, 0.42);
}

h2 {
  font-family: Fredoka, sans-serif;
  font-weight: 700;
  line-height: 1.02;
  letter-spacing: -0.01em;
}

.icon-button {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  border: 0;
  border-radius: 15px;
  background: var(--glass);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    inset 0 -3px 0 rgba(120, 60, 140, 0.12),
    0 10px 20px rgba(70, 16, 84, 0.22);
  color: var(--grape-deep);
  display: grid;
  place-items: center;
}

/* Three-way audio control (home topbar + pause overlay). */
.audio-button {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px 0 12px;
  border: 0;
  border-radius: 15px;
  background: var(--glass);
  color: var(--ink);
  font-family: Fredoka, sans-serif;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    inset 0 -3px 0 rgba(120, 60, 140, 0.12),
    0 10px 20px rgba(70, 16, 84, 0.2);
}

.audio-button .audio-label {
  font-size: 0.82rem;
  white-space: nowrap;
}

/* 'all' = music + SFX: green accent. */
.audio-button[data-mode="all"] {
  background: linear-gradient(180deg, #eafff6, #c4f7e2);
}
.audio-button[data-mode="all"] .audio-label { color: var(--green-deep); }

/* 'sfx' = SFX only: amber accent. */
.audio-button[data-mode="sfx"] {
  background: linear-gradient(180deg, #fff6e0, #ffe9b8);
}
.audio-button[data-mode="sfx"] .audio-label { color: #c9871a; }
.audio-button[data-mode="sfx"] .sound-glyph::after { opacity: 0.25; }

/* 'off' = silent. */
.audio-button[data-mode="off"] { background: var(--glass); }
.audio-button[data-mode="off"] .audio-label { color: var(--ink-soft); }

.sound-glyph,
.x-glyph,
.home-glyph {
  width: 22px;
  height: 22px;
  position: relative;
  display: block;
}

.sound-glyph::before {
  content: "";
  position: absolute;
  left: 1px;
  top: 6px;
  width: 8px;
  height: 10px;
  background: var(--ink);
  clip-path: polygon(0 28%, 45% 28%, 100% 0, 100% 100%, 45% 72%, 0 72%);
}

.sound-glyph::after {
  content: "";
  position: absolute;
  right: 1px;
  top: 4px;
  width: 10px;
  height: 14px;
  border: 3px solid var(--ink);
  border-left: 0;
  border-radius: 0 14px 14px 0;
}

.is-muted .sound-glyph::after {
  transform: rotate(-36deg);
  right: 4px;
  top: 1px;
  width: 3px;
  height: 22px;
  border: 0;
  background: var(--rose);
  border-radius: 2px;
}

.x-glyph::before,
.x-glyph::after {
  content: "";
  position: absolute;
  top: 10px;
  left: 2px;
  width: 19px;
  height: 3px;
  border-radius: 2px;
  background: var(--grape-deep);
}

.x-glyph::before { transform: rotate(45deg); }
.x-glyph::after { transform: rotate(-45deg); }

.home-glyph::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 9px;
  width: 18px;
  height: 12px;
  border-radius: 3px 3px 5px 5px;
  background: var(--grape-deep);
}

.home-glyph::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 14px;
  height: 14px;
  background: var(--grape-deep);
  transform: rotate(45deg);
  border-radius: 3px;
}

/* Pause glyph: two vertical bars. */
.pause-glyph {
  width: 18px;
  height: 18px;
  position: relative;
  display: block;
}

.pause-glyph::before,
.pause-glyph::after {
  content: "";
  position: absolute;
  top: 1px;
  width: 5px;
  height: 16px;
  border-radius: 2px;
  background: var(--grape-deep);
}

.pause-glyph::before { left: 3px; }
.pause-glyph::after { right: 3px; }

.hud-pause {
  width: 44px;
  height: 52px;
  flex: 0 0 44px;
  border-radius: 14px;
}

/* Home hero: big frosted-white candy card. */
.hero-panel {
  margin-top: 8px;
  flex: 1 1 auto;
  min-height: 120px;
  padding: 20px;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 12px;
  overflow: hidden;
  border: 0;
  border-radius: 26px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(255, 255, 255, 0.82));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.95),
    inset 0 -6px 0 rgba(120, 60, 140, 0.08),
    0 26px 46px rgba(70, 16, 84, 0.28);
}

.hero-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 84% 12%, rgba(255, 201, 60, 0.36), transparent 26%),
    radial-gradient(circle at 14% 16%, rgba(255, 77, 141, 0.28), transparent 26%),
    radial-gradient(circle at 92% 92%, rgba(139, 92, 246, 0.24), transparent 30%);
}

.hero-panel > * { position: relative; z-index: 1; }

.hero-panel h2 {
  max-width: 11ch;
  margin-bottom: 0;
  font-size: clamp(2.4rem, 12.5vw, 3.9rem);
  line-height: 0.96;
  color: var(--ink);
  text-shadow: none;
}

.hero-panel p {
  max-width: 31ch;
  margin: 0;
  color: var(--ink-soft);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.35;
}

.fall-demo {
  height: 116px;
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(123, 91, 232, 0.1), rgba(255, 138, 61, 0.08));
  opacity: 1;
}

.demo-chip {
  position: absolute;
  left: var(--x);
  top: var(--y);
  min-width: 88px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.7),
    inset 0 -4px 0 rgba(0, 0, 0, 0.14),
    0 12px 20px rgba(70, 16, 84, 0.26);
  color: #fff;
  font-family: Fredoka, sans-serif;
  font-size: 0.84rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transform: rotate(var(--r, -5deg));
  animation: chip-bob 3200ms ease-in-out infinite;
}

.chip-a { --x: 6%; --y: 12px; --r: -7deg; background: linear-gradient(180deg, #4fe0a8, var(--green) 55%, var(--green-deep)); animation-delay: 0ms; }
.chip-b { --x: 40%; --y: 40px; --r: 5deg; background: linear-gradient(180deg, #ff86a4, var(--rose) 55%, var(--rose-deep)); animation-delay: 420ms; }
.chip-c { --x: 58%; --y: 66px; --r: -2deg; background: linear-gradient(180deg, #ffd96a, var(--yellow) 55%, #f0a91f); color: #5b3d05; text-shadow: none; animation-delay: 840ms; }

@keyframes chip-bob {
  0%, 100% { transform: rotate(var(--r, -5deg)) translateY(0); }
  50% { transform: rotate(var(--r, -5deg)) translateY(-7px); }
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 18px;
}

.stats-grid > div,
.daily-panel,
.result-summary,
.hud-stat {
  border: 0;
  background: var(--glass);
  border-radius: 16px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    inset 0 -3px 0 rgba(120, 60, 140, 0.1),
    0 12px 24px rgba(70, 16, 84, 0.2);
}

.stats-grid > div {
  min-height: 72px;
  padding: 12px;
  position: relative;
  overflow: hidden;
}

.stats-grid > div::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 0;
  height: 3px;
  border-radius: 3px;
  background: linear-gradient(90deg, transparent, rgba(255, 77, 141, 0.6), rgba(255, 138, 61, 0.6), transparent);
  opacity: 0.7;
}

.stats-grid strong {
  display: block;
  margin-top: 6px;
  font-family: Fredoka, sans-serif;
  font-weight: 700;
  font-size: 1.6rem;
  color: var(--grape-deep);
}

.daily-panel {
  min-height: 68px;
  margin-top: 10px;
  padding: 13px 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background:
    linear-gradient(135deg, #ffd96a, #ff9a52 52%, #ff5e9a);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.6),
    inset 0 -4px 0 rgba(150, 40, 70, 0.2),
    0 16px 30px rgba(70, 16, 84, 0.26);
}

.daily-panel strong {
  display: block;
  margin-top: 4px;
  font-family: Fredoka, sans-serif;
  font-weight: 700;
  font-size: 1.16rem;
  color: #fff;
  text-shadow: 0 1px 3px rgba(120, 30, 60, 0.3);
}

.daily-panel .eyebrow,
.daily-panel .stat-label { color: rgba(255, 255, 255, 0.92); }

.daily-meta {
  display: grid;
  gap: 3px;
  justify-items: end;
  min-width: max-content;
}

.daily-panel p {
  margin: 0;
  color: #fff;
  font-size: 0.94rem;
  font-weight: 800;
  text-align: right;
  text-shadow: 0 1px 3px rgba(120, 30, 60, 0.3);
}

.daily-panel #library-count {
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.78rem;
  font-weight: 700;
}

.home-actions,
.result-actions {
  display: grid;
  gap: 10px;
  padding-top: 14px;
}

.home-actions {
  grid-template-columns: minmax(0, 1.12fr) minmax(0, 0.88fr);
}

.daily-action { grid-column: 1 / -1; }

.primary-button,
.secondary-button,
.answer-button {
  min-height: 58px;
  border-radius: 18px;
  font-family: Fredoka, sans-serif;
  font-weight: 700;
  letter-spacing: 0.01em;
  transition: transform 90ms cubic-bezier(0.2, 0.8, 0.3, 1.3), filter 120ms ease, box-shadow 120ms ease;
}

/* Primary = candy green pill with a thick 3D bevel. */
.primary-button {
  color: #06381f;
  background: linear-gradient(180deg, #8dffcf, var(--green) 52%, var(--green-deep));
  border: 0;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.7),
    inset 0 -6px 0 rgba(8, 110, 70, 0.55),
    0 14px 24px rgba(20, 150, 100, 0.36);
}

.secondary-button {
  color: var(--grape-deep);
  background: var(--glass);
  border: 0;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.95),
    inset 0 -5px 0 rgba(120, 60, 140, 0.16),
    0 12px 22px rgba(70, 16, 84, 0.2);
}

/* Share = candy pink; practice = candy tangerine. */
.home-actions .secondary-button:nth-child(3),
#btn-share {
  color: #fff;
  background: linear-gradient(180deg, #ff86a4, var(--rose) 52%, var(--rose-deep));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.5),
    inset 0 -6px 0 rgba(150, 30, 60, 0.45),
    0 14px 24px rgba(234, 63, 99, 0.3);
}

#btn-practice {
  color: #fff;
  background: linear-gradient(180deg, #ffb072, var(--tangerine) 52%, var(--tangerine-deep));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.5),
    inset 0 -6px 0 rgba(170, 70, 20, 0.45),
    0 14px 24px rgba(247, 109, 44, 0.3);
}

/* Press = squash down into the bevel. */
.primary-button:active,
.secondary-button:active,
.answer-button:active {
  transform: translateY(4px) scale(0.97);
  filter: saturate(1.06) brightness(1.03);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.5),
    inset 0 -2px 0 rgba(0, 0, 0, 0.18),
    0 6px 12px rgba(70, 16, 84, 0.2);
}

.game-hud { min-height: 58px; gap: 7px; }

.hud-stat {
  min-width: 0;
  flex: 1 1 0;
  height: 52px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 7px 10px;
  overflow: hidden;
}

.hud-stat strong {
  line-height: 1;
  font-family: Fredoka, sans-serif;
  font-weight: 700;
  font-size: 1.3rem;
  color: var(--grape-deep);
  transition: color 140ms ease, transform 140ms ease;
}

/* Score / streak pop when they change. */
.hud-stat strong.is-pulse {
  animation: hud-pulse 360ms cubic-bezier(0.2, 0.8, 0.3, 1.5) both;
}

@keyframes hud-pulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.32); color: var(--pink); }
  100% { transform: scale(1); }
}

#speed {
  color: var(--tangerine-deep);
}

.shield-pip {
  width: 40px;
  height: 52px;
  flex: 0 0 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.55);
  opacity: 0.6;
  transition: opacity 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.shield-glyph {
  width: 20px;
  height: 22px;
  background: var(--ink-soft);
  clip-path: polygon(50% 0%, 100% 16%, 100% 58%, 50% 100%, 0% 58%, 0% 16%);
  transition: background 180ms ease;
}

.shield-pip.is-armed {
  opacity: 1;
  background: linear-gradient(180deg, #eafff6, #c4f7e2);
  box-shadow: 0 0 16px rgba(47, 208, 138, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.9);
  animation: shield-armed 1600ms ease-in-out infinite;
}

.shield-pip.is-armed .shield-glyph { background: var(--green-deep); }

@keyframes shield-armed {
  0%, 100% { box-shadow: 0 0 12px rgba(47, 208, 138, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.9); }
  50% { box-shadow: 0 0 22px rgba(47, 208, 138, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.9); }
}

/* The lane the cards fall through: a soft frosted-white candy tube. */
.fall-lane {
  flex: 1 1 0;
  min-height: 0;
  margin: 10px 0;
  position: relative;
  overflow: hidden;
  border: 0;
  border-radius: 26px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.22) 30%, rgba(255, 255, 255, 0.12)),
    repeating-linear-gradient(180deg, transparent 0 64px, rgba(255, 255, 255, 0.18) 64px 65px);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.7),
    inset 0 -16px 36px rgba(80, 20, 90, 0.16),
    0 18px 34px rgba(70, 16, 84, 0.22);
}

.fall-lane::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 26px;
  background:
    radial-gradient(circle at 18% 6%, rgba(255, 201, 60, 0.22), transparent 26%),
    radial-gradient(circle at 86% 94%, rgba(255, 94, 126, 0.2), transparent 28%);
}

.danger-line {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 22px;
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(90deg, transparent, var(--rose) 20%, var(--tangerine) 80%, transparent);
  box-shadow: 0 0 16px rgba(255, 94, 126, 0.7), 0 0 30px rgba(255, 138, 61, 0.3);
}

.danger-line::after {
  content: "danger";
  position: absolute;
  left: 50%;
  top: 9px;
  transform: translateX(-50%);
  color: #fff;
  font-family: Fredoka, sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-shadow: 0 1px 6px rgba(234, 63, 99, 0.9);
}

@property --card-scale {
  syntax: "<number>";
  inherits: false;
  initial-value: 1;
}

/* The fact card: a glossy cream candy card with dark, highly readable text. */
.fact-card {
  position: absolute;
  left: 14px;
  right: 14px;
  top: 18px;
  min-height: 172px;
  padding: 20px;
  border-radius: 24px;
  background:
    linear-gradient(180deg, #ffffff, #fff4fb 58%, #ffe9f3);
  border: 0;
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.95),
    inset 0 -7px 0 rgba(120, 60, 140, 0.12),
    0 26px 44px rgba(70, 16, 84, 0.32);
  color: var(--ink);
  transform: translateY(var(--fall-y, 0)) scale(var(--card-scale, 1));
  transform-origin: 50% 50%;
  will-change: transform, box-shadow;
  --card-scale: 1;
}

.fact-card::before {
  content: "";
  position: absolute;
  inset: 2px;
  pointer-events: none;
  border-radius: 22px;
  background: linear-gradient(125deg, rgba(255, 255, 255, 0.85), transparent 30%);
  opacity: 0.8;
}

.fact-card > * { position: relative; z-index: 1; }

/* Juicy entrance: card bounces + fades in at the top of the lane. */
.fact-card.is-enter {
  animation: card-enter 360ms cubic-bezier(0.2, 0.9, 0.25, 1.4) both;
}

@keyframes card-enter {
  0% { --card-scale: 0.62; opacity: 0; }
  55% { --card-scale: 1.09; opacity: 1; }
  76% { --card-scale: 0.97; }
  100% { --card-scale: 1; opacity: 1; }
}

/* Correct: a bright green-lit pop. */
.fact-card.is-correct {
  box-shadow: 0 22px 38px rgba(20, 150, 100, 0.3), 0 0 0 3px rgba(47, 208, 138, 0.7), 0 0 30px rgba(47, 208, 138, 0.5);
  animation: card-correct 280ms cubic-bezier(0.2, 0.8, 0.3, 1.4) both;
}

@keyframes card-correct {
  0% { --card-scale: 1; }
  45% { --card-scale: 1.07; }
  100% { --card-scale: 1; }
}

/* Wrong: a rose shudder. */
.fact-card.is-wrong {
  box-shadow: 0 22px 38px rgba(150, 30, 60, 0.3), 0 0 0 3px rgba(255, 94, 126, 0.8), 0 0 30px rgba(255, 94, 126, 0.5);
  animation: card-wrong 360ms ease-out both;
}

@keyframes card-wrong {
  0%, 100% { --card-scale: 1; transform: translateY(var(--fall-y, 0)) scale(1) translateX(0); }
  15% { transform: translateY(var(--fall-y, 0)) scale(0.98) translateX(-7px); }
  45% { transform: translateY(var(--fall-y, 0)) scale(1.01) translateX(6px); }
  75% { transform: translateY(var(--fall-y, 0)) scale(1) translateX(-3px); }
}

/* Danger: card flushes rose as it nears the floor. */
.fact-card.is-danger {
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.9),
    0 22px 36px rgba(70, 16, 84, 0.3),
    0 0 26px rgba(255, 94, 126, 0.5);
}

.fact-card h2 {
  margin: 12px 0 0;
  font-family: Nunito, sans-serif;
  font-weight: 800;
  font-size: clamp(1.56rem, 7vw, 2.4rem);
  line-height: 1.1;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-shadow: none;
}

.feedback {
  min-height: 28px;
  color: #fff;
  text-align: center;
  font-family: Fredoka, sans-serif;
  font-size: 0.96rem;
  font-weight: 600;
  text-shadow: 0 2px 8px rgba(70, 14, 80, 0.4);
}

.feedback.is-good { color: var(--green-lite); }
.feedback.is-bad { color: var(--rose-lite); }

.answer-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  flex: 0 0 auto;
  padding-bottom: 8px;
}

/* Big chunky 3D candy answer buttons. */
.answer-button {
  min-height: 66px;
  color: #fff;
  border: 0;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 1.18rem;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.18);
}

.false-button {
  background: linear-gradient(180deg, #ff8aa6, var(--rose) 52%, var(--rose-deep));
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.55),
    inset 0 -7px 0 rgba(150, 30, 60, 0.5),
    0 16px 26px rgba(234, 63, 99, 0.32);
}

.true-button {
  background: linear-gradient(180deg, #7dffc4, var(--green) 52%, var(--green-deep));
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.6),
    inset 0 -7px 0 rgba(8, 110, 70, 0.5),
    0 16px 26px rgba(20, 150, 100, 0.32);
}

.result-summary {
  padding: 18px;
  margin: 14px 0 18px;
}

.result-summary p {
  color: var(--ink-soft);
  font-weight: 700;
  line-height: 1.35;
}

#result-score {
  font-family: Fredoka, sans-serif;
  font-weight: 700;
  color: var(--grape-deep);
  transition: color 200ms ease;
}

#result-label.is-new-best {
  color: var(--pink-deep);
}

#result-label.is-new-best + h1,
.is-new-best ~ h1 { color: var(--pink-deep); }

.topbar:has(#result-label.is-new-best) #result-score {
  color: var(--pink-deep);
  text-shadow: 0 0 22px rgba(229, 55, 122, 0.4);
  animation: result-best-pop 660ms cubic-bezier(0.2, 0.8, 0.3, 1.5) both;
}

@keyframes result-best-pop {
  0% { transform: scale(0.82); }
  55% { transform: scale(1.16); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .topbar:has(#result-label.is-new-best) #result-score { animation: none; }
}

.meter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 46px;
  border-top: 1px solid var(--line-ink);
}

.meter-row span {
  color: var(--ink-soft);
  font-weight: 800;
}

.is-disabled,
button:disabled { opacity: 0.5; }

@media (max-height: 640px) {
  .app-shell { padding-left: 10px; padding-right: 10px; }
  .hero-panel { min-height: 0; height: 244px; padding: 14px; gap: 8px; }
  .fall-demo { height: 72px; }
  .demo-chip { min-width: 78px; height: 34px; font-size: 0.74rem; }
  .hero-panel h2 { font-size: clamp(1.9rem, 9.4vw, 2.5rem); }
  .hero-panel p { font-size: 0.86rem; }
  .stats-grid > div { min-height: 62px; padding: 9px; }
  .daily-panel { min-height: 58px; padding: 10px 12px; }
  .fall-lane { min-height: 286px; margin: 6px 0; }
  .fact-card { min-height: 132px; padding: 14px; }
  .hud-stat { height: 48px; padding: 6px 7px; }
  .hud-stat strong { font-size: 1.12rem; }
  .shield-pip { width: 34px; height: 48px; flex-basis: 34px; }
  .shield-glyph { width: 17px; height: 19px; }
  .primary-button, .secondary-button, .answer-button { min-height: 52px; }
}

@media (max-width: 340px) {
  .home-actions { grid-template-columns: 1fr 1fr; }
  .home-actions .primary-button,
  .home-actions .secondary-button { font-size: 0.9rem; }
}

/* Feedback line gets a tiny pop each time its text changes. */
.feedback.is-good,
.feedback.is-bad {
  animation: feedback-pop 260ms cubic-bezier(0.2, 0.8, 0.3, 1.4);
}

@keyframes feedback-pop {
  0% { transform: translateY(4px) scale(0.92); opacity: 0.3; }
  60% { transform: translateY(0) scale(1.06); opacity: 1; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

/* Living danger line. */
.danger-line { animation: danger-breathe 2000ms ease-in-out infinite; }

@keyframes danger-breathe {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* --- Pause overlay ------------------------------------------------------- */
.pause-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
  background: rgba(80, 24, 96, 0.5);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  align-items: center;
  justify-content: center;
}

.pause-overlay.is-open {
  display: flex;
  animation: pause-fade 180ms ease-out both;
}

@keyframes pause-fade {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

.pause-card {
  width: min(100%, 420px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 24px;
  border: 0;
  border-radius: 24px;
  background: linear-gradient(180deg, #ffffff, #fff2f9);
  box-shadow: 0 30px 54px rgba(40, 10, 50, 0.5), inset 0 2px 0 rgba(255, 255, 255, 0.9);
  text-align: center;
  animation: pause-pop 260ms cubic-bezier(0.2, 0.8, 0.3, 1.4) both;
}

@keyframes pause-pop {
  0% { transform: scale(0.86); opacity: 0; }
  60% { transform: scale(1.03); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.pause-title {
  margin: 0;
  font-family: Fredoka, sans-serif;
  font-weight: 700;
  font-size: clamp(2.1rem, 11vw, 2.9rem);
  line-height: 1;
  color: var(--grape-deep);
  text-shadow: none;
}

.pause-sub {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.96rem;
  font-weight: 700;
  line-height: 1.35;
}

.pause-audio {
  align-self: center;
  margin-top: 4px;
  min-height: 52px;
}

.pause-actions {
  display: grid;
  gap: 10px;
  margin-top: 6px;
}

/* Respect reduced-motion: kill the juice, keep the game fully playable. */
@media (prefers-reduced-motion: reduce) {
  .fact-card.is-enter,
  .fact-card.is-correct,
  .fact-card.is-wrong,
  .hud-stat strong.is-pulse,
  .shield-pip.is-armed,
  .feedback.is-good,
  .feedback.is-bad,
  .pause-overlay.is-open,
  .pause-card,
  .demo-chip,
  .danger-line {
    animation: none !important;
  }
  .fact-card { --card-scale: 1; }
  .primary-button:active,
  .secondary-button:active,
  .answer-button:active { transform: none; }
}

/* Extra-narrow phones: keep the HUD row from overflowing on iPhone SE. */
@media (max-width: 360px) {
  .game-hud { gap: 5px; }
  .hud-stat { padding: 6px 6px; }
  .hud-stat span { font-size: 0.6rem; }
  .shield-pip { width: 32px; flex-basis: 32px; }
  .hud-pause { width: 40px; flex-basis: 40px; }
  .audio-button { padding: 0 10px; gap: 6px; }
  .audio-button .audio-label { font-size: 0.74rem; }
}

@media (max-height: 640px) {
  .hud-pause { height: 48px; }
}

/* ===== Today I Learned reveal (results screen) ===== */
.til { margin: 4px 18px 2px; }
.til[hidden] { display: none; }
.til-kicker {
  text-align: center;
  font-family: 'Fredoka', system-ui, sans-serif;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--grape, #7B5BE8);
  font-size: 0.86rem;
  text-transform: uppercase;
  margin: 2px 0 10px;
}
.til-kicker::before { content: '✨ '; }
.til-cards { display: flex; flex-direction: column; gap: 10px; flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.til-card {
  background: var(--card, #fffdf8);
  border-radius: 20px;
  padding: 13px 15px;
  box-shadow: 0 10px 26px rgba(44, 26, 85, 0.20);
  border: 2px solid rgba(123, 91, 232, 0.14);
  opacity: 0;
  transform: translateY(16px) scale(0.95);
}
.til.is-revealing .til-card {
  animation: tilPop 0.52s cubic-bezier(0.2, 1.3, 0.5, 1) forwards;
  animation-delay: calc(var(--til-i, 0) * 0.12s);
}
@keyframes tilPop { to { opacity: 1; transform: translateY(0) scale(1); } }
.til-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 5px; }
.til-cat {
  font-size: 0.66rem;
  font-weight: 800;
  color: var(--ink-soft, #7c6aa8);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.til-verdict {
  font-family: 'Fredoka', system-ui, sans-serif;
  font-weight: 800;
  font-size: 0.74rem;
  color: #fff;
  padding: 3px 13px;
  border-radius: 999px;
  letter-spacing: 0.04em;
}
.til-true .til-verdict { background: var(--green, #2fd08a); }
.til-false .til-verdict { background: var(--rose, #ff5e7e); }
.til-fact {
  font-family: 'Nunito', system-ui, sans-serif;
  font-weight: 800;
  color: var(--ink, #2c1a55);
  font-size: 1rem;
  line-height: 1.26;
  margin: 0 0 6px;
}
.til-why {
  font-family: 'Nunito', system-ui, sans-serif;
  font-weight: 600;
  color: var(--ink-soft, #7c6aa8);
  font-size: 0.88rem;
  line-height: 1.36;
  margin: 0;
}
.til-share-btn { margin-top: 10px; width: 100%; }

/* Keep the results screen one locked page: TIL absorbs slack, actions pinned to the bottom. */
#screen-results .til { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
#screen-results .til[hidden] { display: none; } /* must out-specify the rule above so the TIL truly hides on exit/no-miss */
#screen-results .result-actions { margin-top: auto; }
#screen-results .result-summary { margin: 12px 0 12px; }

.double-button {
  width: 100%;
  margin-top: 4px;
  padding: 12px;
  border-radius: 16px;
  font-family: 'Fredoka', system-ui, sans-serif;
  font-weight: 800;
  font-size: 0.98rem;
  color: #5b3d05;
  background: linear-gradient(180deg, #ffd96a, var(--yellow, #ffc93c) 60%, #f0a91f);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.7), inset 0 -4px 0 rgba(0, 0, 0, 0.12), 0 10px 22px rgba(240, 169, 31, 0.4);
}
.double-button[hidden] { display: none; }
.double-button:active { transform: translateY(2px); }

/* TIL carousel: when 2+ facts were learned (shield saves), swipe through them instead of stacking. */
.til-cards.is-carousel {
  flex-direction: row;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.til-cards.is-carousel::-webkit-scrollbar { display: none; }
.til-cards.is-carousel .til-card { flex: 0 0 100%; scroll-snap-align: center; overflow-y: auto; }
.til-dots { display: flex; justify-content: center; gap: 7px; margin-top: 9px; flex: 0 0 auto; }
.til-dots[hidden] { display: none; }
.til-dot { width: 8px; height: 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.55); transition: width 0.2s ease, background 0.2s ease; }
.til-dot.is-active { width: 22px; background: #fff; }
