:root {
  --ground: #0d0e0f;
  --ink: #fbf6ee;
  --muted: #8b8f89;
  --line: rgba(251, 246, 238, 0.1);
  --glass: rgba(255, 255, 255, 0.045);
  --glass-brd: rgba(251, 246, 238, 0.13);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  --ok: #1fa700;
  --bad: #fb5757;
  --warn: #e29b3f;
  --human: #e0c080;
  --llm: #5eb8e0;
  --ci: #969696;
  --robot: #a39fd3;
  --world: rgba(85, 165, 84, 0.55);
  --speech: #ce6390;
  --witness: #55a554;
  --playhead: #fbf6ee;
  --metal: linear-gradient(#b5b0a6, #f4f3f1);
  --mono: "Geist Mono", ui-monospace, Menlo, Consolas, monospace;
  --sans: Inter, "Helvetica Neue", system-ui, sans-serif;
  --display: Geist, Inter, system-ui, sans-serif;
  --top: 52px;
  --transport: 46px;
  --phase: 26px;
  --dailies: 118px;
  --insp: 320px;
}

html[data-theme="light"] {
  --ground: #f4f3f1;
  --ink: #2d2d2d;
  --muted: #6a6a6a;
  --line: rgba(35, 35, 35, 0.1);
  --glass: rgba(255, 255, 255, 0.72);
  --glass-brd: rgba(35, 35, 35, 0.12);
  --shadow: 0 16px 40px rgba(35, 30, 20, 0.12);
  --playhead: #202033;
  --metal: linear-gradient(#b5b0a6, #f4f3f1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: grid;
  grid-template-rows: var(--top) var(--transport) var(--phase) 1fr var(--dailies);
  grid-template-columns: 1fr var(--insp);
  height: 100vh;
}

/* ---- topbar ---- */
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 176px; }
.mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--metal);
  box-shadow: 0 0 0 0.5px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.5);
}
.brand-title {
  font-family: var(--display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.03em;
  text-transform: uppercase;
}
.brand-sub {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.pages {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  flex: 1;
  justify-content: center;
}
.pages button {
  appearance: none; border: 0; background: transparent;
  color: var(--muted); font-family: var(--mono); font-size: 10.5px;
  letter-spacing: 0.06em; text-transform: uppercase;
  padding: 7px 11px; border-radius: 999px; cursor: pointer;
  transition: color .12s, background .12s;
}
.pages button:hover { color: var(--ink); }
.pages button[aria-current="page"] {
  color: var(--ink);
  background: linear-gradient(#3a3b3d, #1c1d1f);
}
html[data-theme="light"] .pages button[aria-current="page"] {
  background: linear-gradient(#fff, #e6e4df);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.06);
}

.top-actions { display: flex; align-items: center; gap: 8px; }
.live-pill {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--muted);
  padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--glass-brd);
}
.live-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 8px var(--ok); animation: pulse 1.4s ease infinite;
}
.live-pill.paused .live-dot { background: var(--warn); box-shadow: none; animation: none; }
@keyframes pulse { 50% { opacity: 0.45; } }
.conn { color: var(--ok); opacity: 0.85; }

.ghost, .metal {
  appearance: none; border: 0; cursor: pointer;
  font-family: var(--mono); font-size: 11px;
  padding: 7px 12px; border-radius: 999px;
}
.ghost { background: transparent; color: var(--muted); border: 1px solid var(--glass-brd); }
.ghost:hover { color: var(--ink); }
.metal {
  background: var(--metal); color: rgba(0,0,0,.55); font-weight: 500;
  border: 1.5px solid rgba(124,122,106,.4);
  box-shadow: 0 0 0 0.5px rgba(0,0,0,.35);
  min-width: 36px;
}

/* ---- transport ---- */
.transport {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 12px;
  padding: 0 14px; border-bottom: 1px solid var(--line);
}
.time-readout { display: flex; flex-direction: column; gap: 1px; min-width: 88px; }
.time-readout .muted {
  font-size: 9px; color: var(--muted); letter-spacing: 0.1em;
  text-transform: uppercase; font-family: var(--mono);
}
.mono { font-family: var(--mono); font-size: 11px; letter-spacing: 0.02em; }
.mono-sm { font-size: 10.5px; line-height: 1.45; }
.mono-xs { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.04em; color: var(--muted); }
.scrub-wrap { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 120px; }
#scrub { width: 100%; accent-color: var(--llm); cursor: ew-resize; }
.phase-track {
  height: 3px; border-radius: 999px; background: rgba(255,255,255,.06); overflow: hidden;
}
html[data-theme="light"] .phase-track { background: rgba(0,0,0,.06); }
.phase-track > i {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--llm), var(--ok));
  transition: width .4s ease;
}
.score-mini {
  display: flex; gap: 10px; align-items: center;
  font-family: var(--mono); font-size: 10px; color: var(--muted);
  min-width: 220px; flex-wrap: wrap;
}
.score-mini b { color: var(--ink); font-weight: 500; }
.score-mini b.ok { color: var(--ok); }
.score-mini b.warn { color: var(--warn); }
.score-mini b.bad { color: var(--bad); }
.sm-item { display: inline-flex; align-items: center; gap: 4px; }
.spark { display: inline-block; vertical-align: middle; opacity: 0.85; }

