:root {
  --ink: #17221f;
  --muted: #687570;
  --paper: #f6f3ea;
  --white: #fffdf8;
  --navy: #102f36;
  --navy-2: #0a252c;
  --mint: #cfe9df;
  --mint-bright: #7bd9bd;
  --coral: #ff684d;
  --blue: #2385b5;
  --yellow: #f1c34a;
  --line: rgba(23, 34, 31, .16);
  --mono: "DM Mono", monospace;
  --sans: "Noto Sans JP", sans-serif;
  --shadow: 0 24px 70px rgba(18, 38, 34, .12);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--sans);
  line-height: 1.8;
}
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
canvas { display: block; width: 100%; }

.topbar {
  position: fixed;
  z-index: 50;
  top: 0;
  left: 0;
  right: 0;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  color: white;
  background: rgba(10, 37, 44, .94);
  border-bottom: 1px solid rgba(255, 255, 255, .1);
  backdrop-filter: blur(14px);
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .03em; }
.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  color: var(--navy);
  background: var(--mint-bright);
  border-radius: 50%;
  font-family: var(--mono);
  font-size: 24px;
}
.topbar-progress { display: flex; align-items: center; gap: 14px; font: 12px var(--mono); }
.progress-track { overflow: hidden; width: 140px; height: 5px; background: rgba(255,255,255,.16); border-radius: 10px; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--coral); transition: width .5s ease; }
.menu-button { display: none; color: white; background: transparent; border: 1px solid rgba(255,255,255,.25); border-radius: 99px; padding: 7px 15px; }

