/* System One field guide — shared stylesheet */

:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eceef2;
  --ink: #14171c;
  --ink-2: #4a5160;
  --muted: #7c8493;
  --line: #dfe3e9;
  --line-strong: #c6ccd6;
  --accent: #0e7c86;
  --accent-ink: #ffffff;
  --accent-soft: #d9eff1;
  --data-1: #2a78d6;
  --data-1-soft: #cde2fb;
  --data-2: #eb6834;
  --data-3: #1baf7a;
  --data-4: #eda100;
  --good: #0ca30c;
  --good-text: #006300;
  --warn: #fab219;
  --warn-text: #7a5200;
  --bad: #d03b3b;
  --bad-text: #a52323;
  --code-bg: #1b1f26;
  --code-ink: #e6e9ef;
  --code-key: #8fd3ff;
  --code-str: #b5e39a;
  --code-num: #ffcf7a;
  --code-kw: #ff9ec4;
  --code-cm: #8a93a3;
  --shadow: 0 1px 2px rgba(20, 23, 28, 0.06), 0 8px 24px rgba(20, 23, 28, 0.06);
  --radius: 10px;
  --font-display: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  --font-body: "Source Sans 3", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1114;
    --surface: #171a1f;
    --surface-2: #20242b;
    --ink: #eceef2;
    --ink-2: #b7bdc8;
    --muted: #8a919d;
    --line: #2a2f37;
    --line-strong: #3a414c;
    --accent: #3fb3bd;
    --accent-ink: #08252a;
    --accent-soft: #143539;
    --data-1: #3987e5;
    --data-1-soft: #1c3d66;
    --data-2: #d95926;
    --data-3: #199e70;
    --data-4: #c98500;
    --good: #0ca30c;
    --good-text: #4fd24f;
    --warn: #fab219;
    --warn-text: #ffd36b;
    --bad: #e66767;
    --bad-text: #ff9a9a;
    --code-bg: #0b0d10;
    --code-ink: #dfe3ea;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1114;
  --surface: #171a1f;
  --surface-2: #20242b;
  --ink: #eceef2;
  --ink-2: #b7bdc8;
  --muted: #8a919d;
  --line: #2a2f37;
  --line-strong: #3a414c;
  --accent: #3fb3bd;
  --accent-ink: #08252a;
  --accent-soft: #143539;
  --data-1: #3987e5;
  --data-1-soft: #1c3d66;
  --data-2: #d95926;
  --data-3: #199e70;
  --data-4: #c98500;
  --good: #0ca30c;
  --good-text: #4fd24f;
  --warn: #fab219;
  --warn-text: #ffd36b;
  --bad: #e66767;
  --bad-text: #ff9a9a;
  --code-bg: #0b0d10;
  --code-ink: #dfe3ea;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
