:root {
  color-scheme: light;
  --paper: #F6EEDD;
  --paper-deep: #EBDFC6;
  --card: #FFFBF2;
  --ink: #2E241E;
  --ink-soft: #66574A;
  --line: #DCCDB0;
  --leaf: #3F7E44;
  --leaf-deep: #2F6334;
  --berry: #B8402F;
  --honey: #F9E6AC;
  --shadow: 0 1px 0 rgba(46, 36, 30, 0.06), 0 10px 24px -12px rgba(46, 36, 30, 0.35);
  --shadow-press: 0 1px 0 rgba(46, 36, 30, 0.06), 0 4px 10px -6px rgba(46, 36, 30, 0.35);
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-move: cubic-bezier(0.77, 0, 0.175, 1);
  --display: 'Grandstander', 'Andika', system-ui, sans-serif;
  --read: 'Andika', system-ui, sans-serif;
  --gutter: clamp(16px, 2.4vw, 32px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--read);
  font-size: 18px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
::selection { background: var(--honey); color: var(--ink); }
input { caret-color: var(--berry); }
:focus-visible { outline: 4px solid var(--leaf); outline-offset: 3px; border-radius: 12px; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
svg { display: block; }
h1, h2, h3 { font-family: var(--display); font-weight: 800; letter-spacing: -0.01em; margin: 0; text-wrap: balance; }

main { min-height: 100dvh; }
.screen {
  display: none;
  min-height: 100dvh;
  padding: var(--gutter) var(--gutter) calc(var(--gutter) + env(safe-area-inset-bottom));
  max-width: 1280px;
  margin: 0 auto;
}
.screen[data-active] { display: flex; flex-direction: column; animation: screen-in 320ms var(--ease-out); }
@keyframes screen-in { from { opacity: 0; } to { opacity: 1; } }

/* ---------- shared controls ---------- */

.go {
  align-self: center;
  border: 0;
  border-radius: 20px;
  background: var(--leaf);
  color: #FFF8EA;
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(22px, 2.6vw, 30px);
  padding: 18px 40px 20px;
  min-height: 72px;
  box-shadow: 0 4px 0 var(--leaf-deep), var(--shadow);
  transition: transform 160ms var(--ease-out), box-shadow 160ms var(--ease-out), background-color 200ms ease;
}
.go:active:not(:disabled) { transform: translateY(3px) scale(0.98); box-shadow: 0 1px 0 var(--leaf-deep), var(--shadow-press); }
.go:disabled { background: var(--paper-deep); color: var(--ink-soft); box-shadow: none; }
.go.small { font-size: 20px; min-height: 60px; padding: 12px 26px 14px; }

.round {
  flex: none;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 0;
  background: var(--card);
  color: var(--leaf-deep);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
  transition: transform 160ms var(--ease-out);
}
.round svg { width: 28px; height: 28px; }
.round.big { width: 72px; height: 72px; }
.round.big svg { width: 34px; height: 34px; }
.round:active:not(:disabled) { transform: scale(0.94); }
.round:disabled { opacity: 0.35; }

.text-btn {
  border: 0;
  background: none;
  color: var(--leaf-deep);
  font-weight: 700;
  font-size: 18px;
  padding: 10px 12px;
  min-height: 48px;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 5px;
  text-decoration-color: color-mix(in srgb, var(--leaf) 40%, transparent);
}
.text-btn:disabled { color: var(--ink-soft); opacity: 0.5; }

/* ---------- 1. pick ---------- */

#pick { justify-content: center; gap: clamp(20px, 3.5vh, 40px); text-align: center; }
#pick h1 { font-size: clamp(36px, 5.4vw, 64px); line-height: 1.05; }

.heroes {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(10px, 2vw, 24px);
  width: min(100%, 1040px);
  margin: 0 auto;
}
.hero {
  border: 0;
  border-radius: 22px;
  background: var(--card);
  padding: clamp(10px, 1.6vw, 20px) 8px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow);
  position: relative;
  transition: transform 200ms var(--ease-out), box-shadow 200ms var(--ease-out);
}
.hero svg { width: 100%; max-width: 200px; aspect-ratio: 270 / 246; height: auto; overflow: visible; }
.hero span { font-family: var(--display); font-weight: 800; font-size: clamp(22px, 2.4vw, 30px); line-height: 1.1; display: flex; flex-direction: column; }
.hero small { font-family: var(--read); font-weight: 400; font-size: 17px; color: var(--ink-soft); }
.hero:active { transform: scale(0.97); }
.hero[aria-checked="true"] { box-shadow: 0 0 0 5px var(--leaf), var(--shadow); transform: translateY(-4px); }
.hero[aria-checked="true"]:active { transform: translateY(-4px) scale(0.97); }
.hero .pose { transform-box: fill-box; transform-origin: 50% 100%; }
.hero .pose.hop { animation: hop 620ms var(--ease-out); }
@keyframes hop {
  0% { transform: translateY(0) scale(1, 1); }
  25% { transform: translateY(0) scale(1.06, 0.92); }
  55% { transform: translateY(-14%) scale(0.96, 1.05); }
  100% { transform: translateY(0) scale(1, 1); }
}

.paint-row { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.paint-row[hidden] { display: none; }
.paint-label { margin: 0; font-weight: 700; color: var(--ink-soft); }
.paints { display: flex; gap: clamp(10px, 1.6vw, 18px); flex-wrap: wrap; justify-content: center; }
.swatch {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 0;
  background: var(--sw);
  box-shadow: inset 0 -6px 0 var(--sw-dark), var(--shadow);
  transition: transform 160ms var(--ease-out), box-shadow 160ms var(--ease-out);
}
.swatch span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.swatch:active { transform: scale(0.92); }
.swatch[aria-checked="true"] { box-shadow: inset 0 -6px 0 var(--sw-dark), 0 0 0 4px var(--paper), 0 0 0 8px var(--ink); }

/* ---------- 2. story ---------- */

#story { gap: 14px; padding-top: max(12px, env(safe-area-inset-top)); }
.stage-wrap {
  position: relative;
  width: min(100%, calc((100dvh - 330px) * 16 / 9));
  min-width: min(100%, 520px);
  margin: 0 auto;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 0 0 6px var(--card), 0 18px 40px -20px rgba(46, 36, 30, 0.55);
  background: #CFE6E2;
}
.stage { width: 100%; height: auto; aspect-ratio: 16 / 9; }
.stage .piece { transition: transform 560ms var(--ease-move); }
.stage .pose { transition: transform 300ms var(--ease-out); }
.stage .fx-night, .stage .fx-glow, .stage .fx-rain { transition: opacity 600ms ease; pointer-events: none; }
.stage .fx-glow { mix-blend-mode: screen; }
.stage .drops { animation: rain 900ms linear infinite; }
@keyframes rain { from { transform: translate(0, 0); } to { transform: translate(-275px, 900px); } }
.stage .bob > .pose { animation: bob 2.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-14px) rotate(4deg); } }

