/* Layout: a component datasheet. Numbered sections like a real part's PDF,
   a running header with part number and page, a sticky pinout, and specification tables. */
:root {
  --paper: #ffffff;
  --ink: #111418;
  --muted: #5f6670;
  --rule: #d9dce0;
  --tint: #f3f4f6;
  --copper: #b8692e;      /* traces, the one accent */
  --pcb: #13513e;         /* solder-mask green, used only for the board */
  --ok: #1f8a5b;
  --warn: #c2410c;
  --sans: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 64px; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 400 17px/1.6 var(--sans); font-stretch: 100%; overflow-x: hidden; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--copper); outline-offset: 3px; }
::selection { background: var(--copper); color: #fff; }
.mono { font-family: var(--mono); }
.dim { color: var(--muted); }
.num { font: 600 .8em var(--mono); color: var(--copper); margin-right: .7em; letter-spacing: 0; }

/* ---------- running header ---------- */
.dsbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20; height: 52px;
  padding: env(safe-area-inset-top, 0px) 24px 0;
  display: flex; align-items: center; gap: 20px;
  background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-bottom: 2px solid var(--ink);
}
.pn { font: 800 18px var(--sans); font-stretch: 125%; text-decoration: none; letter-spacing: -.01em; }
.dsbar-title { font: 500 13px var(--mono); color: var(--muted); white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.dsnav { margin-left: auto; display: flex; gap: 18px; font-size: 14px; }
.dsnav a { text-decoration: none; color: var(--muted); padding: 4px 0; border-bottom: 2px solid transparent; transition: color .2s, border-color .2s; }
.dsnav a:hover, .dsnav a.on { color: var(--ink); border-color: var(--copper); }
.page { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.dsbar-progress { position: absolute; left: 0; bottom: -2px; height: 2px; width: 0; background: var(--copper); }

/* ---------- sheet ---------- */
.sheet { max-width: 1180px; margin: 0 auto; padding: 120px 24px 96px; border-bottom: 1px solid var(--rule); }
.docmeta { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--ink); padding-bottom: 10px; margin-bottom: 40px; text-transform: uppercase; letter-spacing: .08em; }
h1, h2, h3 { margin: 0; text-wrap: balance; }
.h-sec { font: 700 clamp(28px, 3.6vw, 42px)/1.1 var(--sans); font-stretch: 112%; letter-spacing: -.02em; margin-bottom: 14px; }
.h-sub { font: 700 15px var(--sans); text-transform: uppercase; letter-spacing: .06em; margin: 0 0 12px; }
.intro { max-width: 70ch; margin: 0 0 32px; }

/* overview */
.ov { display: grid; grid-template-columns: 1.15fr .85fr; gap: 56px; align-items: start; }
h1 { display: flex; flex-direction: column; line-height: .92; }
.part { font: 800 clamp(64px, 11vw, 148px) var(--sans); font-stretch: 125%; letter-spacing: -.035em; }
.who { font: 600 clamp(22px, 2.6vw, 32px) var(--sans); font-stretch: 85%; letter-spacing: -.01em; color: var(--muted); margin-top: 14px; }
.lede { font-size: clamp(18px, 1.7vw, 21px); max-width: 60ch; margin: 26px 0 36px; }
.cols { display: grid; grid-template-columns: 1.3fr 1fr; gap: 32px; }
.ticks { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 15px; }
.ticks li { padding-left: 20px; position: relative; }
.ticks li::before { content: ""; position: absolute; left: 0; top: .62em; width: 9px; height: 2px; background: var(--copper); }
.cta { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 24px; }
.btn { display: inline-block; font: 600 14px var(--sans); text-decoration: none; padding: 12px 18px; border-radius: 3px; background: var(--ink); color: #fff; border: 2px solid var(--ink); transition: background .2s, color .2s, transform .2s; }
.btn:hover { transform: translateY(-1px); background: var(--copper); border-color: var(--copper); }
.btn.line { background: transparent; color: var(--ink); }
.btn.line:hover { color: #fff; }
.ov-fig { margin: 0; border: 1px solid var(--rule); padding: 18px; min-width: 0; }
.figcap { font: 600 13px var(--sans); margin-bottom: 12px; }
.sysdiag { width: 100%; height: auto; display: block; }
.sysdiag .blk rect { fill: var(--paper); stroke: var(--ink); stroke-width: 1.5; }
.sysdiag .blk.hl rect { fill: var(--tint); }
.sysdiag text { font: 600 12px var(--sans); fill: var(--ink); text-anchor: middle; }
.sysdiag text.sm { font: 400 10px var(--mono); fill: var(--muted); }
.sysdiag .wire path { fill: none; stroke: var(--rule); stroke-width: 2; }
.sysdiag .sig path { fill: none; stroke: var(--copper); stroke-width: 2; stroke-dasharray: 6 18; animation: sig 1.4s linear infinite; }
.sysdiag .ar { fill: var(--ink); }
@keyframes sig { to { stroke-dashoffset: -24; } }

/* ---------- pinout (sticky) ---------- */
.pinout { height: 420vh; position: relative; border-bottom: 1px solid var(--rule); }
.pin-sticky { position: sticky; top: 52px; height: calc(100vh - 52px); max-width: 1180px; margin: 0 auto; padding: 32px 24px; display: grid; grid-template-columns: 1fr 1.25fr; gap: 40px; align-items: center; }
.pin-text .dim { max-width: 46ch; }
.pin-steps { list-style: none; margin: 28px 0 0; padding: 0; display: grid; gap: 4px; }
.pin-steps li { padding: 12px 16px; border-left: 3px solid var(--rule); color: var(--muted); transition: border-color .3s, color .3s, background .3s; }
.pin-steps li b { display: block; font-weight: 700; font-size: 15px; }
.pin-steps li span { font-size: 14px; }
.pin-steps li.on { border-color: var(--copper); color: var(--ink); }
.pin-steps li.cur { background: var(--tint); }
.pin-hint { font-size: 12px; margin-top: 20px; }
.pin-fig { margin: 0; position: relative; min-width: 0; }
#chip { width: 100%; height: auto; max-height: calc(100vh - 120px); display: block; }
#chip .body { fill: var(--ink); }
#chip .dot { fill: #3a4048; }
#chip .mark { font: 800 26px var(--sans); font-stretch: 125%; fill: #fff; text-anchor: middle; }
#chip .mark2 { font: 500 11px var(--mono); fill: #a7adb5; text-anchor: middle; }
#chip .pad { fill: #c9cdd2; transition: fill .3s; }
#chip .trace { fill: none; stroke: var(--copper); stroke-width: 2; stroke-linecap: round; }
#chip .plabel { font: 500 12px var(--mono); fill: var(--muted); transition: fill .3s; }
#chip .pnum { font: 500 9px var(--mono); fill: #9aa1a9; }
#chip .side-on .pad { fill: var(--copper); }
#chip .side-on .plabel { fill: var(--ink); font-weight: 600; }
#chip g.pin { cursor: default; }
#chip g.pin:hover .plabel { fill: var(--copper); }
.pintip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; font: 12px var(--mono); padding: 6px 9px; border-radius: 3px; max-width: 240px; transform: translate(-50%, -110%); z-index: 3; }

/* ---------- simulator ---------- */
.sim { display: grid; grid-template-columns: .9fr 1.1fr; gap: 28px; align-items: start; }
.sim > div { min-width: 0; }
.sim-board { border: 1px solid var(--rule); padding: 18px; }
.board { width: 100%; height: auto; display: block; }
.board .pcb { fill: var(--pcb); }
.board .holes circle { fill: var(--paper); stroke: #c9a227; stroke-width: 2; }
.board .trace path { fill: none; stroke: #2f7a5f; stroke-width: 3; }
.board .mcu { fill: #1b1f24; stroke: #c9cdd2; stroke-width: 1; }
.board .mk { font: 700 13px var(--sans); fill: #fff; text-anchor: middle; }
.board .mk.sm { font: 500 9px var(--mono); fill: #a7adb5; }
.board .part { fill: #e9ecef; stroke: #1b1f24; }
.board .lbl { font: 600 9px var(--mono); fill: #e7efe9; text-anchor: middle; }
.board .part + .lbl, #relayTxt { fill: #1b1f24; }
.board .led { fill: #3d4a44; transition: fill .2s; }
.board .led-glow { fill: transparent; transition: fill .2s; }
.board .led.on { fill: #ffe066; }
.board .led-glow.on { fill: rgba(255, 224, 102, .35); }
#relayBox.on { fill: #ffd9c2; stroke: var(--warn); }
.board .wifi { fill: none; stroke: #e7efe9; stroke-width: 2.5; stroke-linecap: round; }
.board .wifi-dot { fill: #e7efe9; }
.board .off .wifi, .board .off .wifi-dot { stroke: #7f8e87; fill: none; }
.board .off .wifi-dot { fill: #7f8e87; }
.controls { display: grid; gap: 14px; margin-top: 18px; }
.sw { display: flex; align-items: center; gap: 12px; font-size: 15px; cursor: pointer; }
.sw input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.sw span { width: 40px; height: 22px; border-radius: 11px; background: var(--rule); position: relative; transition: background .2s; flex: none; }
.sw span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.sw input:checked + span { background: var(--ink); }
.sw input:checked + span::after { transform: translateX(18px); }
.sw input:focus-visible + span { outline: 2px solid var(--copper); outline-offset: 2px; }
.rng { display: grid; gap: 6px; font-size: 15px; }
.rng b { font: 600 13px var(--mono); justify-self: end; margin-top: -26px; }
.rng input { width: 100%; accent-color: var(--copper); }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--rule); }
.kpis div { padding: 12px 14px; border-right: 1px solid var(--rule); min-width: 0; }
.kpis div:last-child { border-right: 0; }
.kpis span { display: block; font-size: 12px; }
.kpis b { font: 600 18px var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpis b.ok { color: var(--ok); } .kpis b.warn { color: var(--warn); }
.chartbox { border: 1px solid var(--rule); border-top: 0; padding: 14px 14px 8px; position: relative; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 13px; flex-wrap: wrap; }
.legend { display: flex; align-items: center; gap: 6px; font: 12px var(--mono); color: var(--muted); }
.legend i { display: inline-block; width: 14px; height: 2px; margin-left: 8px; }
.lg-t { background: var(--copper); }
.lg-s { background: repeating-linear-gradient(90deg, var(--muted) 0 3px, transparent 3px 6px); }
#simChart { width: 100%; height: 170px; display: block; margin-top: 8px; }
.ctip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; font: 12px var(--mono); padding: 5px 8px; border-radius: 3px; transform: translate(-50%, -120%); white-space: nowrap; }
.console { border: 1px solid var(--rule); border-top: 0; background: #0f1215; color: #d7dce1; }
.console-head { display: flex; justify-content: space-between; font-size: 11px; padding: 8px 12px; color: #8b939c; border-bottom: 1px solid #22272d; }
#log { list-style: none; margin: 0; padding: 8px 12px; font-size: 12px; height: 176px; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; }
#log li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; animation: in .25s ease-out; }
#log .t { color: #6b737c; } #log .tp { color: #e3a46f; } #log .dn { color: #7cc4ff; } #log .sys { color: #8fd6ae; } #log .wr { color: #ffb08a; }
@keyframes in { from { opacity: 0; transform: translateY(4px); } }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; border-top: 2px solid var(--ink); }
table.spec { width: 100%; border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; }
.spec th { text-align: left; font: 700 12px var(--sans); text-transform: uppercase; letter-spacing: .06em; padding: 10px 12px; background: var(--tint); border-bottom: 1px solid var(--ink); white-space: nowrap; }
.spec td { padding: 11px 12px; border-bottom: 1px solid var(--rule); vertical-align: top; }
.spec .r { text-align: right; font-family: var(--mono); font-size: 14px; }
.spec tbody tr { transition: background .2s; }
.spec tbody tr:hover { background: #fbf6f1; }
.spec td:first-child { font-weight: 600; }
.rev td:first-child { width: 70px; } .rev td:nth-child(2) { width: 150px; white-space: nowrap; }
.spec a { text-decoration-color: var(--copper); text-underline-offset: 3px; }
.note { font-size: 12px; margin-top: 12px; }

/* ---------- case studies ---------- */
.cases { display: grid; gap: 0; border-top: 2px solid var(--ink); }
.case { padding: 28px 0; border-bottom: 1px solid var(--rule); }
.case header { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 0; margin-bottom: 16px; }
.case h3 { font: 700 24px var(--sans); font-stretch: 110%; letter-spacing: -.01em; margin-right: 16px; }
.tagline { font-size: 12px; color: var(--muted); }
.case-body { display: grid; grid-template-columns: 1.2fr 1fr .8fr; gap: 32px; align-items: start; }
.case-body p { margin: 0 0 10px; font-size: 15px; max-width: 60ch; }
.flow { width: 100%; height: auto; display: block; }
.flow .fl rect { fill: var(--paper); stroke: var(--ink); stroke-width: 1.2; }
.flow .fl rect:first-child { fill: var(--tint); }
.flow text { font: 600 10.5px var(--sans); fill: var(--ink); text-anchor: middle; }
.flow .fw path { stroke: var(--copper); stroke-width: 2; }
.results { margin: 0; display: grid; gap: 10px; }
.results div { display: flex; align-items: baseline; gap: 12px; border-bottom: 1px dashed var(--rule); padding-bottom: 8px; }
.results dt { font: 700 24px var(--mono); color: var(--copper); min-width: 96px; font-variant-numeric: tabular-nums; }
.results dd { margin: 0; font-size: 14px; color: var(--muted); }

/* ordering */
.order { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; align-items: start; }
.big { font-size: clamp(20px, 2vw, 26px); line-height: 1.4; margin: 0; max-width: 34ch; }
.legal { margin-top: 64px; font-size: 11px; border-top: 1px solid var(--rule); padding-top: 14px; max-width: 90ch; }

/* reveal */
.rv { opacity: 0; transform: translateY(18px); transition: opacity .6s, transform .6s; }
.rv.in { opacity: 1; transform: none; }

/* ---------- responsive ---------- */
@media (max-width: 1020px) {
  .dsnav { display: none; }
  .dsbar-title { margin-left: auto; }
  .ov, .sim, .order { grid-template-columns: 1fr; }
  .case-body { grid-template-columns: 1fr; gap: 18px; }
}
@media (max-width: 760px) {
  .pinout { height: auto; }
  .pin-sticky { position: static; height: auto; grid-template-columns: 1fr; padding: 96px 16px 48px; }
  .pin-steps li { border-color: var(--copper); color: var(--ink); }
  .sheet { padding: 96px 16px 64px; }
  .dsbar { padding: env(safe-area-inset-top, 0px) 16px 0; gap: 12px; }
  .cols { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpis div:nth-child(2) { border-right: 0; }
  .kpis div:nth-child(-n+2) { border-bottom: 1px solid var(--rule); }
  .docmeta { flex-direction: column; gap: 4px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
  .rv { opacity: 1; transform: none; }
}
