@font-face {
  font-family: 'ABC Display';
  src: url('./fonts/LuckiestGuy-Regular.ttf') format('truetype');
  font-weight: 400;
  font-display: block;
}
@font-face {
  font-family: 'ABC Text';
  src: url('./fonts/Nunito-Regular.ttf') format('truetype');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'ABC Text';
  src: url('./fonts/Nunito-Bold.ttf') format('truetype');
  font-weight: 700;
  font-display: swap;
}

:root {
  --primary: #1B1E53;
  --accent: #D92027;
  --paper: #fdfcf8;
  --ink: #16183f;
  --muted: rgba(255, 255, 255, 0.72);

  /* One page = one viewport. Tools sit in the bottom safe area. */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tools-h: 84px;

  --dur-letter: 900ms;
  --dur-art: 750ms;
  --ease: cubic-bezier(0.22, 0.68, 0.24, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--primary);
  color: #fff;
  font-family: 'ABC Text', ui-rounded, -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: pan-y;
}

body { user-select: none; }

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

.track {
  display: flex;
  height: 100%;
  will-change: transform;
}

.track.animate { transition: transform 420ms var(--ease); }

.page {
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 16px) 20px calc(var(--safe-bottom) + var(--tools-h) + 8px);
  background: var(--primary);
  background-image:
    radial-gradient(120% 80% at 50% 0%, rgba(255, 255, 255, 0.1), transparent 60%),
    radial-gradient(90% 60% at 50% 100%, rgba(0, 0, 0, 0.25), transparent 70%);
}

.page-inner {
  width: 100%;
  max-width: 760px;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(14px, 3vh, 30px);
}

/* ---------- artwork ---------- */

.art {
  position: relative;
  width: min(100%, 62vh);
  aspect-ratio: 1 / 1;
  border-radius: 28px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  flex: 0 1 auto;
  min-height: 0;
}

.art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transform: scale(0.93);
}

.page.active .art img {
  animation: art-in var(--dur-art) var(--ease) 140ms forwards;
}

@keyframes art-in {
  to { opacity: 1; transform: scale(1); }
}

/* Shown when the art file does not exist yet. Generated per letter rather than
   a dashed "coming soon" box, because until the illustrations land this IS what
   a child sees on all 26 pages. Still marked, just not as a construction sign. */
.art.placeholder { background: none; }
.ac-svg { width: 100%; height: 100%; display: block; }

.ac-letter {
  font-family: 'ABC Display', system-ui, sans-serif;
  font-size: 62px;
  fill: #fff;
  paint-order: stroke;
  stroke: rgba(0, 0, 0, 0.16);
  stroke-width: 3px;
}

.ac-drift {
  animation: ac-float var(--dur, 12s) ease-in-out infinite alternate;
  transform-box: fill-box;
  transform-origin: center;
}
@keyframes ac-float {
  from { transform: translate(0, 0); }
  to { transform: translate(var(--dx, 4px), var(--dy, 4px)); }
}

.art.placeholder .ph-note {
  position: absolute;
  right: 10px;
  bottom: 8px;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.42);
  font-weight: 700;
}

/* ---------- words ---------- */

.words {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  flex: 0 0 auto;
}

.letterwrap {
  position: relative;
  line-height: 0.86;
  font-family: 'ABC Display', system-ui, sans-serif;
  font-size: clamp(64px, 13vh, 132px);
}

/* The letter "draws itself in": an outline is there first, then the solid
   fill wipes upward through it. */
.letter-outline,
.letter-fill {
  display: block;
  grid-area: 1 / 1;
}

.letterwrap { display: grid; }

.letter-outline {
  color: transparent;
  -webkit-text-stroke: 3px rgba(255, 255, 255, 0.55);
  opacity: 0;
}

/* The insets are negative on three sides because the glyph overflows its own
   box at this line-height — clipping at 0 would shave the top off the letter. */
.letter-fill {
  color: #fff;
  clip-path: inset(100% -30% -30% -30%);
}

