/* CV-04 · P04 Relay Board · commodity reference board (R4-catalog-v1.1)
   Visual grammar reused from samples/04-relay-board/styles.css: dark equipment surface,
   mint accent, amber signal, square geometry, utility rail, workcells with double rules. */
:root {
  color-scheme: dark;
  --bg: #071013;
  --bg-deep: #04090b;
  --surface: #101d21;
  --surface-raised: #16272c;
  --surface-soft: #1b3036;
  --ink: #f3faf7;
  --muted: #d3e2dd;
  --quiet: #b3c7c1;
  --line: #6f8885;
  --line-strong: #9eb5ae;
  --accent: #9af2c8;
  --signal: #ffd68d;
  --focus: #ffe09f;
  --max: 1600px;
}

* { box-sizing: border-box; }

html { background: var(--bg-deep); scroll-behavior: auto; }

body {
  min-width: 0;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

a { color: var(--accent); text-underline-offset: 0.22em; text-decoration-thickness: 0.11em; }
a:hover { color: #d5ffea; }
button { font: inherit; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
main:focus { outline: none; }

[hidden] { display: none !important; }

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.75rem;
  left: 0.75rem;
  min-height: 44px;
  padding: 0.65rem 1rem;
  background: var(--focus);
  color: #171004;
  font-weight: 800;
  transform: translateY(-180%);
}
.skip-link:focus { transform: translateY(0); }

/* ---------- header ---------- */
.site-head { border-bottom: 1px solid var(--line); background: rgba(7, 16, 19, 0.98); }

.prototype-band {
  margin: 0;
  padding: 0.7rem clamp(1rem, 4vw, 4rem);
  border-bottom: 1px solid #8f7443;
  background: #201a10;
  color: #fff0d2;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.015em;
  text-align: center;
}

.head-rail {
  width: min(100%, var(--max));
  margin-inline: auto;
  padding: 0.85rem clamp(1rem, 4vw, 4rem);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.25rem;
}

.brand-lockup { margin: 0; min-height: 48px; display: inline-flex; align-items: center; gap: 0.75rem; }
.brand-mark { width: 42px; height: 42px; flex: 0 0 auto; border: 2px solid var(--accent); background: #10241e; box-shadow: inset 0 0 0 6px #10241e, inset 0 0 0 9px var(--accent); }
.brand-copy { display: grid; line-height: 1.25; }
.brand-name { font-size: 1.25rem; font-weight: 900; letter-spacing: 0.02em; }
.brand-context { color: var(--muted); font-size: 0.9375rem; font-weight: 600; }

.primary-nav { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.primary-nav a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0.4rem 0.9rem;
  border: 1px solid var(--line); color: var(--ink); font-weight: 700; text-decoration: none;
}
.primary-nav a:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- shared type ---------- */
.eyebrow, .rail-code {
  margin: 0 0 0.75rem;
  color: var(--accent);
  font-size: 0.9375rem;
  font-weight: 850;
  letter-spacing: 0.09em;
  line-height: 1.4;
  text-transform: uppercase;
}
h1, h2, h3 { margin-top: 0; color: var(--ink); font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; }
h1 { font-size: clamp(2rem, 4.5vw, 3.25rem); margin-bottom: 1rem; }
h2 { font-size: clamp(1.5rem, 3vw, 2.25rem); }
h3 { font-size: 1.5rem; }
p { margin: 0 0 0.9rem; }

/* ---------- overview ---------- */
.overview, .board-section > .section-intro, .closing-section, .rail-emphasis, .reading-order, .board-rails {
  width: min(100%, var(--max));
  margin-inline: auto;
  padding: clamp(1.5rem, 4vw, 3.5rem) clamp(1rem, 4vw, 4rem);
}
.overview { border-bottom: 1px solid var(--line); }
.overview-copy { max-width: 900px; }
.overview-copy > p { font-size: 1.0625rem; color: var(--muted); }
.boundary-callout {
  padding: 0.9rem 1rem;
  border-left: 5px solid var(--signal);
  background: #1a1912;
  color: #fff0d1 !important;
  font-weight: 650;
}
.dataset-line { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--ink) !important; }
.how-to-read { border-top: 1px dashed var(--line); padding-top: 0.9rem; }

.utility-rail {
  margin: clamp(1.5rem, 4vw, 3rem) 0 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line-strong);
  background: var(--surface);
}
.utility-rail > div { min-width: 0; padding: 1rem; border-right: 1px solid var(--line); }
.utility-rail > div:last-child { border-right: 0; }
.utility-rail dt, .cell-label, .cell-title, .rail-code {
  color: var(--quiet); font-size: 0.9375rem; font-weight: 850; letter-spacing: 0.06em; text-transform: uppercase;
}
.utility-rail dd { margin: 0.35rem 0 0; display: flex; align-items: center; gap: 0.55rem; font-weight: 700; }

.signal { width: 18px; height: 18px; flex: 0 0 auto; display: inline-block; vertical-align: -3px; border: 2px solid currentColor; color: var(--accent); }
.signal-hatch { background: repeating-linear-gradient(135deg, currentColor 0 2px, transparent 2px 5px); }
.signal-ring { border-radius: 50%; box-shadow: inset 0 0 0 3px var(--surface), inset 0 0 0 5px currentColor; }
.signal-square { background: currentColor; box-shadow: inset 0 0 0 4px var(--surface); }
.signal-stripe { color: var(--signal); background: linear-gradient(90deg, currentColor 0 30%, transparent 30% 65%, currentColor 65% 100%); }
/* category signals: shape + pattern differ, always paired with the visible text label */
.signal-energy { background: repeating-linear-gradient(135deg, currentColor 0 2px, transparent 2px 5px); }
.signal-base-metals { background: currentColor; box-shadow: inset 0 0 0 4px var(--surface-raised); }
.signal-bulk { border-radius: 50%; }
.signal-agri { background: linear-gradient(90deg, currentColor 0 30%, transparent 30% 65%, currentColor 65% 100%); }
.signal-softs { background: repeating-linear-gradient(0deg, currentColor 0 2px, transparent 2px 5px); }
.signal-critical-minerals { color: var(--signal); transform: rotate(45deg) scale(0.85); }

.back-link-wrap { margin: 1.5rem 0 0; }
.back-link { display: inline-flex; align-items: center; min-height: 44px; padding: 0.5rem 1rem; border: 2px solid var(--accent); font-weight: 800; text-decoration: none; }
.back-link:hover { background: #16342b; }

/* ---------- board section ---------- */
.board-section { border-bottom: 1px solid var(--line); background: var(--bg-deep); }
.section-intro p:not(.eyebrow) { max-width: 900px; color: var(--muted); }

.rail-emphasis { padding-top: 0; padding-bottom: 0; }
.rail-emphasis > * { border: 1px solid var(--line-strong); border-top: 0; }
.emphasis-heading {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.75rem 2rem;
  padding: 1rem; border-top: 1px solid var(--line-strong) !important; background: var(--surface);
}
.emphasis-heading .eyebrow { margin-bottom: 0.25rem; }
.emphasis-title { margin: 0; font-size: 1.25rem; font-weight: 800; }
.emphasis-status { margin: 0; align-self: center; max-width: 34rem; font-weight: 700; color: var(--muted); }

.rail-controls { margin: 0; padding: 0.9rem 1rem 1rem; display: flex; flex-wrap: wrap; gap: 0.5rem; background: var(--bg); }
.rail-controls legend { float: left; width: 100%; padding: 0 0 0.5rem; color: var(--muted); font-size: 0.9375rem; font-weight: 800; }
.rail-button {
  min-height: 48px; padding: 0.65rem 0.9rem; border: 2px solid var(--line); border-radius: 0;
  background: var(--bg); color: var(--ink); font-weight: 750; cursor: pointer;
}
.rail-button:hover { border-color: var(--accent); }
.rail-button[aria-pressed="true"] { border: 4px double var(--accent); background: #16342b; box-shadow: inset 0 -4px 0 var(--accent); }
.no-js-note { margin: 0; padding: 0.9rem 1rem; color: var(--muted); background: var(--bg); }
.js .no-js-note, .no-js .rail-controls, .no-js .emphasis-status { display: none; }

.reading-order { padding-top: 1.25rem; padding-bottom: 1.25rem; }
.reading-list {
  margin: 0; padding-left: 1.5rem; columns: 3; column-gap: 2rem;
  font-variant-numeric: tabular-nums;
}
.reading-list li { break-inside: avoid; padding: 0.15rem 0; }
.reading-list a { display: inline-block; padding: 0.35rem 0; font-weight: 700; }

/* rails */
.board-rails { padding-top: 0; display: grid; gap: 1.5rem; }
.rail { border: 1px solid var(--line-strong); background: var(--surface); }
.rail-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 1.5rem; padding: 0.9rem 1rem; border-bottom: 3px double var(--line-strong); }
.rail-head p { margin: 0; }
.rail-name { font-size: 1.375rem; font-weight: 800; display: inline-flex; align-items: center; gap: 0.6rem; }
.rail-meta { color: var(--muted); }

.rail-cells { display: grid; gap: 1px; background: var(--line); }
.workcell { min-width: 0; padding: 1.15rem; background: var(--surface-raised); box-shadow: inset 0 5px 0 var(--line-strong); }
.workcell-topline { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.5rem 1rem; }
.cell-category { margin: 0; display: inline-flex; align-items: center; gap: 0.5rem; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; font-size: 0.9375rem; }
.stage-state { margin: 0; color: #d8e8e3; font-size: 0.9375rem; font-weight: 800; }
.workcell h3 { margin: 0.75rem 0 0.5rem; }
.summary { color: var(--muted); max-width: 70rem; }

.cells { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.cell { min-width: 0; padding: 0.9rem; background: var(--surface); }
.cell-input { box-shadow: inset 4px 0 0 var(--accent); }
.cell-action { box-shadow: inset 4px 0 0 var(--line-strong); }
.cell-output { box-shadow: inset 4px 0 0 var(--signal); }
.cell-title { margin: 0 0 0.25rem; color: var(--ink); }
.cell-state { margin: 0 0 0.75rem; padding-bottom: 0.5rem; border-bottom: 1px dotted var(--line); color: var(--quiet); font-size: 0.9375rem; font-weight: 700; }
.cell-label { margin: 0.9rem 0 0.25rem; }
.cell-note { margin: 0; color: var(--muted); }
.cell-list { margin: 0; padding-left: 1.25rem; color: var(--muted); }
.cell-list li { margin: 0.2rem 0; }

.price-line {
  margin: 0;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line-strong);
  background: var(--surface-raised);
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
}
.price-value { font-size: 1.25rem; font-weight: 900; }

.responsibility { margin: 1rem 0 0; padding: 0.8rem; border-left: 4px solid var(--accent); background: #0c1a18; color: var(--muted); }
.responsibility strong { display: block; color: var(--ink); font-size: 0.9375rem; letter-spacing: 0.045em; text-transform: uppercase; }

.exception { margin: 1rem 0 0; padding: 0.9rem; border-left: 4px solid var(--signal); background: #211b12; color: #fff0d1; }
.exception .cell-title, .exception .cell-label { color: #ffe1ad; }
.exception .cell-list, .exception .cell-note { color: #fff0d1; }

.sources-block { margin-top: 1rem; padding-top: 0.75rem; border-top: 1px dotted var(--line); }
.sources { font-size: 1rem; }
.src-url { word-break: break-all; }

/* emphasis states: only frames and rules change; body/price text colours never do */
.js .rail[data-emphasis="selected"] { border: 3px solid var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.js .rail[data-emphasis="selected"] .rail-head { border-bottom-color: var(--accent); background: #16342b; }
.js .rail[data-emphasis="muted"] { border-color: var(--line); }
.js .rail[data-emphasis="muted"] .rail-head { border-bottom-style: dashed; }
.js .rail[data-emphasis="muted"] .workcell { box-shadow: inset 0 5px 0 #506561; }

/* ---------- closing ---------- */
.closing-section { border-bottom: 1px solid var(--line); }
.next-step, .limits-copy { max-width: 900px; font-size: 1.125rem; }
.limits-copy { padding: 0.9rem 1rem; border-left: 5px solid var(--signal); background: #1a1912; color: #fff0d1; }

.site-foot { padding: 1.5rem clamp(1rem, 4vw, 4rem); text-align: center; color: var(--muted); }
.site-foot p:first-child { font-weight: 700; color: var(--ink); }
.site-foot a { display: inline-block; padding: 0.5rem 0; }

/* ---------- responsive: R4 workcells stack, cells become numbered vertical trays ---------- */
@media (max-width: 1023px) {
  .cells { grid-template-columns: 1fr; }
  .reading-list { columns: 2; }
}
@media (max-width: 767px) {
  .utility-rail { grid-template-columns: 1fr 1fr; }
  .utility-rail > div:nth-child(2n) { border-right: 0; }
  .utility-rail > div:nth-child(-n + 2) { border-bottom: 1px solid var(--line); }
  .reading-list { columns: 1; }
  .rail-button { flex: 1 1 100%; }
  h3 { font-size: 1.3rem; }
}
@media (max-width: 479px) {
  .utility-rail { grid-template-columns: 1fr; }
  .utility-rail > div { border-right: 0; border-bottom: 1px solid var(--line); }
  .utility-rail > div:last-child { border-bottom: 0; }
  .workcell, .cell { padding: 0.75rem; }
}

@media (prefers-reduced-motion: no-preference) {
  .rail, .rail-button { transition: border-color 80ms linear, background-color 80ms linear; }
}

@media (forced-colors: active) {
  .rail-button[aria-pressed="true"] { outline: 3px solid Highlight; outline-offset: -4px; }
}
