/* EduLab — one stylesheet, both themes, plus a print sheet so a lesson can
   leave the browser as a handout. */

:root {
  --bg: #f5f6fa;
  --panel: #ffffff;
  --panel-2: #f0f2f7;
  --ink: #171a21;
  --ink-2: #5b6474;
  --line: #dfe3ec;
  --accent: #2f6df6;
  --accent-ink: #ffffff;
  --good: #18a06a;
  --bad: #d84a4f;
  --warn: #d9911f;
  --shadow: 0 1px 2px rgba(18, 24, 40, .06), 0 8px 24px rgba(18, 24, 40, .06);
  --radius: 14px;
}

:root[data-theme="dark"] {
  --bg: #0b0f18;
  --panel: #141a26;
  --panel-2: #1a2230;
  --ink: #e9edf7;
  --ink-2: #98a2b6;
  --line: #253046;
  --accent: #7aa2ff;
  --accent-ink: #0b0f18;
  --good: #53d8a0;
  --bad: #ff7b80;
  --warn: #f0c650;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.9rem; letter-spacing: -.015em; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.02rem; }
h4 { font-size: .93rem; }
p { margin: 0 0 .7rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em;
       background: var(--panel-2); padding: .1em .35em; border-radius: 5px; }

.hidden { display: none !important; }
.muted { color: var(--ink-2); }
.tiny { font-size: .82rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ------------------------------------------------------------------ header */

.hdr {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.hdr-inner {
  max-width: 1380px; margin: 0 auto; padding: .6rem 1rem;
  display: flex; align-items: center; gap: 1rem; justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 650; color: var(--ink); }
.brand:hover { text-decoration: none; }
.hdr-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.hdr-link { color: var(--ink-2); font-size: .87rem; }
.hdr-link.accent { color: var(--accent); }
.hdr-credits { display: inline-flex; gap: .5rem; align-items: center; font-size: .87rem; color: var(--ink-2); }

/* ------------------------------------------------------------------ buttons */

.btn {
  font: inherit; font-size: .9rem; font-weight: 550;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: .48rem .85rem; border-radius: 10px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.small { padding: .3rem .6rem; font-size: .82rem; border-radius: 8px; }
.btn.big { width: 100%; padding: .7rem 1rem; font-size: 1rem; }
.btn.icon { padding: .4rem .55rem; }
.btn.on { border-color: var(--accent); color: var(--accent); }
.btn-row { display: flex; gap: .45rem; flex-wrap: wrap; margin-top: .5rem; }

/* ------------------------------------------------------------------ layout */

.main { max-width: 1380px; margin: 0 auto; padding: 1.2rem 1rem 3rem; }
.hero { max-width: 62ch; margin-bottom: 1.2rem; }
.hero p { color: var(--ink-2); }

.layout { display: grid; grid-template-columns: minmax(320px, 400px) minmax(0, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 1060px) { .layout { grid-template-columns: 1fr; } }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem;
}
.col-input { position: sticky; top: 64px; }
@media (max-width: 1060px) { .col-input { position: static; } }

/* ------------------------------------------------------------------- input */

textarea, input[type="text"], input[type="search"], select {
  width: 100%; font: inherit; color: var(--ink); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px; padding: .55rem .65rem;
}
textarea { resize: vertical; min-height: 120px; }
textarea:focus, input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; }
.lbl { display: block; font-size: .82rem; color: var(--ink-2); margin-bottom: .3rem; }
.row-3 { display: grid; grid-template-columns: 1fr; gap: .5rem; margin-top: .6rem; }
@media (min-width: 520px) { .row-3 { grid-template-columns: 1fr 1fr; } }

.dropzone { border: 1.5px dashed var(--line); border-radius: 12px; padding: .5rem; transition: border-color .15s, background .15s; }
.dropzone.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.drop-hint { font-size: .8rem; color: var(--ink-2); padding: .35rem .2rem 0; }

.examples { display: grid; gap: .5rem; }
.example-card {
  display: grid; gap: .15rem; text-align: left; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 11px;
  padding: .6rem .7rem; color: var(--ink); font: inherit;
}
.example-card:hover { border-color: var(--accent); }
.example-card span { font-size: .82rem; color: var(--ink-2); }
.example-card small { font-size: .72rem; color: var(--accent); }

/* ----------------------------------------------------------------- status */

.status { margin-top: .7rem; border-top: 1px solid var(--line); padding-top: .6rem; }
.status-head { display: flex; align-items: center; gap: .5rem; font-size: .9rem; }
.status-title { flex: 1; }
.status-timer { color: var(--ink-2); font-variant-numeric: tabular-nums; font-size: .82rem; }
.spinner { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.spinner.stopped { animation: none; border-top-color: var(--line); }
@keyframes spin { to { transform: rotate(360deg); } }
.steps { list-style: none; margin: .5rem 0 0; padding: 0; display: grid; gap: .2rem; }
.step { display: flex; gap: .45rem; align-items: center; font-size: .84rem; color: var(--ink-2); }
.step .mark { width: 1em; opacity: .25; }
.step.done .mark { opacity: 1; color: var(--good); }
.step.active { color: var(--ink); }
.step-time { margin-left: auto; font-variant-numeric: tabular-nums; opacity: .7; font-size: .78rem; }
.status-note { font-size: .8rem; color: var(--ink-2); margin-top: .35rem; }

.banner { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap;
          padding: .55rem .75rem; border-radius: 10px; font-size: .88rem; margin-bottom: .8rem; }
.banner.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); }

/* ----------------------------------------------------------------- lesson */

.empty h3 { margin-bottom: .3rem; }
.empty ul { margin: .5rem 0 0; padding-left: 1.1rem; }
.empty li { margin-bottom: .2rem; }

.lesson-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; margin-bottom: .6rem; }
.lesson-head-actions { display: flex; gap: .4rem; flex-shrink: 0; }

.answer {
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 10%, transparent), transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line));
  border-radius: 12px; padding: .7rem .9rem; margin-bottom: .9rem;
}
.answer-label { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }
.answer-latex { font-size: 1.15rem; margin: .2rem 0; overflow-x: auto; }
.answer-text { margin: .2rem 0 0; color: var(--ink-2); font-size: .92rem; }