.page.active .letter-outline { animation: outline-in 380ms var(--ease) forwards; }
.page.active .letter-fill { animation: fill-in var(--dur-letter) var(--ease) 260ms forwards; }

@keyframes outline-in {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes fill-in {
  from { clip-path: inset(100% -30% -30% -30%); }
  to { clip-path: inset(-30% -30% -30% -30%); }
}

.word {
  font-family: 'ABC Display', system-ui, sans-serif;
  font-size: clamp(30px, 5.4vh, 56px);
  color: var(--accent);
  letter-spacing: 0.01em;
  opacity: 0;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.2));
}

.line {
  margin: 2px 0 0;
  font-size: clamp(17px, 2.5vh, 25px);
  font-weight: 700;
  line-height: 1.42;
  max-width: 22ch;
  color: rgba(255, 255, 255, 0.94);
  opacity: 0;
  text-wrap: balance;
}

.page.active .word { animation: rise 520ms var(--ease) 620ms forwards; }
.page.active .line { animation: rise 520ms var(--ease) 780ms forwards; }

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- cover + end pages ---------- */

.page-cover .page-inner,
.page-end .page-inner { gap: 18px; }

.cover-mark {
  width: clamp(120px, 22vh, 200px);
  height: clamp(120px, 22vh, 200px);
  filter: drop-shadow(0 16px 30px rgba(0, 0, 0, 0.4));
  opacity: 0;
}
.cover-mark svg { width: 100%; height: 100%; display: block; }
.page.active .cover-mark { animation: rise 620ms var(--ease) forwards; }

.cover-title {
  font-family: 'ABC Display', system-ui, sans-serif;
  font-size: clamp(38px, 7.4vh, 78px);
  line-height: 1.02;
  margin: 0;
  text-wrap: balance;
  opacity: 0;
}
.page.active .cover-title { animation: rise 620ms var(--ease) 160ms forwards; }

/* Never below 19px: accent-on-navy is 3.08:1, which only clears AA as large
   bold text. Shrink this and the subtitle stops being readable. */
.cover-sub {
  font-size: clamp(19px, 2.4vh, 22px);
  font-weight: 700;
  color: var(--accent);
  margin: 0;
  max-width: 24ch;
  text-wrap: balance;
  opacity: 0;
}
.page.active .cover-sub { animation: rise 620ms var(--ease) 320ms forwards; }

.cover-author {
  font-size: clamp(14px, 2vh, 18px);
  color: var(--muted);
  margin: 0;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0;
}
.page.active .cover-author { animation: rise 620ms var(--ease) 460ms forwards; }

.cover-hint {
  margin-top: 10px;
  font-size: 15px;
  color: var(--muted);
  opacity: 0;
}
.page.active .cover-hint { animation: rise 620ms var(--ease) 640ms forwards; }

.page-end h2 {
  font-family: 'ABC Display', system-ui, sans-serif;
  font-size: clamp(30px, 5.4vh, 52px);
  margin: 0;
}

.end-copy {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.5;
  max-width: 30ch;
  color: rgba(255, 255, 255, 0.9);
  text-align: center;
  margin: 0;
}

.privacy {
  margin-top: 6px;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-radius: 18px;
  padding: 16px 18px;
  max-width: 34ch;
  font-size: 15px;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(0, 0, 0, 0.18);
}
.privacy strong { color: #fff; }

.end-links {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  margin-top: 4px;
}

.end-links a {
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  text-decoration-color: var(--accent);
  text-underline-offset: 4px;
  text-decoration-thickness: 3px;
}

.capture { display: flex; gap: 8px; width: min(100%, 340px); }
.capture input {
  flex: 1;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-radius: 14px;
  padding: 13px 14px;
  font: inherit;
  font-size: 16px;
  min-width: 0;
}
.capture input::placeholder { color: rgba(255, 255, 255, 0.6); }
.capture button {
  border: 0;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 700;
  border-radius: 14px;
  padding: 13px 18px;
  cursor: pointer;
}

/* ---------- chrome ---------- */

.chrome { position: fixed; inset: 0; pointer-events: none; z-index: 20; }

.progress {
  position: absolute;
  top: var(--safe-top);
  left: 0;
  right: 0;
  height: 4px;
  background: rgba(255, 255, 255, 0.16);
}
.progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 300ms var(--ease);
}

