/* =====================================================================
   RULED SHEET — the locked CIRCLE style, as a drop-in stylesheet
   ---------------------------------------------------------------------
   Drop this file into any app. It supplies:
     1. tokens (colour, type, rule) with the three-state theme
     2. base typography roles
     3. the ruled-sheet layout primitives
     4. the components the guide names
   Fonts: put Grand Haven + Ingram Mono woff2 in ./fonts/ (licensed).
   Until then the stand-ins (Fraunces, Geist Mono) load from Google Fonts
   if you include the <link> from STYLE-GUIDE.md §2, else system fallbacks.
   ===================================================================== */

/* ---------- 0. Fonts (licensed files first, stand-ins after) ---------- */
@font-face { font-family: 'Grand Haven'; src: url('fonts/GrandHaven.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Ingram Mono'; src: url('fonts/IngramMono-Regular.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Ingram Mono'; src: url('fonts/IngramMono-Medium.woff2') format('woff2'); font-weight: 500; font-display: swap; }

/* ---------- 1. Tokens ---------- */
:root {
  /* the four colours, exactly */
  --paper:      #F6F5EA;                 /* Light Mode Primary */
  --paper-2:    #FFFCDF;                 /* Secondary: tinted cell, hover, locked */
  --ink:        #23263C;                 /* Dark Mode Primary, used as ink by day */
  --active:     #DF642F;                 /* Active Color: one thing per screen */
  /* derived tints, never new hues */
  --ink-soft:   rgba(35, 38, 60, 0.70);  /* labels, ticks, secondary text */
  --ink-faint:  rgba(35, 38, 60, 0.22);  /* inner hairlines, grid lines */
  --active-ink: #F6F5EA;                 /* text on active */

  --display: 'Grand Haven', 'Fraunces', 'Constantia', Georgia, serif;
  --mono:    'Ingram Mono', 'Geist Mono', 'Consolas', 'Menlo', monospace;

  --rule: 1px solid var(--ink);
  --rule-faint: 1px solid var(--ink-faint);
  --radius-frame: 14px;                  /* outer frames only; inner cells are square */
  --gutter: 18px;                        /* inner padding of a cell */
  --label-track: 0.09em;

  --t-label: 10.5px;  --t-body: 13.5px;  --t-sub-s: 16px;  --t-sub: 24px;
  --t-mid: 64px;      --t-big: 96px;     --t-title: clamp(38px, 5.5vw, 64px);
  --t-wordmark: clamp(88px, 15vw, 176px);

  --motion: 240ms;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #23263C; --paper-2: #2A2E48; --ink: #F6F5EA;
    --ink-soft: rgba(246, 245, 234, 0.70); --ink-faint: rgba(246, 245, 234, 0.22);
    --active: #DF642F; --active-ink: #F6F5EA;
  }
}
:root[data-theme="dark"] {
  --paper: #23263C; --paper-2: #2A2E48; --ink: #F6F5EA;
  --ink-soft: rgba(246, 245, 234, 0.70); --ink-faint: rgba(246, 245, 234, 0.22);
  --active: #DF642F; --active-ink: #F6F5EA;
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--mono); font-size: var(--t-body); line-height: 1.65;
  -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums;
}
a { color: inherit; }
::selection { background: var(--active); color: var(--active-ink); }
:focus-visible { outline: 2px solid var(--active); outline-offset: 2px; }
p { margin: 0 0 0.9em; max-width: 66ch; }
p:last-child { margin-bottom: 0; }
strong { font-weight: 500; }
code { font-family: var(--mono); font-size: 0.95em; background: var(--paper-2); padding: 0 0.3em; border: var(--rule-faint); }
input, button, textarea, select { font: inherit; color: inherit; }

/* ---------- 3. Type roles ---------- */
.display {                      /* Title Big / Sub Title Big 2 */
  font-family: var(--display); font-weight: 500; text-transform: uppercase;
  letter-spacing: -0.01em; line-height: 0.92; text-wrap: balance;
  font-variation-settings: "opsz" 144, "SOFT" 50, "WONK" 1;   /* stand-in axes; ignored by Grand Haven */
}
.display.sub { font-size: 30px; font-variation-settings: "opsz" 72, "SOFT" 50, "WONK" 1; line-height: 1; }
.wordmark { font-size: var(--t-wordmark); margin: 0; }
.label {                        /* every small caption */
  font-size: var(--t-label); letter-spacing: var(--label-track); text-transform: uppercase;
  color: var(--ink-soft); font-weight: 500;
}
.label.strong { color: var(--ink); }
.num {                          /* Big Number / Mid Number */
  font-family: var(--mono); font-weight: 500; font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em; line-height: 0.9; font-size: var(--t-big);
}
.num.mid { font-size: var(--t-mid); }
.sub { font-size: var(--t-sub); font-weight: 500; line-height: 1.2; text-transform: uppercase; letter-spacing: 0.02em; }
.sub.small { font-size: var(--t-sub-s); text-transform: none; letter-spacing: 0; }

