/* ============================================================
   LiveTube — YouTube Music–style theme
   Authentic YTM dark/light palette, Roboto, Material chips,
   cards and pills, adapted to a Twitch-style live layout.
   ============================================================ */

:root {
  --font: "Roboto", "Roboto Draft", "Segoe UI", system-ui, -apple-system, sans-serif;

  /* YT Music dark palette */
  --bg: #030303;
  --surface: #212121;
  --surface-raised: #2a2a2a;
  --surface-3: #383838;
  --text: #f1f1f1;
  --text-2: #a7a7a7;
  --line: rgba(255, 255, 255, 0.1);
  --hover: rgba(255, 255, 255, 0.08);
  --chip: rgba(255, 255, 255, 0.1);
  --chip-hover: rgba(255, 255, 255, 0.16);
  --scrim: rgba(0, 0, 0, 0.5);
  --accent: #ff0000;
  --accent-hover: #d90000;
  --on-accent: #ffffff;
  --radius-s: 6px;
  --radius: 10px;
  --radius-l: 14px;
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-lift: 0 8px 24px rgba(0, 0, 0, 0.55);
  --topbar-h: 60px;
}

html[data-theme="light"] {
  --bg: #ffffff;
  --surface: #f9f9f9;
  --surface-2: #f2f2f2;
  --surface-3: #e8e8e8;
  --text: #0f0f0f;
  --text-2: #606060;
  --line: rgba(0, 0, 0, 0.1);
  --hover: rgba(0, 0, 0, 0.06);
  --chip: rgba(0, 0, 0, 0.06);
  --chip-hover: rgba(0, 0, 0, 0.12);
  --scrim: rgba(0, 0, 0, 0.3);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  --shadow-lift: 0 6px 20px rgba(0, 0, 0, 0.18);
}

/* Accent variants (default = YouTube red) */
html[data-accent="red"]    { --accent: #ff0000; --accent-hover: #d90000; }
html[data-accent="blue"]   { --accent: #065fd4; --accent-hover: #0552b8; }
html[data-accent="green"]  { --accent: #2ba640; --accent-hover: #238a35; }
html[data-accent="purple"] { --accent: #9147ff; --accent-hover: #7a35e6; }

/* ── Base ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: dark; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }
img { display: block; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--accent); color: var(--on-accent); }

* { scrollbar-width: thin; scrollbar-color: rgba(128, 128, 128, 0.5) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: rgba(128, 128, 128, 0.45); border-radius: 4px; }
*::-webkit-scrollbar-track { background: transparent; }

/* ── Top bar (YT Music app bar) ────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--topbar-h);
  padding: 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
}

.brand-name {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
}

.brand-name em {
  font-style: normal;
  font-weight: 400;
  color: var(--text-2);
}

/* Search — YTM rounded pill */
.search {
  position: relative;
  flex: 1;
  max-width: 540px;
  margin: 0 auto;
}

.search input {
  width: 100%;
  height: 40px;
  padding: 0 76px 0 16px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  outline: none;
  transition: border-color 0.15s;
}

html[data-theme="light"] .search input { background: var(--surface-2); border-color: transparent; }
.search input::placeholder { color: var(--text-2); }
.search input:focus { border-color: var(--accent); }

.search:focus-within {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
  border-radius: 20px;
}

.search-btn {
  position: absolute;
  right: 4px;
  top: 4px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  color: var(--text-2);
  background: transparent;
  border: none;
  border-radius: 50%;
}

.search-btn:hover { color: var(--text); background: var(--hover); }

.search-kbd {
  position: absolute;
  right: 44px;
  top: 50%;
  transform: translateY(-50%);
  padding: 1px 7px;
  font-size: 11px;
  color: var(--text-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  pointer-events: none;
}

/* Nav action buttons */
.nav-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.nav-icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: 50%;
  transition: background 0.15s;
}

.nav-icon-btn:hover { background: var(--hover); }

#refreshBtn.spin svg { animation: rot 0.8s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

/* Theme dropdown */
.dropdown { position: relative; }

.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 200px;
  padding: 8px;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: var(--radius-s);
}

.dropdown-item:hover { background: var(--hover); }
.dropdown-item[aria-checked="true"] { color: var(--accent); }

.dropdown-sep {
  height: 1px;
  margin: 6px 4px;
  background: var(--line);
}

.dropdown-label {
  padding: 6px 12px 4px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-2);
}

.accent-row {
  display: flex;
  gap: 10px;
  padding: 6px 12px 8px;
}

.accent-dot {
  width: 24px;
  height: 24px;
  padding: 0;
  background: var(--dot);
  border: 2px solid transparent;
  border-radius: 50%;
  transition: transform 0.15s;
}

.accent-dot:hover { transform: scale(1.12); }
.accent-dot[aria-checked="true"] {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--text);
}

/* ── Shell layout ──────────────────────────────────────────── */
.shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: calc(100vh - var(--topbar-h));
}