/* One bottom row holds the arrows and the tools, so they can never collide on
   a narrow phone. Arrows sit at the edges: thumb-reachable for small hands,
   and clear of the artwork, which fills the width on a phone. */
.bottombar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--safe-bottom) + 12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 10px;
  pointer-events: none;
}

.nav {
  pointer-events: auto;
  flex: 0 0 auto;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 0;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: opacity 200ms, transform 120ms;
}
.nav:active { transform: scale(0.9); }
.nav svg { width: 30px; height: 30px; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
/* Kept in the layout when disabled so the tools stay centred on the cover. */
.nav[disabled] { opacity: 0; pointer-events: none; }

.tools {
  pointer-events: auto;
  margin: 0 auto;
  display: flex;
  gap: 8px;
  padding: 8px;
  border-radius: 26px;
  background: rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: opacity 220ms;
  min-width: 0;
}
.tools[hidden] { display: none; }

.tool {
  border: 0;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-radius: 20px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  min-height: 52px;
  transition: transform 120ms, background 180ms;
  white-space: nowrap;
}
.tool[hidden] { display: none; }
.tool:active { transform: scale(0.94); }
.tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.tool .i-stop { display: none; fill: currentColor; stroke: none; }
.tool.busy .i-stop { display: block; }
.tool.busy .i-speak, .tool.busy .i-mic { display: none; }

.tool-play.busy { background: rgba(255, 255, 255, 0.3); }
.tool-rec.busy { background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.tool-rec.has-take { background: rgba(255, 255, 255, 0.26); }
.tool-clip { background: var(--accent); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.4); }
  50% { box-shadow: 0 0 0 10px rgba(255, 255, 255, 0); }
}

/* On a phone the row is arrows + up to four tools. Labels do not fit, so the
   icons carry it and the aria-labels do the talking for screen readers. */
@media (max-width: 480px) {
  .tool-label { display: none; }
  .tool { padding: 12px; }
  .tools { gap: 6px; padding: 6px; }
  .nav { width: 54px; height: 54px; }
}

/* ---------- the reward loop ---------- */

.fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 55;
}

.topbar {
  position: absolute;
  top: calc(var(--safe-top) + 10px);
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.mode {
  display: flex;
  padding: 3px;
  border: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
  font: inherit;
}
.mode-opt {
  font-size: 13px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.6);
  padding: 7px 14px;
  border-radius: 999px;
  transition: background 220ms, color 220ms;
}
.mode-opt.on { background: var(--accent); color: #fff; }

.purse {
  display: flex;
  align-items: center;
  gap: 7px;
  border: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #fff;
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  padding: 7px 14px 7px 9px;
  cursor: pointer;
}
.coin-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #FFE9A8, #F0BE4E 55%, #C98F35);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35);
  flex: 0 0 auto;
}

/* --- question panel --- */

.gamepanel {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--safe-bottom) + var(--tools-h) + 14px);
  width: min(560px, calc(100vw - 24px));
  pointer-events: auto;
  background: rgba(8, 10, 34, 0.82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: 24px;
  padding: 14px 14px 10px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}
.gamepanel[hidden] { display: none; }

/* In play mode the art shrinks so the question is never below the fold. */
body.playing .art { width: min(100%, 34vh); }
body.playing .letterwrap { font-size: clamp(48px, 8vh, 84px); }
body.playing .line { display: none; }
body.playing .page { padding-bottom: calc(var(--safe-bottom) + var(--tools-h) + 210px); }