.chip {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 251, 242, 0.94);
  color: var(--ink);
  font-weight: 700;
  font-size: 17px;
  padding: 10px 16px 10px 12px;
  min-height: 48px;
  box-shadow: var(--shadow);
  transition: transform 160ms var(--ease-out);
}
.chip[hidden] { display: none; }
.chip svg { width: 22px; height: 22px; }
.chip:active { transform: scale(0.96); }
.page-no {
  position: absolute;
  top: 14px;
  right: 16px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
  background: rgba(255, 251, 242, 0.9);
  border-radius: 999px;
  padding: 6px 14px;
}

.words {
  display: flex;
  align-items: center;
  gap: 16px;
  width: min(100%, 1100px);
  margin: 0 auto;
  min-height: 72px;
}
.line {
  flex: 1;
  margin: 0;
  font-size: clamp(21px, 2.3vw, 28px);
  line-height: 1.38;
  font-weight: 700;
  max-width: 62ch;
  text-wrap: pretty;
  transition: opacity 200ms ease;
}
.line .w { border-radius: 6px; transition: background-color 120ms ease, box-shadow 120ms ease; }
.line .w.lit { background: var(--honey); box-shadow: 0 0 0 3px var(--honey); }
.busy .line { opacity: 0.45; }

.end-btn {
  flex: none;
  border: 0;
  border-radius: 16px;
  background: var(--berry);
  color: #FFF4EE;
  font-family: var(--display);
  font-weight: 800;
  font-size: 20px;
  min-height: 56px;
  padding: 10px 20px 12px;
  box-shadow: 0 3px 0 #8E2F22, var(--shadow);
  transition: transform 160ms var(--ease-out);
}
.end-btn[hidden] { display: none; }
.end-btn:active { transform: translateY(2px) scale(0.98); }

