:root {
  --ink: #26143f;
  --ink-soft: #665777;
  --primary: #7c3aed;
  --primary-2: #d946ef;
  --accent: #ff8ab6;
  --cyan: #4cc9f0;
  --sun: #ffd166;
  --success: #1f9d72;
  --danger: #be3144;
  --surface: rgba(255,255,255,.90);
  --surface-solid: #fff;
  --line: rgba(84, 45, 125, .14);
  --shadow: 0 22px 70px rgba(62, 34, 93, .14);
  --sidebar: 118px;
  --topbar: 92px;
  --radius-xl: 32px;
  --radius-lg: 24px;
  --radius-md: 18px;
  --font: Inter, ui-rounded, "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; background: #fbf8ff; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 5%, rgba(255, 174, 210, .34), transparent 27%),
    radial-gradient(circle at 88% 10%, rgba(112, 211, 255, .25), transparent 25%),
    linear-gradient(145deg, #fff9fc 0%, #faf6ff 52%, #f2fbff 100%);
}
button, input, select, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 4px solid rgba(124,58,237,.20);
  outline-offset: 3px;
}
img { max-width: 100%; display: block; }
a { color: inherit; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar);
  z-index: 50;
  display: grid;
  grid-template-rows: auto 1fr auto;
  align-items: start;
  gap: 22px;
  padding: 18px 14px 24px;
  background: linear-gradient(180deg, #ffffff 0%, #fff8fd 50%, #f6f2ff 100%);
  border-right: 1px solid var(--line);
  box-shadow: 12px 0 38px rgba(56, 27, 82, .08);
}
.brand-mark {
  width: 86px;
  height: 78px;
  margin: 0 auto;
  display: grid;
  place-items: center;
  border-radius: 24px;
  background: white;
  box-shadow: 0 12px 32px rgba(89, 49, 112, .15);
  overflow: hidden;
}
.brand-mark img { width: 82px; height: 72px; object-fit: contain; }
.sidebar-nav { display: flex; flex-direction: column; gap: 8px; align-self: center; }
.nav-item {
  border: 0;
  background: transparent;
  min-height: 76px;
  width: 88px;
  border-radius: 25px;
  cursor: pointer;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  transition: transform .18s ease, background .18s ease, box-shadow .18s ease, color .18s ease;
}
.nav-item span { font-size: 27px; line-height: 1; }
.nav-item small { font-weight: 850; font-size: 12px; }
.nav-item:hover { transform: translateY(-2px); background: rgba(124,58,237,.08); }
.nav-item.is-active {
  color: white;
  background: linear-gradient(145deg, var(--primary), var(--primary-2));
  box-shadow: 0 16px 30px rgba(139, 54, 206, .28);
}
.parent-nav { align-self: end; margin: 0 auto; }

.app-shell { min-height: 100vh; margin-left: var(--sidebar); }
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  min-height: var(--topbar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px clamp(24px, 4vw, 58px);
  background: rgba(255, 250, 253, .83);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}
.brand-copy { display: grid; gap: 2px; }
.brand-copy strong { font-size: clamp(24px, 2.4vw, 38px); letter-spacing: -.04em; }
.brand-copy span { color: var(--ink-soft); font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.child-chip, .icon-button {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.86);
  box-shadow: 0 10px 28px rgba(74,45,98,.08);
  cursor: pointer;
}
.child-chip { border-radius: 999px; padding: 11px 17px; font-weight: 850; display: flex; gap: 9px; align-items: center; }
.icon-button { width: 48px; height: 48px; border-radius: 16px; font-size: 20px; }

