/* 配線道場 — 樣式
   調色盤：配電箱鈑金灰綠 + 三用電表黃 + 銅線橘；電線四色（黑紅白綠）當語意色 */
:root {
  --bg: #E6EAE5;
  --surface: #F6F8F4;
  --surface-2: #DCE2DB;
  --ink: #16201D;
  --ink-2: #4A5752;
  --ink-3: #75817C;
  --line: #BAC4BD;
  --accent: #F2B705;
  --accent-ink: #1D1700;
  --accent-soft: #FBE9A6;
  --copper: #A9561F;
  --ok: #1F7A4A;
  --ok-soft: #D3EEDC;
  --bad: #BF3326;
  --bad-soft: #F7DAD5;
  --warn: #9A6410;
  --warn-soft: #F7E7C4;
  --enclosure: #C9D0CA;
  --enclosure-edge: #A5AEA7;
  --breaker: #FAFAF6;
  --breaker-edge: #C6CDC7;
  --breaker-ink: #1C2421;
  --board: #DCC6A0;
  --board-grain: #CDB38A;
  --board-edge: #B08F60;
  --board-ink: #3D2F1B;
  --plate: #FBFBF7;
  --plate-edge: #9FA69F;
  --plate-ink: #1F2522;
  --bulb-off: #ECECE4;
  --water: #5C9FD6;
  --wire-halo: rgba(18, 26, 23, .55);
  --w-black: #1B1B1B;
  --w-red: #D0312D;
  --w-white: #F7F7F2;
  --w-green: #2A9D4B;
  --w-blue: #2463C6;
  --focus: #1D6FD1;
  --font-display: "Chiron GoRound TC", "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", sans-serif;
  --font-body: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", "Heiti TC", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --radius: 10px;
  /* 「電從發電廠到你家」插圖：淺色是白天，深色是夜景 */
  --art-sky-1: #B9DCF2; --art-sky-2: #EEF7FC; --art-cloud: #FFFFFF;
  --art-hill: #BCD5B0; --art-hill-2: #D3E3CD; --art-ground: #A9C290; --art-ground-2: #93AD7B;
  --art-gravel: #C9C6BB; --art-soil: #C7A77F; --art-road: #8E9295; --art-walk: #D5D2C8;
  --art-steel: #75818B; --art-wire: #394047; --art-insul: #7F98A8; --art-porc: #9C5A3C;
  --art-bldg: #E4E0D5; --art-bldg-2: #C8C2B2; --art-bldg-3: #E8DCCB; --art-win: #A7C9DF;
  --art-metal: #B5BCC2; --art-tank: #8D9D92; --art-tank-2: #74847A; --art-pole: #BDB9AE;
  --art-tree: #6D9B58; --art-wall: #EFE8DA; --art-floor: #B8936D; --art-ink: #2A2F2C;
}

