:root {
  --bg: #070a0f;
  --panel: rgba(13, 18, 27, 0.80);
  --panel-border: rgba(130, 160, 210, 0.14);
  --text: #dbe4f0;
  --muted: #8592a6;
  --faint: #4b5668;
  --accent: #38bdf8;
  --accent-2: #a78bfa;
  --good: #2ecc71;
  --warn: #f5b942;
  --bad: #ff4757;
  --radius: 12px;
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 13px/1.4 Inter, "Segoe UI", system-ui, -apple-system, sans-serif; }
#viewport { position: fixed; inset: 0; }
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
button, select, input { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.topbar { position: fixed; top: 14px; left: 16px; right: 16px; display: flex; align-items: center;
  justify-content: space-between; pointer-events: none; z-index: 5; }
.brand { display: flex; align-items: center; gap: 12px; pointer-events: auto; }
.logo { width: 34px; height: 34px; position: relative; }
.logo span { position: absolute; border: 1.5px solid var(--accent); border-radius: 4px; inset: 0; }
.logo span:nth-child(2) { inset: 7px; border-color: var(--accent-2); }
.logo span:nth-child(3) { inset: 13px; background: #fff; border: none; border-radius: 2px; }
.title { font-weight: 700; letter-spacing: 0.24em; font-size: 15px; }
.subtitle { color: var(--muted); font-size: 12px; }
.chips { display: flex; gap: 8px; pointer-events: auto; }
.chip { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 999px; padding: 6px 12px;
  backdrop-filter: blur(10px); color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.chip b { color: var(--text); font-family: var(--mono); font-size: 14px; }
.chip.accent { color: var(--accent); border-color: rgba(56, 189, 248, 0.35); font-weight: 600; letter-spacing: 0.06em; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.chip.ok .dot { background: var(--good); box-shadow: 0 0 8px var(--good); }
.chip.err .dot { background: var(--bad); }

/* ---------- panels ---------- */
.panel { position: fixed; top: 66px; bottom: 84px; background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: var(--radius); backdrop-filter: blur(12px); overflow-y: auto; padding: 4px 14px 14px; z-index: 4;
  scrollbar-width: thin; scrollbar-color: #2a3446 transparent; }
.panel.left { left: 16px; width: 248px; }
.panel.right { right: 16px; width: 330px; }
.panel section { padding: 12px 0; border-bottom: 1px solid rgba(130, 160, 210, 0.08); }
.panel section:last-child { border-bottom: none; }
h3 { margin: 0 0 9px; font-size: 11px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted); display: flex; justify-content: space-between; align-items: baseline; }
h3 .val { color: var(--text); font-family: var(--mono); letter-spacing: 0; text-transform: none; font-weight: 500; }
.hint { color: var(--faint); font-size: 11.5px; margin-top: 7px; }
.sub { color: var(--muted); font-size: 11.5px; margin: 12px 0 6px; }

.seg { display: flex; background: rgba(255, 255, 255, 0.04); border-radius: 8px; padding: 3px; gap: 2px; }
.seg.wrap { flex-wrap: wrap; }
.seg.wrap button { flex: 1 1 45%; }
.seg button { flex: 1; border: none; background: transparent; padding: 6px 4px; border-radius: 6px; cursor: pointer;
  color: var(--muted); transition: background 0.15s, color 0.15s; }
.seg button:hover { color: var(--text); }
.seg button.on { background: rgba(56, 189, 248, 0.16); color: var(--accent); }
.seg button:disabled { opacity: 0.35; cursor: not-allowed; }

.tog { display: flex; align-items: center; gap: 9px; padding: 4px 0; cursor: pointer; color: var(--text); }
.tog input { display: none; }
.tog span { width: 28px; height: 16px; border-radius: 8px; background: #263043; position: relative; transition: background 0.15s; flex: none; }
.tog span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%;
  background: #8592a6; transition: transform 0.15s, background 0.15s; }
.tog input:checked + span { background: rgba(56, 189, 248, 0.35); }
.tog input:checked + span::after { transform: translateX(12px); background: var(--accent); }

input[type=range] { width: 100%; accent-color: var(--accent); }

.legend .item { display: flex; align-items: center; gap: 8px; padding: 2.5px 0; color: var(--text); }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; flex: none; }

/* ---------- metrics ---------- */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpis.two { grid-template-columns: repeat(2, 1fr); }
.kpi { background: rgba(255, 255, 255, 0.035); border-radius: 8px; padding: 8px 10px; }
.kpi .k { font-family: var(--mono); font-size: 20px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 11px; }
.stack { display: flex; height: 10px; border-radius: 5px; overflow: hidden; margin: 12px 0 6px; background: #1b2230; }
.stack div { height: 100%; transition: width 0.25s; }
.stage-legend { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 11px; color: var(--muted); }
.stage-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; }
.stage-legend b { color: var(--text); font-family: var(--mono); font-weight: 500; }
#spark { width: 100%; height: 55px; margin-top: 10px; display: block; }

.bar { margin: 7px 0; }
.bar .row { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 3px; }
.bar .row .v { font-family: var(--mono); color: var(--text); }
.bar .row .n { color: var(--muted); }
.bar .track { height: 7px; background: #1b2230; border-radius: 4px; overflow: hidden; }
.bar .fill { height: 100%; border-radius: 4px; transition: width 0.3s; }
.mem-note { margin-top: 10px; font-size: 12px; color: var(--muted); }
.mem-note b { color: var(--good); font-family: var(--mono); }

table.rings { width: 100%; border-collapse: collapse; font-size: 12px; }
table.rings td, table.rings th { padding: 4px 2px; text-align: right; font-variant-numeric: tabular-nums; }
table.rings th { color: var(--muted); font-weight: 500; font-size: 11px; }
table.rings td:first-child, table.rings th:first-child { text-align: left; }
table.rings td { font-family: var(--mono); }
table.rings .sw { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; }

.obj { display: grid; grid-template-columns: 14px 1fr auto auto; gap: 8px; align-items: center; padding: 4px 0;
  border-bottom: 1px dashed rgba(130, 160, 210, 0.07); font-size: 12px; }
.obj .sw { width: 10px; height: 10px; border-radius: 3px; }
.obj .d, .obj .s { font-family: var(--mono); color: var(--muted); text-align: right; }
.badge { font-size: 10px; padding: 1px 6px; border-radius: 6px; margin-left: 6px; font-weight: 600; letter-spacing: 0.04em; }
.badge.mv { background: rgba(255, 71, 87, 0.18); color: #ff7a87; }
.badge.st { background: rgba(133, 146, 166, 0.15); color: var(--muted); }
.empty { color: var(--faint); font-size: 12px; }

/* ---------- timeline ---------- */
.timeline { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); width: min(760px, calc(100% - 640px));
  min-width: 420px; display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 999px; padding: 8px 16px; backdrop-filter: blur(12px); z-index: 5; }
.timeline button { background: none; border: none; cursor: pointer; font-size: 15px; color: var(--muted); padding: 2px 4px; }
.timeline button:hover { color: var(--text); }
.timeline .play { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: #04121c; font-size: 14px; }
.timeline .play:hover { color: #04121c; filter: brightness(1.1); }
.timeline .frame { font-family: var(--mono); color: var(--muted); min-width: 92px; text-align: right; font-size: 12px; white-space: nowrap; }
.timeline select { background: #141b27; border: 1px solid var(--panel-border); border-radius: 8px; padding: 4px 6px; }

/* ---------- 3D labels ---------- */
.tag { position: absolute; transform: translate(-50%, -100%); white-space: nowrap; font-size: 11px; padding: 2px 7px;
  border-radius: 6px; background: rgba(8, 12, 18, 0.78); border: 1px solid rgba(255, 255, 255, 0.12); color: var(--text);
  font-family: var(--mono); }
.tag.ring { background: rgba(8, 12, 18, 0.55); color: #c4b5fd; border-color: rgba(167, 139, 250, 0.35); transform: translate(-50%, -50%); }
.tag.mv { border-color: rgba(255, 71, 87, 0.7); }

@media (max-width: 1100px) {
  .panel.left { width: 210px; }
  .panel.right { width: 280px; }
  .timeline { width: calc(100% - 32px); min-width: 0; bottom: 12px; }
  .panel { bottom: 76px; }
}

/* ---------- cell inspector ---------- */
#inspector { position: fixed; display: none; z-index: 6; width: 232px; pointer-events: none; padding: 9px 11px;
  background: rgba(10, 14, 21, 0.92); border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 10px;
  backdrop-filter: blur(8px); font-size: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); }
#inspector .ih { font-weight: 600; margin-bottom: 6px; }
#inspector .ih span { color: var(--muted); font-weight: 400; font-size: 11px; margin-left: 4px; }
#inspector .ir { display: flex; justify-content: space-between; padding: 1.5px 0; color: var(--muted); }
#inspector .ir b { color: var(--text); font-weight: 500; font-family: var(--mono); font-size: 11.5px; display: flex; align-items: center; gap: 5px; }
#inspector .ir i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

/* ---------- mini-map ---------- */
#minimap { position: fixed; top: 66px; right: 362px; width: 230px; height: 230px; border-radius: 10px; z-index: 3;
  border: 1px solid var(--panel-border); pointer-events: none; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35); }
#minimap span { position: absolute; left: 8px; bottom: 6px; font-size: 10.5px; color: var(--muted); font-family: var(--mono); }

/* ---------- about overlay ---------- */
.chip.btn { cursor: pointer; color: var(--text); }
.chip.btn:hover { border-color: rgba(56, 189, 248, 0.5); }
#about { position: fixed; inset: 0; z-index: 20; display: none; align-items: center; justify-content: center;
  background: rgba(3, 6, 10, 0.6); backdrop-filter: blur(4px); }
#about.open { display: flex; }
#about .card { position: relative; width: min(720px, calc(100% - 32px)); max-height: calc(100% - 64px); overflow-y: auto;
  background: #0d131c; border: 1px solid var(--panel-border); border-radius: 16px; padding: 26px 30px; }
#about h2 { margin: 0 0 6px; font-size: 20px; letter-spacing: 0.02em; }
#about .lead { color: var(--muted); margin: 0 0 16px; }
#about .close { position: absolute; top: 12px; right: 14px; background: none; border: none; color: var(--muted);
  font-size: 22px; cursor: pointer; }
#about .steps { list-style: none; padding: 0; margin: 0; counter-reset: s; }
#about .steps li { display: grid; grid-template-columns: 28px 120px 1fr; gap: 10px; padding: 9px 0;
  border-top: 1px solid rgba(130, 160, 210, 0.08); counter-increment: s; }
#about .steps li::before { content: counter(s); width: 22px; height: 22px; border-radius: 50%; background: rgba(56, 189, 248, 0.15);
  color: var(--accent); display: grid; place-items: center; font-size: 12px; font-weight: 600; }
#about .steps b { color: var(--text); }
#about .steps span { color: var(--muted); }
#about .facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 16px 0 12px; }
#about .facts div { background: rgba(255, 255, 255, 0.035); border-radius: 10px; padding: 10px 12px; }
#about .facts b { display: block; font-size: 22px; font-family: var(--mono); color: var(--good); }
#about .facts span { color: var(--muted); font-size: 12px; }
#about .keys { color: var(--muted); font-size: 12px; margin: 0; }
kbd { font-family: var(--mono); font-size: 11px; padding: 1px 5px; border-radius: 4px; border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.05); color: var(--text); }

