/* Fix-It Stories — bright storybook. One deliberate light look (no dark theme):
   sunny paper, golden trim, four shelf colors, a reading face built for new readers. */
:root {
  color-scheme: light;
  --paper-top: #fff6d6;
  --paper-bottom: #ffe9b8;
  --gold: #ffc94d;
  --gold-deep: #e8a920;
  --ink: #3d2a1e;
  --ink-soft: #6b5545;
  --card: #ffffff;
  --accent: #ff7a2f;
  --accent-deep: #d9561c;
  --title: #e85d2a;
  --hint: #fff07a;
  --found: #ffb84d;
  --fixed-bg: #c8f5d6;
  --green: #3fb56b;
  --green-deep: #2b8f50;
  --blue: #2f8fe0;
  --purple: #9b5de5;
  --pink: #f15bb5;
  --faded: #a8998a;
  --font-read: "Andika", "Comic Sans MS", "Chalkboard SE", system-ui, sans-serif;
  --font-display: "Fredoka", "Andika", "Comic Sans MS", system-ui, sans-serif;
  --radius: 16px;
  --tap: 52px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper-bottom); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  background: linear-gradient(var(--paper-top), var(--paper-bottom)) fixed var(--paper-top);
  font-family: var(--font-read);
  font-size: 18px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
#app {
  max-width: 760px;
  margin: 0 auto;
  padding-block: 12px 32px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 4px solid var(--blue); outline-offset: 3px; }
h1, h2, h3 { margin: 0; text-wrap: balance; }
p { margin: 0; }