.mode-chips { display: flex; gap: 2px; padding: 3px; border-radius: 999px; border: 1px solid var(--glass-brd); }
.mode-chips button {
  appearance: none; border: 0; background: transparent; color: var(--muted);
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 5px 10px; border-radius: 999px; cursor: pointer;
}
.mode-chips button.on { color: var(--ink); background: linear-gradient(#3a3b3d, #1c1d1f); }
html[data-theme="light"] .mode-chips button.on { background: linear-gradient(#fff, #e6e4df); }

.phase-strip {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(0,0,0,.15);
}
html[data-theme="light"] .phase-strip { background: rgba(0,0,0,.03); }
.phase-label { font-size: 12px; flex: 1; }
.phase-strip .hint { margin-left: auto; opacity: 0.7; }

.main {
  grid-column: 1;
  overflow: hidden;
  position: relative;
  min-height: 0;
}

/* ---- inspector ---- */
.inspector {
  grid-column: 2;
  grid-row: 4;
  border-left: 1px solid var(--line);
  background: var(--glass);
  display: flex; flex-direction: column;
  min-height: 0;
}
.insp-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.eyebrow {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.22em;
  text-transform: uppercase; color: var(--muted);
}
.insp-body { padding: 12px 14px; overflow: auto; flex: 1; font-size: 13px; line-height: 1.45; }
.insp-body h4 { font-size: 12px; margin: 12px 0 6px; letter-spacing: -0.02em; }
.insp-body h4:first-child { margin-top: 0; }
.muted-p { color: var(--muted); font-size: 12px; line-height: 1.5; margin-top: 8px; }
.detail { font-size: 12px; color: var(--muted); }
.vlm-note { font-size: 12px; color: var(--speech); line-height: 1.45; }
.session-card { margin-bottom: 8px; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.04em;
  padding: 3px 8px; border-radius: 999px; border: 1px solid var(--glass-brd);
  color: var(--muted);
}
.chip.ok { color: var(--ok); border-color: rgba(31,167,0,.35); }
.chip.bad { color: var(--bad); border-color: rgba(251,87,87,.35); }
.chip.warn { color: var(--warn); border-color: rgba(226,155,63,.35); }
.chip.d { color: var(--llm); }
.kv { display: grid; grid-template-columns: 78px 1fr; gap: 4px 8px; font-size: 12px; }
.kv span:first-child {
  color: var(--muted); font-family: var(--mono); font-size: 10px;
  letter-spacing: 0.06em; text-transform: uppercase;
}

.log-stream { display: flex; flex-direction: column; gap: 4px; max-height: 200px; overflow: auto; }
.log-stream.short { max-height: 140px; }
.log-row {
  display: grid; grid-template-columns: 48px 52px 1fr; gap: 6px;
  font-size: 10.5px; line-height: 1.35;
  padding: 3px 0; border-bottom: 1px solid var(--line);
}
.log-row .t { color: var(--muted); }
.log-row .ch { color: var(--llm); font-family: var(--mono); font-size: 9px; text-transform: uppercase; }
.log-row .tx { color: var(--ink); opacity: 0.9; word-break: break-word; }

.code-snip {
  margin-top: 8px; padding: 10px 12px; border-radius: 10px;
  background: rgba(0,0,0,.35); border: 1px solid var(--glass-brd);
  font-family: var(--mono); font-size: 10.5px; line-height: 1.45;
  color: #c8d0c4; overflow: auto; max-height: 160px; white-space: pre-wrap;
}
html[data-theme="light"] .code-snip {
  background: rgba(0,0,0,.04); color: #3a3a3a;
}
.code-snip.tight { max-height: 120px; margin-top: 10px; }
.code-meta { color: var(--muted); display: block; margin-bottom: 4px; }
.diff { color: var(--ok); margin-top: 4px; }
.speech-bubble {
  padding: 8px 10px; border-radius: 10px;
  background: rgba(206,99,144,.08); border: 1px solid rgba(206,99,144,.2);
  font-size: 12px; line-height: 1.4;
}

/* ---- dailies strip ---- */
.strip {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  display: flex; gap: 10px; align-items: stretch;
  padding: 10px 14px; overflow-x: auto;
  background: linear-gradient(to top, rgba(0,0,0,.28), transparent);
}
html[data-theme="light"] .strip { background: linear-gradient(to top, rgba(0,0,0,.04), transparent); }

.reel-head {
  display: flex; flex-direction: column; justify-content: center;
  min-width: 90px; font-family: var(--mono); font-size: 10px;
  letter-spacing: .14em; text-transform: uppercase; color: var(--muted);
}
.reel-head-main { color: var(--ink); margin-top: 4px; letter-spacing: .12em; }
.reel-empty { color: var(--muted); font-size: 12px; align-self: center; }

.reel-card {
  min-width: 136px; max-width: 152px;
  border: 1px solid var(--glass-brd); border-radius: 12px;
  padding: 10px; background: var(--glass); cursor: pointer;
  display: flex; flex-direction: column; gap: 5px;
  transition: border-color .15s, transform .15s;
}
.reel-card:hover { border-color: rgba(251,246,238,.28); transform: translateY(-1px); }
.reel-card.selected { border-color: var(--llm); }
.reel-card.codeword { box-shadow: inset 0 0 0 1px rgba(31,167,0,.25); }
.reel-card .t { font-family: var(--mono); font-size: 10px; color: var(--muted); }
.reel-card .claim { font-size: 12px; line-height: 1.3; }
.reel-card .meta { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 9px; color: var(--muted); }
.reel-bar {
  height: 3px; border-radius: 999px; background: rgba(255,255,255,.06); overflow: hidden; margin-top: 2px;
}
.reel-bar > i { display: block; height: 100%; background: var(--ok); border-radius: 999px; }

/* ---- page shells ---- */
.page { height: 100%; display: flex; flex-direction: column; min-height: 0; }
.page-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 10px 16px 6px; gap: 12px;
}
.page-head h2 {
  font-family: var(--display); font-size: 14px; font-weight: 600;
  letter-spacing: -0.03em; text-transform: uppercase;
}
.page-head p { font-size: 12px; color: var(--muted); }
.page-meta { text-align: right; }

.tape-wrap, .graph-wrap { flex: 1; position: relative; overflow: hidden; min-height: 0; }
#tapeCanvas, #graphCanvas { display: block; width: 100%; height: 100%; cursor: crosshair; }
#graphCanvas { cursor: grab; }

.takes-bar {
  display: flex; gap: 8px; padding: 6px 14px 10px; overflow-x: auto;
  border-top: 1px solid var(--line);
}
.take-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--glass-brd); background: var(--glass);
  font-size: 11px; white-space: nowrap;
}
.take-chip .dot { width: 7px; height: 7px; border-radius: 50%; }

.panel-grid {
  flex: 1; display: grid; gap: 10px; padding: 8px 14px 14px;
  min-height: 0; overflow: auto;
}
.panel-grid.two { grid-template-columns: 1.1fr 1fr; }
.panel-grid.three { grid-template-columns: 1fr 1fr 1fr; }
.card {
  border: 1px solid var(--glass-brd); border-radius: 14px;
  background: var(--glass); padding: 12px 14px;
  min-height: 120px;
}
.card h3 {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 10px;
}
.bar {
  height: 8px; border-radius: 999px; background: rgba(255,255,255,.06);
  overflow: hidden; margin: 6px 0 12px;
}
html[data-theme="light"] .bar { background: rgba(0,0,0,.06); }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--llm); transition: width .35s ease; }
.bar.ok > i { background: var(--ok); }
.bar.bad > i { background: var(--bad); }
.bar.warn > i { background: var(--warn); }
.score-row {
  display: flex; align-items: center; gap: 8px; font-size: 12px; flex-wrap: wrap;
}

