/* ===== Tokens =====
   Palette: a dark control-room, two working accents (not decoration):
   red = live right now, amber = a captured highlight.
*/
:root {
  --void: #08090b;
  --void-deep: #050506;
  --panel: #15181c;
  --panel-raised: #1d2127;
  --panel-glass: rgba(255, 255, 255, 0.035);
  --line: #262b32;
  --line-soft: rgba(255, 255, 255, 0.07);
  --text: #edf0f3;
  --text-dim: #929aa7;
  --text-faint: #565e6b;
  --live: #ff4433;
  --live-soft: rgba(255, 68, 51, 0.14);
  --live-glow: rgba(255, 68, 51, 0.35);
  --highlight: #f5b700;
  --highlight-soft: rgba(245, 183, 0, 0.13);
  --highlight-glow: rgba(245, 183, 0, 0.35);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-2: 0 1px 2px rgba(0, 0, 0, 0.45), 0 14px 28px -14px rgba(0, 0, 0, 0.65);
  --shadow-3: 0 2px 4px rgba(0, 0, 0, 0.5), 0 28px 48px -18px rgba(0, 0, 0, 0.75);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --font-display: "Big Shoulders Display", sans-serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1100px 560px at 14% -8%, rgba(245, 183, 0, 0.05), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(255, 68, 51, 0.035), transparent 55%),
    var(--void);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
img { max-width: 100%; display: block; }

.mono { font-family: var(--font-mono); letter-spacing: 0.02em; }
.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 0.75rem; }

::selection { background: var(--highlight); color: #14171a; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

/* ===== Shell / layout ===== */
.shell {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

.rail {
  background: linear-gradient(180deg, var(--panel), var(--void-deep) 130%);
  border-right: 1px solid var(--line);
  padding: 30px 22px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 48px;
}
.brand-mark {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 0 4px var(--live-soft), 0 0 14px 1px var(--live-glow);
  animation: pulse-dot 2.2s ease-in-out infinite;
  flex-shrink: 0;
}
.brand-name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.6rem;
  letter-spacing: 0.07em;
  background: linear-gradient(135deg, #fff, #9aa2ad 140%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-link {
  display: flex;
  align-items: baseline;
  gap: 11px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-weight: 500;
  font-size: 0.95rem;
  border-left: 2px solid transparent;
  transition: color 0.16s var(--ease), background-color 0.16s var(--ease), border-color 0.16s var(--ease);
}
.nav-index { font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-faint); transition: color 0.16s var(--ease); }
.nav-link:hover { color: var(--text); background: var(--panel-glass); }
.nav-link.active { color: var(--text); border-left-color: var(--highlight); background: var(--panel-glass); }
.nav-link.active .nav-index { color: var(--highlight); }

.rail-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); transition: background-color 0.2s; }
.status-dot.ok { background: #33d17f; box-shadow: 0 0 8px 1px rgba(51, 209, 127, 0.5); }
.status-dot.warn { background: var(--highlight); box-shadow: 0 0 8px 1px var(--highlight-glow); }
.status-dot.err { background: var(--live); box-shadow: 0 0 8px 1px var(--live-glow); }

.stage { padding: 44px 52px 88px; max-width: 1220px; }

/* ===== Page header ===== */
.page-head { margin-bottom: 36px; }
.page-kicker {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--highlight);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.page-kicker::before {
  content: "";
  width: 14px;
  height: 1px;
  background: var(--highlight);
  display: inline-block;
}
.page-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 3rem;
  line-height: 0.98;
  margin: 0 0 12px;
  letter-spacing: 0.005em;
}
.page-sub { color: var(--text-dim); max-width: 62ch; margin: 0; line-height: 1.6; font-size: 0.98rem; }

/* ===== Signature element: signal waveform ===== */
.waveform {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 36px;
  margin: 20px 0 0;
}
.waveform span {
  width: 3px;
  background: linear-gradient(180deg, var(--highlight), rgba(245, 183, 0, 0.25));
  opacity: 0.75;
  border-radius: 2px;
  animation: bar-bounce 1.6s ease-in-out infinite;
}
@keyframes bar-bounce {
  0%, 100% { transform: scaleY(0.3); }
  50% { transform: scaleY(1); }
}
@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 4px var(--live-soft), 0 0 14px 1px var(--live-glow); }
  50% { box-shadow: 0 0 0 7px rgba(255, 68, 51, 0.06), 0 0 18px 3px var(--live-glow); }
}