/* ---------- shared bits ---------- */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar-mid { flex: 1; display: flex; justify-content: center; min-width: 0; }
.chip {
  min-height: var(--tap);
  padding: 6px 16px;
  border: 3px solid var(--gold);
  border-radius: 14px;
  background: var(--card);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
}
.icon-chip { min-width: var(--tap); padding: 6px 10px; font-size: 22px; }
.game-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(30px, 7vw, 44px);
  color: var(--title);
  text-align: center;
  text-shadow: 3px 3px 0 var(--gold);
  letter-spacing: 0.5px;
}
.big-btn {
  min-height: 60px;
  width: 100%;
  border: 0;
  border-radius: 18px;
  padding: 10px 18px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 24px;
  color: #fff;
  background: var(--green);
  box-shadow: 0 5px 0 var(--green-deep);
}
.big-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--green-deep); }
.big-btn.secondary { background: var(--card); color: var(--ink); border: 3px solid var(--gold); box-shadow: 0 4px 0 var(--gold-deep); font-size: 19px; min-height: var(--tap); }
.big-btn.secondary[aria-pressed="true"] { background: #e3f1fb; border-color: var(--blue); }

.wiggle { animation: wiggle 0.45s ease; }
@keyframes wiggle {
  0%, 100% { transform: translateX(0) rotate(0); }
  20% { transform: translateX(-6px) rotate(-3deg); }
  40% { transform: translateX(6px) rotate(3deg); }
  60% { transform: translateX(-4px) rotate(-2deg); }
  80% { transform: translateX(4px) rotate(1deg); }
}

/* ---------- how to play ---------- */
.howto {
  background: var(--card);
  border: 4px solid var(--gold);
  border-radius: var(--radius);
  padding: 12px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 5px 0 var(--gold-deep);
}
.howto-title { font-family: var(--font-display); font-weight: 700; font-size: 22px; color: var(--title); }
.howto-steps { list-style: none; counter-reset: step; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: 19px; line-height: 1.45; }
.howto-steps li { counter-increment: step; display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 10px; align-items: start; }
.howto-steps li::before {
  content: counter(step);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.howto-closing { font-weight: 700; font-size: 19px; }
.howto .w { border-radius: 5px; padding: 0 1px; }

/* ---------- bookcase ---------- */
.shelves { display: flex; flex-direction: column; gap: 14px; }
.shelf {
  background: var(--shelf);
  border-radius: var(--radius);
  padding: 10px 12px 14px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.18);
}
.shelf-name { color: #fff; font-family: var(--font-display); font-weight: 600; font-size: 20px; margin-bottom: 8px; }
.books { display: flex; gap: 12px; flex-wrap: wrap; }
.shelf-empty { color: #fff; opacity: 0.85; font-size: 16px; }
.book {
  width: 132px;
  min-height: 118px;
  border: 0;
  border-radius: 12px;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-align: center;
  box-shadow: 3px 4px 0 rgba(0, 0, 0, 0.25);
  background: var(--card);
}
.book-emoji { font-size: 38px; line-height: 1.1; }
.book-title { font-family: var(--font-display); font-weight: 600; font-size: 15px; line-height: 1.15; }
.book-note { font-size: 14px; min-height: 1.3em; }
.book-done { background: #fff3a6; }
.book-open { outline: 4px dashed var(--accent); outline-offset: -4px; }
.book-open .book-note { color: var(--accent-deep); font-weight: 700; }
.book-locked { background: rgba(255, 255, 255, 0.5); color: #5a4a5a; box-shadow: none; }
.home-footer { display: flex; justify-content: flex-end; }
.grownups-door { min-height: var(--tap); border: 0; background: none; color: var(--ink-soft); font-size: 16px; text-decoration: underline; padding: 6px 4px; }

/* ---------- stickers ---------- */
.sticker-count { text-align: center; font-size: 18px; color: var(--ink-soft); }
.sticker-shelf { border-radius: var(--radius); border: 4px solid var(--shelf); background: var(--card); padding: 10px 12px 14px; }
.sticker-shelf-name { font-family: var(--font-display); font-weight: 600; font-size: 19px; color: var(--shelf); margin-bottom: 8px; }
.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 12px; }
.sticker-slot { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.sticker-slot figcaption { font-family: var(--font-display); font-size: 15px; line-height: 1.2; }
.sticker {
  width: 86px;
  height: 86px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 46px;
  box-shadow: 0 0 0 5px #fff, 0 4px 10px rgba(0, 0, 0, 0.2);
}
.sticker-plain { background: #f4ecff; }
.sticker-gold { background: radial-gradient(circle at 35% 30%, #fff8c4, #ffcf3f 60%, #f0a500); }
.sticker-none { background: #efe6d6; color: #c9b9a2; font-family: var(--font-display); font-weight: 700; box-shadow: inset 0 0 0 3px #e2d4bd; }
.sticker.big { width: 150px; height: 150px; font-size: 82px; transform: rotate(-8deg); }

/* ---------- play ---------- */
.dots { display: flex; gap: 10px; justify-content: center; }
.dot { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--green); background: var(--card); }
.dot.on { background: var(--green); }
.story-title { font-family: var(--font-display); font-weight: 700; font-size: clamp(24px, 5.5vw, 32px); color: var(--title); text-align: center; text-shadow: 2px 2px 0 var(--gold); }
.banner {
  text-align: center;
  background: var(--accent);
  color: #fff;
  border-radius: 14px;
  padding: 8px 12px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  box-shadow: 0 4px 0 var(--accent-deep);
}
.banner.try-again { background: var(--purple); box-shadow: 0 4px 0 #7440b8; }
.banner.pick { background: var(--blue); box-shadow: 0 4px 0 #1f6db3; }
.page {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 18px;
  font-size: clamp(21px, 4.6vw, 25px);
  line-height: 1.75;
  box-shadow: 4px 5px 0 var(--gold);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.part.faded { color: var(--faded); }
.part.faded .fixed-word { color: var(--ink-soft); }
.w { border-radius: 6px; padding: 0 2px; }
.part.current .w {
  cursor: pointer;
  display: inline-block;
  min-height: 1.6em;
  padding: 0 4px;
  margin: 0 -2px;
  border: 0;
  background: none;
  font: inherit;
  line-height: inherit;
}
.part.current .w:active { background: #f3ead8; }
.nb { white-space: nowrap; }
.part.current .hint { background: var(--hint); box-decoration-break: clone; -webkit-box-decoration-break: clone; border-radius: 6px; }
.part.current .w.found { background: var(--found); box-shadow: inset 0 -4px 0 var(--accent-deep); font-weight: 700; }
.fixed-word { text-decoration: underline wavy var(--green); text-underline-offset: 5px; font-weight: 700; }
.choices { display: flex; flex-direction: column; gap: 12px; }
.choice-row { display: flex; flex-direction: column; gap: 6px; }
.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 18px;
  padding: 4px 6px 4px 18px;
  color: #fff;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.2);
}
.choice.c0 { background: var(--blue); }
.choice.c1 { background: var(--purple); }
.choice.c2 { background: var(--pink); }
.choice-word {
  flex: 1;
  min-height: 58px;
  border: 0;
  background: none;
  color: #fff;
  text-align: left;
  font-family: var(--font-read);
  font-weight: 700;
  font-size: 27px;
  padding: 0;
}
.info {
  width: var(--tap);
  height: var(--tap);
  flex: none;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: var(--blue);
  font-family: Georgia, serif;
  font-style: italic;
  font-weight: 700;
  font-size: 22px;
}
.meaning { background: var(--card); border: 3px solid var(--purple); border-radius: 12px; padding: 8px 12px; font-size: 18px; }
.meaning b { font-weight: 700; }

/* ---------- fixed story + read-along ---------- */
.fixed-story { font-size: clamp(20px, 4.4vw, 24px); }
.fixed-story .fixed-word { background: var(--fixed-bg); text-decoration: none; border-bottom: 3px solid var(--green); border-radius: 4px; padding: 0 3px; }
.reading { background: var(--hint) !important; box-shadow: 0 0 0 3px var(--gold); border-radius: 5px; }
.actions { display: flex; flex-direction: column; gap: 12px; }

/* ---------- reward ---------- */
.reward { position: relative; display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; padding-top: 8px; }
.reward-stars { font-size: 56px; letter-spacing: 6px; }
.reward-msg { font-family: var(--font-display); font-weight: 600; font-size: 24px; }
.reward-sub { font-size: 18px; color: var(--ink-soft); }
.unlock-note { background: var(--card); border: 3px dashed var(--accent); border-radius: 14px; padding: 8px 14px; font-weight: 700; }
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 2px; animation: fall 2.6s linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ---------- grown-ups ---------- */
.gate { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.gate-q { font-family: var(--font-display); font-size: 30px; font-weight: 700; }
.gate-entry { min-width: 140px; min-height: 56px; border: 3px solid var(--gold); border-radius: 12px; background: var(--card); font-size: 30px; text-align: center; padding: 6px; font-variant-numeric: tabular-nums; }
.numpad { display: grid; grid-template-columns: repeat(3, 72px); gap: 10px; }
.numpad button { min-height: 60px; border: 3px solid var(--gold); border-radius: 14px; background: var(--card); font-size: 26px; font-weight: 700; }
.numpad .ok { background: var(--green); border-color: var(--green-deep); color: #fff; }
.grown { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 16px; display: flex; flex-direction: column; gap: 14px; }
.grown h1 { font-size: 26px; font-family: var(--font-display); }
.grown section { background: var(--card); border-radius: 14px; padding: 14px 16px; border: 2px solid #f0dfb5; display: flex; flex-direction: column; gap: 8px; }
.grown h2 { font-size: 18px; font-family: var(--font-display); font-weight: 600; }
.grown table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.grown th, .grown td { text-align: left; padding: 6px 8px 6px 0; border-bottom: 1px solid #f2e7cf; vertical-align: top; }
.grown th { font-weight: 600; color: var(--ink-soft); font-size: 14px; }
.table-wrap { overflow-x: auto; }
.muted { color: var(--ink-soft); }
.kind-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; }
.meter { grid-column: 1 / -1; grid-row: 2; height: 12px; background: #f2e7cf; border-radius: 6px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--green); }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 90px; border-bottom: 2px solid #f2e7cf; }
.bars span { flex: 1; background: var(--blue); border-radius: 3px 3px 0 0; min-height: 2px; }
.bar-labels { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-soft); }
.grown-btn { min-height: 48px; border-radius: 10px; border: 2px solid var(--gold-deep); background: #fff7df; padding: 8px 14px; font-weight: 600; font-size: 16px; }
.grown-btn.danger { border-color: #c0392b; color: #a12e22; background: #fff1ef; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.grown textarea { width: 100%; min-height: 90px; font: 14px/1.4 ui-monospace, Consolas, monospace; border: 2px solid #e6d3a8; border-radius: 10px; padding: 8px; word-break: break-all; }
.notice { font-weight: 600; }
.notice.error { color: #a12e22; }
.notice.ok { color: var(--green-deep); }
.confirm-box { border: 2px dashed #c0392b; border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }

@media (prefers-reduced-motion: reduce) {
  .wiggle, .confetti i { animation: none; }
  .confetti { display: none; }
}

/* ---------- players ---------- */
.player-chip { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center; }
.player-badge {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: var(--tap); padding: 6px 14px; border-radius: 14px;
  background: var(--player); color: #fff;
  font-family: var(--font-display); font-weight: 600; font-size: 18px;
}
.switch-btn {
  min-height: var(--tap); padding: 6px 12px; border: 0; background: none;
  color: var(--ink-soft); font-size: 15px; text-decoration: underline;
}
.who-list { display: grid; gap: 14px; max-width: 420px; width: 100%; margin: 0 auto; }
.who-btn {
  display: flex; align-items: center; gap: 14px;
  min-height: 72px; padding: 10px 20px; border: 0; border-radius: 20px;
  background: var(--player); color: #fff; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.18);
  font-family: var(--font-display); font-weight: 700; font-size: 26px; text-align: left;
}
.who-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.18); }
.who-animal { font-size: 40px; }
.who-name { min-width: 0; overflow-wrap: anywhere; }
.setup { display: grid; gap: 16px; justify-items: center; text-align: center; max-width: 420px; margin: 0 auto; }
.setup-title { font-family: var(--font-display); font-size: 28px; color: var(--title); }
.setup-emoji { font-size: 40px; letter-spacing: 6px; }
@media (max-width: 520px) {
  .topbar .player-chip { order: 3; flex-basis: 100%; }
}

/* ---------- grown-ups: players ---------- */
.player-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.player-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.player-form { display: flex; flex-direction: column; gap: 8px; }
.field-label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.name-input { min-height: 48px; font-size: 18px; border: 2px solid #e6d3a8; border-radius: 10px; padding: 8px 10px; max-width: 320px; }
.animal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px; max-width: 480px; }
.animal-btn { min-height: 52px; font-size: 28px; border: 2px solid #e6d3a8; border-radius: 12px; background: #fff; }
.color-row { display: flex; flex-wrap: wrap; gap: 6px; }
.color-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 48px; padding: 6px 10px; border: 2px solid #e6d3a8; border-radius: 12px; background: #fff; font-weight: 600; }
.swatch { width: 22px; height: 22px; border-radius: 50%; background: var(--swatch); }
.animal-btn[aria-pressed="true"], .color-btn[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--gold); }
.player-pick { background: var(--player); color: #fff; border-color: transparent; }
.stats-area { display: flex; flex-direction: column; gap: 14px; }
.stats-body { display: flex; flex-direction: column; gap: 14px; }
.pick-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.pick-chip { min-height: 48px; padding: 6px 14px; border-radius: 14px; border: 2px solid var(--player); background: #fff; font-weight: 600; font-size: 16px; }
.pick-chip[aria-pressed="true"] { background: var(--player); color: #fff; }

/* ---------- grown-ups: syncing ---------- */
.sync-status { font-weight: 600; }
.link-input { width: 100%; min-height: 48px; font: 14px/1.4 ui-monospace, Consolas, monospace; border: 2px solid #e6d3a8; border-radius: 10px; padding: 8px; }
.qr-figure { margin: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.qr { width: 220px; max-width: 100%; }
.qr svg { display: block; width: 100%; height: auto; }

/* ---------- joining a family ---------- */
.join { display: flex; flex-direction: column; align-items: center; gap: 18px; text-align: center; }
.join-msg { font-family: var(--font-display); font-size: 22px; max-width: 26ch; }
.join-grown { text-align: left; width: 100%; max-width: 520px; }
.match-row { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.match-select { min-height: 48px; font-size: 17px; border: 2px solid #e6d3a8; border-radius: 10px; padding: 6px 8px; background: #fff; max-width: 320px; }