.q-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.q-prompt {
  flex: 1;
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  text-align: center;
}
.q-say {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.q-say svg { width: 20px; height: 20px; fill: none; stroke: #fff; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.q-won-badge {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  margin: -6px 0 10px;
  letter-spacing: 0.02em;
}

.q-grid { display: grid; gap: 10px; }
.q-grid-big { grid-template-columns: repeat(4, 1fr); }
.q-grid-words { grid-template-columns: repeat(3, 1fr); }

.q-tile {
  border: 3px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-radius: 18px;
  cursor: pointer;
  font-family: 'ABC Display', system-ui, sans-serif;
  transition: transform 120ms, background 200ms, border-color 200ms;
  min-height: 66px;
  display: grid;
  place-items: center;
  padding: 6px;
}
.q-grid-big .q-tile { font-size: clamp(30px, 6vw, 40px); }
.q-grid-words .q-tile { font-size: clamp(15px, 3.6vw, 21px); line-height: 1.05; }
.q-tile:active { transform: scale(0.94); }
.q-tile[disabled] { opacity: 0.3; pointer-events: none; }

.q-tile.right {
  background: #2FBF71;
  border-color: #7BD389;
  animation: tile-pop 460ms var(--ease);
}
@keyframes tile-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.16); }
  100% { transform: scale(1); }
}

/* A miss costs nothing: it wobbles, dims for a beat, and stays tappable.
   There is deliberately no red, no buzzer and no counter. */
.q-tile.wrong { animation: tile-wobble 520ms ease; }
@keyframes tile-wobble {
  0%, 100% { transform: translateX(0); opacity: 1; }
  15% { transform: translateX(-7px) rotate(-3deg); opacity: 0.55; }
  35% { transform: translateX(6px) rotate(3deg); }
  55% { transform: translateX(-4px) rotate(-2deg); opacity: 0.75; }
  75% { transform: translateX(3px) rotate(1deg); }
}

.q-nudge {
  margin: 10px 0 2px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.75);
  min-height: 18px;
  opacity: 0;
}
.q-nudge.show { animation: rise 320ms var(--ease) forwards; }

/* --- the celebration --- */

.hooray {
  position: fixed;
  inset: 0;
  z-index: 58;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  pointer-events: none;
  opacity: 0;
  padding: 0 18px;
}
.hooray.show { opacity: 1; }

/* The page dims behind the celebration so it reads as its own moment instead
   of as text piled on top of the letter. Without this it is unreadable on a
   phone, where the artwork fills the width. */
.hooray::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(6, 8, 30, 0.9) 0%, rgba(6, 8, 30, 0.78) 45%, rgba(6, 8, 30, 0.42) 100%);
  opacity: 0;
  transition: opacity 200ms ease;
}
.hooray.show::before { opacity: 1; }
.hooray > * { position: relative; z-index: 1; }

.hooray-word {
  font-family: 'ABC Display', system-ui, sans-serif;
  font-size: clamp(52px, 15vw, 130px);
  color: #fff;
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.28), 0 0 40px rgba(255, 220, 120, 0.7);
  opacity: 0;
}
.hooray.show .hooray-word { animation: hooray-pop 700ms var(--ease) forwards; }
@keyframes hooray-pop {
  0% { opacity: 0; transform: scale(0.4) rotate(-8deg); }
  55% { opacity: 1; transform: scale(1.15) rotate(3deg); }
  100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

.hooray-name {
  font-family: 'ABC Display', system-ui, sans-serif;
  font-size: clamp(30px, 8vw, 62px);
  color: var(--accent);
  letter-spacing: 0.06em;
  opacity: 0;
}
.hooray-name[hidden] { display: none; }
/* Two pulses, on the same beat the crowd audio swells — that is the chant. */
.hooray.show .hooray-name.chant { animation: chant 0.42s steps(1, end) 0.15s 4 alternate, fade-in 200ms forwards; }
@keyframes chant {
  from { transform: scale(1); opacity: 0.55; }
  to { transform: scale(1.22); opacity: 1; }
}
@keyframes fade-in { to { opacity: 1; } }

.hooray-coins {
  font-family: 'ABC Display', system-ui, sans-serif;
  font-size: clamp(26px, 6vw, 44px);
  color: #F0BE4E;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
  opacity: 0;
}
.hooray-coins[hidden] { display: none; }
.hooray.show .hooray-coins { animation: coin-fly 900ms var(--ease) 220ms forwards; }
@keyframes coin-fly {
  0% { opacity: 0; transform: translateY(20px) scale(0.6); }
  40% { opacity: 1; transform: translateY(-6px) scale(1.1); }
  100% { opacity: 1; transform: translateY(-14px) scale(1); }
}

.hooray-line {
  font-size: 16px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.92);
  max-width: 22ch;
  text-align: center;
  text-wrap: balance;
  opacity: 0;
  margin-top: 4px;
}
.hooray.show .hooray-line { animation: rise 500ms var(--ease) 520ms forwards; }

