/* Systems Atlas: tokens, typography, page furniture and shared controls. */

:root {
  --bg: #F6F0E5;
  --paper: #FBF7EF;
  --panel: #EFE7D9;
  --ink: #16120F;
  --ink-2: #3B342D;
  --muted: #675E54;
  --line: #CFC3B1;
  --grid: #E3D8C6;
  --accent: #E0400C;
  --accent-text: #B33206;
  --accent-wash: rgba(224, 64, 12, 0.08);
  --on-ink: #F6F0E5;

  --display: "Helvetica Neue", "Inter", "Arial Nova", Arial, sans-serif;
  --serif: "Iowan Old Style", "Charter", "Source Serif Pro", Georgia, serif;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;

  --gutter: clamp(16px, 3vw, 40px);
  --masthead-h: 64px;
  --ease: cubic-bezier(0.2, 0.7, 0.1, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12100E;
    --paper: #181512;
    --panel: #1D1916;
    --ink: #F4EDE1;
    --ink-2: #D9CFC2;
    --muted: #A1978C;
    --line: #3A332C;
    --grid: #262019;
    --accent: #FF5A1F;
    --accent-text: #FF7A45;
    --accent-wash: rgba(255, 90, 31, 0.1);
    --on-ink: #12100E;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #12100E;
  --paper: #181512;
  --panel: #1D1916;
  --ink: #F4EDE1;
  --ink-2: #D9CFC2;
  --muted: #A1978C;
  --line: #3A332C;
  --grid: #262019;
  --accent: #FF5A1F;
  --accent-text: #FF7A45;
  --accent-wash: rgba(255, 90, 31, 0.1);
  --on-ink: #12100E;
  color-scheme: dark;
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--masthead-h) + 16px);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--display);
  font-size: 1rem;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, ol, ul, dl, dd, figure, fieldset { margin: 0; padding: 0; }
ol, ul { list-style: none; }
fieldset { border: 0; min-width: 0; }
img, svg { display: block; max-width: 100%; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

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

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
[tabindex="-1"]:focus:not(:focus-visible) { outline: none; }

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

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

.field-label {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.skip-link {
  position: absolute; left: var(--gutter); top: -100px; z-index: 100;
  background: var(--ink); color: var(--on-ink); padding: 0.6rem 0.9rem; font-family: var(--mono); font-size: 0.8rem;
}
.skip-link:focus { top: 12px; }

html:not(.js) .js-only { display: none; }

/* Masthead */

.masthead {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1.5rem;
  min-height: 64px;
  padding: 0.6rem var(--gutter);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: baseline; gap: 0.6rem; text-decoration: none; white-space: nowrap; }
.brand-mark { width: 12px; height: 12px; background: var(--accent); align-self: center; }
.brand-name { font-weight: 800; letter-spacing: -0.01em; }
.brand-sub { font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }

.sections-nav { display: flex; gap: 1.25rem; margin-left: auto; }
.sections-nav a {
  font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase;
  text-decoration: none; color: var(--ink-2); padding: 0.4rem 0;
}
.sections-nav a:hover { color: var(--accent-text); box-shadow: inset 0 -2px 0 var(--accent); }

.prefs { display: flex; align-items: center; gap: 0.9rem; }

/* Segmented radio groups (theme, motion) */

.segmented { display: flex; align-items: center; }
.segmented legend {
  float: left; margin-right: 0.45rem;
  font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted);
}
.segmented input, .chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segmented label {
  padding: 0.3rem 0.55rem;
  border: 1px solid var(--line);
  margin-left: -1px;
  font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.06em;
  cursor: pointer; user-select: none;
}
.segmented label:hover { border-color: var(--ink-2); position: relative; }
.segmented input:checked + label { background: var(--ink); color: var(--on-ink); border-color: var(--ink); position: relative; }
.segmented input:focus-visible + label, .chip input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; position: relative; z-index: 1; }

.palette-trigger {
  display: inline-flex; align-items: center; gap: 0.5rem;
  border: 1px solid var(--ink); background: transparent;
  padding: 0.3rem 0.4rem 0.3rem 0.7rem;
  font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase;
}
.palette-trigger:hover { background: var(--ink); color: var(--on-ink); }
kbd {
  font-family: var(--mono); font-size: 0.65rem; padding: 0.1rem 0.35rem;
  border: 1px solid currentColor; opacity: 0.75;
}