body.sidebar-collapsed .shell { grid-template-columns: 0 minmax(0, 1fr); }

body.sidebar-collapsed .sidebar {
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
  border-right: 1px solid var(--line);
  transition: opacity 0.2s;
}

.sidebar-head {
  padding: 14px 16px 8px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-2);
}

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 12px;
}

.sidebar-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 2px;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: var(--radius);
}

.sidebar-item:hover { background: var(--hover); }
.sidebar-item.active { background: var(--chip); }
.sidebar-item.active .side-name { color: var(--accent); }

.side-avatar {
  position: relative;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  border-radius: 50%;
}

.side-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.side-name {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.side-cat {
  font-size: 11.5px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.side-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-2);
}

.live-dot {
  width: 7px;
  height: 7px;
  background: var(--accent);
  border-radius: 50%;
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Hovercard */
.hovercard {
  position: absolute;
  left: calc(100% + 8px);
  top: 2px;
  display: none;
  min-width: 220px;
  max-width: 280px;
  padding: 12px 14px;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
}

.sidebar-item:hover .hovercard,
.sidebar-item:focus-visible .hovercard { display: block; }

.hovercard-title {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.hovercard-sub {
  margin: 0;
  font-size: 12px;
  color: var(--text-2);
}

.sidebar-foot {
  padding: 10px 16px;
  border-top: 1px solid var(--line);
}

.sidebar-foot-text {
  font-size: 11px;
  color: var(--text-2);
}

/* ── Main content ──────────────────────────────────────────── */
.content {
  min-width: 0;
  padding: 20px 24px 32px;
}

.stage-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
}

.stage { min-width: 0; }

/* Player */
.player-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #000;
  border-radius: var(--radius-l);
}

.player-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
}

.player-frame.switching { animation: fadeIn 0.3s ease; }

@keyframes fadeIn {
  from { opacity: 0.4; }
  to { opacity: 1; }
}

.player-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 6px;
  text-align: center;
  padding: 24px;
}

.player-empty-mark {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin-bottom: 8px;
  color: var(--text-2);
  background: var(--chip);
  border-radius: 50%;
}

.player-empty-title {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
}

.player-empty-sub {
  margin: 0;
  max-width: 380px;
  font-size: 13px;
  color: var(--text-2);
}

/* Channel info row (under player) */
.chan-info {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 4px 0;
}

.chan-avatar-wrap { position: relative; flex-shrink: 0; }

.chan-avatar {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  font-size: 18px;
  font-weight: 500;
  color: #fff;
  border-radius: 50%;
}

.chan-avatar.is-live {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--on-accent);
  background: var(--accent);
  border-radius: 4px;
}

.live-pill .live-dot { background: var(--on-accent); }

.chan-main {
  flex: 1;
  min-width: 0;
}

.chan-name {
  margin: 0;
  font-size: 19px;
  font-weight: 500;
  line-height: 1.25;
  color: var(--text);
}

.chan-title {
  margin: 2px 0 8px;
  font-size: 13px;
  color: var(--text-2);
}

.chan-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-2);
  background: var(--chip);
  border-radius: 100px;
}

.badge-cat { color: var(--text); }

.chan-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 18px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--on-accent);
  background: var(--accent);
  border: none;
  border-radius: 100px;
  transition: background 0.15s;
}

.btn-primary:hover { background: var(--accent-hover); }

/* ── Chat panel ────────────────────────────────────────────── */
.chat-panel {
  display: flex;
  flex-direction: column;
  height: clamp(420px, calc(100vh - 200px), 720px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  overflow: hidden;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-2);
}

.chat-head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Material-style switch */
.switch {
  position: relative;
  width: 36px;
  height: 16px;
  padding: 0;
  background: var(--chip);
  border: 1px solid var(--line);
  border-radius: 100px;
  transition: background 0.2s;
}

.switch::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 2px;
  width: 14px;
  height: 14px;
  background: var(--text-2);
  border-radius: 50%;
  transform: translateY(-50%);
  transition: transform 0.2s, background 0.2s;
}

