:root {
  color-scheme: light;
  --paper: #f7f3ea;
  --ink: #1f2421;
  --muted: #6e7169;
  --line: #d8d0c0;
  --panel: #fffaf0;
  --accent: #b13f2a;
  --accent-dark: #742b22;
  --good: #1f7a4d;
  --bad: #b3261e;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(31,36,33,.04) 1px, transparent 1px),
    linear-gradient(var(--paper), #eee5d6);
  background-size: 42px 42px, auto;
  font-family: Georgia, "Times New Roman", serif;
}
button, select { font: inherit; }
.shell { width: min(1180px, calc(100% - 24px)); margin: 0 auto; padding: 18px 0 40px; }
.topbar { display: flex; justify-content: space-between; align-items: end; gap: 18px; border-bottom: 2px solid var(--ink); padding-bottom: 18px; }
.kicker { margin: 0 0 5px; text-transform: uppercase; letter-spacing: .12em; color: var(--accent-dark); font: 700 12px/1.2 system-ui, sans-serif; }
h1 { margin: 0; font-size: clamp(32px, 5vw, 62px); line-height: .95; max-width: 720px; }
.score-pill { min-width: 116px; border: 2px solid var(--ink); padding: 9px 12px; display: grid; gap: 2px; text-align: right; background: var(--panel); }
.score-pill span { color: var(--muted); font: 700 12px/1.2 system-ui, sans-serif; }
.score-pill strong { font-size: 28px; }
.controls { display: grid; grid-template-columns: 1.4fr 1fr .8fr auto; gap: 12px; margin: 18px 0; align-items: end; }
label { display: grid; gap: 6px; color: var(--muted); font: 700 12px/1.2 system-ui, sans-serif; text-transform: uppercase; letter-spacing: .08em; }
select, button { border: 2px solid var(--ink); background: var(--panel); color: var(--ink); min-height: 46px; padding: 9px 11px; }
button { cursor: pointer; background: var(--ink); color: var(--paper); font-weight: 700; }
button:disabled { cursor: not-allowed; opacity: .45; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.quiz-panel, .side-panel { border: 2px solid var(--ink); background: rgba(255,250,240,.94); padding: 18px; }
.meta-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.meta-row span { border: 1px solid var(--line); padding: 6px 8px; color: var(--muted); font: 700 12px/1.2 system-ui, sans-serif; }
#questionText { margin: 0 0 18px; font-size: clamp(22px, 3vw, 34px); line-height: 1.12; }
.options { display: grid; gap: 10px; }
.option { text-align: left; color: var(--ink); background: #fff; border-color: var(--line); font-weight: 500; line-height: 1.35; min-height: 58px; }
.option.correct { border-color: var(--good); box-shadow: inset 6px 0 0 var(--good); }
.option.wrong { border-color: var(--bad); box-shadow: inset 6px 0 0 var(--bad); }
.feedback { margin-top: 14px; padding: 14px; border-left: 6px solid var(--accent); background: #fff; line-height: 1.45; }
.feedback a, .manual a { color: var(--accent-dark); font-weight: 700; }
.hidden { display: none; }
.actions { display: flex; gap: 10px; margin-top: 16px; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 18px; }
.stat-grid div { border: 1px solid var(--line); padding: 10px; background: #fff; }
.stat-grid span { display: block; color: var(--muted); font: 700 11px/1.2 system-ui, sans-serif; text-transform: uppercase; }
.stat-grid strong { font-size: 26px; }
.linked-chapter { scroll-margin-top: 12px; outline: 0; }
.side-label { margin: 0 0 8px; color: var(--accent-dark); font: 800 12px/1.2 system-ui, sans-serif; letter-spacing: .1em; text-transform: uppercase; }
.side-panel h3 { margin: 0 0 8px; font-size: 23px; line-height: 1.1; }
#linkedChapterMeta { margin: 0 0 12px; color: var(--muted); font: 700 12px/1.35 system-ui, sans-serif; }
.chapter-preview { max-height: 430px; overflow: auto; color: #3e423b; line-height: 1.5; border-top: 1px solid var(--line); padding-top: 12px; }
@media (max-width: 820px) {
  .topbar, .actions { align-items: stretch; flex-direction: column; }
  .controls, .layout { grid-template-columns: 1fr; }
  .score-pill { text-align: left; }
}
@media (max-width: 560px) {
  body { background-size: 30px 30px, auto; }
  .shell { width: min(100% - 16px, 1180px); padding-top: 10px; }
  .topbar { gap: 12px; padding-bottom: 12px; }
  h1 { font-size: 33px; }
  .score-pill { grid-template-columns: 1fr auto; align-items: center; min-width: 0; padding: 8px 10px; }
  .score-pill strong { font-size: 24px; }
  .controls { gap: 9px; margin: 12px 0; }
  label { gap: 5px; letter-spacing: .05em; }
  select, button { width: 100%; min-height: 48px; }
  .quiz-panel, .side-panel { padding: 13px; }
  .meta-row { margin-bottom: 12px; }
  .meta-row span { max-width: 100%; overflow-wrap: anywhere; }
  #questionText { font-size: 23px; line-height: 1.16; }
  .option { min-height: 64px; padding: 12px; }
  .feedback { padding: 12px; }
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .stat-grid div { padding: 8px; }
  .stat-grid strong { font-size: 22px; }
  .chapter-preview { max-height: 52vh; }
}
