:root {
  --bg: #fff8f0;
  --surface: #ffffff;
  --surface-2: #fff1e2;
  --text: #1e1b3a;
  --muted: #5c5778;
  --border: #ecd9c6;
  --accent: #ff7a59;
  --accent-deep: #e85a38;
  --blue: #0284c7;
  --indigo: #312e81;
  --night: #15122d;
  --night-2: #241f4d;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --amber-bg: #fef3c7;
  --amber: #b45309;
  --red-bg: #fee2e2;
  --red: #b91c1c;
  --shadow: 0 10px 30px rgba(30, 27, 58, 0.08);
  --radius: 20px;
  --font-display: "Fredoka", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-body: "Andika", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

[data-theme="dark"] {
  --bg: #15122d;
  --surface: #211d42;
  --surface-2: #2b2656;
  --text: #f8f5ff;
  --muted: #c1bce0;
  --border: #3a346e;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.screen {
  min-height: 100vh;
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}
.screen[hidden] { display: none !important; }
.screen.night {
  max-width: 100%;
  background: radial-gradient(circle at 25% 15%, #2e2868 0%, #15122d 65%);
  color: #f8f5ff;
  padding: 24px 18px;
  align-items: center;
  justify-content: center;
}

/* Welcome Screen */
.welcome-card {
  width: 100%;
  max-width: 520px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 26px;
  padding: 28px 24px;
  backdrop-filter: blur(8px);
}
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(253, 224, 71, 0.18);
  color: #fde047;
  border: 1px solid rgba(253, 224, 71, 0.4);
}
.wordmark {
  font-family: var(--font-display);
  font-size: 34px;
  line-height: 1.1;
  margin: 0 0 6px;
}
.brand-tag { margin: 0 0 18px; color: #cbd5e1; font-size: 15px; }
.promises { list-style: none; padding: 0; margin: 0 0 22px; display: grid; gap: 12px; }
.promises li {
  display: flex; align-items: flex-start; gap: 12px;
  background: rgba(255, 255, 255, 0.06);
  padding: 11px 13px;
  border-radius: 14px;
}
.promises .pi { font-size: 22px; line-height: 1.2; }
.promises b { display: block; font-family: var(--font-display); font-size: 15.5px; }
.promises small { color: #cbd5e1; font-size: 13px; }
.welcome-actions { display: grid; gap: 10px; }
.fine { font-size: 12px; color: #cbd5e1; text-align: center; margin: 14px 0 0; }

/* Buttons & Form Inputs */
.btn {
  border: 0;
  cursor: pointer;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  padding: 13px 20px;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.12s ease, opacity 0.15s ease;
  text-decoration: none;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, #ff8a65, #ff5e4d); color: #ffffff; box-shadow: 0 6px 18px rgba(255, 102, 71, 0.32); }
.btn.secondary { background: #312e81; color: #ffffff; }
.btn.ghost { background: var(--surface); color: var(--text); border: 1.5px solid var(--border); }
.btn.ghost-night { background: rgba(255, 255, 255, 0.12); color: #ffffff; border: 1px solid rgba(255, 255, 255, 0.25); }
.btn.small { padding: 8px 14px; font-size: 13.5px; border-radius: 12px; }
.text-btn { background: none; border: 0; color: inherit; cursor: pointer; font: inherit; text-decoration: underline; padding: 6px; opacity: 0.85; }
.link { background: none; border: 0; color: var(--accent-deep); font-weight: 700; cursor: pointer; font-family: var(--font-display); font-size: 14.5px; }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.icon-btn.spacer { border-color: transparent; background: transparent; pointer-events: none; }

/* Header Bar & Scroll */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 18px 10px;
}
.scroll { flex: 1; padding: 8px 18px 28px; overflow-y: auto; }
.display { font-family: var(--font-display); font-size: 25px; line-height: 1.2; margin: 0 0 6px; }
.display.small { font-size: 20px; }
.center { text-align: center; }
.lede { color: var(--muted); margin: 0 0 18px; font-size: 14.5px; }
.group-title { font-family: var(--font-display); font-size: 14px; color: var(--muted); margin: 18px 0 8px; text-transform: uppercase; letter-spacing: 0.4px; }

/* Child Switcher (#who) */
.who-body { width: 100%; max-width: 680px; text-align: center; }
.who-title { font-family: var(--font-display); font-size: 28px; margin: 8px 0 22px; }
.who-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; }
.who-card {
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid var(--kid, #8fc8ff);
  border-radius: 22px;
  padding: 20px 12px;
  color: #ffffff;
  cursor: pointer;
  display: grid; gap: 8px; place-items: center;
  font-family: var(--font-display);
}
.who-card:hover { background: rgba(255, 255, 255, 0.14); }
.who-card.add { border-style: dashed; border-color: rgba(255, 255, 255, 0.4); }
.who-avatar { font-size: 42px; line-height: 1; }
.who-card small { font-family: var(--font-body); font-size: 12px; color: #cbd5e1; }

/* Onboard Form */
.onboard-body { width: 100%; max-width: 520px; margin: 0 auto; padding: 6px 18px 20px; flex: 1; overflow-y: auto; }
.avatar-preview {
  width: 78px; height: 78px; margin: 4px auto 12px;
  border-radius: 50%;
  background: var(--kid, #ffd36b);
  display: grid; place-items: center;
  font-size: 40px;
  box-shadow: var(--shadow);
}
.text-field { display: grid; gap: 6px; margin-bottom: 14px; }
.text-field span, .field-label { font-family: var(--font-display); font-weight: 600; font-size: 14.5px; margin: 12px 0 6px; display: block; }
input, select {
  width: 100%;
  font-family: var(--font-body);
  font-size: 16px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.age-row { display: flex; flex-wrap: wrap; gap: 8px; }
.age-chip {
  min-width: 44px; height: 42px; padding: 0 10px;
  border-radius: 12px; border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text);
  font-family: var(--font-display); font-weight: 600; cursor: pointer;
}
.age-chip[aria-checked="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.band-callout {
  margin-top: 10px; padding: 10px 12px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 13px; color: var(--text);
}
.avatar-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.avatar {
  padding: 12px 8px; border-radius: 14px; border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
  display: grid; place-items: center; gap: 4px; font-family: var(--font-display);
}
.avatar .e { font-size: 28px; }
.avatar[aria-checked="true"] { border-color: var(--accent); background: var(--surface-2); }
.cta-bar {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 12px 18px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

/* Home */
.me-chip {
  display: flex; align-items: center; gap: 10px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 6px 14px 6px 8px;
  border-radius: 999px;
  cursor: pointer;
  text-align: left;
}
.me-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--kid, #8fc8ff);
  display: grid; place-items: center; font-size: 22px;
}
.me-text small { display: block; font-size: 11.5px; color: var(--muted); line-height: 1.1; }
.me-text b { font-family: var(--font-display); font-size: 15px; }
.bar-right { display: flex; align-items: center; gap: 8px; }
.quota-pill {
  font-size: 12px; font-weight: 700;
  padding: 6px 11px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); white-space: nowrap;
}
.mode-banner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 14px;
  margin-bottom: 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  font-size: 13.5px;
}
.create-card {
  width: 100%; border: 0; text-align: left; cursor: pointer;
  background: linear-gradient(135deg, #ff7a59, #ff584b);
  color: #fff; border-radius: 22px; padding: 18px;
  display: flex; align-items: center; gap: 14px;
  box-shadow: 0 12px 24px rgba(255, 98, 75, 0.25);
  margin-bottom: 12px;
}
.create-art { font-size: 26px; display: flex; gap: 3px; }
.create-copy { flex: 1; }
.create-copy b { display: block; font-family: var(--font-display); font-size: 20px; }
.create-copy small { opacity: 0.92; font-size: 13.5px; }
.create-go { font-size: 24px; font-weight: 700; }

.surprise-card {
  width: 100%; border: 1.5px solid var(--border); text-align: left; cursor: pointer;
  background: var(--surface); color: var(--text);
  border-radius: 18px; padding: 13px 16px;
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 18px;
}
.surprise-card .dice { font-size: 26px; }
.surprise-card b { display: block; font-family: var(--font-display); font-size: 16px; }
.surprise-card small { color: var(--muted); font-size: 13px; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin: 16px 0 10px; }
.section-head h2 { font-family: var(--font-display); font-size: 19px; margin: 0; }
.shelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 14px;
}
.book-card {
  position: relative;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 18px;
  padding: 10px;
  display: flex; flex-direction: column; gap: 6px;
  box-shadow: var(--shadow);
}
.book-card .cover {
  height: 112px;
  border-radius: 12px;
  background: linear-gradient(135deg, #1e1b4b, #0284c7);
  color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  cursor: pointer; padding: 8px; text-align: center; position: relative; overflow: hidden;
}
.book-card .cover-emoji { font-size: 34px; line-height: 1; }
.book-card .badge {
  font-size: 10.5px; font-weight: 700;
  background: rgba(255, 255, 255, 0.2); padding: 2px 8px; border-radius: 999px;
}
.book-card b { font-family: var(--font-display); font-size: 14.5px; line-height: 1.25; }
.book-card small { font-size: 12px; color: var(--muted); }
.book-card .del {
  position: absolute; top: 6px; right: 6px; z-index: 2;
  width: 24px; height: 24px; border-radius: 50%; border: 0;
  background: rgba(15, 23, 42, 0.72); color: #fff; cursor: pointer; font-size: 12px;
}
.book-card .series-tag {
  font-size: 11px; font-weight: 700; color: var(--blue);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.book-card .sequel-btn {
  margin-top: auto; width: 100%; padding: 6px 10px; font-size: 12.5px; border-radius: 10px;
}
.sequel-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  background: var(--amber-bg); color: var(--amber); border: 1.5px solid #f59e0b;
  border-radius: 14px; padding: 10px 14px; margin-bottom: 12px; font-size: 13.5px;
}

.empty-shelf {
  text-align: center; padding: 22px 16px;
  border: 1.5px dashed var(--border); border-radius: 18px;
  background: var(--surface);
}
.empty-shelf .es-art { font-size: 32px; display: block; margin-bottom: 6px; }

/* Wizard */
.dots { display: flex; gap: 6px; }
.dots i { width: 10px; height: 10px; border-radius: 999px; background: var(--border); display: block; }
.dots i.done { background: #16a34a; }
.dots i.on { width: 24px; background: var(--accent); }
.wiz-head { padding: 4px 18px 8px; }
.eyebrow { margin: 0; font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--accent-deep); letter-spacing: 0.5px; }
.type-list { display: grid; gap: 10px; }
.type-card {
  width: 100%; border: 1.5px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 18px; padding: 14px; cursor: pointer;
  display: flex; align-items: center; gap: 12px; text-align: left;
}
.type-card[aria-pressed="true"] { border-color: var(--accent); background: var(--surface-2); }
.type-card .bubble { width: 44px; height: 44px; border-radius: 14px; background: var(--surface-2); display: grid; place-items: center; font-size: 24px; }
.type-card b { display: block; font-family: var(--font-display); font-size: 16.5px; }
.type-card small { color: var(--muted); font-size: 13px; }
.type-card .chev { margin-left: auto; font-size: 22px; color: var(--muted); }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(145px, 1fr)); gap: 10px; }
.tile {
  border: 1.5px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 16px; padding: 12px 10px; cursor: pointer;
  display: grid; place-items: center; gap: 4px; text-align: center;
}
.tile .e { font-size: 26px; }
.tile b { font-family: var(--font-display); font-size: 14px; line-height: 1.2; }
.tile small { font-size: 11.5px; color: var(--muted); }
.tile[aria-pressed="true"] { border-color: var(--accent); background: var(--surface-2); }
.tile.wide { grid-column: 1 / -1; grid-auto-flow: column; justify-content: center; gap: 8px; }

.segmented { display: flex; flex-wrap: wrap; gap: 6px; background: var(--surface-2); padding: 5px; border-radius: 14px; margin-bottom: 12px; }
.segmented button {
  flex: 1; min-width: 80px; border: 0; background: transparent; color: var(--text);
  padding: 9px 10px; border-radius: 10px; cursor: pointer; font-family: var(--font-display); font-weight: 600; font-size: 13.5px;
}
.segmented button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08); }

.switch-row {
  width: 100%; border: 1.5px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 14px; padding: 11px 14px; margin-bottom: 10px;
  display: flex; align-items: center; justify-content: space-between; cursor: pointer; font-family: inherit;
}
.summary-box {
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 16px;
  padding: 14px; margin-top: 14px; font-size: 14.5px;
}
.guardrail-notice {
  margin-top: 10px; padding: 11px 13px; border-radius: 12px; font-size: 13.5px;
}
.guardrail-notice.redirect { background: var(--amber-bg); color: var(--amber); border: 1px solid #f59e0b; }
.guardrail-notice.blocked { background: var(--red-bg); color: var(--red); border: 1px solid #ef4444; }
.guardrail-notice.ok { background: var(--green-bg); color: var(--green); border: 1px solid #22c55e; }

/* Loading Screen */
.loading-screen { align-items: center; justify-content: center; padding: 28px 20px; text-align: center; }
.loading-stage { position: relative; height: 95px; width: 160px; margin-bottom: 14px; display: grid; place-items: center; }
.book-anim { font-size: 52px; animation: bob 1.8s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.loading-bar { width: 100%; max-width: 360px; height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 12px auto 16px; }
#loading-fill { height: 100%; width: 10%; background: linear-gradient(90deg, #ff7a59, #38bdf8); transition: width 0.4s ease; }
.stage-list { width: 100%; max-width: 420px; text-align: left; display: grid; gap: 6px; margin: 8px auto 18px; }
.stage-item {
  display: flex; align-items: center; gap: 8px; font-size: 13.5px;
  padding: 7px 11px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border);
  opacity: 0.55;
}
.stage-item.active { opacity: 1; border-color: var(--blue); font-weight: 700; }
.stage-item.done { opacity: 1; border-color: var(--green); background: var(--green-bg); color: #14532d; }

/* Reader */
.reader { max-width: 1040px; }
.progress { flex: 1; height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
#progress-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.25s ease; }
.stage { flex: 1; display: flex; flex-direction: column; padding: 6px 16px 14px; gap: 10px; }
.comic-frame {
  width: 100%; max-width: 780px; margin: 0 auto;
  border-radius: 18px; overflow: hidden; border: 3px solid #0f172a;
  box-shadow: var(--shadow); background: #fff;
}
.comic-svg, .puzzle-svg { display: block; width: 100%; height: auto; }
.caption-strip {
  max-width: 780px; margin: 0 auto; width: 100%;
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 16px;
  padding: 12px 16px; font-size: 17px; text-align: center;
}
.word { cursor: pointer; padding: 1px 2px; border-radius: 5px; }
.word.tricky { text-decoration: underline wavy var(--accent); text-underline-offset: 4px; font-weight: 700; }
.word.on { background: #fde047; color: #0f172a; }

.lab-wrap {
  max-width: 820px; width: 100%; margin: 0 auto;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: 20px; padding: 18px; box-shadow: var(--shadow);
}
.recap-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; margin-top: 12px; }
.recap-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 12px; }
.recap-card b { display: block; font-family: var(--font-display); margin-bottom: 4px; color: var(--indigo); }
[data-theme="dark"] .recap-card b { color: #fde047; }
.quiz-item { border: 1px solid var(--border); border-radius: 14px; padding: 12px; margin-bottom: 10px; }
.quiz-opts { display: grid; gap: 6px; margin-top: 8px; }
.quiz-opt {
  text-align: left; border: 1.5px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 12px; border-radius: 10px; cursor: pointer; font-family: inherit;
}
.quiz-opt.correct { background: var(--green-bg); color: #14532d; border-color: #16a34a; font-weight: 700; }
.quiz-opt.wrong { background: var(--red-bg); color: #7f1d1d; border-color: #ef4444; }
.reader-controls {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 10px 18px 18px;
}
.round {
  border: 1.5px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; height: 48px; min-width: 48px; padding: 0 18px;
  font-family: var(--font-display); font-size: 16px; font-weight: 600; cursor: pointer;
}
.round.play { background: var(--accent); color: #fff; border-color: var(--accent); }
.round:disabled { opacity: 0.4; cursor: not-allowed; }

/* Compiled Backend Book Frame */
.compiled-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 8px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.compiled-frame {
  flex: 1; width: 100%; min-height: 76vh; border: 0; background: #fff;
}

/* Modals & Toast */
dialog.sheet {
  border: 0; border-radius: 22px; padding: 0; max-width: 480px; width: calc(100% - 24px);
  background: var(--surface); color: var(--text); box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
}
dialog::backdrop { background: rgba(15, 23, 42, 0.55); }
.sheet-body { padding: 22px; display: grid; gap: 12px; }
.child-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border: 1.5px solid var(--border); border-radius: 14px; padding: 9px 12px;
}
.child-row.on { border-color: var(--accent); background: var(--surface-2); }
.child-pick { border: 0; background: none; color: inherit; display: flex; align-items: center; gap: 8px; cursor: pointer; font: inherit; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 14px; z-index: 9999; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
  max-width: calc(100% - 24px); text-align: center;
}

@media print {
  .bar, .reader-controls, .compiled-toolbar { display: none !important; }
  .screen { max-width: 100%; }
}

.footer-links {
  margin: 12px 0 0;
  text-align: center;
  font-size: 12px;
  color: #cbd5e1;
}
.footer-links a {
  color: #e0f2fe;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.legal-shell {
  min-height: 100vh;
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 18px 48px;
}
.legal-back {
  display: inline-block;
  margin-bottom: 14px;
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--accent-deep);
  text-decoration: none;
}
.legal-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 22px;
  padding: 26px 24px;
  box-shadow: var(--shadow);
}
.legal-card h1 {
  font-family: var(--font-display);
  font-size: 28px;
  margin: 10px 0 6px;
}
.legal-card h2 {
  font-family: var(--font-display);
  font-size: 18px;
  margin: 20px 0 6px;
}
.legal-card p, .legal-card ul {
  color: var(--text);
  margin: 0 0 10px;
}
.legal-card ul {
  padding-left: 20px;
  display: grid;
  gap: 6px;
}
