:root {
  --bg: #eef2f7;
  --card: #ffffff;
  --text: #1b2733;
  --muted: #5f6e7d;
  --border: #dde4ec;
  --accent: #2e6da4;
  --accent-ink: #ffffff;
  --head-a: #1f3a5f;
  --head-b: #2e6da4;
  --chip: #e8eff7;
  --good: #1e7d4a;
  --good-bg: #dcf4e6;
  --bad: #b02a2a;
  --bad-bg: #fde3e3;
  --warn: #8a6000;
  --warn-bg: #fdf1d6;
  --k: #2e6da4;
  --r: #a05a00;
  --s: #2d7d5a;
  --shadow: 0 1px 4px rgba(27, 39, 51, .08);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10161d;
    --card: #19212b;
    --text: #e6edf4;
    --muted: #9aa8b6;
    --border: #2a3542;
    --accent: #5aa0e0;
    --accent-ink: #0b1420;
    --head-a: #142840;
    --head-b: #1f4d7a;
    --chip: #233142;
    --good: #5fd18f;
    --good-bg: #173326;
    --bad: #ff8a8a;
    --bad-bg: #3a1c1f;
    --warn: #f0c35a;
    --warn-bg: #3a2f14;
    --k: #7ab4ea;
    --r: #f0aa55;
    --s: #6fd0a2;
    --shadow: 0 1px 4px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; font-weight: 400; }

/* Header */
.top {
  background: linear-gradient(135deg, var(--head-a), var(--head-b));
  color: #fff;
  padding: 18px 0 0;
  margin-bottom: 16px;
}
.top a { color: #fff; }
.crumbs { font-size: 13px; opacity: .85; }
.crumbs a { text-decoration: none; font-weight: 600; }
.crumbs a:hover { text-decoration: underline; }
.top h1 { margin: 6px 0 2px; font-size: 25px; font-weight: 650; letter-spacing: -.3px; }
.doc-line { margin: 0 0 14px; font-size: 13.5px; opacity: .85; }
.tabs { display: flex; gap: 4px; }
.tabs button {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 0; border-radius: 10px 10px 0 0;
  padding: 9px 16px;
  background: rgba(255, 255, 255, .14); color: #fff;
}
.tabs button[aria-selected="true"] { background: var(--bg); color: var(--text); }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  min-width: 0;
}
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); margin: 0 0 10px; font-weight: 650; }

