:root {
  /* Vulcan Electric brand: black, red, white */
  --brand-red: #d7192d;
  --brand-black: #000000;
  --bg: #f5f5f6;
  --surface: #ffffff;
  --surface-2: #f0f0f2;
  --text: #121212;
  --muted: #5f6368;
  --border: #e2e2e6;
  --primary: #d7192d;
  --primary-ink: #ffffff;
  --accent: #d7192d;
  --flow: #f59e0b;
  --good: #15803d;
  --good-bg: #e7f6ec;
  --bad: #b91c1c;
  --bad-bg: #fdecec;
  --tip-bg: #fff7e6;
  --safety-bg: #fdecec;
  --resistor: #c8b28a;
  --hot: #ef4444;
  --wire: #475569;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .06);
  --chat-w: 400px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0b0c;
    --surface: #151517;
    --surface-2: #1f1f22;
    --text: #f2f2f3;
    --muted: #a3a3ab;
    --border: #2c2c31;
    --primary: #ef3340;
    --primary-ink: #ffffff;
    --accent: #ef3340;
    --good: #4ade80;
    --good-bg: #12301f;
    --bad: #f87171;
    --bad-bg: #3a1717;
    --tip-bg: #33280f;
    --safety-bg: #3a1717;
    --resistor: #8a7656;
    --wire: #94a3b8;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: var(--primary); }
h1, h2, .brand, .wordmark, .score, .big-number { font-family: Poppins, Inter, system-ui, sans-serif; }
h1 { font-size: clamp(1.6rem, 3vw, 2.2rem); line-height: 1.2; margin: .2em 0 .4em; letter-spacing: -.02em; }
h2 { font-size: 1.2rem; margin-top: 2rem; }
code { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: .9em; }
.muted { color: var(--muted); }
.error { color: var(--bad); }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; font-weight: 700; color: var(--muted); margin: 0; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .4em;
  padding: .6em 1.1em; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  transition: transform .05s, background .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--primary) 85%, black); border-color: color-mix(in srgb, var(--primary) 85%, black); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-sm { padding: .35em .8em; font-size: .9rem; }