/* ===== Buttons / inputs ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 20px;
  background: var(--text);
  color: var(--void);
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: transform 0.14s var(--ease), opacity 0.14s var(--ease), box-shadow 0.14s var(--ease);
}
.btn:hover { opacity: 0.9; transform: translateY(-1px); box-shadow: var(--shadow-1); }
.btn:active { transform: translateY(0); }
.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}
.btn.ghost:hover { border-color: var(--text-dim); background: var(--panel-glass); }
.btn.danger { background: transparent; color: var(--live); border: 1px solid rgba(255, 68, 51, 0.35); }
.btn.danger:hover { background: var(--live-soft); border-color: var(--live); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 18px; }
.field label { font-size: 0.78rem; color: var(--text-dim); font-family: var(--font-mono); }
.field input {
  background: var(--panel-raised);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 12px 13px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: var(--font-body);
  transition: border-color 0.14s var(--ease), box-shadow 0.14s var(--ease);
}
.field input:focus { outline: none; border-color: var(--highlight); box-shadow: 0 0 0 3px var(--highlight-soft); }
.field input::placeholder { color: var(--text-faint); }
.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { margin-bottom: 0; min-width: 260px; flex: 1; }

/* ===== Clip grid ===== */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 22px; }

.clip-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-1);
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease), border-color 0.2s var(--ease);
}
.clip-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-3);
  border-color: rgba(245, 183, 0, 0.28);
}
.clip-thumb {
  position: relative;
  aspect-ratio: 16/9;
  background: linear-gradient(135deg, var(--panel-raised), var(--panel));
  cursor: pointer;
  overflow: hidden;
}
.clip-thumb .clip-img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.35s var(--ease); }
.clip-card:hover .clip-thumb .clip-img { transform: scale(1.045); }
.clip-thumb::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(0deg, rgba(0,0,0,0.55), transparent 42%);
  pointer-events: none;
}
.clip-thumb::before {
  content: "";
  position: absolute; top: 50%; left: 50%;
  width: 44px; height: 44px;
  transform: translate(-50%, -50%) scale(0.85);
  border-radius: 50%;
  background: rgba(8, 9, 11, 0.55);
  border: 1px solid rgba(255,255,255,0.25);
  opacity: 0;
  transition: opacity 0.18s var(--ease), transform 0.18s var(--ease);
  backdrop-filter: blur(2px);
  z-index: 1;
}
.clip-thumb:hover::before { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.clip-thumb {
  --play-icon: polygon(35% 27%, 35% 73%, 72% 50%);
}
.clip-thumb > .play-icon {
  position: absolute; top: 50%; left: 50%;
  width: 44px; height: 44px;
  transform: translate(-50%, -50%) scale(0.85);
  opacity: 0;
  transition: opacity 0.18s var(--ease), transform 0.18s var(--ease);
  z-index: 2;
  pointer-events: none;
}
.clip-thumb:hover > .play-icon { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.clip-thumb > .play-icon svg { width: 100%; height: 100%; }
.clip-badge {
  position: absolute; top: 11px; left: 11px; z-index: 2;
  background: var(--highlight); color: #17140a;
  font-size: 0.64rem; font-weight: 700; letter-spacing: 0.09em;
  padding: 4px 8px; border-radius: 3px;
  box-shadow: 0 2px 8px -2px var(--highlight-glow);
}
.clip-spike {
  position: absolute; bottom: 11px; right: 11px; z-index: 2;
  background: rgba(8, 9, 11, 0.78); color: var(--highlight);
  font-size: 0.7rem; padding: 4px 8px; border-radius: 3px;
  border: 1px solid rgba(245, 183, 0, 0.2);
}
.clip-meta { display: flex; gap: 11px; padding: 13px; align-items: flex-start; }
.clip-avatar { width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; background: var(--panel-raised); border: 1px solid var(--line); }
.clip-title { font-size: 0.88rem; font-weight: 500; line-height: 1.35; margin-bottom: 4px; }
.clip-sub { text-transform: uppercase; }

.player-overlay {
  position: fixed; inset: 0; background: rgba(4, 5, 6, 0.92);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 24px;
  backdrop-filter: blur(6px);
  animation: fade-in 0.15s var(--ease);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.player-overlay-inner { width: min(960px, 100%); }
.player-overlay iframe { width: 100%; aspect-ratio: 16/9; border: 0; background: #000; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-3); }
.player-overlay-close { margin-top: 14px; }

/* ===== Streamer list ===== */
.streamer-row {
  display: flex; align-items: center; gap: 15px; flex-wrap: wrap;
  padding: 15px 17px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 10px;
  transition: border-color 0.16s var(--ease), transform 0.16s var(--ease), box-shadow 0.16s var(--ease);
}
.streamer-row:hover { border-color: var(--line-soft); box-shadow: var(--shadow-2); transform: translateY(-1px); }
.streamer-avatar { width: 46px; height: 46px; border-radius: 50%; background: var(--panel-raised); flex-shrink: 0; border: 1px solid var(--line); }
.streamer-info { flex: 1; min-width: 0; }
.streamer-name { font-weight: 600; display: flex; align-items: center; gap: 9px; }
.streamer-title { color: var(--text-dim); font-size: 0.84rem; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-mono); font-size: 0.65rem; font-weight: 600;
  color: var(--live); border: 1px solid rgba(255, 68, 51, 0.4); background: var(--live-soft);
  padding: 3px 7px; border-radius: 3px;
}
.live-badge .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--live); animation: pulse-dot 1.8s ease-in-out infinite; }
.offline-badge { font-family: var(--font-mono); font-size: 0.65rem; color: var(--text-faint); border: 1px solid var(--line); padding: 3px 7px; border-radius: 3px; }
.viewer-count { font-family: var(--font-mono); font-size: 0.82rem; color: var(--text-dim); min-width: 96px; text-align: right; }
.row-actions { display: flex; gap: 8px; }

/* ===== Watch view ===== */
.watch-layout { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; align-items: start; }
.watch-player { aspect-ratio: 16/9; background: #000; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-2); }
.watch-player iframe { width: 100%; height: 100%; border: 0; }
.watch-chat { aspect-ratio: unset; height: 100%; min-height: 480px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-2); }
.watch-chat iframe { width: 100%; height: 100%; min-height: 480px; border: 0; }
.watch-side { display: flex; flex-direction: column; gap: 12px; }
.watch-clips-title { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.1em; margin: 4px 0; }

/* ===== Auto-clip console ===== */
.console-wrap {
  margin-top: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--void-deep);
  overflow: hidden;
  box-shadow: var(--shadow-1);
}
.console-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 15px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  gap: 14px;
  flex-wrap: wrap;
}
.confidence-wrap { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.confidence-meter { width: 110px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; display: inline-block; }
.confidence-fill { display: block; height: 100%; width: 0%; background: var(--highlight); transition: width 0.4s var(--ease), background-color 0.3s var(--ease); }
.confidence-fill.hot { background: var(--live); box-shadow: 0 0 8px 1px var(--live-glow); }
.console-title {
  font-size: 0.72rem; letter-spacing: 0.12em; color: var(--text-faint);
}
.console-status { display: inline-flex; align-items: center; gap: 6px; }
.console-dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-faint);
}
.console-dot.live { background: var(--highlight); box-shadow: 0 0 8px 1px var(--highlight-glow); }
.console-body {
  height: 220px;
  overflow-y: auto;
  padding: 11px 15px;
  font-size: 0.8rem;
  line-height: 1.65;
  display: flex;
  flex-direction: column; /* JS renders newest-first, so newest lands at the top */
}
.console-body::-webkit-scrollbar { width: 8px; }
.console-body::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
.console-line { color: var(--text-dim); white-space: pre-wrap; word-break: break-word; }
.console-time { margin-right: 8px; }
.console-match { color: var(--text); }
.console-trigger { color: var(--highlight); font-weight: 600; }
.console-clipped { color: var(--highlight); }
.console-connected { color: #7ee787; }
.console-error { color: #ff9d97; }
.console-info { color: var(--text-faint); }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; flex-direction: row; align-items: center; padding: 16px 20px; }
  .brand { margin-bottom: 0; }
  .nav { flex-direction: row; margin-left: 24px; }
  .rail-foot { display: none; }
  .stage { padding: 26px 20px 64px; }
  .watch-layout { grid-template-columns: 1fr; }
  .page-title { font-size: 2.2rem; }
}

