
/* Layout idea: the same engineering notebook as the EM-fields notes. Sticky contents rail, one readable column,
   formula boxes with a coloured stripe; red = output / inverting, blue = input. Shared by every device page. */
:root {
  --paper: #f4f6f9;
  --surface: #ffffff;
  --ink: #142033;
  --muted: #56647a;
  --rule: #d8dee8;
  --accent: #4b3fc4;
  --accent-soft: #ecebfb;
  --pos: #cf3f35;
  --neg: #1f72c4;
  --warn: #a35a00;
  --warn-soft: #fff4e2;
  --ok: #1d7a4f;
  --ok-soft: #e6f5ed;
  --grid: rgba(20, 32, 51, 0.045);
  --font-display: "Newsreader", "Georgia", "Times New Roman", serif;
  --font-body: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0f141c;
    --surface: #171e29;
    --ink: #e5eaf2;
    --muted: #9aa7ba;
    --rule: #2a3444;
    --accent: #a59cff;
    --accent-soft: #232245;
    --pos: #ff7a6e;
    --neg: #5fb0ff;
    --warn: #f0b25a;
    --warn-soft: #2c2214;
    --ok: #5fd39a;
    --ok-soft: #13291f;
    --grid: rgba(229, 234, 242, 0.035);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0f141c;
  --surface: #171e29;
  --ink: #e5eaf2;
  --muted: #9aa7ba;
  --rule: #2a3444;
  --accent: #a59cff;
  --accent-soft: #232245;
  --pos: #ff7a6e;
  --neg: #5fb0ff;
  --warn: #f0b25a;
  --warn-soft: #2c2214;
  --ok: #5fd39a;
  --ok-soft: #13291f;
  --grid: rgba(229, 234, 242, 0.035);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 72px; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16.5px;
  line-height: 1.65;
}
a { color: var(--accent); }
a:focus-visible, button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px;
}

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px max(16px, 3vw);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.brand { font-family: var(--font-mono); font-size: 13px; color: var(--muted); letter-spacing: .02em; }
.brand b { color: var(--ink); font-weight: 500; }
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--rule); border-radius: 999px; padding: 3px; }
.tabs a {
  text-decoration: none; color: var(--muted); font-size: 14px; font-weight: 500;
  padding: 6px 14px; border-radius: 999px;
}
.tabs a[aria-current="page"] { background: var(--accent); color: var(--surface); }

/* hero */
.hero { max-width: 1180px; margin: 0 auto; padding: 40px max(16px, 3vw) 8px; }
.hero h1 {
  font-family: var(--font-display); font-weight: 600; font-size: clamp(30px, 4.4vw, 46px);
  line-height: 1.1; margin: 0 0 10px; text-wrap: balance; letter-spacing: -0.01em;
}
.hero p { margin: 0; max-width: 68ch; color: var(--muted); }
.hero .zh { margin-left: 2px; }

/* lesson layout */
.layout {
  max-width: 1180px; margin: 0 auto; padding: 24px max(16px, 3vw) 80px;
  display: grid; grid-template-columns: 236px minmax(0, 1fr); gap: 40px;
}
nav.toc { position: sticky; top: 72px; align-self: start; max-height: calc(100vh - 90px); overflow-y: auto; font-size: 14px; }
nav.toc h2 { font-family: var(--font-mono); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 18px 0 6px; }
nav.toc h2:first-child { margin-top: 0; }
nav.toc ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
nav.toc a { display: flex; gap: 8px; text-decoration: none; color: var(--ink); padding: 4px 8px; border-radius: 6px; line-height: 1.35; }
nav.toc a span { font-family: var(--font-mono); font-size: 12px; color: var(--muted); min-width: 28px; padding-top: 1px; }
nav.toc a:hover { background: var(--accent-soft); }
nav.toc a.active { background: var(--accent-soft); color: var(--accent); }

