/* theme.css: Task Export Diff. "Incident case sheet": cool paper, ink-black type, one deep teal
   accent, amber kept for risk flags, red and green for removed and added. Every XML value, path
   and SID is monospace, in two lanes: A (baseline) left, B (suspect) right.
   Signature: the evidence tag (.flag), an amber tag with a pointed end and a punched hole.
   Loaded after styles.css; the builder adds layout only, never colours, radii, shadows or sizes.
   Contrast ratios (WCAG 2.x, approximate) are noted beside each text pair. */

:root {
  color-scheme: light dark;

  /* Palette (light) */
  --bg: #f3f4f1;
  --surface: #ffffff;
  --raised: #eaece8;
  --sunken: #f7f8f6;          /* textareas, A lane cells */
  --text: #1a2026;            /* ~16:1 on --surface, ~14.7:1 on --bg, ~13.6:1 on --raised */
  --muted: #4d5660;           /* ~7.4:1 on --surface, ~6.7:1 on --bg, ~6.2:1 on --raised */
  --border: #d5d9d3;          /* hairlines only */
  --border-strong: #848b93;   /* ~3.5:1 on --surface: field outlines (non-text) */
  --accent: #0f5e63;          /* ~7.5:1 with --on-accent */
  --accent-hover: #0b4b4f;
  --accent-active: #083a3d;
  --accent-text: #0f5e63;     /* ~7.5:1 on --surface, ~6.8:1 on --bg */
  --accent-tint: #e0eff0;     /* --accent-text on it ~6.3:1 */
  --on-accent: #ffffff;
  --success: #1c6b3c;         /* ~6.4:1 on --surface, ~5.8:1 on --success-tint */
  --success-tint: #e6f3ea;
  --warning: #7a4a00;         /* ~7.3:1 on --surface, ~6.6:1 on --warning-tint */
  --warning-edge: #d08a17;    /* edges and tag hole only, never text */
  --warning-tint: #fdf0d4;
  --danger: #b42318;          /* ~6.5:1 on --surface, ~5.8:1 on --danger-tint */
  --danger-edge: #d9483b;     /* edges only */
  --danger-tint: #fdecea;

  /* Type */
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --text-xs: 0.8125rem;   /* 13px caps labels, chips, lane headers */
  --text-sm: 0.9375rem;   /* 15px hints, status, values, XML */
  --text-md: 1.0625rem;   /* 17px body */
  --text-lg: 1.3125rem;   /* 21px h2, group titles */
  --text-xl: 2.25rem;     /* 36px tally numerals */
  --text-2xl: clamp(1.75rem, 4.6vw, 2.5rem); /* h1 */

  /* Space */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;

  /* Radii and shadows */
  --r-s: 6px;
  --r-m: 10px;
  --r-l: 14px;
  --shadow-1: 0 1px 2px rgb(26 32 38 / 0.06), 0 2px 8px rgb(26 32 38 / 0.05);
  --shadow-2: 0 8px 28px rgb(26 32 38 / 0.16);

  /* Motion */
  --fast: 160ms;
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);

  /* Template variables, mapped so its own rules follow the theme */
  --line: var(--border);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101418;
    --surface: #171c21;
    --raised: #20262d;
    --sunken: #13181c;
    --text: #e4e8ec;            /* ~15.5:1 on --bg, ~14.3:1 on --surface, ~12.6:1 on --raised */
    --muted: #a0aab4;           /* ~7.9:1 on --bg, ~7.3:1 on --surface, ~6.4:1 on --raised */
    --border: #2b333b;
    --border-strong: #68727c;   /* ~3.4:1 on --surface (non-text) */
    --accent: #6cc4c4;          /* ~8.3:1 with --on-accent */
    --accent-hover: #8ad3d3;
    --accent-active: #a6dfdf;
    --accent-text: #7dcccc;     /* ~9:1 on --surface */
    --accent-tint: #15302f;     /* --accent-text on it ~7.2:1 */
    --on-accent: #062224;
    --success: #6fd394;         /* ~8.3:1 on --success-tint */
    --success-tint: #16281e;
    --warning: #f0b85a;         /* ~9:1 on --warning-tint */
    --warning-edge: #c98a26;
    --warning-tint: #2e2412;
    --danger: #ff8f85;          /* ~7.9:1 on --danger-tint */
    --danger-edge: #e0645a;
    --danger-tint: #2f1a19;
    --shadow-1: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-2: 0 10px 32px rgb(0 0 0 / 0.55);
  }
}

