/* ============================================================================
   saphan.ai — one stylesheet, two themes.

   Dark is the default and the identity; light exists because dark does not
   land for everyone. The light theme is *selected*, not inverted: every value
   below was chosen against its own surface and contrast-checked, because a
   flipped dark palette produces muddy greens and unreadable dim text.

   Contrast, light theme, against --ground unless noted:
     body 12.4 · bright 17.6 · muted 6.1 · dim 4.8 · accent 5.8
     code 10.2 (on --surface) · terracotta 5.5 · blue 7.1
     chart accent 5.3 and chart context 3.2, both on --surface
   Dark theme values are the originals, unchanged.
   ========================================================================= */

:root {
  color-scheme: dark;

  --ground:       #0c0e0d;   /* page */
  --surface:      #101312;   /* terminal blocks, figures */
  --rule:         #1d211e;   /* section and row rules */
  --edge:         #22271f;   /* surface borders, stronger rules */

  --ink:          #eef1ef;   /* headings, emphasis */
  --ink-body:     #d6dad7;   /* body copy */
  --ink-code:     #c3cbc5;   /* monospace inside surfaces */
  --ink-muted:    #9aa39d;   /* secondary copy */
  --ink-dim:      #5a655d;   /* labels, numerals, prompts */
  --ink-faint:    #454f48;   /* the quietest mark on the page */

  --accent:       #86a98f;   /* links, the mark that carries identity */
  --accent-hi:    #a3c2ab;   /* hover */
  --accent-line:  rgba(134,169,143,0.4);
  --accent-edge:  rgba(134,169,143,0.35);
  --accent-wash:  rgba(134,169,143,0.28);

  --status-bad:   #c98a7d;   /* [refused] — always beside a word */
  --status-run:   #7d97c9;   /* [running] — always beside a word */

  --chart-mark:   #86a98f;   /* the measured recommendation */
  --chart-ctx:    #6b756e;   /* everything that is context */

  --highlight-row: #16201a;  /* selected line in the fleet projection */
  --shadow: none;
}

:root[data-theme="light"] {
  color-scheme: light;

  --ground:       #f8f9f6;
  --surface:      #edf0ea;
  --rule:         #dde1d9;
  --edge:         #d3d9cf;

  --ink:          #10140f;
  --ink-body:     #2b322d;
  --ink-code:     #333a35;
  --ink-muted:    #58615a;
  --ink-dim:      #646f67;   /* 4.95 page, 4.55 surface */
  --ink-faint:    #7b837c;   /* decorative, 3.7 - see the a11y note */

  --accent:       #3f6b4f;
  --accent-hi:    #2f5a3f;
  --accent-line:  rgba(63,107,79,0.42);
  --accent-edge:  rgba(63,107,79,0.38);
  --accent-wash:  rgba(63,107,79,0.20);

  --status-bad:   #a24b37;
  --status-run:   #37548a;

  --chart-mark:   #3f6b4f;
  --chart-ctx:    #7e877f;

  --highlight-row: #e3ebe1;
  --shadow: 0 1px 2px rgba(16,20,15,0.05);
}


/* ── Accessibility note, deliberately left as a decision ─────────────────────
   The DARK theme's --ink-dim (#5a655d) measures 3.19:1 on the page and 3.07:1
   on surfaces. That is below WCAG AA (4.5:1) for the small text it carries:
   section labels, row numerals, footer, table headers. This is the ORIGINAL
   value, kept so the dark theme renders pixel-identical to the site as it
   shipped — changing a brand colour is not a refactor's business.

   To bring dark to AA, change one line in :root —
       --ink-dim: #758078;
   which measures 4.72 on the page and 4.55 on surfaces. It is a visibly
   lighter grey; nothing else needs to move.

   The LIGHT theme passes AA on every text role. Its --ink-faint (#7b837c,
   3.7:1) sits below AA by choice: it carries only the ornamental สะพาน in the
   footer, which the logo beside it and the page title already say.
   ─────────────────────────────────────────────────────────────────────────── */

/* ── frame ───────────────────────────────────────────────────────────────── */
html, body { margin: 0; padding: 0; background: var(--ground); }
body { font-family: 'IBM Plex Sans', sans-serif; }
::selection { background: var(--accent-wash); }
a { color: var(--accent); }
a:hover { color: var(--accent-hi); }