main { min-width: 0; }
.part-label {
  font-family: var(--font-mono); font-size: 12.5px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent); margin: 56px 0 4px;
}
.part-label:first-child { margin-top: 0; }
section.lesson { max-width: 760px; padding-top: 8px; margin-bottom: 40px; }
section.lesson > h2 {
  font-family: var(--font-display); font-weight: 600; font-size: 29px; line-height: 1.2;
  margin: 0 0 6px; text-wrap: balance; display: flex; gap: 12px; align-items: baseline;
}
section.lesson > h2 .num { font-family: var(--font-mono); font-size: 15px; font-weight: 500; color: var(--muted); }
h3 { font-size: 18px; font-weight: 600; margin: 28px 0 6px; text-wrap: balance; }
p { margin: 10px 0; }
.lead { color: var(--muted); font-size: 17px; margin-top: 0; }
.zh {
  font-size: 0.82em; font-weight: 500; color: var(--muted);
  border: 1px solid var(--rule); border-radius: 5px; padding: 0 5px; white-space: nowrap;
  background: var(--surface);
}
ul, ol { padding-left: 22px; }
li { margin: 4px 0; }

/* boxes */
.key {
  background: var(--surface); border: 1px solid var(--rule); border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: 14px 18px; margin: 18px 0; overflow-x: auto;
}
.key .tag, .example .tag, .pitfall .tag, .plain .tag {
  font-family: var(--font-mono); font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent); display: block; margin-bottom: 2px;
}
.plain {
  background: var(--ok-soft); border-radius: var(--radius); padding: 12px 16px; margin: 16px 0;
}
.plain .tag { color: var(--ok); }
.pitfall {
  background: var(--warn-soft); border-radius: var(--radius); padding: 12px 16px; margin: 16px 0;
}
.pitfall .tag { color: var(--warn); }
.example {
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 16px 20px; margin: 22px 0; overflow-x: auto;
}
.example h4 { margin: 0 0 6px; font-size: 16.5px; }
.example ol.steps { padding-left: 0; list-style: none; counter-reset: s; margin: 10px 0 0; }
.example ol.steps > li { counter-increment: s; position: relative; padding-left: 34px; margin: 10px 0; }
.example ol.steps > li::before {
  content: counter(s); position: absolute; left: 0; top: 2px;
  width: 22px; height: 22px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  font-family: var(--font-mono); font-size: 12px; display: grid; place-items: center;
}
.math-wide { overflow-x: auto; overflow-y: hidden; }
mjx-container[display="true"] { margin: 0.7em 0 !important; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 15px; margin: 14px 0; background: var(--surface); }
.tbl-wrap { overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--radius); margin: 16px 0; }
.tbl-wrap table.tbl { margin: 0; }
table.tbl th, table.tbl td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--rule); vertical-align: top; }
table.tbl th { font-size: 12.5px; font-family: var(--font-mono); font-weight: 500; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--paper); }
table.tbl tr:last-child td { border-bottom: 0; }

/* widgets */
.widget { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); margin: 22px 0; overflow: hidden; }
.widget-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--rule); }
.widget-head strong { font-size: 15px; }
.widget-head .hint { font-size: 13px; color: var(--muted); }
.widget canvas { display: block; width: 100%; touch-action: none; }
.controls { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--rule); font-size: 14px; }
.controls button {
  font: inherit; font-size: 13.5px; padding: 5px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--rule); background: var(--paper); color: var(--ink);
}
.controls button:hover { border-color: var(--accent); }
.controls button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.controls label { display: flex; align-items: center; gap: 8px; }
.controls input[type="range"] { accent-color: var(--accent); width: 130px; }
.controls output { font-family: var(--font-mono); font-size: 13px; min-width: 42px; display: inline-block; }
.readout { font-family: var(--font-mono); font-size: 13px; color: var(--muted); padding: 0 16px 12px; font-variant-numeric: tabular-nums; }

/* practice */
.q { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 14px 18px; margin: 14px 0; overflow-x: auto; }
.q .qn { font-family: var(--font-mono); font-size: 12px; color: var(--accent); }
.q details { margin-top: 8px; }
.q summary { cursor: pointer; color: var(--accent); font-weight: 500; font-size: 14.5px; }
.q details[open] summary { margin-bottom: 6px; }

