* { box-sizing: border-box; }
html { background: var(--ground); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.4;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--text); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

#app {
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(24px + env(safe-area-inset-top)) var(--pad) calc(104px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
}
#app.no-tabs { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
#app.flush { padding: 0; gap: 0; }

/* Type */
.h1 { font-family: var(--font-head); font-size: 26px; line-height: 30px; font-weight: 700; }
.h1.big { font-size: 28px; line-height: 34px; }
.h2 { font-family: var(--font-head); font-size: 18px; line-height: 24px; font-weight: 700; }
.label { font-size: 14px; line-height: 20px; font-weight: 800; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; line-height: 18px; }
.center { text-align: center; }

/* Layout helpers */
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack.tight { gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 0; min-width: 0; }
.push { margin-top: auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }

/* Colour fills (dark ink on every bright fill) */
.bg-sky { background: var(--sky); color: var(--ink); }
.bg-green { background: var(--green); color: var(--ink); }
.bg-pink { background: var(--pink); color: var(--ink); }
.bg-amber { background: var(--amber); color: var(--ink); }
.bg-lilac { background: var(--lilac); color: var(--ink); }
.bg-raised { background: var(--raised); color: var(--text); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border: 0; border-radius: 999px;
  background: var(--raised); color: var(--text);
  font-weight: 800; font-size: 14px; line-height: 1.2; text-align: center;
}
.btn:disabled { opacity: .6; cursor: default; }
.btn.primary { background: var(--orange); color: var(--ink-orange); }
.btn.dark { background: var(--ink); color: var(--text); }
.btn.light { background: var(--text); color: var(--ink); }
.btn.ghost { background: transparent; border: 2px solid var(--outline); }
.btn.dashed { background: transparent; border: 2px dashed var(--outline); min-height: 52px; font-size: 15px; }
.btn.danger { background: transparent; border: 2px solid var(--pink); color: var(--pink); }
.btn.big { min-height: 58px; font-family: var(--font-head); font-size: 19px; }
.btn.block { width: 100%; }
.btn.icon { width: 44px; min-width: 44px; height: 44px; padding: 0; background: var(--card); }
.btn.icon.lg { width: 48px; min-width: 48px; height: 48px; background: var(--raised); }
.btn.icon.clear { background: transparent; }
.btn.icon.dark { background: var(--ink); }
.btn.icon.danger { background: transparent; }
.btn.icon.loved { background: var(--pink); color: var(--ink); }
.btn.pill { min-width: 64px; padding: 0 12px; font-size: 13px; gap: 4px; }

