@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap");

/* =========================================================
   Digital Sounds Lab — dark theme
   ========================================================= */
:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --surface: #131a22;
  --surface-2: #1a232e;
  --surface-3: #222d3a;
  --border: #2a3644;
  --border-strong: #3a4859;
  --text: #e6edf3;
  --muted: #93a1b0;
  --faint: #5f6e7e;

  --accent: #4cc9f0;      /* analog / original */
  --accent-2: #ff4fa3;    /* digital / quantized */
  --accent-3: #9b8cff;
  --ok: #6ee7a0;
  --warn: #f5c451;
  --danger: #ff6b6b;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent); }
code, pre, kbd { font-family: var(--mono); }
code { background: var(--surface-3); padding: 0.1em 0.35em; border-radius: 4px; font-size: 0.9em; }
kbd {
  background: var(--surface-3); border: 1px solid var(--border-strong); border-bottom-width: 2px;
  border-radius: 4px; padding: 0 0.35em; font-size: 0.85em;
}
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 0.5rem; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.05rem; }
h4 { font-size: 0.95rem; }
p { margin: 0 0 0.75rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Header & tabs ---------- */
.app-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1.5rem;
  padding: 0.75rem clamp(1rem, 3vw, 2rem);
  background: #1a1d20;               /* make.cs.umass.edu charcoal */
  border-bottom: 2px solid #7dd4dc;  /* make.cs.umass.edu teal */
}
@media (max-width: 640px) {
  .app-header { position: static; }
}
.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand h1 { font-family: "Inter", sans-serif; font-size: 18px; font-weight: 600; color: #fff; margin: 0; letter-spacing: -0.01em; transition: color 0.15s; }
.brand-logo { width: 40px; height: 40px; flex: none; display: block; }
a.brand:hover h1 { color: #f5c842; }
.tabs { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.tab {
  appearance: none; border: 1px solid transparent; background: transparent; color: var(--muted);
  font: inherit; font-weight: 600; padding: 0.45rem 0.9rem; border-radius: 999px; cursor: pointer;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab[aria-selected="true"] { color: var(--bg); background: var(--accent); }

main { padding: 1.25rem clamp(1rem, 3vw, 2rem) 3rem; max-width: 1500px; margin: 0 auto; }
.panel[hidden] { display: none; }
.intro { max-width: 70ch; margin-bottom: 1.25rem; }
.intro p { color: var(--muted); }

/* Intro with a photo of the real part: text left, photo right; photo on top on phones. */
.intro.has-photo {
  max-width: none; display: grid; gap: 1rem 1.75rem; align-items: start;
  grid-template-columns: minmax(0, 70ch) minmax(220px, 340px);
}
/* The photo takes no height of its own: the text column sets the row height,
   and the image scales down to fill that height (caption below it). */
.sensor-photo { margin: 0; align-self: stretch; display: flex; flex-direction: column; min-width: 0; }
.sensor-photo .photo-box { position: relative; flex: 1 1 auto; min-height: 120px; }
.sensor-photo img {
  position: absolute; top: 0; left: 0; height: 100%; width: auto; max-width: 100%;
  object-fit: contain; object-position: left top;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-2);
}
.sensor-photo figcaption { font-size: 0.72rem; color: var(--muted); margin-top: 0.35rem; line-height: 1.35; }
.sensor-photo figcaption a { color: inherit; }
@media (max-width: 760px) {
  .intro.has-photo { grid-template-columns: 1fr; }
  .intro.has-photo .sensor-photo { order: -1; max-width: 420px; }
  .sensor-photo .photo-box { position: static; min-height: 0; }
  .sensor-photo img { position: static; width: auto; max-width: 100%; height: auto; max-height: 240px; display: block; }
}

/* ---------- Cards & layout ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card > h3 { display: flex; align-items: center; gap: 0.5rem; }
.card + .card { margin-top: 1rem; }

.lab-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 1rem;
  align-items: start;
}
.lab-layout aside { min-width: 0; }
@media (max-width: 1050px) {
  .lab-layout { grid-template-columns: minmax(0, 1fr); }
}

.learn-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-top: 1.25rem;
}
.learn-grid .card { margin: 0; box-shadow: none; }
.learn-grid h3 { color: var(--accent); }

/* ---------- Form controls ---------- */
.field { display: grid; gap: 0.3rem; margin-bottom: 0.85rem; }
.field:last-child { margin-bottom: 0; }
.field > label, .field-label { font-weight: 600; font-size: 0.88rem; display: flex; justify-content: space-between; gap: 0.5rem; }
.field output, .value { font-family: var(--mono); color: var(--accent); font-weight: 600; }
.hint { font-size: 0.8rem; color: var(--muted); }
.row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1 1 0; min-width: 0; }

input[type="number"], input[type="text"], select {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.6rem;
  font: inherit;
}
input[type="number"] { font-family: var(--mono); }
select { cursor: pointer; }
input:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(76, 201, 240, 0.2); }

input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; }
input[type="checkbox"] { accent-color: var(--accent); width: 1rem; height: 1rem; }
.check { display: inline-flex; align-items: center; gap: 0.45rem; cursor: pointer; font-size: 0.9rem; }