/* ---------- Page ---------- */

html { background: var(--bg); }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--text-md);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

header, main, footer { max-width: 72rem; padding-left: var(--s5); padding-right: var(--s5); }

header {
  padding-top: var(--s3);
  padding-bottom: var(--s3);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
}
.brand:hover { color: var(--accent-text); }
.brand::before {
  content: "";
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: var(--r-s);
  background: url('icons/favicon.svg') center / contain no-repeat;
}
header nav a {
  padding: 0 var(--s3);
  border-radius: var(--r-s);
  color: var(--muted);
  font-weight: 600;
  text-decoration: none;
  transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease);
}
header nav a:hover { background: var(--raised); color: var(--text); }

main { padding-top: var(--s6); }
main > p, main > ul, main > ol, main > h3, main > .lede { max-width: 42rem; }

a { color: var(--accent-text); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }

h1 {
  font-size: var(--text-2xl);
  line-height: 1.12;
  letter-spacing: -0.02em;
  margin: 0 0 var(--s3);
}
h2 { font-size: var(--text-lg); line-height: 1.3; letter-spacing: -0.01em; margin: var(--s7) 0 var(--s3); }
h3 { font-size: var(--text-md); line-height: 1.4; margin: var(--s5) 0 var(--s1); }
.lede { font-size: 1.125rem; color: var(--muted); margin: 0 0 var(--s6); }
main li { margin-bottom: var(--s2); }
main li::marker { color: var(--muted); }

code, kbd, pre, samp {
  font-family: var(--font-mono);
  font-size: 0.9em;
}
:not(pre) > code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--raised);
  overflow-wrap: anywhere;
}

/* ---------- Tool: the two fields ---------- */

.tool { margin-bottom: var(--s7); }

.inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s5);
}

.field {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: var(--s4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-l);
  box-shadow: var(--shadow-1);
}
.field-head {
  display: flex;
  align-items: center;
  gap: var(--s3);
  margin-bottom: var(--s3);
}
.field-head label { font-weight: 650; line-height: 1.3; }
.meter {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.meter.over { color: var(--danger); font-weight: 700; }

/* Lane letters: A is ink, B is teal. Same shape everywhere they appear. */
.lane {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: var(--r-s);
  background: var(--text);
  color: var(--surface);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 1;
}
.lane.lane-b { background: var(--accent); color: var(--on-accent); }
th .lane { width: 20px; height: 20px; font-size: var(--text-xs); margin-right: var(--s2); vertical-align: middle; }

.field textarea {
  width: 100%;
  min-height: 12rem;
  max-height: 24rem;
  margin: 0;
  padding: var(--s3) var(--s4);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-m);
  background: var(--sunken);
  color: var(--text);
  font: 0.875rem/1.55 var(--font-mono);
  tab-size: 2;
  resize: vertical;
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.field textarea::placeholder { color: var(--muted); opacity: 1; }
.field textarea:hover { border-color: var(--text); }
.field textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent), 0 0 0 6px var(--accent-tint);
}
.hint { margin: var(--s2) 0 0; font-size: var(--text-sm); color: var(--muted); }

.field-error {
  margin: var(--s2) 0 0;
  padding-left: 22px;
  position: relative;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--danger);
}
.field-error:empty { display: none; }
.field-error::before {
  content: "!";
  position: absolute;
  left: 0;
  top: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--danger);
  color: var(--surface);
  font-size: 11px;
  font-weight: 800;
  line-height: 16px;
  text-align: center;
}
.field.invalid { border-color: var(--danger-edge); }
.field.invalid textarea { border-color: var(--danger-edge); }

/* ---------- Buttons ---------- */

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2) var(--s3);
  margin: var(--s5) 0 var(--s3);
}
.actions button, .copy-row button, button.primary, button.secondary, button.quiet {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 44px;
  padding: 0 var(--s5);
  border-radius: var(--r-m);
  font: inherit;
  font-size: 1rem;
  font-weight: 650;
  line-height: 1;
  cursor: pointer;
  transition: background-color var(--fast) var(--ease), border-color var(--fast) var(--ease),
    color var(--fast) var(--ease), transform var(--fast) var(--ease);
}
button svg { width: 18px; height: 18px; flex: none; }

button.primary {
  min-height: 48px;
  min-width: 9rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: var(--shadow-1);
}
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.primary:active { background: var(--accent-active); transform: translateY(1px); }
button.primary[aria-busy="true"] { cursor: progress; }

