:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede6;
  --text: #1d1f22;
  --muted: #5d6168;
  --border: #d9d6cc;
  --accent: #b3261e;
  --accent-soft: #fbe9e7;
  --ok: #1e7a3c;
  --ok-soft: #e3f3e8;
  --warn: #9a6200;
  --term-bg: #15171a;
  --term-fg: #d7dbe0;
  --term-dim: #8a9099;
  --term-ok: #7fd69a;
  --term-warn: #f2c14e;
  --term-err: #ff7b72;
  --term-prompt: #79b8ff;
  --radius: 10px;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121315;
    --surface: #1b1d20;
    --surface-2: #24272b;
    --text: #e6e7e9;
    --muted: #a0a5ad;
    --border: #33373d;
    --accent: #ff8a80;
    --accent-soft: #3a1f1d;
    --ok: #7fd69a;
    --ok-soft: #1b3324;
    --warn: #f2c14e;
    --term-bg: #0b0c0e;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121315;
  --surface: #1b1d20;
  --surface-2: #24272b;
  --text: #e6e7e9;
  --muted: #a0a5ad;
  --border: #33373d;
  --accent: #ff8a80;
  --accent-soft: #3a1f1d;
  --ok: #7fd69a;
  --ok-soft: #1b3324;
  --warn: #f2c14e;
  --term-bg: #0b0c0e;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 64px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 var(--sans);
  overflow-x: hidden;
}
img { max-width: 100%; height: auto; display: block; }
code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: .05em .35em; border-radius: 4px; overflow-wrap: anywhere; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; }
h3 { font-size: 1.05rem; margin: 0 0 .5rem; }
.small { font-size: .875rem; color: var(--muted); }

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

