:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --ink: #1f2328;
  --muted: #5b616b;
  --line: #d9d4ca;
  --accent: #1f5f8b;
  --accent-ink: #ffffff;
  --accent-soft: #e3eef6;
  --ok: #1d6b3a;
  --ok-soft: #e2f1e7;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --bad: #a3262a;
  --bad-soft: #f9e3e3;
  --focus: #f0a500;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --surface: #1e2125;
    --surface-2: #262a2f;
    --ink: #e8e6e1;
    --muted: #a2a7ae;
    --line: #3a3f46;
    --accent: #7db8e0;
    --accent-ink: #0d1b26;
    --accent-soft: #1d3142;
    --ok: #7ccf98;
    --ok-soft: #1b3324;
    --warn: #e8bd62;
    --warn-soft: #3a2f17;
    --bad: #f08a8d;
    --bad-soft: #3d1f21;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
main { max-width: 860px; margin: 0 auto; padding: 16px 16px 64px; outline: none; }
main.wide { max-width: 1180px; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.75em; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.skip { position: absolute; left: -9999px; }
.skip:focus { left: 16px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin: 0 0 16px;
  box-shadow: var(--shadow);
}
.eyebrow { text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.75rem; color: var(--muted); margin-bottom: 0.4em; }
.muted, .hint { color: var(--muted); }
.hint { font-size: 0.9rem; }
.packet-meta { color: var(--muted); }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }
.plain { list-style: none; padding: 0; margin: 0; }
.plain li { padding: 6px 0; }
.notice { background: var(--warn-soft); border-color: var(--warn); border-radius: var(--radius); padding: 12px 16px; }
.form-error { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; }
.row { display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap; }
.row > input { flex: 1 1 240px; min-width: 0; }

/* Controls */
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-size: 0.95rem; line-height: 1.2;
  padding: 10px 16px; min-height: 44px;
  border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
  cursor: pointer; text-decoration: none;
}
button:hover, .button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.link {
  background: none; border: none; padding: 4px 0; min-height: 0;
  color: var(--accent); text-decoration: underline; font-size: 0.92rem;
}
button.danger { color: var(--bad); }
input[type=text], input[type=email], input[type=password], input[type=number], input:not([type]), select, textarea {
  font: inherit; font-size: 1rem; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; width: 100%;
}
textarea { resize: vertical; min-height: 64px; }
label { display: block; font-weight: 600; margin: 12px 0 6px; }
label.check, label.opt { font-weight: 400; }
label.check { display: flex; gap: 10px; align-items: flex-start; margin: 16px 0; }
label.check input { width: 20px; height: 20px; margin-top: 3px; flex: none; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; }

/* Instructions */
.instructions h3 { margin-top: 1.2em; }
.defs { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 1em; }
.defs dt { font-weight: 600; }
.defs dd { margin: 0; }
@media (max-width: 600px) { .defs { grid-template-columns: 1fr; } .defs dd { margin-bottom: 8px; } }
dialog {
  max-width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); padding: 0 20px 20px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: var(--surface); padding: 16px 0 8px; }
.dialog-head h2 { margin: 0; }

/* Questionnaire header */
.q-head { display: grid; grid-template-columns: 1fr auto; gap: 12px 20px; align-items: start; }
.q-head h1 { font-size: 1.35rem; margin-bottom: 0.2em; }
.q-head .muted { margin: 0; font-size: 0.92rem; }
.q-progress { grid-column: 1 / -1; }
.q-progress p { margin: 4px 0 0; font-size: 0.92rem; }
.q-tools { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; grid-row: 1; grid-column: 2; }
progress { width: 100%; height: 10px; appearance: none; border: none; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--surface-2); }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }
.save-status { color: var(--muted); }
.save-status[data-kind=saved]::before { content: "✓ "; color: var(--ok); }
.save-status[data-kind=offline], .save-status[data-kind=error] { color: var(--bad); font-weight: 600; }
@media (max-width: 640px) {
  .q-head { grid-template-columns: 1fr; }
  .q-tools { grid-column: 1; grid-row: auto; justify-content: flex-start; }
}
.badge { display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); margin-left: 6px; vertical-align: 1px; }
.badge.draft { background: var(--warn-soft); color: var(--warn); }
.badge.done { background: var(--ok-soft); color: var(--ok); }

.toc ol { counter-reset: none; }
.toc li { padding: 0; border-top: 1px solid var(--line); }
.toc li:first-child { border-top: 0; }
.toc button.link { display: flex; justify-content: space-between; gap: 12px; width: 100%; text-align: left; text-decoration: none; color: var(--ink); padding: 10px 4px; min-height: 44px; font-size: 0.95rem; }
.toc button.link.current { font-weight: 700; color: var(--accent); }
.toc .count { color: var(--muted); font-variant-numeric: tabular-nums; }
.toc .count.complete { color: var(--ok); }
.fatal { background: var(--bad-soft); border-color: var(--bad); }