/* ===== Empty / error / loading states ===== */
.empty-state {
  border: 1px dashed var(--line); border-radius: var(--radius-lg);
  padding: 56px 24px; text-align: center; color: var(--text-dim);
  background: var(--panel-glass);
}
.empty-state .btn { margin-top: 18px; }
.banner {
  border: 1px solid var(--line); border-left: 3px solid var(--highlight);
  background: var(--panel); padding: 13px 15px; border-radius: var(--radius-sm);
  font-size: 0.85rem; color: var(--text-dim); margin-bottom: 22px;
}
.banner.error { border-left-color: var(--live); color: #ff9d97; }
.banner a { color: var(--highlight); text-decoration: underline; }

/* ===== Detection toggle ===== */
.detect-toggle {
  display: inline-flex; align-items: center; gap: 7px;
  background: transparent; border: 1px solid var(--line); color: var(--text-dim);
  padding: 7px 12px; border-radius: var(--radius-sm);
  font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.04em;
  cursor: pointer; transition: border-color 0.14s var(--ease), color 0.14s var(--ease), background-color 0.14s var(--ease);
}
.detect-toggle .swatch { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); flex-shrink: 0; }
.detect-toggle.on { color: #7ee787; border-color: rgba(126, 231, 135, 0.35); }
.detect-toggle.on .swatch { background: #7ee787; box-shadow: 0 0 7px 1px rgba(126, 231, 135, 0.5); }
.detect-toggle.off { color: var(--text-faint); }
.detect-toggle.off .swatch { background: var(--text-faint); }
.detect-toggle:hover { background: var(--panel-glass); border-color: var(--text-dim); }
.detect-toggle:disabled { opacity: 0.45; cursor: not-allowed; }
.detect-pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-mono); font-size: 0.63rem; color: var(--text-faint);
  border: 1px solid var(--line); padding: 2px 7px; border-radius: 3px; text-transform: uppercase;
}
.detect-pill .swatch { width: 5px; height: 5px; border-radius: 50%; background: var(--text-faint); }

