/* The wiki's chrome. Light and dark follow html[data-theme]; the diagram canvas itself is
   coloured by theme.js, which writes --bg-canvas and --grid-dot on the root. */
:root {
  --bg: #f3f2ec; --panel: #ffffff; --panel-2: #f6f6f8; --text: #1e2230; --muted: #6b7288; --border: #dcdfe8;
  --accent: #2456c8; --accent-solid: #2456c8; --accent-bg: #e9effc; --hl: #fff1bf; --sel: #dbe6ff; --code: #eef0f5;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06);
  --bg-canvas: #dcd6c5; --grid-dot: #c0c0c0;
}
html[data-theme="dark"] {
  --bg: #0f1117; --panel: #171a24; --panel-2: #1d2130; --text: #e3e6f0; --muted: #8f97ad; --border: #2b3042;
  --accent: #8fb0ff; --accent-solid: #3b6be0; --accent-bg: #1e2a4a; --hl: #4a3f12; --sel: #243a6b; --code: #242838;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --bg-canvas: #131320; --grid-dot: #2e2e50;
}
* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0; min-height: 100%; display: flex; flex-direction: column;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg);
}
body.viewer { height: 100vh; overflow: hidden; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.toggle { color: var(--muted); }
button.toggle.active { color: var(--accent); background: var(--accent-bg); border-color: var(--accent); }
input[type="search"] { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; width: 100%; }
.muted { color: var(--muted); }
.code { font-family: ui-monospace, Consolas, monospace; font-size: .85em; color: var(--muted); background: var(--code); border-radius: 4px; padding: 1px 6px; white-space: nowrap; }
.count { font-weight: 400; color: var(--muted); font-size: .8em; margin-left: 4px; }

/* header and footer */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.crumbs { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.crumbs span { color: var(--text); }
.top-right { display: flex; gap: 8px; align-items: center; flex: 0 0 auto; }
.top-link { padding: 4px 10px; border: 1px solid var(--border); border-radius: 6px; }
#theme-toggle { font-size: 16px; line-height: 1; padding: 3px 8px; }
.foot { padding: 10px 16px; font-size: 13px; color: var(--muted); border-top: 1px solid var(--border); flex: 0 0 auto; }
body.viewer .foot { display: none; }

/* index pages */
.index-layout { width: min(1100px, 100%); margin: 0 auto; padding: 24px 16px 48px; flex: 1 0 auto; }
.index-head h1 { margin: 0 0 4px; font-size: 28px; }
.lead { margin: 0 0 16px; color: var(--muted); font-size: 16px; }
.intro { margin: 0 0 16px; }
.search-box { margin: 12px 0 24px; }
.search-box input { font-size: 16px; padding: 10px 14px; }
#search-results { margin-top: 8px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); max-height: 50vh; overflow: auto; }
#search-results a, .pages a { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: baseline; padding: 8px 12px; color: var(--text); border-bottom: 1px solid var(--border); }
#search-results a:last-child, .pages li:last-child a { border-bottom: 0; }
#search-results a:hover, .pages a:hover { background: var(--accent-bg); text-decoration: none; }
#search-results p { margin: 0; padding: 8px 12px; }
.meta { color: var(--muted); font-size: 13px; white-space: nowrap; }
.sec { margin: 0 0 22px; }
.sec h2 { font-size: 18px; margin: 0 0 6px; display: flex; gap: 10px; align-items: baseline; }
.pages { list-style: none; margin: 0; padding: 0; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); overflow: hidden; }
.cards { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.diagram-card { display: block; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; box-shadow: var(--shadow); }
.diagram-card:hover { border-color: var(--accent); text-decoration: none; }
.diagram-card h2 { margin: 0 0 6px; font-size: 18px; }
.diagram-card p { margin: 0 0 6px; }

/* a diagram page */
.page-layout { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 380px; }
.canvas-col { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.canvas-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 12px; border-bottom: 1px solid var(--border); background: var(--panel); flex: 0 0 auto; }
.canvas-title { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.canvas-title h1 { font-size: 17px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.section-name { color: var(--muted); font-size: 13px; white-space: nowrap; }
.canvas-tools { display: flex; gap: 6px; flex: 0 0 auto; }
#canvas-wrap { position: relative; flex: 1 1 auto; min-height: 0; }
#canvas-container {
  position: absolute; inset: 0; overflow: hidden; touch-action: none;
  background-color: var(--bg-canvas);
  background-image: radial-gradient(circle, var(--grid-dot) 1px, transparent 1px);
  background-size: 20px 20px;
}
#loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; }
.hint { position: absolute; left: 10px; bottom: 8px; font-size: 12px; color: var(--muted); background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; opacity: .9; pointer-events: none; }
#tooltip {
  position: absolute; z-index: 3; max-width: 320px; font-size: 13px; line-height: 1.35; pointer-events: none;
  background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 6px 9px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}
#side { overflow: auto; border-left: 1px solid var(--border); background: var(--bg); padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; box-shadow: var(--shadow); }
.card h2 { font-size: 15px; margin: 0 0 8px; }
.card h3 { font-size: 14px; margin: 14px 0 6px; }
.card p { margin: 6px 0; }
.card.notes h2 ~ h2, .card.notes h3, .card.notes h4 { margin-top: 14px; }
.card.notes pre { background: var(--code); padding: 8px 10px; border-radius: 6px; overflow: auto; font-size: 13px; }
.card.notes code { background: var(--code); padding: 1px 4px; border-radius: 3px; font-size: .9em; }
.card.notes img { max-width: 100%; height: auto; border-radius: 6px; }
.card.notes blockquote { margin: 8px 0; padding: 2px 12px; border-left: 3px solid var(--border); color: var(--muted); }
.kind { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.row { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; border-bottom: 1px dashed var(--border); font-size: 14px; }
.row span { color: var(--muted); flex: 0 0 auto; }
.row b { font-weight: 500; text-align: right; }
p.notes { white-space: pre-wrap; font-size: 14px; background: var(--panel-2); border-radius: 6px; padding: 8px 10px; }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(0, 0, 0, .25); vertical-align: -2px; margin-right: 5px; }
.sw.stripe { width: 7px; margin-left: -7px; border-left: 0; }
table.pins, table.wires { width: 100%; border-collapse: collapse; font-size: 13px; }
table.pins th, table.wires th { text-align: left; font-weight: 600; color: var(--muted); padding: 4px 6px; border-bottom: 1px solid var(--border); }
table.pins td, table.wires td { padding: 4px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.pins td.num { font-family: ui-monospace, Consolas, monospace; white-space: nowrap; }
table.pins .fn { color: var(--muted); font-size: 12px; }
table.pins .conn a { display: block; color: var(--text); }
table.pins .conn a:hover { color: var(--accent); }
table.wires tbody tr { cursor: pointer; }
table.wires tbody tr:hover { background: var(--accent-bg); }
table.wires tr.hl { background: var(--hl); }
table.wires tr.sel { background: var(--sel); }
table.wires .pin { font-weight: 600; font-family: ui-monospace, Consolas, monospace; }
.parts { list-style: none; margin: 8px 0 0; padding: 0; max-height: 40vh; overflow: auto; }
.parts li button { display: flex; width: 100%; justify-content: space-between; gap: 8px; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; padding: 5px 4px; }
.parts li button:hover { background: var(--accent-bg); }
.parts li.sel button { background: var(--sel); }
.ptype { color: var(--muted); font-size: 12px; flex: 0 0 auto; }
.netlist { list-style: none; margin: 0; padding: 0; }
.netlist li a { display: block; padding: 4px 0; border-bottom: 1px dashed var(--border); color: var(--text); }
.netlist li a:hover { color: var(--accent); text-decoration: none; }
.actions { display: flex; gap: 8px; margin-top: 12px; }
details summary { cursor: pointer; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary h2 { display: inline; }
details summary::before { content: "▸ "; color: var(--muted); }
details[open] summary::before { content: "▾ "; }
.pager { display: flex; justify-content: space-between; gap: 12px; padding: 8px 16px; border-top: 1px solid var(--border); background: var(--panel); font-size: 14px; flex: 0 0 auto; }
.pager a { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 48%; }
.only-narrow { display: none; }

/* home page */
.crumbs .brand { font-weight: 700; color: var(--text); letter-spacing: -.01em; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); color: var(--text); font-weight: 600; font-size: 14px; }
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent-solid); border-color: var(--accent-solid); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.home-main { width: min(1160px, 100%); margin: 0 auto; padding: 0 16px 56px; flex: 1 0 auto; }
.hero { position: relative; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 24px; align-items: center; padding: 56px 0 36px; }
.kicker { margin: 0 0 12px; font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--accent); }
.hero h1 { margin: 0 0 14px; font-size: clamp(32px, 5vw, 52px); line-height: 1.05; letter-spacing: -.025em; }
.hero .lead { font-size: 17px; line-height: 1.6; max-width: 58ch; margin: 0 0 22px; }
.hero-search { margin: 0 0 18px; position: relative; }
.hero-search input { font-size: 16px; padding: 13px 16px; border-radius: 10px; box-shadow: var(--shadow); }
.hero-search #search-results { position: absolute; left: 0; right: 0; top: 100%; z-index: 5; max-height: 60vh; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.hero-art { width: 100%; height: auto; border-radius: 16px; background: var(--bg-canvas); background-image: radial-gradient(circle, var(--grid-dot) 1px, transparent 1px); background-size: 20px 20px; border: 1px solid var(--border); box-shadow: var(--shadow); }
.hero-nodes rect, .hero-nodes circle { fill: var(--panel); stroke: var(--muted); stroke-width: 2; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; margin: 0 0 32px; }
.stat { background: var(--panel); padding: 18px 20px; display: flex; flex-direction: column; }
.stat b { font-size: 28px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 14px; }
.howto { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 0 0 44px; }
.step { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; box-shadow: var(--shadow); }
.step h3 { margin: 8px 0 6px; font-size: 16px; }
.step p { margin: 0; color: var(--muted); font-size: 14px; }
.step-n { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--accent-bg); color: var(--accent); font-weight: 700; font-size: 13px; }
.browse-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 0 0 8px; }
.browse-head h2 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.area { margin: 22px 0 0; }
.area h3 { margin: 0 0 10px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.sys-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.sys { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; color: var(--text); transition: border-color .12s, transform .12s; }
.sys:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.sys .code { align-self: flex-start; }
.sys-title { font-weight: 600; line-height: 1.3; }
.sys-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--muted); font-size: 13px; }
.chip { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--accent-bg); color: var(--accent); }

