:root {
  --bg: #f7f6fb;
  --card: #ffffff;
  --soft: #f1f0f6;
  --text: #1f1d2b;
  --muted: #5d5a6e;
  --line: #e3e1ec;
  --line-strong: #c9c6d8;
  --focus: #534ab7;
  --pu-b: #eeedfe; --pu-t: #3c3489; --pu-s: #534ab7;
  --te-b: #e1f5ee; --te-t: #085041; --te-s: #1d9e75;
  --co-b: #faece7; --co-t: #712b13; --co-s: #d85a30;
  --pi-b: #fbeaf0; --pi-t: #72243e; --pi-s: #d4537e;
  --am-b: #faeeda; --am-t: #633806; --am-s: #ef9f27;
  --danger: #a32d2d;
  --blob: #afa9ec; --face: #26215c;
  --font: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --fs: 16px;
  --radius: 18px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #15141c; --card: #1f1e29; --soft: #2a2936; --text: #f2f1f7; --muted: #b7b4c6;
    --line: #34323f; --line-strong: #4a4858; --focus: #afa9ec;
    --pu-b: #3c3489; --pu-t: #cecbf6; --pu-s: #afa9ec;
    --te-b: #085041; --te-t: #9fe1cb; --te-s: #5dcaa5;
    --co-b: #712b13; --co-t: #f5c4b3; --co-s: #f0997b;
    --pi-b: #72243e; --pi-t: #f4c0d1; --pi-s: #ed93b1;
    --am-b: #633806; --am-t: #fac775; --am-s: #ba7517;
    --danger: #f09595; --blob: #7f77dd;
    color-scheme: dark;
  }
}

/* High contrast: plain black on white, strong borders, no pastel fills. */
:root[data-contrast='high'] {
  --bg: #ffffff; --card: #ffffff; --soft: #ffffff; --text: #000000; --muted: #000000;
  --line: #000000; --line-strong: #000000; --focus: #0000cc;
  --pu-b: #ffffff; --pu-t: #000000; --pu-s: #000000;
  --te-b: #ffffff; --te-t: #000000; --te-s: #000000;
  --co-b: #ffffff; --co-t: #000000; --co-s: #000000;
  --pi-b: #ffffff; --pi-t: #000000; --pi-s: #000000;
  --am-b: #ffffff; --am-t: #000000; --am-s: #000000;
  --danger: #b00000;
  color-scheme: light;
}
:root[data-contrast='high'] .card,
:root[data-contrast='high'] .chip,
:root[data-contrast='high'] .tile,
:root[data-contrast='high'] .mode { border: 2px solid #000; }

/* Easy-read: a typeface designed for low-vision readers, plus wider spacing. */
:root[data-easy='on'] {
  --font: 'Atkinson Hyperlegible', system-ui, sans-serif;
}
:root[data-easy='on'] main { letter-spacing: 0.04em; word-spacing: 0.14em; line-height: 1.9; }

* { box-sizing: border-box; }
html { font-size: var(--fs); }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--font);
  line-height: 1.6; -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.skip { position: absolute; left: -999px; top: 8px; background: var(--card); padding: 8px 12px; border-radius: 10px; z-index: 10; }
.skip:focus { left: 8px; }
.banner { background: var(--am-b); color: var(--am-t); text-align: center; padding: 8px 16px; font-size: 0.9rem; }

.top, main, .foot { max-width: 760px; margin: 0 auto; padding: 0 16px; }
.top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; padding-top: 20px; padding-bottom: 12px; }
.brand { display: flex; align-items: center; gap: 12px; flex: 1 1 280px; }
.brand h1 { font-size: 1.4rem; margin: 0; font-weight: 700; }
.buddy { width: 56px; height: 56px; flex: none; }
.buddy-body { fill: var(--blob); }
.buddy-face { fill: var(--face); }
.buddy-smile { stroke: var(--face); stroke-width: 3; fill: none; stroke-linecap: round; }
.bubble { margin: 4px 0 0; display: inline-block; background: var(--pu-b); color: var(--pu-t); border-radius: 16px 16px 16px 4px; padding: 6px 12px; font-size: 0.95rem; }
.prefs { display: flex; flex-wrap: wrap; gap: 6px; }

