:root {
  --bg: #0a0f1c; --side: #0d1426; --panel: #111a2e; --panel2: #16213a; --line: #24324d;
  --text: #e2e8f0; --dim: #94a3b8; --accent: #38bdf8; --accent2: #a78bfa;
  --good: #4ade80; --bad: #f87171; --warn: #fbbf24;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { display: flex; background: var(--bg); color: var(--text); font: 15px/1.6 "Segoe UI", system-ui, sans-serif; }
a { color: var(--accent); text-decoration: none; }
sub, sup { line-height: 0; }

/* sidebar */
#sidebar { width: 290px; flex: none; background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.brand { display: flex; gap: 12px; align-items: center; padding: 18px 18px 14px; border-bottom: 1px solid var(--line); }
.brand .logo { width: 42px; height: 42px; }
.brand b { font-size: 19px; display: block; }
.brand small { color: var(--dim); }
#nav { overflow-y: auto; padding: 10px; flex: 1; }
#nav a { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 8px 12px; border-radius: 8px; color: var(--text); font-size: 14px; }
#nav a:hover { background: var(--panel); }
#nav a.active { background: linear-gradient(90deg, #1e3a5f, #172554); color: #fff; }
.nav-h { color: var(--dim); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; margin: 14px 12px 6px; }
.pill { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: #334155; flex: none; }
.pill.good { background: #14532d; color: #bbf7d0; } .pill.mid { background: #713f12; color: #fde68a; } .pill.low { background: #7f1d1d; color: #fecaca; }

/* main */
#main { flex: 1; overflow-y: auto; padding: 28px 40px 60px; scroll-behavior: smooth; }
.hero { background: radial-gradient(circle at 80% 0%, #1e3a8a55, transparent 60%), var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 30px 34px; margin-bottom: 26px; }
.hero h1 { margin: 0 0 8px; font-size: 32px; }
.hero h1 span { background: linear-gradient(90deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { color: #cbd5e1; max-width: 820px; }
.stats { display: flex; gap: 14px; margin: 18px 0; flex-wrap: wrap; }
.stats div { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 18px; min-width: 120px; }
.stats b { font-size: 24px; display: block; color: var(--accent); }
.stats small { color: var(--dim); }
.how { display: flex; gap: 18px; flex-wrap: wrap; margin: 6px 0 10px; }
.how span { color: #cbd5e1; }
.how b { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--accent2); color: #0a0f1c; margin-right: 6px; }
.small { font-size: 13px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; color: var(--text); transition: transform .15s, border-color .15s; display: flex; flex-direction: column; }
.card:hover { transform: translateY(-3px); border-color: var(--accent); }
.card .ic { font-size: 30px; }
.card .meta { color: var(--dim); font-size: 12px; margin-top: 4px; }
.card h3 { margin: 4px 0 6px; font-size: 17px; }
.card p { color: var(--dim); font-size: 13.5px; margin: 0 0 12px; flex: 1; }
.card small { color: var(--dim); font-size: 12px; margin-top: 4px; }
.bar { height: 6px; background: #1e293b; border-radius: 9px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--good)); }

/* topic */
.topic-head { margin-bottom: 18px; position: relative; }
.topic-head h1 { margin: 2px 0 6px; font-size: 30px; }
.topic-head p { color: #cbd5e1; margin: 0 0 14px; max-width: 900px; }
.crumb { color: var(--dim); font-size: 13px; }
.tabs { display: flex; gap: 8px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 9px 18px; color: var(--dim); border-bottom: 3px solid transparent; font-weight: 600; }
.tabs a.on { color: #fff; border-color: var(--accent); }
.topic-body { max-width: 1000px; }
.toc { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 18px; }
.toc button { background: var(--panel); border: 1px solid var(--line); border-radius: 99px; padding: 4px 14px; font: inherit; font-size: 13px; color: #cbd5e1; cursor: pointer; }
.toc button:hover { border-color: var(--accent); }
.lesson { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px 24px; margin-bottom: 18px; }
.lesson h2 { margin: 0 0 10px; font-size: 21px; color: #f1f5f9; }
.lesson ul, .lesson ol { padding-left: 22px; }
.lesson li { margin: 4px 0; }
.key { background: #0c2a3f; border-left: 4px solid var(--accent); border-radius: 8px; padding: 10px 14px; margin: 12px 0; }
.tip { background: #2a210b; border-left: 4px solid var(--warn); border-radius: 8px; padding: 10px 14px; margin: 12px 0; }
.tip::before { content: '💡 '; }
.note { background: #1c1730; border: 1px solid #3b2f63; border-radius: 10px; padding: 10px 14px; color: #ddd6fe; font-size: 13.5px; max-width: 900px; }
.ext { display: inline-block; font-size: 11px; font-weight: 700; color: #ddd6fe; background: #4c1d95; border-radius: 6px; padding: 0 7px; margin: 0 2px; vertical-align: 1px; }
.dim { color: var(--dim); }
.hl { color: var(--warn); font-weight: 700; }
.good { color: var(--good); font-weight: 700; }
.warn { color: var(--warn); }
.big { font-size: 1.15em; }
.nuc sup, .nuc sub { font-size: 70%; }
.tbl { border-collapse: collapse; margin: 10px 0; width: 100%; font-size: 14px; }
.tbl th, .tbl td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.tbl th { background: var(--panel2); }
.next { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
pre.df { background: #0b1220; padding: 8px 14px; border-radius: 8px; display: inline-block; font-size: 14px; }

/* interactives */
.anim-slot { background: #0b1220; border: 1px solid #1e3a5f; border-radius: 12px; margin: 6px 0 16px; overflow: hidden; min-height: 560px; }
.anim-slot.mounted { min-height: 120px; }
.anim-title { background: linear-gradient(90deg, #0f2a4a, #0b1220); color: var(--accent); font-weight: 700; font-size: 13.5px; padding: 7px 14px; }
.anim-inner { padding: 10px 12px 12px; }
.anim-canvas { width: 100%; max-width: 820px; display: block; margin: 0 auto; border-radius: 8px; }
.anim-controls { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin: 10px 0 4px; }
.anim-controls > span { display: contents; }
.ctl { display: inline-flex; align-items: center; gap: 6px; color: #cbd5e1; font-size: 13.5px; }
.ctl input[type=range] { width: 140px; accent-color: var(--accent); }
.ctl .val { color: var(--accent); min-width: 54px; font-weight: 600; }
select, .txt, .num, textarea { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px; font: inherit; font-size: 14px; }
.num { width: 90px; }
.txt { width: 160px; }
.anim-info { background: var(--panel); border-radius: 8px; padding: 10px 14px; margin-top: 8px; font-size: 14px; color: #cbd5e1; }
.anim-info ul { margin: 6px 0; padding-left: 20px; }
.step { padding: 3px 0; opacity: .45; transition: opacity .3s; }
.step.on { opacity: 1; color: #fff; }
.step.done { opacity: .8; }
.tag { display: inline-block; font-size: 12px; font-weight: 700; border-radius: 5px; padding: 0 6px; }
.tag.neg { background: #1e3a8a; } .tag.pos { background: #7f1d1d; }
.nuclide { display: inline-grid; grid-template: auto auto / auto auto auto; float: right; font-size: 13px; margin: 0 6px 6px 10px; line-height: 1.1; }
.nuclide .sup { grid-area: 1 / 1; text-align: right; } .nuclide .sub { grid-area: 2 / 1; text-align: right; }
.nuclide .sym { grid-area: 1 / 2 / 3 / 3; font-size: 38px; font-weight: 800; padding: 0 2px; line-height: 1; }
.nuclide .chg { grid-area: 1 / 3; font-weight: 700; }
.calc { padding: 4px; }
.calc-grid { display: grid; grid-template-columns: 1fr 220px; gap: 16px; align-items: start; }
.calc-grid .ctl { margin: 4px 14px 4px 0; }
.triangle { width: 220px; }
.triangle .tri { fill: #e2e8f0; font: 600 16px "Segoe UI", sans-serif; cursor: pointer; }
.triangle .tri:hover { fill: var(--accent); }
.equation { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 22px; margin: 12px 0; }
.species { display: inline-flex; align-items: center; gap: 3px; background: var(--panel); border-radius: 10px; padding: 4px 6px; }
.coef { color: var(--warn); font-weight: 800; min-width: 10px; }
.mini { background: #1e293b; color: var(--text); border: 1px solid var(--line); border-radius: 6px; width: 24px; height: 24px; cursor: pointer; font-size: 14px; line-height: 1; }
.mini:hover { border-color: var(--accent); }
.plus, .arrow { color: var(--dim); }
.tally { display: grid; gap: 6px; }
.trow { display: flex; align-items: center; gap: 8px; background: #2a1414; border-radius: 8px; padding: 4px 10px; font-size: 14px; }
.trow.ok { background: #102a1a; }
.trow b { width: 26px; }
.trow .n { width: 22px; text-align: center; font-weight: 700; }
.trow .vs { color: var(--warn); font-weight: 700; }
.atoms { display: inline-flex; flex-wrap: wrap; gap: 3px; min-width: 120px; }
.atoms i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.ptable-wrap { overflow-x: auto; }
.ptable { display: grid; grid-template-columns: repeat(18, minmax(36px, 1fr)); gap: 3px; min-width: 700px; }
.ptable .gh { text-align: center; color: var(--dim); font-size: 11px; font-weight: 700; }
.pt { background: color-mix(in srgb, var(--c) 28%, #0b1220); border: 1px solid color-mix(in srgb, var(--c) 60%, transparent); color: #fff; border-radius: 5px; padding: 2px 0; cursor: pointer; display: flex; flex-direction: column; align-items: center; line-height: 1.15; }
.pt:hover { transform: scale(1.12); z-index: 1; }
.pt small { font-size: 9px; opacity: .8; }
.pt b { font-size: 14px; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; font-size: 12px; color: #cbd5e1; }
.legend span::before { content: ''; display: inline-block; width: 11px; height: 11px; border-radius: 3px; background: var(--c); margin-right: 5px; vertical-align: -1px; }

/* buttons */
.btn { background: linear-gradient(180deg, #2563eb, #1d4ed8); color: #fff; border: 0; border-radius: 8px; padding: 7px 14px; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; display: inline-block; }
.btn:hover { filter: brightness(1.15); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: #cbd5e1; }
.btn.ghost:hover { border-color: var(--accent); }
.btn.big { padding: 10px 20px; font-size: 15px; margin-top: 12px; }

/* quiz */
.quiz { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px 26px; max-width: 820px; }
.qprog { display: flex; justify-content: space-between; color: var(--dim); font-size: 13px; }
.qbar { height: 5px; background: #1e293b; border-radius: 9px; margin: 6px 0 14px; overflow: hidden; }
.qbar i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.qtext { font-size: 19px; margin: 6px 0 16px; line-height: 1.45; }
.opts { display: grid; gap: 10px; }
.opt { display: flex; gap: 12px; align-items: center; text-align: left; background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 11px 14px; font: inherit; cursor: pointer; }
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt .letter { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: #1e293b; font-weight: 700; }
.opt.right { border-color: var(--good); background: #0f2a1a; } .opt.right .letter { background: var(--good); color: #052e16; }
.opt.wrong { border-color: var(--bad); background: #2a1010; } .opt.wrong .letter { background: var(--bad); color: #450a0a; }
.opt:disabled { cursor: default; }
.explain { margin-top: 14px; border-radius: 10px; padding: 12px 16px; }
.explain.ok { background: #0f2a1a; border-left: 4px solid var(--good); }
.explain.no { background: #2a1010; border-left: 4px solid var(--bad); }
.result { text-align: center; }
.ring { width: 130px; height: 130px; border-radius: 50%; margin: 6px auto; display: grid; place-items: center; background: conic-gradient(var(--good) calc(var(--p) * 1%), #1e293b 0); }
.ring b { width: 104px; height: 104px; border-radius: 50%; background: var(--panel); display: grid; place-items: center; font-size: 26px; }
.review details { background: var(--panel2); border-radius: 8px; padding: 6px 12px; margin: 6px 0; }
.review details.ok summary { color: #bbf7d0; } .review details.no summary { color: #fecaca; }
.review summary { cursor: pointer; }

/* papers */
.timer { position: absolute; right: 0; top: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px 14px; font-weight: 700; }
.timer.low { color: var(--bad); border-color: var(--bad); }
.scorebar { position: sticky; top: -28px; z-index: 5; background: #0f2a4a; border: 1px solid #1e3a5f; border-radius: 10px; padding: 8px 14px; margin-bottom: 14px; }
.question .stem { margin-bottom: 10px; }
.part { border-top: 1px solid var(--line); padding: 12px 0; }
.pq { margin-bottom: 6px; }
.marks { color: var(--warn); font-weight: 700; float: right; }
.part textarea { width: 100%; display: block; margin-bottom: 8px; resize: vertical; }
.answer { background: #0f2a1a; border-radius: 10px; padding: 10px 14px; margin-top: 8px; }
.answer.hidden { display: none; }
.answer .ms { margin: 8px 0 4px; color: #bbf7d0; font-size: 13.5px; }
.point { display: block; padding: 2px 0; cursor: pointer; }
.point input { accent-color: var(--good); }

@media (max-width: 1100px) { #sidebar { width: 240px; } #main { padding: 20px; } .calc-grid { grid-template-columns: 1fr; } }

/* ---------- tools: periodic table, bond lab, ions, journey ---------- */
.sect { font-size: 20px; margin: 26px 0 12px; }
.cards.tools .card { background: linear-gradient(160deg, #1e1b4b, var(--panel)); }
.ptable2 { display: grid; grid-template-columns: repeat(18, minmax(40px, 1fr)); grid-auto-rows: auto; gap: 3px; min-width: 820px; }
.ptable2 .gh { text-align: center; color: var(--dim); font-size: 11px; font-weight: 700; }
.ptable2 .ph { display: grid; place-items: center; font-size: 10px; color: var(--dim); border: 1px dashed var(--line); border-radius: 5px; }
.ptable2 .gap { height: 8px; }
.pt2 { background: color-mix(in srgb, var(--c) 30%, #0b1220); border: 1px solid color-mix(in srgb, var(--c) 65%, transparent); color: #fff; border-radius: 5px; padding: 3px 0 2px; cursor: pointer; display: flex; flex-direction: column; align-items: center; line-height: 1.1; font: inherit; transition: transform .1s; }
.pt2:hover { transform: scale(1.15); z-index: 2; position: relative; }
.pt2 small { font-size: 9px; opacity: .8; } .pt2 b { font-size: 15px; } .pt2 i { font-size: 8.5px; font-style: normal; opacity: .7; }
.ptable2.compact .pt2 b { font-size: 13px; }
.pt2.sel { outline: 3px solid var(--warn); transform: scale(1.12); z-index: 3; position: relative; }
.pt2.selb { outline: 3px solid var(--accent); transform: scale(1.12); z-index: 3; position: relative; }
.pt2.sel.selb { outline: 3px dashed var(--good); }
.el-detail { margin-top: 14px; }
.el-card { display: flex; gap: 18px; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; align-items: flex-start; }
.el-card canvas { width: 300px; flex: none; background: #0b1220; border-radius: 10px; }
.el-big { width: 110px; height: 120px; border-radius: 12px; background: color-mix(in srgb, var(--c) 35%, #0b1220); border: 2px solid var(--c); display: flex; flex-direction: column; align-items: center; justify-content: center; flex: none; }
.el-big small { font-size: 13px; } .el-big b { font-size: 42px; line-height: 1; } .el-big span { font-size: 12px; } .el-big i { font-size: 12px; font-style: normal; color: var(--dim); }
.el-info { flex: 1; min-width: 300px; } .el-info h2 { margin: 0 0 6px; }
.picks { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.pick { min-width: 220px; background: var(--panel); border: 2px dashed var(--line); border-radius: 12px; padding: 10px 14px; color: var(--dim); }
.pick.on { border-style: solid; border-color: var(--warn); color: var(--text); }
.pick.on:nth-of-type(2) { border-color: var(--accent); }
.pick b { font-size: 22px; margin-right: 6px; } .pick small { display: block; color: var(--dim); }
.plusbig { font-size: 28px; color: var(--dim); }
.toc button.on, .ionchip.on { border-color: var(--warn); color: #fff; }
.bond-out { margin-top: 16px; max-width: 1000px; }
.bond-head h2 { margin: 6px 0; }
.badge { display: inline-block; font-weight: 800; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; border-radius: 6px; padding: 2px 10px; }
.b-ionic { background: #9a3412; } .b-covalent { background: #155e75; } .b-metallic, .b-alloy { background: #713f12; } .b-none, .b-other { background: #374151; }
.bigformula { font-size: 34px; font-weight: 800; margin: 6px 0 10px; color: #fff; }
.bigformula span { font-size: 16px; font-weight: 600; color: var(--dim); margin-left: 10px; }
.bond-steps { padding-left: 22px; } .bond-steps li { margin: 8px 0; }
.st { font-size: .75em; color: var(--dim); }
.ion-chips .nav-h { margin: 10px 0 4px; }
.ionchip.pos { color: #fdba74; } .ionchip.neg { color: #67e8f9; }
.ion-panel { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; margin-top: 10px; }
.ion-panel canvas { width: 380px; flex: none; background: #0b1220; border-radius: 10px; }
.ion-panel .anim-info { flex: 1; min-width: 300px; margin: 0; }
.ion-panel p { margin: 6px 0; }
.ion-title { font-size: 16px; margin-bottom: 6px; }
.tiles { display: grid; gap: 10px; margin: 12px 0; }
.tile-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tile { border-radius: 10px; padding: 6px 10px; display: flex; align-items: center; gap: 8px; animation: pop .35s ease-out; }
.tile.pos { background: #7c2d12; border: 1px solid var(--orange, #fb923c); } .tile.neg { background: #164e63; border: 1px solid #22d3ee; }
.tile span { display: flex; gap: 3px; } .tile i { font-style: normal; width: 18px; height: 18px; border-radius: 4px; display: grid; place-items: center; font-weight: 800; background: rgba(255,255,255,.15); }
.tile-sum { color: var(--dim); margin-left: 8px; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.dots { display: inline-flex; gap: 6px; } .dots i { width: 9px; height: 9px; border-radius: 50%; background: #334155; } .dots i.on { background: var(--accent); }
.btn:disabled { opacity: .4; cursor: default; }
.example { background: #101c33; border: 1px solid #1e3a5f; border-radius: 10px; padding: 10px 14px; margin: 10px 0; }
.example > b:first-child { color: var(--accent); }
.example .work { color: #cbd5e1; margin-top: 4px; }

/* ---------- tablets & phones ---------- */
body { font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, system-ui, sans-serif; height: 100dvh; -webkit-tap-highlight-color: transparent; }
#topbar, #scrim { display: none; }
.anim-canvas { touch-action: manipulation; }
.el-card canvas, .ion-panel canvas { max-width: 100%; height: auto; }
@media (max-width: 900px) {
  body { flex-direction: column; }
  #topbar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; padding-top: max(8px, env(safe-area-inset-top)); background: var(--side); border-bottom: 1px solid var(--line); flex: none; }
  #topbar img { width: 30px; height: 30px; }
  #topbar span { color: var(--dim); font-size: 13px; }
  #menuBtn { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; font-size: 20px; width: 42px; height: 38px; cursor: pointer; }
  #sidebar { position: fixed; z-index: 50; top: 0; bottom: 0; left: 0; width: min(300px, 85vw); transform: translateX(-105%); transition: transform .25s ease; padding-top: env(safe-area-inset-top); box-shadow: 8px 0 30px #0008; }
  body.menu-open #sidebar { transform: none; }
  #scrim { position: fixed; inset: 0; z-index: 40; background: #0008; }
  body.menu-open #scrim { display: block; }
  #main { padding: 16px 14px 60px; padding-bottom: max(60px, env(safe-area-inset-bottom)); }
  #nav a { padding: 11px 12px; }
  .hero { padding: 20px; } .hero h1 { font-size: 24px; }
  .topic-head h1 { font-size: 24px; }
  .tbl { display: block; overflow-x: auto; white-space: normal; }
  .timer { position: static; display: inline-block; margin-top: 8px; }
  .quiz { padding: 16px; }
  .lesson { padding: 14px 14px; }
  .pick { min-width: 0; flex: 1; }
  .bigformula { font-size: 26px; }
  .equation { font-size: 18px; }
  .ctl input[type=range] { width: 110px; }
}
@media (max-width: 520px) {
  .cards { grid-template-columns: 1fr; }
  .ctl { flex-wrap: wrap; max-width: 100%; }
  select { max-width: 100%; }
  .atoms { min-width: 0; }
  .trow { flex-wrap: wrap; }
  .stats div { min-width: 0; flex: 1; padding: 8px 10px; }
  .anim-inner { padding: 6px; }
}
.get-app { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 12px; }