.btn {
  appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  font: inherit; font-weight: 600; font-size: 0.9rem;
  color: var(--text);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.85rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #2c3a4a; border-color: var(--faint); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn svg { width: 1em; height: 1em; fill: currentColor; }
.btn-primary { background: var(--accent); color: #04121a; border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: #79d8f5; border-color: #79d8f5; }
.btn-hot { background: var(--accent-2); color: #1a0410; border-color: var(--accent-2); }
.btn-hot:hover:not(:disabled) { background: #ff7dbb; border-color: #ff7dbb; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.82rem; }
.btn[aria-pressed="true"] { background: var(--accent-3); color: #0d0824; border-color: var(--accent-3); }

.segmented {
  display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden;
}
.segmented button {
  appearance: none; border: 0; background: var(--surface-2); color: var(--muted);
  font: inherit; font-size: 0.85rem; font-weight: 600; padding: 0.4rem 0.75rem; cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--border-strong); }
.segmented button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); }
.segmented button[data-value="quantized"][aria-pressed="true"] { color: var(--accent-2); }
.segmented button[data-value="original"][aria-pressed="true"] { color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip {
  appearance: none; font: inherit; font-size: 0.78rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border-strong);
  border-radius: 999px; padding: 0.2rem 0.6rem; cursor: pointer;
}
.chip:hover { color: var(--text); border-color: var(--faint); }
.chip[aria-pressed="true"] { color: var(--bg); background: var(--accent); border-color: var(--accent); }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; margin-bottom: 0.75rem;
}
.toolbar .spacer { flex: 1; }
.toolbar .divider { width: 1px; align-self: stretch; background: var(--border); }
.vol { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--muted); }
.vol input { width: 90px; }

/* ---------- Canvases ---------- */
.canvas-wrap {
  position: relative;
  width: 100%;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #0a0e13;
  border: 1px solid var(--border);
}
.canvas-wrap canvas { display: block; width: 100%; height: 100%; touch-action: none; }
#q-graph-wrap { height: clamp(320px, 55vh, 520px); cursor: crosshair; }
#q-graph-wrap.erasing { cursor: cell; }
#q-wave-wrap { height: 150px; cursor: crosshair; }
#pwm-scope-wrap { height: 260px; }
#pwm-spectrum-wrap { height: 140px; }

.graph-footer {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.5rem 1rem;
  margin-top: 0.6rem;
}
.readout { font-family: var(--mono); font-size: 0.82rem; color: var(--muted); min-height: 1.3em; }
.legend { display: flex; flex-wrap: wrap; gap: 0.35rem 1rem; font-size: 0.82rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.swatch { width: 18px; height: 3px; border-radius: 2px; display: inline-block; }
.swatch.analog { background: var(--accent); }
.swatch.digital { background: var(--accent-2); }
.swatch.error { background: rgba(255, 79, 163, 0.35); height: 10px; }
.swatch.level { background: rgba(155, 140, 255, 0.6); height: 1px; }
.swatch.avg { background: repeating-linear-gradient(90deg, var(--warn) 0 4px, transparent 4px 7px); }
.swatch.rc { background: var(--ok); }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin: 0; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.5rem 0.6rem; min-width: 0; }
.stat dt { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat dd { margin: 0.1rem 0 0; font-family: var(--mono); font-weight: 600; font-size: 0.95rem; overflow-wrap: anywhere; }
.stat.wide { grid-column: 1 / -1; }

.callout {
  border-left: 3px solid var(--accent-3); background: rgba(155, 140, 255, 0.08);
  padding: 0.6rem 0.8rem; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; font-size: 0.88rem; margin: 0.75rem 0 0;
}
.callout.warn { border-color: var(--warn); background: rgba(245, 196, 81, 0.08); }
.callout.danger { border-color: var(--danger); background: rgba(255, 107, 107, 0.08); }
.callout[hidden] { display: none; }

/* ---------- Waveform editor ---------- */
.wave-tools { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.5rem; }

/* ---------- PWM tab ---------- */
.pwm-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 1rem;
  align-items: stretch;
}
@media (max-width: 800px) { .pwm-top { grid-template-columns: minmax(0, 1fr); } }

