/* "Blue book" exam paper: cool ruled paper, navy ink, a cobalt pen for the student, red only for the margin
   rule and the subskill under focus. */
:root {
  --paper: #f3f6f9;
  --sheet: #ffffff;
  --rule: #d5dfea;
  --rule-soft: #ebf0f6;
  --ink: #1c2748;
  --ink-2: #5a6684;
  --pen: #2a47c4;
  --margin-red: #d2574a;
  --focus-ring: #2a47c4;
  --fill: #1c2748;
  --empty: #dfe6ef;
  --serif: "Literata", Georgia, serif;
  --sans: "Public Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0e1525; --sheet: #141d33; --rule: #26334f; --rule-soft: #1b2640;
    --ink: #e2e8f3; --ink-2: #94a0bb; --pen: #93a9ff; --margin-red: #e8776b;
    --focus-ring: #93a9ff; --fill: #e2e8f3; --empty: #26334f; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0e1525; --sheet: #141d33; --rule: #26334f; --rule-soft: #1b2640;
  --ink: #e2e8f3; --ink-2: #94a0bb; --pen: #93a9ff; --margin-red: #e8776b;
  --focus-ring: #93a9ff; --fill: #e2e8f3; --empty: #26334f; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: 3px; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- shell */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr) 288px; height: 100dvh; }
.sessions, .ledger { background: var(--paper); display: flex; flex-direction: column; min-height: 0; }
.sessions { border-right: 1px solid var(--rule); padding: 20px 14px 14px; }
.ledger { border-left: 1px solid var(--rule); padding: 20px 20px 16px; overflow-y: auto; }
.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--sheet); }

.wordmark { font: 600 1.25rem/1 var(--serif); color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.sessions-head, .ledger-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.new-btn { width: 100%; margin-bottom: 14px; }
.session-list { flex: 1; overflow-y: auto; margin: 0 -6px; }
.session-item { display: flex; align-items: center; gap: 4px; border-radius: 6px; }
.session-item a { flex: 1; min-width: 0; padding: 7px 8px; color: var(--ink); text-decoration: none; font-size: 0.9rem; line-height: 1.3; }
.session-item a span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-item a small { color: var(--ink-2); font-size: 0.75rem; }
.session-item:hover { background: var(--rule-soft); }
.session-item.active { background: var(--rule-soft); box-shadow: inset 2px 0 0 var(--margin-red); }
.session-item .del { opacity: 0; border: 0; background: none; color: var(--ink-2); cursor: pointer; padding: 6px 8px; border-radius: 4px; }
.session-item:hover .del, .session-item .del:focus-visible { opacity: 1; }
.session-empty { color: var(--ink-2); font-size: 0.875rem; padding: 4px 8px; }
.sessions-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 12px; border-top: 1px solid var(--rule); }
.mode-pill { font-size: 0.75rem; color: var(--ink-2); }

/* ---------- buttons */
.btn { appearance: none; border: 1px solid var(--rule); background: var(--sheet); color: var(--ink); padding: 9px 16px; border-radius: 6px; cursor: pointer; font-weight: 500; font-size: 0.95rem; white-space: nowrap; }
.btn:hover { border-color: var(--ink-2); }
.btn-primary { background: var(--ink); border-color: var(--ink); color: var(--sheet); }
.btn-primary:hover { background: var(--pen); border-color: var(--pen); }
.btn:disabled { opacity: 0.5; cursor: default; }
.link-btn { border: 0; background: none; padding: 4px 2px; color: var(--ink-2); cursor: pointer; font-size: 0.9rem; text-decoration: underline; text-underline-offset: 3px; }
.link-btn:hover { color: var(--ink); }
.icon-btn { border: 0; background: none; padding: 6px 8px; cursor: pointer; color: var(--ink-2); font-size: 0.95rem; border-radius: 4px; }