.hooray-mascot { width: clamp(96px, 22vw, 150px); opacity: 0; margin-top: 6px; }
.hooray.show .hooray-mascot { animation: rise 460ms var(--ease) 180ms forwards; }
.mascot-svg { width: 100%; height: auto; overflow: visible; }

.hooray.show .mascot-body { animation: mascot-bounce 0.62s var(--ease) infinite; transform-origin: 50% 90%; }
.hooray.show.big .mascot-body { animation: mascot-party 0.5s var(--ease) infinite; }
@keyframes mascot-bounce {
  0%, 100% { transform: translateY(0) scaleY(1); }
  30% { transform: translateY(-16px) scaleY(1.06); }
  60% { transform: translateY(0) scaleY(0.94); }
}
@keyframes mascot-party {
  0%, 100% { transform: translateY(0) rotate(-6deg); }
  25% { transform: translateY(-20px) rotate(6deg); }
  50% { transform: translateY(0) rotate(-4deg); }
  75% { transform: translateY(-12px) rotate(4deg); }
}
.hooray.show .mascot-arm-l { animation: arm-l 0.5s ease-in-out infinite alternate; transform-origin: 100% 50%; }
.hooray.show .mascot-arm-r { animation: arm-r 0.5s ease-in-out infinite alternate; transform-origin: 0% 50%; }
@keyframes arm-l { from { transform: rotate(10deg); } to { transform: rotate(-48deg); } }
@keyframes arm-r { from { transform: rotate(-10deg); } to { transform: rotate(48deg); } }

/* --- trophy + trail --- */

.trophy-wrap { width: 150px; margin: 0 auto 10px; }
.trophy-svg { width: 100%; height: auto; }
.trophy-svg rect, .trophy-svg path { transition: opacity 600ms var(--ease); }
.trophy-count { font-size: 15px; font-weight: 700; color: rgba(255, 255, 255, 0.9); margin: 0 0 14px; }

.trail {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: center;
  margin-bottom: 18px;
}
.trail-dot {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-family: 'ABC Display', system-ui, sans-serif;
  font-size: 15px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.45);
  cursor: pointer;
  padding: 0;
  transition: transform 120ms, background 180ms;
}
.trail-dot:active { transform: scale(0.9); }
.trail-dot.on { background: var(--accent); color: #fff; }

.again-btn {
  border: 0;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-family: 'ABC Display', system-ui, sans-serif;
  font-size: 20px;
  padding: 14px 30px;
  border-radius: 18px;
  cursor: pointer;
  margin-top: 6px;
  transition: transform 120ms;
}
.again-btn:active { transform: scale(0.95); }

/* ---------- the locker ---------- */

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.sheet-inner.locker { max-width: 420px; max-height: 88vh; display: flex; flex-direction: column; }

.lk-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  margin-bottom: 14px;
  flex: 0 0 auto;
}
.lk-tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.65);
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  padding: 9px 6px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 200ms, color 200ms;
}
.lk-tab.on { background: var(--accent); color: #fff; }

.lk-body { overflow-y: auto; flex: 1 1 auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
.lk-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
  margin: 14px 0 7px;
  text-align: left;
}

.coin-dot.sm {
  display: inline-block;
  width: 13px;
  height: 13px;
  vertical-align: -2px;
  margin-right: 5px;
}
.purse.owing { box-shadow: inset 0 0 0 2px #F0BE4E; }

/* --- me --- */

.av-stage {
  width: 150px;
  margin: 0 auto 4px;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.45));
}
.avatar-svg { width: 100%; height: auto; overflow: visible; }