.page {
  min-height: 100vh; background: var(--ground); color: var(--ink-body);
  font-family: 'IBM Plex Sans', sans-serif; font-size: 17px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
.wrap {
  max-width: 820px; margin: 0 auto; padding: 0 clamp(20px, 5vw, 48px);
  display: flex; flex-direction: column;
}

/* ── sections ────────────────────────────────────────────────────────────── */
.sec { padding: clamp(40px, 8vh, 72px) 0; border-top: 1px solid var(--rule); }
.sec-hero {
  min-height: 88vh; display: flex; flex-direction: column;
  justify-content: center; padding: clamp(48px, 10vh, 96px) 0;
}
.sec-top { padding: clamp(40px, 8vh, 72px) 0 clamp(32px, 6vh, 56px); }
.sec-cta { padding: clamp(48px, 10vh, 88px) 0 clamp(56px, 10vh, 96px); border-top: 1px solid var(--rule); }

.label {
  font-family: 'IBM Plex Mono', monospace; font-weight: 400; font-size: 13px;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-dim);
  margin: 0 0 28px;
}
/* must follow .label — same specificity, source order decides */
.label-tight { margin-bottom: 16px; }

/* ── numbered rows ───────────────────────────────────────────────────────── */
.rows { display: flex; flex-direction: column; }
.row {
  display: grid; grid-template-columns: 3ch 1fr; gap: 20px;
  padding: 22px 0; border-bottom: 1px solid var(--rule);
}
.row:last-child { border-bottom: none; }
.num { font-family: 'IBM Plex Mono', monospace; font-size: 13px; color: var(--ink-dim); padding-top: 5px; }
.row :where(h3), .rh { font-family: 'Schibsted Grotesk', sans-serif; font-weight: 600; font-size: 17px; color: var(--ink); margin: 0 0 6px; }
.row :where(p) { margin: 0; color: var(--ink-body); max-width: 42em; text-wrap: pretty; }

/* ── copy ────────────────────────────────────────────────────────────────── */
.p     { margin: 0; color: var(--ink-body); max-width: 42em; text-wrap: pretty; }
.p-b   { margin: 0 0 18px; color: var(--ink-body); max-width: 42em; text-wrap: pretty; }
.p-in  { margin: 0 0 20px; color: var(--ink-body); max-width: 42em; text-wrap: pretty; }
.intro { margin: 0 0 24px; color: var(--ink-muted); max-width: 42em; text-wrap: pretty; }
/* No max-width: the original had none, and adding one re-wraps ten paragraphs.
   Kept faithful on purpose — capping this measure is a separate decision. */
.note  { margin: 12px 0 0; font-size: 15px; color: var(--ink-muted); }
.note-lg { margin: 20px 0 0; font-size: 15px; color: var(--ink-muted); max-width: 42em; text-wrap: pretty; }
.foot-note { margin: 24px 0 0; font-size: 15px; color: var(--ink-muted); max-width: 42em; text-wrap: pretty; }
.lede  { margin: 28px 0 0; font-size: clamp(17px, 2.2vw, 20px); color: var(--ink-muted); max-width: 34em; text-wrap: pretty; }
.stack { display: flex; flex-direction: column; gap: 18px; max-width: 42em; }
.stack :where(p), .p-plain { margin: 0; color: var(--ink-body); text-wrap: pretty; }
.bright { color: var(--ink); }
.dim    { color: var(--ink-dim); }
.grn    { color: var(--accent); }
.ter    { color: var(--status-bad); }
.blu    { color: var(--status-run); }

.h1 {
  font-family: 'Schibsted Grotesk', sans-serif; font-weight: 700;
  font-size: clamp(30px, 5.4vw, 54px); line-height: 1.12; letter-spacing: -0.015em;
  color: var(--ink); margin: clamp(40px, 8vh, 72px) 0 0; max-width: 15em; text-wrap: balance;
}
.h1-sub {
  font-family: 'Schibsted Grotesk', sans-serif; font-weight: 700;
  font-size: clamp(28px, 4.8vw, 46px); line-height: 1.14; letter-spacing: -0.015em;
  color: var(--ink); margin: 18px 0 0; max-width: 16em; text-wrap: balance;
}
.hero-sub { margin: 28px 0 0; font-size: clamp(17px, 2.2vw, 20px); color: var(--ink-muted); max-width: 34em; text-wrap: pretty; }

