/* Question Ladder - calm paper. Book serif for the dialogue, system sans for
 * the instruments and controls. Light by default; dark kept. */
:root {
  --page: #f4efe4;
  --paper: #fffcf5;
  --paper-2: #f9f4e8;
  --ink: #2c2a25;
  --ink-2: #5d584d;
  --ink-3: #8a8476;
  --rule: #e2d9c6;
  --rule-2: #d3c7ae;
  --sage: #557a5c;
  --sage-ink: #3f6146;
  --sage-soft: #e3ece0;
  --sage-mid: #9fbca2;
  --clay: #b0654a;
  --clay-soft: #f6e4da;
  --honey: #b98a2c;
  --honey-soft: #f6ecd2;
  --sky: #4f7591;
  --sky-soft: #e2ebf1;
  --shadow: 0 1px 2px rgba(60, 50, 30, 0.06), 0 6px 18px rgba(60, 50, 30, 0.06);
  --radius: 12px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "Charter", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --page: #1b1d19;
  --paper: #24271f;
  --paper-2: #2a2e25;
  --ink: #ebe6d8;
  --ink-2: #bdb6a4;
  --ink-3: #8f8a7b;
  --rule: #3a3e33;
  --rule-2: #4a4f41;
  --sage: #8fb894;
  --sage-ink: #a9cfad;
  --sage-soft: #2d3a2d;
  --sage-mid: #5f8466;
  --clay: #e09a7f;
  --clay-soft: #3e2c24;
  --honey: #ddb766;
  --honey-soft: #3a3220;
  --sky: #8db3cf;
  --sky-soft: #243440;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 18px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--sage-ink); }
.hidden { display: none !important; }
.muted { color: var(--ink-3); }
.tiny { font-size: 12px; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--sage); outline-offset: 2px; border-radius: 6px; }