img, svg { max-width: 100%; }
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3, h4 { font-family: var(--font-display); text-wrap: balance; line-height: 1.15; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: clamp(2rem, 4.2vw, 3rem); font-weight: 700; }
h2 { font-size: clamp(1.45rem, 2.4vw, 1.9rem); font-weight: 650; margin-top: 3rem; }
h3 { font-size: 1.15rem; font-weight: 650; margin-top: 1.75rem; }
h4 { font-size: 1rem; font-weight: 650; margin-top: 1.25rem; }
p, ul, ol { margin: 0.9rem 0; }
ul, ol { padding-left: 1.4rem; }
li + li { margin-top: 0.35rem; }
strong { font-weight: 650; }
code, kbd, pre, .mono { font-family: var(--font-mono); }
code { font-size: 0.86em; background: var(--surface-2); padding: 0.08em 0.38em; border-radius: 5px; color: var(--ink); }
pre code { background: none; padding: 0; font-size: inherit; color: inherit; }
hr { border: 0; border-top: 1px solid var(--line); margin: 2.5rem 0; }
small, .small { font-size: 0.875rem; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
.eyebrow { font-family: var(--font-display); font-size: 0.74rem; font-weight: 650; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); }
.tabular { font-variant-numeric: tabular-nums; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 1fr; min-height: 100vh; }
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar .brand { font-family: var(--font-display); font-weight: 700; font-size: 1rem; color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 26px; height: 26px; flex: none; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn {
  appearance: none; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  width: 38px; height: 38px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.rail {
  display: none; background: var(--surface); border-right: 1px solid var(--line);
  padding: 20px 18px 40px; overflow-y: auto;
}
.rail.open { display: block; position: fixed; inset: 58px 0 0 0; z-index: 39; }
.rail .brand { display: none; }
.rail nav { margin-top: 6px; }
.rail .nav-title { font-family: var(--font-display); font-size: 0.72rem; font-weight: 650; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin: 18px 0 8px; }
.rail a.page-link { display: block; padding: 7px 10px; border-radius: 8px; color: var(--ink-2); text-decoration: none; font-size: 0.95rem; }
.rail a.page-link:hover { background: var(--surface-2); color: var(--ink); }
.rail a.page-link.active { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.rail a.page-link .n { display: inline-block; width: 1.6em; font-family: var(--font-mono); font-size: 0.75rem; color: var(--muted); }
.rail .toc a { display: block; padding: 4px 10px 4px 22px; font-size: 0.86rem; color: var(--muted); text-decoration: none; border-left: 2px solid var(--line); margin-left: 12px; }
.rail .toc a:hover { color: var(--ink); border-left-color: var(--accent); }
.rail .toc a.current { color: var(--accent); border-left-color: var(--accent); }
.main { min-width: 0; }
.page { max-width: 880px; margin: 0 auto; padding-block: 28px 80px; padding-inline: 16px; }
.page-head { padding: 24px 0 8px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.page-head .lede { font-size: 1.22rem; color: var(--ink-2); max-width: 64ch; margin: 1rem 0 1.2rem; text-wrap: pretty; }
.prose { max-width: 70ch; }
.prose > p, .prose > ul, .prose > ol { max-width: 70ch; }

@media (min-width: 1024px) {
  .shell { grid-template-columns: 272px 1fr; }
  .topbar { display: none; }
  .rail { display: block; position: sticky; top: 0; height: 100vh; }
  .rail .brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 700; color: var(--ink); text-decoration: none; margin-bottom: 4px; }
  .rail .rail-actions { display: flex; justify-content: flex-start; margin-top: 12px; }
  .page { padding-inline: 48px; }
}

/* ---------- content blocks ---------- */
.callout { border: 1px solid var(--line); border-left: 4px solid var(--accent); background: var(--surface); border-radius: var(--radius); padding: 14px 18px; margin: 1.4rem 0; }
.callout.warn { border-left-color: var(--warn); }
.callout.bad { border-left-color: var(--bad); }
.callout.good { border-left-color: var(--good); }
.callout > :first-child { margin-top: 0; }
.callout > :last-child { margin-bottom: 0; }
.callout .label { font-family: var(--font-display); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); display: block; margin-bottom: 4px; }

.grid-2, .grid-3 { display: grid; gap: 14px; margin: 1.4rem 0; grid-template-columns: 1fr; }
@media (min-width: 680px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3 { grid-template-columns: repeat(3, 1fr); } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.card h3, .card h4 { margin-top: 0; }
.card p:last-child { margin-bottom: 0; }
.card .eyebrow { display: block; margin-bottom: 6px; }
.card.link { text-decoration: none; color: inherit; display: block; transition: border-color 120ms; }
.card.link:hover { border-color: var(--accent); }

.pill { display: inline-block; font-family: var(--font-mono); font-size: 0.74rem; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--ink-2); background: var(--surface); white-space: nowrap; }
.pill.choice { border-color: var(--data-1); color: var(--data-1); }
.pill.score { border-color: var(--data-2); color: var(--data-2); }
.pill.noul { border-color: var(--data-3); color: var(--data-3); }
.pill.code { border-color: var(--muted); }
.pill.good { border-color: var(--good); color: var(--good-text); }
.pill.warn { border-color: var(--warn); color: var(--warn-text); }
.pill.bad { border-color: var(--bad); color: var(--bad-text); }

.table-wrap { overflow-x: auto; margin: 1.2rem 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-family: var(--font-display); font-size: 0.78rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 650; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--font-mono); font-size: 0.86rem; }

/* code */
pre.code { background: var(--code-bg); color: var(--code-ink); border-radius: var(--radius); padding: 14px 16px; overflow-x: auto; font-size: 0.82rem; line-height: 1.55; margin: 1rem 0; position: relative; tab-size: 2; }
pre.code[data-title]::before { content: attr(data-title); display: block; font-family: var(--font-display); font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--code-cm); margin-bottom: 8px; }
.tok-key { color: var(--code-key); }
.tok-str { color: var(--code-str); }
.tok-num { color: var(--code-num); }
.tok-kw { color: var(--code-kw); }
.tok-cm { color: var(--code-cm); font-style: italic; }
.tabs { margin: 1rem 0; }
.tab-row { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.tab-row button { appearance: none; background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; padding: 8px 12px; font: inherit; font-family: var(--font-display); font-weight: 600; font-size: 0.86rem; color: var(--muted); cursor: pointer; }
.tab-row button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.tabs [data-panel] { margin-top: 0; }
.tabs [data-panel] pre.code { margin-top: 10px; }

/* labs */
.lab { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); margin: 1.8rem 0; overflow: hidden; }
.lab-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.lab-head .eyebrow { color: var(--data-2); }
.lab-head h3 { margin: 0; font-size: 1.05rem; }
.lab-head .hint { color: var(--muted); font-size: 0.88rem; flex-basis: 100%; }
.lab-body { padding: 16px 18px 18px; }
.lab-body > :first-child { margin-top: 0; }
.lab-note { font-size: 0.84rem; color: var(--muted); border-top: 1px dashed var(--line); margin-top: 14px; padding-top: 10px; }
.lab-grid { display: grid; gap: 18px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .lab-grid { grid-template-columns: 1fr 1fr; } .lab-grid.wide-right { grid-template-columns: 5fr 7fr; } .lab-grid.wide-left { grid-template-columns: 7fr 5fr; } }
.lab-col > :first-child { margin-top: 0; }
.lab-title { font-family: var(--font-display); font-weight: 650; font-size: 0.86rem; color: var(--ink-2); margin: 0 0 8px; letter-spacing: 0.02em; }

