/* ==========================================================================
   tdalogic.com — design system
   Scientific reference style: serif headings, sans body, ~70ch measure.
   System font stacks; no external assets. Light theme + dark scheme.
   ========================================================================== */

/* ---------- 1. Tokens ---------- */
:root {
  color-scheme: light dark;

  /* Typography */
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua",
    Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    "Noto Sans", "Liberation Sans", Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", "Segoe UI Mono",
    Menlo, Consolas, "Liberation Mono", monospace;

  --fs-base: 1.0625rem;          /* 17px body */
  --fs-small: 0.875rem;
  --fs-xsmall: 0.8125rem;
  --lh-body: 1.65;
  --lh-tight: 1.25;
  --measure: 70ch;               /* comfortable reading width */
  --page: 52rem;                 /* overall column, allows wider tables/figures */

  /* Spacing scale */
  --s-1: 0.25rem;
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.5rem;
  --s-6: 2rem;
  --s-7: 3rem;
  --s-8: 4rem;

  --radius: 6px;
  --radius-pill: 999px;

  /* Colour — light (all text pairs checked to WCAG AA or better) */
  --paper: #fcfbf8;
  --paper-2: #f4f2ec;            /* tinted panels */
  --ink: #1b1e23;                /* body text, ~15.9:1 on paper */
  --ink-2: #4a505a;              /* secondary text, ~8:1 */
  --ink-3: #5f6672;              /* meta text, ~5.8:1 */
  --rule: #d8d4ca;
  --rule-strong: #b9b3a6;
  --accent: #0b5563;             /* deep teal, ~8:1 on paper */
  --accent-ink: #083f4a;
  --accent-tint: #e5f0f1;
  --link: #0b5563;
  --link-visited: #4b3f72;
  --focus: #c2410c;              /* high-visibility focus ring */
  --mark: #fff3c4;

  /* Evidential status pills (text colour on tint, AA at small size) */
  --st-spec-fg: #1e3a8a;  --st-spec-bg: #e6ecfb;  --st-spec-bd: #9fb3e8;
  --st-meas-fg: #14532d;  --st-meas-bg: #e3f3e8;  --st-meas-bd: #93c9a5;
  --st-mod-fg:  #7c2d12;  --st-mod-bg:  #fbeee2;  --st-mod-bd:  #e3b48f;
  --st-not-fg:  #3f3f46;  --st-not-bg:  #ededee;  --st-not-bd:  #a1a1aa;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #14171b;
    --paper-2: #1c2026;
    --ink: #e7e5df;
    --ink-2: #bdbab2;
    --ink-3: #a29f97;
    --rule: #343a42;
    --rule-strong: #4a515b;
    --accent: #6cc3cf;
    --accent-ink: #9fdbe3;
    --accent-tint: #15313a;
    --link: #7fcfda;
    --link-visited: #b9a8e6;
    --focus: #fb923c;
    --mark: #4a3d0c;

    --st-spec-fg: #c7d5fb;  --st-spec-bg: #1c2747;  --st-spec-bd: #4060a8;
    --st-meas-fg: #bfe8cc;  --st-meas-bg: #15301f;  --st-meas-bd: #3f8a5a;
    --st-mod-fg:  #f6d0b0;  --st-mod-bg:  #3a2416;  --st-mod-bd:  #a5653a;
    --st-not-fg:  #d9d9de;  --st-not-bg:  #2a2b30;  --st-not-bd:  #6b6b75;
  }
}

/* ---------- 2. Base ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: var(--s-5);
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  font-kerning: normal;
  font-variant-numeric: oldstyle-nums proportional-nums;
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
}

img, svg, video { max-width: 100%; height: auto; }

::selection { background: var(--mark); color: var(--ink); }

/* ---------- 3. Links & focus ---------- */
a {
  color: var(--link);
  text-decoration-line: underline;
  text-decoration-thickness: 0.06em;
  text-underline-offset: 0.18em;
  text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
}
a:visited { color: var(--link-visited); }
a:hover { text-decoration-color: currentColor; text-decoration-thickness: 0.1em; }

:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Skip link: hidden until focused */
.skip {
  position: absolute;
  left: var(--s-4);
  top: -100px;
  z-index: 100;
  padding: var(--s-2) var(--s-4);
  background: var(--ink);
  color: var(--paper);
  font-weight: 600;
  text-decoration: none;
  border-radius: var(--radius);
}
.skip:visited { color: var(--paper); }
.skip:focus,
.skip:focus-visible { top: var(--s-4); }

/* ---------- 4. Layout ---------- */
.wrap {
  width: 100%;
  max-width: var(--page);
  margin-inline: auto;
  padding-inline: clamp(1rem, 4vw, 2rem);
}

main.wrap {
  padding-top: var(--s-6);
  padding-bottom: var(--s-8);
}

/* ---------- 5. Header & navigation (no JS; wraps on small screens) ---------- */
.site-header {
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}
.site-header .wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-2) var(--s-5);
  padding-block: var(--s-4);
}

.brand {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.brand:visited { color: var(--ink); }
.brand:hover { color: var(--accent); }
.brand-mark {
  color: var(--accent);
  font-size: 1.1em;
  margin-right: 0.15em;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-1) var(--s-4);
  font-size: 0.9375rem;
}
.site-nav a {
  color: var(--ink-2);
  text-decoration: none;
  padding-block: var(--s-1);
  border-bottom: 2px solid transparent;
}
.site-nav a:visited { color: var(--ink-2); }
.site-nav a:hover { color: var(--accent); border-bottom-color: var(--accent); }
.site-nav a[aria-current="page"] {
  color: var(--ink);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

@media (max-width: 40rem) {
  .site-header .wrap { display: block; }
  .brand { display: inline-block; margin-bottom: var(--s-2); }
  .site-nav { gap: var(--s-1) var(--s-3); }
  .site-nav a { padding-block: 0.35rem; } /* larger touch targets */
}

/* ---------- 6. Document column ---------- */
.doc { max-width: var(--page); }

.doc > p,
.doc > ul,
.doc > ol,
.doc > dl,
.doc > blockquote,
.doc > h1,
.doc > h2,
.doc > h3,
.doc > h4,
.doc section > p,
.doc section > ul,
.doc section > ol,
.doc li,
.doc dd { max-width: var(--measure); }

.eyebrow {
  margin: 0 0 var(--s-2);
  font-size: var(--fs-xsmall);
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent);
}

.lede {
  margin-top: var(--s-3);
  font-family: var(--font-serif);
  font-size: 1.25rem;
  line-height: 1.5;
  color: var(--ink-2);
}

.meta {
  margin: var(--s-4) 0 var(--s-6);
  padding-bottom: var(--s-4);
  border-bottom: 1px solid var(--rule);
  font-size: var(--fs-small);
  color: var(--ink-3);
}
.meta a { color: inherit; }

/* ---------- 7. Headings & text ---------- */
h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 700;
  line-height: var(--lh-tight);
  color: var(--ink);
  font-variant-numeric: lining-nums;
  text-wrap: balance;
}
h1 {
  margin: 0;
  font-size: clamp(1.9rem, 1.4rem + 2.2vw, 2.6rem);
  letter-spacing: -0.01em;
}
h2 {
  margin: var(--s-7) 0 var(--s-3);
  padding-top: var(--s-3);
  border-top: 1px solid var(--rule);
  font-size: clamp(1.4rem, 1.2rem + 0.9vw, 1.7rem);
}
h3 {
  margin: var(--s-6) 0 var(--s-2);
  font-size: 1.25rem;
}
h4 {
  margin: var(--s-5) 0 var(--s-2);
  font-family: var(--font-sans);
  font-size: 1rem;
  letter-spacing: 0.01em;
}
h2 + h3 { margin-top: var(--s-4); }

p { margin: 0 0 var(--s-4); }
ul, ol { margin: 0 0 var(--s-4); padding-left: 1.4em; }
li { margin-bottom: var(--s-2); }
li > ul, li > ol { margin-top: var(--s-2); }

strong, b { font-weight: 650; }
small { font-size: var(--fs-small); }
sub, sup { font-size: 0.75em; line-height: 0; }
abbr[title] { text-decoration: underline dotted; cursor: help; }
dfn { font-style: normal; font-weight: 700; }
mark { background: var(--mark); color: inherit; padding: 0 0.15em; }

