/* nscribe
   Layout: a sticky top bar, one reading column (max 72ch) with a tools rail
   that sits beside the text on wide screens and stacks beneath it on phones.
   Palette: jade-tinted paper, indigo ink, lacquer red seal, gold thread. */
:root {
  --bg: #F3F6F1;
  --surface: #FFFFFF;
  --surface-2: #E7EDE4;
  --fg: #1B2434;
  --muted: #5A6577;
  --line: #CFD8CC;
  --lacquer: #B5302A;
  --lacquer-soft: #F6E1DE;
  --on-lacquer: #FFFFFF;
  --gold: #B8841F;
  --gold-soft: #F6ECD4;
  --jade: #2B7A66;
  --jade-soft: #D9EEE5;
  --sky: #35699B;
  --sky-soft: #DCE8F4;
  --shadow: 0 1px 2px rgba(27, 36, 52, 0.06), 0 8px 24px -12px rgba(27, 36, 52, 0.25);

  --font-display: "Baloo 2", "Trebuchet MS", "Segoe UI", sans-serif;
  --font-body: "Be Vietnam Pro", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --reader-size: 1.2rem;
  --reader-leading: 1.75;
  --radius: 14px;
  --radius-sm: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111827; --surface: #1A2333; --surface-2: #232E41; --fg: #ECF0F5; --muted: #A2ADBE;
    --line: #34405A; --lacquer: #E25A4F; --lacquer-soft: #3B2426; --on-lacquer: #FFFFFF;
    --gold: #E6B657; --gold-soft: #3A3122; --jade: #5CBC9C; --jade-soft: #1E3A33;
    --sky: #86B5E6; --sky-soft: #1F3247;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px -12px rgba(0,0,0,0.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111827; --surface: #1A2333; --surface-2: #232E41; --fg: #ECF0F5; --muted: #A2ADBE;
  --line: #34405A; --lacquer: #E25A4F; --lacquer-soft: #3B2426; --on-lacquer: #FFFFFF;
  --gold: #E6B657; --gold-soft: #3A3122; --jade: #5CBC9C; --jade-soft: #1E3A33;
  --sky: #86B5E6; --sky-soft: #1F3247;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px -12px rgba(0,0,0,0.6);
  color-scheme: dark;
}
html[data-size="1"] { --reader-size: 1.05rem; --reader-leading: 1.65; }
html[data-size="3"] { --reader-size: 1.4rem;  --reader-leading: 1.9; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-text-size-adjust: 100%;
}
img, svg { max-width: 100%; }
h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.15; margin: 0; text-wrap: balance; font-weight: 700; }
h1 { font-size: clamp(1.9rem, 2.2vw + 1.4rem, 2.8rem); }
h2 { font-size: clamp(1.4rem, 1vw + 1.1rem, 1.8rem); }
h3 { font-size: 1.2rem; }
p { margin: 0; }
a { color: var(--sky); }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.eyebrow { font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 600; color: var(--muted); }
.vi { font-weight: 600; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 8px; z-index: 50; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 4px; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner, .app, .footer-inner {
  width: 100%; max-width: 1120px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.topbar-inner { display: flex; align-items: center; gap: 18px; padding-block: 10px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--fg); margin-right: auto; }
.seal {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 9px;
  background: var(--lacquer); color: var(--on-lacquer); font-family: var(--font-display); font-weight: 800; font-size: 1.5rem; line-height: 1;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.35);
}
.brand-text { font-family: var(--font-display); font-weight: 800; font-size: 1.45rem; line-height: 1; display: flex; flex-direction: column; }
.brand-text small { font-family: var(--font-body); font-weight: 500; font-size: 0.7rem; letter-spacing: 0.06em; color: var(--muted); margin-top: 3px; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { text-decoration: none; color: var(--fg); padding: 7px 11px; border-radius: 999px; font-weight: 600; font-size: 0.95rem; }
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current="page"] { background: var(--lacquer-soft); color: var(--lacquer); }
.topbar-tools { display: flex; gap: 6px; }
.icon-btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 9px; cursor: pointer;
  font-family: var(--font-display); font-weight: 700; display: inline-flex; align-items: baseline; gap: 1px;
}
.icon-btn .minus, .icon-btn .plus { font-size: 0.8em; }
.icon-btn:hover { background: var(--surface-2); }