/* Chips, segmented, tiles */
.chip {
  min-height: 44px; padding: 0 16px; border: 0; border-radius: 22px;
  background: var(--card); color: var(--text); font-weight: 700; font-size: 14px;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip[aria-pressed="true"] { background: var(--green); color: var(--ink); font-weight: 800; }
.chip.filter[aria-pressed="true"] { background: var(--text); color: var(--ink); }

.seg { min-height: 52px; border-radius: 26px; background: var(--card); padding: 4px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.seg button { border: 0; border-radius: 22px; background: transparent; font-weight: 700; font-size: 15px; min-height: 44px; }
.seg button[aria-pressed="true"] { background: var(--text); color: var(--ink); font-weight: 800; }

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.tile {
  height: 88px; border: 0; border-radius: var(--r-tile); padding: 4px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  font-weight: 800; font-size: 12.5px; line-height: 1.15; text-align: center;
}
.tiles.pick { gap: 8px; }
.tiles.pick .tile { height: 78px; border-radius: 20px; gap: 4px; }
.tile[aria-pressed="true"] { box-shadow: inset 0 0 0 3px var(--text), 0 0 0 2px var(--ground), 0 0 0 4px var(--text); }

.kidchip {
  min-height: 56px; padding: 0 16px 0 6px; border-radius: 28px; border: 2px solid var(--line);
  background: var(--card); display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 15px;
}
.kidchip[aria-pressed="true"] { border-color: var(--orange); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-head); font-weight: 800; font-size: 18px;
}
.avatar.lg { width: 52px; height: 52px; font-size: 24px; }
.avatar.md { width: 48px; height: 48px; font-size: 20px; }
.avatar.inverse { background: var(--ink); }
.add-round { width: 56px; height: 56px; border-radius: 50%; border: 2px dashed var(--outline); color: var(--muted); display: inline-flex; align-items: center; justify-content: center; }

/* Cards */
.card { border-radius: var(--r-card); background: var(--card); padding: 12px; }
.card.pad { padding: 16px; border-radius: 26px; }
.rowcard { display: flex; align-items: center; gap: 12px; min-height: 88px; }
.thumb { width: 64px; height: 64px; border-radius: 18px; overflow: hidden; flex-shrink: 0; }
.thumb.lg { width: 72px; height: 72px; }
.thumb svg, .cover svg, .tilecover svg { width: 100%; height: 100%; display: block; }
.title { font-weight: 800; font-size: 15px; line-height: 20px; display: block; }
.tag { display: inline-block; margin-top: 4px; padding: 2px 10px; border-radius: 10px; font-size: 11px; line-height: 16px; font-weight: 800; }
.round-play { width: 48px; height: 48px; border-radius: 50%; background: var(--orange); color: var(--ink-orange); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; border: 0; }

.hero { border-radius: var(--r-hero); padding: 20px; min-height: 172px; display: flex; justify-content: space-between; gap: 8px; overflow: hidden; }
.hero .copy { display: flex; flex-direction: column; justify-content: space-between; gap: 16px; align-items: flex-start; }
.hero h2 { font-family: var(--font-head); font-size: 24px; line-height: 28px; font-weight: 800; }
.hero p { margin-top: 4px; font-size: 14px; line-height: 19px; }
.hero svg.art { flex-shrink: 0; align-self: center; }

.streak { display: inline-flex; align-items: center; gap: 6px; height: 44px; padding: 0 14px; border-radius: 22px; background: var(--amber); color: var(--ink); font-weight: 800; }

.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tilecover { height: 100px; border-radius: 22px; overflow: hidden; position: relative; display: block; }
.tilecover span { position: absolute; left: 10px; right: 10px; bottom: 10px; background: var(--ink); color: var(--text); border-radius: 12px; padding: 5px 10px; font-size: 12px; line-height: 16px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.cover { height: 140px; border-radius: 26px; overflow: hidden; flex-shrink: 0; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 8px; }
.input {
  width: 100%; min-height: 52px; border-radius: 18px; border: 2px solid var(--line);
  background: var(--card); color: var(--text); padding: 0 16px; font-weight: 600; font-size: 15px;
}
.input::placeholder { color: var(--read); }
.search { position: relative; }
.search svg { position: absolute; left: 16px; top: 16px; color: var(--muted); }
.search .input { border-radius: 26px; border-color: transparent; padding-left: 46px; }
.swatches { display: flex; gap: 10px; }
.swatches label { position: relative; }
.swatches input { position: absolute; opacity: 0; inset: 0; }
.swatches span { display: block; width: 44px; height: 44px; border-radius: 50%; }
.swatches input:checked + span { box-shadow: 0 0 0 3px var(--ground), 0 0 0 6px var(--text); }
.swatches input:focus-visible + span { outline: 3px solid var(--text); outline-offset: 8px; }

/* Bottom navigation */
.nav {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: min(440px, calc(100% - 40px)); height: 64px; padding: 8px;
  background: var(--card); border-radius: 32px;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: 0 0 0 6px var(--ground);
  z-index: 5;
}
.nav a { min-width: 64px; height: 48px; border-radius: 24px; color: var(--muted); display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 800; font-size: 14px; }
.nav a span { display: none; }
.nav a[aria-current="page"] { background: var(--orange); color: var(--ink-orange); padding: 0 20px; }
.nav a[aria-current="page"] span { display: inline; }

/* Reader */
.story { font-size: 17px; line-height: 28px; }
.story p { margin: 0 0 12px; }
.story .s { border-radius: 8px; padding: 3px 0; cursor: pointer; }
.story .s.done { color: var(--read); }
.story .s.now { background: var(--amber); color: var(--ink); padding: 3px 4px; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.moral { border-radius: 22px; background: var(--card); padding: 14px 16px; }
.player { position: sticky; bottom: calc(12px + env(safe-area-inset-bottom)); border-radius: 28px; background: var(--card); padding: 16px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 0 0 8px var(--ground); z-index: 4; }
.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.bar > div { height: 100%; border-radius: 4px; background: var(--orange); width: 0; }
.bar-meta { margin-top: 6px; display: flex; justify-content: space-between; font-size: 12px; line-height: 16px; font-weight: 700; color: var(--muted); }
.controls { display: flex; align-items: center; justify-content: space-between; }
.playbtn { width: 68px; height: 68px; border-radius: 50%; border: 0; background: var(--orange); color: var(--ink-orange); display: inline-flex; align-items: center; justify-content: center; }
.opt { min-height: 48px; border-radius: 18px; border: 0; background: var(--raised); display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; font-size: 13px; padding: 0 8px; }
.opt[aria-pressed="true"] { background: var(--text); color: var(--ink); }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--pink); display: inline-block; }

.dim { position: fixed; inset: 0; background: #000; color: #55585f; z-index: 20; display: flex; align-items: flex-end; justify-content: center; padding: 40px; border: 0; font-size: 14px; font-weight: 700; }

/* Quiz */
.quiz-head { background: var(--green); color: var(--ink); border-radius: 0 0 32px 32px; padding: calc(20px + env(safe-area-inset-top)) 20px 22px; display: flex; flex-direction: column; gap: 14px; }
.quiz-head.miss { background: var(--pink); }
.quiz-body { padding: 18px 20px 20px; display: flex; flex-direction: column; gap: 16px; flex: 1 1 auto; }
.steps { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 8px; }
.steps i { height: 8px; border-radius: 4px; background: rgba(22, 23, 28, .35); }
.steps i.on { background: var(--ink); }
.answers { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.answer { position: relative; min-height: 112px; border-radius: 24px; border: 3px solid transparent; background: var(--card); padding: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; font-weight: 800; font-size: 15px; line-height: 19px; text-align: center; }
.answer .letter { width: 36px; height: 36px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-family: var(--font-head); font-size: 18px; }
.answer.right { border-color: var(--green); }
.answer.wrong { border-color: var(--pink); }
.answer .mark { position: absolute; top: -10px; right: -8px; width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--ink); }
.answer.right .mark { background: var(--green); }
.answer.wrong .mark { background: var(--pink); }
.darkpill { display: inline-flex; align-items: center; gap: 6px; height: 44px; padding: 0 14px; border-radius: 22px; background: var(--ink); color: var(--amber); font-weight: 800; }

/* Reward */
.reward { background: var(--amber); color: var(--ink); min-height: 100dvh; display: flex; flex-direction: column; }
.reward .badge { height: 280px; flex-shrink: 0; padding-top: env(safe-area-inset-top); }
.reward .badge svg { width: 100%; height: 100%; display: block; }
.reward .sheet { flex: 1 1 auto; background: var(--ground); color: var(--text); border-radius: 36px 36px 0 0; padding: 28px 20px calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 18px; }
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; text-align: center; font-size: 12px; font-weight: 800; color: var(--muted); }
.week div { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.week span { width: 38px; height: 38px; border-radius: 50%; border: 2px dashed var(--outline); display: flex; align-items: center; justify-content: center; }
.week .done span { border: 0; background: var(--amber); color: var(--ink); }
.week .today { color: var(--text); }
.week .today.done span { background: var(--orange); color: var(--ink-orange); border: 3px solid var(--text); }
.sticker { width: 56px; height: 56px; border-radius: 20px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.stickers { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.stickers .sticker { width: 100%; height: 64px; }
.stickers .sticker.locked { background: transparent; border: 2px dashed var(--outline); color: var(--outline); }

/* Family */
.kidcard { border-radius: 26px; padding: 14px; min-height: 186px; display: flex; flex-direction: column; gap: 8px; }
.kidcard h3 { font-family: var(--font-head); font-size: 22px; line-height: 26px; font-weight: 800; }
.kidcard .edit { min-height: 44px; padding: 0 14px; border-radius: 22px; border: 2px solid var(--ink); background: transparent; color: var(--ink); font-weight: 800; font-size: 13px; }

/* Dialog, toast */
dialog { border: 0; border-radius: 28px; background: var(--card); color: var(--text); padding: 20px; width: min(440px, calc(100% - 32px)); max-height: calc(100dvh - 32px); }
dialog::backdrop { background: rgba(0, 0, 0, .7); }
dialog form { display: flex; flex-direction: column; gap: 14px; }
dialog .input { background: var(--raised); }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 30;
  max-width: min(420px, calc(100% - 40px)); padding: 12px 18px; border-radius: 18px;
  background: var(--text); color: var(--ink); font-weight: 800; font-size: 14px; text-align: center;
}
.empty { border-radius: 26px; border: 2px dashed var(--outline); padding: 24px 16px; text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; }

@media (max-width: 359px) {
  .tiles { gap: 6px; }
  .tile { font-size: 11.5px; }
  .kidcard { min-height: 0; }
}
@media (prefers-reduced-motion: no-preference) {
  .bar > div { transition: width .3s ease; }
  .btn, .chip, .tile, .answer { transition: transform .1s ease; }
  .btn:active, .chip:active, .tile:active, .answer:active, .playbtn:active { transform: scale(.97); }
}
