:root {
  --bg: #0d0f12;
  --panel: #15181d;
  --panel-2: #1b1f25;
  --line: #262b32;
  --text: #e9e7e0;
  --text-dim: #8a8f98;
  --amber: #e8a33d;
  --amber-dim: rgba(232, 163, 61, 0.16);
  --red: #d9564a;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
}

#topbar {
  height: 48px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  gap: 16px;
  position: relative;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { color: var(--amber); font-size: 16px; }
.brand-name {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--text);
}

.status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-left: auto;
}
.status .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-dim);
}
.status.live .dot { background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.status.live #connText { color: var(--amber); }

.chip-btn {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 6px 10px;
  cursor: pointer;
}
.chip-btn:hover { border-color: var(--amber); color: var(--amber); }
.chip-btn span { color: var(--amber); font-weight: 700; }

#stage {
  position: relative;
  width: 100vw;
  height: calc(100vh - 48px);
  overflow: hidden;
}

#focusContainer, #gridContainer {
  position: absolute;
}

.tile {
  position: absolute;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 2px;
  overflow: hidden;
}

.tile video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  display: block;
  color-scheme: dark;
}

.tile-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  background: #0a0b0d;
  pointer-events: none;
}
.tile.ready .tile-loading { display: none; }

.tile-chrome {
  position: absolute;
  left: 0; right: 0; top: 0;
  display: flex;
  align-items: center;
  padding: 6px 8px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.75), transparent);
  opacity: 0;
  transition: opacity 0.12s ease;
  pointer-events: none;
}
.tile:hover .tile-chrome,
.tile.focused .tile-chrome { opacity: 1; }

.tile-tally {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--text);
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}
.tally-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 5px var(--amber);
  flex: none;
}

.tile.small .tile-tally { font-size: 9px; }

.ctx-menu {
  position: fixed;
  z-index: 100;
  min-width: 150px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 3px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  padding: 20px 4px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ctx-close {
  position: absolute;
  top: 3px; right: 3px;
  width: 16px; height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
  color: var(--text-dim);
  background: transparent;
  border: none;
  border-radius: 2px;
  padding: 0;
  cursor: pointer;
}
.ctx-close:hover { color: var(--amber); }
.ctx-item {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-align: left;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: 2px;
  padding: 7px 10px;
  cursor: pointer;
}
.ctx-item:hover { background: var(--amber-dim); color: var(--amber); }
.ctx-item.active { color: var(--red); }
.ctx-menu[hidden] { display: none; }

.tile-rec {
  position: absolute;
  top: 6px; right: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  background: rgba(0,0,0,0.65);
  border: 1px solid var(--red);
  border-radius: 2px;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--red);
  pointer-events: none;
  z-index: 5;
}
.tile-rec[hidden] { display: none; }
.tile-rec::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 5px var(--red);
  animation: rec-pulse 1.2s ease-in-out infinite;
}
@keyframes rec-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

#emptyState {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--text-dim);
  pointer-events: none;
}
#stage.empty #emptyState { display: flex; }
.empty-glyph { font-size: 34px; color: var(--line); }
.empty-title {
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.2em;
  color: var(--text-dim);
}
.empty-sub { font-size: 12px; letter-spacing: 0.02em; }

.hidden-panel {
  position: absolute;
  top: 48px;
  right: 0;
  max-width: 320px;
  max-height: calc(100vh - 48px);
  background: var(--panel);
  border-left: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  z-index: 30;
  overflow-y: auto;
}
.hidden-panel-head {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  padding: 10px 12px 6px;
}
.hidden-list { display: flex; flex-direction: column; }
.hidden-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 11px;
}
.hidden-row button {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.06em;
  color: var(--amber);
  background: var(--amber-dim);
  border: 1px solid var(--amber);
  border-radius: 2px;
  padding: 4px 8px;
  cursor: pointer;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