/* ---------- start screen: a ruled sheet with a red margin */
.start {
  flex: 1; overflow-y: auto; padding: 12vh 40px 40px 120px; position: relative;
  background:
    linear-gradient(to right, transparent 86px, var(--margin-red) 86px, var(--margin-red) 88px, transparent 88px),
    repeating-linear-gradient(to bottom, transparent 0, transparent 31px, var(--rule-soft) 31px, var(--rule-soft) 32px);
}
.start-form { max-width: 640px; }
.start-q { font: 500 clamp(2rem, 4.5vw, 3.1rem)/1.1 var(--serif); letter-spacing: -0.02em; margin: 0 0 28px; text-wrap: balance; }
.start-row { display: flex; gap: 10px; }
.start-row input { flex: 1; min-width: 0; padding: 13px 14px; border: 1px solid var(--rule); border-radius: 6px; background: var(--sheet); font-size: 1.05rem; color: var(--pen); }
.start-row input::placeholder { color: var(--ink-2); opacity: 0.7; }
.start-row .btn { padding: 13px 18px; }
.start-blurb { color: var(--ink-2); max-width: 60ch; margin: 14px 0 36px; font-size: 0.95rem; }
.skill-pick { border: 0; padding: 0; margin: 0; }
.skill-pick legend { font-weight: 600; font-size: 0.9rem; margin-bottom: 10px; padding: 0; }
.skill-opt { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; margin-bottom: 6px; border: 1px solid var(--rule); border-radius: 6px; background: var(--sheet); cursor: pointer; }
.skill-opt:has(input:checked) { border-color: var(--ink); }
.skill-opt input { margin-top: 4px; accent-color: var(--ink); }
.skill-opt strong { font-weight: 600; }
.skill-desc { display: block; color: var(--ink-2); font-size: 0.875rem; margin-top: 2px; }
.custom-skill { margin: 8px 0 0 0; }
.custom-row { display: flex; gap: 8px; margin-bottom: 8px; }
.custom-row input, .custom-skill textarea { flex: 1; width: 100%; min-width: 0; padding: 9px 11px; border: 1px solid var(--rule); border-radius: 6px; background: var(--sheet); }
.custom-skill textarea { font: 0.82rem/1.5 var(--mono); resize: vertical; }
.hint { color: var(--ink-2); font-size: 0.82rem; margin: 6px 0 0; }
.credit { color: var(--ink-2); font-size: 0.8rem; margin: 48px 0 0; max-width: 640px; }
.credit a { color: inherit; }