.switch[aria-checked="true"] {
  background: color-mix(in srgb, var(--accent) 45%, transparent);
  border-color: transparent;
}

.switch[aria-checked="true"]::after {
  transform: translate(18px, -50%);
  background: var(--accent);
}

.chat-name-edit {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--text-2);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 100px;
}

.chat-name-edit:hover { background: var(--hover); color: var(--text); }

.chat-name-dot {
  width: 7px;
  height: 7px;
  background: var(--accent);
  border-radius: 50%;
}

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
}

.chat-empty {
  padding: 20px 8px;
  font-size: 13px;
  color: var(--text-2);
  text-align: center;
}

.chat-msg {
  padding: 5px 8px;
  margin-bottom: 2px;
  border-radius: var(--radius-s);
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
}

.chat-msg-head {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 1px;
}

.chat-msg-name { font-weight: 500; font-size: 12.5px; }
.chat-msg-time { font-size: 10.5px; color: var(--text-2); }
.chat-msg-text { color: var(--text); }

.chat-msg-sys {
  font-size: 12px;
  font-style: italic;
  color: var(--text-2);
}

.chat-msg-mine { background: var(--chip); }

.chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.chat-form input {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 14px;
  font-size: 13px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 100px;
  outline: none;
}

.chat-form input:focus { border-color: var(--accent); }
.chat-form input::placeholder { color: var(--text-2); }

.chat-send {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  color: var(--on-accent);
  background: var(--accent);
  border: none;
  border-radius: 50%;
  transition: background 0.15s;
}

.chat-send:hover { background: var(--accent-hover); }

/* ── Discover section ──────────────────────────────────────── */
.discover { margin-top: 28px; }

.discover-head { margin-bottom: 14px; }

.discover-title {
  margin: 0;
  font-size: 20px;
  font-weight: 500;
  color: var(--text);
}

.discover-sub {
  margin: 4px 0 14px;
  font-size: 13px;
  color: var(--text-2);
}

/* Chips — YT Music filter chips */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tab {
  height: 32px;
  padding: 0 15px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: var(--chip);
  border: none;
  border-radius: 8px;
  transition: background 0.15s;
}

.tab:hover { background: var(--chip-hover); }

.tab-active {
  background: var(--text) !important;
  color: var(--bg);
}

.tab-count {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  margin-left: 6px;
  padding: 0 5px;
  font-size: 11px;
  font-weight: 700;
  color: var(--on-accent);
  background: var(--accent);
  border-radius: 100px;
}

/* ── Channel cards (Quick-picks style) ─────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 12px;
}

.grid-loading {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 12px;
  width: 100%;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: var(--radius-l);
  transition: background 0.15s;
}

.card:hover { background: var(--surface); }
.card.active { background: var(--chip); }

.card-thumb {
  position: relative;
  display: block;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: var(--radius);
}

.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-initial {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 28px;
  font-weight: 500;
  color: var(--text-2);
}

.card-badges {
  position: absolute;
  left: 8px;
  bottom: 8px;
  display: flex;
  gap: 6px;
}

.card-live-tag {
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--on-accent);
  background: var(--accent);
  border-radius: 4px;
}

.card-offline-tag {
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text);
  background: rgba(0, 0, 0, 0.7);
  border-radius: 4px;
}

.card-viewers-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text);
  background: rgba(0, 0, 0, 0.7);
  border-radius: 4px;
}

.card-viewers-tag .live-dot { animation: none; }

.card-body {
  display: flex;
  gap: 10px;
  padding: 0 4px 4px;
}

.card-avatar {
  position: relative;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  font-size: 15px;
  font-weight: 500;
  color: #fff;
  border-radius: 50%;
  overflow: hidden;
}

.card-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.card-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-cat {
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Empty state */
.empty {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  justify-items: center;
  gap: 6px;
  padding: 48px 24px;
  text-align: center;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: 6px;
  color: var(--text-2);
  background: var(--chip);
  border-radius: 50%;
}

.empty-title {
  margin: 0;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}

.empty-desc {
  margin: 0;
  max-width: 400px;
  font-size: 13px;
  color: var(--text-2);
}

