/* Design tokens. Light = warm paper + ink, dark = ink + paper, one accent (vermilion). */
:root {
  color-scheme: light dark;

  --bg: light-dark(#f4f0e6, #12110d);
  --surface: light-dark(#fbf8f1, #1a1914);
  --surface-2: light-dark(#ebe6d8, #23211b);
  --ink: light-dark(#16140e, #efebe0);
  --muted: light-dark(#5b5547, #a8a190);
  --line: light-dark(rgb(22 20 14 / .16), rgb(239 235 224 / .16));
  --line-strong: light-dark(rgb(22 20 14 / .52), rgb(239 235 224 / .42));
  --accent: light-dark(#b83208, #ff7a4d);
  --on-accent: light-dark(#ffffff, #1b0d06);
  --accent-soft: light-dark(rgb(184 50 8 / .09), rgb(255 122 77 / .13));
  --good: light-dark(#14633a, #6bd69a);
  --good-soft: light-dark(rgb(20 99 58 / .1), rgb(107 214 154 / .13));
  --warn: light-dark(#7d5200, #f2c14e);
  --warn-soft: light-dark(rgb(125 82 0 / .1), rgb(242 193 78 / .13));
  --bad: light-dark(#a3201a, #ff8f86);
  --bad-soft: light-dark(rgb(163 32 26 / .09), rgb(255 143 134 / .13));

  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --radius: 14px;
  --radius-sm: 9px;
  --gutter: clamp(1.1rem, 4.2vw, 2.5rem);
  --maxw: 72rem;
  --shadow: 0 1px 0 light-dark(rgb(22 20 14 / .05), rgb(0 0 0 / .3)),
            0 22px 40px -28px light-dark(rgb(22 20 14 / .45), rgb(0 0 0 / .8));
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

/* Reset, typography and the few shared components (buttons, pills, form controls). */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: 5.5rem; }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
body {
  margin: 0; min-height: 100vh;
  background: var(--bg); color: var(--ink);
  font: 1.0625rem/1.6 var(--font-sans);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 {
  margin: 0; font-family: var(--font-serif); font-weight: 400;
  line-height: 1.08; letter-spacing: -.015em; text-wrap: balance;
}
p { margin: 0; text-wrap: pretty; }
ul, ol { margin: 0; padding: 0; list-style: none; }
a { color: inherit; text-decoration-color: var(--accent); text-decoration-thickness: .08em; text-underline-offset: .22em; }
a:hover { text-decoration-thickness: .17em; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
::selection { background: var(--accent); color: var(--on-accent); }

.container { width: min(100% - 2 * var(--gutter), var(--maxw)); margin-inline: auto; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: var(--gutter); top: -4rem; z-index: 100;
  background: var(--ink); color: var(--bg); padding: .7rem 1rem; border-radius: 8px; text-decoration: none; font-weight: 600;
}
.skip:focus { top: .75rem; }
.eyebrow { font: 600 .74rem/1.3 var(--font-mono); letter-spacing: .13em; text-transform: uppercase; color: var(--muted); }
.mono { font-family: var(--font-mono); }

/* buttons */
.btn {
  --btn-bg: transparent; --btn-fg: var(--ink); --btn-bd: var(--line-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: .55rem;
  min-height: 3rem; padding: .7rem 1.3rem; border-radius: 999px;
  border: 1.5px solid var(--btn-bd); background: var(--btn-bg); color: var(--btn-fg);
  font: 600 .98rem/1.1 var(--font-sans); text-decoration: none; text-align: center;
  transition: transform .18s ease, background-color .18s ease, border-color .18s ease, filter .18s ease;
}
.btn:hover { transform: translateY(-1px); border-color: var(--ink); text-decoration: none; }
.btn:active { transform: translateY(0); }
.btn--primary { --btn-bg: var(--accent); --btn-fg: var(--on-accent); --btn-bd: var(--accent); }
.btn--primary:hover { border-color: var(--accent); filter: brightness(1.07); }
.btn--sm { min-height: 2.75rem; padding: .5rem 1.05rem; font-size: .92rem; }
.btn--lg { min-height: 3.4rem; padding: .9rem 1.7rem; font-size: 1.04rem; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn .arr { transition: transform .18s ease; }
.btn:hover .arr { transform: translateX(3px); }

.pill {
  display: inline-flex; align-items: center; gap: .5rem; padding: .38rem .75rem;
  border: 1px solid var(--line-strong); border-radius: 999px;
  font: 600 .7rem/1 var(--font-mono); letter-spacing: .09em; text-transform: uppercase; color: var(--ink);
}
.pill .dot { width: .5rem; height: .5rem; border-radius: 50%; background: var(--accent); }

/* form controls (used by the demos) */
.field { display: grid; gap: .35rem; }
.field > label, .field > .label, legend.label { font-weight: 600; font-size: .92rem; }
.hint { color: var(--muted); font-size: .86rem; font-weight: 400; }
.input, .select, .textarea {
  width: 100%; min-height: 2.9rem; padding: .6rem .8rem;
  background: var(--surface); border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.textarea { min-height: 6rem; resize: vertical; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--ink); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; border-color: var(--ink); }
.input[aria-invalid="true"] { border-color: var(--bad); }
.error-text { color: var(--bad); font-size: .88rem; font-weight: 600; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}

/* Shared chrome for the interactive demos. */
.demo-bar { border-bottom: 1px solid var(--line); background: color-mix(in oklab, var(--bg) 92%, transparent); }
.demo-bar__in { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.2rem; min-height: 3.6rem; padding-block: .4rem; }
.demo-bar .back { display: inline-flex; align-items: center; min-height: 2.75rem; text-decoration: none; font-weight: 600; font-size: .95rem; margin-right: auto; }
.demo-bar .back:hover { text-decoration: underline; text-decoration-color: var(--accent); }
.demo-note { color: var(--muted); font-size: .86rem; }
.demo-main { padding-block: clamp(1.75rem, 5vw, 3.5rem) 1rem; }
.demo-intro { max-width: 46rem; margin-bottom: clamp(1.5rem, 4vw, 2.4rem); }
.demo-intro h1 { margin-top: .8rem; font-size: clamp(2.2rem, 1.2rem + 3.8vw, 3.9rem); letter-spacing: -.025em; line-height: 1.02; }
.demo-intro h1 em { font-style: italic; color: var(--accent); }
.demo-intro p:not(.eyebrow) { margin-top: 1rem; color: color-mix(in oklab, var(--ink) 80%, var(--bg)); font-size: 1.1rem; max-width: 40rem; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(1rem, 2.5vw, 1.5rem); }
.panel h2 { font-size: clamp(1.4rem, 1.1rem + 1vw, 1.9rem); letter-spacing: -.015em; }
.panel__eyebrow, .panel .panel__eyebrow { font: 600 .72rem/1.3 var(--font-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.stack { display: grid; gap: 1rem; }

.seg { display: inline-flex; flex-wrap: wrap; gap: .4rem; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.seg span {
  display: inline-flex; align-items: center; min-height: 2.75rem; padding: 0 1.05rem; border-radius: 999px;
  border: 1.5px solid var(--line-strong); font-weight: 600; font-size: .95rem; background: var(--bg); transition: background-color .15s, border-color .15s, color .15s;
}
.seg input:hover + span { border-color: var(--ink); }
.seg input:checked + span { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.seg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

.explain { margin-top: clamp(2.5rem, 6vw, 4rem); }
.explain h2 { font-size: clamp(1.7rem, 1.2rem + 1.6vw, 2.4rem); letter-spacing: -.02em; }
.explain__grid { display: grid; gap: 1.5rem 2rem; margin-top: 1.5rem; }
@media (min-width: 48rem) { .explain__grid { grid-template-columns: repeat(2, 1fr); } }
.explain__grid h3 { font: 600 1.02rem/1.3 var(--font-sans); letter-spacing: 0; }
.explain__grid p { margin-top: .35rem; color: var(--muted); }
.explain__grid li { padding-top: 1rem; border-top: 1px solid var(--line-strong); }

.demo-cta {
  margin-top: clamp(2.5rem, 6vw, 4.5rem); padding: clamp(1.4rem, 4vw, 2.4rem); border: 1px solid var(--line-strong); border-radius: var(--radius);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1.2rem 2rem; background: var(--surface);
}
.demo-cta h2 { font-size: clamp(1.6rem, 1.2rem + 1.4vw, 2.2rem); letter-spacing: -.02em; }
.demo-cta p { margin-top: .4rem; color: var(--muted); max-width: 32rem; }
.demo-footer { margin-top: clamp(2.5rem, 6vw, 4rem); padding-block: 1.6rem 2.2rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .9rem; }
.demo-footer__in { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .6rem 2rem; }


[hidden] { display: none !important; }
.cc + .cc { margin-top: 1.25rem; }
.cc h2 { display: flex; align-items: center; gap: .8rem; margin-bottom: 1rem; }
.num { display: inline-grid; place-items: center; flex: none; width: 2rem; height: 2rem; border-radius: 50%; background: var(--ink); color: var(--bg); font: 600 .9rem/1 var(--font-mono); }
.cc__lede { color: var(--muted); margin: -.3rem 0 1rem; }
.cc__row { display: flex; flex-wrap: wrap; align-items: center; gap: .8rem 1.2rem; margin-top: 1rem; }
.file-info { color: var(--muted); font-size: .92rem; overflow-wrap: anywhere; }

/* drop zone */
.drop { position: relative; border: 2px dashed var(--line-strong); border-radius: var(--radius); background: var(--bg); transition: border-color .15s, background-color .15s; }
.drop:hover, .drop.is-over { border-color: var(--accent); background: var(--accent-soft); }
.drop:focus-within { outline: 3px solid var(--accent); outline-offset: 3px; }
.drop__input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.drop__label { display: grid; justify-items: center; gap: .3rem; padding: clamp(1.6rem, 5vw, 2.6rem) 1rem; text-align: center; pointer-events: none; }
.drop__label strong { font: 400 1.5rem/1.2 var(--font-serif); }

/* tables */
.tablewrap { overflow: auto; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--bg); max-width: 100%; }
.tablewrap:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.cols { width: 100%; border-collapse: collapse; font-size: .92rem; }
.cols th, .cols td { padding: .6rem .8rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.cols thead th { font: 600 .72rem/1.3 var(--font-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; }
.cols tbody th { font-weight: 650; overflow-wrap: anywhere; min-width: 7rem; }
.cols tbody tr:last-child > * { border-bottom: 0; }
.cols .sample { color: var(--muted); font-family: var(--font-mono); font-size: .8rem; min-width: 12rem; max-width: 22rem; overflow-wrap: anywhere; }
.cols .res { white-space: nowrap; color: var(--muted); }
.cols .res--flag { color: var(--warn); font-weight: 600; }
.select--sm { min-height: 2.5rem; padding-block: .3rem; font-size: .92rem; min-width: 11rem; }

/* options */
.optgrid { display: grid; gap: 1rem; margin-top: 1.4rem; }
@media (min-width: 40rem) { .optgrid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 66rem) { .optgrid { grid-template-columns: repeat(4, 1fr); } }
.optset { display: grid; gap: .8rem; align-content: start; padding: 1rem; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.optset legend { padding: 0 .4rem; font: 600 .72rem/1.3 var(--font-mono); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.check { display: flex; align-items: flex-start; gap: .65rem; cursor: pointer; line-height: 1.4; }
.check input { flex: none; width: 1.25rem; height: 1.25rem; margin: .1rem 0 0; accent-color: var(--accent); cursor: pointer; }
.check small { color: var(--muted); font-size: .84rem; }
.check--inline { display: inline-flex; margin: .2rem 1rem .2rem 0; }
.dedupecols { display: flex; flex-wrap: wrap; padding: .3rem 0 0; }
.optset .field label { font-size: .88rem; }
.optset code, .export code { font: 600 .85em var(--font-mono); background: var(--surface-2); padding: .05em .35em; border-radius: 4px; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); gap: .75rem; margin: 0 0 .9rem; }
.stats > div { padding: .8rem 1rem; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.stats dt { font: 600 .68rem/1.35 var(--font-mono); letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.stats dd { margin: .2rem 0 0; font: 400 1.9rem/1 var(--font-serif); letter-spacing: -.02em; }
.stats .is-alert dd { color: var(--bad); }
.note { color: var(--muted); min-height: 1.4rem; margin-bottom: 1rem; font-size: .94rem; }
.reviewbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .8rem 1.5rem; margin-bottom: .9rem; }
.legend { display: inline-flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .84rem; }
.dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; margin-left: .6rem; }
.dot--err { background: var(--bad); }
.dot--warn { background: var(--warn); }

/* preview table */
.tablewrap--preview { max-height: 34rem; }
.preview { border-collapse: separate; border-spacing: 0; min-width: 100%; font-size: .86rem; }
.preview th, .preview td { padding: .5rem .75rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; max-width: 24rem; overflow-wrap: break-word; }
.preview thead th { position: sticky; top: 0; z-index: 2; background: var(--surface-2); font-weight: 650; white-space: nowrap; border-bottom: 1px solid var(--line-strong); }
.typetag { display: block; font: 600 .64rem/1.4 var(--font-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.preview .rownum { position: sticky; left: 0; z-index: 1; background: var(--surface-2); font: 600 .8rem/1.4 var(--font-mono); color: var(--muted); white-space: nowrap; border-right: 1px solid var(--line-strong); }
.preview thead .rownum { z-index: 3; }
.preview td { min-width: 7.5rem; }
.preview td.empty { color: var(--muted); padding: 1.4rem; text-align: center; }
.preview del { display: block; width: fit-content; max-width: 100%; color: var(--bad); text-decoration: line-through; font-family: var(--font-mono); font-size: .8em; line-height: 1.4; }
.preview ins { display: block; width: fit-content; max-width: 100%; text-decoration: none; background: var(--good-soft); padding: .05em .3em; margin-top: .1rem; border-radius: 4px; font-weight: 600; }
.preview ins.is-blank { color: var(--muted); font-weight: 400; font-style: italic; background: none; }
.preview td.flag { box-shadow: inset 3px 0 0 var(--bad); background: var(--bad-soft); }
.preview td.flag--warn { box-shadow: inset 3px 0 0 var(--warn); background: var(--warn-soft); }
.cell-msg { display: block; margin-top: .2rem; font-size: .76rem; font-weight: 650; line-height: 1.35; color: var(--bad); }
.flag--warn .cell-msg { color: var(--warn); }
.preview tr.is-removed td, .preview tr.is-removed th { color: var(--muted); }
.preview td.is-gone { text-decoration: line-through; }
.rm { display: block; margin-top: .15rem; font: 600 .7rem/1.3 var(--font-mono); color: var(--bad); text-decoration: none; white-space: normal; min-width: 8.5rem; }
.showing { margin-top: .7rem; color: var(--muted); font-size: .9rem; min-height: 1.3rem; }
.more { margin-top: .4rem; }

/* export */
.export { display: grid; gap: 1.4rem; margin-top: 1.6rem; padding-top: 1.4rem; border-top: 1px solid var(--line-strong); }
@media (min-width: 56rem) { .export { grid-template-columns: 1.1fr 1fr; align-items: start; } }
.export__opts { display: grid; gap: .8rem; }
.export__btns { display: grid; gap: .8rem; justify-items: start; }
.explain__note { margin-top: 1.4rem; max-width: 44rem; }
