:root {
  --bg: #0b0d14;
  --bg-soft: #11141f;
  --card: #161a27;
  --card-hover: #1c2133;
  --border: #262c40;
  --text: #e9ebf3;
  --text-dim: #8b91a7;
  --accent: #7c5cff;
  --accent-2: #ff5c8a;
  --live: #ff3b5c;
  --green: #22c98a;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  font-family: 'Segoe UI', 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  isolation: isolate; /* keeps the animated layers below below, never above, real content */
}

/* ---------- Animated studio background ---------- */
/* Soft glowing color fields that drift very slowly, like a broadcast
   virtual-set backdrop. Purely decorative, sits behind every card/panel. */
body::before {
  content: "";
  position: fixed;
  inset: -10%;
  z-index: -2;
  pointer-events: none;
  background:
    radial-gradient(38rem 32rem at 18% 22%, rgba(124,92,255,0.24), transparent 60%),
    radial-gradient(32rem 30rem at 82% 12%, rgba(255,92,138,0.16), transparent 60%),
    radial-gradient(36rem 34rem at 50% 92%, rgba(34,201,138,0.10), transparent 62%),
    radial-gradient(26rem 26rem at 92% 78%, rgba(124,92,255,0.14), transparent 60%);
  background-repeat: no-repeat;
  filter: blur(6px);
  animation: studioDrift 26s ease-in-out infinite alternate;
  will-change: background-position, transform;
}

@keyframes studioDrift {
  0% {
    background-position: 0% 0%, 100% 0%, 40% 100%, 100% 100%;
    transform: scale(1) rotate(0deg);
  }
  50% {
    background-position: 8% 12%, 88% 8%, 52% 88%, 90% 82%;
    transform: scale(1.06) rotate(0.6deg);
  }
  100% {
    background-position: 4% 6%, 94% 4%, 46% 94%, 96% 88%;
    transform: scale(1.02) rotate(-0.4deg);
  }
}

/* Faint moving grid — the kind of subtle broadcast-graphics texture that
   reads as "professional studio" rather than "plain dark page", visible
   enough to notice moving but never competing with content. */
body::after {
  content: "";
  position: fixed;
  inset: -60px;
  z-index: -1;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(80% 70% at 50% 30%, #000 40%, transparent 90%);
  -webkit-mask-image: radial-gradient(80% 70% at 50% 30%, #000 40%, transparent 90%);
  animation: gridPan 34s linear infinite;
}

@keyframes gridPan {
  from { background-position: 0 0, 0 0; }
  to   { background-position: 184px 138px, 184px 138px; }
}

@media (prefers-reduced-motion: reduce) {
  body::before,
  body::after {
    animation: none;
  }
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-2); }

/* ---------- Nav ---------- */
.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  border-bottom: 1px solid var(--border);
  background: rgba(17,20,31,0.7);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  font-weight: 700;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: 0.3px;
}
.brand-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 12px var(--accent);
}
.nav-links { display: flex; align-items: center; gap: 20px; }
.nav-links a { color: var(--text-dim); font-weight: 500; }
.nav-links a:hover { color: var(--text); }
.nav-user { color: var(--text-dim); font-size: 0.9rem; }
.nav-user em { color: var(--accent); font-style: normal; }
.inline-form { display: inline; }

/* ---------- Layout ---------- */
.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 36px 24px 80px;
}
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 28px;
}
.page-header h1 { margin: 0 0 6px; font-size: 1.7rem; }
.page-header p { margin: 0; color: var(--text-dim); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s ease;
}
.btn:hover { background: var(--card-hover); border-color: var(--accent); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #5b3df0);
  border: none;
  color: #fff;
  box-shadow: 0 6px 18px rgba(124,92,255,0.35);
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-danger { border-color: #4a2030; color: #ff8fa3; }
.btn-danger:hover { background: rgba(255,60,92,0.12); border-color: var(--live); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-dim); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; border-radius: 8px; }

/* ---------- Cards / Grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: transform .15s ease, border-color .15s ease;
}
.card:hover { transform: translateY(-3px); border-color: var(--accent); }

.stream-card { display: flex; flex-direction: column; gap: 12px; }
.stream-card .thumb {
  height: 130px;
  border-radius: 10px;
  background: linear-gradient(135deg, #1b2035, #10131e);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  position: relative;
  overflow: hidden;
}
.stream-card .thumb.live { background: linear-gradient(135deg, #2a1030, #1b0f22); color: #fff; }
.stream-name { font-weight: 700; font-size: 1.05rem; }
.stream-owner { color: var(--text-dim); font-size: 0.82rem; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.badge-live { background: rgba(255,59,92,0.15); color: var(--live); }
.badge-offline { background: rgba(139,145,167,0.15); color: var(--text-dim); }
.pulse {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 0 0 rgba(255,59,92,0.6);
  animation: pulse 1.6s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255,59,92,0.55); }
  70% { box-shadow: 0 0 0 8px rgba(255,59,92,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,59,92,0); }
}

/* ---------- Forms ---------- */
.form-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 460px;
}
label { display: block; font-size: 0.85rem; color: var(--text-dim); margin-bottom: 6px; font-weight: 600; }
input[type=text], input[type=password], select {
  width: 100%;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 16px;
  outline: none;
  transition: border-color .15s ease;
}
input:focus, select:focus { border-color: var(--accent); }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.checkbox-row input { width: auto; margin: 0; }
.checkbox-row label { margin: 0; }

/* ---------- Toggle switch (restream destinations) ---------- */
.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  border: 1px solid var(--border);
  cursor: pointer;
  padding: 0;
  background: var(--bg-soft);
  transition: background .18s ease, border-color .18s ease;
  flex-shrink: 0;
}
.toggle-switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform .18s ease, background .18s ease;
}
.toggle-switch.on {
  background: linear-gradient(135deg, var(--accent), #5b3df0);
  border-color: transparent;
}
.toggle-switch.on::after {
  transform: translateX(20px);
  background: #fff;
}

.destination-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.destination-row:last-child { border-bottom: none; }
.platform-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.platform-icon.youtube { background: rgba(255,0,0,0.12); }
.platform-icon.facebook { background: rgba(24,119,242,0.12); }
.platform-icon.twitch { background: rgba(145,71,255,0.12); }
.platform-icon.custom { background: rgba(139,145,167,0.12); }
.destination-info { flex: 1; min-width: 0; }
.destination-name { font-weight: 600; font-size: 0.92rem; }
.destination-url { color: var(--text-dim); font-size: 0.78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: calc(100vh - 70px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 4px; font-size: 1.4rem; text-align: center; }
.login-card .sub { text-align: center; color: var(--text-dim); font-size: 0.88rem; margin-bottom: 24px; }
.error-msg {
  background: rgba(255,59,92,0.12);
  border: 1px solid rgba(255,59,92,0.3);
  color: #ff8fa3;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.85rem;
  margin-bottom: 16px;
}

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; margin-top: 16px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { color: var(--text-dim); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.5px; }
tr:hover td { background: rgba(255,255,255,0.02); }
code {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.82rem;
  color: var(--accent);
}

/* ---------- Section ---------- */
.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 40px 0 14px;
  display: flex; align-items: center; gap: 10px;
}

/* ---------- Watch page ---------- */
.player-wrap {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
video { width: 100%; display: block; aspect-ratio: 16/9; background: #000; }
.offline-note {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-dim);
}

.select-wrap { max-width: 340px; margin-bottom: 24px; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row code { flex: 1; overflow-x: auto; white-space: nowrap; }

.error-page {
  max-width: 480px;
  margin: 80px auto;
  text-align: center;
  color: var(--text-dim);
}
