:root {
  --bg: #0f1623;
  --panel: #1a2436;
  --panel-2: #222f45;
  --ink: #e8eef7;
  --muted: #9fb0c8;
  --accent: #36c9b0;
  --accent-2: #5b8cff;
  --h-color: #8fd0ff;   /* hydrogen */
  --o-color: #ff6b6b;   /* oxygen */
  --line: #32415c;
  --good: #46d39a;
  --warn: #ffb454;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }

/* ---------- header ---------- */
.site-header { padding: 18px 28px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { display: flex; align-items: center; gap: 14px; }
.logo { font-size: 34px; }
.site-header h1 { margin: 0; font-size: 22px; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

/* ---------- hub ---------- */
.hub { max-width: 920px; margin: 32px auto; padding: 0 20px; }
.course-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px 26px; }
.course-card h2 { margin: 0 0 4px; }
.muted { color: var(--muted); }
.chapter-list { list-style: none; padding: 0; margin: 18px 0 0; display: grid; gap: 12px; }
.chapter { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.chapter.ready:hover { border-color: var(--accent); transform: translateY(-1px); transition: .15s; }
.chapter.soon { opacity: .55; }
.chapter .num { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-2); color: #06101f; display: grid; place-items: center; font-weight: 700; }
.chapter .title { flex: 1; font-weight: 600; }
.badge { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: rgba(54,201,176,.15); color: var(--accent); border: 1px solid rgba(54,201,176,.4); }
.soon-badge { background: rgba(159,176,200,.12); color: var(--muted); border-color: var(--line); }

/* ---------- lab (dual pane) ---------- */
.lab-header { padding: 12px 22px; border-bottom: 1px solid var(--line); background: var(--panel); display: flex; align-items: center; gap: 16px; }
.lab-header a.back { color: var(--muted); text-decoration: none; font-size: 14px; }
.lab-header h1 { font-size: 18px; margin: 0; }
.lab-header .eq { margin-left: auto; font-size: 15px; color: var(--accent); letter-spacing: .3px; }

.lab { display: grid; grid-template-columns: 1fr 1.25fr; gap: 16px; padding: 16px; height: calc(100vh - 56px); }
@media (max-width: 900px) { .lab { grid-template-columns: 1fr; height: auto; } }

.pane { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; overflow: auto; }
.pane h2 { margin: 0 0 10px; font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }

/* explanation pane */
.video-box { aspect-ratio: 16/9; background: #0a111d; border: 1px dashed var(--line); border-radius: 10px; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 10px; }
.lesson-step { margin-top: 16px; line-height: 1.6; }
.lesson-step h3 { margin: 0 0 6px; color: var(--accent); font-size: 16px; }
.key-points { margin: 14px 0 0; padding-left: 18px; line-height: 1.7; }
.key-points li::marker { color: var(--accent-2); }

/* simulator pane */
.controls { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-end; margin-bottom: 8px; }
.control label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.control .val { color: var(--ink); font-weight: 700; }
.control input[type=range] { width: 160px; accent-color: var(--accent); }
.btns { margin-left: auto; display: flex; gap: 10px; }
button { font: inherit; border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); padding: 9px 16px; border-radius: 10px; cursor: pointer; }
button.primary { background: var(--accent); color: #06121022; border-color: var(--accent); color: #04201b; font-weight: 700; }
button:hover { filter: brightness(1.1); }

#viz { width: 100%; height: 340px; background: #0b1320; border-radius: 10px; border: 1px solid var(--line); margin: 10px 0; }
.legend { display: flex; gap: 18px; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }

/* results */
.results { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 8px; }
.result { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.result .k { font-size: 12px; color: var(--muted); }
.result .v { font-size: 18px; font-weight: 700; margin-top: 2px; }
.result.limiting .v { color: var(--warn); }
.result.product .v { color: var(--good); }
.verdict { margin-top: 12px; padding: 12px 14px; border-radius: 10px; background: rgba(91,140,255,.1); border: 1px solid rgba(91,140,255,.35); line-height: 1.55; }
.tip { font-size: 13px; color: var(--muted); margin: 4px 0 0; }
.tip b { color: var(--accent); }

/* view switch (molecular vs real lab) */
.view-switch { display: flex; gap: 8px; margin-bottom: 14px; }
.vbtn { background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); padding: 8px 14px; border-radius: 999px; }
.vbtn.active { background: var(--accent); color: #04201b; border-color: var(--accent); font-weight: 700; }
#labViz { width: 100%; height: 360px; background: #0b1320; border-radius: 10px; border: 1px solid var(--line); margin: 10px 0; }
.eq-bar { text-align: center; font-size: 18px; color: var(--accent); letter-spacing: .4px; padding: 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; }
select { font: inherit; background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; max-width: 100%; }

/* ---------- virtual chemistry lab ---------- */
.vlab { display: grid; grid-template-columns: 1fr 1.3fr 1fr; gap: 16px; padding: 16px; }
@media (max-width: 1000px) { .vlab { grid-template-columns: 1fr; } }
.shelf .bottles { display: grid; gap: 10px; }
.bottle { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); cursor: grab; }
.bottle:hover { border-color: var(--accent); }
.bottle:active { cursor: grabbing; }
.bottle .vial { width: 16px; height: 26px; border-radius: 3px 3px 5px 5px; background: linear-gradient(to top, var(--c) 60%, rgba(255,255,255,.15) 60%); border: 1px solid #06101f; box-shadow: inset 0 0 0 2px rgba(255,255,255,.08); }
.bottle .bl { display: flex; flex-direction: column; line-height: 1.15; }
.bottle .bl small { color: var(--muted); font-size: 11px; }

.bench #benchSvg { width: 100%; height: 420px; background: #0b1320; border-radius: 10px; border: 1px solid var(--line); }
.bench #benchSvg.drop-hot { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(54,201,176,.4) inset; }
.bench-controls { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
#heatBtn.on { background: #ff7676; border-color: #ff7676; color: #2a0808; font-weight: 700; }
.in-beaker { display: flex; flex-wrap: wrap; gap: 6px; min-height: 28px; }
.in-beaker .chip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 13px; }
.in-beaker .chip i { cursor: pointer; color: var(--muted); font-style: normal; margin-left: 4px; }
.in-beaker .chip i:hover { color: #ff7676; }

.obs .hints { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.obs .hints h3 { margin: 0 0 8px; font-size: 14px; color: var(--muted); }
.obs .hints ul { margin: 0; padding-left: 18px; line-height: 1.8; font-size: 14px; }
.obs .hints li::marker { color: var(--accent); }

/* ---------- periodic table lab ---------- */
.pt-wrap { padding: 16px 20px 40px; max-width: 1280px; margin: 0 auto; }
.pt-howto { color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.pt-howto b { color: var(--accent); }

.pt-grid { display: grid; grid-template-columns: repeat(18, 1fr); grid-auto-rows: 1fr; gap: 4px; margin: 14px 0; }
.pt-tile {
  position: relative; aspect-ratio: 1 / 1; border-radius: 6px; cursor: grab;
  border: 1px solid rgba(0,0,0,.35); background: var(--cat); color: #06101f;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  overflow: hidden; user-select: none; transition: transform .1s, box-shadow .1s;
}
.pt-tile:hover { transform: translateY(-2px) scale(1.06); box-shadow: 0 6px 14px rgba(0,0,0,.45); z-index: 5; }
.pt-tile.dragging { opacity: .4; }
.pt-tile.drop-hover { outline: 3px solid #fff; outline-offset: -1px; z-index: 6; }
.pt-tile .z { position: absolute; top: 2px; left: 4px; font-size: 8px; opacity: .8; }
.pt-tile .sym { font-size: 17px; font-weight: 800; line-height: 1; }
.pt-tile .nm { font-size: 6.5px; text-align: center; line-height: 1; margin-top: 2px; padding: 0 1px; white-space: nowrap; overflow: hidden; max-width: 100%; }
@media (max-width: 760px) { .pt-tile .nm { display: none; } .pt-tile .sym { font-size: 12px; } }

.pt-legend { display: flex; flex-wrap: wrap; gap: 10px 16px; font-size: 12px; color: var(--muted); margin: 8px 0 18px; }
.pt-legend .lg { display: inline-flex; align-items: center; gap: 6px; }

.pt-result { margin-top: 8px; }
.pt-result.flash { animation: flashpulse .6s ease; }
@keyframes flashpulse { 0% { box-shadow: 0 0 0 0 rgba(54,201,176,.5); } 100% { box-shadow: 0 0 0 16px rgba(54,201,176,0); } }
.pt-result-body { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
#prodSvg { width: 360px; max-width: 100%; height: 220px; background: #0b1320; border-radius: 10px; border: 1px solid var(--line); }
.pt-result-text { flex: 1; min-width: 220px; }
.pt-formula { font-size: 40px; font-weight: 800; color: var(--ink); }
.pt-name { font-size: 18px; color: var(--accent); margin: 4px 0 8px; }
.pt-eq { font-size: 16px; color: var(--accent-2); margin-bottom: 8px; }

/* ---------- atomic-structure modal ---------- */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(4,8,16,.72); z-index: 50; align-items: center; justify-content: center; padding: 20px; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; max-width: 540px; width: 100%; }
.modal-top { display: flex; align-items: center; justify-content: space-between; font-size: 17px; margin-bottom: 8px; }
.modal-top button { padding: 4px 10px; }
#atomicSvg { width: 100%; height: 300px; background: #0b1320; border-radius: 10px; border: 1px solid var(--line); }
.modal-card .muted { margin: 12px 0 0; line-height: 1.5; }
