/* eCircuitCalc — Batteries & Energy Storage (reuses base.css tokens/components) */

/* Reading progress */
.rprog{position:fixed;top:0;left:0;right:0;height:3px;z-index:120;pointer-events:none}
.rprog span{display:block;height:100%;width:0;background:var(--grad);transition:width .1s linear}

/* Sticky control bar */
.batt-bar{position:sticky;top:var(--nav-h,64px);z-index:90;background:color-mix(in srgb,var(--bg) 84%,transparent);backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px);border-bottom:1px solid var(--border)}
.batt-controls{display:flex;align-items:center;gap:.8rem;flex-wrap:wrap;padding:.6rem 0}
.lvl-filters{display:flex;gap:.4rem;overflow-x:auto;scrollbar-width:thin}
.lvl-btn{flex:none;font-size:.82rem;padding:.5rem .9rem;border-radius:999px;border:1px solid var(--border);color:var(--text2);background:var(--surface);white-space:nowrap;transition:transform .2s var(--ease),color .2s,border-color .2s}
.lvl-btn:hover{color:var(--accent);border-color:var(--accent);transform:translateY(-1px)}
.lvl-btn.active{color:#fff;background:var(--grad);border-color:transparent}
.jump{margin-left:auto;font-size:.82rem;color:var(--text2);display:flex;align-items:center;gap:.45rem}
.jump select{padding:.45rem .6rem;border-radius:10px;border:1px solid var(--border2);background:var(--surface2);color:var(--text);font:inherit;font-size:.82rem;max-width:220px}
.prog-pill{font-family:var(--mono);font-size:.72rem;color:var(--accent);border:1px solid var(--border2);border-radius:999px;padding:.35rem .7rem;white-space:nowrap}
@media (max-width:640px){.jump{order:3;margin-left:0;width:100%}.jump select{flex:1;max-width:none}}

/* Prose + levels */
.prose{width:min(1120px,92%);margin:0 auto;display:grid;gap:clamp(2rem,4vw,3rem);padding:1.5rem 0 2rem}
.lvl-head{font-size:clamp(1.5rem,3.5vw,2.1rem);font-weight:800;letter-spacing:-.02em;padding-bottom:.6rem;border-bottom:2px solid var(--border)}
.lvl-intro{color:var(--text2);line-height:1.75}
.lesson{scroll-margin-top:150px}
.lesson-title{font-size:1.15rem;font-weight:700;display:flex;align-items:baseline;gap:.6rem;margin-bottom:.35rem}
.lnum{font-family:var(--mono);font-size:.82rem;font-weight:600;color:#fff;background:var(--grad);border-radius:8px;padding:.1rem .5rem;align-self:center}
.lvl-tag{font-family:var(--mono);font-size:.68rem;letter-spacing:.1em;text-transform:uppercase;color:var(--accent);margin-bottom:.7rem}
.lesson p{color:var(--text2);line-height:1.72;margin-bottom:.85rem}
.lesson a{color:var(--accent);text-decoration:underline;text-underline-offset:3px}
.inline-f{font-family:var(--mono);font-size:.9em;color:var(--text)}
.muted{color:var(--text2);font-size:.92rem}

/* Formula */
.formula{font-family:var(--mono);font-size:.9rem;background:var(--surface);border:1px solid var(--border);border-left:3px solid var(--accent);border-radius:0 12px 12px 0;padding:.85rem 1.1rem;margin:1rem 0;overflow-x:auto}
.formula code{color:var(--text);white-space:nowrap}

/* Worked example */
.worked{border:1px solid var(--border);border-radius:14px;background:var(--surface);padding:1.1rem 1.2rem;margin:1.2rem 0}
.worked .tag{display:inline-block;font-family:var(--mono);font-size:.62rem;letter-spacing:.12em;text-transform:uppercase;color:var(--accent);font-weight:600;margin-bottom:.5rem}
.worked ol{margin:0 0 0 1.2rem;color:var(--text2);line-height:1.65}
.worked li{margin-bottom:.45rem}
.worked li strong{color:var(--text)}

/* Tables */
.table-wrap{overflow-x:auto;border:1px solid var(--border);border-radius:14px;background:var(--surface);margin:1.2rem 0}
table{width:100%;border-collapse:collapse}
.spec{min-width:440px}
.spec caption{caption-side:top;text-align:left;padding:.9rem 1.1rem .3rem;font-family:var(--mono);font-size:.7rem;letter-spacing:.08em;text-transform:uppercase;color:var(--text2)}
.spec th,.spec td{padding:.7rem 1rem;text-align:left;border-bottom:1px solid var(--border);font-size:.92rem}
.spec th{font-family:var(--mono);font-size:.7rem;letter-spacing:.08em;text-transform:uppercase;color:var(--text2);background:var(--surface2)}

.spec tbody tr:last-child td{border-bottom:0}
.spec td strong{color:var(--text)}

/* Callouts */
.callout{border:1px solid var(--border);border-left:3px solid var(--accent);background:var(--surface);border-radius:0 12px 12px 0;padding:1rem 1.2rem;margin:1.1rem 0}
.callout p{margin:0}
.callout .tag{display:inline-block;font-family:var(--mono);font-size:.62rem;letter-spacing:.12em;text-transform:uppercase;margin-bottom:.4rem;font-weight:600}
.callout.safety{border-left-color:#f87171;background:color-mix(in srgb,#f87171 8%,var(--surface))}
.callout.safety .tag{color:#f87171}
.callout.tip{border-left-color:#4ade80}.callout.tip .tag{color:#4ade80}

/* Reveal */
.qa{border:1px solid var(--border);border-radius:14px;background:var(--surface);padding:1rem 1.2rem;margin:1rem 0}
.qa-q{margin:0 0 .8rem}
.qa-badge{display:inline-block;font-family:var(--mono);font-size:.6rem;letter-spacing:.12em;text-transform:uppercase;color:var(--accent);border:1px solid var(--border2);border-radius:6px;padding:.15rem .5rem;margin-right:.5rem;vertical-align:middle}
.qa-body{margin-bottom:.9rem}
.qa-a{margin-bottom:.5rem}
.qa-ex{color:var(--text2);font-size:.9rem;margin:0;border-left:2px solid var(--border);padding-left:.8rem}
.qa-btn{font-size:.85rem;font-weight:600;padding:.5rem 1rem;border-radius:10px;border:1px solid var(--border2);background:var(--surface2);color:var(--accent);cursor:pointer;transition:.2s}
.qa-btn:hover{border-color:var(--accent)}

/* Quiz */
.quiz{border:1px solid var(--border);border-radius:14px;background:var(--surface);padding:1.1rem 1.2rem;margin:1rem 0}
.quiz-q{margin:0 0 .9rem}
.quiz-opts{display:grid;gap:.5rem;margin-bottom:.9rem}
.quiz-opt{text-align:left;font-size:.92rem;padding:.7rem .9rem;border-radius:10px;border:1px solid var(--border2);background:var(--surface2);color:var(--text);cursor:pointer;transition:.2s}
.quiz-opt:hover:not(:disabled){border-color:var(--accent);color:var(--accent)}
.quiz-opt[aria-pressed="true"]{border-color:var(--accent);background:color-mix(in srgb,var(--accent) 14%,var(--surface2));color:var(--accent);font-weight:600}
.quiz-opt:disabled{cursor:default;opacity:.85}
.quiz-opt.correct{border-color:#4ade80;background:rgba(74,222,128,.14);color:#4ade80;font-weight:600;opacity:1}
.quiz-opt.wrong{border-color:#f87171;background:rgba(248,113,113,.14);color:#f87171;opacity:1}
.quiz-foot{display:flex;align-items:center;gap:.9rem;flex-wrap:wrap}
.quiz-check{font-size:.85rem;font-weight:600;padding:.55rem 1.1rem;border-radius:10px;background:var(--grad);color:#fff;cursor:pointer;transition:transform .2s}
.quiz-check:hover:not(:disabled){transform:translateY(-1px)}
.quiz-check:disabled{opacity:.5;cursor:default}
.quiz-feedback{margin:0;font-weight:600;font-size:.9rem}
.quiz-feedback.ok{color:#4ade80}
.quiz-feedback.no{color:#fbbf24}
.quiz-ex{margin-top:.8rem}

/* Checklist */
.checklist{border:1px solid var(--border);border-radius:14px;background:var(--surface);padding:1.1rem 1.2rem;margin:1.2rem 0}
.checklist h3{margin:0 0 .8rem}
.checklist ul{list-style:none;display:grid;gap:.55rem;margin-bottom:.9rem}
.checklist label{display:flex;gap:.6rem;align-items:flex-start;cursor:pointer;font-size:.92rem;color:var(--text2);transition:color .2s}
.checklist input{margin-top:.25rem;accent-color:var(--accent);width:17px;height:17px;flex:none;cursor:pointer}
.checklist label.done{color:var(--text);text-decoration:line-through;text-decoration-color:var(--border2)}
.checklist-status{font-family:var(--mono);font-size:.78rem;color:var(--text2)}
.checklist.all-done{border-color:#4ade80}
.checklist.all-done .checklist-status{color:#4ade80}

/* ============ Interactive LAB ============ */
.blab{border:1px solid var(--border);border-radius:16px;background:var(--surface);padding:1.2rem;margin:1.3rem 0}
.blab h3{margin:0 0 1rem}
.blab-controls{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:1rem;margin-bottom:1rem}
.ctl{display:grid;gap:.45rem;align-content:start}
.ctl label,.ctl-legend{font-size:.82rem;font-weight:600;color:var(--text)}
.ctl input[type=number]{padding:.55rem .7rem;border-radius:10px;border:1px solid var(--border2);background:var(--surface2);color:var(--text);font:inherit}
.ctl-val{font-family:var(--mono);font-size:.88rem;color:var(--accent);font-weight:600}
.radio-row{display:flex;gap:1rem;flex-wrap:wrap}
.radio-row label{display:flex;align-items:center;gap:.4rem;font-size:.88rem;color:var(--text);cursor:pointer}
.radio-row input{accent-color:var(--accent);width:16px;height:16px}
input[type=range]{-webkit-appearance:none;appearance:none;width:100%;height:6px;border-radius:99px;background:var(--surface2);outline:none;cursor:pointer}
input[type=range]::-webkit-slider-thumb{-webkit-appearance:none;width:18px;height:18px;border-radius:50%;background:var(--grad);border:2px solid var(--bg);cursor:pointer;box-shadow:0 2px 6px var(--glow)}
input[type=range]::-moz-range-thumb{width:16px;height:16px;border-radius:50%;background:var(--accent);border:2px solid var(--bg);cursor:pointer}
input[type=range]::-moz-range-track{height:6px;border-radius:99px;background:var(--surface2)}
input[type=range]:focus-visible,.ctl input:focus-visible,.jump select:focus-visible{outline:2px solid var(--accent);outline-offset:3px}
.blab-result{display:grid;gap:.5rem}
.res-line{font-size:.95rem;color:var(--text2);line-height:1.6}
.res-line strong{color:var(--text)}
.res-status{font-size:.9rem;font-weight:600;padding:.7rem .9rem;border-radius:10px;border:1px solid var(--border);line-height:1.5}
.res-status.ok{color:#4ade80;border-color:rgba(74,222,128,.4);background:rgba(74,222,128,.08)}
.res-status.warn{color:#fbbf24;border-color:rgba(251,191,36,.4);background:rgba(251,191,36,.08)}
.res-status.danger,.res-status.error{color:#f87171;border-color:rgba(248,113,113,.4);background:rgba(248,113,113,.08)}

/* ============ Animated battery SVG ============ */
.batt-anim{border:1px solid var(--border);border-radius:16px;background:var(--surface);padding:1.2rem;margin:1.3rem 0}
.batt-svg{width:100%;height:auto;display:block;max-width:640px;margin:0 auto}
.batt-svg .frame{fill:var(--surface2);stroke:var(--border2);stroke-width:2}
.batt-svg .cellbg{fill:var(--surface);stroke:var(--border2);stroke-width:1.5}
.batt-svg .cellfill{fill:var(--accent);transform-origin:center bottom;transform:scaleY(var(--soc,1))}
.batt-svg .chip{fill:var(--surface2);stroke:var(--accent);stroke-width:1.5}
.batt-svg .cable{stroke:var(--text2);stroke-width:3;fill:none}
.batt-svg .flow{stroke:var(--accent);stroke-width:3;fill:none;stroke-linecap:round;stroke-dasharray:6 10;opacity:0;transition:opacity .3s}
.batt-svg.charging .flow-in{opacity:1;animation:battflow 1s linear infinite}
.batt-svg.discharging .flow-out{opacity:1;animation:battflow 1s linear infinite}
@keyframes battflow{to{stroke-dashoffset:-16}}
.batt-svg .lbl{fill:var(--text2);font:600 12px var(--mono)}
.batt-svg .soc-bg{fill:var(--surface2)}
.batt-svg .soc-fill{fill:var(--grad)}
.batt-svg .read{fill:var(--text);font:700 15px var(--mono)}
.batt-controls{display:flex;gap:.6rem;justify-content:center;margin-top:1rem;flex-wrap:wrap}
.batt-btn{font-size:.85rem;font-weight:600;padding:.55rem 1.1rem;border-radius:10px;border:1px solid var(--border2);background:var(--surface2);color:var(--text);cursor:pointer;transition:.2s}
.batt-btn.active{background:var(--grad);color:#fff;border-color:transparent}

/* ============ Charge / Discharge viz ============ */
.viz{border:1px solid var(--border);border-radius:16px;background:var(--surface);padding:1.2rem;margin:1.3rem 0}
.viz h3{margin:0 0 1rem}
.viz-svg{background:var(--bg2);border:1px solid var(--border);border-radius:12px;padding:.6rem}
.viz-svg svg{width:100%;height:auto;display:block}
.viz-svg .grid{stroke:var(--border);stroke-width:1}
.viz-svg .axis{stroke:var(--text2);stroke-width:1.5}
.viz-svg .curve-v{stroke:var(--accent);stroke-width:2.6;fill:none}
.viz-svg .curve-i{stroke:#fbbf24;stroke-width:2.2;fill:none;stroke-dasharray:4 4}
.viz-svg .scan{stroke:var(--accent);stroke-width:1.5;opacity:.7}
.viz-svg .dot{fill:var(--accent)}
.viz-svg .dot-i{fill:#fbbf24}
.viz-svg .legend{fill:var(--text2);font:600 11px var(--mono)}
.viz-controls{display:flex;align-items:center;gap:1rem;margin-top:.9rem;flex-wrap:wrap}
.viz-btn{font-size:.85rem;font-weight:600;padding:.5rem 1.1rem;border-radius:10px;background:var(--grad);color:#fff;cursor:pointer}
.viz-scrub{flex:1;min-width:140px}
.viz-read{display:flex;gap:1rem;flex-wrap:wrap;margin-top:.8rem}
.viz-read .res-line{margin:0}

/* Ad slot (auto-hides when empty) */
.ad-slot{max-width:728px;margin:1.5rem auto;text-align:center;transition:max-height .5s var(--ease),opacity .4s,margin .5s;max-height:160px;overflow:hidden}
.ad-slot.ad-hidden{max-height:0;opacity:0;margin:0}
.ad-label{display:block;font-family:var(--mono);font-size:.6rem;letter-spacing:.2em;text-transform:uppercase;color:var(--text2);opacity:.6;margin-bottom:.4rem}
.ad-box{min-height:90px;border:1.5px dashed var(--border2);border-radius:12px;display:grid;place-items:center;color:var(--text2);font-size:.85rem;background:var(--surface)}

/* Module prev/next */
.modnav{display:flex;gap:1rem;justify-content:space-between;flex-wrap:wrap}
.modnav-link{flex:1 1 240px;display:flex;flex-direction:column;gap:.2rem;padding:1rem 1.2rem;border-radius:14px;border:1px solid var(--border);background:var(--surface);transition:transform .2s var(--ease),border-color .2s}
.modnav-link:hover{transform:translateY(-3px);border-color:var(--accent)}
.mn-label{font-family:var(--mono);font-size:.66rem;letter-spacing:.12em;text-transform:uppercase;color:var(--text2)}
.mn-title{font-weight:700;color:var(--text)}

/* Completed button */
.btn.done,.btn.btn-primary.done{background:linear-gradient(135deg,#22c55e 0%,#16a34a 100%);border-color:transparent;color:#fff;cursor:default;box-shadow:0 8px 24px -10px rgba(34,197,94,.6)}
.btn.done:hover{transform:none}

/* Focus + reduced motion + responsive */
.lvl-btn:focus-visible,.qa-btn:focus-visible,.quiz-check:focus-visible,.quiz-opt:focus-visible,.modnav-link:focus-visible,.batt-btn:focus-visible,.viz-btn:focus-visible,.checklist input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){
  .rprog span{transition:none}
  .batt-svg .flow{animation:none}
  .lvl-btn,.qa-btn,.quiz-check,.quiz-opt,.modnav-link,.batt-btn,.viz-btn{transition:none}
  .batt-svg .cellfill{transition:none}
}
@media (max-width:640px){
  .blab,.viz,.batt-anim{padding:1rem}
  .blab-controls{grid-template-columns:1fr 1fr}
  .res-line,.res-status{font-size:.88rem}
}
@media (max-width:420px){
  .blab-controls{grid-template-columns:1fr}
}
