/* ============================================================================
   Shared design system — "instrument"
   Loaded by every page before the page's own stylesheet.

   Dark is the default. Light is opt-in via prefers-color-scheme: light, so a
   visitor whose OS asks for light gets light, and everyone else gets dark.

   Each tool sets only --accent / --accent-dim in its own stylesheet.
   Everything structural lives here.
   ========================================================================= */

:root {
  /* Tells the browser to theme native controls — radios, checkboxes, select
     popups, scrollbars, date pickers. Without it Chrome paints unchecked
     radios as bright white discs on the dark panel, and native date pickers
     render dark-on-dark. */
  color-scheme: dark;

  /* -- palette: dark (default) ------------------------------------------ */
  --bg:            #0e1116;
  --bg-sunk:       #0a0c10;
  --surface:       #161a21;
  --surface-2:     #1c212a;
  --line:          rgba(255, 255, 255, 0.09);
  --line-strong:   rgba(255, 255, 255, 0.38);   /* 3.55:1 — input borders, 1.4.11 */
  --text:          #e7eaf0;
  --text-dim:      #a2acbb;
  /* --text-faint carries .eyebrow / .field-label / legend / th, all of which
     are small text and so need 4.5:1, not 3:1. 5.68:1 on --surface. */
  --text-faint:    #8a94a2;

  --ok:            #4ade80;
  --ok-bg:         rgba(74, 222, 128, 0.11);
  --warn:          #fbbf24;
  --warn-bg:       rgba(251, 191, 36, 0.11);
  --err:           #fb7185;
  --err-bg:        rgba(251, 113, 133, 0.11);

  /* fallback accent; each tool overrides these two */
  --accent:        #8ea2c4;
  --accent-dim:    rgba(142, 162, 196, 0.14);
  --on-accent:     #0e1116;

  /* -- type ------------------------------------------------------------- */
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
          Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", "Cascadia Mono",
          "JetBrains Mono", "Roboto Mono", Menlo, Consolas, monospace;

  /* -- metrics ---------------------------------------------------------- */
  --maxw: 68rem;
  --gut: clamp(1rem, 4vw, 2rem);
  --radius: 10px;
  --radius-sm: 6px;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg:          #fbfaf8;
    --bg-sunk:     #f2f0ec;
    --surface:     #ffffff;
    --surface-2:   #f6f5f2;
    --line:        rgba(18, 22, 28, 0.11);
    --line-strong: rgba(18, 22, 28, 0.50);     /* 3.2:1 — input borders, 1.4.11 */
    --text:        #161a20;
    --text-dim:    #545c68;
    --text-faint:  #646d7a;      /* 5.24:1 on white — small-text AA */

    --ok:   #15803d;  --ok-bg:   rgba(21, 128, 61, 0.09);
    --warn: #a35709;  --warn-bg: rgba(163, 87, 9, 0.09);
    --err:  #be123c;  --err-bg:  rgba(190, 18, 60, 0.08);

    --on-accent: #ffffff;
  }
}

/* ------------------------------------------------------ page transitions -- */
/* Cross-document view transitions. This is a multi-page site with no client
   router, so every click is a real navigation — that stays true. What this
   removes is the white flash between pages: the browser snapshots the old
   document and the new one and crossfades them, so navigation reads as
   continuous rather than as a reload.

   Pure CSS, no JavaScript, so it does not touch the CSP. Progressive
   enhancement: Chrome/Edge 126+ and Safari 18.2+ animate, everything else
   navigates exactly as before. It does not make loading faster — caching did
   that — it makes the load stop being visible. */

@view-transition { navigation: auto; }

/* The header is identical on every page, so crossfading it makes a fixed
   element appear to flicker. Naming it hands the browser the same element on
   both sides of the navigation, and it stays put while the content changes. */
.site-header { view-transition-name: site-header; }

@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
}

/* ---------------------------------------------------------------- reset -- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

:where(a) { color: var(--accent); text-underline-offset: 0.18em; }
:where(a:hover) { text-decoration-thickness: 2px; }

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

::selection { background: var(--accent); color: var(--on-accent); }

.wrap { width: 100%; max-width: var(--maxw); margin-inline: auto; padding-inline: var(--gut); }

.skip-link {
  position: absolute; left: -9999px;
  background: var(--accent); color: var(--on-accent);
  padding: 0.6rem 1rem; border-radius: var(--radius-sm); z-index: 99;
}
.skip-link:focus { left: 1rem; top: 1rem; }

/* --------------------------------------------------------------- header -- */
/* Two rows on narrow screens rather than one wrapping row — this is what
   stops the nav colliding with the wordmark. The nav scrolls sideways
   instead of wrapping, so adding a link can never break the layout again. */

