:root {
  --bg: #0b0d10;
  --bg-2: #11151a;
  --surface: #161b22;
  --surface-2: #1c232c;
  --surface-3: #242c36;
  --line: #2c3542;
  --line-2: #3a4554;
  --text: #eceae4;
  --muted: #8d949e;
  --faint: #5e6670;
  --copper: #c4783a;
  --copper-2: #e09a55;
  --amber: #e8b84a;
  --live: #3ee0c2;
  --live-dim: #1a8f7c;
  --volt: #f0c14b;
  --danger: #e85d4c;
  --danger-dim: #8a2e24;
  --ok: #5dcc7a;
  --info: #6aa8e8;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --sidebar: 272px;
  --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", "Cascadia Mono", "Consolas", monospace;
  --display: "Syne", "IBM Plex Sans", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; width: 100%; max-width: 100%; }
html { scroll-behavior: smooth; overflow-x: hidden; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  overflow: hidden;
}
a { color: var(--live); text-decoration: none; }
a:hover { color: #7ff0dc; }
button, input, select { font-family: inherit; }
img { max-width: 100%; display: block; }

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  height: 100vh;
  min-width: 0;
}
.app-shell > div { min-width: 0; overflow: hidden; display: flex; flex-direction: column; }
.app-shell > div > .main { flex: 1; min-width: 0; }

/* ---------- Sidebar ---------- */
.sidebar {
  background: linear-gradient(180deg, #12171d 0%, #0d1116 100%);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.brand {
  padding: 22px 20px 18px;
  border-bottom: 1px solid var(--line);
}
.brand-kicker {
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--copper-2);
  font-weight: 600;
}
.brand h1 {
  font-family: var(--display);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin-top: 4px;
}
.brand p {
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 6px;
}
.nav {
  padding: 12px 10px 20px;
  overflow-y: auto;
  flex: 1;
}
.nav-label {
  font-size: 10.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 14px 12px 6px;
  font-weight: 600;
}
.nav a, .nav button.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 9px;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.nav a:hover, .nav button.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav a.active, .nav button.nav-link.active {
  background: linear-gradient(90deg, rgba(196,120,58,0.18), rgba(62,224,194,0.06));
  color: var(--text);
  box-shadow: inset 2px 0 0 var(--copper);
}
.nav .num {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--copper-2);
  width: 18px;
}
.progress-pill {
  margin: 12px 16px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}
.progress-pill .row { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.bar {
  height: 6px;
  background: var(--surface-3);
  border-radius: 99px;
  margin-top: 8px;
  overflow: hidden;
}
.bar > span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--copper), var(--live));
  border-radius: 99px;
  transition: width 0.4s ease;
}

/* ---------- Main ---------- */
.main {
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-height: 0;
  height: auto;
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(196,120,58,0.08), transparent 50%),
    radial-gradient(800px 400px at 10% 100%, rgba(62,224,194,0.05), transparent 50%),
    var(--bg);
}
.page { max-width: 1120px; margin: 0 auto; padding: 36px 40px 80px; min-width: 0; }
.topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(11,13,16,0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px;
  align-items: center;
  gap: 12px;
}
.menu-btn {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  width: 40px; height: 40px;
  border-radius: 10px;
  cursor: pointer;
}

/* ---------- Typography ---------- */
.kicker {
  font-size: 12px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--copper-2);
  font-weight: 600;
}
h2.page-title {
  font-family: var(--display);
  font-size: clamp(32px, 5vw, 52px);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.05;
  margin: 8px 0 12px;
}
.lede { font-size: 18px; color: #c5c8cc; max-width: 62ch; }
h3 {
  font-family: var(--display);
  font-size: 26px;
  letter-spacing: -0.03em;
  margin: 8px 0 10px;
}
h4 { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.section { margin-top: 42px; }
p { margin: 0 0 12px; color: #d5d7da; }
.muted { color: var(--muted); }

/* ---------- Cards / grids ---------- */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
}
.card.clickable { cursor: pointer; transition: transform 0.15s, border-color 0.15s; }
.card.clickable:hover { transform: translateY(-2px); border-color: var(--copper); }
.card .icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: grid; place-items: center;
  background: var(--surface-3);
  margin-bottom: 12px;
  font-size: 18px;
}
.card h4 { font-family: var(--display); font-size: 18px; letter-spacing: -0.02em; }
.card p { font-size: 13.5px; color: var(--muted); margin: 0; }
.tag {
  display: inline-block;
  font-size: 11px;
  font-family: var(--mono);
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--surface-3);
  color: var(--amber);
  border: 1px solid var(--line-2);
}