/* Skeletons */
.skeleton {
  background: linear-gradient(
    100deg,
    var(--surface-2) 40%,
    var(--surface-3) 50%,
    var(--surface-2) 60%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

.skel-card {
  display: block;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
}

/* ── Footer ────────────────────────────────────────────────── */
.foot {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 20px 24px;
  font-size: 12px;
  color: var(--text-2);
  border-top: 1px solid var(--line);
}

.foot-sep { opacity: 0.5; }

/* ── Toast ─────────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 200;
  padding: 11px 22px;
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 100px;
  box-shadow: var(--shadow-lift);
  animation: toastIn 0.25s ease;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ── Admin panel ───────────────────────────────────────────── */
.admin-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.admin-wrap {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.admin-wrap .brand { margin-bottom: 4px; }

.admin-card {
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
}

.admin-title {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 500;
  color: var(--text);
}

.admin-sub {
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--text-2);
}

.admin-card form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-card input {
  height: 42px;
  padding: 0 14px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
}

.admin-card input:focus { border-color: var(--accent); }
.admin-card input::placeholder { color: var(--text-2); }

.admin-card form .btn-primary {
  justify-content: center;
  width: 100%;
  height: 42px;
}

.admin-hint {
  margin: 14px 0 0;
  font-size: 12px;
  color: var(--text-2);
}

.admin-list { margin-top: 16px; }

.admin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  background: var(--surface-2);
  border-radius: var(--radius);
}

.admin-row-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.admin-row-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.admin-row-meta {
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-danger {
  padding: 7px 16px;
  font-size: 12.5px;
  font-weight: 500;
  color: #ff6b6b;
  background: transparent;
  border: 1px solid rgba(255, 107, 107, 0.4);
  border-radius: 100px;
  transition: background 0.15s;
}

.btn-danger:hover { background: rgba(255, 107, 107, 0.12); }

/* ── Theater mode ──────────────────────────────────────────── */
body.theater .shell { grid-template-columns: minmax(0, 1fr); }
body.theater .sidebar { display: none; }
body.theater .stage-row { grid-template-columns: minmax(0, 1fr); }
body.theater .chat-panel { display: none; }
body.theater .player-frame {
  aspect-ratio: auto;
  height: min(76vh, 900px);
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 1400px) {
  .stage-row { grid-template-columns: minmax(0, 1fr) 300px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .grid-loading { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}

@media (max-width: 1200px) {
  .shell { grid-template-columns: 220px minmax(0, 1fr); }
  .content { padding: 16px 18px 28px; }
  .search { max-width: 460px; }
}

@media (max-width: 1024px) {
  .stage-row { grid-template-columns: minmax(0, 1fr); }
  .chat-panel { height: 440px; }
  .discover { margin-top: 22px; }
}

@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }

  /* Sidebar becomes an off-canvas drawer */
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    width: 290px;
    max-width: 84vw;
    z-index: 150;
    background: var(--bg);
    box-shadow: var(--shadow-lift);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    visibility: hidden;
  }

  /* Burger toggles .sidebar-collapsed — on mobile, absent class = open */
  body:not(.sidebar-collapsed) .sidebar {
    transform: translateX(0);
    visibility: visible;
  }

  /* Dimmed backdrop behind the drawer */
  body:not(.sidebar-collapsed)::after {
    content: "";
    position: fixed;
    inset: var(--topbar-h) 0 0 0;
    z-index: 140;
    background: var(--scrim);
  }

  .search { max-width: none; }
  .content { padding: 16px 14px 24px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .grid-loading { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .discover-title { font-size: 18px; }
}

@media (max-width: 640px) {
  .topbar { height: 52px; padding: 0 10px; gap: 8px; }
  :root { --topbar-h: 52px; }
  .nav-icon-btn { width: 36px; height: 36px; }
  .search input { height: 38px; padding-right: 44px; }
  .search-btn { top: 3px; }
  .search-kbd { display: none; }
  .brand-mark { width: 28px; height: 28px; }

  .content { padding: 12px 10px 20px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 10px; }
  .grid-loading { grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 10px; }
  .card { padding: 6px; gap: 8px; }
  .card-body { padding: 0 2px 2px; gap: 8px; }
  .card-avatar { width: 32px; height: 32px; font-size: 13px; }
  .card-name { font-size: 13px; }
  .card-cat { font-size: 11px; }

  .chan-info { flex-wrap: wrap; gap: 12px; padding-top: 14px; }
  .chan-name { font-size: 17px; }
  .chan-actions { width: 100%; justify-content: flex-end; }

  .chat-panel { height: 400px; }
  .chat-head { padding: 10px 12px; }
  .chat-name-edit { padding: 3px 8px; }

  .foot { padding: 16px 12px; flex-direction: column; gap: 4px; }
  .foot-sep { display: none; }
}

@media (max-width: 420px) {
  .brand-name { display: none; }
  .grid { grid-template-columns: 1fr; }
  .grid-loading { grid-template-columns: 1fr; }
  .player-frame { border-radius: var(--radius); }
  .btn-primary { padding: 0 12px; font-size: 12.5px; height: 34px; }
  .chan-actions .nav-icon-btn { width: 34px; height: 34px; }
}

/* ============================================================
   LiveTube — component additions + responsive pass
   (catalog presets, logo avatars, fluid layout at all widths)
   ============================================================ */

/* Remote logo images layered over the generated initial */
.avatar-initial { position: relative; z-index: 0; }

.avatar-img {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  background: var(--surface-2);
}

.side-avatar,
.chan-avatar { position: relative; overflow: hidden; }

.side-avatar .live-dot {
  position: absolute;
  right: 0;
  bottom: 0;
  z-index: 2;
  border: 2px solid var(--bg);
}

.thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-logo {
  width: 100%;
  height: 100%;
  padding: 16%;
  object-fit: contain;
  background: var(--surface-2);
}

.sidebar-empty {
  padding: 16px;
  font-size: 13px;
  color: var(--text-2);
}

/* Preset chips scroll horizontally on narrow screens */
.tabs {
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* Safe-area aware chrome (iPhone notch / home indicator) */
.topbar {
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

.content {
  padding-left: max(24px, env(safe-area-inset-left));
  padding-right: max(24px, env(safe-area-inset-right));
}

.sidebar {
  padding-left: env(safe-area-inset-left);
}

.foot {
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}

/* ── Wide screens ─────────────────────────────────────────── */
@media (min-width: 1600px) {
  .content { padding: 24px 40px 40px; }
  .stage-row { grid-template-columns: minmax(0, 1fr) 360px; gap: 24px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
  .grid-loading { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
}

/* ── Tablet landscape ─────────────────────────────────────── */
@media (max-width: 1180px) {
  .shell { grid-template-columns: 210px minmax(0, 1fr); }
  .content { padding: 18px 16px 28px; }
}

/* ── Tablet portrait ──────────────────────────────────────── */
@media (max-width: 1024px) {
  .stage-row { grid-template-columns: minmax(0, 1fr); }
  .chat-panel { height: min(52vh, 460px); }
  .search { max-width: none; }
}

/* ── Small tablet / large phone: drawer + scrollable chips ── */
@media (max-width: 820px) {
  /* The sidebar is fixed/off-canvas here, so the shell must stay a single
     column even when `sidebar-collapsed` is set (otherwise .content would
     be auto-placed into the 0-width first column). */
  .shell,
  body.sidebar-collapsed .shell { grid-template-columns: minmax(0, 1fr); }

  .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    margin: 0 -14px;
    padding: 0 14px 6px;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: 0 0 auto; }

  .content {
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }
  .sidebar {
    width: min(300px, 86vw);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ── Phone ────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .search input { padding-left: 14px; }
  .search:focus-within { box-shadow: none; }

  .discover { margin-top: 20px; }
  .discover-head { margin-bottom: 10px; }
  .discover-title { font-size: 17px; }

  .stage-row { gap: 14px; }
  .player-frame { border-radius: var(--radius); }
  .chan-actions { flex-wrap: wrap; }
  .chan-actions .btn-primary { flex: 1; justify-content: center; }

  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .grid-loading { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }

  .chat-panel { height: min(58vh, 420px); }
}

/* ── Small phone: 2-up grid, edge-to-edge player ──────────── */
@media (max-width: 480px) {
  .topbar { gap: 6px; }
  .brand-name { font-size: 16px; }

  .stage { margin: 0 calc(-1 * max(12px, env(safe-area-inset-left))); }
  .player-frame { border-radius: 0; }
  .chan-info { padding: 12px max(12px, env(safe-area-inset-left)) 0; }

  .grid,
  .grid-loading { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }

  .card { padding: 5px; gap: 6px; border-radius: var(--radius); }
  .card-body { padding: 0 1px 1px; gap: 7px; }
  .card-avatar { width: 30px; height: 30px; font-size: 12px; }
  .card-name { font-size: 12.5px; }
  .card-cat { font-size: 10.5px; }
  .card-live-tag,
  .card-offline-tag,
  .card-viewers-tag { font-size: 10px; padding: 2px 6px; }

  .chat-panel { height: 56vh; }
}

/* ── Very small phone (320–360) ───────────────────────────── */
@media (max-width: 360px) {
  .brand-mark { width: 26px; height: 26px; }
  .nav-icon-btn { width: 34px; height: 34px; }
  .grid,
  .grid-loading { grid-template-columns: minmax(0, 1fr); }
  .tab { height: 30px; padding: 0 12px; font-size: 12.5px; }
}

/* Respect reduced-motion preferences */
@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;
  }
  .live-dot { animation: none; }
}

.sidebar-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-foot-links a {
  color: var(--text-2);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.sidebar-foot-links a:hover { color: var(--accent); }

/* Prevent long channel names from forcing grid tracks wider than the viewport */
.card,
.card-thumb,
.card-body,
.card-main { min-width: 0; }

.card-thumb { width: 100%; }

/* ============================================================
   Discover tools, live toggle, unmute, card hover — polish
   ============================================================ */

.discover-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
}

.filter-wrap {
  position: relative;
  flex: 1 1 220px;
  max-width: 380px;
}

.filter-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-2);
  pointer-events: none;
}

.filter-input {
  width: 100%;
  height: 36px;
  padding: 0 14px 0 34px;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 100px;
  outline: none;
  transition: border-color 0.15s;
}

html[data-theme="light"] .filter-input { background: var(--surface-2); border-color: transparent; }
.filter-input::placeholder { color: var(--text-2); }
.filter-input:focus { border-color: var(--accent); }

.chip-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 15px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: var(--chip);
  border: 1px solid transparent;
  border-radius: 100px;
  transition: background 0.15s, color 0.15s;
}

.chip-toggle:hover { background: var(--chip-hover); }
.chip-toggle .live-dot { background: var(--text-2); animation: none; }
.chip-toggle[aria-checked="true"] { color: var(--on-accent); background: var(--accent); }
.chip-toggle[aria-checked="true"] .live-dot {
  background: var(--on-accent);
  animation: pulse 1.6s ease-in-out infinite;
}

/* Unmute overlay (default Lofi Girl autoplays muted) */
.unmute-btn {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: rgba(0, 0, 0, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 100px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fadeIn 0.25s ease;
}

.unmute-btn:hover { background: rgba(0, 0, 0, 0.88); }

/* Card hover: dim + centered play affordance */
.card { transition: background 0.15s, transform 0.15s; }
.card:hover { transform: translateY(-2px); }

.card-thumb::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: radial-gradient(circle at center, rgba(0, 0, 0, 0.38), rgba(0, 0, 0, 0.04) 62%);
  opacity: 0;
  transition: opacity 0.18s;
  pointer-events: none;
}

.card-thumb::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  width: 46px;
  height: 46px;
  transform: translate(-50%, -50%) scale(0.8);
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M8 5.5l11 6.5-11 6.5z' fill='%23fff'/%3E%3C/svg%3E") center / 22px no-repeat;
  border-radius: 50%;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transition: opacity 0.18s, transform 0.18s;
  pointer-events: none;
}

.card:hover .card-thumb::before,
.card:focus-visible .card-thumb::before { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.card:hover .card-thumb::after,
.card:focus-visible .card-thumb::after { opacity: 1; }

/* Thumbnails fade in as they load */
.card-thumb img { transition: opacity 0.25s; }
.card-thumb img:not([src]) { opacity: 0; }

@media (max-width: 480px) {
  .filter-wrap { flex: 1 1 100%; max-width: none; }
  .chip-toggle { height: 34px; }
}

/* ============================================================
   Floating jump button + keyboard shortcuts modal
   ============================================================ */

.jump-btn {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 180;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  color: var(--on-accent);
  background: var(--accent);
  border: none;
  border-radius: 50%;
  box-shadow: var(--shadow-lift);
  animation: fadeIn 0.2s ease;
}

.jump-btn:hover { background: var(--accent-hover); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--scrim);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fadeIn 0.15s ease;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  padding: 20px 22px;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-lift);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-title { margin: 0; font-size: 17px; font-weight: 500; }

.shortcuts {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.shortcuts li {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 4px;
  font-size: 14px;
  color: var(--text);
  border-bottom: 1px solid var(--line);
}

.shortcuts li:last-child { border-bottom: none; }

.shortcuts kbd {
  min-width: 34px;
  text-align: center;
  padding: 3px 9px;
  font-size: 12px;
  font-family: inherit;
  color: var(--text-2);
  background: var(--chip);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.chip-toggle svg { opacity: 0.9; }