/* overview */
.overview { max-width: 1180px; margin: 0 auto; padding: 24px max(16px, 3vw) 80px; }
.ov-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.ov-card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 16px 20px; min-width: 0; overflow-x: auto; }
.ov-card.wide { grid-column: 1 / -1; }
.ov-card h2 { font-family: var(--font-display); font-weight: 600; font-size: 22px; margin: 0 0 4px; text-wrap: balance; }
.ov-card h2 small { font-family: var(--font-mono); font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 8px; }
.ov-card p.sub { margin: 0 0 8px; color: var(--muted); font-size: 14.5px; }
.ov-card table.tbl { font-size: 14.5px; }
.ov-card table.tbl td, .ov-card table.tbl th { padding: 7px 10px; }
.map-svg { width: 100%; height: auto; display: block; }
.map-svg text { font-family: var(--font-body); fill: var(--ink); }
.map-svg .lbl { font-family: var(--font-mono); font-size: 12.5px; fill: var(--muted); }
.flow { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 8px; }
.flow li { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1.15fr); gap: 10px; align-items: center; background: var(--paper); border-radius: 8px; padding: 8px 12px; margin: 0; font-size: 14.5px; }
.flow .arrow { color: var(--accent); font-family: var(--font-mono); }
.check { list-style: none; padding: 0; margin: 6px 0 0; columns: 2 260px; column-gap: 28px; }
.check li { break-inside: avoid; padding-left: 26px; position: relative; font-size: 15px; }
.check li::before { content: ""; position: absolute; left: 2px; top: 6px; width: 13px; height: 13px; border: 1.5px solid var(--accent); border-radius: 3px; }
.pill { display: inline-block; font-family: var(--font-mono); font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); margin-right: 4px; }
.pill.pos { background: color-mix(in srgb, var(--pos) 14%, transparent); color: var(--pos); }
.pill.neg { background: color-mix(in srgb, var(--neg) 14%, transparent); color: var(--neg); }

[hidden] { display: none !important; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; gap: 12px; }
  nav.toc { position: static; max-height: none; border: 1px solid var(--rule); background: var(--surface); border-radius: var(--radius); padding: 12px; }
  nav.toc ol { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
  .ov-grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .brand { display: none; }
  .topbar { justify-content: center; }
  .flow li { grid-template-columns: 1fr; gap: 2px; }
  .flow .arrow { display: none; }
  body { font-size: 16px; }
}

/* ---------- additions for the transistor set ---------- */
.topbar { flex-wrap: wrap; }
.devnav { display: flex; flex-wrap: wrap; gap: 2px; font-size: 14px; }
.devnav a { text-decoration: none; color: var(--muted); padding: 6px 10px; border-radius: 8px; font-weight: 500; }
.devnav a:hover { color: var(--ink); background: var(--surface); }
.devnav a[aria-current="page"] { color: var(--ink); background: var(--surface); box-shadow: inset 0 -2px 0 var(--accent); }

.figs { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; margin: 18px 0; }
figure.ckt-fig { margin: 0; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 10px 12px 12px; min-width: 0; }
figure.ckt-fig figcaption { font-size: 14px; margin-top: 4px; }
figure.ckt-fig figcaption b { display: block; font-size: 14.5px; }
figure.ckt-fig figcaption span { color: var(--muted); font-size: 13.5px; }
svg.ckt { width: 100%; height: auto; display: block; max-height: 260px; }
svg.ckt line, svg.ckt polyline, svg.ckt path.w { stroke: var(--ink); stroke-width: 1.7; fill: none; stroke-linecap: round; stroke-linejoin: round; }
svg.ckt .fill { fill: var(--ink); stroke: none; }
svg.ckt .open { fill: var(--surface); stroke: var(--ink); stroke-width: 1.6; }
svg.ckt text { fill: var(--ink); font-family: var(--font-mono); font-size: 12.5px; }
svg.ckt text.pin { fill: var(--muted); font-size: 10.5px; }
svg.ckt text.note { fill: var(--muted); font-size: 10.5px; }
svg.ckt .in line, svg.ckt .in polyline { stroke: var(--neg); }
svg.ckt .in .open { stroke: var(--neg); }
svg.ckt .in text { fill: var(--neg); font-weight: 500; }
svg.ckt .out line, svg.ckt .out polyline { stroke: var(--pos); }
svg.ckt .out .open { stroke: var(--pos); }
svg.ckt .out text { fill: var(--pos); font-weight: 500; }