/* ---------- 4. Sheet, rules, boxes ---------- */
.sheet { max-width: 1180px; margin: 0 auto; padding: 28px 24px 80px; }
.rule { border-top: var(--rule); }
.box { border: var(--rule); }
.frame { border: var(--rule); border-radius: var(--radius-frame); overflow: hidden; }
.tint { background: var(--paper-2); }

/* section head: display title left, label right, one rule beneath */
.sec-head {
  display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 16px;
  padding-bottom: 10px; border-bottom: var(--rule);
}
.sec-head h1, .sec-head h2 { font-size: var(--t-title); margin: 0; }
.sec-head .label { padding-bottom: 6px; }
section + section { margin-top: 56px; }

/* ruled rows: label left, content right */
.rows { display: grid; }
.row { display: grid; grid-template-columns: 200px 1fr; gap: 20px; padding: 14px 0; border-bottom: var(--rule-faint); }
.row:last-child { border-bottom: var(--rule); }
.row > .label { padding-top: 3px; }

/* cell grid: n equal boxed cells in one ruled row (the "map" / "equipment" grid) */
.cells { display: grid; border: var(--rule); }
.cells.c4 { grid-template-columns: repeat(4, 1fr); }
.cells.c3 { grid-template-columns: repeat(3, 1fr); }
.cells.c2 { grid-template-columns: repeat(2, 1fr); }
.cells.c6 { grid-template-columns: repeat(6, 1fr); }
.cells.attach { border-top: none; }           /* sits directly under a .sec-head */
.cell { padding: 22px var(--gutter) 18px; border-right: var(--rule); display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.cell:last-child { border-right: none; }
.cell .foot { margin-top: auto; padding-top: 12px; border-top: var(--rule-faint); display: flex; justify-content: space-between; }

/* two-column intro under the masthead */
.intro { display: grid; grid-template-columns: 1fr 1fr; border-bottom: var(--rule); }
.intro > div { padding: 18px 20px 20px 0; }
.intro > div + div { border-left: var(--rule); padding-left: 20px; padding-right: 0; }

/* ---------- 5. Masthead + nav ---------- */
.masthead { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 24px; padding-bottom: 18px; border-bottom: var(--rule); }
.masthead-meta { display: grid; gap: 4px; justify-items: end; text-align: right; padding-bottom: 10px; }
.appbar { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 24px; border: var(--rule); padding: 10px var(--gutter); }
.appbar .brand { font-weight: 500; font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; }
.appbar nav { display: flex; gap: 22px; justify-content: flex-end; }
.appbar nav a { text-decoration: none; font-size: var(--t-label); letter-spacing: var(--label-track); text-transform: uppercase; color: var(--ink-soft); }
.appbar nav a[aria-current="page"] { color: var(--ink); border-bottom: 1px solid var(--ink); }

/* ---------- 6. Log entry (the header block with big numbers) ---------- */
.entry { border: var(--rule); display: grid; grid-template-columns: 1fr 2fr; }
.entry > .cell + .cell { border-left: var(--rule); border-right: none; text-align: right; }
.entry .title { font-size: clamp(44px, 7vw, 92px); margin-top: 6px; }
.metrics { display: grid; border: var(--rule); border-top: none; }
.metrics.col { grid-template-rows: repeat(4, 1fr); }
.metric { padding: 16px var(--gutter) 14px; border-bottom: var(--rule); display: grid; align-content: end; gap: 6px; }
.metric:last-child { border-bottom: none; }
.metric .num { font-size: 72px; }
.metric.alert .num { color: var(--active); }
.split { display: grid; grid-template-columns: 1fr 300px; border: var(--rule); border-top: none; }
.split > :first-child { border-right: var(--rule); }
.split .metrics { border: none; }

/* ---------- 7. Controls ---------- */
.btn {
  font-size: var(--t-label); letter-spacing: var(--label-track); text-transform: uppercase;
  background: var(--paper); color: var(--ink); border: var(--rule); padding: 7px 12px; cursor: pointer;
}
.btn:hover { background: var(--paper-2); }
.btn[aria-pressed="true"], .btn.commit { background: var(--active); color: var(--active-ink); border-color: var(--active); }
.btnrow { display: flex; flex-wrap: wrap; gap: 8px; }
.toggle { display: grid; grid-template-columns: 1fr 1fr; border: var(--rule); }
.toggle button { font-size: var(--t-label); letter-spacing: 0.08em; text-transform: uppercase; background: var(--paper); border: none; padding: 7px 8px; cursor: pointer; }
.toggle button + button { border-left: var(--rule); }
.toggle button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.field { font-size: 13px; background: var(--paper); border: var(--rule); padding: 8px 10px; width: 100%; }
.field::placeholder { color: var(--ink-soft); }
.chip { display: inline-block; font-size: var(--t-label); letter-spacing: 0.08em; text-transform: uppercase; border: var(--rule); padding: 2px 8px; }
.chip.on { background: var(--ink); color: var(--paper); }
.chip.ext { border-style: dashed; color: var(--ink-soft); }   /* marked extension / provenance */

/* ---------- 8. Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { text-align: left; vertical-align: top; padding: 10px 12px 10px 0; border-bottom: var(--rule-faint); }
th { font-weight: 500; font-size: var(--t-label); letter-spacing: var(--label-track); text-transform: uppercase; color: var(--ink-soft); border-bottom: var(--rule); }
tr:last-child td { border-bottom: var(--rule); }
td.n { color: var(--ink-soft); width: 34px; white-space: nowrap; }
.tablewrap { overflow-x: auto; }

/* ---------- 9. Readout + verdict (label/value pairs; the tinted verdict bar) ---------- */
.readout { display: grid; gap: 6px; font-size: 12.5px; }
.readout > div { display: grid; grid-template-columns: 90px 1fr; gap: 10px; }
.readout > div > span:first-child { color: var(--ink-soft); font-size: var(--t-label); letter-spacing: var(--label-track); text-transform: uppercase; padding-top: 2px; }
.verdict { border: var(--rule); border-top: none; display: grid; grid-template-columns: 200px 1fr; gap: 20px; padding: 16px var(--gutter); background: var(--paper-2); }
.verdict .path { margin-top: 8px; }

/* ---------- 10. Charts (SVG text + marks) ---------- */
.tick   { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.08em; fill: var(--ink-soft); text-transform: uppercase; }
.xlab   { font-family: var(--mono); font-size: 10px; letter-spacing: 0.06em; fill: var(--ink-soft); text-anchor: middle; }
.grid   { stroke: var(--ink-faint); stroke-width: 1; }
.axis   { stroke: var(--ink); stroke-width: 1; }
.seg    { stroke: var(--ink); stroke-width: 2; fill: none; }
.seg.dashed { stroke-dasharray: 4 5; }
.mk     { fill: var(--ink); stroke: var(--paper); stroke-width: 2; }
.mk.hollow { fill: var(--paper); stroke: var(--ink); stroke-width: 1.5; }
.mk.active { fill: var(--active); stroke: var(--paper); stroke-width: 2; }
.sel    { fill: none; stroke: var(--active); stroke-width: 1.5; }
.fault  { font-family: var(--mono); font-size: 9.5px; letter-spacing: var(--label-track); fill: var(--ink); text-transform: uppercase; paint-order: stroke; stroke: var(--paper); stroke-width: 4; text-anchor: middle; }
.glyph svg * { stroke: var(--ink); fill: none; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 11. Motion ---------- */
.draw { stroke-dasharray: 1000; stroke-dashoffset: 1000; animation: draw 400ms ease-out forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.snap { animation: snap 120ms ease-out; }
@keyframes snap { from { transform: scale(0.96); } to { transform: scale(1); } }
.slide-in { animation: slide var(--motion) ease-out; }
@keyframes slide { from { transform: translateX(24px); opacity: 0.6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .draw, .snap, .slide-in { animation: none; stroke-dashoffset: 0; }
  html { scroll-behavior: auto; }
}

/* ---------- 12. Responsive ---------- */
@media (max-width: 900px) {
  .cells.c4, .cells.c6 { grid-template-columns: 1fr 1fr; }
  .cells.c4 .cell:nth-child(2n), .cells.c6 .cell:nth-child(2n) { border-right: none; }
  .cells.c4 .cell:nth-child(-n+2), .cells.c6 .cell:not(:nth-last-child(-n+2)) { border-bottom: var(--rule); }
  .split { grid-template-columns: 1fr; }
  .split > :first-child { border-right: none; border-bottom: var(--rule); }
  .metrics.col { grid-template-rows: none; grid-template-columns: 1fr 1fr; }
  .metric:nth-child(odd) { border-right: var(--rule); }
}
@media (max-width: 680px) {
  .masthead, .intro, .row, .verdict, .entry, .cells.c2, .cells.c3, .cells.c4, .cells.c6 { grid-template-columns: 1fr; }
  .masthead-meta { justify-items: start; text-align: left; }
  .intro > div + div, .entry > .cell + .cell { border-left: none; border-top: var(--rule); padding-left: 0; text-align: left; }
  .cell { border-right: none; border-bottom: var(--rule); }
  .cell:last-child { border-bottom: none; }
  .metric .num { font-size: 56px; }
  .btn, .toggle button { min-height: 44px; }
}
@media print {
  body { background: #fff; color: #000; }
  .btn, .toggle, .appbar nav { display: none; }
  @page { margin: 14mm; }
}