.led-stage {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.5rem;
  background: radial-gradient(ellipse at 50% 35%, #141c26 0%, #080b0f 70%);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  padding: 0.75rem;
  min-height: 300px;
}
.led-svg { width: 100%; max-width: 220px; height: auto; overflow: visible; }
.led-svg .led-core { fill: var(--led); }
.led-svg .led-tint { fill: var(--led); }
.led-svg .led-halo-stop { stop-color: var(--led); }
.led-meter { width: 100%; max-width: 220px; }
.meter {
  height: 8px; background: var(--surface-3); border-radius: 999px; overflow: hidden; border: 1px solid var(--border);
}
.meter > div { height: 100%; width: 0; background: var(--led, var(--accent)); }
.led-colors { display: flex; gap: 0.4rem; justify-content: center; }
.led-color {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border-strong); cursor: pointer; padding: 0;
}
.led-color[aria-pressed="true"] { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--c); }

.big-duty { font-family: var(--mono); font-size: 2rem; font-weight: 700; color: var(--accent); line-height: 1; }
.run-btn[aria-pressed="true"] { background: var(--ok); color: #04170c; border-color: var(--ok); }

pre.code {
  margin: 0; background: #0a0e13; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.85rem 1rem; overflow-x: auto; font-size: 0.82rem; line-height: 1.55; color: #cdd9e5;
}
pre.code code { background: none; padding: 0; border-radius: 0; font-size: inherit; }
pre.code .c { color: #6b7d8f; }
pre.code .k { color: #ff7b72; }
pre.code .n { color: #79c0ff; }
pre.code .f { color: #d2a8ff; }

.schematic { width: 100%; max-width: 300px; height: auto; }
.schematic text { fill: var(--muted); font: 600 11px var(--font); }
.schematic .wire { stroke: var(--muted); stroke-width: 2; fill: none; }

/* ---------- GPIO tab ---------- */
.gpio-layout {
  display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 1rem; align-items: start;
}
@media (max-width: 1000px) { .gpio-layout { grid-template-columns: minmax(0, 1fr); } }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
table.pins { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.pins th, table.pins td { padding: 0.45rem 0.6rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
table.pins th { background: var(--surface-2); color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; position: sticky; top: 0; }
table.pins tr:last-child td { border-bottom: 0; }
table.pins td:first-child { font-family: var(--mono); font-weight: 700; white-space: nowrap; }
.tag {
  display: inline-block; font-size: 0.7rem; font-weight: 700; padding: 0.05rem 0.45rem; border-radius: 999px;
  margin: 0 0.2rem 0.2rem 0; border: 1px solid currentColor; white-space: nowrap;
}
.tag.safe { color: var(--ok); }
.tag.caution { color: var(--warn); }
.tag.avoid { color: var(--danger); }
.tag.info { color: var(--accent); }
.tag.dac { color: var(--accent-3); }
.tag.touch { color: #ffa657; }

.concepts { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; margin-top: 1rem; }
.concepts .card { margin: 0; box-shadow: none; }
.concepts h3 { color: var(--accent); }
.concepts ul { padding-left: 1.1rem; margin: 0; }
.concepts li { margin-bottom: 0.3rem; }
/* Spans two grid columns once there is room for two; stays single-column on phones. */
@media (min-width: 640px) { .concepts .card.wide { grid-column: span 2; } }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%) translateY(150%);
  background: var(--surface-3); color: var(--text); border: 1px solid var(--border-strong);
  padding: 0.6rem 1rem; border-radius: var(--radius-sm); box-shadow: var(--shadow);
  transition: transform 0.25s ease; z-index: 50; max-width: calc(100vw - 2rem); font-size: 0.9rem;
}
.toast:not(.show) { visibility: hidden; transition: transform 0.25s ease, visibility 0s 0.25s; }
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--danger); }

footer.site { text-align: center; color: var(--faint); font-size: 0.8rem; padding: 0 1rem 2rem; }

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

/* =========================================================
   Multi-page site: navigation
   ========================================================= */
.app-header { min-height: 58px; }
.site-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem; }
.site-nav > a.tab { text-decoration: none; }
.nav-group { position: relative; }
.nav-group > summary {
  list-style: none; cursor: pointer; user-select: none;
  color: var(--muted); font-weight: 600; padding: 0.45rem 0.85rem; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 0.35rem;
}
.nav-group > summary::-webkit-details-marker { display: none; }
.nav-group > summary::after { content: "\25BE"; font-size: 0.75em; opacity: 0.7; }
.nav-group > summary:hover, .nav-group[open] > summary { color: var(--text); background: var(--surface-2); }
.nav-group.current > summary { color: var(--accent); }
.nav-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30;
  min-width: 260px; max-width: calc(100vw - 2rem);
  max-height: 75vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 0.4rem; margin: 0; list-style: none;
}
.nav-group:nth-last-child(-n+2) .nav-menu { left: auto; right: 0; }
@media (min-width: 720px) {
  .nav-menu.wide { display: grid; grid-template-columns: repeat(2, minmax(250px, 1fr)); gap: 0 0.25rem; width: min(620px, calc(100vw - 2rem)); }
}
.nav-menu a {
  display: block; padding: 0.45rem 0.65rem; border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none; font-size: 0.92rem;
}
.nav-menu a small { display: block; color: var(--muted); font-size: 0.78rem; }
.nav-menu a:hover { background: var(--surface-2); }
.nav-menu a[aria-current="page"] { background: rgba(76, 201, 240, 0.12); color: var(--accent); }
a.tab[aria-current="page"] { color: var(--bg); background: var(--accent); }
a.brand { text-decoration: none; color: inherit; }
@media (max-width: 640px) {
  .nav-menu { position: fixed; left: 1rem !important; right: 1rem !important; top: auto; min-width: 0; max-width: none; }
}

.page-nav {
  display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--border);
}
.page-nav a {
  display: grid; gap: 0.1rem; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.7rem 1rem; min-width: 200px;
}
.page-nav a:hover { border-color: var(--accent); }
.page-nav a span { font-size: 0.78rem; color: var(--muted); }
.page-nav a.next { text-align: right; margin-left: auto; }

/* =========================================================
   Content components (shared by all topic pages)
   ========================================================= */
.section { margin-top: 1.75rem; }
.section > h2 { font-size: 1.25rem; margin-bottom: 0.75rem; display: flex; align-items: center; gap: 0.5rem; }
.section > h2::before { content: ""; width: 4px; height: 1.1em; background: var(--accent); border-radius: 2px; flex: none; }
.section > p.lead { color: var(--muted); max-width: 75ch; }

.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; align-items: start; }
.three-col { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; align-items: start; }
@media (max-width: 900px) { .two-col, .three-col { grid-template-columns: minmax(0, 1fr); } }
.two-col > .card, .three-col > .card, .two-col > div > .card:first-child { margin-top: 0; }

