:root {
  --bg: #07090a;
  --ink: #e9eef0;
  --dim: #78868c;
  --line: #1a2227;
  --line-2: #243036;
  --amber: #ffb547;
  --cyan: #4fd2ff;
  --hot: #ff6b4a;
  --violet: #b58cff;
  --panel: #0b1013;
  --panel-2: #0f1519;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.45 var(--sans);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
.mono { font-family: var(--mono); font-size: 11px; letter-spacing: .02em; }
.dim { color: var(--dim); }
button {
  font: inherit;
  color: inherit;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  transition: border-color .12s, background .12s, color .12s;
}
button:hover { border-color: #35464e; }
button:active { transform: translateY(.5px); }
button.primary { background: var(--amber); color: #1a1204; border-color: var(--amber); font-weight: 600; }
button.primary:hover { background: #ffc266; }
button.ghost { background: transparent; }
button:disabled { opacity: .45; cursor: default; }
.x { position: absolute; top: 8px; right: 8px; border: 0; background: transparent; color: var(--dim); font-size: 18px; line-height: 1; padding: 2px 6px; }

/* ---------- header ---------- */
header {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 46px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  background: linear-gradient(180deg, #0a0e10, #07090a);
  z-index: 5;
}
.mark { font-weight: 650; letter-spacing: -.01em; }
.mark span { color: var(--amber); font-weight: 400; }
.sep { width: 1px; height: 20px; background: var(--line-2); }
.grow { flex: 1; }
.ctl { display: flex; align-items: center; gap: 8px; }
.ctl label { color: var(--dim); font-size: 11px; font-family: var(--mono); }
.ctl output { font-family: var(--mono); font-size: 11px; color: var(--amber); min-width: 16px; }
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  height: 2px; background: var(--line-2); border-radius: 2px; outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 11px; height: 11px; border-radius: 50%;
  background: var(--ink); cursor: pointer; border: 2px solid var(--bg);
}
input[type="range"]::-moz-range-thumb { width: 11px; height: 11px; border-radius: 50%; background: var(--ink); border: 2px solid var(--bg); }
#layer { width: 150px; }
.seg { border: 1px solid var(--line-2); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; padding: 4px 9px; font-family: var(--mono); font-size: 11px; color: var(--dim); }
.seg button.on { background: #1b2429; color: var(--ink); }
.pill { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: .06em;
  padding: 3px 7px; border-radius: 999px; border: 1px solid var(--line-2); color: var(--dim); }
.pill.on { color: #0d1a10; background: #7fe0a4; border-color: #7fe0a4; }
#status.on { color: #9fe8bb; }
.pill.warn { color: #2a1b06; background: var(--amber); border-color: var(--amber); }

/* ---------- stage ---------- */
main { position: relative; flex: 1 1 auto; display: flex; min-height: 0; overflow: hidden; }
#stage { position: relative; flex: 1 1 auto; min-width: 0; overflow: hidden; }
#map { display: block; width: 100%; height: 100%; }
#labels { position: absolute; inset: 0; pointer-events: none; }
.layer-label {
  position: absolute; transform: translate(-50%, -50%);
  font-family: var(--mono); font-size: 10px; color: var(--dim);
  padding: 1px 5px; border-radius: 3px; cursor: pointer; pointer-events: auto;
  border: 1px solid transparent; white-space: nowrap;
}
.layer-label:hover { color: var(--ink); border-color: var(--line-2); }
.layer-label.on { color: #1a1204; background: var(--amber); }
.layer-label b { font-weight: 600; }
#hint { position: absolute; left: 14px; bottom: 12px; color: #46545a; pointer-events: none; }
#legend { position: absolute; left: 14px; top: 12px; display: flex; flex-direction: column; gap: 3px; pointer-events: none; color: #5b6a70; }
#legend .lg { display: none; align-items: center; gap: 5px; }
#legend .lg.writes, #legend .lg.fires, #legend .lg.mass { display: flex; }
#legend .lg i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
#legend .writes i { background: linear-gradient(90deg, #0f1b21, #3f90a8); }
#legend .fires i { background: #ffb547; }
#legend .fires i.neg { background: #b58cff; }
#legend .mass i { background: linear-gradient(90deg, #0f1b21, #ff8a3d); }
#legend b { font-weight: 400; color: #7e8d93; }
#legend[data-mode="writes"] .fires, #legend[data-mode="writes"] .mass { display: none; }
#legend[data-mode="fires"] .writes, #legend[data-mode="fires"] .mass { display: none; }
#legend[data-mode="mass"] .writes, #legend[data-mode="mass"] .fires { display: none; }
#face { position: absolute; right: 12px; bottom: 12px; font-family: var(--mono); font-size: 11px; }
#tooltip {
  position: absolute; pointer-events: none; z-index: 4; display: none;
  background: #0c1215ee; border: 1px solid var(--line-2); border-radius: 5px;
  padding: 3px 7px; font-family: var(--mono); font-size: 11px; white-space: nowrap;
  color: var(--ink);
}

/* ---------- gate ---------- */
#gate {
  position: absolute; inset: 0; z-index: 8;
  display: grid; place-items: center;
  background: radial-gradient(120% 90% at 50% 0%, #0d1418 0%, #07090a 60%);
}
#gate.hidden { display: none; }
.gate-card { width: min(520px, calc(100vw - 40px)); }
.gate-card h1 { font-size: 26px; letter-spacing: -.02em; margin: 0 0 6px; font-weight: 600; }
.lede { color: #a6b3b8; margin: 0 0 18px; max-width: 46ch; }
.facts { margin: 0 0 18px; border-top: 1px solid var(--line); }
.facts div { display: flex; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.facts dt { width: 84px; color: var(--dim); font-family: var(--mono); font-size: 11px; padding-top: 1px; }
.facts dd { margin: 0; flex: 1; color: #c6d1d5; }
#progress { height: 3px; background: var(--line); border-radius: 2px; margin: 14px 0 8px; overflow: hidden; display: none; }
#progress.on { display: block; }
#bar { height: 100%; width: 0%; background: var(--amber); transition: width .2s; }
#gate button { width: 100%; padding: 10px; font-size: 14px; }
.tiny { font-size: 10px; line-height: 1.5; margin: 10px 0 0; }
.tiny code { color: #9fb4bb; }

/* ---------- panel ---------- */
#panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: 336px; z-index: 6;
  background: var(--panel); border-left: 1px solid var(--line);
  padding: 14px; overflow-y: auto;
  transition: transform .18s ease;
}
#panel.closed { transform: translateX(100%); }
.panel-head { margin-bottom: 14px; }
.unit { font-family: var(--mono); font-size: 15px; letter-spacing: .04em; }
.block { border-top: 1px solid var(--line); padding: 10px 0 12px; }
.block-title { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: .1em;
  color: var(--dim); margin-bottom: 8px; display: flex; gap: 6px; }
.dose { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.dose input { flex: 1; }
.dose output { color: var(--amber); min-width: 34px; text-align: right; }
.row { display: flex; gap: 6px; flex-wrap: wrap; }
.row button { flex: 1; padding: 4px 6px; font-family: var(--mono); font-size: 11px; }
.lens { min-height: 32px; }
.lens .grp { margin-bottom: 7px; }
.lens .grp h4 { margin: 0 0 3px; font-family: var(--mono); font-size: 10px; font-weight: 400; letter-spacing: .06em; text-transform: uppercase; }
.lens .up h4 { color: var(--amber); }
.lens .down h4 { color: var(--violet); }
.lens .tok { display: inline-flex; gap: 4px; align-items: baseline; margin: 0 8px 3px 0; color: var(--ink); }
.lens .tok small { color: var(--dim); }
#spark { width: 100%; height: 64px; display: block; background: #080c0e; border: 1px solid var(--line); border-radius: 5px; }
#act-meta { margin-top: 5px; }
.chips.tight { margin-top: 7px; gap: 4px; }
.chips.tight .chip { padding: 1px 6px; font-size: 10px; cursor: pointer; }
.chips.tight .chip:hover { border-color: #3d5158; color: #fff; }
.compare { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.compare .col { border: 1px solid var(--line); border-radius: 5px; padding: 6px 8px; background: #080d0f; }
.compare .col h5 { margin: 0 0 3px; font-family: var(--mono); font-size: 10px; font-weight: 400; color: var(--dim); }
.compare .col p { margin: 0; white-space: pre-wrap; color: #d5dee1; }
.compare .first { font-size: 10px; margin-bottom: 3px; letter-spacing: .01em; }
.compare .col.pos { border-color: #4a3a1a; }
.compare .col.neg { border-color: #33264a; }

/* ---------- footer ---------- */
footer {
  flex: 0 0 auto; display: flex; gap: 14px; align-items: flex-start;
  border-top: 1px solid var(--line); padding: 9px 14px 11px; background: #080b0d;
}
.prompt { width: 46%; max-width: 620px; }
textarea {
  width: 100%; resize: none; background: #0c1114; color: var(--ink);
  border: 1px solid var(--line-2); border-radius: 6px; padding: 7px 9px;
  font: inherit; outline: none; min-height: 34px; max-height: 90px;
}
textarea:focus { border-color: #2f4048; }
.prompt .row { margin-top: 6px; }
.prompt .row button { flex: 0 0 auto; }
.readout { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.chips { display: flex; gap: 5px; flex-wrap: wrap; min-height: 20px; }
.chip { font-family: var(--mono); font-size: 11px; padding: 2px 7px; border-radius: 4px;
  border: 1px solid var(--line-2); color: #cfd9dc; background: #0b1013; }
.chip b { color: var(--amber); font-weight: 500; }

@media (max-width: 820px) {
  #legend { top: 8px; left: 10px; }
  header { gap: 8px; height: auto; padding: 6px 10px; flex-wrap: wrap; }
  #layer { width: 96px; }
  .prompt { width: 100%; max-width: none; }
  footer { flex-direction: column; gap: 8px; }
  #panel { width: 100%; top: auto; height: 58vh; border-left: 0;
    border-top: 1px solid var(--line); border-radius: 12px 12px 0 0;
    box-shadow: 0 -18px 40px #000a; }
  #hint { display: none; }
}