/* ── links, brand ────────────────────────────────────────────────────────── */
.brand { display: flex; align-items: center; gap: 14px; color: var(--ink); }
.home-link { display: flex; align-items: center; gap: 14px; color: var(--ink); text-decoration: none; }
.brand-name { font-family: 'Schibsted Grotesk', sans-serif; font-weight: 600; font-size: 22px; letter-spacing: 0.01em; color: var(--ink); }
.brand-name-sm { font-family: 'Schibsted Grotesk', sans-serif; font-weight: 600; font-size: 20px; letter-spacing: 0.01em; }
.mono-link {
  font-family: 'IBM Plex Mono', monospace; font-size: 14px; letter-spacing: 0.06em;
  color: var(--accent); text-decoration: none;
  border-bottom: 1px solid var(--accent-line); padding-bottom: 2px;
}
.links { margin: 22px 0 0; display: flex; gap: 22px; flex-wrap: wrap; align-items: baseline; }
.contact-link {
  font-family: 'Schibsted Grotesk', sans-serif; font-weight: 600;
  font-size: clamp(20px, 3vw, 28px); color: var(--accent); text-decoration: none;
  border-bottom: 1px solid var(--accent-line); padding-bottom: 3px;
}
.contact-link:hover { color: var(--accent-hi); border-bottom-color: var(--accent-hi); }

/* ── terminal blocks ─────────────────────────────────────────────────────── */
.term { background: var(--surface); border: 1px solid var(--edge); border-radius: 6px; padding: 22px 24px; box-shadow: var(--shadow); }
/* Base for every code block. Diagram <pre>s that must not wrap keep an inline
   `white-space: pre; overflow-x: auto` and win on specificity. */
.term pre, .page pre {
  margin: 0; font-family: 'IBM Plex Mono', monospace;
  font-size: clamp(12px, 1.6vw, 14.5px); line-height: 1.9; color: var(--ink-code);
  white-space: pre-wrap; word-break: break-word;
}

/* ── disclosure ──────────────────────────────────────────────────────────── */
.disc { margin-top: 14px; }
.disc > summary {
  font-family: 'IBM Plex Mono', monospace; font-size: 14px; letter-spacing: 0.06em;
  color: var(--accent); cursor: pointer; list-style: none;
  -webkit-user-select: none; user-select: none;
}
summary::-webkit-details-marker { display: none; }
summary::marker { content: ''; }
summary:hover { color: var(--accent-hi); }
details[open] > summary { color: var(--accent-hi); }
.disc-body { margin-top: 12px; }

/* ── footer ──────────────────────────────────────────────────────────────── */
.site-foot {
  padding: 28px 0 40px; border-top: 1px solid var(--rule);
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
}
.foot-copy { font-size: 13.5px; color: var(--ink-dim); }
.foot-mark { display: flex; align-items: center; gap: 10px; color: var(--ink-dim); }
.foot-thai { font-size: 12.5px; color: var(--ink-faint); }
.foot-dot { fill: var(--accent); }

/* ── theme toggle ────────────────────────────────────────────────────────── */
.theme-toggle {
  position: fixed; top: 16px; right: 16px; z-index: 20;
  display: inline-flex; align-items: center; gap: 7px;
  font-family: 'IBM Plex Mono', monospace; font-size: 12px; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--ink-dim);
  background: var(--ground); border: 1px solid var(--rule); border-radius: 5px;
  padding: 6px 11px; cursor: pointer; line-height: 1;
  transition: color .12s ease, border-color .12s ease;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--edge); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-toggle svg { width: 13px; height: 13px; flex: 0 0 auto; }