.list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.list.compact { gap: 3px; }
.list li {
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
  padding: 8px 10px; border-radius: 10px; border: 1px solid transparent;
  cursor: pointer; font-size: 12px;
}
.list li:hover { background: rgba(255,255,255,.04); }
.list li.sel { border-color: var(--glass-brd); background: rgba(255,255,255,.05); }
.list .tag { font-family: var(--mono); font-size: 10px; color: var(--muted); white-space: nowrap; }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.btn-row button {
  appearance: none; border: 1px solid var(--glass-brd); background: transparent;
  color: var(--ink); font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em;
  text-transform: uppercase; padding: 8px 12px; border-radius: 999px; cursor: pointer;
}
.btn-row button.primary {
  background: var(--metal); color: rgba(0,0,0,.55); border-color: rgba(124,122,106,.4);
}
.btn-row button:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-row button.danger { color: var(--bad); border-color: rgba(251,87,87,.35); }

.view-stack {
  flex: 1; display: grid; grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr;
  gap: 8px; padding: 8px 14px 14px; min-height: 0;
}
.view-stack.dense .view-pane { font-size: 12px; }
.view-pane {
  border: 1px solid var(--glass-brd); border-radius: 12px; background: var(--glass);
  padding: 10px; overflow: auto; min-height: 0;
}
.view-pane h3 {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 8px;
}
.heat-row {
  display: grid; grid-template-columns: 1fr 48px 28px; gap: 8px; align-items: center;
  font-size: 11px; margin: 4px 0;
}
.heat-row .h { height: 6px; border-radius: 4px; background: var(--world); }