/* Context */
.page-head { background: var(--accent-soft); border-color: transparent; }
.page-head h2 { font-size: 1.3rem; }
.context, .claim { display: grid; gap: 8px; }
.field { display: grid; grid-template-columns: 9.5rem 1fr; gap: 2px 12px; }
.field-label { color: var(--muted); font-size: 0.85rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; padding-top: 2px; }
.field-value { font-weight: 500; }
.field .coded { grid-column: 1 / -1; }
@media (max-width: 600px) { .field { grid-template-columns: 1fr; } }
.coded { list-style: none; padding: 0; margin: 4px 0 0; display: grid; gap: 4px; }
.code { display: inline-block; min-width: 2.4em; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--muted); }
.claim { background: var(--surface-2); border-left: 4px solid var(--accent); border-radius: 6px; padding: 12px 14px; margin-bottom: 14px; }
.claim-text { font-size: 1.05rem; font-weight: 500; margin: 0; }
h3.cat { margin: 24px 4px 10px; color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; }

/* Questions */
.q { scroll-margin-top: 16px; }
.q.warn { border-color: var(--warn); }
.q.error { border-color: var(--bad); }
.q-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.8rem; color: var(--muted); margin-bottom: 10px; }
.item-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.75rem; }
.item-state { margin-left: auto; }
.item-state[data-kind=saved] { color: var(--ok); }
.item-state[data-kind=error] { color: var(--bad); font-weight: 600; }
.q-text { font-weight: 600; font-size: 1.05rem; margin-bottom: 12px; }
.opts { display: grid; gap: 8px; }
.opt {
  display: flex; gap: 12px; align-items: flex-start;
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 0;
  cursor: pointer; background: var(--surface);
}
.opt input { width: 20px; height: 20px; margin: 2px 0 0; flex: none; accent-color: var(--accent); }
.opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.opt:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 1px; }
.opt:has(input:disabled) { cursor: default; }
.opts.multi .opt.exclusive:first-of-type { margin-bottom: 6px; }
.opts.multi .opt.exclusive:last-of-type { margin-top: 6px; }
.writein { margin-top: 12px; }
.writein label { font-weight: 500; font-size: 0.95rem; }
.writein.emph label { font-weight: 700; }
.writein.emph textarea { border-color: var(--accent); }
.warn-text { color: var(--warn); }
.readonly-text { white-space: pre-wrap; background: var(--surface-2); padding: 8px 12px; border-radius: 6px; }
.writein .label { font-size: 0.85rem; color: var(--muted); margin: 0 0 4px; }
.clear { margin-top: 8px; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 8px; }
@media (max-width: 480px) { .pager .muted { display: none; } }

.assignments .assignment { display: flex; justify-content: space-between; gap: 16px; align-items: center; border-top: 1px solid var(--line); padding: 14px 0; }
.assignments .assignment:first-child { border-top: 0; }
.assignment h3 { margin: 0 0 2px; }
.assignment p { margin: 0 0 2px; }
@media (max-width: 520px) { .assignments .assignment { flex-direction: column; align-items: stretch; } }
.done-card { border-color: var(--ok); }
.linkbox input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; }

/* Researcher pages */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tabs button { border: none; border-bottom: 3px solid transparent; border-radius: 0; background: none; }
.tabs button[aria-selected=true] { border-bottom-color: var(--accent); font-weight: 700; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.report { margin-top: 12px; }
.report ul { margin: 4px 0 8px; padding-left: 20px; }
.ok-text { color: var(--ok); }
.bad-text { color: var(--bad); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.secret { background: var(--warn-soft); border: 1px solid var(--warn); border-radius: 8px; padding: 12px; margin: 12px 0; }
.checks label { font-weight: 400; display: flex; gap: 8px; margin: 6px 0; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0 12px; }
.toolbar select { width: auto; max-width: 100%; }

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
.narrow { max-width: 420px; margin: 40px auto; }
.admin-head h1 { margin: 0; flex: 1; font-size: 1.3rem; }

/* One subsection per page; evidence boxes above each question */
.subhead { margin: 8px 4px 14px; }
.subhead h2 { font-size: 1.35rem; margin: 0 0 2px; }
.subhead p { margin: 0; }
.evidence { display: grid; gap: 8px; background: var(--accent-soft); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.evidence.claim { border-left: 4px solid var(--accent); }
.evidence.claim .field-value, .evidence .claim-text { font-weight: 600; }
.q-text strong { text-decoration: underline; text-underline-offset: 3px; }
#all-answers .subhead { margin-top: 28px; }