button.secondary {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
}
button.secondary:hover { border-color: var(--accent); color: var(--accent-text); background: var(--accent-tint); }
button.secondary:active { transform: translateY(1px); }

button.quiet {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 0 var(--s4);
}
button.quiet:hover { background: var(--raised); color: var(--text); }
button.quiet:active { transform: translateY(1px); }

button:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.facts {
  margin-left: auto;
  font-size: var(--text-sm);
  color: var(--muted);
}

/* ---------- Status line ---------- */

#status {
  display: flex;
  align-items: flex-start;
  gap: var(--s2);
  min-height: 1.6em;
  margin: 0 0 var(--s5);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
#status:not(:empty)::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  margin-top: 0.5em;
  border-radius: 50%;
  background: var(--border-strong);
}
#status.busy { color: var(--text); }
#status.busy::before { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
#status.ok { color: var(--success); }
#status.ok::before { background: var(--success); }
#status.error { color: var(--danger); }
#status.error::before { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.3; } }

/* ---------- Output: empty and error ---------- */

#output { min-height: 12rem; }

.empty-state {
  display: flex;
  gap: var(--s5);
  padding: var(--s5) var(--s6);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-l);
  background: transparent;
}
.empty-mark { flex: none; color: var(--accent-text); }
.empty-mark svg { display: block; width: 48px; height: 48px; }
.empty-state strong { display: block; font-size: var(--text-lg); line-height: 1.3; margin-bottom: var(--s2); }
.empty-state p { margin: 0 0 var(--s3); color: var(--muted); max-width: 42rem; }
.empty-state ul { margin: 0; padding-left: var(--s5); font-size: var(--text-sm); }
.empty-state li { margin-bottom: var(--s1); }

.error-card {
  display: flex;
  gap: var(--s4);
  padding: var(--s5);
  border: 1px solid var(--danger-edge);
  border-left-width: 4px;
  border-radius: var(--r-l);
  background: var(--danger-tint);
  color: var(--text);
}
.err-mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--danger);
  color: var(--surface);
  font-weight: 800;
}
.error-card strong { display: block; color: var(--danger); margin-bottom: var(--s1); }
.error-card p { margin: 0; }

/* ---------- Output: the result ---------- */

.result { animation: rise 180ms var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.result-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18rem;
  gap: var(--s5);
  align-items: start;
  margin-bottom: var(--s5);
}

.tally {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--s3);
}
.tile {
  display: flex;
  flex-direction: column;
  gap: var(--s1);
  padding: var(--s4) var(--s5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--accent);
  border-radius: var(--r-m);
  box-shadow: var(--shadow-1);
}
.tile .k {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}
.tile .n {
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  font-weight: 700;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.tile.flagged { border-top-color: var(--warning-edge); background: var(--warning-tint); }
.tile.flagged .n, .tile.flagged .k { color: var(--warning); }
.tile.flagged.zero { border-top-color: var(--border-strong); background: var(--surface); }
.tile.flagged.zero .n, .tile.flagged.zero .k { color: var(--muted); }
.tile.noise { border-top-color: var(--border-strong); }
.tile.noise .n { color: var(--muted); }
.tile.zero { border-top-color: var(--border-strong); }
.tile.zero .n { color: var(--muted); }

.summary-line { margin: var(--s4) 0 var(--s3); font-weight: 600; font-variant-numeric: tabular-nums; }
.copy-row { display: flex; flex-wrap: wrap; gap: var(--s2); margin: 0; }
.copy-row button { min-width: 12.5rem; }

.scope-note {
  display: flex;
  gap: var(--s3);
  padding: var(--s4);
  border-radius: var(--r-m);
  background: var(--raised);
  font-size: var(--text-sm);
  color: var(--muted);
}
.scope-note svg { flex: none; width: 20px; height: 20px; margin-top: 2px; color: var(--accent-text); }
.scope-note p { margin: 0; }
.scope-note strong { color: var(--text); }

/* Groups */

.group {
  margin: 0 0 var(--s4);
  padding: var(--s4) var(--s5) var(--s5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-l);
  box-shadow: var(--shadow-1);
}
.group-head {
  display: flex;
  align-items: baseline;
  gap: var(--s3);
  padding-bottom: var(--s3);
  border-bottom: 1px solid var(--border);
}
.group-head h2 { margin: 0; font-size: var(--text-lg); }
.count {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.group.none { padding-bottom: var(--s3); box-shadow: none; background: transparent; }
.group.none .group-head { border-bottom: 0; padding-bottom: 0; }
.group.none h2 { color: var(--muted); font-size: var(--text-md); }

/* Items: a section of the group, not a nested card. A left edge carries its kind. */
.item {
  padding: var(--s4) 0 var(--s1) var(--s4);
  margin-top: var(--s3);
  border-left: 4px solid var(--accent);
}
.item + .item { border-top: 0; }
.item.added { border-left-color: var(--success); }
.item.removed { border-left-color: var(--danger-edge); }
.item.flagged { border-left-color: var(--warning-edge); }

.item-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); margin-bottom: var(--s3); }
.item-name { font-family: var(--font-mono); font-size: var(--text-sm); font-weight: 700; overflow-wrap: anywhere; }

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 var(--s2);
  border-radius: var(--r-s);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  line-height: 1;
}
.chip.added { background: var(--success-tint); color: var(--success); }
.chip.removed { background: var(--danger-tint); color: var(--danger); }
.chip.changed { background: var(--accent-tint); color: var(--accent-text); }