.prompt { margin: 0 auto; width: min(100%, 1100px); font-family: var(--display); font-weight: 800; font-size: 20px; color: var(--ink-soft); }
.choices {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(10px, 1.4vw, 18px);
  width: min(100%, 1100px);
  margin: 0 auto;
}
.choices[hidden] { display: none; }
.choice {
  border: 0;
  border-radius: 18px;
  background: var(--card);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px 10px 10px;
  min-height: 96px;
  text-align: left;
  animation: choice-in 360ms var(--ease-out) backwards;
  animation-delay: calc(var(--i) * 45ms + 260ms);
  transition: transform 160ms var(--ease-out), box-shadow 160ms var(--ease-out), opacity 200ms ease;
}
@keyframes choice-in { from { opacity: 0; transform: translateY(10px); } }
.choice:active:not(:disabled) { transform: scale(0.97); box-shadow: var(--shadow-press); }
.choice:disabled { opacity: 0.5; }
.choice .pic {
  flex: none;
  width: 76px;
  height: 76px;
  border-radius: 14px;
  background: var(--paper);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.choice .pic svg { width: 64px; height: 64px; }
.choice .pic svg.thumb { width: 100%; height: 100%; }
.choice .label { font-weight: 700; font-size: clamp(18px, 1.7vw, 21px); line-height: 1.2; }
.choice.own { background: transparent; box-shadow: inset 0 0 0 3px var(--line); }
.choice.own .pic { background: var(--card); }
.busy .choice { animation: none; }

.idea { width: min(100%, 1100px); margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.idea[hidden] { display: none; }
.idea label { font-family: var(--display); font-weight: 800; font-size: 22px; }
.idea-row { display: flex; gap: 12px; }
.idea input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  background: var(--card);
  border: 3px solid var(--line);
  border-radius: 16px;
  padding: 12px 18px;
  min-height: 60px;
  transition: border-color 160ms ease;
}
.idea input::placeholder { color: #8A7A6B; font-weight: 400; }
.idea input:focus { outline: none; border-color: var(--leaf); }
.idea-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.idea-note { margin: 0; font-weight: 700; color: var(--berry); }

/* ---------- 3. book ---------- */

#book { gap: 14px; }
.book-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; width: min(100%, 1100px); margin: 0 auto; }
.book-head .text-btn { justify-self: start; }
.book-head h2 { font-size: clamp(26px, 3.2vw, 40px); text-align: center; }
.book-wrap { width: min(100%, calc((100dvh - 300px) * 16 / 9)); }
#book.is-cover .book-wrap { box-shadow: 0 0 0 6px var(--card), 0 0 0 10px var(--berry), 0 18px 40px -20px rgba(46, 36, 30, 0.55); }
#book.is-cover #book-line { font-family: var(--display); color: var(--ink-soft); }
.book-nav { display: flex; align-items: center; justify-content: center; gap: 20px; flex-wrap: wrap; }
.book-nav .round[hidden] { display: none; }
.dots { display: flex; gap: 8px; }
.dots i { width: 12px; height: 12px; border-radius: 50%; background: var(--line); transition: background-color 200ms ease, transform 200ms var(--ease-out); }
.dots i.on { background: var(--berry); transform: scale(1.25); }
.book-finish { display: flex; align-items: center; gap: 12px; }
.book-finish[hidden] { display: none; }

/* ---------- grown-ups ---------- */

.grownups {
  position: fixed;
  right: 12px;
  bottom: max(10px, env(safe-area-inset-bottom));
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 700;
  padding: 10px 12px;
}
body[data-screen="story"] .grownups { display: none; }
.panel {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: min(380px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow: auto;
  background: var(--card);
  border-radius: 20px;
  box-shadow: 0 24px 60px -20px rgba(46, 36, 30, 0.5), 0 2px 0 rgba(46, 36, 30, 0.06);
  padding: 20px 22px 16px;
  font-size: 16px;
  z-index: 10;
  transform-origin: bottom right;
  animation: panel-in 220ms var(--ease-out);
}
.panel[hidden] { display: none; }
@keyframes panel-in { from { opacity: 0; transform: scale(0.96) translateY(6px); } }
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.panel h2 { font-size: 24px; }
.panel h3 { font-family: var(--read); font-size: 16px; font-weight: 700; margin: 18px 0 8px; }
.panel-intro { color: var(--ink-soft); margin: 6px 0 14px; }
.facts { margin: 0; display: grid; gap: 2px; }
.facts dt { font-weight: 700; }
.facts dd { margin: 0; color: var(--ink-soft); }
.toggle { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-weight: 700; min-height: 44px; }
.toggle[hidden] { display: none; }
.toggle input { width: 22px; height: 22px; accent-color: var(--leaf); }
.wishes { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.wishes li { background: var(--paper); border-radius: 999px; padding: 4px 6px 4px 12px; display: flex; gap: 8px; align-items: center; font-weight: 700; }
.wishes li b { font-size: 13px; background: var(--card); border-radius: 999px; padding: 1px 8px; font-variant-numeric: tabular-nums; }
.wishes li.empty { background: none; padding: 0; font-weight: 400; color: var(--ink-soft); }
.panel-actions { display: flex; gap: 4px; margin-top: 8px; }
.panel-actions .text-btn { font-size: 16px; padding: 8px; }

/* ---------- smaller screens ---------- */

@media (max-width: 860px) {
  .heroes { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 520px; }
  .choices { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stage-wrap { width: 100%; min-width: 0; }
  .book-wrap { width: 100%; }
}
@media (max-width: 560px) {
  body { font-size: 17px; }
  .choice { flex-direction: column; text-align: center; padding: 10px 8px 12px; min-height: 0; gap: 6px; }
  .choice .pic { width: 64px; height: 64px; }
  .choice .pic svg { width: 54px; height: 54px; }
  .words { gap: 10px; flex-wrap: wrap; }
  .line { flex-basis: calc(100% - 66px); }
  .end-btn { margin-left: auto; }
  .idea-row { flex-direction: column; }
  .swatch { width: 52px; height: 52px; }
  .stage-wrap { border-radius: 14px; box-shadow: 0 0 0 4px var(--card), 0 12px 28px -16px rgba(46, 36, 30, 0.55); }
  .chip span { display: none; }
  .chip { padding: 10px 12px; }
}
@media (max-height: 560px) and (orientation: landscape) {
  #story[data-active] {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    gap: 10px 18px;
    align-items: start;
  }
  #story .stage-wrap { grid-column: 1; grid-row: 1 / span 2; width: 100%; min-width: 0; margin: 0; }
  #story .words, #story .choices, #story .idea { grid-column: 2; width: 100%; }
  .words { min-height: 0; gap: 10px; }
  .line { font-size: 18px; }
  .round { width: 44px; height: 44px; }
  .round svg { width: 22px; height: 22px; }
  .end-btn { min-height: 44px; font-size: 16px; padding: 6px 12px 8px; }
  .prompt { display: none; }
  .choices { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .choice { min-height: 60px; padding: 6px 10px 6px 6px; gap: 8px; flex-direction: row; text-align: left; }
  .choice .pic { width: 48px; height: 48px; }
  .choice .pic svg { width: 42px; height: 42px; }
  .choice .label { font-size: 16px; }
  .idea label { font-size: 18px; }
  #pick { gap: 12px; }
  #pick h1 { font-size: 30px; }
  .heroes { grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: none; }
  .hero svg { max-width: 96px; }
  .hero span { font-size: 18px; }
  .hero small { font-size: 14px; }
  .swatch { width: 44px; height: 44px; }
  .go { min-height: 56px; font-size: 20px; padding: 10px 28px 12px; }
  .book-wrap { width: min(100%, calc((100dvh - 190px) * 16 / 9)); }
}
@media (max-width: 560px) {
  #pick { padding-bottom: 64px; }
  .paints { gap: 8px; flex-wrap: nowrap; }
  .swatch { width: 46px; height: 46px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; }
  .stage .piece, .stage .pose { transition: none !important; }
  .stage .drops { animation: none !important; }
}