.room-wrap {
  height: 140px; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--glass-brd); margin-bottom: 8px;
  background: #0a0b0c;
}
#roomCanvas { display: block; width: 100%; height: 100%; }
.room-stats { color: var(--muted); }
.tg-head { margin-bottom: 8px; color: var(--speech); }
.speech-line {
  font-size: 11px; margin: 6px 0; padding-bottom: 6px;
  border-bottom: 1px solid var(--line); line-height: 1.35;
}

.go-layout {
  flex: 1; display: grid; grid-template-columns: 1.2fr 1fr;
  gap: 14px; padding: 12px 16px 16px; min-height: 0;
}
.go-stage {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 20px;
  border: 1px solid var(--glass-brd); border-radius: 16px; background: var(--glass);
}
.go-btn {
  width: 148px; height: 148px; border-radius: 50%;
  border: 2px solid rgba(124,122,106,.5);
  background: var(--metal);
  color: rgba(0,0,0,.55);
  font-family: var(--display); font-size: 28px; font-weight: 600;
  letter-spacing: -0.04em; cursor: pointer;
  box-shadow: 0 12px 40px rgba(0,0,0,.35), 0 0 0 0.5px rgba(0,0,0,.4);
  transition: transform .15s, box-shadow .15s, filter .15s;
}
.go-btn.ready {
  box-shadow: 0 12px 40px rgba(31,167,0,.2), 0 0 0 1px rgba(31,167,0,.35), 0 0 60px rgba(31,167,0,.12);
}
.go-btn:not(:disabled):hover { transform: scale(1.03); }
.go-btn:disabled {
  filter: grayscale(0.6); opacity: 0.45; cursor: not-allowed;
}
.go-status {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--muted); text-align: center;
  max-width: 42ch; line-height: 1.5;
}
.go-gates { min-height: 0; overflow: auto; }
.gate-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.gate-list li {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 8px 10px; border-radius: 10px; font-size: 12px;
  border: 1px solid var(--glass-brd);
}
.gate-list li.ok { border-color: rgba(31,167,0,.3); color: var(--ok); }
.gate-list li.bad { border-color: rgba(251,87,87,.25); color: var(--warn); }

.glyph-list { display: flex; flex-direction: column; gap: 6px; }
.glyph-btn {
  appearance: none; border: 1px solid transparent; background: transparent;
  text-align: left; padding: 8px 10px; border-radius: 10px; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px; color: inherit;
}
.glyph-btn:hover { background: rgba(255,255,255,.04); }
.glyph-btn.on { border-color: var(--glass-brd); background: rgba(94,184,224,.08); }

.matrix { display: flex; flex-direction: column; gap: 8px; }
.matrix-row { display: flex; align-items: center; gap: 10px; }

.media-item {
  padding: 8px 0; border-bottom: 1px solid var(--line);
}
.media-item:last-child { border-bottom: 0; }

.toast {
  position: fixed; bottom: calc(var(--dailies) + 16px); left: 50%; transform: translateX(-50%);
  z-index: 50; padding: 10px 16px; border-radius: 999px;
  background: #1c1d1f; color: #fbf6ee; border: 1px solid rgba(251,246,238,.15);
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.06em;
  box-shadow: var(--shadow);
}
html[data-theme="light"] .toast {
  background: #2d2d2d; color: #fbf6ee;
}

.legend {
  display: flex; flex-wrap: wrap; gap: 10px; padding: 0 16px 8px;
  font-family: var(--mono); font-size: 9.5px; color: var(--muted);
  letter-spacing: 0.06em; text-transform: uppercase;
}
.legend i {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  margin-right: 4px; vertical-align: middle;
}

@media (max-width: 1100px) {
  .panel-grid.three { grid-template-columns: 1fr 1fr; }
  .go-layout { grid-template-columns: 1fr; }
  .view-stack { grid-template-columns: 1fr 1fr; grid-template-rows: auto; }
}
@media (max-width: 960px) {
  #app { grid-template-columns: 1fr; grid-template-rows: var(--top) var(--transport) var(--phase) 1fr 0; }
  .inspector, .strip { display: none; }
  .pages { justify-content: flex-start; overflow-x: auto; }
  .score-mini { display: none; }
}
