:root {
  --bg: #0f0f0f;
  --bg-elev: #1f1f1f;
  --bg-elev-2: #272727;
  --text: #f1f1f1;
  --text-muted: #aaa;
  --text-faint: #717171;
  --accent: #ff0033;
  --accent-hover: #ff3355;
  --border: #303030;
  --hover: #272727;
  --topbar-h: 56px;
  --sidebar-w: 240px;
  --sidebar-w-collapsed: 0px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --font: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f9f9f9;
    --bg-elev: #fff;
    --bg-elev-2: #f1f1f1;
    --text: #0f0f0f;
    --text-muted: #606060;
    --text-faint: #909090;
    --border: #e5e5e5;
    --hover: #f1f1f1;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  }
}

* { box-sizing: border-box; }

html {
  overflow-x: hidden;
}

html, body {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }

/* ── Top bar ───────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 24px;
  height: var(--topbar-h);
  padding: 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.topbar-left { display: flex; align-items: center; gap: 8px; }
.topbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--text);
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s;
}
.icon-btn:hover { background: var(--hover); }

.logo {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  letter-spacing: -1.2px;
  font-size: 20px;
}
.logo-mark { display: inline-flex; align-items: center; }
.logo-text { color: var(--text); }

.search {
  flex: 1;
  max-width: 640px;
  display: flex;
  margin: 0 auto;
}
.search input {
  flex: 1;
  height: 40px;
  padding: 0 16px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-right: none;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  border-radius: 20px 0 0 20px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search input:focus {
  border-color: #3ea6ff;
  box-shadow: inset 0 0 0 1px #3ea6ff;
}
.search button {
  width: 64px;
  height: 40px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  border-radius: 0 20px 20px 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.search button:hover { background: var(--hover); }

/* ── Layout ────────────────────────────────────── */
.layout {
  display: flex;
  align-items: flex-start;
  min-height: calc(100vh - var(--topbar-h));
}

.sidebar {
  position: sticky;
  top: var(--topbar-h);
  width: var(--sidebar-w);
  flex-shrink: 0;
  padding: 12px 12px 80px;
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  scrollbar-width: thin;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.side-link {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 12px;
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  transition: background 0.15s;
}
.side-link:hover { background: var(--hover); }
.side-link.active { background: var(--bg-elev-2); font-weight: 500; }
.side-link svg { flex-shrink: 0; }

.side-divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}

.side-heading {
  padding: 8px 12px 4px;
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.1px;
}

.side-channel { padding: 6px 12px; }
.side-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.side-avatar.placeholder { background: var(--bg-elev-2); }

.side-empty {
  padding: 12px;
  color: var(--text-muted);
  font-size: 13px;
}
.side-empty a { color: #3ea6ff; }

.content {
  flex: 1;
  min-width: 0;
  padding: 24px 40px;
}

@media (max-width: 1024px) {
  .content { padding: 16px 24px; }
}
/* ── Sidebar backdrop (mobile) ─────────────────── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 199;
  backdrop-filter: blur(2px);
}
.sidebar-backdrop.visible { display: block; }

@media (max-width: 768px) {
  .sidebar {
    display: none;
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    width: min(280px, 85vw);
    z-index: 200;
    background: var(--bg-elev);
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .sidebar.open {
    display: block;
    transform: translateX(0);
  }
  .content { padding: 16px; }
  .search { max-width: none; }
}

/* ── Video grid + cards ────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 28px 16px;
}

.card {
  display: flex;
  flex-direction: column;
  color: var(--text);
}
.card:hover .card-thumb img { transform: scale(1.02); }

.card-thumb {
  display: block;
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--bg-elev-2);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s;
}
.card-duration {
  position: absolute;
  bottom: 8px;
  right: 8px;
  padding: 2px 6px;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  border-radius: 4px;
  letter-spacing: 0.2px;
}

.card-body {
  display: flex;
  gap: 12px;
  margin-top: 12px;
}
.card-avatar-link {
  flex-shrink: 0;
  display: block;
  width: 36px;
  height: 36px;
}
.card-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}
.card-avatar.placeholder {
  display: inline-block;
  background: var(--bg-elev-2);
}
.card-meta { flex: 1; min-width: 0; }
.card-title-link { display: block; color: var(--text); }
.card-title {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  letter-spacing: -0.1px;
}
.card-channel {
  display: block;
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  transition: color 0.15s;
}
.card-channel:hover { color: var(--text); }
.card-sub {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Watch page ────────────────────────────────── */
.watch {
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: 24px;
  max-width: 1800px;
  margin: 0 auto;
}
@media (max-width: 1100px) {
  .watch { grid-template-columns: 1fr; }
}

.player {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.player iframe,
.player > div { width: 100% !important; height: 100% !important; border: 0; }
#ytplayer { width: 100%; height: 100%; }

.watch-title {
  font-size: 20px;
  font-weight: 600;
  margin: 16px 0 12px;
  line-height: 1.3;
  letter-spacing: -0.3px;
}

.watch-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.watch-channel {
  display: flex;
  align-items: center;
  gap: 12px;
}
.watch-channel img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}
.watch-channel-name { margin: 0; font-weight: 500; font-size: 15px; }
.watch-channel-sub { margin: 2px 0 0; font-size: 13px; color: var(--text-muted); }

.watch-stats { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  background: var(--bg-elev-2);
  border-radius: 18px;
  font-size: 14px;
  font-weight: 500;
}

.watch-description {
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--bg-elev-2);
  border-radius: var(--radius-sm);
  max-height: 200px;
  overflow-y: auto;
}
.watch-description pre {
  margin: 0;
  font-family: inherit;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 13.5px;
  color: var(--text-muted);
}