hr {
  margin: var(--s-7) 0;
  border: 0;
  border-top: 1px solid var(--rule);
}

blockquote {
  margin: var(--s-5) 0;
  padding: var(--s-1) 0 var(--s-1) var(--s-5);
  border-left: 3px solid var(--rule-strong);
  font-family: var(--font-serif);
  font-size: 1.0625rem;
  color: var(--ink-2);
}
blockquote p:last-child { margin-bottom: 0; }

/* ---------- 8. Code ---------- */
code, kbd, samp, pre {
  font-family: var(--font-mono);
  font-size: 0.875em;
  font-variant-numeric: lining-nums tabular-nums;
}
code {
  padding: 0.1em 0.3em;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 4px;
}
pre {
  margin: var(--s-4) 0 var(--s-5);
  padding: var(--s-4);
  overflow-x: auto;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  line-height: 1.5;
  tab-size: 2;
}
pre code {
  padding: 0;
  background: none;
  border: 0;
  font-size: 0.875rem;
  white-space: pre;
}
kbd {
  padding: 0.05em 0.4em;
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  font-size: 0.85em;
}

/* ---------- 9. Boxes: keyfacts, note, callout ---------- */
.keyfacts {
  margin: var(--s-5) 0 var(--s-6);
  padding: var(--s-4) var(--s-5);
  background: var(--accent-tint);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
}
.keyfacts > :first-child { margin-top: 0; }
.keyfacts > :last-child { margin-bottom: 0; }
.keyfacts h2,
.keyfacts h3 {
  margin: 0 0 var(--s-2);
  padding: 0;
  border: 0;
  font-size: 1.1rem;
}
.keyfacts ul, .keyfacts ol { margin-bottom: 0; }
.keyfacts dl { margin: 0; }
.keyfacts dt { font-weight: 650; }
.keyfacts dd { margin: 0 0 var(--s-3); }

.note {
  margin: var(--s-5) 0;
  padding: var(--s-3) var(--s-4);
  background: var(--paper-2);
  border-left: 3px solid var(--rule-strong);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.96rem;
  color: var(--ink-2);
  max-width: var(--measure);
}
.note > :last-child { margin-bottom: 0; }
.note strong:first-child { color: var(--ink); }

.callout {
  margin: var(--s-6) 0;
  padding: var(--s-4) var(--s-5);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 1px 0 var(--rule);
  max-width: var(--measure);
}
.callout > :first-child { margin-top: 0; }
.callout > :last-child { margin-bottom: 0; }
.callout h2,
.callout h3 {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
  font-size: 1.15rem;
}

/* ---------- 10. Tables (wrapper-free horizontal scroll) ---------- */
table.data {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: var(--s-5) 0 var(--s-6);
  border-collapse: collapse;
  font-size: 0.9375rem;
  line-height: 1.45;
  font-variant-numeric: lining-nums tabular-nums;
}
table.data caption {
  caption-side: top;
  padding: 0 0 var(--s-2);
  text-align: left;
  font-family: var(--font-serif);
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
}
table.data th,
table.data td {
  padding: var(--s-2) var(--s-3);
  border-bottom: 1px solid var(--rule);
  text-align: left;
  vertical-align: top;
  min-width: 9rem;
}
table.data thead th {
  border-bottom: 2px solid var(--ink-2);
  font-size: var(--fs-small);
  font-weight: 650;
  letter-spacing: 0.02em;
  color: var(--ink);
  white-space: nowrap;
}
table.data tbody th { font-weight: 650; }
table.data tbody tr:last-child > * { border-bottom: 2px solid var(--ink-2); }
table.data tbody tr:nth-child(even) { background: color-mix(in srgb, var(--paper-2) 60%, transparent); }
table.data td.num,
table.data th.num { text-align: right; }