@media (max-width: 1100px) { #minimap { right: 312px; width: 170px; height: 170px; } }

a.dl { display: inline-block; margin-top: 10px; font-size: 12px; color: var(--accent); text-decoration: none;
  border: 1px solid rgba(56, 189, 248, 0.35); border-radius: 8px; padding: 5px 10px; }
a.dl:hover { background: rgba(56, 189, 248, 0.1); }

/* static replay (?replay=…): no server behind the page */
body.replay .dl { display: none; }

/* replay loading screen: the four resolution rings fill in from the 5 cm centre outward */
#replay-loader { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center;
  background: radial-gradient(ellipse at 50% 45%, rgba(20, 30, 46, 0.92), rgba(7, 10, 15, 0.97) 70%);
  transition: opacity 0.6s ease, visibility 0.6s; }
#replay-loader.done { opacity: 0; visibility: hidden; pointer-events: none; }
.rl-card { width: min(420px, calc(100vw - 40px)); display: grid; gap: 12px; justify-items: center; text-align: center; }
.rl-card h2 { margin: 6px 0 0; font-size: 18px; font-weight: 600; letter-spacing: 0.01em; }
.rl-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.rl-rings { position: relative; width: 120px; height: 120px; }
.rl-rings i { position: absolute; border: 1.5px solid var(--faint); border-radius: 6px; opacity: 0.35;
  transition: border-color 0.4s, opacity 0.4s, box-shadow 0.4s; animation: rl-breathe 2.4s ease-in-out infinite; }