/* 深色：系統為深色時自動套用；頁面上的「淺色／深色」開關（data-app-theme）優先於系統與外框設定 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-app-theme="light"]) {
    color-scheme: dark;
    --bg: #101614;
    --surface: #18201D;
    --surface-2: #222B28;
    --ink: #E3E9E5;
    --ink-2: #A5B2AC;
    --ink-3: #76847E;
    --line: #34413C;
    --accent-soft: #4A3C0A;
    --copper: #E0894E;
    --ok: #52C585;
    --ok-soft: #163726;
    --bad: #F2705F;
    --bad-soft: #401D19;
    --warn: #E7AC3E;
    --warn-soft: #3B2D10;
    --enclosure: #2A3330;
    --enclosure-edge: #3D4945;
    --breaker: #D9DDD8;
    --breaker-edge: #98A29C;
    --board: #4A3C2A;
    --board-grain: #574733;
    --board-edge: #2E2518;
    --board-ink: #EBDCC1;
    --plate: #D8DCD6;
    --plate-edge: #7D877F;
    --bulb-off: #3A413E;
    --water: #4F8FC4;
    --wire-halo: rgba(232, 238, 234, .55);
    --focus: #6FA8FF;
    --art-sky-1: #111C2E; --art-sky-2: #2A3B52; --art-cloud: #3A4A60;
    --art-hill: #22322C; --art-hill-2: #283A37; --art-ground: #2C3A29; --art-ground-2: #25311F;
    --art-gravel: #45453F; --art-soil: #4B3E30; --art-road: #34383B; --art-walk: #4A4943;
    --art-steel: #A2ADB7; --art-wire: #C6CDD4; --art-insul: #A9C0CD; --art-porc: #BD7552;
    --art-bldg: #5F5C56; --art-bldg-2: #4D4A45; --art-bldg-3: #625A50; --art-win: #E8C66E;
    --art-metal: #8E969D; --art-tank: #6C7C72; --art-tank-2: #58675E; --art-pole: #8B887F;
    --art-tree: #37543A; --art-wall: #34322D; --art-floor: #4A3A2C; --art-ink: #E6EBE7;
  }
}
:root[data-theme="dark"]:not([data-app-theme="light"]),
:root[data-app-theme="dark"] {
  color-scheme: dark;
  --bg: #101614;
  --surface: #18201D;
  --surface-2: #222B28;
  --ink: #E3E9E5;
  --ink-2: #A5B2AC;
  --ink-3: #76847E;
  --line: #34413C;
  --accent-soft: #4A3C0A;
  --copper: #E0894E;
  --ok: #52C585;
  --ok-soft: #163726;
  --bad: #F2705F;
  --bad-soft: #401D19;
  --warn: #E7AC3E;
  --warn-soft: #3B2D10;
  --enclosure: #2A3330;
  --enclosure-edge: #3D4945;
  --breaker: #D9DDD8;
  --breaker-edge: #98A29C;
  --board: #4A3C2A;
  --board-grain: #574733;
  --board-edge: #2E2518;
  --board-ink: #EBDCC1;
  --plate: #D8DCD6;
  --plate-edge: #7D877F;
  --bulb-off: #3A413E;
  --water: #4F8FC4;
  --wire-halo: rgba(232, 238, 234, .55);
  --focus: #6FA8FF;
  --art-sky-1: #111C2E; --art-sky-2: #2A3B52; --art-cloud: #3A4A60;
  --art-hill: #22322C; --art-hill-2: #283A37; --art-ground: #2C3A29; --art-ground-2: #25311F;
  --art-gravel: #45453F; --art-soil: #4B3E30; --art-road: #34383B; --art-walk: #4A4943;
  --art-steel: #A2ADB7; --art-wire: #C6CDD4; --art-insul: #A9C0CD; --art-porc: #BD7552;
  --art-bldg: #5F5C56; --art-bldg-2: #4D4A45; --art-bldg-3: #625A50; --art-win: #E8C66E;
  --art-metal: #8E969D; --art-tank: #6C7C72; --art-tank-2: #58675E; --art-pole: #8B887F;
  --art-tree: #37543A; --art-wall: #34322D; --art-floor: #4A3A2C; --art-ink: #E6EBE7;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.7;
}
h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.3; text-wrap: balance; margin: 0; }
p { margin: 0; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.mono, .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
b, strong { font-weight: 700; }

/* ---------- 頂列 ---------- */
.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; flex: none; }
.topbar-right { display: flex; align-items: center; gap: 14px; min-width: 0; }

/* 背景顏色開關：三段式，選中的那段用電表黃，跟配電盤把手同色 */
.theme-switch {
  display: inline-flex; gap: 2px; padding: 3px; flex: none;
  border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line);
}
.theme-switch button {
  display: inline-flex; align-items: center; gap: 5px;
  min-height: 30px; padding: 3px 11px; border: 0; border-radius: 999px;
  background: transparent; color: var(--ink-2);
  font-size: 13px; font-weight: 500; line-height: 1;
  transition: background .15s, color .15s;
}
.theme-switch button:hover { color: var(--ink); }
.theme-switch button[aria-pressed="true"] {
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}
.theme-switch svg {
  width: 16px; height: 16px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}
.brand-mark { width: 30px; height: 30px; flex: none; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 20px; letter-spacing: .04em; }
.overall { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink-2); }
.overall-bar { width: 120px; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.overall-bar > i { display: block; height: 100%; background: var(--accent); transition: width .5s; }
.overall .num { color: var(--ink); font-weight: 700; }

.wrap { max-width: 1200px; margin: 0 auto; padding-inline: 16px; padding-block: 24px 64px; }

/* ---------- 共用元件 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 6px 16px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink);
  font-weight: 500; font-size: 15px; line-height: 1.2;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: #C99700; color: var(--accent-ink); font-weight: 700; }
.btn-primary:hover { border-color: var(--accent-ink); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-ghost { background: transparent; }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.muted { color: var(--ink-2); }
.small { font-size: 14px; }
.tiny { font-size: 12px; }
.eyebrow { font-size: 12px; letter-spacing: .12em; color: var(--ink-3); font-weight: 700; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 10px; border-radius: 999px; font-size: 13px; font-weight: 700;
  background: var(--surface-2); color: var(--ink-2);
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.kbd { font-family: var(--font-mono); font-size: 12px; padding: 0 5px; border: 1px solid var(--line); border-radius: 4px; }
.stars { color: var(--accent); letter-spacing: 2px; font-size: 14px; }
.stars .off { color: var(--line); }

.callout { border-radius: 8px; padding: 12px 14px; font-size: 15px; background: var(--surface-2); }
.callout.ok { background: var(--ok-soft); }
.callout.bad { background: var(--bad-soft); }
.callout.warn { background: var(--warn-soft); }
.callout b { font-weight: 700; }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(20px);
  max-width: min(560px, calc(100% - 32px));
  padding: 12px 18px; border-radius: 10px;
  background: var(--ink); color: var(--bg);
  font-size: 15px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--bad); color: #fff; }
#toast.ok { background: var(--ok); color: #fff; }

/* ---------- 首頁 ---------- */
.hero { display: grid; gap: 8px; margin-bottom: 24px; max-width: 760px; }
.hero h1 { font-size: clamp(34px, 6vw, 52px); letter-spacing: .06em; }
.hero h1 .spec { font-family: var(--font-mono); font-size: .32em; letter-spacing: 0; vertical-align: middle; color: var(--copper); border: 1.5px solid currentColor; border-radius: 4px; padding: 2px 6px; margin-left: 10px; }
.hero p { color: var(--ink-2); font-size: 17px; max-width: 62ch; }

.enclosure {
  position: relative;
  background: var(--enclosure);
  border: 2px solid var(--enclosure-edge);
  border-radius: 16px;
  padding: 44px 22px 22px;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.25), 0 6px 24px rgba(0,0,0,.08);
}
.enclosure::before, .enclosure::after {
  content: ""; position: absolute; top: 14px; width: 12px; height: 12px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff 0 20%, #9aa39c 60%, #6d766f);
}
.enclosure::before { left: 14px; }
.enclosure::after { right: 14px; }
.enclosure-plate {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  font-family: var(--font-mono); font-size: 12px; letter-spacing: .08em;
  background: var(--breaker); color: var(--breaker-ink);
  padding: 2px 12px; border-radius: 4px; border: 1px solid var(--breaker-edge); white-space: nowrap;
}
.panel-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.branches { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }

.breaker {
  position: relative; display: grid; grid-template-rows: auto auto 1fr auto; gap: 8px;
  text-align: left; padding: 14px; border-radius: 10px;
  background: var(--breaker); color: var(--breaker-ink);
  border: 1px solid var(--breaker-edge);
  box-shadow: 0 2px 0 var(--breaker-edge);
  text-decoration: none; min-height: 210px;
  transition: transform .12s, box-shadow .12s;
}
.breaker:hover { transform: translateY(-2px); box-shadow: 0 4px 0 var(--breaker-edge); }
.breaker .b-top { display: flex; justify-content: space-between; align-items: baseline; font-family: var(--font-mono); font-size: 12px; color: #56615B; }
.breaker .b-name { font-family: var(--font-display); font-size: 20px; font-weight: 700; }
.breaker .b-desc { font-size: 14px; color: #4C5751; line-height: 1.55; }
.breaker .b-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.b-handle-wrap { display: flex; align-items: center; gap: 10px; }
.b-slot { position: relative; width: 26px; height: 44px; border-radius: 5px; background: #2A302D; box-shadow: inset 0 2px 4px rgba(0,0,0,.5); flex: none; }
.b-handle { position: absolute; left: 3px; right: 3px; height: 20px; border-radius: 3px; background: linear-gradient(#5b6560, #3a423e); transition: top .25s cubic-bezier(.5,1.6,.5,1); top: 21px; }
.breaker.on .b-handle { top: 3px; background: linear-gradient(#F7C930, #D89F00); }
.b-state { font-family: var(--font-mono); font-size: 13px; font-weight: 700; color: #6A746E; }
.breaker.on .b-state { color: #1B7D45; }
.b-prog { height: 5px; border-radius: 3px; background: #DDE2DD; overflow: hidden; }
.b-prog > i { display: block; height: 100%; background: #1B7D45; }
.breaker.main { display: flex; align-items: center; gap: 18px; min-height: 0; padding: 14px 18px; }
.main-body { flex: 1; display: grid; gap: 4px; min-width: 0; }
.main-row { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.breaker.spare { background: repeating-linear-gradient(135deg, var(--breaker) 0 10px, #e9ece8 10px 20px); opacity: .8; cursor: default; }
.breaker.spare:hover { transform: none; box-shadow: 0 2px 0 var(--breaker-edge); }
.breaker.main .b-slot { width: 34px; height: 60px; }
.breaker.main .b-handle { height: 28px; top: 29px; }
.breaker.main.on .b-handle { top: 3px; }
.main-pct { font-family: var(--font-mono); font-size: 40px; font-weight: 700; line-height: 1; }

.home-lower { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; margin-top: 28px; }
.home-lower h2 { font-size: 20px; margin-bottom: 10px; }
.exam-facts { display: grid; gap: 10px; font-size: 15px; }
.exam-facts dt { font-weight: 700; }
.exam-facts dd { margin: 0 0 6px; color: var(--ink-2); }
.route-list { margin: 0; padding-left: 1.3em; display: grid; gap: 6px; font-size: 15px; color: var(--ink-2); }
.route-list b { color: var(--ink); }

/* ---------- 章節頁 ---------- */
.ch-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.ch-head h1 { font-size: clamp(26px, 4vw, 36px); }
.ch-head .back { text-decoration: none; font-size: 14px; color: var(--ink-2); display: inline-flex; gap: 6px; margin-bottom: 6px; }
.ch-head .back:hover { color: var(--ink); }
.circuit-tag { font-family: var(--font-mono); font-size: 12px; color: var(--copper); border: 1.5px solid currentColor; border-radius: 4px; padding: 1px 6px; margin-right: 8px; vertical-align: middle; }

/* 課程卡 */
.lesson { display: grid; grid-template-columns: 220px 1fr; gap: 24px; align-items: start; }
.toc { position: sticky; top: calc(76px + env(safe-area-inset-top, 0px)); display: grid; gap: 2px; }
.toc button {
  text-align: left; border: 0; background: transparent; border-radius: 6px;
  padding: 7px 10px; font-size: 14px; color: var(--ink-2); display: flex; gap: 8px; align-items: baseline;
}
.toc button .n { font-family: var(--font-mono); font-size: 12px; color: var(--ink-3); width: 1.6em; flex: none; }
.toc button.cur { background: var(--surface); color: var(--ink); font-weight: 700; box-shadow: inset 3px 0 0 var(--accent); }
.toc button.seen .n { color: var(--ok); }
.lesson-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: clamp(18px, 3vw, 32px); display: grid; gap: 18px; min-width: 0; }
.lesson-card > * { min-width: 0; }
.lesson-card h2 { font-size: clamp(22px, 3vw, 28px); }
.lesson-card .prose { display: grid; gap: 12px; max-width: 68ch; }
.lesson-card .prose ul, .lesson-card .prose ol { margin: 0; padding-left: 1.3em; display: grid; gap: 4px; }
.lesson-nav { display: flex; justify-content: space-between; gap: 8px; border-top: 1px solid var(--line); padding-top: 16px; }
.figure { background: var(--surface-2); border-radius: 10px; padding: 16px; overflow-x: auto; }
.figure svg { display: block; width: 100%; height: auto; max-width: 720px; margin: 0 auto; }
.figure > svg { min-width: 480px; }
.figcap { font-size: 13px; color: var(--ink-3); margin-top: 8px; text-align: center; }
.term-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.term-table th, .term-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.term-table th { font-size: 13px; color: var(--ink-3); font-weight: 700; }
.table-scroll { overflow-x: auto; }
.chip-wire { display: inline-block; width: 30px; height: 10px; border-radius: 5px; vertical-align: middle; margin-right: 8px; box-shadow: 0 0 0 1.5px var(--wire-halo); }

.lab { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: center; }
.lab-controls { display: grid; gap: 14px; }
.slider-row { display: grid; gap: 4px; }
.slider-row label { display: flex; justify-content: space-between; font-size: 14px; color: var(--ink-2); }
.slider-row label .num { color: var(--ink); font-weight: 700; font-size: 16px; }
input[type="range"] { width: 100%; accent-color: var(--copper); }
.readouts { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.readout { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
.readout .k { font-size: 12px; color: var(--ink-3); }
.readout .v { font-family: var(--font-mono); font-size: 22px; font-weight: 700; }
.appl-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.appl { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-size: 14px; cursor: pointer; }
.appl input { accent-color: var(--copper); }
.appl .w { margin-left: auto; font-family: var(--font-mono); font-size: 12px; color: var(--ink-3); }
.loadbar { height: 18px; border-radius: 9px; background: var(--surface-2); overflow: hidden; position: relative; }
.loadbar > i { display: block; height: 100%; background: var(--ok); transition: width .3s, background .3s; }
.loadbar.hot > i { background: var(--warn); }
.loadbar.trip > i { background: var(--bad); }
.loadbar .mark { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); left: 80%; }

/* 居家用電規劃：分頁、電器、分路卡 */
.stack > .seg { align-self: flex-start; }
.slider-row > .seg { justify-self: start; }
.seg-wrap { flex-wrap: wrap; border-radius: 18px; max-width: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 4px 12px;
  border: 1.5px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink);
  font-size: 14px; font-weight: 500; line-height: 1.2;
}
.chip:hover { border-color: var(--ink-3); }
.chip.sel { border-color: #C99700; background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.chip.on { min-height: 30px; padding: 2px 10px; font-size: 13px; background: var(--surface-2); }
.chip .tag { padding: 0 6px; border-radius: 999px; font-size: 11px; font-weight: 700; background: var(--surface-2); color: var(--ink-2); }
.chip.sel .tag { background: rgba(0, 0, 0, .12); color: inherit; }
.branch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); gap: 10px; }
.branch-card { display: grid; gap: 8px; align-content: start; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface); min-width: 0; }
.branch-card.warn { border-color: var(--warn); }
.branch-card.trip { border-color: var(--bad); background: var(--bad-soft); }
.branch-card .loadbar, .plan-leg .loadbar { height: 12px; }

/* 電從發電廠到你家：每一站的插圖與編號說明 */
.stn-panel { display: grid; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); min-width: 0; }
.stn-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stn-title h3 { font-size: 20px; }
.stn-art { position: relative; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.stn-art svg { display: block; width: 100%; height: auto; }
.spot-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 4px 12px; }
.spot-list li { display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 8px; align-items: start; padding: 6px 8px; border-radius: 8px; font-size: 15px; cursor: pointer; }
.spot-list li:hover { background: var(--surface-2); }
.spot-list li.on { background: var(--accent-soft); }
.spot-n, .ga-pin { display: grid; place-items: center; border-radius: 50%; border: 2px solid #1B1F1D; background: #F2B705; color: #1B1F1D; font: 700 12px/1 var(--font-mono); }
.spot-n { width: 22px; height: 22px; margin-top: 2px; }
.ga-pin { position: absolute; width: 24px; height: 24px; padding: 0; transform: translate(-50%, -50%); box-shadow: 0 1px 3px rgba(0, 0, 0, .35); }
.ga-pin.on { background: #FFFFFF; border-color: #D0312D; box-shadow: 0 0 0 4px rgba(242, 183, 5, .65); z-index: 1; }
.ga-sign { font: 700 10px var(--font-body); fill: #1B1B1B; }
.ga-red { fill: #C62828; }
.ga-tiny { font: 700 8px var(--font-body); fill: #3A3F3C; }
.ga-cap { font: 700 11px var(--font-body); fill: var(--art-ink); }
.stn-nav { justify-content: space-between; }

/* 測驗 */
.quiz { display: grid; gap: 16px; max-width: 760px; }
.quiz-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 14px; color: var(--ink-2); }
.quiz-prog { flex: 1; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.quiz-prog > i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.quiz-q { font-size: 19px; font-weight: 700; line-height: 1.6; }
.quiz-opts { display: grid; gap: 8px; }
.quiz-opt {
  text-align: left; display: flex; gap: 12px; align-items: baseline;
  padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 16px;
}
.quiz-opt:hover:not([disabled]) { border-color: var(--ink-3); }
.quiz-opt .letter { font-family: var(--font-mono); font-weight: 700; color: var(--ink-3); flex: none; }
.quiz-opt.right { border-color: var(--ok); background: var(--ok-soft); }
.quiz-opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.quiz-opt.picked { border-color: var(--ink); }
.quiz-opt[disabled] { cursor: default; }
.score-big { font-family: var(--font-mono); font-size: 56px; font-weight: 700; line-height: 1; }
.review { display: grid; gap: 12px; }
.review-item { border-left: 3px solid var(--bad); padding: 4px 0 4px 14px; display: grid; gap: 4px; font-size: 15px; }

/* ---------- 配線工坊 ---------- */
.lvl-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 16px; }
.lvl-chip {
  flex: none; display: grid; gap: 2px; text-align: left; min-width: 132px;
  padding: 8px 12px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface);
}
.lvl-chip .n { font-family: var(--font-mono); font-size: 12px; color: var(--ink-3); }
.lvl-chip .t { font-weight: 700; font-size: 14px; }
.lvl-chip.cur { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.wb { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
.wb-main { display: grid; gap: 10px; min-width: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.palette { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px 5px 6px;
  border: 1.5px solid var(--line); border-radius: 999px; background: var(--surface); font-size: 13px;
}
.swatch i { width: 18px; height: 18px; border-radius: 50%; box-shadow: 0 0 0 1.5px var(--wire-halo); }
.swatch.cur { border-color: var(--ink); background: var(--surface-2); font-weight: 700; }
.board-wrap {
  border-radius: 12px; overflow-x: auto; overflow-y: hidden; border: 2px solid var(--board-edge);
  background: var(--board); touch-action: manipulation; overscroll-behavior-x: contain;
}
.board-wrap svg { display: block; width: 100%; height: auto; user-select: none; -webkit-user-select: none; }
/* 窄螢幕：板子維持可點的大小，改在框內左右滑動 */
.scroll-hint { display: none; font-size: 13px; color: var(--ink-3); }
.status-line { font-size: 14px; color: var(--ink-2); min-height: 1.7em; }
.wb-side { display: grid; gap: 14px; }
.wb-side h3 { font-size: 18px; }
.steps { margin: 0; padding-left: 1.3em; display: grid; gap: 6px; font-size: 15px; }
details.hint summary { cursor: pointer; font-weight: 700; font-size: 15px; }
details.hint[open] summary { margin-bottom: 8px; }
.result-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 14px; }
.result-list li { display: grid; grid-template-columns: 22px 1fr; gap: 6px; }
.result-list .ic { font-weight: 700; }
.result-list .fail .ic { color: var(--bad); }
.result-list .safety .ic { color: var(--warn); }
.result-list .style .ic { color: var(--warn); }
.result-list .pass .ic { color: var(--ok); }
.truth { border-collapse: collapse; font-size: 13px; width: 100%; }
.truth th, .truth td { border: 1px solid var(--line); padding: 3px 6px; text-align: center; font-family: var(--font-mono); }
.truth th { font-family: var(--font-body); font-weight: 700; color: var(--ink-2); }
.truth td.bad { background: var(--bad-soft); color: var(--bad); font-weight: 700; }

/* SVG 配線板 */
.term { cursor: crosshair; }
.term-hit { fill: transparent; }
.term-screw { fill: #D8D2C2; stroke: #5B5446; stroke-width: 1.5; }
.term:hover .term-screw, .term.pending .term-screw { fill: var(--accent); stroke: #6B5200; }
.term.pending .term-hit { fill: rgba(242, 183, 5, .35); }
.term-slot { stroke: #5B5446; stroke-width: 1.6; }
.term-label { font-size: 13px; font-weight: 700; fill: var(--board-ink); font-family: var(--font-body); pointer-events: none; }
.part-title { font-size: 14px; font-weight: 700; fill: var(--board-ink); font-family: var(--font-body); }
.part-note { font-size: 12px; fill: var(--board-ink); opacity: .8; font-family: var(--font-body); }
.plate { fill: var(--plate); stroke: var(--plate-edge); stroke-width: 1.5; }
.plate-ink { fill: var(--plate-ink); font-family: var(--font-mono); font-size: 12px; }
.lead { stroke: #6F6A5E; stroke-width: 2; fill: none; }
.contact { stroke: var(--plate-ink); stroke-width: 3; stroke-linecap: round; fill: none; }
.sw-live { cursor: pointer; }
.sw-live:hover .plate { stroke: var(--accent); stroke-width: 3; }
.wire-hit { stroke: transparent; stroke-width: 16; fill: none; cursor: pointer; }
.wire-halo { stroke: var(--wire-halo); stroke-width: 7.5; fill: none; stroke-linecap: round; }
.wire-core { stroke-width: 4.5; fill: none; stroke-linecap: round; pointer-events: none; }
.wire-sel { stroke: var(--focus); stroke-width: 12; fill: none; opacity: .45; stroke-linecap: round; }
.rubber { stroke-width: 3.5; fill: none; stroke-dasharray: 8 6; pointer-events: none; }
.trip-flash { animation: trip 1.4s ease-out forwards; pointer-events: none; }

/* 電箱工坊：端子台零件盒、馬達風扇 */
.asm-tray { display: flex; flex-wrap: wrap; gap: 8px; }
.asm-part { display: grid; justify-items: center; gap: 4px; min-width: 96px; padding: 8px 10px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 13px; font-weight: 500; }
.asm-part:hover { border-color: var(--accent); }
.asm-ic { display: block; width: 44px; height: 30px; border-radius: 4px; }
.asm-ic.rail { height: 12px; margin: 9px 0; background: repeating-linear-gradient(90deg, #aeb5bb 0 14px, #7d858c 14px 17px); }
.asm-ic.stop { width: 16px; background: #3f4448; }
.asm-ic.tb { width: 20px; background: #cfd3cf; box-shadow: inset 0 0 0 1.5px #7d8580; }
.asm-ic.pe { width: 20px; background: repeating-linear-gradient(45deg, #2a9d4b 0 5px, #e8c93a 5px 10px); }
.asm-ic.end { width: 6px; background: #9ea4a0; }
.asm-ic.mark { width: 40px; height: 14px; margin: 8px 0; background: #fff; box-shadow: inset 0 0 0 1.5px #8a908b; }
.asm-list li.cur .ic { color: var(--accent-ink); background: var(--accent); border-radius: 50%; text-align: center; }
.board-wrap.asm-wrap svg { width: 100%; max-width: 100%; }
.box-fan { transform-box: fill-box; transform-origin: center; }
.box-fan.spin { animation: fan-spin .7s linear infinite; }
.box-fan.spin.rev { animation-direction: reverse; }
@keyframes fan-spin { to { transform: rotate(360deg); } }
@keyframes trip { 0% { opacity: .9; } 100% { opacity: 0; } }

/* ---------- 三用電表 ---------- */
.meter-lab { display: grid; grid-template-columns: minmax(260px, 380px) minmax(0, 1fr); gap: 22px; align-items: start; }
.meter-col { display: grid; gap: 12px; position: sticky; top: calc(70px + env(safe-area-inset-top, 0px)); }
.meter-svg { width: 100%; height: auto; display: block; max-width: 380px; margin: 0 auto; }
.meter-svg .sel-hit { cursor: pointer; fill: transparent; }
.meter-svg .sel-lab { font-family: var(--font-mono); font-size: 11.5px; font-weight: 700; pointer-events: none; }
.adj-row { display: grid; grid-template-columns: auto auto 1fr auto; gap: 8px; align-items: center; font-size: 14px; }
.probe-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.probe-btn { border: 2px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 10px; text-align: left; font-size: 14px; display: grid; gap: 2px; }
.probe-btn .pname { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.probe-btn .pdot { width: 12px; height: 12px; border-radius: 50%; }
.probe-btn .ploc { font-size: 12px; color: var(--ink-2); }
.probe-btn.armed { border-color: var(--ink); background: var(--surface-2); }
.read-hint { font-size: 14px; }
.bench { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.item { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: grid; gap: 8px; align-content: start; }
.item h4 { font-size: 15px; font-family: var(--font-body); }
.item .spec { font-family: var(--font-mono); font-size: 12px; color: var(--ink-3); }
.item svg { width: 100%; height: 70px; }
.tps { display: flex; flex-wrap: wrap; gap: 6px; }
.tp-btn { border: 1.5px solid var(--line); background: var(--surface-2); border-radius: 6px; padding: 3px 9px; font-size: 13px; display: inline-flex; align-items: center; gap: 5px; }
.tp-btn:hover { border-color: var(--ink-3); }
.tp-btn .pin { width: 9px; height: 9px; border-radius: 50%; }
.tp-btn.has-red { border-color: var(--w-red); }
.tp-btn.has-black { border-color: var(--ink); }
.task-card { border: 2px solid var(--accent); background: var(--surface); border-radius: 12px; padding: 16px 18px; display: grid; gap: 10px; }
.task-card h3 { font-size: 19px; }
.task-card .prose { font-size: 15px; line-height: 1.8; }
.task-steps { display: flex; gap: 4px; flex-wrap: wrap; }
.task-steps i { width: 22px; height: 6px; border-radius: 3px; background: var(--surface-2); }
.task-steps i.done { background: var(--ok); }
.task-steps i.cur { background: var(--accent); }
.probe-btn[disabled] { cursor: default; }

/* 工作台操作方式切換（和背景開關同一種樣式） */
.bench-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
.seg button {
  min-height: 32px; padding: 3px 14px; border: 0; border-radius: 999px;
  background: transparent; color: var(--ink-2); font-size: 14px; font-weight: 500; line-height: 1;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 700; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); }

/* 3D 工作台 */
.bench3d {
  position: relative; aspect-ratio: 16 / 10.5; min-height: 280px; max-height: 74vh;
  border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: var(--surface-2);
}
.bench3d > canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.b3d-labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.b3d-label {
  position: absolute; left: 0; top: 0; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 700; line-height: 1.5; white-space: nowrap;
  color: var(--ink); background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .22);
  opacity: .92; will-change: transform;
}
.b3d-tag { background: var(--accent); color: var(--accent-ink); opacity: 1; z-index: 2; }
.b3d-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-2); font-size: 14px; }
.b3d-reset { position: absolute; top: 10px; right: 10px; z-index: 3; }

/* 3D 配線板 */
.board3d {
  position: relative; aspect-ratio: 16 / 10; min-height: 300px; max-height: 76vh;
  border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: var(--surface-2);
}
.board3d > canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.b3d-title { font-size: 11.5px; padding: 1px 8px; }
.b3d-term { font-size: 11px; padding: 0 6px; opacity: .88; }
.b3d-term .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: middle; box-shadow: 0 0 0 1px rgba(0, 0, 0, .35); }
.b3d-state { font-size: 11px; background: var(--surface-2); }
.b3d-badge { background: #1B7D45; color: #fff; font-family: var(--font-mono); opacity: 1; }
.b3d-badge.bad { background: #8a2a20; }
.b3d-flash {
  position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; pointer-events: none;
  background: rgba(226, 59, 46, .35); color: #fff; text-shadow: 0 2px 0 #7a120b;
  font-family: var(--font-display); font-size: clamp(28px, 5vw, 52px); font-weight: 700;
}
.b3d-flash.go { animation: trip 1.4s ease-out forwards; }
.b3d-state.bad { background: var(--bad); color: #fff; }
.b3d-legend {
  position: absolute; left: 10px; bottom: 10px; z-index: 3; pointer-events: none;
  display: flex; flex-wrap: wrap; gap: 4px 12px; padding: 4px 12px; border-radius: 999px;
  background: var(--surface); color: var(--ink); font-size: 12px; font-weight: 700; box-shadow: 0 1px 3px rgba(0, 0, 0, .22);
}
.b3d-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .35); }

/* 3D 故障偵探：量測點編號 */
.b3d-tp {
  min-width: 20px; padding: 0 5px; text-align: center;
  font-family: var(--font-mono); font-size: 11px; line-height: 18px;
  background: var(--ink); color: var(--bg); opacity: .9;
}
.b3d-tp.red { background: var(--w-red); color: #fff; opacity: 1; }
.b3d-tp.black { background: #1b1b1b; color: #fff; box-shadow: 0 0 0 2px var(--accent); opacity: 1; }
.b3d-labels.narrow .b3d-tp { font-size: 10px; min-width: 15px; line-height: 14px; padding: 0 3px; }
.b3d-labels.narrow .b3d-label:not(.b3d-tp) { font-size: 10.5px; padding: 0 6px; }

.answer-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.answer-row input { width: 130px; min-height: 40px; padding: 6px 10px; border: 1.5px solid var(--line); border-radius: 8px; background: var(--surface); font-family: var(--font-mono); font-size: 16px; }

/* ---------- 故障偵探 ---------- */
.fault { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 18px; align-items: start; }
.fault > .stack, .fault > aside, .wb > *, .meter-lab > * { min-width: 0; }
.schem-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; overscroll-behavior-x: contain; }
.schem-wrap svg { display: block; width: 100%; min-width: 800px; height: auto; user-select: none; -webkit-user-select: none; }
.tp circle.tp-hit { fill: transparent; stroke: none; }
.schem-txt { font-family: var(--font-body); font-size: 13px; fill: var(--ink-2); }
.schem-title { font-family: var(--font-body); font-size: 14px; font-weight: 700; fill: var(--ink); }
.schem-box { fill: var(--surface-2); stroke: var(--ink-3); stroke-width: 1.5; }
.schem-sym { stroke: var(--ink); stroke-width: 2.2; fill: none; stroke-linecap: round; }
.tp { cursor: pointer; }
.tp circle.tp-dot { fill: var(--surface); stroke: var(--ink); stroke-width: 2; }
.tp:hover circle.tp-dot { fill: var(--accent); }
.tp text { font-family: var(--font-mono); font-size: 11px; font-weight: 700; fill: var(--ink); pointer-events: none; }
.clickable { cursor: pointer; }
.clickable:hover .schem-box, .clickable:hover .brk-body { stroke: var(--accent); stroke-width: 3; }
.brk-body { fill: var(--breaker); stroke: var(--breaker-edge); stroke-width: 1.5; }
.tools { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; }
.tool-btn { border: 1.5px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 6px; font-size: 13px; display: grid; justify-items: center; gap: 2px; text-align: center; line-height: 1.3; }
.tool-btn svg { width: 26px; height: 26px; }
.tool-btn.cur { border-color: var(--ink); background: var(--surface-2); font-weight: 700; }
.lcd {
  background: #C9D4B8; color: #1E261A; border-radius: 8px; padding: 10px 14px;
  font-family: var(--font-mono); box-shadow: inset 0 2px 6px rgba(0,0,0,.25);
  display: grid; gap: 2px; min-height: 84px;
}
.lcd .lcd-mode { font-size: 12px; opacity: .75; }
.lcd .lcd-val { font-size: 30px; font-weight: 700; line-height: 1.1; }
.lcd .lcd-sub { font-size: 12px; }
.lcd.danger { background: #E9B5A8; }
.log { list-style: none; margin: 0; padding: 0; font-family: var(--font-mono); font-size: 12.5px; display: grid; gap: 3px; max-height: 190px; overflow-y: auto; color: var(--ink-2); }
.log li.new { color: var(--ink); font-weight: 700; }
.story { display: grid; gap: 6px; }
.story .who { font-size: 13px; color: var(--ink-3); }
.story blockquote { margin: 0; font-size: 17px; font-weight: 500; border-left: 3px solid var(--copper); padding-left: 12px; }
.diag-opts { display: grid; gap: 6px; }
.diag-opt { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border: 1.5px solid var(--line); border-radius: 8px; font-size: 14px; cursor: pointer; background: var(--surface); }
.diag-opt input { margin-top: 5px; accent-color: var(--copper); }
.ctrl-grid { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- 響應式 ---------- */
@media (max-width: 1000px) {
  .wb, .fault { grid-template-columns: minmax(0, 1fr); }
  .meter-lab { grid-template-columns: minmax(0, 1fr); }
  .meter-col { position: static; }
  .home-lower { grid-template-columns: minmax(0, 1fr); }
  .branches { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .panel-grid { grid-template-columns: minmax(0, 1fr); }
  .branches { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .breaker.main { min-height: 0; }
  .lesson { grid-template-columns: minmax(0, 1fr); }
  .toc { position: static; display: flex; overflow-x: auto; gap: 4px; }
  .toc button { flex: none; }
  .toc button.cur { box-shadow: inset 0 -3px 0 var(--accent); }
  .lab { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .board-wrap svg { width: 900px; max-width: none; }
  .scroll-hint { display: block; }
}
@media (max-width: 640px) {
  .bench3d { aspect-ratio: 4 / 3.8; }
  .board3d { aspect-ratio: 4 / 3.6; }
  .board3d.life3d { aspect-ratio: 16 / 11; min-height: 220px; }
  .b3d-legend { left: 8px; bottom: 8px; gap: 2px 8px; padding: 2px 8px; font-size: 11px; }
  .b3d-legend i { width: 8px; height: 8px; margin-right: 3px; }
  .b3d-label { font-size: 11px; padding: 1px 7px; }
  .theme-switch .ts-lbl { display: none; }
  .theme-switch button { padding: 3px 8px; }
}
@media (max-width: 520px) {
  .ga-pin { width: 20px; height: 20px; font-size: 11px; }
  .stn-panel { padding: 0; border: 0; background: none; }
  .branches { grid-template-columns: minmax(0, 1fr); }
  .breaker { min-height: 0; }
  .overall-bar { width: 64px; }
  .overall .lbl { display: none; }
  .enclosure { padding: 44px 12px 12px; }
}
@media (max-width: 420px) {
  .overall-bar { display: none; }
  .topbar-right { gap: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
}