/* Solid, not translucent. A semi-transparent backdrop-filter bar under
   position: sticky is a known repaint hazard on iOS Safari and some
   Android/Chromium compositors — the sticky layer's backdrop sample can
   fail to invalidate while the page scrolls beneath it, leaving stale
   content ghosting through the header. --surface is fully opaque, so
   there is nothing behind the header to fail to repaint: no compositing
   layer sampling the page, no possible stale-pixel artifact. It's the
   same token .panel uses, so the header reads as an elevated bar rather
   than a flat cut, without the fragile mechanism. */
.site-header {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky; top: 0; z-index: 20;
}

.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 2rem;
  min-height: 3.75rem;
  flex-wrap: wrap;
}

.brand {
  display: inline-flex; align-items: center; gap: 0.6rem;
  font-family: var(--mono);
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  flex: 0 0 auto;
}
.brand:hover { color: var(--accent); }
.brand svg, .brand img { width: 1.375rem; height: 1.375rem; flex: 0 0 auto; }

.site-nav {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  font-family: var(--mono);
  font-size: 0.8125rem;
  letter-spacing: 0.01em;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  margin-inline: -0.4rem;
  padding-inline: 0.4rem;
}
.site-nav::-webkit-scrollbar { display: none; }

.site-nav a {
  color: var(--text-dim);
  text-decoration: none;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  flex: 0 0 auto;
  transition: color 0.12s ease, background-color 0.12s ease;
}
.site-nav a:hover { color: var(--text); background: var(--surface-2); }
.site-nav a[aria-current="page"] { color: var(--accent); background: var(--accent-dim); }

/* the "All tools" backlink reads as a level-up, not a sibling */
.site-nav a.nav-up { color: var(--text-faint); }
.site-nav a.nav-up::before { content: "← "; opacity: 0.7; }
.site-nav a.nav-up:hover { color: var(--text); }

/* ------------------------------------------------------------ typography -- */

/* Keeps in-page anchors (skip-link -> #main, FAQ/section deep links) from
   landing under the sticky header. 5.5rem clears the tallest header state
   (the two-row mobile layout, ~76px) with room to spare; on the one-row
   desktop header (~61px) it just leaves a bit of extra breathing room
   above the target. */
h1, h2, h3, h4, main {
  scroll-margin-top: 5.5rem;
}

h1, h2, h3, h4 {
  line-height: 1.15;
  letter-spacing: -0.022em;
  font-weight: 640;
  margin: 0 0 0.5em;
  text-wrap: balance;
}

h1 { font-size: clamp(1.75rem, 1.1rem + 2.6vw, 2.6rem); margin-bottom: 0.35em; }
h2 { font-size: clamp(1.3rem, 1.05rem + 1vw, 1.65rem); margin-top: 2.2em; }
h3 { font-size: 1.125rem; margin-top: 1.8em; letter-spacing: -0.012em; }
h4 { font-size: 0.9375rem; margin-top: 1.4em; }

p { margin: 0 0 1.1em; }
p, li { text-wrap: pretty; }

.lede {
  font-size: 1.125rem;
  color: var(--text-dim);
  max-width: 62ch;
  margin-bottom: 2em;
}

.prose { max-width: 68ch; }
.prose ul, .prose ol { padding-left: 1.25em; margin: 0 0 1.1em; }
.prose li { margin-bottom: 0.4em; }

/* the small uppercase mono label that ties the whole system together */
.eyebrow, .field-label, legend, .stat-label {
  font-family: var(--mono);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
}

code, kbd, samp, pre, .mono, .num {
  font-family: var(--mono);
  font-variant-ligatures: none;
  font-feature-settings: "tnum" 1, "zero" 1;
}

code:not(pre code) {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.1em 0.38em;
  font-size: 0.875em;
}

pre {
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  overflow-x: auto;
  font-size: 0.875rem;
  line-height: 1.6;
}

hr { border: 0; border-top: 1px solid var(--line); margin: 2.5rem 0; }

/* ------------------------------------------------------------- surfaces -- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(1rem, 3vw, 1.5rem);
}

.panel-sunk {
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(0.875rem, 2.5vw, 1.25rem);
}

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(20rem, 100%), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(15rem, 100%), 1fr)); }

/* ---------------------------------------------------------------- forms -- */
/* Selects reserve room for their own chevron. This is the fix for text
   running under the arrow — the padding-right and the background arrow are
   defined together so they cannot drift apart. */

label { display: block; }

input[type="text"], input[type="number"], input[type="date"],
input[type="time"], input[type="datetime-local"], input[type="search"],
input[type="email"], input[type="url"], textarea, select {
  width: 100%;
  min-width: 0;
  font: inherit;
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--bg-sunk);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.7rem;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

input:hover, textarea:hover, select:hover { border-color: var(--text-faint); }

input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

input::placeholder, textarea::placeholder { color: var(--text-faint); }

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2.25rem;                 /* room for the chevron */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%23a2acbb' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  background-size: 0.75rem;
  text-overflow: ellipsis;                /* graceful, never under the arrow */
}
@media (prefers-color-scheme: light) {
  select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%23545c68' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  }
}
select option { background: var(--surface); color: var(--text); }