.stage-wrap { position: relative; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--panel-2); }
.stage { display: block; width: 100%; height: clamp(320px, 46vh, 560px); }
/* The WebGL canvases are injected by three.js, so they get no rules of their
   own — pin them to their host so a renderer sizing slip can never overflow
   the crop again. */
.stage > canvas { display: block; width: 100%; height: 100%; }
.stage-none { display: flex; align-items: center; justify-content: center; color: var(--ink-2); font-size: .9rem; height: 160px; }

.controls { display: grid; gap: .5rem; padding: .7rem 0 .2rem; }
#ctl-solid { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.slider-row { display: flex; align-items: center; gap: .6rem; }
.slider-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.param-label { min-width: 2.5rem; }
.param-value { font-variant-numeric: tabular-nums; color: var(--ink-2); min-width: 4.5rem; text-align: right; font-size: .9rem; }

.readouts { display: grid; gap: .3rem; }
.readout { display: flex; justify-content: space-between; gap: 1rem; align-items: baseline;
           background: var(--panel-2); border-radius: 9px; padding: .35rem .6rem; }
.readout-value { font-variant-numeric: tabular-nums; font-weight: 600; }

.rangebar { display: grid; gap: .25rem; }
.rangebar-track { position: relative; height: 8px; background: var(--panel-2); border-radius: 99px; border: 1px solid var(--line); }
.rangebar-fill { position: absolute; top: 0; bottom: 0; background: color-mix(in srgb, var(--accent) 35%, transparent); border-radius: 99px; }
.rangebar-dot { position: absolute; top: 50%; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--panel); }
.rangebar-labels { display: flex; justify-content: space-between; font-size: .8rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }

.eq-row { font-size: 1.02rem; font-weight: 600; margin-bottom: .4rem; }
.atom-grid { display: flex; gap: .4rem; flex-wrap: wrap; }
.atom-chip { display: flex; gap: .35rem; align-items: baseline; background: var(--panel-2); border: 1px solid var(--line);
             border-radius: 8px; padding: .2rem .5rem; font-size: .84rem; }
.atom-chip.bad { border-color: var(--bad); color: var(--bad); }
.bonds { display: grid; gap: .5rem; grid-template-columns: 1fr; }
@media (min-width: 700px) { .bonds { grid-template-columns: 1fr 1fr 1fr; } }
.bond-group h5 { margin: 0 0 .25rem; font-size: .8rem; color: var(--ink-2); text-transform: uppercase; letter-spacing: .05em; }
.bond-chips { display: flex; gap: .3rem; flex-wrap: wrap; }
.bond-chip { font: inherit; font-size: .78rem; cursor: pointer; border-radius: 7px; padding: .12rem .42rem;
             border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); }
.bond-chip:hover { border-color: var(--accent); }
.bond-group.break .bond-chip { border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
.bond-group.form .bond-chip { border-color: color-mix(in srgb, var(--good) 45%, var(--line)); }
.energy { width: 100%; max-width: 520px; height: auto; }

/* ------------------------------------------------------------------- tabs */

.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); margin: 1rem 0 .8rem; }
.tab { font: inherit; font-size: .9rem; background: none; border: none; color: var(--ink-2);
       padding: .45rem .7rem; cursor: pointer; border-bottom: 2px solid transparent; }
.tab.sel { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

.step-nav { display: flex; gap: .4rem; align-items: center; margin-bottom: .7rem; flex-wrap: wrap; }
.step-nav .muted { margin-left: auto; }

.given { margin-bottom: .8rem; }
.given-grid { display: flex; gap: .4rem; flex-wrap: wrap; }
.given-row { display: flex; gap: .3rem; align-items: baseline; background: var(--panel-2);
             border: 1px solid var(--line); border-radius: 8px; padding: .2rem .5rem; font-size: .9rem; }

.steps-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; counter-reset: none; }
.step-item { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--panel); }
.step-item.sel { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent); }
.step-head { display: flex; gap: .6rem; align-items: center; width: 100%; text-align: left;
             font: inherit; font-weight: 600; background: var(--panel-2); border: none; color: var(--ink);
             padding: .5rem .7rem; cursor: pointer; }
.step-n { width: 1.5rem; height: 1.5rem; flex: none; display: grid; place-items: center; border-radius: 50%;
          background: var(--accent); color: var(--accent-ink); font-size: .8rem; }
.step-body { padding: .6rem .8rem .2rem; }
.step-body p { margin: 0 0 .55rem; }
.step-list { margin: 0 0 .55rem; padding-left: 1.2rem; }
.math-display { overflow-x: auto; padding: .2rem 0 .4rem; }
.math-fallback { white-space: pre-wrap; }
.notes { border-left: 3px solid var(--line); padding-left: .7rem; font-size: .88rem; margin-top: .8rem; }

/* ------------------------------------------------------------------ check */

.check-head { display: grid; gap: .3rem; padding: .6rem .8rem; border-radius: 11px; margin-bottom: .6rem;
              border: 1px solid var(--line); background: var(--panel-2); }
.check-head p { margin: 0; font-size: .92rem; }
.check-badge { font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; font-weight: 700; }
.check-head.ok { border-color: color-mix(in srgb, var(--good) 45%, var(--line)); }
.check-head.ok .check-badge { color: var(--good); }
.check-head.mismatch { border-color: color-mix(in srgb, var(--bad) 50%, var(--line)); }
.check-head.mismatch .check-badge { color: var(--bad); }
.check-head.skipped .check-badge { color: var(--ink-2); }
.check-table { width: 100%; border-collapse: collapse; font-size: .87rem; margin: .6rem 0; }
.check-table th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: .78rem;
                  text-transform: uppercase; letter-spacing: .04em; padding: .3rem .4rem; border-bottom: 1px solid var(--line); }