/* the button advertises the theme you will get, not the one you are in */
.theme-toggle .t-moon, .theme-toggle .t-dark { display: none; }
:root[data-theme="light"] .theme-toggle .t-moon,
:root[data-theme="light"] .theme-toggle .t-dark { display: inline; }
:root[data-theme="light"] .theme-toggle .t-sun,
:root[data-theme="light"] .theme-toggle .t-light { display: none; }
@media (max-width: 640px) {
  .theme-toggle { top: 10px; right: 10px; padding: 6px 9px; }
  .theme-toggle .t-light, .theme-toggle .t-dark { display: none !important; }
}
@media print { .theme-toggle { display: none; } }

/* ── bench: figure & table ───────────────────────────────────────────────── */
.fig { background: var(--surface); border: 1px solid var(--edge); border-radius: 6px; padding: 24px 26px 20px; margin: 28px 0 0; box-shadow: var(--shadow); }
.fig-t { font-family: 'Schibsted Grotesk', sans-serif; font-weight: 600; font-size: 16px; color: var(--ink); margin: 0 0 4px; }
.fig-s { font-size: 13px; color: var(--ink-dim); margin: 0 0 20px; line-height: 1.55; max-width: 52em; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 20px; margin: 0 0 22px; font-size: 12.5px; color: var(--ink-muted); }
.legend span { display: inline-flex; align-items: center; gap: 8px; }
.sw { width: 11px; height: 11px; border-radius: 2px; flex: 0 0 auto; }
.sw-mark { background: var(--chart-mark); }
.sw-ctx  { background: var(--chart-ctx); }
.panels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; }
@media (max-width: 720px) { .panels { grid-template-columns: 1fr; gap: 24px; } }
.panel h4 { font-family: 'IBM Plex Mono', monospace; font-weight: 500; font-size: 12px; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-code); margin: 0 0 3px; }
.panel .ax { font-size: 11.5px; color: var(--ink-dim); margin: 0 0 14px; padding-bottom: 8px; border-bottom: 1px solid var(--rule); }
.bars { display: flex; flex-direction: column; gap: 2px; }
.brow { padding: 3px 0; }
.blab { font-family: 'IBM Plex Mono', monospace; font-size: 11.5px; color: var(--ink-muted); margin: 0 0 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btrack { display: flex; align-items: center; gap: 8px; }
.bar { height: 10px; border-radius: 0 3px 3px 0; min-width: 2px; background: var(--chart-ctx); }
.bar-mark { background: var(--chart-mark); }
.bval { font-family: 'IBM Plex Mono', monospace; font-size: 11.5px; color: var(--ink-muted); white-space: nowrap; flex: 0 0 auto; }
.base { height: 1px; background: var(--edge); margin-top: 10px; }

.tw { overflow-x: auto; margin: 26px 0 0; -webkit-overflow-scrolling: touch; }
table.m { border-collapse: collapse; width: 100%; font-size: 13.5px; min-width: 520px; font-family: 'IBM Plex Mono', monospace; }
table.m caption { text-align: left; font-family: 'IBM Plex Sans', sans-serif; font-size: 13px; color: var(--ink-dim); padding: 0 0 12px; line-height: 1.55; }
table.m th, table.m td { text-align: right; padding: 9px 8px; border-bottom: 1px solid var(--rule); white-space: nowrap; }
table.m th:first-child, table.m td:first-child { text-align: left; padding-left: 0; }
table.m th:last-child, table.m td:last-child { padding-right: 0; }
table.m thead th { font-size: 11px; font-weight: 400; color: var(--ink-dim); text-transform: uppercase; letter-spacing: .08em; border-bottom: 1px solid var(--edge); }
table.m tbody tr:last-child td { border-bottom: none; }
table.m td { color: var(--ink-code); }
.mark { display: block; font-family: 'IBM Plex Sans', sans-serif; font-size: 11.5px; margin: 2px 0 0 17px; white-space: normal; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 9px; vertical-align: baseline; background: var(--chart-ctx); }
.dot-mark { background: var(--chart-mark); }

.tag {
  font-family: 'IBM Plex Mono', monospace; font-size: 11.5px; letter-spacing: .08em;
  text-transform: uppercase; color: var(--accent); border: 1px solid var(--accent-edge);
  border-radius: 3px; padding: 1px 7px; margin-left: 9px; vertical-align: 2px; white-space: nowrap;
}
.tag-dim { color: var(--ink-dim); border-color: var(--edge); }
