:root {
  --bg: #0f1722;
  --panel: #172233;
  --panel2: #1d2b40;
  --line: #2a3a54;
  --text: #e6edf6;
  --dim: #8fa3bd;
  --accent: #ffb703;
  --ten: #3aa0ff;
  --com: #ff5d5d;
  --ok: #4ade80;
  --bad: #ff6b6b;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { height: 100dvh; overscroll-behavior: none; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  display: flex; flex-direction: column;
}
.top {
  display: flex; align-items: center; gap: 16px; padding: 8px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.top h1 { margin: 0; font-size: 18px; letter-spacing: .04em; }
.tabs { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
.tabs button {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 4px 10px; cursor: pointer;
}
.tabs button.on { border-color: var(--accent); color: var(--accent); }
.tabs button .star { color: var(--ok); margin-left: 4px; }
.help { color: var(--dim); text-decoration: none; }
.home { color: var(--dim); text-decoration: none; font-size: 13px; white-space: nowrap; }
.home:hover { color: var(--accent); }
.layout { flex: 1; display: flex; min-height: 0; }
.stagewrap { flex: 1; position: relative; min-width: 0; }
#cv { width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.hint {
  position: absolute; left: 12px; bottom: 8px; color: #ffffffb0; font-size: 12px;
  pointer-events: none; text-shadow: 0 1px 2px #000;
}
.toast {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  background: #000c; border: 1px solid var(--line); padding: 6px 14px; border-radius: 20px;
  pointer-events: none;
}
.panel {
  width: 320px; overflow-y: auto; background: var(--bg);
  border-left: 1px solid var(--line); padding: 10px; display: flex; flex-direction: column; gap: 10px;
}
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.card h2 { margin: 0 0 8px; font-size: 13px; color: var(--dim); font-weight: 600; letter-spacing: .06em; }
.row { display: flex; justify-content: space-between; align-items: baseline; }
.row.big b { font-size: 28px; color: var(--accent); }
.lbl { color: var(--dim); }
.small { font-size: 12px; }
.dim { color: var(--dim); }
p { margin: 4px 0; }
.meter { margin: 8px 0; }
.meterhead { display: flex; justify-content: space-between; font-size: 12px; }
.bar { position: relative; height: 8px; background: var(--panel2); border-radius: 4px; margin-top: 3px; overflow: visible; }
.bar > div { height: 100%; border-radius: 4px; background: var(--ten); width: 0; transition: width .15s; }
.bar > i { position: absolute; top: -3px; width: 2px; height: 14px; background: var(--accent); }
.status { margin-top: 6px; padding: 6px 8px; background: var(--panel2); border-radius: 6px; font-size: 12px; min-height: 2.4em; }
.status.ok { border-left: 3px solid var(--ok); }
.status.bad { border-left: 3px solid var(--bad); }
.seg { display: flex; gap: 4px; margin-bottom: 6px; }
.seg button, .btns button, .primary {
  flex: 1; background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 4px; cursor: pointer; font: inherit;
}
.seg button.on { border-color: var(--accent); color: var(--accent); background: #2b2a1a; }
.seg button.size { display: flex; align-items: center; justify-content: center; min-height: 30px; }
.seg button.size i { display: block; background: #c9d3e0; border-radius: 50%; }
.btns { display: flex; gap: 4px; margin-bottom: 8px; }
.primary { width: 100%; background: var(--accent); color: #231a00; border: 0; font-weight: 700; padding: 10px; font-size: 15px; }
.primary:disabled { opacity: .5; cursor: default; }
.tcol { color: var(--ten); } .ccol { color: var(--com); }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; max-width: 560px; }
dialog::backdrop { background: #000a; }
dialog li { margin: 6px 0; }
dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 0; }
dl.kv dt { color: var(--dim); } dl.kv dd { margin: 0; text-align: right; }
.explain { margin-top: 8px; padding: 8px; background: var(--panel2); border-radius: 6px; }
.pass { color: var(--ok); } .fail { color: var(--bad); }
@media (max-width: 800px) {
  .layout { flex-direction: column; }
  .panel { width: 100%; border-left: 0; border-top: 1px solid var(--line); max-height: 45vh; }
}

.share { width: 100%; margin-top: 8px; padding: 8px; border: 0; border-radius: 6px; background: #000; color: #fff;
  font: inherit; font-weight: 700; cursor: pointer; border: 1px solid #444; }
.share:hover { background: #1a1a1a; }

.top-share { width: auto; margin: 0; padding: 4px 12px; flex: none; animation: pop .4s ease-out; }
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---- Heat Lab additions ---- */
.stagewrap canvas { position: absolute; inset: 0; }
#fx { pointer-events: none; }
.legend { height: 10px; border-radius: 5px; margin: 6px 0 2px;
  background: linear-gradient(90deg, #000004, #1b0c41, #4a0c6b, #781c6d, #a52c60, #cf4446, #ed6925, #fb9b06, #f7d13d, #fcffa4); }
.legend-lbl { display: flex; justify-content: space-between; font-size: 11px; color: var(--dim); }
.mat .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.chk { display: flex; gap: 14px; font-size: 13px; margin: 4px 0 8px; }
.chk label { cursor: pointer; }
.cellinfo { min-height: 1.4em; }
.hint-li { margin: 4px 0; }

#fx { width: 100%; height: 100%; }

/* ---- phones: let the page scroll, give the canvas a real height ---- */
@media (max-width: 800px) {
  html, body { height: auto; }
  body { height: auto; min-height: 100dvh; }
  .top { flex-wrap: wrap; gap: 6px 12px; padding: 6px 10px; }
  .top .tabs { order: 5; flex: 1 0 100%; }
  .top .help { margin-left: auto; }
  .hint { display: none; }
  .layout { flex: none; flex-direction: column; }
  .stagewrap { flex: none; height: 64dvh; min-height: 360px; }
  .panel { width: 100%; max-height: none; overflow: visible; border-left: 0; border-top: 1px solid var(--line); }
  #gplot { height: 110px; }
}

/* ---- Magnet Lab additions ---- */
.mat button .sw { margin-right: 4px; }
.seg.wrap { flex-wrap: wrap; }
.seg.wrap button { flex: 1 1 30%; }
.legend.b { background: linear-gradient(90deg, #000004, #1b0c41, #4a0c6b, #781c6d, #a52c60, #cf4446, #ed6925, #fb9b06, #f7d13d, #fcffa4); }