.btn-good { background: var(--good); border-color: var(--good); color: #fff; }
.btn-bad { background: var(--bad); border-color: var(--bad); color: #fff; }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1.5rem;
  padding: .7rem 1.5rem; background: var(--brand-black); border-bottom: 3px solid var(--brand-red);
}
.brand { display: flex; align-items: center; gap: .9rem; text-decoration: none; color: #fff; font-weight: 600; line-height: 1.15; }
.brand-text { padding-left: .9rem; border-left: 1px solid #333; font-size: .95rem; }
.brand-text small { display: block; color: #9a9a9a; font-size: .7rem; font-weight: 500; text-transform: uppercase; letter-spacing: .1em; }
.wordmark { display: inline-flex; flex-direction: column; align-items: flex-end; color: #fff; font-weight: 800; font-size: 1.55rem; letter-spacing: -.02em; line-height: 1; }
.wordmark b { color: var(--brand-red); font-weight: 800; }
.wordmark small { color: var(--brand-red); font-size: .55rem; font-weight: 500; letter-spacing: .32em; margin-top: 2px; }
.wordmark.big { font-size: 2.6rem; align-items: center; margin-bottom: 1rem; }
.wordmark.big small { font-size: .8rem; }
.login-card .wordmark.big { color: var(--text); }
.nav { display: flex; gap: .25rem; flex: 1; }
.nav a { padding: .45em .9em; text-decoration: none; color: #cfcfcf; font-weight: 500; position: relative; border-bottom: 2px solid transparent; }
.nav a:hover { color: #fff; }
.nav a.active { color: #fff; border-bottom-color: var(--brand-red); }
.badge { margin-left: .35em; background: var(--brand-red); color: #fff; border-radius: 999px; padding: 0 .45em; font-size: .75rem; }
.topbar-actions { display: flex; gap: .5rem; align-items: center; }
.topbar .lang-select { background: #111; color: #fff; border-color: #333; }
.topbar .btn-ghost { color: #cfcfcf; }
.topbar .btn-ghost:hover { background: #1a1a1a; color: #fff; }
.lang-select { font: inherit; padding: .4em .6em; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }

.main { max-width: 900px; margin: 0 auto; padding: 2rem 1.5rem 7rem; transition: margin .2s; }
body.chat-open .main { margin-right: calc(var(--chat-w) + 1rem); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 2.5rem 2rem; text-align: center; box-shadow: var(--shadow); }
.login-card form { display: flex; gap: .5rem; margin: 1.5rem 0 1rem; }
.login-card input { flex: 1; font: inherit; padding: .6em .8em; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }

/* ---------- home ---------- */
.hero p { color: var(--muted); max-width: 60ch; }
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; margin: 1.5rem 0 2rem; }
.mode { display: flex; flex-direction: column; gap: .3rem; padding: 1.2rem 1.3rem; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); text-decoration: none; color: var(--text); }
.mode:hover { border-color: var(--primary); }
.mode span { color: var(--muted); font-size: .95rem; }
.modules { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .8rem; }
.module { display: grid; grid-template-columns: auto 1fr; gap: .2rem .7rem; align-items: center; padding: .9rem 1rem; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); text-decoration: none; color: var(--text); }
.module:not(.locked):hover { border-color: var(--primary); box-shadow: var(--shadow); }
.module.locked { opacity: .55; cursor: default; }
.module-num { grid-row: span 3; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: var(--surface-2); font-weight: 800; color: var(--primary); }
.module-title { font-weight: 600; font-size: .95rem; line-height: 1.3; }
.module-meta { font-size: .8rem; color: var(--muted); }
.progress-bar { display: block; height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress-bar > span { display: block; height: 100%; background: var(--good); border-radius: inherit; transition: width .3s; }

/* ---------- chapter ---------- */
.crumbs { font-size: .9rem; color: var(--muted); margin-bottom: 1rem; }
.crumbs a { color: var(--muted); }
.chapter-head, .panel, .lesson { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.8rem; box-shadow: var(--shadow); }
.lead { font-size: 1.05rem; }
.objectives ul { margin: .4rem 0 0; }
.bookref { font-size: .9rem; color: var(--muted); }
.lesson-list { list-style: none; padding: 0; margin: 1.2rem 0 0; display: grid; gap: .5rem; }
.lesson-list a { display: flex; align-items: center; gap: .9rem; padding: .8rem 1rem; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); text-decoration: none; color: var(--text); }
.lesson-list a:hover { border-color: var(--primary); }
.lesson-check { display: grid; place-items: center; min-width: 42px; height: 30px; border-radius: 8px; background: var(--surface-2); font-weight: 700; font-size: .85rem; color: var(--muted); }
.lesson-list a.done .lesson-check { background: var(--good-bg); color: var(--good); }
.lesson-title { flex: 1; font-weight: 600; }
.lesson-min { color: var(--muted); font-size: .85rem; }

/* ---------- lesson blocks ---------- */
.block { margin: 1.4rem 0; }
.block p { margin: .4em 0; }
.callout { padding: 1rem 1.2rem; border-radius: 12px; }
.callout p:first-child { display: inline; }
.tip { background: var(--tip-bg); }
.safety { background: var(--safety-bg); }
.formula { display: flex; flex-wrap: wrap; align-items: baseline; gap: .4rem 1rem; padding: 1rem 1.4rem; border-radius: 12px; background: var(--surface-2); border-left: 5px solid var(--primary); }
.formula-main { font-family: "JetBrains Mono", monospace; font-size: 1.45rem; font-weight: 500; }
.formula-note { color: var(--muted); font-size: .95rem; }
.example { border: 1px solid var(--border); border-radius: 12px; padding: 1rem 1.2rem; }
.example-problem { font-weight: 600; }
.example details summary { cursor: pointer; color: var(--primary); font-weight: 600; margin-top: .4rem; }
.steps { padding-left: 1.4rem; }
.steps li p { margin: .15em 0; }
.example-answer { background: var(--good-bg); padding: .5rem .8rem; border-radius: 8px; }
.check { border: 2px dashed var(--border); border-radius: 14px; padding: 1.2rem; }
.question { padding: .8rem 0; border-bottom: 1px solid var(--border); }
.question:last-child { border-bottom: 0; }
.q-prompt { font-weight: 600; }
.q-num { display: inline-grid; place-items: center; width: 1.6em; height: 1.6em; border-radius: 50%; background: var(--primary); color: var(--primary-ink); font-size: .85em; margin-right: .3em; }
.choices { border: 0; padding: 0; margin: .4rem 0 .7rem; display: grid; gap: .4rem; }
.choice { display: flex; gap: .6rem; align-items: center; padding: .55rem .8rem; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.choice:has(input:checked) { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, transparent); }
.numeric { display: flex; align-items: center; gap: .5rem; margin: .4rem 0 .7rem; }
.numeric input { width: 12rem; font: inherit; padding: .5em .7em; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.unit { font-weight: 700; color: var(--muted); }
.feedback { margin-top: .6rem; border-radius: 10px; }
.feedback.good, .feedback.bad { padding: .6rem .9rem; }
.feedback.good { background: var(--good-bg); }
.feedback.bad { background: var(--bad-bg); }
.feedback details summary { cursor: pointer; margin-top: .3rem; }
.lesson-foot { display: flex; flex-wrap: wrap; align-items: center; gap: .8rem; margin-top: 2rem; padding-top: 1.2rem; border-top: 1px solid var(--border); }
.hint { width: 100%; margin: 0; color: var(--muted); font-size: .9rem; }

/* ---------- simulator ---------- */
.sim { background: var(--surface-2); border-radius: 14px; padding: 1.2rem; }
.sim-title { margin: 0 0 .8rem; font-size: 1.05rem; }
.sim-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.2rem; align-items: center; }
.sim-circuit { width: 100%; height: auto; }
.wire { fill: none; stroke: var(--wire); stroke-width: 4; stroke-linejoin: round; }
.flow { fill: none; stroke: var(--flow); stroke-width: 4; stroke-dasharray: 6 18; stroke-linejoin: round; animation: flow 2s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -48; } }
.battery { fill: var(--surface); stroke: var(--wire); stroke-width: 2; }
.battery-plate { stroke: var(--text); stroke-width: 3; }
.resistor { fill: var(--resistor); stroke: var(--wire); stroke-width: 2; transition: fill .2s; }
.resistor-zigzag { fill: none; stroke: var(--text); stroke-width: 2; }
.meter { fill: var(--surface); stroke: var(--wire); stroke-width: 2; }
.meter-label { font-size: 11px; font-weight: 700; fill: var(--muted); }
.meter-value { font-size: 10px; font-weight: 700; fill: var(--text); }
.sim-label { font-size: 13px; font-weight: 700; fill: var(--text); }
.sim-controls { display: grid; gap: .7rem; }
.sim-controls label { display: grid; gap: .2rem; font-size: .9rem; }
.sim-controls input[type="range"] { width: 100%; accent-color: var(--primary); }
.sim-controls select { font: inherit; padding: .3em .5em; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.sim-readout { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.sim-readout-3 { grid-template-columns: repeat(3, 1fr); }
.sim-readout div { background: var(--surface); border-radius: 10px; padding: .5rem .7rem; display: grid; }
.sim-readout span { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.sim-readout strong { font-size: 1.3rem; }
.sim-readout code { font-size: .75rem; color: var(--muted); }
.sim-status { padding: .5rem .7rem; border-radius: 10px; font-weight: 600; font-size: .9rem; }
.sim-status.ok { background: var(--good-bg); color: var(--good); }
.sim-status.warm { background: var(--tip-bg); color: #b45309; }
.sim-status.hot { background: var(--bad-bg); color: var(--bad); }

/* ---------- review ---------- */
.big-number { font-size: 2.6rem; font-weight: 800; margin: .5rem 0; }
.big-number small { font-size: 1rem; font-weight: 500; color: var(--muted); }
.flashcard { margin-top: 1.2rem; padding: 1.5rem; border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2); }
.card-front { font-size: 1.15rem; font-weight: 600; }
.card-back { margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed var(--border); }
.card-choices { font-weight: 400; font-size: 1rem; }
.done-msg { font-size: 1.3rem; font-weight: 700; }

/* ---------- exam ---------- */
.exam-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .8rem; padding: 1rem 0; border-top: 1px solid var(--border); }
.exam-row .actions { margin: 0; }
.exam-bar { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: .5rem; }
.exam-timer.low { color: var(--bad); }
.exam-question { border: 0; font-size: 1.05rem; }
.exam-dots { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: 1rem; }
.dot { width: 2.1rem; height: 2.1rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font: inherit; font-size: .8rem; cursor: pointer; }
.dot.answered { background: var(--surface-2); color: var(--text); font-weight: 700; }
.dot.current { outline: 2px solid var(--primary); }
.score { font-size: 3.5rem; font-weight: 800; margin: 0; }
.score.good, td.good, li.good > p:first-child { color: var(--good); }
.score.bad, td.bad, li.bad > p:first-child { color: var(--bad); }
.exam-review { padding-left: 1.2rem; }
.exam-review li { margin-bottom: 1rem; }
.exam-review p { margin: .15rem 0; }
.explain { font-size: .95rem; }
.weak { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin: 1rem 0; }

/* ---------- progress ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .8rem; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 1rem; display: grid; }
.stat span { font-size: .8rem; color: var(--muted); }
.stat strong { font-size: 1.8rem; }
.history { width: 100%; border-collapse: collapse; }
.history td { padding: .5rem; border-bottom: 1px solid var(--border); }

/* ---------- chips ---------- */
.chip { display: inline-block; padding: .35em .8em; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: .85rem; text-decoration: none; cursor: pointer; }
.chip:hover { border-color: var(--primary); color: var(--primary); }

/* ---------- chat ---------- */
.chat-fab {
  position: fixed; right: 1.5rem; bottom: 1.5rem; z-index: 20;
  padding: .85em 1.3em; border-radius: 999px; border: 0;
  background: var(--primary); color: var(--primary-ink); font: inherit; font-weight: 700;
  box-shadow: 0 6px 24px rgba(215, 25, 45, .35); cursor: pointer;
}
body.chat-open .chat-fab, body.exam-running .chat-fab { display: none; }
.chat {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 30;
  width: var(--chat-w); max-width: 100vw;
  display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: -8px 0 32px rgba(0, 0, 0, .08);
  transform: translateX(100%); transition: transform .2s;
}
body.chat-open .chat { transform: none; }
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: .8rem 1rem; border-bottom: 1px solid var(--border); }
.chat-log { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .7rem; }
.msg { max-width: 92%; padding: .6rem .9rem; border-radius: 14px; font-size: .95rem; }
.msg p { margin: .3em 0; }
.msg ul, .msg ol { margin: .3em 0; padding-left: 1.2rem; }
.msg-assistant { background: var(--surface-2); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg-user { background: var(--primary); color: var(--primary-ink); align-self: flex-end; border-bottom-right-radius: 4px; }
.typing { color: var(--muted); font-style: italic; }
.chat-chips { display: flex; flex-wrap: wrap; gap: .35rem; padding: 0 1rem .6rem; }
.chat-form { display: flex; gap: .5rem; padding: .7rem 1rem; border-top: 1px solid var(--border); }
.chat-form textarea { flex: 1; resize: none; font: inherit; padding: .5em .7em; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.chat-disclaimer { margin: 0; padding: 0 1rem .7rem; font-size: .75rem; color: var(--muted); }

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; gap: .6rem; padding: .6rem 1rem; }
  .nav { order: 3; flex: 1 0 100%; overflow-x: auto; scrollbar-width: none; }
  .topbar-actions { margin-left: auto; }
  .main { padding: 1.2rem 1rem 6rem; }
  body.chat-open .main { margin-right: auto; }
  .sim-body { grid-template-columns: 1fr; }
  .chapter-head, .panel, .lesson { padding: 1.2rem; }
}
