:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #f1ede6;
  --text: #1f2430;
  --muted: #646b7a;
  --line: #e4dfd6;
  --primary: #2f6fed;
  --primary-ink: #ffffff;
  --primary-soft: #e6eeff;
  --red: #d7263d;
  --red-soft: #fde8eb;
  --green: #1f9d55;
  --green-soft: #e2f6ea;
  --amber: #f2a900;
  --amber-soft: #fff4d6;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(20, 20, 40, .06), 0 6px 24px rgba(20, 20, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c; --surface: #1d2029; --surface-2: #262a35; --text: #eef0f5; --muted: #a2a9b8;
    --line: #313644; --primary: #6b9bff; --primary-ink: #0d1430; --primary-soft: #1f2a48;
    --red: #ff6b7d; --red-soft: #3a1f26; --green: #4fd18b; --green-soft: #17322a;
    --amber: #ffc94a; --amber-soft: #3a3020; --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.5 "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.7rem; font-weight: 800; }
h2 { font-size: 1.25rem; font-weight: 800; }
h3 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0 0 .8em; }
a { color: var(--primary); }
[hidden] { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px;
  padding: 10px max(16px, env(safe-area-inset-left)); background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; color: var(--text); text-decoration: none; white-space: nowrap; }
.flag { width: 26px; height: 18px; border-radius: 4px; background: linear-gradient(#fff 50%, #dc143c 50%); box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a { padding: 6px 12px; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 700; white-space: nowrap; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }

main { max-width: 860px; margin: 0 auto; padding: 24px 16px 80px; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; border: 1px solid var(--line); }
.card.tight { padding: 14px 16px; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }

button, .btn {
  font: inherit; font-weight: 700; border: 0; border-radius: 999px; padding: 10px 20px; cursor: pointer;
  background: var(--primary); color: var(--primary-ink); text-decoration: none; display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px;
}
button:disabled { opacity: .5; cursor: default; }
button.secondary, .btn.secondary { background: var(--surface-2); color: var(--text); }
button.danger { background: var(--red-soft); color: var(--red); }
button.link { background: none; color: var(--muted); padding: 6px 8px; min-height: 0; }
button.big { font-size: 1.15rem; padding: 14px 28px; }

input, textarea, select {
  font: inherit; width: 100%; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text);
}
textarea { min-height: 160px; resize: vertical; }
label { display: block; font-weight: 700; font-size: .92rem; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 999px; font-weight: 600; cursor: pointer; margin: 0; }
.check input { width: auto; margin: 0; }
.check:has(input:checked) { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.error-box { background: var(--red-soft); color: var(--red); padding: 10px 14px; border-radius: 12px; font-weight: 600; }

/* Login */
.login { max-width: 380px; margin: 8vh auto; text-align: center; }
.login .flag { width: 64px; height: 44px; margin: 0 auto 16px; border-radius: 8px; }
.login form { text-align: left; }

/* Kid home */
.hello { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; }
.star-total { background: var(--amber-soft); color: #9a6a00; font-weight: 800; padding: 8px 16px; border-radius: 999px; white-space: nowrap; }
@media (prefers-color-scheme: dark) { .star-total { color: var(--amber); } }
.lesson-tile { display: block; text-decoration: none; color: inherit; transition: transform .12s; }
.lesson-tile:hover { transform: translateY(-2px); }
.lesson-tile h2 { margin-bottom: 6px; }
.progress { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 10px; }
.progress > span { display: block; height: 100%; background: var(--green); border-radius: 999px; }
.badge { display: inline-block; font-size: .78rem; font-weight: 800; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: var(--amber-soft); color: #9a6a00; }
.badge.red { background: var(--red-soft); color: var(--red); }
.stars { color: var(--amber); letter-spacing: 2px; font-size: 1.1rem; white-space: nowrap; }
.stars .off { color: var(--line); }

/* Lesson */
.intro p { font-size: 1.08rem; }
.facts { margin: 0; padding-left: 1.2em; }
.facts li { margin-bottom: 4px; }
.vocab { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; }
.vocab div { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.vocab b { display: block; }
.task-item { display: flex; gap: 14px; align-items: center; text-decoration: none; color: inherit; padding: 14px 0; border-top: 1px solid var(--line); }
.task-item:first-child { border-top: 0; }
.task-num { flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; background: var(--primary-soft); color: var(--primary); }
.task-num.done { background: var(--green-soft); color: var(--green); }
.task-item .q { flex: 1; }

/* Recorder */
.question { font-size: 1.35rem; font-weight: 800; line-height: 1.35; }
.recorder { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 12px 0 4px; text-align: center; }
.mic {
  width: 112px; height: 112px; border-radius: 50%; padding: 0; justify-content: center;
  background: var(--red); color: #fff; box-shadow: 0 8px 24px rgba(215, 38, 61, .35);
}
.mic svg { width: 46px; height: 46px; }
.mic.recording { animation: pulse 1.2s ease-in-out infinite; background: var(--red); }
.mic.stop svg { width: 38px; height: 38px; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(215, 38, 61, .45); } 50% { box-shadow: 0 0 0 18px rgba(215, 38, 61, 0); } }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.2rem; }
.thinking { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 20px; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 5px solid var(--primary-soft); border-top-color: var(--primary); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
audio { width: 100%; max-width: 420px; }

/* Feedback */
.feedback .praise { font-size: 1.15rem; font-weight: 700; }
.feedback .big-stars { font-size: 2.2rem; letter-spacing: 6px; }
.transcript { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; font-size: 1.05rem; }
mark.err { background: var(--red-soft); color: var(--red); border-radius: 4px; padding: 0 2px; text-decoration: underline wavy; text-decoration-thickness: 1px; }
.fix { border-left: 4px solid var(--red); padding: 8px 12px; background: var(--surface-2); border-radius: 0 12px 12px 0; margin-bottom: 8px; }
.fix .pair { font-size: 1.05rem; }
.fix .said { color: var(--red); text-decoration: line-through; }
.fix .correct { color: var(--green); font-weight: 800; }
.ok-list { list-style: none; padding: 0; margin: 0; }
.ok-list li::before { content: "✓ "; color: var(--green); font-weight: 800; }
.model { border-left: 4px solid var(--green); background: var(--green-soft); padding: 10px 14px; border-radius: 0 12px 12px 0; font-size: 1.05rem; }
.help { background: var(--primary-soft); border-radius: 12px; padding: 10px 14px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.say { background: none; color: var(--primary); padding: 4px 8px; min-height: 0; }

/* Admin */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 8px 6px; border-top: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .82rem; color: var(--muted); border-top: 0; }
.day-head { font-weight: 800; margin: 18px 0 6px; }
details summary { cursor: pointer; font-weight: 700; }
pre.topic-body { white-space: pre-wrap; font: inherit; margin: 6px 0 0; color: var(--muted); }

@media (max-width: 560px) {
  body { font-size: 16px; }
  .topbar { gap: 8px; }
  .brand span + * { display: none; }
  .question { font-size: 1.2rem; }
  .card { padding: 16px; }
}

/* Topic drafting */
.ideas { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; margin-top: 12px; }
.ideas > p { grid-column: 1 / -1; margin: 0; }
button.idea {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; font-weight: 400;
  background: var(--surface-2); color: var(--text); border-radius: 12px; padding: 10px 12px;
}
button.idea:hover:not(:disabled) { background: var(--primary-soft); }
.spinner.inline { display: inline-block; width: 16px; height: 16px; border-width: 3px; vertical-align: -3px; }
.example { background: var(--surface-2); border-radius: 12px; padding: 10px 14px; margin-bottom: 8px; }
.example ol { margin: 6px 0 0; padding-left: 1.4em; }

/* Lesson start */
.start-card { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; text-decoration: none; color: inherit; }
.start-card img { width: 100%; max-height: 260px; object-fit: cover; border-radius: 12px; }
.start-card.fresh .btn { animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-3px); } }

/* Lesson player */
.player { max-width: 680px; margin: 0 auto; }
.player-top { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.player-top .close { text-decoration: none; color: var(--muted); font-size: 1.3rem; padding: 4px 8px; }
.player-top .sound { font-size: 1.3rem; }
.dots { flex: 1; display: flex; gap: 4px; }
.dots span { flex: 1; height: 6px; border-radius: 999px; background: var(--line); }
.dots span.done { background: var(--green); }
.dots span.now { background: var(--primary); }
.slide { animation: slide-in .25s ease-out; }
@keyframes slide-in { from { opacity: 0; transform: translateX(14px); } }
.slide h2 { font-size: 1.45rem; }
.slide-text { font-size: 1.3rem; line-height: 1.5; }
.visual:empty { display: none; }
.visual { margin-bottom: 14px; }
.visual .picture { display: block; width: 100%; max-height: 42vh; object-fit: contain; border-radius: 14px; background: var(--surface-2); }
.say-row { margin-top: 6px; }
.player-nav { display: flex; justify-content: space-between; gap: 12px; }
.player-nav #next { flex: 1; justify-content: center; font-size: 1.1rem; }

.slide.no-anim, .slide.no-anim * { animation: none !important; }
.quiz { margin-top: 14px; padding-top: 14px; border-top: 2px dashed var(--line); }
.quiz-q { font-weight: 800; font-size: 1.15rem; margin-bottom: 10px; }
.options { display: grid; gap: 8px; }
button.option { background: var(--surface-2); color: var(--text); border: 2px solid var(--line); border-radius: 14px; justify-content: flex-start; font-size: 1.1rem; }
button.option:hover:not(:disabled) { border-color: var(--primary); }
button.option:disabled { opacity: 1; }
button.option.right { background: var(--green-soft); border-color: var(--green); color: var(--green); }
button.option.right::after { content: "✓"; margin-left: auto; }
button.option.wrong { background: var(--red-soft); border-color: var(--red); color: var(--red); animation: shake .3s; }
button.option.dim { opacity: .55; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.quiz-explain { margin-top: 10px; font-weight: 700; background: var(--amber-soft); border-radius: 12px; padding: 10px 14px; }

.ex-steps { font-size: 1.2rem; padding-left: 1.4em; }
.ex-steps li { margin-bottom: 6px; animation: slide-in .25s ease-out; }
.facts.big li { font-size: 1.15rem; margin-bottom: 8px; }
.flips { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
button.flip { flex-direction: column; align-items: flex-start; gap: 4px; text-align: left; background: var(--primary-soft); color: var(--text); border-radius: 14px; font-weight: 400; min-height: 64px; }
button.flip b { font-size: 1.1rem; color: var(--primary); }
button.flip.open { background: var(--surface-2); }
.end { text-align: center; padding: 10px 0; }
.end-emoji { font-size: 4rem; }

/* Diagrams */
.groups { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.grp { position: relative; display: grid; justify-items: center; gap: 2px; padding: 18px 8px 8px; border: 2px solid var(--primary); border-radius: 14px; background: var(--primary-soft); font-size: 1.6rem; line-height: 1.1; animation: pop .35s ease-out backwards; }
.grp.loose { display: flex; flex-wrap: wrap; justify-content: center; border: 0; background: none; }
.grp.rest { border: 2px dashed var(--red); background: var(--red-soft); }
.grp-n { position: absolute; top: 2px; left: 0; right: 0; text-align: center; font-size: .72rem; color: var(--primary); }
.grp.rest .grp-n { color: var(--red); }
@keyframes pop { from { opacity: 0; transform: scale(.6); } }
svg.numline, svg.timeline { width: 100%; height: auto; display: block; font: 700 15px "Nunito", system-ui, sans-serif; }
svg .axis { stroke: var(--text); stroke-width: 3; stroke-linecap: round; }
svg.numline line { stroke: var(--text); stroke-width: 2; }
svg text { fill: var(--text); text-anchor: middle; }
svg.numline .jump path { fill: none; stroke: var(--primary); stroke-width: 3; }
svg.numline .jump text { fill: var(--primary); font-size: 13px; }
svg.numline circle { fill: var(--red); }
svg .jump, svg .event { animation: fade .4s ease-out backwards; }
@keyframes fade { from { opacity: 0; } }
svg.timeline .band { fill: var(--primary-soft); }
svg.timeline .band.alt { fill: var(--amber-soft); }
svg.timeline .band-label { font-size: 13px; fill: var(--muted); }
svg.timeline .event line { stroke: var(--muted); stroke-width: 1.5; }
svg.timeline .event circle { fill: var(--red); stroke: var(--surface); stroke-width: 2; }
svg.timeline .ev-year { fill: var(--red); font-size: 14px; }
svg.timeline text { font-size: 13px; }

@media (max-width: 560px) {
  .slide-text { font-size: 1.15rem; }
  .grp { font-size: 1.3rem; }
  svg.numline, svg.timeline { font-size: 18px; }
}

/* Tabs (admin topics) */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.tab { background: var(--surface-2); color: var(--muted); }
.tab.active { background: var(--primary); color: var(--primary-ink); }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }

/* Points and rewards */
.points-chip { background: var(--amber-soft); color: #9a6a00; font-weight: 800; padding: 8px 16px; border-radius: 999px; white-space: nowrap; text-decoration: none; }
.points-chip.small { padding: 2px 10px; font-size: .85rem; }
@media (prefers-color-scheme: dark) { .points-chip { color: var(--amber); } }
.points-hero { text-align: center; }
.points-big { font-size: 2.6rem; font-weight: 800; }
.reward-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.reward-grid .card { margin: 0; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; }
.reward-emoji { font-size: 3rem; line-height: 1; }
.reward-emoji.small-emoji { font-size: 2rem; }
.reward-cost { font-weight: 800; color: #9a6a00; }
@media (prefers-color-scheme: dark) { .reward-cost { color: var(--amber); } }
.reward button { margin-top: auto; }
.reward button.confirm { background: var(--green); color: #fff; }
.box-ok { background: var(--green-soft); color: var(--green); padding: 10px 14px; border-radius: 12px; font-weight: 700; margin-bottom: 16px; }
.request-row { padding: 10px 0; border-top: 1px solid var(--line); }
.request-row:first-of-type { border-top: 0; }
.earned { margin: 12px auto; max-width: 320px; }
.earned-total { font-size: 2.2rem; font-weight: 800; color: #9a6a00; animation: pop .5s ease-out; }
@media (prefers-color-scheme: dark) { .earned-total { color: var(--amber); } }
.earned-list { list-style: none; padding: 0; margin: 8px 0; text-align: start; }
.earned-list li { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.grid-reward { display: grid; grid-template-columns: 90px 1fr 140px; gap: 12px; }
@media (max-width: 560px) { .grid-reward { grid-template-columns: 70px 1fr; } }
.card.inactive { opacity: .6; }

/* Lesson preview and editing */
.preview-banner { background: var(--primary-soft); color: var(--primary); font-weight: 700; padding: 8px 14px; border-radius: 12px; margin-bottom: 10px; }
.edit-thumb { max-width: 220px; border-radius: 10px; display: block; margin-bottom: 10px; }
.save-bar { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
