@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --bg: #0B0F14;
  --panel: #141A22;
  --panel-2: #1C242E;
  --border: #2A3441;
  --hair: rgba(138, 151, 166, 0.14);
  --text: #E6EAEF;
  --muted: #8A97A6;
  --accent: #FFB020;       /* on-air amber */
  --accent-dim: rgba(255, 176, 32, 0.14);
  --live: #36D399;         /* live tally */
  --danger: #F26D6D;
  --display: 'Space Grotesk', system-ui, sans-serif;
  --body: 'Inter', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
a { color: var(--accent); }

.eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--hair);
  position: sticky; top: 0; background: rgba(11, 15, 20, 0.85);
  backdrop-filter: blur(8px); z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.tally {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-dim);
}
.brand h1 {
  font-family: var(--display); font-weight: 700; font-size: 17px;
  margin: 0; letter-spacing: -0.01em;
}
.brand .sub { font-family: var(--mono); font-size: 11px; color: var(--muted); letter-spacing: 0.14em; }

.btn {
  font-family: var(--body); font-weight: 600; font-size: 14px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 16px; cursor: pointer; transition: border-color .15s, background .15s;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: #1a1206; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: rgba(242,109,109,.3); }
.btn:focus-visible, input:focus-visible, .cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input, select {
  font-family: var(--body); font-size: 14px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; width: 100%;
}
input::placeholder { color: var(--muted); }
label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px; }

/* ---------- access gate ---------- */
.gate {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
}
.gate-card {
  width: 100%; max-width: 420px; text-align: center;
}
.gate .tally-big {
  width: 14px; height: 14px; border-radius: 50%; margin: 0 auto 28px;
  background: var(--accent); box-shadow: 0 0 0 6px var(--accent-dim), 0 0 24px var(--accent);
  animation: pulse 2.6s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }
.gate h2 { font-family: var(--display); font-size: 26px; margin: 0 0 8px; letter-spacing: -0.02em; }
.gate p { color: var(--muted); margin: 0 0 28px; font-size: 15px; }

.code-row { display: flex; gap: 10px; justify-content: center; margin-bottom: 20px; }
.cell {
  width: 48px; height: 60px; text-align: center;
  font-family: var(--mono); font-size: 26px; font-weight: 600;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  color: var(--text); text-transform: uppercase; padding: 0;
}
.cell.filled { border-color: var(--accent); }
.gate-error { color: var(--danger); font-size: 14px; min-height: 20px; margin-bottom: 12px; }

/* ---------- viewer layout ---------- */
.viewer { display: grid; grid-template-columns: 1fr; }
.stage { padding: 24px; }
.player-wrap {
  background: #000; border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; aspect-ratio: 16 / 9; position: relative; max-width: 1100px; margin: 0 auto;
}
.player-wrap video { width: 100%; height: 100%; display: block; background: #000; }
.player-empty {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: var(--muted);
  font-family: var(--mono); letter-spacing: .1em; font-size: 13px;
}
.now-playing {
  max-width: 1100px; margin: 14px auto 0; display: flex; align-items: center; gap: 12px;
}
.now-playing .live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--live); box-shadow: 0 0 8px var(--live); }
.now-playing .name { font-family: var(--display); font-weight: 600; font-size: 18px; }
.now-playing .status { font-family: var(--mono); font-size: 11px; color: var(--muted); letter-spacing: .14em; text-transform: uppercase; }

.controls-row {
  max-width: 1100px; margin: 22px auto 12px; display: flex; gap: 12px; flex-wrap: wrap; align-items: center;
}
.controls-row .search { flex: 1; min-width: 200px; }
.controls-row select { width: auto; min-width: 160px; }

/* ---------- channel grid ---------- */
.grid {
  max-width: 1100px; margin: 0 auto; padding-bottom: 60px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px;
}
.channel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; cursor: pointer; text-align: left;
  transition: border-color .15s, transform .15s, background .15s;
  display: flex; flex-direction: column; gap: 10px;
}
.channel:hover { border-color: var(--accent); transform: translateY(-2px); }
.channel.active { border-color: var(--accent); background: var(--accent-dim); }
.channel .logo {
  width: 100%; aspect-ratio: 16/10; object-fit: contain; background: var(--bg);
  border-radius: 8px; border: 1px solid var(--hair);
}
.channel .logo.placeholder { display: grid; place-items: center; font-family: var(--mono); color: var(--muted); font-size: 22px; }
.channel .cat { font-family: var(--mono); font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.channel .cname { font-weight: 600; font-size: 14px; line-height: 1.3; }

/* ---------- admin ---------- */
.admin-wrap { max-width: 1000px; margin: 0 auto; padding: 28px 24px 80px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; margin-bottom: 20px;
}
.card h3 { font-family: var(--display); font-size: 16px; margin: 0 0 4px; }
.card .hint { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 160px; margin-bottom: 0; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--hair); }
th { font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 500; }
td .mono { font-family: var(--mono); }
.tag { font-family: var(--mono); font-size: 11px; padding: 3px 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); }
.tag.on { color: var(--live); border-color: rgba(54,211,153,.35); }

.list { max-height: 460px; overflow: auto; border: 1px solid var(--hair); border-radius: 10px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--hair); }
.list-item:last-child { border-bottom: 0; }
.list-item img { width: 40px; height: 28px; object-fit: contain; background: var(--bg); border-radius: 5px; }
.list-item .meta { flex: 1; min-width: 0; }
.list-item .meta .n { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .meta .c { font-family: var(--mono); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.switch { position: relative; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; cursor: pointer; transition: .15s; }
.slider::before { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: var(--muted); border-radius: 50%; transition: .15s; }
.switch input:checked + .slider { background: var(--accent-dim); border-color: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); background: var(--accent); }

.notice { font-size: 13px; padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; }
.notice.err { background: rgba(242,109,109,.1); color: var(--danger); border: 1px solid rgba(242,109,109,.3); }
.notice.ok { background: rgba(54,211,153,.1); color: var(--live); border: 1px solid rgba(54,211,153,.3); }
.empty { color: var(--muted); font-size: 14px; padding: 18px 0; text-align: center; }
.hidden { display: none !important; }

@media (max-width: 560px) {
  .cell { width: 42px; height: 54px; font-size: 22px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