/* Signature: the evidence tag */
.flags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  margin: 0 0 var(--s3);
  padding: 0;
  list-style: none;
}
.flags li { margin: 0; }
.flag {
  position: relative;
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 var(--s2);
  min-height: 30px;
  padding: 5px var(--s3) 5px 26px;
  background: var(--warning-tint);
  color: var(--warning);
  font-size: var(--text-sm);
  line-height: 1.35;
  border-radius: 0 var(--r-s) var(--r-s) 0;
  clip-path: polygon(12px 0, 100% 0, 100% 100%, 12px 100%, 0 50%);
  box-shadow: inset -1px 0 0 var(--warning-edge), inset 0 1px 0 var(--warning-edge), inset 0 -1px 0 var(--warning-edge);
}
.flag::before {
  content: "";
  position: absolute;
  left: 11px;
  top: 50%;
  width: 7px;
  height: 7px;
  margin-top: -3.5px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 0 0 1.5px var(--warning-edge);
}
.flag b { font-weight: 750; }
.flag span { color: var(--text); }
.flag code { background: transparent; padding: 0; color: var(--text); font-weight: 600; }

/* Field tables: A lane and B lane */
table.fields {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  table-layout: fixed;
}
table.fields th, table.fields td {
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}
table.fields thead th {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  border-bottom: 1px solid var(--border-strong);
}
table.fields thead th:first-child { width: 22%; }
table.fields .to { width: 2rem; padding-left: 0; padding-right: 0; text-align: center; color: var(--muted); }
table.fields tbody th {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text);
}
table.fields td.old, table.fields td.new { font-family: var(--font-mono); }
table.fields td.old { color: var(--muted); background: var(--sunken); }
table.fields td.new { color: var(--text); font-weight: 600; }
table.fields tbody tr:last-child > * { border-bottom: 0; }
.absent {
  font-family: var(--font-ui);
  font-style: italic;
  font-weight: 400;
  color: var(--muted);
}
.case-only {
  display: inline-block;
  margin-left: var(--s1);
  padding: 0 6px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-family: var(--font-ui);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  vertical-align: 1px;
}

/* Noise fold. Scoped to details and p: the Noise tally tile also carries the class. */
details.noise,
p.noise.none {
  margin-top: var(--s5);
  border: 1px solid var(--border);
  border-radius: var(--r-l);
  background: var(--raised);
}
.noise > summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s1) var(--s3);
  min-height: 52px;
  padding: var(--s3) var(--s5) var(--s3) 44px;
  position: relative;
  border-radius: var(--r-l);
  cursor: pointer;
  list-style: none;
  transition: background-color var(--fast) var(--ease);
}
.noise > summary::-webkit-details-marker { display: none; }
.noise > summary::before {
  content: "";
  position: absolute;
  left: 20px;
  top: 50%;
  width: 8px;
  height: 8px;
  margin-top: -5px;
  border-right: 2px solid var(--text);
  border-bottom: 2px solid var(--text);
  transform: rotate(-45deg);
  transition: transform var(--fast) var(--ease);
}
.noise[open] > summary::before { transform: rotate(45deg); }
.noise > summary:hover { background: var(--border); }
.noise-title { font-weight: 700; }
.noise-hint { font-size: var(--text-sm); color: var(--muted); }
.noise summary .noise-toggle { margin-left: auto; font-size: var(--text-sm); font-weight: 600; color: var(--accent-text); }
.noise summary:hover .noise-toggle { text-decoration: underline; }
.noise > table.fields { margin: 0 var(--s5) var(--s4); width: calc(100% - 2 * var(--s5)); }
.noise > table.fields td.old { background: transparent; }
p.noise.none { padding: var(--s3) var(--s5); color: var(--muted); font-size: var(--text-sm); }