/* ---------- masthead & nav ---------- */
.masthead { background: var(--term-bg); color: #f1f2f4; padding: 48px 0 40px; }
.masthead h1 { font-size: clamp(2rem, 6vw, 3.2rem); margin: .2rem 0 .6rem; letter-spacing: -.02em; }
.kicker { font: 600 .8rem/1 var(--mono); text-transform: uppercase; letter-spacing: .12em; color: #ff8a80; margin: 0; }
.lede { max-width: 46rem; color: #c5c9cf; font-size: 1.1rem; margin: 0; }

.sectionnav { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--border); }
.sectionnav .wrap { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.sectionnav a { padding: 14px 12px; white-space: nowrap; color: var(--muted); text-decoration: none; font-weight: 600; font-size: .92rem; border-bottom: 2px solid transparent; }
.sectionnav a:hover, .sectionnav a.active { color: var(--text); border-bottom-color: var(--accent); }

section { padding: 48px 0 8px; }
section h2 { font-size: 1.6rem; display: flex; align-items: center; gap: .6rem; margin: 0 0 1rem; }
.num { display: inline-grid; place-items: center; width: 1.8rem; height: 1.8rem; border-radius: 50%; background: var(--accent); color: var(--surface); font-size: 1rem; }

/* ---------- briefing ---------- */
.split { display: grid; grid-template-columns: 1.2fr 1fr; gap: 24px; align-items: start; }
.memo { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 24px; }
.memo-head { font-family: var(--mono); font-size: .85rem; border-bottom: 1px dashed var(--border); padding-bottom: 12px; color: var(--muted); }
.memo-head strong { color: var(--accent); }
.exhibit { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.exhibit figcaption { padding: 12px 16px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.callout { margin-top: 24px; background: var(--accent-soft); border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 16px 20px; }
.callout ul, .callout ol { margin: 0; padding-left: 1.2rem; }

/* ---------- custody ---------- */
.formhead { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.formhead label { display: flex; flex-direction: column; font-size: .8rem; color: var(--muted); font-weight: 600; }
.formhead input { font: inherit; font-size: .95rem; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; margin-top: 4px; }
.tablewrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.custody { width: 100%; border-collapse: collapse; min-width: 720px; font-size: .9rem; }
.custody th, .custody td { border-bottom: 1px solid var(--border); padding: 8px 10px; text-align: left; vertical-align: top; }
.custody th { background: var(--surface-2); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.custody td[contenteditable] { height: 2.6em; }
.custody td[contenteditable]:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.custody tr.prefilled td { color: var(--muted); }
.actions { margin-top: 12px; }
.btn { font: 600 .92rem var(--sans); background: var(--accent); color: var(--surface); border: 0; border-radius: 8px; padding: 9px 16px; cursor: pointer; }
.linkbtn { font: inherit; background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; }

/* ---------- lab ---------- */
.labgrid { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 20px; align-items: start; }
.terminal { background: var(--term-bg); color: var(--term-fg); border-radius: var(--radius); overflow: hidden; font: 13.5px/1.5 var(--mono); box-shadow: 0 6px 24px rgb(0 0 0 / .18); }
.term-bar { display: flex; align-items: center; gap: 6px; padding: 8px 12px; background: #23262b; color: var(--term-dim); font-size: .75rem; }
.term-bar span { width: 11px; height: 11px; border-radius: 50%; background: #4a4f57; }
.term-bar b { font-weight: 500; margin-left: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-out { height: 420px; overflow-y: auto; padding: 12px 14px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.term-out .cmd { color: #fff; }
.term-out .cmd .p { color: var(--term-prompt); }
.term-out .dim { color: var(--term-dim); }
.term-out .ok { color: var(--term-ok); }
.term-out .warn { color: var(--term-warn); }
.term-out .err { color: var(--term-err); }
.term-in { display: flex; gap: 8px; padding: 4px 14px 14px; align-items: baseline; }
.term-in .prompt { color: var(--term-prompt); white-space: nowrap; }
.term-in input { flex: 1; min-width: 0; background: transparent; border: 0; outline: none; color: #fff; font: inherit; caret-color: var(--term-ok); }
.term-in input:disabled { opacity: .4; }

.checklist { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.checklist > ol { list-style: none; padding: 0; margin: 0 0 12px; }
.checklist > ol li { padding: 6px 0 6px 30px; position: relative; color: var(--muted); }
.checklist > ol li::before { content: ""; position: absolute; left: 0; top: 8px; width: 18px; height: 18px; border: 2px solid var(--border); border-radius: 50%; }
.checklist > ol li.done { color: var(--text); }
.checklist > ol li.done::before { background: var(--ok); border-color: var(--ok); }
.checklist > ol li.done::after { content: "✓"; position: absolute; left: 4px; top: 6px; font-size: 13px; font-weight: 700; color: var(--surface); }
.checklist > ol li.bad { color: var(--accent); }
.checklist > ol li.bad::before { border-color: var(--accent); }
.lab-result { border-radius: 8px; padding: 10px 12px; font-size: .9rem; margin-bottom: 12px; }
.lab-result.ok { background: var(--ok-soft); color: var(--ok); }
.lab-result.bad { background: var(--accent-soft); color: var(--accent); }
.hints summary { cursor: pointer; font-weight: 600; font-size: .92rem; }
.hints ol { padding-left: 1.1rem; font-size: .88rem; color: var(--muted); }

/* ---------- download ---------- */
.locked { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 20px 24px; }
.locked p { margin: 0 0 6px; }
.dlcards { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; margin: 16px 0; }
.dlcard { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); text-decoration: none; color: var(--text); min-width: 0; }
.dlcard:hover { border-color: var(--accent); }
.dlcard.primary { border-color: var(--accent); border-width: 2px; }
.dl-name { font: 600 .95rem var(--mono); overflow-wrap: anywhere; }
.dl-meta { font-size: .82rem; color: var(--muted); }
.hashes { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; }
.tabs { display: flex; gap: 4px; margin-top: 8px; }
.tabs button { font: 600 .85rem var(--sans); padding: 6px 14px; border: 1px solid var(--border); border-bottom: 0; border-radius: 8px 8px 0 0; background: var(--surface-2); color: var(--muted); cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--term-bg); color: var(--term-fg); border-color: var(--term-bg); }
pre.code { margin: 0; background: var(--term-bg); color: var(--term-fg); font: 13.5px/1.5 var(--mono); padding: 14px 16px; border-radius: 0 var(--radius) var(--radius) var(--radius); overflow-x: auto; }


.foot { padding: 40px 16px; color: var(--muted); font-size: .85rem; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .split, .labgrid { grid-template-columns: 1fr; }
  .dlcards { grid-template-columns: 1fr; }
  .term-out { height: 340px; }
}

/* ---------- print: chain-of-custody form only ---------- */
@media print {
  body { background: #fff; color: #000; }
  .masthead, .sectionnav, .foot, section:not(#custody), .actions { display: none !important; }
  #custody { padding: 0; }
  .tablewrap { overflow: visible; border: 0; }
  table.custody { min-width: 0; }
  .custody th, .custody td { border: 1px solid #000; color: #000; background: #fff; }
  .custody td[contenteditable] { height: 3.2em; }
  .formhead { grid-template-columns: 1fr 1fr; }
  .formhead input { border: 0; border-bottom: 1px solid #000; border-radius: 0; color: #000; }
  .formhead input::placeholder { color: transparent; }
}

.wbcta { display: flex; flex-direction: column; gap: 2px; margin: 16px 0 8px; padding: 14px 18px; border-radius: var(--radius); background: var(--term-bg); color: #f1f2f4; text-decoration: none; }
.wbcta strong { color: #ff8a80; }
.wbcta span { font-size: .88rem; color: #c5c9cf; }