.card ul, .card ol { padding-left: 1.2rem; margin: 0 0 0.5rem; }
.card li { margin-bottom: 0.3rem; }
.card li:last-child { margin-bottom: 0; }
.card > :last-child { margin-bottom: 0; }

/* Numbered build steps */
ol.steps { list-style: none; counter-reset: step; padding: 0; margin: 0; }
ol.steps > li { counter-increment: step; position: relative; padding: 0 0 0.9rem 2.6rem; margin: 0; }
ol.steps > li::before {
  content: counter(step); position: absolute; left: 0; top: -0.1rem;
  width: 1.8rem; height: 1.8rem; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-3); border: 1px solid var(--accent); color: var(--accent); font-weight: 700; font-size: 0.85rem;
}
ol.steps > li:not(:last-child)::after {
  content: ""; position: absolute; left: 0.88rem; top: 1.8rem; bottom: 0.1rem; width: 2px; background: var(--border);
}
ol.steps > li > strong:first-child { display: block; }

/* Generic data tables (wiring, specs, comparisons) — wrap in .table-wrap */
table.data { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.data th, table.data td { padding: 0.45rem 0.6rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data th { background: var(--surface-2); color: var(--muted); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.mono { font-family: var(--mono); white-space: nowrap; }

/* Wire color dots for wiring tables */
.wire-dot { display: inline-block; width: 0.8em; height: 0.8em; border-radius: 50%; margin-right: 0.35em; vertical-align: -0.05em; border: 1px solid rgba(255,255,255,0.25); }
.wd-red { background: #ff5a52; } .wd-black { background: #222; } .wd-brown { background: #8b5a2b; }
.wd-orange { background: #ff9f43; } .wd-yellow { background: #f5c451; } .wd-white { background: #f2f2f2; }
.wd-green { background: #30d158; } .wd-blue { background: #0a84ff; } .wd-purple { background: #9b8cff; }

/* Circuit diagrams (inline SVG). Use classes below instead of hard-coded colors. */
figure.diagram {
  margin: 0; background: #0a0e13; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.75rem; overflow-x: auto;
}
figure.diagram svg { display: block; width: 100%; height: auto; min-width: 480px; }
figure.diagram.compact svg { min-width: 0; }
figure.diagram figcaption { font-size: 0.8rem; color: var(--muted); margin-top: 0.5rem; }
.diagram text { fill: #c9d4df; font: 600 12px var(--font); }
.diagram text.small { font-size: 10px; font-weight: 500; fill: var(--muted); }
.diagram text.t-pwr { fill: #ff8a84; }
.diagram text.t-gnd { fill: #9fb0c3; }
.diagram text.t-sig { fill: #f5c451; }
.diagram text.t-data { fill: #4cc9f0; }
.diagram .part { fill: #1a232e; stroke: #4a5a6d; stroke-width: 1.5; }
.diagram .board { fill: #13202b; stroke: #2f6f8f; stroke-width: 1.5; }
.diagram .pin { fill: #c9d4df; }
.diagram .w { fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.diagram .w-pwr { stroke: #ff5a52; }
.diagram .w-5v { stroke: #ff9f43; }
.diagram .w-gnd { stroke: #7d8da0; }
.diagram .w-sig { stroke: #f5c451; }
.diagram .w-data { stroke: #4cc9f0; }
.diagram .w-alt { stroke: #9b8cff; }
.diagram .w-motor { stroke: #30d158; }
.diagram .dot { fill: #c9d4df; }
.diagram .flow { stroke-dasharray: 6 8; animation: flow 0.8s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -14; } }
@media (prefers-reduced-motion: reduce) { .diagram .flow { animation: none; } }

/* Key/value spec list */
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; margin: 0; font-size: 0.9rem; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; font-family: var(--mono); }

.badge {
  display: inline-block; font-size: 0.72rem; font-weight: 700; padding: 0.1rem 0.5rem; border-radius: 999px;
  border: 1px solid currentColor; vertical-align: middle;
}
.badge.ok { color: var(--ok); } .badge.warn { color: var(--warn); } .badge.bad { color: var(--danger); } .badge.info { color: var(--accent); }

.callout.ok { border-color: var(--ok); background: rgba(110, 231, 160, 0.08); }
.callout.info { border-color: var(--accent); background: rgba(76, 201, 240, 0.07); }

/* Code blocks with copy button (js/code.js) */
.code-block { position: relative; }
.code-block + .code-block { margin-top: 0.75rem; }
.code-title { font-size: 0.78rem; color: var(--muted); font-family: var(--mono); margin: 0 0 0.3rem; }
.code-copy { position: absolute; top: 0.45rem; right: 0.45rem; opacity: 0.8; }
.code-copy:hover { opacity: 1; }
pre.code .s { color: #a5d6ff; }
pre.code .p { color: #ffa657; }

/* Simulator widgets */
.sim { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1rem; align-items: start; }
@media (max-width: 900px) { .sim { grid-template-columns: minmax(0, 1fr); } }
.sim-stage { background: #0a0e13; border: 1px solid var(--border); border-radius: var(--radius-sm); position: relative; overflow: hidden; }
.sim-stage > canvas, .sim-stage > svg { display: block; width: 100%; }

/* Resources */
ul.resources { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.6rem; }
ul.resources li a { font-weight: 600; }
ul.resources li span { display: block; font-size: 0.82rem; color: var(--muted); }

/* Home page */
.hero { padding: 1rem 0 0.5rem; max-width: 80ch; }
.hero h2 { font-size: clamp(1.6rem, 3vw, 2.2rem); }
.hero p { color: var(--muted); font-size: 1.05rem; }
.topic-group { margin-top: 1.75rem; }
.topic-group > h2 { font-size: 0.95rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 0.85rem; }
a.topic {
  display: block;
  text-decoration: none; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.9rem; transition: border-color 0.15s, transform 0.15s;
}
a.topic:hover { border-color: var(--accent); transform: translateY(-2px); }
a.topic strong { display: block; }
a.topic span { color: var(--muted); font-size: 0.85rem; }