/* ---------- Reading section ---------- */

.example {
  max-width: 52rem;
  padding: var(--s5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-l);
  box-shadow: var(--shadow-1);
}
.example > p:first-child { margin-top: 0; }
.example > p:last-child { margin-bottom: 0; color: var(--muted); }

table.plain {
  width: 100%;
  max-width: 52rem;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
table.plain th, table.plain td {
  padding: var(--s3);
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
table.plain th { width: 38%; font-weight: 600; }

/* ---------- Template parts: ad slot, house card, consent, footer ---------- */

.ad-slot {
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--r-l);
}
.ad-label {
  opacity: 1;
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}
.house-card {
  padding: var(--s4);
  border-radius: var(--r-m);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: border-color var(--fast) var(--ease);
}
.house-card:hover { border-color: var(--accent); }
.house-card strong { color: var(--accent-text); }
.house-card span { color: var(--muted); }

.consent {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-l);
  box-shadow: var(--shadow-2);
}
.consent button {
  border: 1px solid var(--border-strong);
  border-radius: var(--r-m);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  transition: background-color var(--fast) var(--ease), border-color var(--fast) var(--ease);
}
.consent button:hover { border-color: var(--accent); background: var(--accent-tint); }

footer {
  opacity: 1;
  margin-top: var(--s8);
  padding-top: var(--s5);
  padding-bottom: var(--s6);
  border-top: 1px solid var(--border);
  font-size: var(--text-sm);
  color: var(--muted);
}

/* ---------- Focus ---------- */

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px var(--accent-tint);
}
.noise > summary:focus-visible { outline-offset: -2px; }

/* ---------- Phone ---------- */

@media (max-width: 46rem) {
  header, main, footer { padding-left: var(--s4); padding-right: var(--s4); }
  main { padding-top: var(--s5); }
  .inputs { grid-template-columns: 1fr; gap: var(--s4); }
  .field { padding: var(--s3); }
  .field-head { flex-wrap: wrap; row-gap: var(--s1); }
  .field-head .meter { flex-basis: 100%; text-align: start; padding-left: calc(28px + var(--s3)); }
  .field textarea { min-height: 10rem; }
  .actions button.primary { flex: 1 1 100%; }
  .actions button.secondary, .actions button.quiet { flex: 1 1 0; }
  .facts { margin-left: 0; flex-basis: 100%; }
  .empty-state { flex-direction: column; gap: var(--s3); padding: var(--s4); }
  .result-head { grid-template-columns: 1fr; }
  .tally { gap: var(--s2); }
  .tile { padding: var(--s3); }
  .tile .n { font-size: 1.75rem; }
  .copy-row button { flex: 1 1 100%; min-width: 0; }
  .group { padding: var(--s3) var(--s4) var(--s4); }
  .item { padding-left: var(--s3); }

  table.fields, table.fields tbody, table.fields tr, table.fields th, table.fields td { display: block; width: auto; }
  table.fields thead, table.fields .to { display: none; }
  table.fields tr { padding: var(--s2) 0; border-bottom: 1px solid var(--border); }
  table.fields tbody tr:last-child { border-bottom: 0; }
  table.fields th, table.fields td { border: 0; padding: 2px 0; }
  table.fields td.old, table.fields td.new { position: relative; padding: var(--s1) var(--s2) var(--s1) 30px; border-radius: var(--r-s); }
  table.fields td.new { margin-top: 2px; }
  table.fields td[data-lane]::before {
    content: attr(data-lane);
    position: absolute;
    left: 4px;
    top: 5px;
    width: 18px;
    height: 18px;
    border-radius: 4px;
    background: var(--text);
    color: var(--surface);
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
  }
  table.fields td.new[data-lane]::before { background: var(--accent); color: var(--on-accent); }
  .noise > table.fields { margin: 0 var(--s4) var(--s3); width: auto; }
  .noise > summary { padding-right: var(--s4); }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  button:active { transform: none !important; }
}