/* ---------- dialogue: a script, speaker in the margin */
.convo { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.scroll { flex: 1; overflow-y: auto; }
.dialogue {
  list-style: none; margin: 0; padding: 40px 32px 24px 0; max-width: 820px;
  background: linear-gradient(to right, transparent 102px, var(--margin-red) 102px, var(--margin-red) 104px, transparent 104px);
  min-height: 100%;
}
.turn { display: grid; grid-template-columns: 104px minmax(0, 1fr); margin-bottom: 26px; }
.speaker { text-align: right; padding: 3px 16px 0 0; font-size: 0.78rem; font-weight: 600; color: var(--ink-2); letter-spacing: 0.01em; }
.turn .body { padding-left: 22px; min-width: 0; max-width: 68ch; }
.turn.user .speaker { color: var(--pen); }
.turn.user .body { color: var(--pen); white-space: pre-wrap; font-size: 1rem; }
.turn.assistant .body { font: 1.03rem/1.65 var(--serif); }
.body > :first-child { margin-top: 0; }
.body > :last-child { margin-bottom: 0; }
.body p { margin: 0 0 0.8em; }
.body h1, .body h2, .body h3 { font: 600 1.1rem/1.3 var(--serif); margin: 1.2em 0 0.4em; }
.body ul, .body ol { padding-left: 1.3em; margin: 0 0 0.8em; }
.body li { margin: 0.2em 0; }
.body code { font: 0.86em var(--mono); background: var(--rule-soft); padding: 0.1em 0.35em; border-radius: 3px; }
.body pre { font: 0.82rem/1.45 var(--mono); background: var(--paper); border: 1px solid var(--rule); border-radius: 6px; padding: 12px 14px; overflow-x: auto; margin: 0 0 0.9em; }
.body pre code { background: none; padding: 0; font-size: inherit; }
.body blockquote { margin: 0 0 0.8em; padding-left: 14px; border-left: 2px solid var(--rule); color: var(--ink-2); }
.body a { color: var(--pen); }
.body table { border-collapse: collapse; font-size: 0.9rem; margin-bottom: 0.9em; }
.body th, .body td { border: 1px solid var(--rule); padding: 4px 8px; }
.cursor::after { content: ""; display: inline-block; width: 0.5em; height: 1.05em; background: var(--ink-2); vertical-align: text-bottom; margin-left: 2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.thinking { color: var(--ink-2); font: italic 1rem var(--serif); }
.turn-error { color: var(--margin-red); font-size: 0.92rem; }
.turn-error .btn { margin-left: 8px; padding: 4px 10px; font-size: 0.85rem; }

/* ---------- composer */
.composer-wrap { border-top: 1px solid var(--rule); padding: 12px 32px 14px 126px; background: var(--sheet); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; max-width: 694px; }
.chip { border: 1px solid var(--rule); background: var(--sheet); color: var(--ink-2); border-radius: 999px; padding: 3px 11px; font-size: 0.8rem; cursor: pointer; }
.chip:hover { color: var(--ink); border-color: var(--ink-2); }
.composer { display: flex; gap: 8px; align-items: flex-end; max-width: 694px; }
.composer textarea { flex: 1; min-width: 0; resize: none; border: 1px solid var(--rule); border-radius: 6px; padding: 10px 12px; background: var(--sheet); color: var(--pen); max-height: 40vh; line-height: 1.45; }
.composer textarea:focus { border-color: var(--ink-2); outline: none; }
.composer-hint { margin: 6px 0 0; font-size: 0.72rem; color: var(--ink-2); }

/* ---------- ledger (skill map) */
.ledger h2 { font: 600 1.05rem/1 var(--serif); margin: 0; }
.ledger-topic { font: 500 1rem/1.3 var(--serif); margin: 0 0 4px; }
.ledger-overall { display: flex; align-items: baseline; gap: 8px; margin-bottom: 18px; color: var(--ink-2); font-size: 0.85rem; }
.ledger-overall b { font: 500 1.9rem/1 var(--serif); color: var(--ink); font-variant-numeric: tabular-nums; }
.skill-rows { list-style: none; margin: 0 0 20px; padding: 0; }
.skill-row { padding: 9px 0; border-bottom: 1px solid var(--rule-soft); }
.skill-row:first-child { border-top: 1px solid var(--rule-soft); }
.skill-row-top { display: flex; justify-content: space-between; gap: 8px; font-size: 0.88rem; line-height: 1.3; margin-bottom: 6px; }
.skill-row-top span:last-child { font-variant-numeric: tabular-nums; color: var(--ink-2); flex: none; }
.pips { display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px; }
.pip { height: 6px; border-radius: 1px; background: var(--empty); }
.pip.on { background: var(--fill); }
.skill-row.focus .skill-row-top span:first-child { color: var(--margin-red); font-weight: 600; }
.skill-row.focus .pip.on { background: var(--margin-red); }
.skill-note { display: block; font-size: 0.75rem; color: var(--ink-2); margin-top: 4px; }
.ledger-empty { color: var(--ink-2); font-size: 0.88rem; margin: 0 0 20px; }
.ledger-updated { font-size: 0.75rem; color: var(--ink-2); margin: -10px 0 20px; }
.scale { margin: auto 0 0; padding-top: 14px; border-top: 1px solid var(--rule); font-size: 0.78rem; color: var(--ink-2); display: grid; gap: 3px; }
.scale div { display: flex; gap: 8px; }
.scale dt { font-family: var(--mono); color: var(--ink); width: 1ch; }
.scale dd { margin: 0; }

/* ---------- settings */
.settings { border: 1px solid var(--rule); border-radius: 10px; padding: 24px; width: min(460px, calc(100vw - 32px)); background: var(--sheet); color: var(--ink); }
.settings::backdrop { background: rgb(14 21 37 / 0.45); }
.settings h2 { font: 600 1.3rem/1.2 var(--serif); margin: 0 0 6px; }
.settings-lede { color: var(--ink-2); font-size: 0.92rem; margin: 0 0 18px; }
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-weight: 600; font-size: 0.88rem; margin-bottom: 5px; }
.field input { width: 100%; padding: 9px 11px; border: 1px solid var(--rule); border-radius: 6px; background: var(--paper); }
.field small { display: block; color: var(--ink-2); font-size: 0.78rem; margin-top: 5px; line-height: 1.4; }
.check-result { min-height: 1.4em; font-size: 0.88rem; margin: 0 0 12px; }
.check-result.ok { color: var(--pen); }
.check-result.bad { color: var(--margin-red); }
.settings-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- responsive */
.only-mobile { display: none; }
.scrim { display: none; }
@media (max-width: 1100px) {
  .shell { grid-template-columns: 232px minmax(0, 1fr); }
  .ledger { position: fixed; inset: 0 0 0 auto; width: min(320px, 88vw); z-index: 20; transform: translateX(100%); transition: transform 0.2s ease; box-shadow: none; }
  .shell.map-open .ledger { transform: none; box-shadow: -8px 0 30px rgb(0 0 0 / 0.12); }
  .shell.map-open .scrim { display: block; }
  .only-mobile.ledger-only, #open-map { display: inline-block; }
  .topbar { display: flex !important; }
  #open-sessions { visibility: hidden; }
  #close-map { display: inline-block; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sessions { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 20; transform: translateX(-100%); transition: transform 0.2s ease; }
  .shell.sessions-open .sessions { transform: none; box-shadow: 8px 0 30px rgb(0 0 0 / 0.12); }
  .shell.sessions-open .scrim { display: block; }
  .only-mobile { display: inline-block; }
  #open-sessions { visibility: visible; }
  .start { padding: 48px 16px 32px 16px; background: repeating-linear-gradient(to bottom, transparent 0, transparent 31px, var(--rule-soft) 31px, var(--rule-soft) 32px); }
  .start-row { flex-direction: column; }
  .dialogue { padding: 20px 16px 16px 0; background: linear-gradient(to right, transparent 15px, var(--margin-red) 15px, var(--margin-red) 16px, transparent 16px); }
  .turn { grid-template-columns: 16px minmax(0, 1fr); }
  .speaker { grid-column: 2; padding: 0 0 4px 14px; text-align: left; }
  .turn .body { grid-column: 2; padding-left: 14px; }
  .composer-wrap { padding: 10px 16px 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .composer-hint { display: none; }
}
.topbar { display: none; align-items: center; justify-content: space-between; padding: 8px 10px; border-bottom: 1px solid var(--rule); background: var(--sheet); }
.topbar-title { font: 600 1rem/1 var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scrim { position: fixed; inset: 0; background: rgb(14 21 37 / 0.35); z-index: 10; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