/* ---------- Callouts ---------- */
.callout {
  border-radius: var(--radius);
  padding: 16px 18px;
  border: 1px solid var(--line);
  margin: 16px 0;
}
.callout.key { background: linear-gradient(90deg, rgba(62,224,194,0.08), transparent); border-left: 3px solid var(--live); }
.callout.safety { background: linear-gradient(90deg, rgba(232,93,76,0.1), transparent); border-left: 3px solid var(--danger); }
.callout.worked { background: linear-gradient(90deg, rgba(196,120,58,0.1), transparent); border-left: 3px solid var(--copper); }
.callout.try { background: linear-gradient(90deg, rgba(232,184,74,0.08), transparent); border-left: 3px solid var(--amber); }
.callout h4 { display: flex; align-items: center; gap: 8px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 14px 0 18px; border: 1px solid var(--line); border-radius: 12px; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--amber); font-weight: 600; background: var(--surface-2); font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }
tr.hl td { background: rgba(232,93,76,0.12); color: #ffd4cf; }
tr.ok td { background: rgba(93,204,122,0.1); }
code, .mono { font-family: var(--mono); }

/* ---------- Forms / tools ---------- */
.tool {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  margin: 18px 0;
}
.tool-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 16px; }
.tool-head h3 { margin: 0; font-size: 22px; }
.fields { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
input[type="number"], input[type="text"], select, textarea {
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: var(--mono);
}
input:focus, select:focus { outline: 2px solid rgba(62,224,194,0.35); border-color: var(--live); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: linear-gradient(180deg, #d08948, #b56a2e);
  color: #1a120a;
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 700;
  cursor: pointer;
  font-size: 14px;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line-2);
  font-weight: 600;
}
.btn.live { background: linear-gradient(180deg, #49e8cc, #1f9e89); color: #06231e; }
.btn.danger { background: linear-gradient(180deg, #ef6e5f, #c44738); color: #2a0c08; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.big-readout {
  font-family: var(--mono);
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--live);
  line-height: 1;
}
.sub-readout { color: var(--muted); font-size: 13px; margin-top: 6px; }

/* ---------- Triangle ---------- */
.triangle-wrap { display: grid; grid-template-columns: 280px 1fr; gap: 24px; align-items: center; }
.tri { width: 260px; height: 230px; }
.tri polygon { cursor: pointer; transition: fill 0.15s; }
.formula-box {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
  font-family: var(--mono);
  font-size: 22px;
}

/* ---------- Resistor ---------- */
.resistor-stage { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.resistor-svg { width: min(520px, 100%); }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.swatch {
  width: 34px; height: 28px; border-radius: 6px; border: 1px solid #0006;
  cursor: pointer; position: relative;
}
.swatch.active { outline: 2px solid #fff; outline-offset: 2px; }
.band-pick { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }

/* ---------- Gates / bits ---------- */
.bit {
  width: 52px; height: 64px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  background: var(--surface-3);
  display: grid; place-items: center;
  font-family: var(--mono);
  font-size: 22px;
  cursor: pointer;
  user-select: none;
}
.bit.on { background: #123c36; border-color: var(--live); color: var(--live); box-shadow: 0 0 18px rgba(62,224,194,0.25); }
.switch {
  width: 54px; height: 28px;
  background: var(--surface-3);
  border-radius: 99px;
  border: 1px solid var(--line-2);
  position: relative;
  cursor: pointer;
}
.switch::after {
  content: "";
  width: 22px; height: 22px;
  background: #c9cdd3;
  border-radius: 50%;
  position: absolute; top: 2px; left: 3px;
  transition: transform 0.18s;
}
.switch.on { background: #1a6b5e; border-color: var(--live); }
.switch.on::after { transform: translateX(24px); background: var(--live); }
.led {
  width: 22px; height: 22px; border-radius: 50%;
  background: #2a313a;
  box-shadow: inset 0 0 0 2px #111;
}
.led.on.green { background: #4dff88; box-shadow: 0 0 16px #4dff88; }
.led.on.red { background: #ff5a4a; box-shadow: 0 0 16px #ff5a4a; }
.led.on.yellow { background: #ffe14a; box-shadow: 0 0 16px #ffe14a; }

/* ---------- Quiz ---------- */
.q { margin-bottom: 18px; }
.choices { display: grid; gap: 8px; margin-top: 10px; }
.choice {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  font-size: 14.5px;
}
.choice:hover { border-color: var(--copper); }
.choice.correct { border-color: var(--ok); background: rgba(93,204,122,0.12); }
.choice.wrong { border-color: var(--danger); background: rgba(232,93,76,0.12); }
.explain { margin-top: 8px; font-size: 13.5px; color: #c8ccd2; }

/* ---------- Schedule ---------- */
.week {
  display: grid;
  grid-template-columns: 70px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.week:last-child { border-bottom: 0; }

/* ---------- Hero ---------- */
.hero-art {
  height: 220px;
  min-width: 0;
  max-width: 100%;
  border-radius: 18px;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(22,27,34,0.2), rgba(11,13,16,0.85)),
    repeating-linear-gradient(90deg, transparent 0 18px, rgba(196,120,58,0.07) 18px 19px),
    radial-gradient(circle at 20% 50%, rgba(62,224,194,0.18), transparent 40%),
    var(--surface);
  position: relative;
  overflow: hidden;
  margin: 22px 0 28px;
}
.hero-art canvas { width: 100%; max-width: 100%; height: 100%; display: block; }

.fig {
  background: #f4f1ea;
  border-radius: 12px;
  padding: 10px;
  margin: 14px 0 8px;
}
.fig img { margin: 0 auto; }
.caption { font-size: 12.5px; color: var(--muted); font-style: italic; margin-bottom: 16px; }

.probe {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface-3);
  border-radius: 99px;
  padding: 6px 12px;
  font-family: var(--mono);
  font-size: 13px;
  border: 1px solid var(--line);
}
.chip {
  font-size: 11px; font-family: var(--mono);
  padding: 2px 8px; border-radius: 6px;
  background: var(--surface-3); color: var(--muted);
}

.toc a { display: block; padding: 6px 0; color: var(--muted); }
.toc a:hover { color: var(--live); }

.overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 30;
}
.sidebar.open { transform: translateX(0); }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(86vw, 300px);
    z-index: 40; transform: translateX(-105%);
    transition: transform 0.22s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .topbar { display: flex; }
  .page { padding: 20px 16px 64px; overflow-x: hidden; }
  h2.page-title { font-size: 28px; }
  .lede { font-size: 16px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .triangle-wrap { grid-template-columns: 1fr; }
  .week { grid-template-columns: 1fr; }
  .hero-art { height: 160px; }
}

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
ul.plain { padding-left: 18px; margin: 8px 0 14px; }
ul.plain li { margin: 4px 0; color: #d5d7da; }
.kpi { font-family: var(--mono); font-size: 28px; color: var(--amber); }
.steps { counter-reset: step; }
.steps > li {
  list-style: none;
  margin: 8px 0;
  padding-left: 36px;
  position: relative;
}
.steps > li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute; left: 0; top: 0;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--amber);
  font-size: 12px;
  font-family: var(--mono);
  display: grid; place-items: center;
}
.hidden { display: none !important; }
.result-ok { color: var(--ok); }
.result-bad { color: var(--danger); }
.meter {
  background: #0a0c0e;
  border: 2px solid #3a414c;
  border-radius: 16px;
  padding: 16px 18px;
  font-family: var(--mono);
}
.meter .lcd {
  background: #0e1f18;
  color: #7cffb2;
  padding: 12px;
  border-radius: 8px;
  font-size: 28px;
  letter-spacing: 0.08em;
  text-align: right;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.5);
}
.chain { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chain .node {
  min-width: 88px;
  text-align: center;
  padding: 10px 8px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  background: var(--surface-2);
  font-size: 12px;
  cursor: pointer;
}
.chain .node.has { border-color: var(--live); color: var(--live); }
.chain .node.open { border-color: var(--danger); color: var(--danger); }
.chain .wire { width: 18px; height: 2px; background: var(--line-2); }
.chain .wire.hot { background: var(--live); box-shadow: 0 0 8px var(--live); }
