:root {
  --bg: #0a0f1c;
  --bg-elev: #111827;
  --bg-inset: #0d1424;
  --border: #1e293b;
  --border-hi: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #38bdf8;
  --primary-soft: rgba(56, 189, 248, 0.14);
  --primary-fg: #082f49;
  --emerald: #10b981;
  --emerald-soft: rgba(16, 185, 129, 0.14);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.15);
  --rose: #f43f5e;
  --rose-soft: rgba(244, 63, 94, 0.15);
  --violet: #a78bfa;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

html.light {
  --bg: #f8fafc;
  --bg-elev: #ffffff;
  --bg-inset: #f1f5f9;
  --border: #e2e8f0;
  --border-hi: #cbd5e1;
  --text: #0f172a;
  --muted: #475569;
  --primary: #0284c7;
  --primary-soft: rgba(2, 132, 199, 0.10);
  --primary-fg: #ffffff;
  --emerald: #059669;
  --emerald-soft: rgba(5, 150, 105, 0.12);
  --amber: #d97706;
  --amber-soft: rgba(217, 119, 6, 0.12);
  --rose: #e11d48;
  --rose-soft: rgba(225, 29, 72, 0.12);
  --violet: #7c3aed;
  --shadow: 0 6px 24px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-variant-numeric: tabular-nums; }

/* Sticky Top Bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 16px;
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(56, 189, 248, 0.35);
}

.brand-title {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--muted);
}

.pill.live {
  border-color: color-mix(in srgb, var(--emerald) 45%, var(--border));
  background: var(--emerald-soft);
  color: var(--emerald);
}

.pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 8px var(--emerald);
  animation: pulse 1.8s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.82); }
}

.hud-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.timer-box {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  font-size: 12.5px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--primary);
  color: var(--primary-fg);
  border-color: var(--primary);
}

.btn.primary:hover:not(:disabled) {
  opacity: 0.9;
  color: var(--primary-fg);
}

.btn.danger {
  border-color: var(--rose);
  background: var(--rose-soft);
  color: var(--rose);
}

.btn.success {
  border-color: var(--emerald);
  background: var(--emerald-soft);
  color: var(--emerald);
}

.btn.sm {
  padding: 4px 9px;
  font-size: 12px;
}

/* Stage Tabs */
.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.tab-btn:hover {
  color: var(--text);
  border-color: var(--border-hi);
}

.tab-btn.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

.tab-btn .time-tag {
  font-size: 11px;
  font-weight: 500;
  opacity: 0.8;
}

/* Layout */
.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn 0.2s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* KPI Banner */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.kpi-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

.kpi-val {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.kpi-sub {
  font-size: 12px;
  color: var(--muted);
}

.c-primary { color: var(--primary); }
.c-emerald { color: var(--emerald); }
.c-amber { color: var(--amber); }
.c-rose { color: var(--rose); }
.c-violet { color: var(--violet); }

/* Cards & Grids */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.grid-asymmetric {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 18px;
}

.grid-asymmetric-rev {
  display: grid;
  grid-template-columns: 0.85fr 1.15fr;
  gap: 18px;
}

@media (max-width: 960px) {
  .grid-2, .grid-asymmetric, .grid-asymmetric-rev {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.card-title {
  font-size: 15.5px;
  font-weight: 700;
  margin: 0;
}

.card-desc {
  font-size: 12.5px;
  color: var(--muted);
  margin: 3px 0 0;
}

.stage-box {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 12px;
  overflow: hidden;
}

.inset-box {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

/* Sliders & Toggles */
.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
}

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

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border-radius: 8px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}

.toggle-chip input { accent-color: var(--primary); cursor: pointer; }

/* Interactive Block Chips for Act 1 */
.block-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

@media (max-width: 640px) {
  .block-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.block-chip {
  padding: 9px 10px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-inset);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
  color: var(--text);
}

.block-chip:hover { border-color: var(--primary); transform: translateY(-1px); }
.block-chip.spd-40 { border-left: 4px solid var(--muted); }
.block-chip.spd-100 { border-left: 4px solid var(--primary); }
.block-chip.spd-200 { border-left: 4px solid var(--emerald); }

/* Animated Optical Flow Dashes */
.flow-dash {
  stroke-dasharray: 8 6;
  animation: dashFlow 1.0s linear infinite;
}

.flow-dash-fast {
  stroke-dasharray: 7 5;
  animation: dashFlow 0.55s linear infinite;
}

@keyframes dashFlow {
  to { stroke-dashoffset: -28; }
}

/* Progress Bars */
.bar-track {
  height: 9px;
  border-radius: 999px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.25s ease, background-color 0.25s ease;
}

/* Tables */
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

table.data-table th {
  text-align: left;
  padding: 7px 8px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

table.data-table td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
}

table.data-table tr:last-child td { border-bottom: none; }

/* OpenFlow Code Box */
.code-box {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--primary);
  overflow-x: auto;
  white-space: pre;
}

/* Slide Plot Image Cards & Lightbox */
.plot-img {
  width: 100%;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: #ffffff;
  cursor: zoom-in;
  display: block;
  transition: transform 0.15s ease;
}

.plot-img:hover {
  transform: scale(1.008);
  border-color: var(--primary);
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(2, 6, 23, 0.88);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  cursor: zoom-out;
}

.lightbox.open { display: flex; }
.lightbox img {
  max-width: 96vw;
  max-height: 92vh;
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

/* Domain Kill Switch Buttons */
.domain-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.domain-btn {
  padding: 10px 8px;
  border-radius: 10px;
  border: 1px solid var(--emerald);
  background: var(--emerald-soft);
  color: var(--emerald);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s ease;
}

.domain-btn.killed {
  border-color: var(--rose);
  background: var(--rose-soft);
  color: var(--rose);
}

.domain-btn:hover { transform: translateY(-1px); }

/* Cue Card */
.cue-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cue-item {
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
}

.cue-item h4 {
  margin: 0 0 4px;
  font-size: 13.5px;
}

.cue-item p {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
}

.callout {
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-inset);
  font-size: 12.5px;
  line-height: 1.55;
}

.callout.ok { border-color: color-mix(in srgb, var(--emerald) 55%, var(--border)); background: var(--emerald-soft); }
.callout.bad { border-color: color-mix(in srgb, var(--rose) 55%, var(--border)); background: var(--rose-soft); }
.callout.warn { border-color: color-mix(in srgb, var(--amber) 55%, var(--border)); background: var(--amber-soft); }
