:root {
  --paper: #faf8f3;
  --panel: #f2eee5;
  --ink: #1d1b18;
  --soft: #5f5a51;
  --rule: #e0d9cb;
  --accent: #8c3f1f;
  --added: #1f6a66;
  --added-bg: #e3f0ee;
  --pick: #f6e3b4;
  --speak: #ffd98a;
  --good: #2e6b3a;
  --warn: #9a5a00;
  --bad: #a3271f;
  --read: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #171612;
    --panel: #201e19;
    --ink: #ece7dc;
    --soft: #a59f92;
    --rule: #37332b;
    --accent: #e39a73;
    --added: #7fcbc4;
    --added-bg: #17302e;
    --pick: #4a3d17;
    --speak: #6b5210;
    --good: #84c891;
    --warn: #e0ad5a;
    --bad: #ef8a80;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--ui); font-size: 1rem; line-height: 1.5; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--rule); background: var(--paper); border-radius: 0.4rem; padding: 0.45rem 0.9rem; touch-action: manipulation; }
button.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
button.quiet { border-color: transparent; background: none; padding: 0.3rem 0.5rem; color: var(--soft); }
button:disabled { opacity: 0.5; cursor: default; }
@media (hover: hover) {
  button:hover:not(:disabled) { border-color: var(--soft); }
  button.quiet:hover:not(:disabled) { color: var(--ink); border-color: transparent; }
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--read); font-weight: 600; line-height: 1.2; margin: 0; }
.soft { color: var(--soft); }
.small { font-size: 0.875rem; }
.error { color: var(--bad); }

/* ---------- home */
.home { max-width: 46rem; margin: 0 auto; padding: 2.5rem 1rem 4rem; }
.home h1 { font-size: 2rem; margin-bottom: 0.4rem; }
.home textarea { width: 100%; min-height: 16rem; margin-top: 1.25rem; padding: 0.9rem; border: 1px solid var(--rule); border-radius: 0.5rem; background: var(--panel); resize: vertical; font-size: 1rem; }
.home input[type=text], .home input[type=password] { width: 100%; margin-top: 0.75rem; padding: 0.6rem 0.9rem; border: 1px solid var(--rule); border-radius: 0.5rem; background: var(--panel); font-size: 1rem; }
.home .go { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; flex-wrap: wrap; }
.runs { margin-top: 3rem; border-top: 1px solid var(--rule); }
.runs a { display: block; padding: 0.9rem 0; border-bottom: 1px solid var(--rule); color: inherit; text-decoration: none; }
.runs .t { font-family: var(--read); font-size: 1.125rem; }
.badge { display: inline-block; font-size: 0.75rem; padding: 0.1rem 0.5rem; border-radius: 1rem; background: var(--pick); margin-left: 0.5rem; vertical-align: middle; }

/* ---------- progress */
.steps { list-style: none; padding: 0; margin: 1.5rem 0; }
.steps li { display: flex; gap: 0.75rem; padding: 0.5rem 0; border-bottom: 1px solid var(--rule); }
.steps .dot { width: 1.25rem; text-align: center; }
.steps .running .dot { animation: pulse 1.2s ease-in-out infinite; }
.steps .waiting { color: var(--soft); }
.steps .detail { margin-left: auto; color: var(--soft); font-size: 0.875rem; }
@keyframes pulse { 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .steps .running .dot { animation: none; } }

/* ---------- reader */
.reader { display: grid; grid-template-columns: 15rem minmax(0, 42rem) minmax(0, 24rem); gap: 2.5rem; max-width: 88rem; margin: 0 auto; padding: 2rem 1.5rem 8rem; align-items: start; }
.outline { position: sticky; top: 1.5rem; font-size: 0.875rem; max-height: calc(100vh - 3rem); overflow: auto; }
.outline a { display: block; padding: 0.35rem 0 0.35rem 0.75rem; border-left: 2px solid var(--rule); color: var(--soft); text-decoration: none; }
.outline a.here { color: var(--ink); border-left-color: var(--accent); }
.outline .home-link { border: 0; padding-left: 0; margin-bottom: 0.75rem; }
.outline button { margin-top: 1rem; width: 100%; }

