:root {
  --bg: #04050b;
  --panel: rgba(12, 14, 28, 0.62);
  --line: rgba(140, 160, 255, 0.16);
  --text: #dfe5ff;
  --muted: #8a93b8;
  --accent: #7fd6ff;
  --p: #ff6b4d;
  --n: #4da6ff;
  --e: #7fe9ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 13px/1.45 ui-sans-serif, -apple-system, "Segoe UI", Inter, sans-serif; overflow: hidden; }
canvas#gl { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; cursor: grab; }
canvas#gl:active { cursor: grabbing; }

#labels { position: fixed; inset: 0; pointer-events: none; }
.lbl { position: absolute; transform: translate(-50%, -50%); font-size: 12px; font-weight: 600;
  color: #fff; text-shadow: 0 0 6px #000, 0 0 12px #000; white-space: nowrap; transition: opacity .2s; }
.lbl small { display: block; font-weight: 400; color: var(--muted); font-size: 10px; text-align: center; }

.panel { position: fixed; background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2); padding: 14px 16px; }

#top { position: fixed; top: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; z-index: 5; pointer-events: none; }
#top > * { pointer-events: auto; }
.brand { font-size: 18px; font-weight: 700; letter-spacing: .3px; }
.brand .logo { color: var(--accent); font-size: 22px; margin-right: 4px; }
.brand .tag { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 10px; }
nav { display: flex; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 4px; backdrop-filter: blur(12px); }
button { font: inherit; color: var(--text); background: rgba(255,255,255,.05); border: 1px solid var(--line);
  border-radius: 8px; padding: 5px 10px; cursor: pointer; }
button:hover:not(:disabled) { background: rgba(127,214,255,.14); }
button:disabled { opacity: .4; cursor: default; }
button.nav { border-radius: 999px; border: none; background: transparent; padding: 6px 14px; }
button.nav.active { background: rgba(127,214,255,.18); color: #fff; }

#leftCol { position: fixed; top: 64px; left: 18px; width: 290px; max-height: calc(100vh - 110px); overflow: auto; display: flex; flex-direction: column; gap: 10px; }
#leftCol .panel { position: static; width: auto; }
body.mol-mode #leftCol { display: none; }
.el-head { display: flex; gap: 14px; align-items: center; margin-bottom: 10px; }
.el-symbol { width: 64px; height: 64px; border-radius: 12px; display: grid; place-items: center; font-size: 30px; font-weight: 700;
  background: radial-gradient(circle at 30% 25%, rgba(127,214,255,.35), rgba(127,214,255,.05)); border: 1px solid var(--line); }
.el-name { font-size: 20px; font-weight: 700; }
.el-sub { color: var(--muted); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.bad { color: #ffb36b; }
.good { color: #8ff0b0; }

#controls { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row select { flex: 1; max-width: 170px; }
select { font: inherit; color: var(--text); background: rgba(255,255,255,.06); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; }
select option { background: #0d1020; }
.slider input { flex: 1; max-width: 150px; accent-color: var(--accent); }
.check { justify-content: flex-start; }
.check input { accent-color: var(--accent); }
.stepper { display: grid; grid-template-columns: 12px 1fr 30px 44px 30px; align-items: center; gap: 6px; }
.stepper output { text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.stepper button { padding: 2px 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 8px currentColor; }
.dot.p { background: var(--p); color: var(--p); }
.dot.n { background: var(--n); color: var(--n); }
.dot.e { background: var(--e); color: var(--e); }
.btnrow { display: flex; gap: 6px; }
.btnrow button { flex: 1; }
hr { border: none; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }

#scale { top: 64px; right: 18px; width: 320px; max-height: calc(100vh - 110px); overflow: auto; }
.ladder { display: flex; flex-direction: column; gap: 4px; position: relative; }
.ladder button { display: flex; justify-content: space-between; align-items: baseline; text-align: left; padding: 7px 10px; }
.ladder button small { color: var(--muted); }
.ladder button.active { background: rgba(127,214,255,.2); border-color: rgba(127,214,255,.5); }
#levelExtra { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 5px; }
#levelExtra:empty { display: none; }
#levelExtra button.on { background: rgba(127,214,255,.25); border-color: rgba(127,214,255,.6); }
#levelExtra .note { color: var(--muted); width: 100%; font-size: 12px; }
#explain { margin-top: 12px; color: #c4cbec; }
#explain h3 { margin: 0 0 6px; font-size: 15px; color: #fff; }
#explain p { margin: 0 0 8px; }
#explain .legend-line { display: flex; align-items: center; gap: 6px; margin: 2px 0; color: var(--muted); }
#explain .sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

#hint { position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%); color: var(--muted); font-size: 12px;
  background: var(--panel); border: 1px solid var(--line); padding: 6px 14px; border-radius: 999px; backdrop-filter: blur(10px); }

#tableView { position: fixed; inset: 0; z-index: 4; background: rgba(4,5,11,.86); backdrop-filter: blur(6px); overflow: auto; padding: 70px 24px 24px; }
.table-wrap { max-width: 1250px; margin: 0 auto; }
.table-head h2 { margin: 0; }
.table-head p { color: var(--muted); margin: 4px 0 10px; }
#legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 14px; }
#legend span { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; cursor: pointer; }
#legend span i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
#legend span.dim { opacity: .35; }
#ptable { display: grid; grid-template-columns: repeat(18, minmax(0, 1fr)); grid-template-rows: repeat(7, auto) 14px repeat(2, auto); gap: 4px; }
.cell { aspect-ratio: 1 / 1.12; border-radius: 7px; padding: 4px 5px; cursor: pointer; position: relative; overflow: hidden;
  border: 1px solid rgba(255,255,255,.08); background: rgba(255,255,255,.03); transition: transform .12s, box-shadow .12s, opacity .2s; }
.cell::before { content: ""; position: absolute; inset: 0; background: var(--c); opacity: .18; }
.cell:hover { transform: scale(1.12); z-index: 2; box-shadow: 0 0 18px var(--c); }
.cell.sel { box-shadow: 0 0 0 2px var(--c), 0 0 22px var(--c); }
.cell.dim { opacity: .2; }
.cell .z { font-size: 9px; color: var(--muted); position: relative; }
.cell .s { font-size: clamp(11px, 1.5vw, 19px); font-weight: 700; color: var(--c); position: relative; line-height: 1.1; }
.cell .nm { font-size: clamp(6px, .62vw, 9px); color: #c8cff0; position: relative; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell .m { font-size: clamp(6px, .6vw, 9px); color: var(--muted); position: relative; }

@media (max-width: 1100px) {
  #scale { width: 260px; }
  #info, #controls { width: 250px; }
}

/* ---- molecules tab ---- */
.mol-only { display: none !important; }
body.mol-mode .mol-only { display: block !important; }
body.mol-mode #info, body.mol-mode #controls, body.mol-mode #scale, body.mol-mode #hint, body.mol-mode #labels { display: none; }
#molLabels { position: fixed; inset: 0; pointer-events: none; }
#molLeft { top: 64px; left: 18px; width: 290px; }
#molLeft > * + * { margin-top: 8px; }
body.mol-mode #molLeft { display: flex !important; flex-direction: column; gap: 8px; }
body.mol-mode #molLeft > * + * { margin-top: 0; }
.mol-h { margin: 0; font-size: 15px; }
.mol-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.mol-grid button, .seg button, #molRight .btnrow button { padding: 6px 4px; }
.mol-grid button.on, .seg button.on, #molLeft .btnrow button.on, #molRight button.on { background: rgba(127,214,255,.25); border-color: rgba(127,214,255,.6); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
#molRight { top: 64px; right: 18px; width: 340px; max-height: calc(100vh - 110px); overflow: auto; }
.mol-title { font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.mol-title span { font-size: 24px; font-weight: 700; color: #fff; margin-right: 6px; }
.mol-sub { color: var(--muted); font-size: 12px; margin: 12px 0 4px; }
#molDiagram, #molCurve { width: 100%; height: auto; display: block; background: rgba(255,255,255,.02); border-radius: 8px; cursor: pointer; }
#molCurve { cursor: default; }
.mol-text { margin-top: 12px; color: #c4cbec; }
.mol-text p { margin: 0 0 8px; }
.mol-text .legend-line { color: var(--muted); font-size: 12px; }
#molHint { position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%); color: var(--muted); font-size: 12px;
  background: var(--panel); border: 1px solid var(--line); padding: 6px 14px; border-radius: 999px; backdrop-filter: blur(10px); white-space: nowrap; }
#busy { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line);
  padding: 6px 14px; border-radius: 999px; color: var(--accent); font-size: 12px; backdrop-filter: blur(10px); z-index: 6; }
canvas.shells { width: 100%; height: auto; margin-top: 6px; background: rgba(255,255,255,.02); border-radius: 8px; }