/* ---------- 11. Evidential status pills (text + shape, not colour alone) ---------- */
.status {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.05em 0.6em 0.1em;
  border: 1px solid;
  border-radius: var(--radius-pill);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.5;
  letter-spacing: 0.02em;
  white-space: nowrap;
  vertical-align: 0.08em;
}
.status::before {
  font-size: 0.85em;
  line-height: 1;
}
.status-specified   { color: var(--st-spec-fg); background: var(--st-spec-bg); border-color: var(--st-spec-bd); border-style: solid; }
.status-specified::before   { content: "\25C6"; }   /* ◆ design */
.status-measured    { color: var(--st-meas-fg); background: var(--st-meas-bg); border-color: var(--st-meas-bd); border-style: solid; }
.status-measured::before    { content: "\25CF"; }   /* ● observed */
.status-modelled    { color: var(--st-mod-fg);  background: var(--st-mod-bg);  border-color: var(--st-mod-bd);  border-style: dashed; }
.status-modelled::before    { content: "\25D0"; }   /* ◐ calculated */
.status-notmeasured { color: var(--st-not-fg);  background: var(--st-not-bg);  border-color: var(--st-not-bd);  border-style: dotted; }
.status-notmeasured::before { content: "\25CB"; }   /* ○ open */

/* ---------- 12. References ---------- */
ol.refs {
  margin: var(--s-4) 0 var(--s-6);
  padding-left: 2.6em;
  font-size: 0.9375rem;
  line-height: 1.55;
  max-width: var(--measure);
}
ol.refs li {
  margin-bottom: var(--s-3);
  padding-left: 0.3em;
}
ol.refs li::marker {
  font-variant-numeric: lining-nums tabular-nums;
  color: var(--ink-3);
  font-weight: 600;
}
ol.refs a { word-break: break-word; }
ol.refs li:target,
.terms dt:target,
.terms dt:target + dd,
h2:target, h3:target {
  background: var(--mark);
  border-radius: 3px;
}

/* ---------- 13. Glossary terms ---------- */
dl.terms {
  margin: var(--s-4) 0 var(--s-6);
  max-width: var(--measure);
}
dl.terms dt {
  margin-top: var(--s-5);
  padding: 0 0.2em;
  font-family: var(--font-serif);
  font-size: 1.125rem;
  font-weight: 700;
  line-height: var(--lh-tight);
  color: var(--ink);
}
dl.terms dt:first-child { margin-top: 0; }
dl.terms dt a.anchor {
  margin-left: 0.4em;
  font-family: var(--font-sans);
  font-size: 0.8em;
  font-weight: 400;
  color: var(--ink-3);
  text-decoration: none;
}
dl.terms dt a.anchor:hover { color: var(--accent); }
dl.terms dd {
  margin: var(--s-1) 0 0;
  padding: 0 0.2em var(--s-4);
  border-bottom: 1px solid var(--rule);
}
dl.terms dd p:last-child { margin-bottom: 0; }

/* ---------- 14. Figures & SVG ---------- */
figure {
  margin: var(--s-6) 0;
  padding: var(--s-4);
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
figure svg,
figure img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  margin-inline: auto;
}
figure svg { max-height: 34rem; }
figcaption {
  margin-top: var(--s-3);
  font-size: var(--fs-small);
  line-height: 1.5;
  color: var(--ink-2);
  max-width: var(--measure);
}
figcaption strong:first-child { color: var(--ink); }

/* Inline SVG text follows the theme when authors use currentColor */
svg { color: var(--ink); }
svg text { font-family: var(--font-sans); }

/* ---------- 15. Cards & grids ---------- */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
  gap: var(--s-4);
  margin: var(--s-5) 0 var(--s-6);
}