.col { min-width: 0; }
.col .answer { font-family: var(--read); font-size: 1.75rem; line-height: 1.25; margin: 0.5rem 0 1rem; }
.col .overview { font-family: var(--read); font-size: 1.125rem; line-height: 1.6; margin: 0 0 1.25rem; }
.notice { border: 1px solid var(--rule); border-radius: 0.5rem; padding: 0.75rem 1rem; background: var(--panel); margin: 1rem 0; font-size: 0.9375rem; }
.chip { display: inline-flex; flex-wrap: wrap; gap: 0.35rem 0.9rem; align-items: baseline; border: 1px solid var(--rule); border-radius: 0.5rem; padding: 0.5rem 0.9rem; background: none; text-align: left; font-size: 0.875rem; }
.chip b { font-weight: 600; }
.ok { color: var(--good); } .warn { color: var(--warn); } .bad { color: var(--bad); }
details.cast { margin: 1.25rem 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding: 0.6rem 0; }
details.cast summary { cursor: pointer; font-weight: 600; }
details.cast dl { margin: 0.75rem 0 0.25rem; }
details.cast dt { font-weight: 600; margin-top: 0.6rem; }
details.cast dd { margin: 0; color: var(--soft); }

section.part { margin-top: 3rem; scroll-margin-top: 1rem; }
section.part h2 { font-size: 1.5rem; }
section.part .q { font-family: var(--read); font-style: italic; color: var(--soft); margin: 0.4rem 0 0; font-size: 1.0625rem; }
section.part .bar { display: flex; gap: 0.5rem; margin: 0.75rem 0 0; }
section.part p.para { font-family: var(--read); font-size: 1.1875rem; line-height: 1.65; margin: 1rem 0; }
.s { cursor: pointer; border-radius: 0.2rem; padding: 0.05em 0; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
@media (hover: hover) { .s:hover { background: var(--panel); } }
.s.added { color: var(--added); }
.s.flag { text-decoration: underline wavy var(--bad); text-underline-offset: 0.2em; }
.s.pick { background: var(--pick); }
.s.speaking { background: var(--speak); }
.tag { font-family: var(--ui); font-size: 0.6875rem; font-style: normal; background: var(--added-bg); color: var(--added); border-radius: 0.25rem; padding: 0.1rem 0.4rem; margin-right: 0.35rem; vertical-align: 0.15em; white-space: nowrap; }

figure.diagram { margin: 1.5rem 0; padding: 1rem; border: 1px solid var(--rule); border-radius: 0.5rem; background: var(--panel); overflow-x: auto; }
figure.diagram figcaption { font-size: 0.875rem; color: var(--soft); margin-bottom: 0.75rem; }
figure.diagram figcaption b { color: var(--ink); }
figure.diagram svg { display: block; max-width: 100%; height: auto; margin: 0 auto; }
figure.diagram ul { margin: 0; padding-left: 1.1rem; font-size: 0.9375rem; }
figure.diagram table { border-collapse: collapse; width: 100%; font-size: 0.9375rem; }
figure.diagram th, figure.diagram td { text-align: left; vertical-align: top; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--rule); }

.ledger { margin-top: 4rem; border-top: 2px solid var(--ink); padding-top: 1.25rem; scroll-margin-top: 1rem; }
.ledger h2 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.ledger h3 { font-family: var(--ui); font-size: 0.9375rem; margin: 1.25rem 0 0.4rem; }
.ledger ul { margin: 0; padding-left: 1.1rem; }
.ledger li { margin: 0.4rem 0; }
.ledger li button { padding: 0 0.3rem; font-size: 0.8125rem; }
.finish { margin-top: 3rem; padding: 1.25rem; border: 1px solid var(--ink); border-radius: 0.5rem; }
.finish h2 { font-size: 1.375rem; margin-bottom: 0.4rem; }