input[type="color"] {
  padding: 0.2rem; height: 2.5rem; cursor: pointer;
  background: var(--bg-sunk);
}

/* The input rules above are (0,1,1) and beat a plain .visually-hidden (0,1,0),
   so a visually-hidden input keeps width:100% and silently blows out the page
   width while absolutely positioned. Guard it here rather than per tool. */
input.visually-hidden, input.sr-only, input.visually-hidden:focus {
  width: 1px; min-width: 0; padding: 0;
}

/* numeric/data inputs read as instrument readouts */
.input-mono, input.mono, textarea.mono {
  font-family: var(--mono);
  font-feature-settings: "tnum" 1, "zero" 1;
  letter-spacing: 0.01em;
}

.field { display: grid; gap: 0.35rem; }

/* ------------------------------------------------------------- controls -- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  font-family: var(--mono);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--on-accent);
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.95rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: filter 0.12s ease, transform 0.06s ease;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(1px); }

.btn-quiet {
  color: var(--text-dim);
  background: transparent;
  border-color: var(--line-strong);
}
.btn-quiet:hover { color: var(--text); background: var(--surface-2); filter: none; }

/* chip / preset row — used by nearly every tool */
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  font-family: var(--mono);
  font-size: 0.78125rem;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.12s ease, border-color 0.12s ease, background-color 0.12s ease;
}
.chip:hover { color: var(--text); border-color: var(--line-strong); }
.chip[aria-pressed="true"], .chip.is-active {
  color: var(--accent); border-color: var(--accent); background: var(--accent-dim);
}

/* --------------------------------------------------------------- output -- */
/* The big answer. Every tool has one; they should all look like this. */

.readout {
  font-family: var(--mono);
  font-size: clamp(1.35rem, 1rem + 1.8vw, 2rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--accent);
  overflow-wrap: anywhere;
}

.stat { display: grid; gap: 0.2rem; }
.stat-value { font-family: var(--mono); font-size: 1.25rem; font-weight: 600; }

.badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-family: var(--mono); font-size: 0.75rem; font-weight: 600;
  letter-spacing: 0.04em; text-transform: uppercase;
  border-radius: 999px; padding: 0.2rem 0.6rem;
  border: 1px solid currentColor;
}
.badge-pass { color: var(--ok);   background: var(--ok-bg); }
.badge-fail { color: var(--err);  background: var(--err-bg); }
.badge-warn { color: var(--warn); background: var(--warn-bg); }

.note {
  font-size: 0.9375rem; color: var(--text-dim);
  border-left: 2px solid var(--line-strong);
  padding-left: 0.9rem;
}
.note-err  { color: var(--err);  border-color: var(--err); }
.note-warn { color: var(--warn); border-color: var(--warn); }

/* ---------------------------------------------------------------- table -- */

.table-scroll { overflow-x: auto; margin-inline: calc(var(--gut) * -1); padding-inline: var(--gut); }

table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
th, td { text-align: left; padding: 0.55rem 0.9rem 0.55rem 0; border-bottom: 1px solid var(--line); }
th {
  font-family: var(--mono); font-size: 0.6875rem; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-faint);
  border-bottom-color: var(--line-strong);
}
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num, .tabular td { font-family: var(--mono); font-feature-settings: "tnum" 1; }

/* ----------------------------------------------------------------- FAQ --- */

details {
  border-bottom: 1px solid var(--line);
  padding: 0.9rem 0;
}
details summary {
  cursor: pointer; font-weight: 600; list-style: none;
  display: block;                 /* not flex: flex spreads inline <code> apart */
  position: relative;
  padding-right: 1.75rem;         /* room for the marker */
}
details summary::-webkit-details-marker { display: none; }
details summary::after {
  content: "+"; font-family: var(--mono); color: var(--text-faint);
  font-size: 1.1rem; line-height: 1;
  position: absolute; right: 0; top: 0.28em;
  transition: transform 0.15s ease;
}
details[open] summary::after { transform: rotate(45deg); }
details > *:not(summary) { margin-top: 0.7rem; color: var(--text-dim); }

/* --------------------------------------------------------------- footer -- */

.site-footer {
  border-top: 1px solid var(--line);
  margin-top: 4rem;
  padding: 2rem 0 3rem;
  font-size: 0.875rem;
  color: var(--text-dim);
}
.site-footer nav { display: flex; flex-wrap: wrap; gap: 0.4rem 1.2rem; margin-bottom: 0.9rem; }
.site-footer a { color: var(--text-dim); text-decoration: none; }
.site-footer a:hover { color: var(--accent); text-decoration: underline; }
.site-footer .fine { color: var(--text-faint); font-size: 0.8125rem; max-width: 60ch; }

/* --------------------------------------------------------------- layout -- */

main { padding-block: clamp(1.75rem, 5vw, 3rem); }
section { margin-bottom: 2.5rem; }

.tool-bay { margin-bottom: 2.5rem; }   /* the working tool, above the fold */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