/* controls */
.btn { appearance: none; font: inherit; font-family: var(--font-display); font-weight: 600; font-size: 0.9rem; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); cursor: pointer; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); color: var(--accent-ink); }
.btn.small { padding: 5px 10px; font-size: 0.8rem; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 10px; }
.seg button { appearance: none; border: 0; background: transparent; color: var(--ink-2); font: inherit; font-family: var(--font-display); font-weight: 600; font-size: 0.84rem; padding: 6px 12px; border-radius: 7px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,0.12); }
.field { display: grid; gap: 4px; margin: 8px 0; }
.field label { font-family: var(--font-display); font-size: 0.8rem; font-weight: 600; color: var(--ink-2); }
.field input[type="text"], .field textarea, .field select { font: inherit; font-size: 0.95rem; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--ink); width: 100%; }
.field textarea { font-family: var(--font-mono); font-size: 0.82rem; min-height: 80px; resize: vertical; }
input[type="range"] { width: 100%; accent-color: var(--accent); margin: 4px 0; }
.slider-row { display: grid; grid-template-columns: minmax(112px, 1.2fr) 3fr 56px; gap: 10px; align-items: center; margin: 6px 0; }
.slider-row .lbl { font-size: 0.88rem; line-height: 1.2; color: var(--ink-2); overflow-wrap: break-word; }
.slider-row .val { font-family: var(--font-mono); font-size: 0.82rem; text-align: right; font-variant-numeric: tabular-nums; }