main { display: flex; flex-direction: column; gap: 14px; padding-bottom: 24px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 18px 20px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

fieldset.levels { border: 0; padding: 0; margin: 0 0 14px; }
legend, .label { font-size: 0.9rem; color: var(--muted); margin-bottom: 8px; display: flex; align-items: center; gap: 6px; padding: 0; }
.num { width: 24px; height: 24px; border-radius: 50%; background: var(--pu-b); color: var(--pu-t); font-size: 0.8rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }

textarea, input[type='date'], input[type='number'], select {
  width: 100%; background: var(--soft); border: 1.5px dashed var(--line-strong); border-radius: 14px; padding: 10px 12px; min-height: 44px;
}
textarea { resize: vertical; line-height: 1.5; }
.hint { font-size: 0.85rem; color: var(--muted); margin: 6px 0 0; }
.error { font-size: 0.85rem; color: var(--danger); margin: 4px 0 0; min-height: 1em; }
.form-row { margin-top: 10px; align-items: flex-start; }
.field { flex: 1 1 200px; display: block; font-size: 0.9rem; color: var(--muted); }
.field input, .field select { margin-top: 4px; }
.optional { font-size: 0.8rem; }
.actions { margin-top: 14px; }
.status { font-size: 0.9rem; color: var(--muted); margin: 10px 0 0; min-height: 1.2em; }

button { cursor: pointer; }
.chip {
  min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--card);
  display: inline-flex; align-items: center; gap: 6px; font-size: 0.9rem;
}
.sizer { display: inline-flex; align-items: center; gap: 2px; min-height: 36px; padding: 0 4px 0 12px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--card); font-size: 0.9rem; }
.sizer span { display: inline-flex; align-items: center; gap: 6px; margin-right: 4px; }
.sizer button { width: 30px; height: 30px; border-radius: 50%; border: 0; background: var(--soft); display: inline-flex; align-items: center; justify-content: center; }
:root[data-contrast='high'] .sizer { border: 2px solid #000; }
.chip[aria-pressed='true'] { background: var(--te-b); color: var(--te-t); border-color: var(--te-s); }
.level { border-width: 2px; }
.level[aria-pressed='true'] { background: var(--pu-b); color: var(--pu-t); border-color: var(--pu-s); }
.primary {
  min-height: 46px; padding: 0 22px; border-radius: 999px; border: 0; background: var(--pu-s); color: #fff; font-weight: 700;
  display: inline-flex; align-items: center; gap: 8px; font-size: 1rem;
}
:root[data-contrast='high'] .primary { background: #000; }
@media (prefers-color-scheme: dark) { :root:not([data-contrast='high']) .primary { color: #15141c; } }
.primary[aria-busy='true'] { opacity: 0.7; cursor: progress; }

/* Plan */
.plan-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.plan-head h2 { margin: 0; font-size: 1.25rem; }
.shared { background: var(--te-b); color: var(--te-t); border-radius: 14px; padding: 8px 12px; font-size: 0.9rem; margin-bottom: 10px; }
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.mode {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 6px; border-radius: 16px; border: 2px solid transparent; font-size: 0.9rem; font-weight: 600;
}
.mode i { font-size: 1.6rem; }
.mode[aria-pressed='true'] { border-color: currentColor; }
.m-visual { background: var(--co-b); color: var(--co-t); }
.m-steps { background: var(--pu-b); color: var(--pu-t); }
.m-listen { background: var(--te-b); color: var(--te-t); }
.m-simple { background: var(--pi-b); color: var(--pi-t); }
.tools { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 6px; }
.note { border-radius: 16px; padding: 10px 14px; margin: 6px 0; font-size: 0.95rem; }
.note-te { background: var(--te-b); color: var(--te-t); }
.note-soft { background: var(--soft); }
.small { font-size: 0.8rem; }
.sub { margin: 18px 0 8px; font-size: 0.85rem; color: var(--muted); }

.progress { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.track { flex: 1; height: 10px; background: var(--soft); border-radius: 999px; overflow: hidden; }
.fill { height: 10px; background: var(--pu-s); border-radius: 999px; transition: width 0.3s; }
.pill { font-size: 0.8rem; padding: 3px 10px; border-radius: 999px; white-space: nowrap; background: var(--pu-b); color: var(--pu-t); }

.step { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 14px; margin-top: 8px; background: var(--soft); cursor: pointer; }
.step input { width: 22px; height: 22px; flex: none; accent-color: var(--pu-s); }
.step > i { font-size: 1.4rem; color: var(--pu-s); }
.step-body { flex: 1; min-width: 0; }
.step-title { font-weight: 700; }
.step-detail, .step-home { font-size: 0.9rem; color: var(--muted); }
.step-home { font-style: italic; }
.step.done .step-title { text-decoration: line-through; color: var(--muted); }

.focus-card { text-align: center; padding: 22px; border-radius: 22px; background: var(--pu-b); color: var(--pu-t); margin-top: 8px; }
.focus-card i { font-size: 3rem; }
.focus-card .big { font-size: 1.4rem; font-weight: 700; }

/* Road (preschool / elementary) */
.road { position: relative; height: 310px; border-radius: 22px; background: var(--te-b); overflow: hidden; margin-top: 6px; }
.road svg.path { position: absolute; inset: 0; width: 100%; height: 280px; }
.road .deco { position: absolute; font-size: 1.8rem; color: var(--te-s); }
.road .deco.cloud { color: var(--line-strong); }
.stop {
  position: absolute; transform: translate(-50%, -50%); width: 58px; height: 58px; border-radius: 50%; padding: 0;
  display: flex; align-items: center; justify-content: center; border: 3px solid var(--card); background: var(--card); color: var(--muted); font-size: 1.5rem;
}
.stop.now { width: 70px; height: 70px; background: var(--co-s); color: #fff; font-size: 1.9rem; }
.stop.ok { background: var(--te-s); color: #fff; }
.stop-label { position: absolute; transform: translateX(-50%); width: 104px; text-align: center; font-size: 0.78rem; line-height: 1.3; }
.walker { position: absolute; width: 40px; height: 40px; transform: translate(-50%, -115%); transition: left 0.4s, top 0.4s; }
.flag { position: absolute; right: 6px; transform: translateY(-100%); color: var(--co-s); font-size: 1.9rem; }

.shape { display: flex; flex-wrap: wrap; gap: 6px; }
.shape > div { flex: 1 1 100px; padding: 12px 8px; text-align: center; font-size: 0.85rem; border-radius: 10px; }
.c0 { background: var(--pu-b); color: var(--pu-t); }
.c1 { background: var(--co-b); color: var(--co-t); }
.c2 { background: var(--te-b); color: var(--te-t); }
.c3 { background: var(--pi-b); color: var(--pi-t); }
.c4 { background: var(--am-b); color: var(--am-t); }
.shape > div:first-child { border-radius: 20px 10px 10px 20px; }
.shape > div:last-child { border-radius: 10px 20px 20px 10px; }

/* Timeline */
.timeline { display: grid; gap: 6px; }
.day { background: var(--soft); border-radius: 12px; padding: 8px; min-height: 64px; min-width: 0; }
.day.due { background: var(--co-b); color: var(--co-t); }
.day-name { font-size: 0.78rem; color: inherit; opacity: 1; }
.task { display: block; width: 100%; text-align: left; padding: 5px 8px; font-size: 0.8rem; line-height: 1.35; border-radius: 8px; margin-top: 4px; border: 1px solid var(--line); background: var(--card); color: var(--text); }
.task.ok { background: var(--te-b); color: var(--te-t); }
@media (max-width: 520px) { .timeline { grid-template-columns: 1fr 1fr !important; } }

/* Argument map */
.claim { text-align: center; background: var(--pu-b); color: var(--pu-t); border-radius: 16px; padding: 14px; }
.claim .big { font-weight: 700; }
.vline { height: 14px; width: 2px; background: var(--line-strong); margin: 0 auto; }
.hline { border-top: 2px solid var(--line-strong); margin: 0 16.7%; }
.reasons { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.reasons > div { display: flex; flex-direction: column; }
.tile { flex: 1; border: 1px solid var(--line); border-radius: 14px; padding: 10px; background: var(--soft); font-size: 0.88rem; line-height: 1.45; }
.evidence { border: 1.5px dashed var(--line-strong); border-radius: 10px; padding: 6px 8px; font-size: 0.8rem; margin-top: 8px; }
.counter { margin-top: 8px; border-radius: 14px; padding: 10px 12px; background: var(--co-b); color: var(--co-t); font-size: 0.9rem; }
.budget { display: flex; gap: 3px; }
.budget > div { min-width: 0; overflow: hidden; border-radius: 8px; padding: 6px 4px; font-size: 0.72rem; text-align: center; line-height: 1.3; }
@media (max-width: 560px) { .reasons { grid-template-columns: 1fr; } .hline { display: none; } }

/* Experiment */
.cups { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.cup { text-align: center; border-radius: 16px; padding: 12px 10px; }
.cup .ti-cup { font-size: 2.2rem; display: block; }
.cup label { font-size: 0.8rem; display: block; margin-top: 6px; }
.cup input { margin-top: 4px; text-align: center; background: var(--card); }
.bars { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.bar-row { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
.bar-row .name { width: 30%; min-width: 60px; }
.bar-row .val { width: 96px; text-align: right; white-space: nowrap; }
.bar { flex: 1; background: var(--soft); border-radius: 999px; height: 16px; }
.bar > div { height: 16px; border-radius: 999px; transition: width 0.3s; }

/* Matrix */
.matrix { width: 100%; border-collapse: separate; border-spacing: 4px; font-size: 0.85rem; table-layout: fixed; }
.matrix th { font-weight: 700; font-size: 0.78rem; border-radius: 8px; padding: 6px 4px; }
.matrix th.src { text-align: left; color: var(--muted); width: 30%; background: none; }
.matrix td.src { font-size: 0.8rem; color: var(--muted); }
.cell { width: 100%; height: 30px; padding: 0; border-radius: 8px; border: 1px solid var(--line); background: var(--soft); }
.gap { background: var(--am-b); color: var(--am-t); }

/* Listen */
.player { display: flex; align-items: center; gap: 12px; padding: 6px 0 12px; flex-wrap: wrap; }
.play { width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--te-b); color: var(--te-t); font-size: 1.6rem; display: flex; align-items: center; justify-content: center; }
.player select { width: auto; }
.chunk { padding: 6px 10px; border-radius: 10px; margin: 4px 0; }
.chunk.reading { background: var(--te-b); color: var(--te-t); }

/* Simple words */
.plain { background: var(--pi-b); color: var(--pi-t); border-radius: 16px; padding: 12px 14px; margin: 6px 0 12px; }
.words { display: flex; flex-wrap: wrap; gap: 8px; }
.word { flex: 1 1 160px; background: var(--soft); border-radius: 14px; padding: 10px 12px; font-size: 0.9rem; }
.word b { color: var(--pi-t); }

.quiz { margin-top: 16px; background: var(--am-b); color: var(--am-t); border-radius: 16px; padding: 12px 14px; }
.quiz .row { margin-top: 8px; }
.quiz .chip { background: var(--card); color: var(--text); }

.foot { color: var(--muted); font-size: 0.8rem; padding-bottom: 32px; }

.loading { display: flex; align-items: center; gap: 10px; }
.loading .buddy { animation: bob 1s ease-in-out infinite alternate; width: 40px; height: 40px; }
@keyframes bob { to { transform: translateY(-6px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Print: a one-page checklist, no controls. */
.print-only { display: none; }
@media print {
  body { background: #fff; color: #000; }
  .top, #form, .modes, .tools, .quiz, .foot, .skip, .banner, #plan-body { display: none !important; }
  #result { display: block !important; }
  .card { border: 0; padding: 0; }
  .print-only { display: block; }
  .print-only li { margin: 8px 0; list-style: none; }
  .print-only li::before { content: '☐  '; }
}