/* Main */
.app { flex: 1; padding-block: 28px 56px; min-width: 0; }
.footer { border-top: 1px solid var(--line); background: var(--surface); }
.footer-inner { padding-block: 18px; font-size: 0.9rem; display: grid; gap: 4px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; font-weight: 600; text-decoration: none; color: var(--fg); line-height: 1.2; min-height: 42px;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--lacquer); border-color: var(--lacquer); color: var(--on-lacquer); }
.btn-primary:hover { filter: brightness(1.08); background: var(--lacquer); }
.btn-jade { background: var(--jade); border-color: var(--jade); color: #fff; }
.btn-jade:hover { filter: brightness(1.08); background: var(--jade); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 6px 12px; min-height: 34px; font-size: 0.9rem; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn.is-live { box-shadow: 0 0 0 4px var(--lacquer-soft); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row-between { justify-content: space-between; }
.stack { display: grid; gap: 14px; }
.stack-lg { display: grid; gap: 28px; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; min-width: 0; }
.card-soft { background: var(--surface-2); border-color: transparent; }
.note { border-left: 4px solid var(--gold); background: var(--gold-soft); padding: 12px 16px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.note-jade { border-left-color: var(--jade); background: var(--jade-soft); }
.note-sky { border-left-color: var(--sky); background: var(--sky-soft); }
.note-red { border-left-color: var(--lacquer); background: var(--lacquer-soft); }

/* Home */
.hero { display: grid; gap: 18px; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); align-items: start; }
.hero-copy { display: grid; gap: 14px; max-width: 62ch; }
.hero-copy p { font-size: 1.08rem; }
.how { display: grid; gap: 10px; }
.how-step { display: grid; grid-template-columns: 44px 1fr; gap: 12px; align-items: start; }
.how-step .mark { width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; font-family: var(--font-display); font-weight: 800; font-size: 1.2rem; }
.mark-read { background: var(--sky-soft); color: var(--sky); }
.mark-check { background: var(--jade-soft); color: var(--jade); }
.mark-think { background: var(--gold-soft); color: var(--gold); }
.mark-type { background: var(--surface-2); color: var(--fg); }
.mark-speak { background: var(--lacquer-soft); color: var(--lacquer); }
.how-step strong { display: block; font-family: var(--font-display); font-size: 1.05rem; }
.library { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.story-card {
  display: grid; grid-template-rows: auto 1fr auto; gap: 12px; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0;
  transition: transform 160ms ease, box-shadow 160ms ease;
}
.story-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.story-card .top { display: flex; align-items: center; gap: 12px; }
.story-card .num {
  width: 42px; height: 42px; border-radius: 9px; background: var(--lacquer); color: var(--on-lacquer); display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 800; font-size: 1.25rem; box-shadow: inset 0 0 0 2px rgba(255,255,255,0.35); flex: none;
}
.story-card .word { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; color: var(--jade); }
.story-card .word small { display: block; font-family: var(--font-body); font-weight: 500; font-size: 0.8rem; color: var(--muted); }
.story-card h3 { font-size: 1.25rem; }
.story-card .blurb { color: var(--muted); font-size: 0.95rem; }
.story-card .meta { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 0.85rem; color: var(--muted); flex-wrap: wrap; }
.dots { display: inline-flex; gap: 5px; }
.dot { width: 11px; height: 11px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); }
.dot.on { background: var(--gold); border-color: var(--gold); }

/* Story shell */
.story-head { display: grid; gap: 10px; }
.story-head .eyebrow-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding-bottom: 10px; margin-top: 8px; }
.tabs a {
  text-decoration: none; color: var(--fg); padding: 9px 14px; border-radius: 999px; font-weight: 600; font-size: 0.95rem;
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid transparent;
}
.tabs a:hover { background: var(--surface-2); }
.tabs a[aria-current="page"] { background: var(--fg); color: var(--bg); }
.tabs .tick { width: 18px; height: 18px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 0.7rem; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.tabs .tick.on { background: var(--jade); color: #fff; border-color: var(--jade); }
.tabs a[aria-current="page"] .tick { border-color: transparent; }

.story-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; align-items: start; margin-top: 22px; }
.rail { display: grid; gap: 14px; position: sticky; top: 84px; }
@media (max-width: 520px) {
  .nav a { font-size: 0.88rem; padding: 6px 9px; }
  .brand-text { font-size: 1.3rem; }
}
@media (max-width: 860px) {
  .story-layout { grid-template-columns: 1fr; }
  .rail { position: static; }
  .hero { grid-template-columns: 1fr; }
}

/* Reader */
.reader { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(18px, 3vw, 36px); min-width: 0; }
.reader .page-label { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 18px; }
.reader-text { max-width: 68ch; display: grid; gap: calc(var(--reader-size) * 0.9); }
.reader-text p { font-size: var(--reader-size); line-height: var(--reader-leading); transition: background 200ms; border-radius: 6px; }
.reader-text p.speaking { background: var(--gold-soft); box-shadow: 0 0 0 6px var(--gold-soft); }
.reader-text .vi-word {
  background: var(--jade-soft); color: inherit; border-bottom: 2px solid var(--jade); border-radius: 3px; padding: 0 2px; cursor: pointer;
  font-weight: 600;
}
.reader-text .vi-word:hover { background: var(--jade); color: #fff; }
.reader-text .vi-name { background: transparent; color: inherit; border-bottom: 2px dotted var(--sky); cursor: pointer; border-radius: 2px; }
.reader-text .vi-name:hover { background: var(--sky-soft); }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 26px; flex-wrap: wrap; }
.page-dots { display: inline-flex; gap: 8px; }
.page-dots a { width: 12px; height: 12px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); display: block; }
.page-dots a.read { background: var(--jade); border-color: var(--jade); }
.page-dots a.current { outline: 2px solid var(--fg); outline-offset: 2px; }
.wordbox { display: grid; gap: 8px; }
.wordbox .big { font-family: var(--font-display); font-size: 1.7rem; color: var(--jade); font-weight: 800; line-height: 1.1; }
.range { width: 100%; accent-color: var(--lacquer); }

/* Check */
.quiz { display: grid; gap: 18px; }
.q { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: grid; gap: 12px; }
.q h3 { font-family: var(--font-body); font-weight: 600; font-size: 1.1rem; }
.opts { display: grid; gap: 8px; }
.opt {
  text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 14px; cursor: pointer;
  display: grid; grid-template-columns: 30px 1fr; gap: 10px; align-items: center; line-height: 1.4;
}
.opt .letter { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); font-weight: 700; font-size: 0.9rem; }
.opt:hover { background: var(--surface-2); }
.opt.correct { border-color: var(--jade); background: var(--jade-soft); }
.opt.correct .letter { background: var(--jade); color: #fff; }
.opt.wrong { border-color: var(--lacquer); background: var(--lacquer-soft); }
.opt.wrong .letter { background: var(--lacquer); color: #fff; }
.opt:disabled { cursor: default; }
.feedback { font-size: 0.95rem; }

/* Think & type */
.think { display: grid; gap: 22px; }
.answer { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: grid; gap: 12px; }
.answer .prompt { font-size: 1.1rem; font-weight: 600; line-height: 1.5; }
.answer textarea {
  width: 100%; min-height: 160px; resize: vertical; font: inherit; font-size: 1.05rem; line-height: 1.6; padding: 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg);
}
.answer textarea:focus { outline: 3px solid var(--gold); border-color: transparent; }
.starters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 5px 11px; font-size: 0.85rem; cursor: pointer; }
.chip:hover { background: var(--gold-soft); border-color: var(--gold); }
.stats { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.9rem; color: var(--muted); font-variant-numeric: tabular-nums; align-items: center; }
.meter { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; flex: 1 1 120px; min-width: 80px; }
.meter > span { display: block; height: 100%; background: var(--gold); border-radius: 999px; transition: width 200ms; }
.meter.done > span { background: var(--jade); }
.selfcheck { display: grid; gap: 6px; font-size: 0.95rem; }
.selfcheck label { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.selfcheck input { margin-top: 4px; accent-color: var(--jade); }

/* Typing drill */
.drill { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(18px, 3vw, 32px); display: grid; gap: 18px; }
.target { font-size: 1.35rem; line-height: 1.8; font-family: var(--font-body); word-break: break-word; }
.target span { border-radius: 3px; padding: 1px 0; }
.target .ok { color: var(--jade); }
.target .bad { color: var(--lacquer); background: var(--lacquer-soft); text-decoration: underline; }
.target .cur { background: var(--gold-soft); box-shadow: inset 0 -3px 0 var(--gold); }
.target .todo { color: var(--muted); }
.drill input[type="text"] {
  width: 100%; font: inherit; font-size: 1.2rem; padding: 14px 16px; border-radius: 10px; border: 2px solid var(--line); background: var(--bg); color: var(--fg);
}
.drill input[type="text"]:focus { outline: none; border-color: var(--gold); }
.bigstats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.bigstat { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; }
.bigstat .v { font-family: var(--font-display); font-size: 1.8rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.bigstat .l { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 4px; }
.progress-steps { display: flex; gap: 6px; }
.progress-steps span { flex: 1; height: 6px; border-radius: 999px; background: var(--surface-2); }
.progress-steps span.done { background: var(--jade); }
.progress-steps span.now { background: var(--gold); }

/* Say it */
.say { display: grid; gap: 18px; }
.keyword-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(18px, 3vw, 32px); display: grid; gap: 16px; }
.keyword-card .huge { font-family: var(--font-display); font-size: clamp(2.4rem, 5vw, 3.6rem); font-weight: 800; line-height: 1.05; color: var(--jade); }
.keyword-card .sounds { font-family: var(--font-display); font-size: 1.3rem; letter-spacing: 0.06em; }
.stars { display: inline-flex; gap: 4px; font-size: 1.4rem; line-height: 1; color: var(--gold); }
.stars .off { color: var(--line); }
.heard { font-size: 1.05rem; }
.heard b { color: var(--jade); }
.vocab-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.vocab { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: grid; gap: 8px; min-width: 0; }
.vocab .vi-big { font-family: var(--font-display); font-weight: 700; font-size: 1.3rem; color: var(--jade); line-height: 1.1; }
.vocab .en { color: var(--muted); font-size: 0.92rem; }
.vocab .actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.vocab .result { font-size: 0.85rem; min-height: 1.2em; }
.keys { display: flex; gap: 6px; flex-wrap: wrap; }
.key { min-width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); font-size: 1.15rem; cursor: pointer; font-family: var(--font-body); }
.key:hover { background: var(--gold-soft); }
.spell input[type="text"] { font-size: 1.3rem; padding: 12px 14px; border-radius: 10px; border: 2px solid var(--line); width: 100%; max-width: 420px; background: var(--bg); color: var(--fg); font: inherit; }
.spell input[type="text"]:focus { outline: none; border-color: var(--gold); }

/* Progress */
.progress-table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.progress-table th, .progress-table td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.progress-table th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.progress-table td.c { text-align: center; }
.badge { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); font-size: 0.8rem; }
.badge.on { background: var(--jade); border-color: var(--jade); color: #fff; }
.table-wrap { overflow-x: auto; }
.totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }

/* Grown-ups */
.prose { max-width: 70ch; display: grid; gap: 14px; }
.prose ul, .prose ol { margin: 0; padding-left: 1.3em; display: grid; gap: 6px; }
.prose h2 { margin-top: 10px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 600; box-shadow: var(--shadow); z-index: 40; max-width: calc(100vw - 32px);
}

/* Printing answers */
@media print {
  .topbar, .footer, .tabs, .rail, .starters, .stats, .toast, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .answer, .card { border: 1px solid #999; break-inside: avoid; }
  .answer textarea { border: none; min-height: 0; height: auto; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