.rl-rings i:nth-child(1) { inset: 0; animation-delay: 0.45s; }
.rl-rings i:nth-child(2) { inset: 18px; animation-delay: 0.3s; }
.rl-rings i:nth-child(3) { inset: 34px; animation-delay: 0.15s; }
.rl-rings i:nth-child(4) { inset: 48px; }
.rl-rings i.on { opacity: 1; }
.rl-rings i.on:nth-child(4) { border-color: rgb(167, 139, 250); box-shadow: 0 0 14px rgba(167, 139, 250, 0.45); }
.rl-rings i.on:nth-child(3) { border-color: rgb(56, 189, 248); box-shadow: 0 0 14px rgba(56, 189, 248, 0.35); }
.rl-rings i.on:nth-child(2) { border-color: rgb(45, 212, 191); box-shadow: 0 0 14px rgba(45, 212, 191, 0.3); }
.rl-rings i.on:nth-child(1) { border-color: rgb(250, 204, 21); box-shadow: 0 0 14px rgba(250, 204, 21, 0.25); }
@keyframes rl-breathe { 50% { transform: scale(0.94); } }
@media (prefers-reduced-motion: reduce) { .rl-rings i { animation: none; } }
.rl-bar { width: 100%; height: 6px; margin-top: 8px; border-radius: 3px; background: rgba(130, 160, 210, 0.12); overflow: hidden; }
.rl-bar div { width: 0; height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--accent-2), var(--accent)); transition: width 0.2s linear; }
.rl-meta { width: 100%; display: flex; justify-content: space-between; font: 12px var(--mono); color: var(--muted); }
.rl-pct { color: var(--text); }