.side-nav {
  position: fixed;
  z-index: 30;
  top: 72px;
  bottom: 0;
  left: 0;
  width: 230px;
  padding: 48px 22px 30px;
  color: #cce0da;
  background: var(--navy-2);
}
.eyebrow { margin: 0 0 9px; font: 500 11px/1.4 var(--mono); letter-spacing: .18em; }
.side-nav .eyebrow { padding-left: 14px; color: #7fa69d; }
.side-nav nav { display: grid; gap: 5px; margin-top: 20px; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 11px 14px;
  border-radius: 8px;
  color: #89aaa3;
  font-size: 13px;
  transition: .2s ease;
}
.nav-link span { font: 11px var(--mono); }
.nav-link:hover, .nav-link.active { color: white; background: rgba(255,255,255,.08); }
.nav-link.active span { color: var(--coral); }
.side-note {
  position: absolute;
  bottom: 30px;
  margin-right: 22px;
  padding: 18px;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px;
  font-size: 11px;
  line-height: 1.7;
}
.side-note strong { color: var(--mint-bright); }
.side-note p { margin: 6px 0 0; }

main, footer { margin-left: 230px; }
.lesson-section { scroll-margin-top: 72px; padding: 110px clamp(40px, 6vw, 100px); }
.paper-section { background-color: var(--paper); background-image: radial-gradient(rgba(23,34,31,.08) .7px, transparent .7px); background-size: 13px 13px; }

.hero {
  min-height: 100vh;
  display: grid;
  grid-template-columns: .9fr 1.1fr;
  align-items: center;
  gap: 5vw;
  color: white;
  background: var(--navy);
}
.hero h1 { margin: 12px 0 24px; font-size: clamp(48px, 6vw, 88px); line-height: 1.1; letter-spacing: -.055em; }
.hero h1 em { color: var(--mint-bright); font-style: normal; }
.hero-lead { max-width: 540px; color: #bcd1cc; font-size: 16px; line-height: 2; }
.hero-actions { display: flex; gap: 12px; margin-top: 38px; flex-wrap: wrap; }
.button {
  cursor: pointer;
  display: inline-flex;
  min-height: 51px;
  align-items: center;
  justify-content: center;
  gap: 30px;
  padding: 0 23px;
  border: 0;
  border-radius: 5px;
  font-weight: 700;
  transition: transform .2s, background .2s;
}
.button:hover { transform: translateY(-2px); }
.button.primary { color: white; background: var(--coral); }
.button.ghost { color: #b9d0ca; background: transparent; border: 1px solid #47635d; }
.hero-facts { display: flex; gap: 34px; margin-top: 48px; }
.hero-facts div { display: flex; align-items: baseline; gap: 7px; }
.hero-facts strong { font: 500 25px var(--mono); color: var(--mint-bright); }
.hero-facts span { color: #87a59e; font-size: 11px; }
.hero-visual {
  position: relative;
  min-height: 560px;
  display: grid;
  align-items: center;
  border-left: 1px solid rgba(255,255,255,.08);
}
#heroCanvas { height: 430px; }
.socket-card, .frequency-badge {
  position: absolute;
  padding: 16px 19px;
  color: var(--ink);
  background: var(--white);
  box-shadow: var(--shadow);
}
.socket-card { top: 22%; right: 5%; display: grid; border-radius: 5px; }
.socket-card span, .socket-card small { font-size: 10px; color: var(--muted); }
.socket-card strong { font: 500 32px var(--mono); }
.frequency-badge { bottom: 17%; left: 6%; border-left: 4px solid var(--coral); }
.frequency-badge span { display: block; font-size: 10px; color: var(--muted); }
.frequency-badge strong { font: 500 20px var(--mono); }

.section-heading { display: grid; grid-template-columns: 88px 1fr; gap: 25px; max-width: 850px; margin-bottom: 62px; }
.chapter-number {
  width: 70px;
  height: 70px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--navy);
  font: 500 20px var(--mono);
  border-radius: 50%;
}
.section-heading h2 { margin: 0; font-size: clamp(34px, 4vw, 56px); line-height: 1.3; letter-spacing: -.04em; }
.section-heading p:not(.eyebrow) { max-width: 700px; margin: 13px 0 0; color: var(--muted); }
.section-heading.light { color: white; }
.section-heading.light .chapter-number { color: var(--navy); background: var(--mint-bright); }
.section-heading.light p:not(.eyebrow) { color: #aac3bd; }

.concept-grid { display: grid; grid-template-columns: .8fr 1.2fr; gap: 22px; }
.explain-card, .lab-card, .metric-card, .phase-control-card, .phase-visual-card, .element-lab, .input-panel, .result-panel, .resonance-card {
  background: var(--white);
  border: 1px solid var(--line);
  box-shadow: 0 12px 35px rgba(25, 48, 43, .06);
}
.explain-card, .lab-card { padding: clamp(25px, 3vw, 42px); }
.card-label {
  display: inline-block;
  margin-bottom: 14px;
  padding: 5px 10px;
  color: white;
  background: var(--navy);
  border-radius: 3px;
  font: 500 10px var(--mono);
  letter-spacing: .1em;
}
.card-label.coral { background: var(--coral); }
.explain-card h3, .lab-card h3, .phase-control-card h3, .element-notes h3, .resonance-card h3, .power-copy h3 { margin: 3px 0 24px; font-size: 25px; line-height: 1.55; }
.dc-ac-compare { display: grid; gap: 13px; margin: 35px 0; }
.dc-ac-compare > div { padding: 18px; background: #edf1ed; border-radius: 5px; }
.mini-label { font: 10px var(--mono); color: var(--muted); }
.arrow-line { margin: 8px 0 4px; color: var(--blue); font: 24px var(--mono); letter-spacing: -5px; }
.arrow-line.ac { color: var(--coral); }
.dc-ac-compare p { margin: 0; font-size: 11px; color: var(--muted); }
.plain-note { padding: 15px 18px; border-left: 3px solid var(--yellow); background: #fff9e7; color: #625c4d; font-size: 12px; }
.lab-header, .panel-title { display: flex; align-items: flex-start; justify-content: space-between; }
.live-pill { color: var(--coral); font: 10px var(--mono); }
.live-pill i { display: inline-block; width: 7px; height: 7px; margin-right: 5px; background: var(--coral); border-radius: 50%; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
#waveCanvas { height: 280px; margin: 8px 0 25px; background: #f1f5f1; }
.controls { display: grid; gap: 25px; }
.controls.two { grid-template-columns: 1fr 1fr; }
.controls label, .frequency-control { display: grid; gap: 7px; }
.controls label > span, .frequency-control label, .power-controls label > span { display: flex; justify-content: space-between; font-size: 12px; }
.controls b, .frequency-control strong, .power-controls b { font: 500 12px var(--mono); color: var(--coral); }
.controls small { color: var(--muted); font-size: 10px; }
input[type="range"] { width: 100%; accent-color: var(--coral); }
.formula-strip { display: grid; grid-template-columns: 75px 1fr 1.2fr; align-items: center; gap: 15px; margin-top: 28px; padding: 16px 20px; color: white; background: var(--navy); }
.formula-strip span { color: var(--mint-bright); font: 10px var(--mono); }
.formula-strip strong { font: 500 16px var(--mono); }
.formula-strip p { margin: 0; color: #a7c1ba; font-size: 10px; line-height: 1.6; }
.three-cards { display: grid; grid-template-columns: repeat(3,1fr); gap: 18px; margin-top: 22px; }
.metric-card { padding: 27px; }
.metric-card h3 { margin: 16px 0 4px; font-size: 15px; }
.metric-card p { min-height: 45px; margin: 0; color: var(--muted); font-size: 11px; }
.metric-card strong { display: block; margin: 17px 0 7px; font: 500 23px var(--mono); }
.metric-card code { color: var(--coral); font: 11px var(--mono); }
.metric-icon { display: grid; width: 35px; height: 35px; place-items: center; color: white; background: var(--blue); border-radius: 50%; }

.checkpoint { display: grid; grid-template-columns: 1fr auto; gap: 25px; align-items: center; margin-top: 45px; padding: 30px; color: white; background: var(--navy); border-radius: 5px; }
.checkpoint > div:first-child span { color: var(--mint-bright); font: 10px var(--mono); letter-spacing: .1em; }
.checkpoint h3 { margin: 6px 0 0; font-size: 18px; }
.quiz-options { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.quiz-options button { cursor: pointer; padding: 10px 16px; color: #d6e5e1; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.15); border-radius: 4px; font-size: 12px; }
.quiz-options button:hover { background: rgba(255,255,255,.14); }
.quiz-options button.correct { color: var(--navy); background: var(--mint-bright); border-color: var(--mint-bright); }
.quiz-options button.wrong { color: white; background: var(--coral); border-color: var(--coral); }
.feedback { grid-column: 1/-1; display: none; margin: -10px 0 0; color: #b9d5ce; font-size: 12px; }
.feedback.show { display: block; }

.dark-section { color: white; background: var(--navy); }
.phase-layout { display: grid; grid-template-columns: .8fr 1.2fr; gap: 22px; color: var(--ink); }
.phase-control-card, .phase-visual-card { padding: clamp(25px, 3vw, 40px); }
.dial-wrap { display: flex; align-items: center; justify-content: space-around; gap: 20px; margin: 25px 0; }
.dial {
  position: relative;
  width: 170px;
  aspect-ratio: 1;
  border: 2px solid var(--navy);
  border-radius: 50%;
  background: repeating-radial-gradient(circle, transparent 0 27px, rgba(23,34,31,.06) 28px 29px);
}
.dial:after { content: ""; position: absolute; inset: 48%; background: var(--coral); border-radius: 50%; }
.dial span { position: absolute; font: 9px var(--mono); color: var(--muted); }
.dial span:nth-of-type(1) { top: 46%; right: 7px; }
.dial span:nth-of-type(2) { top: 7px; left: 45%; }
.dial span:nth-of-type(3) { top: 46%; left: 3px; }
.dial span:nth-of-type(4) { bottom: 7px; left: 43%; }
.dial-hand { position: absolute; z-index: 2; top: calc(50% - 2px); left: 50%; width: 39%; height: 3px; background: var(--coral); transform-origin: left center; transition: transform .2s; }
.dial-hand:after { content: ""; position: absolute; right: -1px; top: -4px; border-left: 8px solid var(--coral); border-top: 5px solid transparent; border-bottom: 5px solid transparent; }
.dial-readout { display: grid; gap: 4px; }
.dial-readout strong { font: 500 36px var(--mono); }
.dial-readout span { max-width: 120px; color: var(--muted); font-size: 11px; }
.phase-presets { display: flex; gap: 6px; margin-top: 18px; }
.phase-presets button { cursor: pointer; flex: 1; padding: 9px 3px; background: #edf0ec; border: 0; font-size: 10px; }
.phase-presets button.active { color: white; background: var(--navy); }
#phaseCanvas { height: 300px; background: #eff4f0; }
.legend { display: flex; gap: 22px; margin: 15px 0 24px; font: 10px var(--mono); color: var(--muted); }
.legend i { display: inline-block; width: 20px; height: 3px; margin-right: 6px; vertical-align: middle; }
.legend .voltage { background: var(--blue); }
.legend .current { background: var(--coral); }
.analogy { display: grid; grid-template-columns: 70px 1fr; gap: 15px; padding-top: 18px; border-top: 1px solid var(--line); }
.analogy span { color: var(--coral); font: 10px var(--mono); }
.analogy p { margin: 0; color: var(--muted); font-size: 12px; }
.vector-explain { display: grid; grid-template-columns: .8fr 1.2fr; align-items: center; gap: 50px; margin: 70px 0 20px; padding: 50px; border: 1px solid rgba(255,255,255,.13); }
.vector-explain h3 { margin: 10px 0 15px; font-size: 28px; }
.vector-explain p:not(.eyebrow) { color: #a9c2bc; font-size: 13px; }
#vectorCanvas { height: 260px; }
.checkpoint.inverse { color: var(--ink); background: var(--mint); }
.checkpoint.inverse > div:first-child span { color: #327866; }
.checkpoint.inverse .quiz-options button { color: var(--ink); border-color: rgba(23,34,31,.18); }
.checkpoint.inverse .feedback { color: #43665e; }

.element-tabs { display: flex; max-width: 700px; margin: 0 auto; }
.element-tabs button { cursor: pointer; flex: 1; padding: 16px; color: var(--muted); background: transparent; border: 0; border-bottom: 2px solid var(--line); font: 500 20px var(--mono); }
.element-tabs button span { margin-left: 7px; font: 11px var(--sans); }
.element-tabs button.active { color: var(--coral); border-color: var(--coral); }
.element-lab { display: grid; grid-template-columns: 1.15fr .85fr; max-width: 1000px; margin: 25px auto 0; }
.circuit-stage { padding: 35px; background: #e8efeb; }
.circuit-stage svg { width: 100%; }
.wire, .symbol { fill: none; stroke: var(--navy); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }
.source { fill: var(--white); stroke: var(--navy); stroke-width: 5; }
.source-wave { fill: none; stroke: var(--coral); stroke-width: 4; }
.circuit-stage text { fill: var(--navy); font: 600 17px var(--mono); }
.flow-dot { fill: var(--coral); filter: drop-shadow(0 0 5px rgba(255,104,77,.7)); animation: currentFlow 4s linear infinite; }
@keyframes currentFlow {
  0% { cx: 95px; cy: 55px; }
  35% { cx: 390px; cy: 55px; }
  60% { cx: 390px; cy: 195px; }
  85% { cx: 95px; cy: 195px; }
  100% { cx: 95px; cy: 55px; }
}
.frequency-control { margin: 15px 30px 0; }
.element-notes { position: relative; overflow: hidden; padding: 45px; }
.element-big { position: absolute; top: -45px; right: 10px; color: rgba(23,34,31,.05); font: 500 200px var(--mono); }
.element-notes > *:not(.element-big) { position: relative; }
.element-notes .eyebrow { color: var(--coral); }
.element-notes > p:not(.eyebrow) { color: var(--muted); font-size: 13px; }
.element-notes dl { margin: 25px 0; border-top: 1px solid var(--line); }
.element-notes dl div { display: flex; justify-content: space-between; gap: 20px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.element-notes dt { color: var(--muted); font-size: 10px; }
.element-notes dd { margin: 0; text-align: right; font: 500 11px var(--mono); }
.memory-hook { padding: 13px; color: white; background: var(--navy); text-align: center; font-size: 11px; }
.rlc-summary { display: grid; grid-template-columns: repeat(3,1fr); max-width: 1000px; margin: 20px auto; border: 1px solid var(--line); }
.rlc-summary div { display: grid; gap: 2px; padding: 24px; background: rgba(255,253,248,.65); border-right: 1px solid var(--line); }
.rlc-summary div:last-child { border: 0; }
.rlc-summary b { color: var(--coral); font: 500 24px var(--mono); }
.rlc-summary span { font-size: 13px; font-weight: 700; }
.rlc-summary small { color: var(--muted); }

.mint-section { background: var(--mint); }
.calculator-layout { display: grid; grid-template-columns: .75fr 1.25fr; gap: 20px; }
.input-panel, .result-panel { padding: clamp(25px, 3vw, 40px); }
.panel-title { margin-bottom: 25px; padding-bottom: 12px; border-bottom: 1px solid var(--line); font: 500 10px var(--mono); letter-spacing: .1em; }
.panel-title i { color: var(--coral); font: 700 10px var(--sans); }
.input-panel > label { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 13px 0; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.input-panel input { width: 80px; padding: 8px; color: var(--ink); background: #eef2ed; border: 1px solid var(--line); text-align: right; font: 500 13px var(--mono); }
.button.full { width: 100%; margin-top: 25px; }
.result-primary { margin-bottom: 22px; padding: 22px; color: white; background: var(--navy); }
.result-primary span { color: #a5c1ba; font-size: 11px; }
.result-primary strong { display: block; font: 500 42px var(--mono); }
.result-primary small { font-size: 17px; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); }
.result-grid > div { display: grid; padding: 18px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.result-grid > div:nth-child(2n) { border-right: 0; }
.result-grid > div:nth-child(n+3) { border-bottom: 0; }
.result-grid span { color: var(--coral); font: 500 12px var(--mono); }
.result-grid strong { font: 500 16px var(--mono); }
.result-grid small { color: var(--muted); font-size: 9px; }
.impedance-chart { margin-top: 18px; padding: 15px; background: #edf1ed; }
#impedanceCanvas { height: 180px; }
.result-message { margin: 17px 0 0; color: var(--muted); font-size: 11px; }
.resonance-card { display: grid; grid-template-columns: 1.2fr .8fr; gap: 40px; align-items: center; margin-top: 22px; padding: 38px; }
.resonance-card h3 { margin-bottom: 12px; }
.resonance-card p { margin: 0; color: var(--muted); font-size: 12px; }
.resonance-formula { padding: 25px; color: white; background: var(--navy); }
.resonance-formula span, .resonance-formula small { display: block; color: #a8c1bb; font-size: 10px; }
.resonance-formula strong { display: block; margin: 10px 0; font: 500 19px var(--mono); color: var(--mint-bright); }

.power-section { color: white; background: #091f25; }
.power-lab { display: grid; grid-template-columns: 1.05fr .95fr; gap: 22px; }
.power-triangle-card, .power-copy { padding: clamp(28px, 4vw, 48px); border: 1px solid rgba(255,255,255,.12); }
.power-triangle-card { background: #102f36; }
#powerCanvas { height: 330px; }
.power-controls { margin-top: 20px; }
.power-copy { background: #0e2930; }
.power-definitions { display: grid; gap: 16px; margin: 30px 0; }
.power-definitions div { display: grid; grid-template-columns: 8px 1fr; gap: 13px; }
.power-definitions i { width: 7px; height: 100%; border-radius: 5px; }
.power-definitions i.p { background: var(--mint-bright); }
.power-definitions i.q { background: var(--coral); }
.power-definitions i.s { background: var(--yellow); }
.power-definitions span { display: grid; color: #91aea7; font-size: 10px; }
.power-definitions b { color: white; font-size: 12px; }
.power-readout { display: grid; grid-template-columns: repeat(3,1fr); gap: 7px; }
.power-readout div { padding: 15px; background: rgba(255,255,255,.06); }
.power-readout span { color: var(--mint-bright); font: 10px var(--mono); }
.power-readout strong { display: block; font: 500 13px var(--mono); }
.light-note { color: #c9d8d4; background: rgba(241,195,74,.08); }
.completion-card {
  display: none;
  margin-top: 80px;
  padding: 70px 25px;
  color: var(--ink);
  background: var(--mint-bright);
  text-align: center;
}
.completion-card.show { display: block; animation: reveal .6s ease; }
@keyframes reveal { from { opacity: 0; transform: translateY(20px); } }
.completion-wave { margin: auto; font: 70px var(--mono); }
.completion-card h2 { margin: 7px 0 15px; font-size: 38px; }
.completion-card p:not(.eyebrow) { max-width: 650px; margin: 0 auto 25px; }
.light-button { background: var(--white); color: var(--ink); }

footer { display: flex; align-items: center; justify-content: space-between; gap: 25px; padding: 30px 50px; color: #9bb3ad; background: #06171b; font-size: 10px; }
footer a:last-child { color: var(--mint-bright); }

@media (max-width: 1050px) {
  .side-nav { transform: translateX(-100%); transition: transform .25s; }
  .side-nav.open { transform: translateX(0); box-shadow: 20px 0 50px rgba(0,0,0,.25); }
  main, footer { margin-left: 0; }
  .menu-button { display: block; }
  .hero { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 780px) {
  .topbar { height: 62px; padding: 0 18px; }
  .topbar-progress { display: none; }
  .side-nav { top: 62px; }
  .lesson-section { scroll-margin-top: 62px; padding: 82px 20px; }
  .hero { min-height: auto; grid-template-columns: 1fr; padding-top: 120px; }
  .hero-visual { min-height: 420px; border: 0; }
  #heroCanvas { height: 340px; }
  .section-heading { grid-template-columns: 54px 1fr; gap: 15px; margin-bottom: 40px; }
  .chapter-number { width: 50px; height: 50px; font-size: 14px; }
  .concept-grid, .phase-layout, .vector-explain, .element-lab, .calculator-layout, .resonance-card, .power-lab { grid-template-columns: 1fr; }
  .three-cards, .rlc-summary { grid-template-columns: 1fr; }
  .rlc-summary div { border-right: 0; border-bottom: 1px solid var(--line); }
  .controls.two { grid-template-columns: 1fr; }
  .formula-strip { grid-template-columns: 1fr; }
  .checkpoint { grid-template-columns: 1fr; }
  .quiz-options { justify-content: flex-start; }
  .vector-explain { padding: 25px; }
  .element-lab { max-width: 560px; }
  .power-readout { grid-template-columns: 1fr; }
  footer { flex-direction: column; text-align: center; }
}

@media (max-width: 460px) {
  .hero h1 { font-size: 47px; }
  .hero-facts { gap: 17px; }
  .hero-facts strong { font-size: 19px; }
  .hero-facts span { font-size: 9px; }
  .socket-card { right: 0; }
  .dial-wrap { flex-direction: column; }
  .phase-presets { flex-direction: column; }
  .element-tabs button span { display: block; margin: 0; }
  .result-grid { grid-template-columns: 1fr; }
  .result-grid > div { border-right: 0; border-bottom: 1px solid var(--line) !important; }
  .result-grid > div:last-child { border-bottom: 0 !important; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *:before, *:after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