.watch-side-title { margin: 0 0 12px; font-size: 16px; font-weight: 500; }
.sug {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.sug:hover { background: var(--hover); }
.sug-thumb {
  position: relative;
  width: 168px;
  flex-shrink: 0;
  aspect-ratio: 16 / 9;
  background: var(--bg-elev-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.sug-thumb img { width: 100%; height: 100%; object-fit: cover; }
.sug-body { flex: 1; min-width: 0; }
.sug-body h4 {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.sug-body p { margin: 0; font-size: 12px; color: var(--text-muted); }
.sug-sub { margin-top: 2px !important; }

/* ── Channel page ──────────────────────────────── */
.channel-header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 16px 0 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.channel-avatar {
  width: 128px;
  height: 128px;
  border-radius: 50%;
  object-fit: cover;
}
.channel-header h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }
.channel-handle { margin: 4px 0; color: var(--text-muted); font-size: 14px; }
.channel-stats { margin: 4px 0 0; color: var(--text-muted); font-size: 14px; }

.page-title {
  margin: 0 0 24px;
  font-size: 20px;
  font-weight: 600;
}

/* ── Empty / alerts ────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 80px 24px;
}
.empty-state h2 {
  font-size: 22px;
  margin: 0 0 8px;
  font-weight: 600;
}
.empty-state p { color: var(--text-muted); }
.empty-state a { color: #3ea6ff; }

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 14px;
}
.alert-error {
  background: rgba(255, 80, 80, 0.15);
  border: 1px solid rgba(255, 80, 80, 0.4);
  color: #ff8888;
}
.alert-ok {
  background: rgba(80, 220, 100, 0.12);
  border: 1px solid rgba(80, 220, 100, 0.4);
  color: #76e093;
}

/* ── Admin ─────────────────────────────────────── */
.admin {
  max-width: 760px;
  margin: 0 auto;
}
.admin h1 {
  margin: 0 0 24px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.admin-section {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}
.admin-section h2 {
  margin: 0 0 16px;
  font-size: 17px;
  font-weight: 600;
}
.admin-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.admin-section-head h2 { margin: 0; }

.admin-form {
  display: flex;
  gap: 8px;
}
.admin-form input {
  flex: 1;
  height: 40px;
  padding: 0 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.admin-form input:focus { border-color: #3ea6ff; }

.admin-form button,
.admin-section-head button {
  height: 40px;
  padding: 0 18px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
  font-size: 14px;
}
.admin-form button:hover { background: var(--accent-hover); }

.admin-section-head button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.admin-section-head button.ghost:hover { background: var(--hover); }

.admin-hint {
  margin: 10px 0 0;
  font-size: 12.5px;
  color: var(--text-faint);
}
.admin-hint code {
  font-family: 'SF Mono', 'Monaco', 'Cascadia Code', monospace;
  font-size: 12px;
  background: var(--bg-elev-2);
  padding: 1px 6px;
  border-radius: 4px;
}

.admin-empty {
  margin: 0;
  color: var(--text-muted);
  text-align: center;
  padding: 24px;
}

.admin-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.admin-list li {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}
.admin-list li:first-child { border-top: none; }
.admin-list img,
.admin-list .placeholder {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.admin-channel-info { flex: 1; min-width: 0; }
.admin-channel-info strong { font-size: 15px; }
.admin-channel-info a:hover strong { color: #3ea6ff; }
.admin-handle, .admin-subs, .admin-id {
  display: inline-block;
  margin-left: 8px;
  font-size: 12.5px;
  color: var(--text-muted);
}
.admin-id {
  font-family: 'SF Mono', 'Monaco', monospace;
  color: var(--text-faint);
  font-size: 11.5px;
}

button.danger {
  height: 36px;
  padding: 0 14px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  transition: all 0.15s;
}
button.danger:hover {
  background: rgba(255, 80, 80, 0.15);
  border-color: rgba(255, 80, 80, 0.5);
  color: #ff8888;
}