/* Chips (domain filter, lab capability) */

.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chips legend { width: 100%; margin-bottom: 0.5rem; }
.chip label {
  display: inline-block;
  padding: 0.28rem 0.55rem;
  border: 1px solid var(--line);
  font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.04em;
  cursor: pointer; user-select: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chip label:hover { border-color: var(--ink); }
.chip input:checked + label { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }

.text-button {
  border: 0; background: none; padding: 0;
  font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--accent-text); text-decoration: underline; text-underline-offset: 0.25em;
}

/* Section heads shared by lab, research, contact */

.section-head {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.5rem;
  padding-top: 1.25rem; border-top: 2px solid var(--ink);
  margin-bottom: clamp(1.5rem, 3vw, 2.5rem);
}
.section-title {
  font-size: clamp(2.4rem, 6.5vw, 5.5rem);
  font-weight: 800; letter-spacing: -0.045em; line-height: 0.9;
}

.noscript-note { font-family: var(--serif); font-size: 1.05rem; color: var(--ink-2); padding: 1rem 0; }

/* Colophon */

.colophon {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1rem;
  margin: 0 var(--gutter); padding: 1.5rem 0 2.5rem;
  border-top: 1px solid var(--line);
  font-family: var(--mono); font-size: 0.75rem; color: var(--muted);
}

/* Command palette */

.palette {
  width: min(560px, calc(100vw - 32px));
  margin: 12vh auto auto;
  padding: 0; border: 1px solid var(--ink);
  background: var(--paper); color: var(--ink);
  box-shadow: 12px 12px 0 var(--accent);
}
.palette::backdrop { background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(3px); }
.palette-input {
  width: 100%; padding: 1rem 1.1rem;
  border: 0; border-bottom: 1px solid var(--line); background: transparent;
  font-size: 1.1rem;
}
.palette-input:focus { outline: none; box-shadow: inset 0 -2px 0 var(--accent); }
.palette-list { max-height: min(52vh, 420px); overflow-y: auto; padding: 0.35rem 0; }
.palette-option {
  display: grid; grid-template-columns: 6.5rem minmax(0, 1fr); gap: 0.75rem; align-items: baseline;
  padding: 0.55rem 1.1rem; cursor: pointer;
}
.palette-option[aria-selected="true"] { background: var(--ink); color: var(--on-ink); }
.palette-option[aria-selected="true"] .palette-group { color: inherit; opacity: 0.7; }
.palette-group { font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.palette-label { font-weight: 600; white-space: pre; overflow: hidden; text-overflow: ellipsis; }
.palette-empty { padding: 0.8rem 1.1rem; color: var(--muted); }
.palette-hint { padding: 0.6rem 1.1rem; border-top: 1px solid var(--line); font-family: var(--mono); font-size: 0.66rem; color: var(--muted); letter-spacing: 0.06em; }

/* Motion preferences: "off" always wins; "auto" defers to the OS setting. */

:root[data-motion="off"] *, :root[data-motion="off"] *::before, :root[data-motion="off"] *::after {
  animation: none !important;
  transition-duration: 0s !important;
}
:root[data-motion="off"] { scroll-behavior: auto; }

@media (prefers-reduced-motion: reduce) {
  :root *, :root *::before, :root *::after {
    animation: none !important;
    transition-duration: 0s !important;
  }
  :root { scroll-behavior: auto; }
}

/* Masthead responsiveness */

@media (max-width: 1080px) {
  .masthead { flex-wrap: wrap; row-gap: 0.5rem; }
  .sections-nav { order: 3; width: 100%; margin-left: 0; overflow-x: auto; }
  .prefs { margin-left: auto; }
}

@media (max-width: 640px) {
  html { scroll-padding-top: 12px; }
  .masthead { position: static; }
  .brand-sub { display: none; }
  .prefs { width: 100%; margin-left: 0; flex-wrap: wrap; gap: 0.6rem; }
  .palette-trigger kbd { display: none; }
  .segmented legend { margin-right: 0.35rem; font-size: 0.62rem; }
  .segmented label { padding: 0.25rem 0.4rem; }
  .sections-nav { gap: 1rem; }
}