/* --- header ------------------------------------------------------------------ */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 28px; border-bottom: 1px solid var(--rule); background: var(--page);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mark { width: 34px; height: 34px; color: var(--sage); flex: none; }
.brand-text h1 { margin: 0; font-family: var(--serif); font-size: 22px; font-weight: 600; letter-spacing: 0.2px; }
.topic-line { margin: 0; color: var(--ink-2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 52vw; }
.session { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.chip-link { font-size: 13px; text-decoration: none; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--rule); color: var(--ink-2); }
.chip-link:hover { border-color: var(--sage-mid); color: var(--ink); }
.credits { font-size: 13px; padding: 5px 10px; border-radius: 999px; background: var(--sage-soft); color: var(--sage-ink); font-variant-numeric: tabular-nums; }

/* --- buttons ------------------------------------------------------------------ */
.btn {
  appearance: none; border: 1px solid var(--rule-2); background: var(--paper); color: var(--ink);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; font-size: 14px; line-height: 1.2;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover:not(:disabled) { border-color: var(--sage-mid); background: var(--paper-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--sage); border-color: var(--sage); color: #fff; }
:root[data-theme="dark"] .btn.primary { color: #13170f; }
.btn.primary:hover:not(:disabled) { background: var(--sage-ink); border-color: var(--sage-ink); color: #fff; }
:root[data-theme="dark"] .btn.primary:hover:not(:disabled) { color: #13170f; }
.btn.quiet { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.icon { width: 34px; height: 34px; padding: 0; border-radius: 999px; }
a.btn { text-decoration: none; display: inline-block; }

/* --- layout -------------------------------------------------------------------- */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 28px;
  max-width: 1240px; margin: 0 auto; padding: 24px 28px 8px;
}
.dialogue-pane { min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.instruments {
  position: sticky; top: 16px; align-self: start; display: flex; flex-direction: column; gap: 14px;
  max-height: calc(100vh - 32px); overflow-y: auto; padding-bottom: 8px;
}
.paper { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow); }

/* --- intake ------------------------------------------------------------------- */
.intake { padding: 22px 24px; display: flex; flex-direction: column; gap: 12px; }
.intake-head h2 { margin: 0; font-family: var(--serif); font-size: 24px; font-weight: 600; }
.intake-head .sub { margin: 4px 0 0; color: var(--ink-2); }
.templates { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.tpl {
  text-align: left; border: 1px solid var(--rule); background: var(--paper-2); border-radius: 10px;
  padding: 10px 12px; cursor: pointer; display: flex; flex-direction: column; gap: 2px;
}
.tpl:hover { border-color: var(--sage-mid); }
.tpl.on { border-color: var(--sage); background: var(--sage-soft); }
.tpl-title { font-family: var(--serif); font-size: 16px; font-weight: 600; }
.tpl-blurb { font-size: 12.5px; color: var(--ink-2); line-height: 1.35; }
.modes { border: 0; padding: 0; margin: 0; }
.modes legend { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); margin-bottom: 6px; padding: 0; }
.mode-list { display: flex; flex-wrap: wrap; gap: 8px; }
.mode { position: relative; }
.mode input { position: absolute; opacity: 0; pointer-events: none; }
.mode span { display: inline-block; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--rule-2); font-size: 13.5px; cursor: pointer; }
.mode input:checked + span { background: var(--sage); border-color: var(--sage); color: #fff; }
:root[data-theme="dark"] .mode input:checked + span { color: #13170f; }
.mode input:focus-visible + span { outline: 2px solid var(--sage); outline-offset: 2px; }
.label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); margin-bottom: 4px; }
.label .muted { text-transform: none; letter-spacing: 0; }
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
input[type="text"], select, textarea {
  width: 100%; border: 1px solid var(--rule-2); background: var(--paper); border-radius: 10px;
  padding: 9px 12px; color: var(--ink);
}
textarea { resize: vertical; line-height: 1.55; }
#passage { font-family: var(--serif); font-size: 16px; }
.passage-wrap.drag textarea { border-color: var(--sage); background: var(--sage-soft); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: end; }
.concept-tools { display: flex; gap: 8px; }
.concept-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.cchip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 10px; border-radius: 999px; background: var(--sage-soft); color: var(--sage-ink); font-size: 13.5px; }
.cchip .cid { font-family: var(--mono); font-size: 11px; opacity: 0.75; }
.cchip button { border: 0; background: transparent; cursor: pointer; color: inherit; font-size: 15px; line-height: 1; padding: 0 4px; border-radius: 999px; }
.add-row { display: flex; gap: 8px; }
.add-row.slim { margin-top: 8px; }
.add-row.slim input { padding: 6px 10px; font-size: 13px; }
.note { margin: 0; font-size: 13px; color: var(--ink-2); }
.note:empty { display: none; }
.intake-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.intake-strip { display: flex; align-items: center; gap: 10px; padding: 4px 2px; }
.strip-topic { font-family: var(--serif); font-size: 18px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.08em; padding: 3px 9px; border-radius: 999px; background: var(--sage-soft); color: var(--sage-ink); white-space: nowrap; }

/* --- thread --------------------------------------------------------------------- */
.thread { display: flex; flex-direction: column; gap: 14px; }
.thread:empty { display: none; }
.card { max-width: 88%; border-radius: var(--radius); padding: 14px 18px 12px; position: relative; }
.card.tutor { align-self: flex-start; background: var(--paper); border: 1px solid var(--rule); box-shadow: var(--shadow); }
.card.tutor::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px; border-radius: 0 3px 3px 0; background: var(--type-color, var(--sage)); }
.card.learner { align-self: flex-end; background: var(--sage-soft); border: 1px solid transparent; }
:root[data-theme="dark"] .card.learner { background: #2b3328; }
.card.gap { align-self: center; max-width: 70%; padding: 4px 12px; font-style: italic; color: var(--ink-3); font-size: 13px; }
.t-question { --type-color: var(--sage); }
.t-hint { --type-color: var(--honey); }
.t-check { --type-color: var(--sky); }
.t-summary { --type-color: var(--clay); }
.card-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; font-size: 12px; }
.type-label { text-transform: uppercase; letter-spacing: 0.1em; font-weight: 600; font-size: 11px; color: var(--type-color, var(--sage)); }
.c-chip { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--paper-2); border: 1px solid var(--rule); color: var(--ink-2); }
.c-chip.unknown { border-style: dashed; color: var(--clay); }
.lvl { margin-left: auto; font-size: 11.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.turn-no { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.say { font-family: var(--serif); font-size: 17px; line-height: 1.68; margin: 0; white-space: pre-wrap; }
.card.learner .say { font-size: 16.5px; }
.learner-meta { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 6px; font-size: 12px; color: var(--ink-2); }
.conf-dots { display: inline-flex; gap: 3px; }
.conf-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--rule-2); display: inline-block; }
.conf-dots i.on { background: var(--sage); }
.assess { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: baseline; margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--rule); font-size: 13px; color: var(--ink-2); }
.verdict { font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.08em; padding: 2px 8px; border-radius: 999px; }
.v-correct { background: var(--sage-soft); color: var(--sage-ink); }
.v-partial { background: var(--honey-soft); color: var(--honey); }
.v-misconception { background: var(--clay-soft); color: var(--clay); }
.v-stuck { background: var(--sky-soft); color: var(--sky); }
.delta { font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 12px; }
.delta.up { color: var(--sage-ink); }
.delta.down { color: var(--clay); }
.callout { margin-top: 10px; padding: 8px 12px; border-radius: 10px; font-size: 14px; }
.callout b { font-weight: 600; }
.callout.mis { background: var(--clay-soft); }
.callout.parent { background: var(--sky-soft); }
.callout.fix { background: var(--honey-soft); }
.fix-old { text-decoration: line-through; text-decoration-color: var(--clay); color: var(--ink-2); }
.fix-new { font-family: var(--serif); font-weight: 600; }
.hints { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.hints li { font-size: 14px; padding: 6px 10px; border-left: 3px solid var(--honey); background: var(--honey-soft); border-radius: 0 8px 8px 0; }
.hints .hl { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--honey); margin-right: 6px; font-weight: 600; }
.widgets { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.widgets .btn { font-size: 13px; padding: 5px 11px; border-radius: 999px; }
.recap { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.recap li { font-size: 14px; display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; align-items: baseline; }
.recap .rc-next { grid-column: 2 / 4; color: var(--ink-2); font-size: 13px; }
.transfer { margin-top: 10px; padding: 10px 12px; border: 1px dashed var(--clay); border-radius: 10px; font-family: var(--serif); font-size: 16px; }
.transfer .btn { display: block; margin-top: 8px; font-family: var(--sans, system-ui, sans-serif); }
.flags { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.flags li { font-size: 12.5px; color: var(--ink-2); padding-left: 16px; position: relative; }
.flags li::before { content: ""; position: absolute; left: 3px; top: 7px; width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); }
.flags li.warn::before { background: var(--clay); }
.flags .btn { margin-left: 6px; padding: 1px 8px; font-size: 12px; }
.card-meta { margin-top: 8px; font-size: 11.5px; color: var(--ink-3); }

/* --- composer, replay, progress ------------------------------------------------- */
.composer, .replay-bar, .progress { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); padding: 14px 18px; box-shadow: var(--shadow); }
.composer textarea { font-family: var(--serif); font-size: 16.5px; }
.conf-row { display: flex; align-items: center; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.conf-label { font-size: 13px; color: var(--ink-2); }
#confidence { flex: 1; min-width: 140px; accent-color: var(--sage); }
.conf-out { font-size: 13px; min-width: 110px; color: var(--sage-ink); font-variant-numeric: tabular-nums; }
.composer-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.meter { margin: 10px 0 0; font-size: 13px; color: var(--ink-2); }
.meter:empty { display: none; }
.gate { margin-top: 8px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 10px; background: var(--honey-soft); font-size: 13.5px; }
.replay-bar { position: sticky; bottom: 12px; z-index: 15; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; background: var(--sage-soft); border-color: transparent; }
.replay-note { flex: 1; min-width: 180px; font-size: 13.5px; color: var(--sage-ink); }
.pg-head { display: flex; justify-content: space-between; font-size: 13.5px; font-weight: 600; }
.pg-clock { font-family: var(--mono); font-weight: 400; color: var(--ink-3); }
.pg-steps { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--ink-3); }
.pg-steps li::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; border: 1.5px solid var(--rule-2); vertical-align: 0; }
.pg-steps li.done { color: var(--ink-2); }
.pg-steps li.done::before { background: var(--sage); border-color: var(--sage); }
.pg-steps li.now { color: var(--ink); }
.pg-steps li.now::before { border-color: var(--sage); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { background: var(--sage-mid); } }
@media (prefers-reduced-motion: reduce) { .pg-steps li.now::before { animation: none; } .bar-fill { transition: none !important; } }

/* --- instruments ------------------------------------------------------------------- */
.inst { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); padding: 14px 16px; }
.inst h3 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-3); font-weight: 600; }
.inst-head { display: flex; justify-content: space-between; align-items: baseline; }
.mastery-grid { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.mastery-grid:empty::after { content: "No concepts yet - add some on the left."; font-size: 13px; color: var(--ink-3); }
.m-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: 13px; }
.m-row.focus .m-label { font-weight: 600; }
.m-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-label .cid { font-family: var(--mono); font-size: 11px; color: var(--ink-3); margin-right: 5px; }
.m-pct { font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 12px; }
.bar { grid-column: 1 / 3; height: 8px; border-radius: 999px; background: var(--paper-2); border: 1px solid var(--rule); position: relative; overflow: hidden; }
.bar-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; background: var(--sage-mid); transition: width 0.6s ease; }
.bar-fill.b-solid { background: var(--sage); }
.bar-fill.b-mastered { background: var(--sage-ink); }
.bar-fill.b-new { background: var(--rule-2); }
.bar-tick { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--rule-2); }
.m-band { grid-column: 1 / 3; font-size: 11px; color: var(--ink-3); }
.suggestions { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.suggestions:empty { display: none; }
.sugg { font-size: 12.5px; border: 1px dashed var(--clay); border-radius: 10px; padding: 6px 8px; display: flex; gap: 6px; align-items: center; justify-content: space-between; }
.dial-wrap { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.dial { width: 100%; max-width: 230px; height: auto; }
.dial .arc { fill: none; stroke: var(--rule); stroke-width: 12; stroke-linecap: round; }
.dial .seg { fill: none; stroke-width: 12; stroke-linecap: butt; stroke: var(--paper-2); }
.dial .seg.allowed { stroke: var(--sage-soft); }
.dial .seg.cur { stroke: var(--sage); }
.dial .needle { stroke: var(--ink); stroke-width: 2.5; stroke-linecap: round; transition: transform 0.5s ease; transform-origin: 100px 100px; }
.dial .hub { fill: var(--ink); }
.dial text { font-size: 10px; fill: var(--ink-3); font-family: var(--sans); }
.dial-ctl { display: flex; align-items: center; gap: 10px; }
.dial-text { font-size: 13px; text-align: center; min-width: 150px; }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.timeline:empty::after { content: "Turns appear here."; font-size: 13px; color: var(--ink-3); }
.tl { width: 26px; height: 26px; border-radius: 7px; display: inline-flex; align-items: center; justify-content: center; font-size: 10.5px; font-family: var(--mono); cursor: pointer; border: 1px solid var(--rule); background: var(--paper-2); color: var(--ink-2); }
.tl.tutor { background: var(--type-color, var(--sage)); color: #fff; border-color: transparent; }
:root[data-theme="dark"] .tl.tutor { color: #13170f; }
.tl.learner.over { box-shadow: inset 0 0 0 2px var(--clay); }
.tl.learner.under { box-shadow: inset 0 0 0 2px var(--sky); }
.export-row { display: flex; flex-wrap: wrap; gap: 6px; }
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.history-list:empty::after { content: "Nothing saved yet."; font-size: 13px; color: var(--ink-3); }
.h-item { display: flex; align-items: center; gap: 6px; }
.h-open { flex: 1; min-width: 0; text-align: left; border: 1px solid var(--rule); background: var(--paper-2); border-radius: 10px; padding: 6px 10px; cursor: pointer; }
.h-open.cur { border-color: var(--sage); }
.h-title { display: block; font-family: var(--serif); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-sub { display: block; font-size: 11.5px; color: var(--ink-3); }
.h-del { border: 0; background: transparent; color: var(--ink-3); cursor: pointer; font-size: 16px; padding: 2px 6px; border-radius: 6px; }

/* --- footer, toasts ------------------------------------------------------------------ */
.foot { max-width: 1240px; margin: 12px auto 0; padding: 14px 28px 32px; color: var(--ink-3); font-size: 13px; }
.foot p { margin: 4px 0; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: var(--page); padding: 10px 14px; border-radius: 10px; font-size: 13.5px; box-shadow: var(--shadow); transition: opacity 0.4s; }
.toast a { color: inherit; margin-left: 8px; }
.toast.err { background: var(--clay); color: #fff; }
.toast.warn { background: var(--honey); color: #1d1a10; }
.toast.gone { opacity: 0; }

/* --- phones: the sidebar becomes a top strip ---------------------------------------- */
@media (max-width: 900px) {
  .topbar { padding: 12px 16px; }
  .topic-line { max-width: 60vw; }
  .layout { grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 12px 16px 8px; }
  .instruments {
    order: -1; position: sticky; top: 0; z-index: 20; flex-direction: row; overflow-x: auto; overflow-y: hidden;
    max-height: none; gap: 10px; padding: 8px 0; background: var(--page); scroll-snap-type: x proximity;
  }
  .inst { flex: 0 0 auto; width: 250px; padding: 10px 12px; scroll-snap-align: start; max-height: 168px; overflow-y: auto; }
  .inst h3 { margin-bottom: 6px; }
  .dial { max-width: 150px; }
  .card { max-width: 96%; }
  .row-2 { grid-template-columns: 1fr; }
  .intake { padding: 16px; }
  .foot { padding: 12px 16px 28px; }
}
@media (max-width: 520px) {
  .brand-text h1 { font-size: 19px; }
  .session .chip-link#home { display: none; }
  .say { font-size: 16px; }
  .composer-actions .btn { flex: 1 1 45%; }
}