/* probability bars */
.bars { display: grid; gap: 7px; margin: 8px 0; }
.bar-row { display: grid; grid-template-columns: minmax(96px, 1.1fr) 3fr 52px; gap: 10px; align-items: center; }
.bar-label { font-size: 0.88rem; line-height: 1.2; color: var(--ink-2); overflow-wrap: break-word; }
.bar-label.hi { color: var(--ink); font-weight: 600; }
.bar-track { height: 14px; background: var(--surface-2); border-radius: 4px; overflow: hidden; position: relative; }
.bar-fill { height: 100%; background: var(--data-1); border-radius: 0 4px 4px 0; transition: width 160ms ease-out; min-width: 0; }
.bar-fill.dim { background: var(--data-1-soft); }
.bar-fill.c2 { background: var(--data-2); }
.bar-fill.c3 { background: var(--data-3); }
.bar-value { font-family: var(--font-mono); font-size: 0.8rem; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.bar-value.hi { color: var(--ink); font-weight: 600; }

/* stat tiles */
.stats { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin: 10px 0; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.stat .k { font-family: var(--font-display); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.stat .v { font-family: var(--font-mono); font-size: 1.35rem; font-weight: 600; line-height: 1.2; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 0.8rem; color: var(--muted); }
.stat.good .v { color: var(--good-text); }
.stat.warn .v { color: var(--warn-text); }
.stat.bad .v { color: var(--bad-text); }

/* answer object rendering */
.answer { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--surface); margin: 8px 0; }
.answer .id { font-family: var(--font-mono); font-size: 0.8rem; color: var(--muted); display: flex; justify-content: space-between; gap: 6px 12px; align-items: center; flex-wrap: wrap; }
.answer .id b { color: var(--ink); font-weight: 600; }

/* compare panes */
.compare { display: grid; gap: 14px; grid-template-columns: 1fr; margin: 1.2rem 0; }
@media (min-width: 720px) { .compare { grid-template-columns: 1fr 1fr; } }
.pane { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 12px 14px; }
.pane .pane-title { font-family: var(--font-display); font-weight: 650; font-size: 0.85rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.pane.bad .pane-title { color: var(--bad-text); }
.pane.good .pane-title { color: var(--good-text); }
.pane pre.code { margin: 8px 0; }


/* grid children must be allowed to shrink below their content width, or a long code line widens the column */
.compare > .pane, .lab-grid > .lab-col, .grid-2 > *, .grid-3 > *, .lab-body, .lab, .page,
.page [class*="grid"] > *, .page .card, .page .pane, .page .lab-col, .page .answer, .page .quiz-item { min-width: 0; }
pre.code { max-width: 100%; }

/* diagrams */
.diagram { margin: 1.2rem 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; overflow-x: auto; }
.diagram svg { display: block; width: 100%; height: auto; font-family: var(--font-display); }
.diagram .box { fill: var(--surface-2); stroke: var(--line-strong); }
.diagram .box.model { fill: var(--accent-soft); stroke: var(--accent); }
.diagram .box.code { fill: var(--surface-2); stroke: var(--ink-2); }
.diagram .box.human { fill: var(--surface); stroke: var(--data-2); stroke-dasharray: 4 3; }
.diagram text { fill: var(--ink); font-size: 13px; }
.diagram text.small { font-size: 11px; fill: var(--muted); }
.diagram .arrow { stroke: var(--ink-2); fill: none; stroke-width: 1.6; marker-end: url(#arr); }
.diagram .arrow.dashed { stroke-dasharray: 5 4; }

/* checklist / quiz */
.quiz-item { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin: 8px 0; background: var(--surface); }
.quiz-item .q { font-weight: 600; }
.quiz-item .opts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.quiz-item .why { margin-top: 8px; font-size: 0.9rem; color: var(--ink-2); border-top: 1px dashed var(--line); padding-top: 8px; }
.quiz-item.right { border-color: var(--good); }
.quiz-item.wrong { border-color: var(--bad); }

/* page footer */
.page-foot { margin-top: 3.5rem; border-top: 1px solid var(--line); padding-top: 1.4rem; }
.pager { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.pager a { text-decoration: none; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; color: var(--ink); background: var(--surface); flex: 1 1 200px; }
.pager a:hover { border-color: var(--accent); }
.pager a .k { display: block; font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); font-family: var(--font-display); }
.pager a.next { text-align: right; }
.refs { margin-top: 1.4rem; font-size: 0.9rem; color: var(--ink-2); }
.refs ul { padding-left: 1.2rem; }
.colophon { margin-top: 2rem; font-size: 0.8rem; color: var(--muted); }

.skip { position: absolute; left: -9999px; }
.skip:focus { left: 16px; top: 16px; background: var(--surface); padding: 8px 12px; z-index: 100; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
