/* Layout: white pages, deep purple for structure and action. The four steps
   are sheets of working paper; tables print with lavender bars; the balance
   bridge is an adding-machine tape with red-ink negatives and a double rule.
   White and purple by default; [data-theme="dark"] (set by ../../theme.js from
   the moon button) swaps the tokens below for a dark palette. */
@font-face { font-family: "Bricolage Grotesque"; src: url("../../fonts/bricolage-grotesque.woff2") format("woff2"); font-weight: 200 800; font-display: swap; }
@font-face { font-family: "Public Sans"; src: url("../../fonts/public-sans.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("../../fonts/jetbrains-mono.woff2") format("woff2"); font-weight: 100 800; font-display: swap; }

:root {
  --purple: #5b21b6;        /* purple text and lines: 8.6:1 on white */
  --purple-deep: #3b0f7a;
  --purple-fill: #5b21b6;   /* purple behind white text */
  --purple-fill-deep: #3b0f7a;
  --purple-ink: #ffffff;    /* text on the fill */
  --purple-soft: #f1ebfd;
  --purple-line: #d9cdf6;
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f7f4fd;
  --bar: #f6f2fe;            /* table banding */
  --ink: #120d1f;
  --muted: #463f57;          /* 9.7:1 on white */
  --line: #ddd7ea;
  --ok: #047857;  --ok-soft: #e3f6ee; --on-ok: #ffffff;
  --warn: #8a4b00; --warn-soft: #fff3df;
  --bad: #b91c1c; --bad-soft: #fde8e8;
  --info: #1d4ed8; --info-soft: #e8eefd;
  --tape: #fffef9;
  --focus: #7c3aed;
  --topbar-bg: rgb(255 255 255 / 0.94);
  --toast-bg: #120d1f; --toast-ink: #ffffff;
  --shadow: 0 1px 2px rgb(59 15 122 / 0.06), 0 12px 32px -14px rgb(59 15 122 / 0.22);

  --font-ui: "Public Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;

  --step-0: 0.9375rem;      /* 15px: captions, table text */
  --step-1: 1.0625rem;      /* 17px: body */
  --step-2: 1.45rem;
  --step-3: 1.85rem;
  --step-4: clamp(2.4rem, 1.5rem + 3.4vw, 3.8rem);
  --radius: 10px;
  color-scheme: light;
}
/* Dark: violet-black paper, light ink, a lighter purple for text; text keeps
   at least 4.5:1 against its background. */
:root[data-theme="dark"] {
  --purple: #a78bfa;
  --purple-deep: #c4b5fd;
  --purple-fill: #6d28d9;
  --purple-fill-deep: #4c1d95;
  --purple-soft: #2a1f4a;
  --purple-line: #4c3d75;
  --bg: #0e0b16;
  --surface: #161222;
  --surface-2: #1c172b;
  --bar: #1a1528;
  --ink: #ede9f6;
  --muted: #b3aac6;
  --line: #2f2843;
  --ok: #34d399;  --ok-soft: #0d2e24; --on-ok: #052e1f;
  --warn: #fbbf24; --warn-soft: #33260a;
  --bad: #f87171; --bad-soft: #3a1418;
  --info: #93b4ff; --info-soft: #16213d;
  --tape: #1b1726;
  --focus: #c4b5fd;
  --topbar-bg: rgb(14 11 22 / 0.92);
  --toast-bg: #ede9f6; --toast-ink: #0e0b16;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.5), 0 12px 32px -14px rgb(0 0 0 / 0.75);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 var(--step-1)/1.6 var(--font-ui);
  font-variant-numeric: tabular-nums;
}
[hidden] { display: none !important; }
a { color: var(--purple); }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.1; text-wrap: balance; margin: 0; letter-spacing: -0.02em; color: var(--ink); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---- header ------------------------------------------------------------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  background: var(--topbar-bg); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-in, .wrap, .foot-in { max-width: 74rem; margin: 0 auto; padding-inline: 20px; }
.topbar-in { display: flex; align-items: center; gap: 0.6rem 1.2rem; flex-wrap: wrap; padding-block: 0.85rem; }
.brand { font: 800 1.55rem/1 var(--font-display); letter-spacing: -0.035em; color: var(--ink); text-decoration: none; }
.brand b { color: var(--purple); }
.crumb { color: var(--muted); font-size: var(--step-0); display: inline-flex; gap: 0.5rem; align-items: center; font-weight: 500; }
.crumb .pill { background: var(--purple-soft); color: var(--purple); }
.privacy {
  margin-left: auto; display: inline-flex; align-items: center; gap: 0.45rem;
  font-size: var(--step-0); font-weight: 600; color: var(--ok); background: var(--ok-soft);
  border-radius: 999px; padding: 0.35rem 0.85rem;
}
.privacy svg { width: 15px; height: 15px; }

.wrap { padding-block: 0 4rem; display: grid; gap: 1.75rem; }
.foot { border-top: 1px solid var(--line); color: var(--muted); font-size: var(--step-0); background: var(--surface-2); }
.foot-in { padding-block: 1.5rem 2.25rem; display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; }

/* ---- intro -------------------------------------------------------------- */
.intro { display: grid; gap: 0.9rem; padding-block: 3rem 0.5rem; }
.eyebrow { font: 700 var(--step-0)/1 var(--font-ui); letter-spacing: 0.14em; text-transform: uppercase; color: var(--purple); }
.intro h1 { font-size: var(--step-4); font-weight: 800; letter-spacing: -0.045em; max-width: 16ch; }
.intro p { margin: 0; color: var(--muted); max-width: 60ch; font-size: 1.15rem; }
.engine { display: flex; align-items: center; gap: 0.6rem; font: 500 var(--step-0)/1.4 var(--font-ui); color: var(--muted); }
.engine .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.engine[data-state="loading"] .dot { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
.engine[data-state="ready"] .dot { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }
.engine[data-state="error"] { color: var(--bad); }
.engine[data-state="error"] .dot { background: var(--bad); }
@keyframes pulse { 50% { opacity: 0.35; } }
.toolbar { display: flex; flex-wrap: wrap; gap: 0.6rem; }

.banner {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem;
  background: var(--purple-soft); color: var(--ink); border-left: 4px solid var(--purple);
  border-radius: 0 var(--radius) var(--radius) 0; padding: 0.85rem 1.1rem; font-size: var(--step-0); max-width: 54rem;
}

/* ---- steps -------------------------------------------------------------- */
.step {
  position: relative; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.5rem 1.5rem 1.6rem; display: grid; gap: 1.2rem; min-width: 0;
  border-top: 4px solid var(--purple);
}
.step-head { display: grid; grid-template-columns: auto 1fr auto; gap: 0.3rem 1rem; align-items: start; }
.step-no {
  width: 2.6rem; height: 2.6rem; display: grid; place-items: center;
  font: 800 1.3rem/1 var(--font-display); background: var(--purple-fill); color: var(--purple-ink);
  border-radius: 8px;
}
.step-head h2 { font-size: var(--step-2); font-weight: 750; }
.step-head p { margin: 0.25rem 0 0; color: var(--muted); font-size: var(--step-0); max-width: 70ch; }
.pill {
  font: 700 0.8rem/1 var(--font-ui); letter-spacing: 0.02em; border-radius: 999px; padding: 0.42rem 0.8rem;
  white-space: nowrap; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.pill[data-tone="ok"] { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill[data-tone="ok"]::before { content: "\2713  "; font-weight: 800; }
.pill[data-tone="warn"] { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill[data-tone="bad"] { background: var(--bad-soft); color: var(--bad); border-color: transparent; }

.drop {
  border: 2px dashed var(--purple-line); border-radius: var(--radius); padding: 1.15rem 1.25rem;
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 1rem; color: var(--muted);
  font-size: var(--step-0); background: var(--surface-2); transition: border-color 0.15s, background 0.15s;
}
.drop.over { border-color: var(--purple); background: var(--purple-soft); }
.drop input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.example { margin: -0.4rem 0 0; font-size: var(--step-0); color: var(--muted); }
button.link {
  background: none; border: 0; padding: 0; box-shadow: none; color: var(--purple); font: inherit;
  font-weight: 650; text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}
button.link:hover { color: var(--purple-deep); }

.panel { display: grid; gap: 1.1rem; min-width: 0; }
.fileline { display: flex; flex-wrap: wrap; gap: 0.35rem 1.1rem; align-items: baseline; font-size: var(--step-0); color: var(--muted); }
.fileline strong { color: var(--ink); font: 600 var(--step-1)/1.3 var(--font-mono); word-break: break-all; }

/* ---- controls ----------------------------------------------------------- */
button, .btn {
  font: 650 var(--step-0)/1 var(--font-ui); border-radius: 8px; border: 1.5px solid var(--line);
  background: var(--surface); color: var(--ink); padding: 0.7rem 1rem; cursor: pointer;
  display: inline-flex; align-items: center; gap: 0.4rem; text-decoration: none;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
button:hover, .btn:hover { border-color: var(--purple); color: var(--purple); }
button:active, .btn:active { transform: translateY(1px); }
button.primary, .btn.primary { background: var(--purple-fill); color: var(--purple-ink); border-color: var(--purple-fill); }
button.primary:hover, .btn.primary:hover { background: var(--purple-fill-deep); border-color: var(--purple-fill-deep); color: var(--purple-ink); }
button[data-act="excel"] {
  background: var(--purple-fill); color: var(--purple-ink); border-color: var(--purple-fill);
  font-size: var(--step-1); padding: 0.95rem 1.4rem; box-shadow: 0 6px 18px -6px rgb(91 33 182 / 0.55);
}
button[data-act="excel"]:hover { background: var(--purple-fill-deep); color: var(--purple-ink); }
button[data-act="reject"], button.danger { color: var(--bad); }
button[data-act="reject"]:hover, button.danger:hover { border-color: var(--bad); color: var(--bad); }
button.quiet { border-color: transparent; background: transparent; color: var(--purple); padding-inline: 0.4rem; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
select, input[type="text"], input[type="number"] {
  font: 500 var(--step-0)/1.3 var(--font-ui); color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--line); border-radius: 8px; padding: 0.55rem 0.65rem; min-width: 0; max-width: 100%;
}
input[type="number"] { width: 7rem; font-family: var(--font-mono); }
select:hover, input:hover { border-color: var(--purple-line); }
select:focus, input:focus { border-color: var(--purple); outline: none; box-shadow: 0 0 0 3px var(--purple-soft); }
label { cursor: pointer; }

/* ---- mapping grid ------------------------------------------------------- */
.map { display: grid; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.map-row {
  display: grid; grid-template-columns: minmax(11rem, 1.1fr) minmax(12rem, 1.3fr) minmax(10rem, 1fr);
  gap: 0.4rem 1rem; align-items: center; padding: 0.6rem 0.9rem; border-top: 1px solid var(--line);
}
.map-row:first-child { border-top: 0; }
.map-row:nth-child(even):not(.head) { background: var(--bar); }
.map-row.head { background: var(--purple-fill); color: var(--purple-ink); font: 700 0.78rem/1 var(--font-ui); letter-spacing: 0.08em; text-transform: uppercase; padding-block: 0.75rem; }
.map-row select { width: 100%; }
.field { display: flex; flex-wrap: wrap; gap: 0.2rem 0.5rem; align-items: baseline; }
.lvl { font-style: normal; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.lvl.required { color: var(--purple); font-weight: 800; }
.status { font-size: var(--step-0); font-weight: 600; }
.status small { display: block; color: var(--muted); font-weight: 400; }
.tone-ok { color: var(--ok); } .tone-warn { color: var(--warn); } .tone-bad { color: var(--bad); }
.tone-muted { color: var(--muted); font-weight: 500; }
.status.tone-ok::before { content: "\2713  "; font-weight: 800; }

.opts { display: flex; flex-wrap: wrap; gap: 0.8rem 1.6rem; align-items: center; font-size: var(--step-0); }
.seg { display: inline-flex; border: 1.5px solid var(--line); border-radius: 8px; overflow: hidden; padding: 0; margin: 0; }
.seg legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.seg label { padding: 0.45rem 0.8rem; display: inline-flex; align-items: center; gap: 0.4rem; font-family: var(--font-mono); }
.seg label + label { border-left: 1.5px solid var(--line); }
.seg label:has(input:checked) { background: var(--purple-fill); color: var(--purple-ink); }
.seg input, .check input { accent-color: var(--purple); }
.opts .lead { color: var(--muted); font-weight: 600; }
.check { display: inline-flex; gap: 0.45rem; align-items: center; }

/* ---- notes -------------------------------------------------------------- */
.issues { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.45rem; font-size: var(--step-0); }
.issues li { display: grid; grid-template-columns: auto 1fr; gap: 0.75rem; align-items: start; padding: 0.6rem 0.8rem; border-left: 4px solid var(--line); background: var(--surface-2); border-radius: 0 8px 8px 0; }
.issues .tag { font: 800 0.7rem/1.7 var(--font-ui); letter-spacing: 0.08em; text-transform: uppercase; }
.issues .blocking { background: var(--bad-soft); border-left-color: var(--bad); } .issues .blocking .tag { color: var(--bad); }
.issues .warning { background: var(--warn-soft); border-left-color: var(--warn); } .issues .warning .tag { color: var(--warn); }
.issues .info { background: var(--info-soft); border-left-color: var(--info); } .issues .info .tag { color: var(--info); }
.issues .choices { display: block; color: var(--muted); margin-top: 0.15rem; }
code, .mono { font-family: var(--font-mono); font-size: 0.92em; }
.alert { margin: 0; padding: 0.85rem 1rem; font-size: var(--step-0); font-weight: 500; border-left: 4px solid currentColor; border-radius: 0 8px 8px 0; }
.alert.bad { background: var(--bad-soft); color: var(--bad); }
.alert.ok { background: var(--ok-soft); color: var(--ok); font-weight: 700; }
.alert.ok::before { content: "\2713  "; font-weight: 800; }
.alert.warn { background: var(--warn-soft); color: var(--warn); }

.stats { display: flex; flex-wrap: wrap; gap: 0.4rem 1.75rem; font-size: var(--step-0); color: var(--muted); align-items: baseline; }
.stats b { color: var(--ink); font: 700 var(--step-2)/1 var(--font-mono); }
.actions { display: flex; flex-wrap: wrap; gap: 0.65rem; align-items: center; }
.actions input[type="text"] { width: 16rem; }

details { border-top: 1px solid var(--line); padding-top: 0.75rem; min-width: 0; }
details > summary { cursor: pointer; font-weight: 700; font-size: var(--step-1); color: var(--ink); list-style: none; display: flex; align-items: baseline; gap: 0.55rem; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "+"; font: 800 1.05rem/1 var(--font-mono); color: var(--purple); width: 1rem; }
details[open] > summary::before { content: "\2212"; }
details > summary:hover { color: var(--purple); }
details[open] > summary { margin-bottom: 0.8rem; }
details .sub { color: var(--muted); font-size: var(--step-0); margin: 0 0 0.6rem; }

/* ---- tables ------------------------------------------------------------- */
.scroll { overflow-x: auto; min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: var(--step-0); }
th, td { padding: 0.6rem 0.8rem; text-align: left; vertical-align: top; }
th {
  background: var(--purple-fill); color: var(--purple-ink);
  font: 700 0.76rem/1.2 var(--font-ui); letter-spacing: 0.07em; text-transform: uppercase; white-space: nowrap;
}
tbody tr:nth-child(even) td { background: var(--bar); }
tbody tr + tr td { border-top: 1px solid var(--line); }
td.num, th.num { text-align: right; white-space: nowrap; }
td.num { font-family: var(--font-mono); font-weight: 500; }
td.neg { color: var(--bad); }
td.doc { font-family: var(--font-mono); white-space: nowrap; font-weight: 700; }
td.wide { min-width: 17rem; }

/* ---- results ------------------------------------------------------------ */
.results-controls { display: flex; flex-wrap: wrap; gap: 0.8rem 1.6rem; align-items: end; font-size: var(--step-0); }
.results-controls label { display: grid; gap: 0.35rem; color: var(--muted); font-weight: 600; }
.summary {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  background: linear-gradient(135deg, var(--purple-fill-deep), var(--purple-fill)); color: var(--purple-ink);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.summary div { padding: 1.15rem 1.25rem; display: grid; gap: 0.35rem; }
.summary div + div { border-left: 1px solid rgb(255 255 255 / 0.18); }
.summary span { font: 700 0.75rem/1 var(--font-ui); letter-spacing: 0.1em; text-transform: uppercase; color: #e6dcfb; }
.summary b { font: 700 var(--step-3)/1.1 var(--font-mono); letter-spacing: -0.02em; }
.summary .tone-bad b { color: #ffd2cc; }
.summary .tone-ok b { color: #b6f2d8; }
@media (max-width: 44rem) {
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary div:nth-child(3) { border-left: 0; }
}

.review { display: grid; gap: 0.6rem; }
.review-item {
  display: grid; grid-template-columns: 1fr auto; gap: 0.6rem 1rem; align-items: center;
  padding: 0.85rem 1rem; background: var(--surface); border: 1px solid var(--line);
  border-left: 5px solid var(--purple); border-radius: 0 var(--radius) var(--radius) 0;
}
.review-item p { margin: 0; font-size: var(--step-0); }
.pairing { display: grid; gap: 0.25rem; min-width: 0; }
.pairing .side { display: inline-block; min-width: 6.5rem; color: var(--muted); font: 700 0.72rem/1 var(--font-ui); letter-spacing: 0.08em; text-transform: uppercase; }
.pairing .mono { font-weight: 700; }
.pairing .when { color: var(--muted); margin-inline: 0.45rem; font-family: var(--font-mono); }
.pairing .amt { font: 700 var(--step-0)/1 var(--font-mono); }
.review-item .btns { display: flex; gap: 0.45rem; }
.decision { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.3rem 1rem; font-size: var(--step-0); padding: 0.45rem 0; border-bottom: 1px dashed var(--line); }
.manual { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 0.7rem; align-items: end; font-size: var(--step-0); }
.manual label { display: grid; gap: 0.3rem; color: var(--muted); font-weight: 600; }
.manual select { width: 100%; font-family: var(--font-mono); }

/* The bridge: an adding-machine tape. */
.scroll:has(.bridge) {
  border: 1px solid var(--line); border-radius: 4px; background: var(--tape); color: var(--ink);
  max-width: 44rem; padding: 0.75rem 0.5rem; box-shadow: var(--shadow);
}
.bridge { font-family: var(--font-mono); font-size: var(--step-0); }
.bridge th { background: transparent; color: var(--muted); border-bottom: 1.5px dashed var(--line); }
.bridge tbody tr td { background: transparent !important; border-top: 0 !important; }
.bridge td.label { width: 100%; text-transform: uppercase; letter-spacing: 0.02em; }
.bridge td.neg { color: var(--bad); }
.bridge tr.open td, .bridge tr.close td { font-weight: 800; }
.bridge tr.close td { border-top: 1.5px dashed var(--line) !important; }
.bridge tr.close td.num { border-bottom: 3px double var(--ink); }
.bridge tr.proof td { color: var(--muted); }
.bridge tr.proof.ok td.num { color: var(--ok); font-weight: 800; }
.bridge tr.proof.ok td.num::after { content: "  \2713"; }
.bridge tr.proof.bad td.num { color: var(--bad); font-weight: 800; }

.h3 { font: 750 var(--step-2)/1.15 var(--font-display); }
.section-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.3rem 0.9rem; }
.section-title p { margin: 0; color: var(--muted); font-size: var(--step-0); }
.count { color: var(--muted); font-weight: 500; font-family: var(--font-mono); font-size: 0.85em; }

.templates { border-top-color: var(--purple-line); }
.templates ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.35rem; font-size: var(--step-0); }
.templates li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.3rem 1rem; border-bottom: 1px dashed var(--line); padding-block: 0.45rem; }

/* ---- busy + toast ------------------------------------------------------- */
.busy {
  position: fixed; inset: auto 16px calc(16px + env(safe-area-inset-bottom, 0px)) auto; z-index: 20;
  background: var(--purple-fill-deep); color: var(--purple-ink); border-radius: 999px;
  padding: 0.65rem 1.1rem; font: 600 var(--step-0)/1 var(--font-ui); display: flex; gap: 0.6rem; align-items: center; box-shadow: var(--shadow);
}
.spinner { width: 15px; height: 15px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 21; background: var(--toast-bg); color: var(--toast-ink); border-radius: 8px;
  padding: 0.75rem 1.1rem; font-size: var(--step-0); box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}

@media (max-width: 44rem) {
  .map-row { grid-template-columns: 1fr; }
  .map-row.head { display: none; }
  .manual { grid-template-columns: 1fr; }
  .review-item { grid-template-columns: 1fr; }
  .privacy { margin-left: 0; order: 3; }   /* phones: brand and switch share the first row */
  .theme-toggle { margin-left: auto; order: 1; }
  .crumb { order: 2; flex-basis: 100%; }
  .step { padding: 1.2rem 1.1rem 1.3rem; }
  .step-head { grid-template-columns: auto 1fr; }
  .step-head .pill { grid-column: 2; justify-self: start; }
}

/* ==== motion =================================================================
   Everything is readable without it; prefers-reduced-motion turns it off. */
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes print-row { from { opacity: 0; transform: translateY(-6px); clip-path: inset(0 0 100% 0); } to { opacity: 1; transform: none; clip-path: inset(0); } }
@keyframes stamp { 0% { opacity: 0; transform: scale(2.2) rotate(-8deg); } 60% { opacity: 1; transform: scale(0.92); } 100% { transform: none; } }
@keyframes pop { 0% { transform: scale(0.85); } 60% { transform: scale(1.08); } 100% { transform: none; } }
@keyframes leave { to { opacity: 0; transform: translateX(24px); height: 0; padding-block: 0; margin-block: 0; } }
@keyframes breathe { 50% { border-color: var(--purple); background: var(--purple-soft); } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 16px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes busy-in { from { opacity: 0; transform: translateY(10px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes bob { 50% { transform: translateY(-3px); } }

.intro > * { animation: rise 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) backwards; }
.intro > :nth-child(2) { animation-delay: 0.06s; }
.intro > :nth-child(3) { animation-delay: 0.12s; }
.intro > :nth-child(4) { animation-delay: 0.18s; }
.intro > :nth-child(5) { animation-delay: 0.24s; }
.step { animation: rise 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) backwards; }
#step-statement { animation-delay: 0.15s; }
#step-books { animation-delay: 0.25s; }
#step-history { animation-delay: 0.35s; }
#step-results { animation-delay: 0.45s; }
.step { transition: box-shadow 0.25s ease, transform 0.25s ease; }
.step:hover { box-shadow: 0 1px 2px rgb(59 15 122 / 0.06), 0 18px 40px -16px rgb(59 15 122 / 0.32); }

/* The engine line shimmers while it downloads. */
.engine[data-state="loading"] #engine-text {
  background: linear-gradient(90deg, var(--muted) 40%, var(--purple) 50%, var(--muted) 60%) 0 0 / 200% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shimmer 2.2s linear infinite;
}

/* Upload boxes invite a drop. */
.drop { transition: border-color 0.2s, background 0.2s, transform 0.2s; }
.drop:hover { border-color: var(--purple); }
.drop:hover .btn.primary { animation: bob 0.9s ease-in-out infinite; }
.drop.over { animation: breathe 1s ease-in-out infinite; transform: scale(1.01); }

/* A freshly read file unfolds. */
.panel.fresh > * { animation: rise 0.45s cubic-bezier(0.2, 0.7, 0.2, 1) backwards; }
.panel.fresh > :nth-child(2) { animation-delay: 0.05s; }
.panel.fresh > :nth-child(3) { animation-delay: 0.1s; }
.panel.fresh > :nth-child(4) { animation-delay: 0.15s; }
.panel.fresh > :nth-child(5) { animation-delay: 0.2s; }
.panel.fresh > :nth-child(n+6) { animation-delay: 0.25s; }

.pill { transition: background 0.3s, color 0.3s; }
.pill[data-tone="ok"], .pill[data-tone="warn"], .pill[data-tone="bad"] { animation: pop 0.4s ease; }
details[open] > :not(summary) { animation: rise 0.3s ease backwards; }
details > summary::before { transition: transform 0.2s; }
details[open] > summary::before { transform: rotate(180deg); }

/* A new result: totals rise, the tape prints line by line, the proof stamps. */
#panel-results.animate .summary div { animation: rise 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) backwards; }
#panel-results.animate .summary div:nth-child(2) { animation-delay: 0.08s; }
#panel-results.animate .summary div:nth-child(3) { animation-delay: 0.16s; }
#panel-results.animate .summary div:nth-child(4) { animation-delay: 0.24s; }
#panel-results.animate .review-item { animation: rise 0.45s ease backwards; animation-delay: 0.3s; }
#panel-results.animate .bridge tbody tr { animation: print-row 0.3s ease-out backwards; }
#panel-results.animate .bridge tbody tr:nth-child(1) { animation-delay: 0.35s; }
#panel-results.animate .bridge tbody tr:nth-child(2) { animation-delay: 0.45s; }
#panel-results.animate .bridge tbody tr:nth-child(3) { animation-delay: 0.55s; }
#panel-results.animate .bridge tbody tr:nth-child(4) { animation-delay: 0.65s; }
#panel-results.animate .bridge tbody tr:nth-child(5) { animation-delay: 0.75s; }
#panel-results.animate .bridge tbody tr:nth-child(6) { animation-delay: 0.85s; }
#panel-results.animate .bridge tbody tr:nth-child(7) { animation-delay: 0.95s; }
#panel-results.animate .bridge tbody tr:nth-child(8) { animation-delay: 1.05s; }
#panel-results.animate .bridge tbody tr:nth-child(n+9) { animation-delay: 1.15s; }
#panel-results.animate .bridge tr.proof td.num { display: table-cell; animation: stamp 0.55s cubic-bezier(0.3, 1.4, 0.5, 1) 1.35s backwards; }
#panel-results.animate .alert { animation: fade 0.5s ease backwards; }
.review-item.leaving { animation: leave 0.3s ease forwards; overflow: hidden; }
.review-item { transition: border-color 0.2s, box-shadow 0.2s; }
.review-item:hover { box-shadow: var(--shadow); }

button, .btn { transition: border-color 0.15s, background 0.15s, transform 0.12s, box-shadow 0.2s; }
button.primary:hover, button[data-act="excel"]:hover { transform: translateY(-1px); }
button[data-act="excel"]:hover { box-shadow: 0 10px 24px -8px rgb(91 33 182 / 0.65); }

.toast:not([hidden]) { animation: toast-in 0.3s cubic-bezier(0.2, 0.7, 0.2, 1); }
.busy:not([hidden]) { animation: busy-in 0.2s ease; }

@media (prefers-reduced-motion: reduce) {
  .engine[data-state="loading"] #engine-text { color: var(--muted); background: none; }
}

/* Several files in one step: each sits in its own block. */
.file-panel + .file-panel { border-top: 2px dashed var(--purple-line); padding-top: 1.2rem; }

/* ==== orientation =========================================================
   A progress bar under the header always says where you are; finished
   steps shrink to one line; results show one group at a time in tabs. */
.stepper {
  max-width: 74rem; margin: 0 auto; padding: 0 20px 0.6rem;
  display: flex; gap: 0.4rem; overflow-x: auto; scrollbar-width: none;
}
.stepper::-webkit-scrollbar { display: none; }
.stepper a {
  flex: 1 1 0; min-width: max-content; display: flex; align-items: center; gap: 0.55rem;
  padding: 0.45rem 0.8rem 0.45rem 0.45rem; border-radius: 999px; text-decoration: none;
  color: var(--muted); font: 600 var(--step-0)/1 var(--font-ui); background: var(--surface-2);
  border: 1.5px solid transparent; transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.stepper a:hover { border-color: var(--purple-line); color: var(--ink); }
.stepper .n {
  width: 1.65rem; height: 1.65rem; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--surface); border: 1.5px solid var(--line); color: var(--muted); font: 800 0.85rem/1 var(--font-display);
}
.stepper small { font-weight: 500; color: var(--muted); }
.stepper a[aria-current] { border-color: var(--purple); color: var(--ink); background: var(--surface); }
.stepper a[data-tone="ok"] .n { background: var(--ok); border-color: var(--ok); color: var(--on-ok); font-size: 0; }
.stepper a[data-tone="ok"] .n::before { content: "\2713"; font-size: 0.9rem; }
.stepper a[data-tone="warn"] .n { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.stepper a[data-tone="bad"] .n { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.step { scroll-margin-top: 8.5rem; }

/* A finished file: one calm line. */
.fileline.done { align-items: center; }
.done-tick {
  width: 1.5rem; height: 1.5rem; border-radius: 50%; display: inline-grid; place-items: center;
  background: var(--ok); color: var(--on-ok); font-weight: 800; font-size: 0.85rem; flex: none;
}

/* Results tabs. */
.tabs {
  display: flex; flex-wrap: wrap; gap: 0.4rem; border-bottom: 2px solid var(--line); padding-bottom: 0.6rem;
}
.tab {
  border-radius: 999px; padding: 0.55rem 0.9rem; font: 650 var(--step-0)/1 var(--font-ui);
  background: var(--surface-2); border: 1.5px solid transparent; color: var(--ink);
}
.tab:hover { border-color: var(--purple-line); color: var(--purple); }
.tab.on { background: var(--purple-fill); color: var(--purple-ink); border-color: var(--purple-fill); }
.badge {
  display: inline-grid; place-items: center; min-width: 1.5rem; height: 1.5rem; padding: 0 0.4rem;
  margin-left: 0.35rem; border-radius: 999px; font: 700 0.78rem/1 var(--font-mono);
  background: var(--surface); color: var(--muted); border: 1px solid var(--line);
}
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.tab.on .badge { background: rgb(255 255 255 / 0.2); color: #ffffff; border-color: transparent; }
.tab-panel { display: grid; gap: 1rem; min-width: 0; }
.tab-help { margin: 0; font-size: var(--step-1); color: var(--ink); font-weight: 500; }
.empty { margin: 0; color: var(--muted); font-style: italic; }
.tab-panel { animation: fade 0.25s ease; }

/* One step at a time: Back / Next at the foot of each. */
.step-nav {
  display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  border-top: 1px solid var(--line); padding-top: 1.1rem; margin-top: 0.2rem;
}
.step-nav button.primary { font-size: var(--step-1); padding: 0.85rem 1.3rem; }
.stepper a { cursor: pointer; }

/* With one step per screen the title only needs to name the tool. */
.intro { padding-block: 1.75rem 0; gap: 0.6rem; }
.intro h1 { font-size: clamp(1.9rem, 1.4rem + 1.8vw, 2.6rem); max-width: none; }
.intro p { font-size: var(--step-1); }

/* Warnings: a count per kind above the table. */
.warn-kinds { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0; padding: 0; list-style: none; }
.warn-kinds li {
  padding: 0.35rem 0.75rem; border-radius: 999px; background: var(--warn-soft); color: var(--warn);
  font-weight: 650; font-size: var(--step-0);
}
.warn-kinds b { font-family: var(--font-mono); margin-left: 0.25rem; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }

/* Another company's POs: suggestions, the saved rules, and the form. */
.callout {
  display: grid; gap: 0.65rem; padding: 0.9rem 1rem; font-size: var(--step-0);
  border: 1.5px solid var(--purple-line); background: var(--purple-soft); border-radius: var(--radius);
}
.callout p { margin: 0; }
.suggest { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.8rem; }
.suggest .prefix { font-weight: 800; color: var(--purple); min-width: 3.5rem; }
.suggest input { flex: 1 1 12rem; min-width: 0; }
.setaside { display: grid; gap: 0.65rem; border-top: 1px solid var(--line); padding-top: 0.9rem; margin-top: 0.9rem; font-size: var(--step-0); }
.setaside h4 { margin: 0; font: 700 var(--step-1)/1.2 var(--font-display); color: var(--ink); }
.setaside p { margin: 0; }
.rules { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.35rem; font-size: var(--step-0); }
.rules li {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.3rem 0.75rem;
  padding: 0.4rem 0.7rem; background: var(--surface-2); border-radius: 8px;
}
.rules .mono { font-weight: 800; color: var(--purple); }
.setaside-form { display: flex; flex-wrap: wrap; gap: 0.6rem 1rem; align-items: end; }
.setaside-form label { display: grid; gap: 0.3rem; color: var(--muted); font-weight: 600; min-width: 0; }
.setaside-form input[data-ref="sa-prefix"] { width: 8rem; font-family: var(--font-mono); text-transform: uppercase; }
.setaside-form input[data-ref="sa-new-company"] { width: min(16rem, 100%); }
.setaside-form input[data-ref="sa-prefix"]::placeholder { text-transform: none; }

/* Light / dark switch (theme.js). */
.theme-toggle {
  width: 2.5rem; height: 2.5rem; padding: 0; justify-content: center; flex: none;
  border-radius: 999px; background: var(--surface); color: var(--ink);
}
.theme-toggle svg { width: 1.15rem; height: 1.15rem; }
.theme-toggle .sun, :root[data-theme="dark"] .theme-toggle .moon { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; }

/* An "already paid" line to look up before writing to the vendor. */
.check-first { color: var(--warn); }