/* fuse finder */
.fuse-main { width: min(1100px, 100%); }
.fuse-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; margin: 16px 0 28px; }
.fuse { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; box-shadow: var(--shadow); scroll-margin-top: 80px; }
.fuse[hidden], #relay-table tr[hidden] { display: none; }
.fuse.flash { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.fuse header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.fnum { font-size: 22px; font-weight: 700; min-width: 2ch; }
.amp { padding: 1px 9px; border-radius: 999px; background: var(--accent-bg); color: var(--accent); font-size: 13px; font-weight: 600; }
.hot { margin-left: auto; font-size: 12px; color: var(--muted); }
.fuse ul { margin: 0; padding-left: 18px; font-size: 14px; }
.fuse li { margin: 3px 0; }
.also { color: var(--muted); font-size: 12.5px; }
.detail { display: inline-block; margin-top: 8px; font-size: 13px; }
.fuse.unused { opacity: .55; padding: 8px 14px; }
.fuse.unused .amp { background: transparent; color: var(--muted); }

/* guides */
.guides-home { margin: 0 0 44px; }
.guide-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; margin-top: 10px; }
.guide-card { display: block; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 10px; padding: 16px 18px; box-shadow: var(--shadow); }
.guide-card:hover { border-color: var(--accent); text-decoration: none; }
.guide-card h3 { margin: 4px 0 6px; font-size: 18px; }
.guide-card p { margin: 0; color: var(--muted); font-size: 14px; }
.kind { margin: 0; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.guide-main, .article-main { width: min(820px, 100%); margin: 0 auto; padding: 24px 16px 56px; flex: 1 0 auto; }
.guide-head h1, .article-main h1 { margin: 0 0 6px; font-size: 30px; letter-spacing: -.02em; }
.article-main h2 { margin: 32px 0 8px; font-size: 22px; letter-spacing: -.01em; scroll-margin-top: 16px; }
.article-main .lead { font-size: 17px; }
.article-main p, .article-main li { line-height: 1.65; }
.article-main li { margin: 4px 0; }
.toc { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 8px; }
.toc a { padding: 5px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--panel); color: var(--text); font-size: 14px; }
.toc a:hover { border-color: var(--accent); text-decoration: none; }
table.plain { width: 100%; border-collapse: collapse; font-size: 14px; margin: 12px 0; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; }
table.plain th { text-align: left; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.plain td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.plain tr:last-child td { border-bottom: 0; }
.note { background: var(--panel-2); border-left: 3px solid var(--border); padding: 8px 12px; border-radius: 4px; font-size: 14px; }
.warn { background: #fff1e0; color: #5a2d00; border: 1px solid #f0b36b; border-radius: 8px; padding: 10px 14px; margin: 14px 0; font-size: 14.5px; }
html[data-theme="dark"] .warn { background: #3a2610; color: #ffd9a8; border-color: #7a4a14; }
figure { margin: 16px 0; }
figcaption { color: var(--muted); font-size: 13px; margin-top: 4px; }
.relay-svg { width: min(520px, 100%); height: auto; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 10px; }
.steps { padding-left: 22px; }
.disclaimer { margin-top: 36px; padding-top: 14px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.flow { margin-top: 18px; }
.flow-bar { display: flex; align-items: center; gap: 10px; padding: 8px 0 14px; flex-wrap: wrap; }
.trail { display: flex; flex-wrap: wrap; gap: 4px 6px; list-style: none; margin: 0; padding: 0; flex: 1 1 200px; font-size: 13px; color: var(--muted); min-width: 0; }
.trail li { max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trail li + li::before { content: "›"; margin-right: 6px; }
.trail li[aria-current] { color: var(--text); font-weight: 600; }
.node { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 22px 24px; margin: 0 0 18px; box-shadow: var(--shadow); }
.flow.js .node { display: none; }
.flow.js .node.active { display: block; animation: nodein .18s ease-out; }
@keyframes nodein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .flow.js .node.active { animation: none; } }
.node h2 { margin: 0 0 8px; font-size: 24px; letter-spacing: -.015em; line-height: 1.2; }
.node .lead { margin: 0 0 14px; font-size: 16px; }
.node .steps li { margin: 8px 0; line-height: 1.6; }
.node .links { font-size: 14px; color: var(--muted); margin: 14px 0 0; }
.choices { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.choice { display: block; padding: 13px 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel-2); color: var(--text); font-weight: 500; line-height: 1.4; }
.choice:hover { border-color: var(--accent); background: var(--accent-bg); text-decoration: none; }
.choice::after { content: "  ›"; color: var(--accent); font-weight: 700; }
.choice.again { text-align: center; }
.choice.again::after { content: ""; }
.node.result { border-left: 5px solid var(--accent); }
.node.result .kind { color: var(--accent); margin-bottom: 4px; }
button:disabled { opacity: .45; cursor: default; }

@media (max-width: 900px) {
  .node { padding: 16px; }
  .node h2 { font-size: 21px; }
  .hero { grid-template-columns: 1fr; padding: 32px 0 24px; }
  .hero-art { display: none; }
  .howto { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .stat { padding: 12px; }
  .stat b { font-size: 22px; }
  body.viewer { height: auto; overflow: auto; }
  .page-layout { grid-template-columns: 1fr; }
  #canvas-wrap { height: 62vh; }
  #side { border-left: 0; border-top: 1px solid var(--border); }
  .only-narrow { display: inline-block; }
  .section-name, .hint { display: none; }
  #search-results a, .pages a { grid-template-columns: auto 1fr; }
  .meta { grid-column: 2; white-space: normal; }
}

.affiliate-note { font-size: 13px; color: var(--muted); margin: 4px 0 0; }
.article-main h3 { margin: 22px 0 6px; font-size: 17px; }