/* ---------- source panel */
.side { position: sticky; top: 1.5rem; max-height: calc(100vh - 3rem); overflow: auto; font-size: 0.9375rem; border-left: 1px solid var(--rule); padding-left: 1.25rem; }
.side .hint { color: var(--soft); }
.side h3 { font-family: var(--ui); font-size: 0.8125rem; color: var(--soft); font-weight: 600; margin: 0 0 0.5rem; }
.side .close { display: none; }
.claim { margin: 0 0 1.25rem; padding-bottom: 1rem; border-bottom: 1px solid var(--rule); }
.claim .kind { font-size: 0.75rem; color: var(--soft); }
.claim .ct { margin: 0.15rem 0 0.5rem; font-weight: 500; }
.claim blockquote { margin: 0; padding: 0.6rem 0.8rem; background: var(--panel); border-radius: 0.4rem; font-family: var(--read); white-space: pre-wrap; max-height: 16rem; overflow: auto; }
.claim blockquote mark { background: var(--pick); color: inherit; }
.note { margin: 0.4rem 0; font-size: 0.875rem; }

/* ---------- player */
#player { position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%); display: flex; gap: 0.4rem; align-items: center; background: var(--ink); color: var(--paper); border-radius: 2rem; padding: 0.4rem 0.6rem; box-shadow: 0 0.25rem 1rem rgb(0 0 0 / 0.25); max-width: calc(100vw - 1rem); z-index: 5; }
#player[hidden] { display: none; }
#player button, #player select { background: none; color: inherit; border-color: transparent; padding: 0.35rem 0.6rem; }
#player select { max-width: 9rem; border: 1px solid rgb(128 128 128 / 0.5); border-radius: 1rem; }
#player option { color: #111; }

/* ---------- explain-back */
.back { max-width: 44rem; margin: 0 auto; padding: 2.5rem 1rem 6rem; }
.back h1 { font-size: 1.75rem; margin-bottom: 0.5rem; }
.back textarea { width: 100%; min-height: 18rem; padding: 0.9rem; border: 1px solid var(--rule); border-radius: 0.5rem; background: var(--panel); font-family: var(--read); font-size: 1.125rem; line-height: 1.55; resize: vertical; }
.scale { display: flex; gap: 0.4rem; flex-wrap: wrap; margin: 0.5rem 0 1.25rem; }
.scale button { min-width: 2.75rem; min-height: 2.75rem; }
.scale button.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.marks { list-style: none; padding: 0; margin: 1.25rem 0; counter-reset: m; }
.marks li { counter-increment: m; border-top: 1px solid var(--rule); padding: 0.9rem 0; }
.marks .head { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: baseline; }
.marks .head::before { content: counter(m) "."; font-weight: 600; }
.pill { font-size: 0.75rem; padding: 0.1rem 0.5rem; border-radius: 1rem; border: 1px solid currentColor; }
.pill.got { color: var(--good); } .pill.partial { color: var(--warn); } .pill.missing, .pill.wrong { color: var(--bad); }
.marks q { font-family: var(--read); display: block; margin: 0.4rem 0 0; color: var(--soft); }
.ask { font-family: var(--read); font-size: 1.25rem; line-height: 1.45; border-left: 3px solid var(--accent); padding: 0.25rem 0 0.25rem 1rem; margin: 1.5rem 0; }
.qa { border-top: 1px solid var(--rule); padding: 1rem 0; }
.qa textarea { min-height: 6rem; font-size: 1rem; }
.row { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; margin-top: 0.75rem; }

@media (max-width: 68rem) {
  .reader { grid-template-columns: minmax(0, 42rem); justify-content: center; gap: 0; padding: 1rem 1rem 8rem; }
  .outline { position: static; max-height: none; margin-bottom: 1rem; display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
  .outline a:not(.home-link) { display: none; }
  .outline .home-link { margin: 0; }
  .outline button { width: auto; margin: 0 0 0 auto; }
  .side { position: fixed; inset: auto 0 0 0; max-height: 62vh; background: var(--paper); border: 0; border-top: 1px solid var(--ink); padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom)); z-index: 6; box-shadow: 0 -0.5rem 1.5rem rgb(0 0 0 / 0.2); }
  .side.empty { display: none; }
  .side .close { display: block; float: right; }
  .col .answer { font-size: 1.5rem; }
  section.part p.para { font-size: 1.125rem; }
}
