:root {
  --bg: #0f0f0f;
  --surface: #181818;
  --surface-2: #212121;
  --line: #303030;
  --text: #f1f1f1;
  --text-dim: #aaa;
  --text-faint: #717171;
  --accent: #3ea6ff;
  --danger: #ff5252;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 14px/1.45 'Roboto', system-ui, -apple-system, sans-serif;
}
a, a:visited { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }

button {
  border: 0; background: var(--surface-2); color: var(--text);
  padding: 8px 14px; border-radius: 999px; cursor: pointer;
  font: inherit; font-weight: 500;
}
button:hover:not(:disabled) { background: #303030; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: #061018; }
button.primary:hover { background: #65b8ff; }

input, select {
  background: var(--surface-2); border: 1px solid var(--line); color: inherit;
  padding: 9px 12px; border-radius: 6px; font: inherit; width: 100%;
}
input:focus, select:focus { outline: 1px solid var(--accent); border-color: var(--accent); }

.loading { padding: 60px; text-align: center; color: var(--text-dim); }

/* ---- Top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { font-weight: 700; font-size: 18px; letter-spacing: .02em; }
.topbar .brand .accent { color: var(--accent); }
.topbar .spacer { flex: 1; }
.topbar .search { max-width: 520px; flex: 1; display: flex; }
.topbar .search input { border-radius: 999px 0 0 999px; border-right: 0; }
.topbar .search button { border-radius: 0 999px 999px 0; padding: 9px 16px; background: var(--surface-2); }

/* ---- Layout ---- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: calc(100vh - 57px); }
.sidebar {
  border-right: 1px solid var(--line); padding: 12px 0;
  position: sticky; top: 57px; align-self: start; height: calc(100vh - 57px);
  overflow-y: auto;
}
.sidebar .section-title {
  font-size: 11px; text-transform: uppercase; color: var(--text-faint);
  padding: 12px 20px 6px;
}
.sidebar a {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 20px; font-size: 14px; color: var(--text);
}
.sidebar a:hover { background: var(--surface); color: var(--text); }
.sidebar a.active { background: var(--surface-2); }
.sidebar .count { color: var(--text-faint); font-size: 12px; margin-left: auto; }

.content { padding: 20px 24px 60px; min-width: 0; }

/* ---- Cards (home / channel grids) ---- */
.section h2 { font-size: 16px; font-weight: 600; margin: 8px 0 12px; }
.grid {
  display: grid; gap: 18px 14px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.card { display: flex; flex-direction: column; }
.card .thumb {
  aspect-ratio: 16/9; background: var(--surface-2); border-radius: 10px;
  overflow: hidden; position: relative;
}
.card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .duration {
  position: absolute; right: 6px; bottom: 6px;
  background: rgba(0,0,0,.8); color: #fff; padding: 1px 6px; border-radius: 4px;
  font-size: 11px; font-weight: 500;
}
.card .meta { padding: 10px 2px 0; }
.card .title {
  font-size: 14px; font-weight: 500;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; line-height: 1.3; max-height: 2.6em;
}
.card .sub { color: var(--text-dim); font-size: 12px; margin-top: 4px; }

.card-empty { color: var(--text-dim); padding: 60px 20px; text-align: center; }

/* ---- Video page ---- */
.video-page { display: grid; grid-template-columns: 1fr 360px; gap: 24px; max-width: 1600px; }
.video-page .player video { width: 100%; max-height: 70vh; background: #000; border-radius: 12px; }
.video-page .player .player-error {
  background: var(--surface-2); padding: 40px; border-radius: 12px;
  text-align: center; color: var(--danger);
}
.video-page h1 { font-size: 20px; font-weight: 600; margin: 14px 0 8px; }
.video-page .row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--line); padding-bottom: 14px; margin-bottom: 14px;
}
.video-page .channel-pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); border-radius: 999px; padding: 6px 14px;
  font-weight: 500;
}
.video-page .stats { color: var(--text-dim); font-size: 13px; }
.video-page .actions { margin-left: auto; display: flex; gap: 8px; }
.video-page .description {
  background: var(--surface); border-radius: 12px; padding: 14px 18px;
  white-space: pre-wrap; word-break: break-word;
  max-height: 220px; overflow: hidden; position: relative; cursor: pointer;
  transition: max-height .2s;
}
.video-page .description.expanded { max-height: none; }
.video-page .description .fade {
  position: absolute; left: 0; right: 0; bottom: 0; height: 60px;
  background: linear-gradient(to bottom, transparent, var(--surface));
  pointer-events: none;
}
.video-page .description.expanded .fade { display: none; }
.video-page .desc-meta { color: var(--text-dim); font-size: 13px; margin-bottom: 10px; }
.video-page .desc-meta strong { color: var(--text); }

.related h3 { font-size: 14px; font-weight: 500; margin: 4px 0 10px; color: var(--text-dim); }
.related .item { display: flex; gap: 10px; margin-bottom: 10px; }
.related .item .thumb {
  flex: 0 0 168px; aspect-ratio: 16/9; border-radius: 8px; overflow: hidden;
  background: var(--surface-2); position: relative;
}
.related .item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.related .item .info { min-width: 0; flex: 1; }
.related .item .t {
  font-size: 13px; line-height: 1.3; max-height: 2.6em; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.related .item .s { color: var(--text-dim); font-size: 12px; margin-top: 4px; }

@media (max-width: 1100px) {
  .video-page { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}

/* ---- Login ---- */
.login {
  max-width: 380px; margin: 80px auto; background: var(--surface);
  padding: 28px; border-radius: 12px;
}
.login h1 { margin: 0 0 6px; font-size: 22px; }
.login p { color: var(--text-dim); margin: 0 0 18px; font-size: 13px; }
.login label { font-size: 12px; color: var(--text-dim); display: block; margin: 12px 0 4px; }
.login button { width: 100%; margin-top: 16px; }
.login .err { color: var(--danger); font-size: 13px; margin-top: 10px; }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface-2); color: var(--text);
  padding: 12px 20px; border-radius: 8px;
  border: 1px solid var(--line); z-index: 100;
  box-shadow: 0 4px 18px rgba(0,0,0,.4);
  max-width: 80vw;
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.hidden { display: none; }