.sw-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.sw {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  padding: 0;
}
.sw.on { border-color: #fff; transform: scale(1.08); }

.chip {
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  text-transform: capitalize;
}
.chip.on { background: var(--accent); border-color: var(--accent); }

.shop { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.shop-item {
  border: 2px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.07);
  border-radius: 16px;
  padding: 12px 8px;
  color: #fff;
  font: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
}
.shop-name { font-weight: 700; font-size: 14px; }
.shop-price { font-size: 13px; font-weight: 700; color: #F0BE4E; display: flex; align-items: center; }
.shop-item.owned { border-color: rgba(255, 255, 255, 0.35); }
.shop-item.worn { background: var(--accent); border-color: var(--accent); }
.shop-item.worn .shop-price { color: #fff; }
/* Locked items stay visible and tappable — tapping says how to get there
   rather than doing nothing, because a dead button teaches nothing. */
.shop-item.locked { opacity: 0.55; }

/* --- bank --- */

.bank-rows { display: flex; flex-direction: column; gap: 7px; margin-bottom: 10px; }
.bank-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 14px;
  padding: 11px 14px;
}
.bank-row.vault { background: rgba(240, 190, 78, 0.16); }
.bank-row.owe { background: rgba(217, 32, 39, 0.22); }
.bank-k { font-size: 14px; font-weight: 700; color: rgba(255, 255, 255, 0.8); }
.bank-v { font-size: 19px; font-weight: 700; display: flex; align-items: center; }

.bank-line {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 14px;
  text-wrap: balance;
}

.bank-moves { display: flex; gap: 7px; flex-wrap: wrap; justify-content: center; }
.bank-btn {
  flex: 1 1 auto;
  min-width: 92px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  padding: 11px 10px;
  border-radius: 14px;
  cursor: pointer;
}
.bank-btn.primary { background: var(--accent); border-color: var(--accent); }
.bank-btn.warn { background: transparent; border-color: #F0BE4E; color: #F0BE4E; }
.bank-btn[disabled] { opacity: 0.35; cursor: default; }

.bank-proj { margin-top: 6px; }
.proj-row { display: flex; gap: 7px; }
.proj-cell {
  flex: 1;
  background: rgba(240, 190, 78, 0.14);
  border-radius: 14px;
  padding: 10px 4px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: center;
}
.proj-d { font-size: 11px; font-weight: 700; color: rgba(255, 255, 255, 0.6); text-transform: uppercase; letter-spacing: 0.04em; }
.proj-n { font-size: 17px; font-weight: 700; color: #F0BE4E; display: flex; align-items: center; }

.bank-borrow { margin-top: 16px; }
.bank-small { font-size: 13px; line-height: 1.45; color: rgba(255, 255, 255, 0.82); margin: 0 0 10px; text-wrap: balance; }
.bank-note {
  font-size: 12px;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.5);
  margin: 18px 0 0;
  text-wrap: balance;
}

/* ---------- growth chart ---------- */

/* Two heaps of drawn coins side by side. No numbers, no axis, no subtraction —
   a child reads "that one is bigger" and that is the entire lesson. */
.pile-row { display: flex; gap: 12px; align-items: flex-end; }
.pile { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.pile-heap {
  position: relative;
  width: 100%;
  height: 128px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
}
.pile-later .pile-heap { background: rgba(240, 190, 78, 0.12); }

/* The coin's RESTING state is visible. The drop-in is an animation played on
   top of it, not a transition into existence.
   Earlier this rested at opacity 0 and transitioned to 1 — but transitions do
   not advance on a hidden page, so the pile stayed permanently empty instead of
   simply appearing un-animated. Never make "invisible" the default state of
   something the user needs to see. */
.pile-coin {
  position: absolute;
  width: 11%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #FFE9A8, #F0BE4E 55%, #C98F35);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}
/* The entrance is animated on the HEAP, not on each coin. A per-coin animation
   needed `backwards` fill for the stagger, and that fill holds the element at
   its invisible first frame whenever the animation cannot run — which put the
   coins right back to permanently hidden. One animation on the container has no
   such failure mode: if it never plays, the full pile is simply already there. */
.pile-row.go .pile-heap { animation: heap-in 520ms cubic-bezier(0.34, 1.35, 0.5, 1); }
@keyframes heap-in {
  from { opacity: 0.2; transform: translateY(-10px) scale(0.9); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.pile-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.5);
}
.pile-later .pile-label { color: #F0BE4E; }
.grow-note {
  font-size: 13px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.85);
  margin: 12px 0 0;
  text-wrap: balance;
}
.story-cta { width: 100%; margin-top: 14px; }

/* ---------- the chicken story ---------- */

.sheet-inner.story { max-width: 460px; }
.story-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: radial-gradient(ellipse at 50% 100%, rgba(120, 200, 140, 0.22), transparent 62%),
    rgba(255, 255, 255, 0.05);
  border-radius: 18px;
  overflow: hidden;
  transition: background 600ms ease;
}
.story-stage.waiting { background: radial-gradient(ellipse at 50% 100%, rgba(120, 200, 140, 0.3), transparent 62%), rgba(255, 255, 255, 0.05); }
.story-stage.finish { background: radial-gradient(ellipse at 50% 60%, rgba(240, 190, 78, 0.28), transparent 68%), rgba(255, 255, 255, 0.06); }

.hen, .egg {
  position: absolute;
  transform-origin: 50% 50%;
  transition: left 900ms cubic-bezier(0.22, 0.68, 0.24, 1),
              top 900ms cubic-bezier(0.22, 0.68, 0.24, 1),
              transform 900ms cubic-bezier(0.34, 1.4, 0.5, 1),
              opacity 520ms ease;
}
.hen { width: 34%; }
.egg { width: 9%; }
.hen-svg, .egg-svg { width: 100%; height: auto; display: block; }

.story-plate {
  position: absolute;
  left: 50%;
  bottom: 8%;
  transform: translateX(-50%) scale(0.6);
  opacity: 0;
  background: rgba(217, 32, 39, 0.9);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 6px 14px;
  border-radius: 999px;
  transition: opacity 400ms ease, transform 400ms ease;
}
.story-plate.show { opacity: 1; transform: translateX(-50%) scale(1); }

.story-caption {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.45;
  color: #fff;
  min-height: 3.2em;
  margin: 14px 0 8px;
  text-wrap: balance;
  opacity: 0;
}
.story-caption.in { animation: rise 420ms var(--ease) forwards; }

.story-dots { display: flex; gap: 5px; justify-content: center; margin-bottom: 12px; }
.story-dot { width: 7px; height: 7px; border-radius: 50%; background: rgba(255, 255, 255, 0.2); transition: background 300ms; }
.story-dot.on { background: var(--accent); }
.story-controls { min-height: 44px; display: flex; justify-content: center; }

/* ---------- the grown-up guide ----------
   Deliberately grey, small, still and unbadged. A child scanning for something
   fun should slide straight past it; an adult looking for help should find it
   without being told. Nothing in the bank requires opening any of this. */

.gd-wrap { position: relative; display: inline-block; margin-left: 6px; }
.gd-dot {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: transparent;
  color: rgba(255, 255, 255, 0.45);
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  vertical-align: 1px;
}
.gd-bubble {
  position: absolute;
  top: 24px;
  left: -8px;
  z-index: 5;
  width: min(250px, 68vw);
  background: #F1EFE8;
  color: #2C2C2A;
  font-size: 12.5px;
  font-weight: 400;
  line-height: 1.5;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.4);
}
.gd-bubble[hidden] { display: none; }

.guide-link {
  display: block;
  margin: 18px auto 0;
  border: 0;
  background: none;
  color: rgba(255, 255, 255, 0.38);
  font: inherit;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  padding: 4px;
}

.sheet-inner.guide { max-width: 460px; max-height: 88vh; display: flex; flex-direction: column; }
.guide-body {
  overflow-y: auto;
  text-align: left;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 12px;
}
.guide-intro { font-size: 14px; font-weight: 700; color: var(--accent); margin: 0 0 16px; line-height: 1.5; }
.guide-h {
  font-family: 'ABC Text', system-ui, sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.5);
  margin: 20px 0 8px;
}
.guide-p { font-size: 14.5px; line-height: 1.6; color: rgba(255, 255, 255, 0.9); margin: 0 0 10px; font-weight: 400; }
.guide-list { margin: 4px 0 0; padding-left: 18px; }
.guide-list li { font-size: 14.5px; line-height: 1.6; color: rgba(255, 255, 255, 0.9); margin-bottom: 8px; }
.guide-foot { font-size: 12.5px; color: rgba(255, 255, 255, 0.42); margin: 22px 0 0; line-height: 1.5; }

.bank-together {
  font-size: 12.5px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.55);
  margin: 0 0 10px;
}

/* ---------- toast + clip sheet ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + var(--tools-h) + 16px);
  transform: translate(-50%, 12px);
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  font-size: 15px;
  padding: 12px 18px;
  border-radius: 16px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms, transform 220ms;
  z-index: 60;
  max-width: min(90vw, 420px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(6, 8, 30, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  padding: 24px;
}
.sheet[hidden] { display: none; }
.sheet-inner { text-align: center; max-width: 340px; width: 100%; }
.sheet h2 { font-family: 'ABC Display', system-ui, sans-serif; font-size: 26px; margin: 0 0 14px; }
#clip-canvas {
  width: 100%;
  max-width: 200px;
  height: auto;
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  background: #000;
}
.sheet-bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
  margin: 16px 0 10px;
  overflow: hidden;
}
.sheet-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 200ms linear; }
.sheet-note { font-size: 14px; color: var(--muted); margin: 0 0 14px; }
.btn-ghost {
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: transparent;
  color: #fff;
  font: inherit;
  font-weight: 700;
  padding: 11px 20px;
  border-radius: 14px;
  cursor: pointer;
}

/* ---------- landscape ---------- */

@media (orientation: landscape) and (min-width: 700px) {
  .page-letter .page-inner {
    flex-direction: row;
    gap: 40px;
    align-items: center;
    max-width: 1100px;
  }
  .page-letter .art { width: min(46%, 64vh); }
  .page-letter .words { align-items: flex-start; text-align: left; flex: 1; }
  .page-letter .line { max-width: 24ch; }
}

/* ---------- calm mode ---------- */

@media (prefers-reduced-motion: reduce) {
  .track.animate { transition: none; }
  .page.active .art img,
  .page.active .letter-outline,
  .page.active .letter-fill,
  .page.active .word,
  .page.active .line,
  .page.active .cover-mark,
  .page.active .cover-title,
  .page.active .cover-sub,
  .page.active .cover-author,
  .page.active .cover-hint {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
    clip-path: none !important;
  }
  .letter-outline { opacity: 0 !important; }
  .tool-rec.busy { animation: none; }
  .progress span { transition: none; }

  /* The celebration still happens — it just stops moving. The crowd, the
     coins and the words all remain; only the motion is removed. */
  .hooray.show .hooray-word,
  .hooray.show .hooray-name,
  .hooray.show .hooray-coins,
  .hooray.show .hooray-line,
  .hooray.show .hooray-mascot,
  .hooray.show .mascot-body,
  .hooray.show .mascot-arm-l,
  .hooray.show .mascot-arm-r,
  .q-tile.right,
  .q-tile.wrong,
  .q-nudge.show {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
  .q-tile.wrong { opacity: 0.55 !important; }
}