.card,
.dest-card {
  padding: var(--s-4) var(--s-4) var(--s-3);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.card > :first-child,
.dest-card > :first-child { margin-top: 0; }
.card > :last-child,
.dest-card > :last-child { margin-bottom: 0; }
.card h3, .dest-card h3,
.card h4, .dest-card h4 {
  margin: 0 0 var(--s-2);
  font-size: 1.1rem;
}
.card p, .dest-card p { font-size: 0.96rem; }

.dest-card {
  border-top: 4px solid var(--accent);
  background: linear-gradient(var(--accent-tint), var(--paper) 3.5rem);
}
.dest-card dl { margin: 0; font-size: 0.93rem; }
.dest-card dt {
  margin-top: var(--s-2);
  font-size: var(--fs-xsmall);
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.dest-card dd { margin: 0; }

ul.card-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr));
  gap: var(--s-4);
  margin: var(--s-5) 0 var(--s-6);
  padding: 0;
  list-style: none;
}
ul.card-list > li {
  margin: 0;
  max-width: none;
}
ul.card-list > li.card { display: flex; flex-direction: column; }
ul.card-list .card a:first-child,
ul.card-list h3 a {
  font-family: var(--font-serif);
  font-weight: 700;
  text-decoration: none;
}
ul.card-list .card a:hover { text-decoration: underline; }

/* ---------- 16. Footer ---------- */
.site-footer {
  margin-top: var(--s-6);
  padding: var(--s-6) 0 var(--s-7);
  border-top: 1px solid var(--rule);
  background: var(--paper-2);
  font-size: var(--fs-small);
  color: var(--ink-2);
}
.site-footer p { max-width: var(--measure); margin-bottom: var(--s-3); }
.site-footer a { color: var(--ink-2); }
.site-footer a:hover { color: var(--accent); }

/* ---------- 17. Small screens ---------- */
@media (max-width: 40rem) {
  :root { --fs-base: 1rem; }
  main.wrap { padding-top: var(--s-5); }
  h2 { margin-top: var(--s-6); }
  .lede { font-size: 1.125rem; }
  .keyfacts, .callout { padding: var(--s-3) var(--s-4); }
  figure { padding: var(--s-3); margin-inline: 0; }
  table.data { font-size: 0.875rem; }
  table.data th, table.data td { min-width: 7.5rem; }
}

/* ---------- 18. Motion & contrast preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
@media (prefers-contrast: more) {
  :root { --rule: #8a857b; --ink-2: #2b2f36; --ink-3: #3a3f47; }
  a { text-decoration-color: currentColor; }
}
@media (forced-colors: active) {
  .status { border: 1px solid CanvasText; forced-color-adjust: auto; }
  .keyfacts, .callout, .note, figure, .card, .dest-card { border: 1px solid CanvasText; }
}

/* ---------- 19. Print ---------- */
@media print {
  @page { margin: 18mm 16mm; }
  :root {
    --paper: #fff; --paper-2: #fff; --ink: #000; --ink-2: #222; --ink-3: #333;
    --rule: #999; --accent: #000; --accent-tint: #fff; --link: #000;
  }
  html { font-size: 10.5pt; }
  body { background: #fff; color: #000; line-height: 1.45; font-variant-numeric: lining-nums; }
  .skip, .site-nav, dl.terms dt a.anchor { display: none !important; }
  .site-header { border-bottom: 1px solid #000; }
  .site-header .wrap, .wrap { max-width: none; padding: 0; }
  main.wrap { padding: 0; }
  .doc > *, .doc li, .doc dd { max-width: none; }
  a, a:visited { color: #000; text-decoration: underline; }
  .doc a[href^="http"]::after,
  .site-footer a[href^="http"]::after {
    content: " <" attr(href) ">";
    font-size: 0.85em;
    word-break: break-all;
  }
  .doc a[href^="/"]::after { content: " <https://tdalogic.com" attr(href) ">"; font-size: 0.85em; }
  h1, h2, h3, h4 { page-break-after: avoid; break-after: avoid; }
  h2 { border-top: 0; margin-top: 1.5em; }
  p, li, dd { orphans: 3; widows: 3; }
  figure, table.data, pre, .keyfacts, .callout, .note, .card, .dest-card, dl.terms dd {
    page-break-inside: avoid;
    break-inside: avoid;
  }
  table.data { display: table; overflow: visible; }
  table.data tbody tr:nth-child(even) { background: none; }
  figure, .keyfacts, .callout, .note, .card, .dest-card, pre, code {
    background: #fff !important;
    box-shadow: none;
    border-color: #777;
  }
  .status { background: #fff !important; color: #000 !important; border-color: #000 !important; }
  .site-footer { background: #fff; border-top: 1px solid #000; margin-top: 2em; padding: 1em 0 0; }
}