.pill.inv { background: color-mix(in srgb, var(--pos) 14%, transparent); color: var(--pos); }
.pill.non { background: var(--ok-soft); color: var(--ok); }
.pill.reg { background: var(--accent-soft); color: var(--accent); }
.pill.bad { background: var(--warn-soft); color: var(--warn); }

.readout.big { font-size: 13.5px; color: var(--ink); line-height: 1.8; padding-top: 10px; }
.readout.big b { font-weight: 500; }
.readout .sep { color: var(--rule); margin: 0 6px; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin: 16px 0; }
.two-col > div { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px 16px; min-width: 0; overflow-x: auto; }
.two-col h4 { margin: 0 0 4px; font-size: 15.5px; }

/* home */
.hub { max-width: 1180px; margin: 0 auto; padding: 8px max(16px, 3vw) 80px; }
.hub-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px; margin-top: 18px; }
a.hub-card { display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: var(--ink); background: var(--surface); border: 1px solid var(--rule); border-radius: 14px; padding: 18px 20px; transition: border-color .15s, transform .15s; }
a.hub-card:hover { border-color: var(--accent); transform: translateY(-2px); }
@media (prefers-reduced-motion: reduce) { a.hub-card { transition: none; } a.hub-card:hover { transform: none; } }
a.hub-card .step { font-family: var(--font-mono); font-size: 12px; color: var(--accent); letter-spacing: .06em; text-transform: uppercase; }
a.hub-card h2 { font-family: var(--font-display); font-weight: 600; font-size: 26px; margin: 0; }
a.hub-card p { margin: 0; color: var(--muted); font-size: 15px; }
a.hub-card ul { margin: 4px 0 0; padding-left: 18px; font-size: 14.5px; }
a.hub-card svg.ckt { max-height: 110px; width: auto; align-self: flex-start; }
.hub-note { margin-top: 26px; max-width: 760px; }

/* 中文排版；保留原有页面布局、主题与交互。 */
:root {
  --font-display: "Newsreader", "Noto Serif CJK SC", "Source Han Serif SC", "Songti SC", "SimSun", serif;
  --font-body: "IBM Plex Sans", "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", Consolas, "Microsoft YaHei", "PingFang SC", monospace;
}
.hero h1 { line-height: 1.3; }
section.lesson > h2 { line-height: 1.4; }
body { line-height: 1.8; }
.hero p { max-width: 70ch; }
.figs { grid-template-columns: repeat(auto-fit, minmax(min(230px, 100%), 1fr)); }
.two-col { grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); }
.hub-grid { grid-template-columns: repeat(auto-fit, minmax(min(250px, 100%), 1fr)); }
a.hub-card > div[style*="display:flex"] > [data-symbol] { flex: 0 0 56px; }
a.hub-card > div[style*="display:flex"] svg.ckt { width: 56px; height: 110px; }
.plain, .pitfall { overflow-x: auto; }
.lesson, .readout { overflow-wrap: anywhere; }
.controls label { max-width: 100%; flex-wrap: wrap; }
.devnav a, .tabs a { white-space: nowrap; }
@media (max-width: 520px) {
  html { scroll-padding-top: 150px; }
  .topbar { gap: 8px; padding: 8px 12px; }
  .devnav { justify-content: center; font-size: 13px; }
  .devnav a { padding: 5px 7px; }
  .hero h1 { font-size: 30px; }
}