main#app { padding: 34px clamp(24px, 4vw, 58px) 90px; max-width: 1680px; margin: 0 auto; }
.page { animation: pageIn .25s ease both; }
@keyframes pageIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.page-heading { margin-bottom: 24px; }
.page-heading h1 { margin: 3px 0 8px; font-size: clamp(36px, 5vw, 68px); letter-spacing: -.055em; line-height: .98; }
.page-heading p { margin: 0; color: var(--ink-soft); font-size: clamp(17px, 1.4vw, 21px); font-weight: 650; max-width: 860px; line-height: 1.55; }
.eyebrow { display: inline-block; font-size: 12px; font-weight: 950; letter-spacing: .12em; text-transform: uppercase; color: var(--primary); }
.muted { color: var(--ink-soft); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.card-pad { padding: clamp(20px, 2.4vw, 34px); }
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.hero {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: 1.22fr .78fr;
  min-height: 450px;
  background:
    radial-gradient(circle at 22% 12%, rgba(255,255,255,.95), transparent 31%),
    linear-gradient(135deg, rgba(255,236,246,.94), rgba(244,239,255,.94) 52%, rgba(224,249,255,.94));
}
.hero::before, .hero::after { content: ""; position: absolute; border-radius: 50%; filter: blur(3px); opacity: .58; }
.hero::before { width: 180px; height: 180px; background: #ffd5e8; left: -60px; bottom: -58px; }
.hero::after { width: 210px; height: 210px; background: #cbeeff; right: -70px; top: -70px; }
.hero-copy { padding: clamp(28px, 4vw, 58px); z-index: 2; display: flex; flex-direction: column; justify-content: center; }
.hero-copy h1 { margin: 8px 0 14px; max-width: 880px; font-size: clamp(42px, 5.3vw, 82px); line-height: .96; letter-spacing: -.06em; }
.hero-copy p { font-size: clamp(18px, 1.55vw, 23px); color: var(--ink-soft); line-height: 1.5; font-weight: 680; max-width: 760px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 24px; }
.hero-art { position: relative; min-height: 360px; display: grid; place-items: end center; z-index: 1; }
.hero-art img { width: min(94%, 620px); max-height: 430px; object-fit: contain; filter: drop-shadow(0 24px 30px rgba(62,30,78,.18)); }

.button, .button-ghost, .button-soft {
  border: 0;
  border-radius: 16px;
  padding: 13px 21px;
  font-weight: 900;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  transition: transform .17s ease, box-shadow .17s ease, opacity .17s ease;
}
.button { color: white; background: linear-gradient(135deg, var(--primary), var(--primary-2)); box-shadow: 0 13px 26px rgba(129,54,200,.25); }
.button:hover, .button-ghost:hover, .button-soft:hover { transform: translateY(-2px); }
.button-ghost { background: white; border: 1px solid var(--line); }
.button-soft { background: rgba(124,58,237,.09); color: var(--primary); }
.button-danger { background: linear-gradient(135deg, #d64b68, #a61c3c); }
.button-small { padding: 9px 13px; font-size: 13px; border-radius: 13px; }
.button-wide { width: 100%; margin-top: 18px; }
button:disabled { cursor: not-allowed; opacity: .45; transform: none !important; }

.stat-strip { margin-top: 22px; grid-template-columns: repeat(4, 1fr); }
.stat-card { padding: 22px; display: grid; gap: 6px; }
.stat-card strong { font-size: 30px; letter-spacing: -.04em; }
.stat-card span { color: var(--ink-soft); font-weight: 720; }

.section-title { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin: 34px 0 16px; }
.section-title h2 { margin: 0; font-size: clamp(26px, 3vw, 40px); letter-spacing: -.04em; }
.section-title p { margin: 4px 0 0; color: var(--ink-soft); }

.mission-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.mission-card { padding: 20px; cursor: pointer; min-height: 150px; display: grid; align-content: space-between; gap: 16px; transition: transform .2s ease, border-color .2s ease; }
.mission-card:hover { transform: translateY(-5px); border-color: rgba(124,58,237,.35); }
.mission-card .icon { font-size: 34px; }
.mission-card strong { font-size: 17px; line-height: 1.25; }
.mission-card small { color: var(--ink-soft); font-weight: 700; }

.progress-track { height: 12px; background: #eee5fb; border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; min-width: 0; background: linear-gradient(90deg, var(--primary), var(--primary-2), var(--cyan)); border-radius: inherit; transition: width .35s ease; }

.level-tabs { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 24px; }
.level-tab { border: 1px solid var(--line); background: white; border-radius: 999px; padding: 12px 18px; font-weight: 900; cursor: pointer; }
.level-tab.is-active { color: white; background: var(--ink); border-color: var(--ink); }
.subject-grid { grid-template-columns: repeat(3, minmax(0,1fr)); }
.subject-card { position: relative; overflow: hidden; padding: 24px; cursor: pointer; min-height: 226px; display: grid; align-content: space-between; transition: transform .2s ease, box-shadow .2s ease; }
.subject-card:hover { transform: translateY(-6px); box-shadow: 0 26px 70px rgba(62,34,93,.20); }
.subject-icon { width: 58px; height: 58px; border-radius: 19px; display: grid; place-items: center; font-size: 31px; background: linear-gradient(145deg, rgba(124,58,237,.12), rgba(217,70,239,.12)); }
.subject-card h3 { margin: 16px 0 6px; font-size: 24px; }
.subject-card p { margin: 0; color: var(--ink-soft); line-height: 1.45; }
.subject-meta { display: flex; justify-content: space-between; margin-top: 20px; color: var(--ink-soft); font-weight: 800; font-size: 13px; }

.breadcrumbs { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; color: var(--ink-soft); font-weight: 740; margin-bottom: 20px; }
.breadcrumbs button { border: 0; background: none; color: var(--primary); font-weight: 900; cursor: pointer; padding: 0; }
.subject-header { display: grid; grid-template-columns: 1fr auto; gap: 18px; align-items: center; padding: 26px; margin-bottom: 20px; }
.subject-header h1 { margin: 6px 0; font-size: clamp(34px, 4vw, 54px); letter-spacing: -.05em; }
.lesson-list { display: grid; gap: 14px; }
.lesson-row { display: grid; grid-template-columns: auto 1fr auto; gap: 16px; align-items: center; padding: 18px 20px; }
.lesson-index { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 15px; background: #f1eafd; color: var(--primary); font-weight: 950; }
.lesson-row h3 { margin: 0 0 4px; }
.lesson-row p { margin: 0; color: var(--ink-soft); }
.lesson-complete { color: var(--success); font-weight: 900; }

.lesson-layout { grid-template-columns: minmax(0, 1.15fr) minmax(320px, .85fr); align-items: start; }
.lesson-content { padding: 30px; }
.lesson-content h1 { font-size: clamp(34px, 4vw, 56px); letter-spacing: -.05em; margin: 6px 0 18px; }
.lesson-content h2 { margin-top: 30px; }
.lesson-content p, .lesson-content li { line-height: 1.68; font-size: 17px; }
.objective-box, .example-box { border-radius: 20px; padding: 20px; margin: 18px 0; }
.objective-box { background: linear-gradient(135deg, #f6efff, #fff5fa); border: 1px solid #e8d9fb; }
.example-box { background: #eefaff; border: 1px solid #cceef7; }
.exercise-panel { position: sticky; top: calc(var(--topbar) + 20px); padding: 24px; }
.exercise-card { padding: 20px; border: 1px solid var(--line); border-radius: 20px; background: white; margin: 14px 0; }
.exercise-card h4 { margin: 0 0 12px; line-height: 1.4; }
.choice-list { display: grid; gap: 9px; }
.choice-button { border: 1px solid var(--line); background: #fff; padding: 12px 14px; border-radius: 14px; text-align: left; cursor: pointer; font-weight: 750; }
.choice-button:hover { border-color: rgba(124,58,237,.48); background: #faf7ff; }
.choice-button.is-correct { border-color: #4bb894; background: #e9fbf5; }
.choice-button.is-wrong { border-color: #e1788b; background: #fff1f4; }
.solution { margin-top: 12px; padding: 12px 14px; border-radius: 14px; background: #f7f4fb; color: var(--ink-soft); line-height: 1.5; }
.text-answer { width: 100%; min-height: 72px; border: 1px solid var(--line); border-radius: 14px; padding: 12px; resize: vertical; }

.story-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.story-card { overflow: hidden; cursor: pointer; transition: transform .2s ease; }
.story-card:hover { transform: translateY(-5px); }
.story-card img { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; }
.story-card-body { padding: 20px; }
.story-card h3 { margin: 0 0 8px; font-size: 22px; }
.story-card p { color: var(--ink-soft); line-height: 1.5; }
.story-tags { display: flex; gap: 8px; flex-wrap: wrap; }
.tag { padding: 7px 10px; border-radius: 999px; background: #f3ecfc; color: #6f35a8; font-size: 12px; font-weight: 900; }
.generator { padding: 26px; margin-bottom: 26px; }
.form-grid { display: grid; gap: 16px; }
.two-cols { grid-template-columns: repeat(2, minmax(0,1fr)); }
.three-cols { grid-template-columns: repeat(3, minmax(0,1fr)); }
label { display: grid; gap: 7px; font-weight: 820; }
input, select, textarea {
  width: 100%;
  border: 1px solid rgba(73,42,99,.18);
  background: rgba(255,255,255,.92);
  border-radius: 15px;
  padding: 13px 14px;
  color: var(--ink);
}
textarea { resize: vertical; min-height: 108px; }
.form-help { color: var(--ink-soft); font-size: 13px; line-height: 1.5; }
.form-error { color: var(--danger); font-weight: 800; min-height: 1.2em; }

.reader-page { max-width: 1280px; margin: 0 auto; }
.reader-top { display: flex; justify-content: space-between; gap: 14px; align-items: center; margin-bottom: 18px; }
.reader-progress { flex: 1; }
.reader-stage { overflow: hidden; }
.reader-visual { position: relative; background: white; min-height: 460px; }
.reader-visual img { width: 100%; height: 460px; object-fit: cover; }
.reader-page-number { position: absolute; right: 20px; top: 18px; background: rgba(255,255,255,.92); padding: 10px 15px; border-radius: 999px; font-weight: 950; box-shadow: 0 8px 20px rgba(0,0,0,.08); }
.reader-text { padding: 30px clamp(25px, 5vw, 68px) 38px; background: white; font-size: clamp(24px, 2.7vw, 39px); line-height: 1.55; letter-spacing: .015em; }
.reader-text.school-font { font-family: "Comic Sans MS", "Segoe Print", cursive; }
.reader-text .spoken { background: #fff1a8; border-radius: 5px; }
.reader-controls { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; padding: 14px; margin-top: 14px; }
.reader-controls button { min-height: 52px; }

.game-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.game-card { padding: 24px; min-height: 210px; display: grid; align-content: space-between; }
.game-card .icon { font-size: 38px; }
.game-card h3 { margin: 12px 0 6px; font-size: 24px; }
.game-card p { color: var(--ink-soft); line-height: 1.45; }
.game-stage { max-width: 900px; margin: 0 auto; padding: 30px; }
.game-question { font-size: clamp(28px, 4vw, 50px); margin: 16px 0 28px; letter-spacing: -.035em; }
.game-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.game-options button { min-height: 76px; font-size: 20px; }
.canvas-wrap { background: #fff; border: 1px solid var(--line); border-radius: 20px; overflow: hidden; }
#drawingCanvas { width: 100%; height: 340px; touch-action: none; display: block; }

.badge-grid { grid-template-columns: repeat(4, minmax(0,1fr)); }
.badge { padding: 22px; text-align: center; }
.badge-icon { font-size: 48px; filter: grayscale(1); opacity: .35; }
.badge.is-earned .badge-icon { filter: none; opacity: 1; }
.badge strong { display: block; margin-top: 8px; }

.parent-grid { grid-template-columns: 1fr 1fr; align-items: start; }
.settings-card { padding: 24px; }
.settings-card h2 { margin-top: 0; }
.sync-status { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 999px; background: #f1edf7; font-weight: 850; font-size: 13px; }
.sync-status.ok { background: #e9fbf5; color: #167454; }
.sync-status.warn { background: #fff6dc; color: #8a6000; }
.danger-zone { border-color: rgba(190,49,68,.22); }

.dialog {
  border: 0;
  border-radius: 28px;
  width: min(760px, calc(100vw - 30px));
  padding: 0;
  color: var(--ink);
  box-shadow: 0 30px 120px rgba(34,16,52,.32);
}
.dialog::backdrop { background: rgba(32,16,45,.55); backdrop-filter: blur(7px); }
.dialog form { padding: 30px; }
.dialog h2 { margin: 6px 0 9px; font-size: 32px; }
.dialog p { color: var(--ink-soft); line-height: 1.5; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.onboarding-dialog { width: min(860px, calc(100vw - 30px)); }

.toast-stack { position: fixed; right: 22px; bottom: 22px; z-index: 100; display: grid; gap: 10px; max-width: min(420px, calc(100vw - 44px)); }
.toast { background: #26143f; color: white; padding: 14px 17px; border-radius: 15px; box-shadow: 0 16px 40px rgba(25,14,38,.28); animation: toastIn .2s ease; }
.toast.success { background: #166d52; }
.toast.error { background: #9d273a; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

.install-banner {
  position: fixed;
  z-index: 70;
  left: 16px;
  right: 16px;
  bottom: calc(82px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.97);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 20px 55px rgba(44,22,64,.24);
  padding: 15px;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
}
.install-banner[hidden] { display: none; }
.install-banner > div:first-child { display: grid; gap: 3px; }
.install-banner span { color: var(--ink-soft); font-size: 13px; }
.install-actions { display: flex; gap: 7px; }
.mobile-nav { display: none; }
.empty-state { text-align: center; padding: 55px 22px; }
.empty-state .icon { font-size: 60px; }

@media (max-width: 1200px) {
  .mission-grid { grid-template-columns: repeat(3, 1fr); }
  .subject-grid, .story-grid, .game-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-4, .badge-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 820px) {
  :root { --topbar: 76px; }
  body { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
  .sidebar { display: none; }
  .app-shell { margin-left: 0; }
  .topbar { padding: 10px 15px; }
  .brand-copy strong { font-size: 21px; }
  .brand-copy span { font-size: 12px; }
  .child-chip { padding: 9px 12px; }
  .child-chip span:last-child { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  main#app { padding: 20px 15px 34px; }
  .mobile-nav {
    position: fixed;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    padding: 8px 7px calc(7px + env(safe-area-inset-bottom));
    background: rgba(255,255,255,.95);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(16px);
  }
  .mobile-nav .nav-item { width: auto; min-height: 59px; border-radius: 18px; gap: 2px; }
  .mobile-nav .nav-item span { font-size: 21px; }
  .mobile-nav .nav-item small { font-size: 10px; }
  .hero { grid-template-columns: 1fr; min-height: auto; }
  .hero-copy { padding: 28px 23px 8px; }
  .hero-copy h1 { font-size: clamp(39px, 12vw, 58px); }
  .hero-art { min-height: 250px; }
  .hero-art img { max-height: 285px; }
  .grid-2, .grid-3, .grid-4, .stat-strip, .mission-grid, .subject-grid, .story-grid, .game-grid, .badge-grid, .parent-grid, .lesson-layout { grid-template-columns: 1fr; }
  .two-cols, .three-cols { grid-template-columns: 1fr; }
  .exercise-panel { position: static; }
  .subject-header { grid-template-columns: 1fr; }
  .lesson-row { grid-template-columns: auto 1fr; }
  .lesson-row > :last-child { grid-column: 1 / -1; }
  .reader-visual, .reader-visual img { min-height: 280px; height: 280px; }
  .reader-text { font-size: 25px; padding: 24px 22px 30px; }
  .reader-controls { grid-template-columns: repeat(2, 1fr); }
  .reader-controls button:last-child { grid-column: 1 / -1; }
  .game-options { grid-template-columns: 1fr; }
  .install-banner { flex-direction: column; align-items: stretch; }
  .install-actions { justify-content: flex-end; }
  .dialog form { padding: 24px 20px; }
}

@media (max-width: 480px) {
  .topbar-actions .icon-button { display: none; }
  .brand-copy strong { font-size: 18px; }
  .hero-actions { display: grid; }
  .hero-actions .button, .hero-actions .button-ghost { width: 100%; }
  .page-heading h1 { font-size: 42px; }
  .lesson-index { width: 40px; height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