/* ===== Group select / tags ===== */
.group-select {
  background: var(--panel-raised); border: 1px solid var(--line); color: var(--text);
  padding: 8px 10px; border-radius: var(--radius-sm); font-size: 0.82rem; font-family: var(--font-body);
  min-width: 140px; cursor: pointer;
}
.group-select:focus { outline: none; border-color: var(--highlight); box-shadow: 0 0 0 3px var(--highlight-soft); }
.group-tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-mono); font-size: 0.63rem; color: var(--highlight);
  background: var(--highlight-soft); border: 1px solid rgba(245, 183, 0, 0.25);
  padding: 2px 8px; border-radius: 3px; text-transform: uppercase; letter-spacing: 0.04em;
}

/* ===== Groups management panel ===== */
.groups-panel {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
  padding: 18px 20px; margin-bottom: 28px;
}
.groups-panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.groups-panel-title { font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.1em; margin: 0; }
.groups-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.groups-list:empty { display: none; }
.group-chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--panel-raised); border: 1px solid var(--line); border-radius: 20px;
  padding: 6px 8px 6px 13px; font-size: 0.82rem;
}
.group-chip .count { color: var(--text-faint); font-family: var(--font-mono); font-size: 0.7rem; }
.group-chip .remove {
  width: 18px; height: 18px; border-radius: 50%; border: none; background: var(--line);
  color: var(--text-dim); font-size: 0.7rem; line-height: 1; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.group-chip .remove:hover { background: var(--live-soft); color: var(--live); }
.groups-form { display: flex; gap: 8px; }
.groups-form input {
  background: var(--panel-raised); border: 1px solid var(--line); color: var(--text);
  padding: 9px 12px; border-radius: var(--radius-sm); font-size: 0.85rem; flex: 1; max-width: 260px;
}
.groups-form input:focus { outline: none; border-color: var(--highlight); box-shadow: 0 0 0 3px var(--highlight-soft); }

/* ===== Highlights: group sections ===== */
.group-section { margin-bottom: 40px; }
.group-section-head {
  display: flex; align-items: baseline; gap: 12px; margin-bottom: 16px;
  padding-bottom: 10px; border-bottom: 1px solid var(--line);
}
.group-section-title {
  font-family: var(--font-display); font-weight: 800; font-size: 1.4rem; letter-spacing: 0.01em; margin: 0;
}
.group-section-title.ungrouped { color: var(--text-dim); font-family: var(--font-body); font-weight: 600; font-size: 1.05rem; }
.group-section-count { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-faint); }

.skeleton-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 22px; }
.skeleton-card { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: var(--panel); }
.skeleton-thumb { aspect-ratio: 16/9; background: linear-gradient(100deg, var(--panel) 30%, var(--panel-raised) 50%, var(--panel) 70%); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
.skeleton-line { height: 11px; margin: 13px; border-radius: 4px; background: var(--panel-raised); }
.skeleton-line.short { width: 55%; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