/* ---------- phones: the panels become sheets behind two buttons ---------- */
.mobile-toggles { display: none; }
@media (max-width: 760px) {
  .topbar { top: 10px; left: 10px; right: 10px; }
  .brand .subtitle, #chip-seq, #chip-source, #chip-lat, #btn-about { display: none; }
  .chips { gap: 6px; }
  .panel { display: none; left: 8px !important; right: 8px !important; width: auto !important; top: auto; bottom: 118px; max-height: 56vh; overflow-y: auto; z-index: 7; }
  body.sheet-left .panel.left, body.sheet-right .panel.right { display: block; }
  .mobile-toggles { display: flex; gap: 8px; position: fixed; left: 50%; transform: translateX(-50%); bottom: 72px; z-index: 8; }
  .mobile-toggles button { font: 600 12px/1 Inter, system-ui, sans-serif; color: var(--text); background: var(--panel); border: 1px solid var(--panel-border);
    border-radius: 999px; padding: 9px 14px; backdrop-filter: blur(10px); }
  body.sheet-left [data-sheet=left], body.sheet-right [data-sheet=right] { background: var(--accent); color: #04121c; border-color: var(--accent); }
  #minimap { display: none !important; }
  .timeline { width: calc(100% - 16px); bottom: 10px; gap: 6px; padding: 8px 10px; }
  .timeline .frame { min-width: 0; }
  #inspector { display: none !important; }
}