.check-table td { padding: .35rem .4rem; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.check-table td:first-child { font-variant-numeric: normal; }
.check-table tr.bad td { color: var(--bad); }
.check-mark { text-align: center; font-weight: 700; }
.check-warn { color: var(--bad); font-size: .88rem; }

.json { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: .7rem;
        overflow: auto; max-height: 460px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
        font-size: .78rem; line-height: 1.5; white-space: pre; }

/* ---------------------------------------------------------------- history */

.history { display: grid; gap: .4rem; margin-top: .5rem; }
.hist-row { display: flex; gap: .5rem; align-items: center; background: var(--panel-2);
            border: 1px solid var(--line); border-radius: 10px; padding: .45rem .55rem; }
.hist-body { flex: 1; min-width: 0; }
.hist-title { font-size: .88rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-meta { font-size: .76rem; color: var(--ink-2); }

/* ------------------------------------------------------------------- misc */

.how ol { padding-left: 1.2rem; margin: 0; }
.how li { margin-bottom: .35rem; }
.foot { border-top: 1px solid var(--line); background: var(--panel); }
.foot-inner { max-width: 1380px; margin: 0 auto; padding: 1.2rem 1rem 2rem; color: var(--ink-2); font-size: .86rem; }
.foot-links { display: flex; gap: 1rem; flex-wrap: wrap; }

/* ------------------------------------------------------------------ print */

@media print {
  /* What a handout needs: the problem, the figure, the numbers beside it and
     the worked steps. What it must not carry: the app's chrome, the controls
     you cannot press on paper, and — the bug this replaced — the raw lesson
     JSON, which printed as one clipped grey box. */
  .hdr, .col-input, .foot-links, .tabs, .step-nav, .lesson-head-actions, .how, .hero,
  #tab-data, .btn, input[type="range"], #run-status, .banner { display: none !important; }
  body { background: #fff; color: #000; }
  .layout { display: block; }
  .card { box-shadow: none; border: none; padding: 0; }
  #tab-steps.hidden, #tab-check.hidden { display: block !important; }

  /* The readouts, range bar, atom counter and bond lists carry the argument —
     they stay, minus their controls. */
  /* :not(.hidden) matters — without it this un-hides the control panels
     belonging to the other two modes, printing a 3D orbit hint under a 2D
     conic board. */
  .controls:not(.hidden) { display: grid !important; gap: .4rem; }
  .slider-row, #ctl-solid .muted { display: none !important; }
  .readout, .atom-chip, .bond-chip, .given-row { border-color: #bbb; background: #fff; }
  .rangebar-track { border-color: #999; }

  .stage-wrap { break-inside: avoid; border-color: #bbb; }
  .stage { height: 380px; }
  .answer { border-color: #999; background: #fff; }
  .step-item { break-inside: avoid; border-color: #ccc; }
  .step-head { background: #f2f2f2; }
  .check-head, .check-table td, .check-table th { border-color: #bbb; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: .75em; color: #555; }
}

/* Progressive reveal: a step's prose stays covered until it has been reached. */
.steps-list.reveal .step-item:not(.revealed) .step-body { display: none; }
.steps-list.reveal .step-item:not(.revealed) .step-head { opacity: .55; }

/* A copy to hand out: the figure, the problem and the step titles, no answers. */
.lesson.answers-hidden #answer-card,
.lesson.answers-hidden .step-body,
.lesson.answers-hidden #lesson-notes { display: none !important; }

textarea.json { width: 100%; min-height: 260px; max-height: 460px; resize: vertical; }
.stage-wrap:fullscreen { background: var(--panel); display: flex; align-items: center; }
.stage-wrap:fullscreen .stage { height: 100vh; width: 100vw; }