.toolbar { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; }
.field { display: grid; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); flex: 1 1 260px; min-width: 0; }
.check { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
select, button { font: inherit; color: var(--text); }
select {
  width: 100%; min-width: 0;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
button {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 12px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.link { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; font-size: 13px; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 860px) { .grid { grid-template-columns: minmax(0, 1fr); } }

/* Task card */
.task h3 { margin: 0 0 4px; font-size: 19px; line-height: 1.3; }
.task .code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; color: var(--muted); }
.task dl { margin: 12px 0; display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; font-size: 13.5px; }
.task dt { font-weight: 650; color: var(--muted); }
.task dd { margin: 0; }
.note { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 6px 10px; font-size: 13px; margin: 6px 0; }
.applies { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .5px; padding: 2px 8px; border-radius: 20px; background: var(--chip); color: var(--muted); margin-left: 6px; vertical-align: middle; }
.stats { font-size: 13px; color: var(--muted); margin: 8px 0 4px; }

.section-title { display: flex; align-items: center; gap: 8px; margin: 18px 0 6px; font-size: 13px; font-weight: 700; }
.section-title .dot { width: 10px; height: 10px; border-radius: 3px; }
.dot.K { background: var(--k); } .dot.R { background: var(--r); } .dot.S { background: var(--s); }
.section-title .intro { font-weight: 400; color: var(--muted); }

ul.elements { list-style: none; margin: 0; padding: 0; }
.el { display: grid; grid-template-columns: 6.8em minmax(0, 1fr) auto; gap: 4px 10px; padding: 6px 0; border-top: 1px solid var(--border); font-size: 14px; align-items: start; }
.el.sub { padding-left: 1.2em; grid-template-columns: 5.6em minmax(0, 1fr) auto; }
.el .ecode { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--muted); padding-top: 2px; overflow-wrap: anywhere; }
.el.archived .etext { color: var(--muted); font-style: italic; }
.el.heading .etext { font-weight: 600; }
.el .side { display: flex; gap: 6px; align-items: center; }
.qchip { font-size: 12px; padding: 1px 8px; border-radius: 20px; background: var(--chip); border: 1px solid transparent; color: var(--text); }
.qchip:hover { border-color: var(--accent); }
.qchip.active { background: var(--accent); color: var(--accent-ink); }
.mark { width: 28px; height: 24px; padding: 0; font-size: 13px; line-height: 1; border-radius: 6px; color: var(--muted); }
.mark[data-state="ok"] { background: var(--good-bg); color: var(--good); border-color: var(--good); }
.mark[data-state="review"] { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }

/* Quiz */
.quiz-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.quiz-head h2 { margin: 0; }
.scope { display: flex; flex-wrap: wrap; gap: 4px; }
.scope button { font-size: 13px; padding: 4px 10px; }
.scope button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.filter-chip { margin: 10px 0 0; font-size: 13px; }
.filter-chip button { font-size: 12px; padding: 1px 8px; margin-left: 6px; }
#quiz-status { font-size: 13px; margin: 10px 0 6px; }
.qmeta { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.qmeta .kind { font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.prompt { font-size: 16.5px; font-weight: 600; line-height: 1.45; margin: 0 0 12px; }
.options { display: grid; gap: 8px; }
.option {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: start;
  text-align: left; width: 100%; padding: 10px 12px; border-radius: 10px; line-height: 1.4;
}
.option .key { font-weight: 700; color: var(--muted); }
.option.correct { background: var(--good-bg); border-color: var(--good); }
.option.incorrect { background: var(--bad-bg); border-color: var(--bad); }
.option:disabled { cursor: default; color: var(--text); }
.reveal { margin-top: 4px; }
.answer { border-left: 4px solid var(--s); padding: 8px 12px; background: var(--chip); border-radius: 0 8px 8px 0; line-height: 1.5; }
.grade { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.feedback { margin-top: 12px; font-size: 14px; line-height: 1.5; }
.feedback .ok { color: var(--good); font-weight: 700; }
.feedback .no { color: var(--bad); font-weight: 700; }
.feedback .ref { color: var(--muted); font-size: 12.5px; margin-top: 6px; }
.controls { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.controls .primary { margin-left: auto; }
.empty { color: var(--muted); }

/* Flags */
.flag-box { margin-top: 12px; }
.flag-btn { font-size: 13px; padding: 4px 10px; color: var(--muted); }
.flag-btn[aria-pressed="true"] { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.flag-note { font-size: 13px; color: var(--warn); margin-left: 6px; }
.flag-box textarea {
  display: block; width: 100%; min-height: 72px; margin: 8px 0;
  font: inherit; font-size: 14px; color: var(--text); background: var(--card);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; resize: vertical;
}
.flag-box .row { display: flex; flex-wrap: wrap; gap: 8px; }
.flag-item { border-top: 1px solid var(--border); padding: 10px 0; font-size: 13.5px; }
.flag-item .fhead { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px; color: var(--muted); font-size: 12.5px; }
.flag-item .fq { margin: 4px 0; font-weight: 600; }
.flag-item .fn { color: var(--warn); white-space: pre-wrap; }
.flag-item .fbtns { display: flex; gap: 6px; }
.flag-item .fbtns button { font-size: 12px; padding: 2px 8px; }
.flags .controls .link { margin-left: auto; }

/* Progress */
.progress table { width: 100%; border-collapse: collapse; font-size: 13px; }
.progress th, .progress td { text-align: left; padding: 6px 8px; border-top: 1px solid var(--border); }
.progress th { color: var(--muted); font-weight: 600; }
.progress td.num, .progress th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar { height: 8px; background: var(--chip); border-radius: 4px; overflow: hidden; min-width: 60px; }
.bar i { display: block; height: 100%; background: var(--accent); }
.progress .tbl { overflow-x: auto; }
.progress button.link { margin-top: 10px; }

.foot { font-size: 12.5px; color: var(--muted); padding-bottom: 32px; }

@media (max-width: 520px) {
  .el, .el.sub { grid-template-columns: minmax(0, 1fr) auto; }
  .el .ecode { grid-column: 1 / -1; padding: 0; }
  .progress .hide-sm { display: none; }
}
