:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-alt: #efefec;
  --hover: rgba(0, 0, 0, 0.05);
  --selected: rgba(0, 0, 0, 0.09);
  --border: rgba(0, 0, 0, 0.1);
  --text: #1c1c1a;
  --text-2: #5f5e5a;
  --text-3: #8b8a85;
  --accent: #2563eb;
  --accent-bg: #e3edfd;
  --accent-text: #1a4fbf;
  --on-accent: #ffffff;
  --danger: #c0392b;
  --radius: 8px;
  --sidebar-w: 300px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161615;
    --surface: #1f1f1e;
    --surface-alt: #2a2a28;
    --hover: rgba(255, 255, 255, 0.06);
    --selected: rgba(255, 255, 255, 0.11);
    --border: rgba(255, 255, 255, 0.1);
    --text: #ececea;
    --text-2: #b4b2a9;
    --text-3: #85847e;
    --accent: #5b8def;
    --accent-bg: #1c2b4a;
    --accent-text: #a9c4fa;
    --on-accent: #0b1322;
    --danger: #f08070;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }

.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); height: 100vh; }

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-height: 0;
  padding: 12px 10px 0;
}
.sidebar-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; padding: 0 4px; }
.brand { font-weight: 600; font-size: 15px; }
.head-actions { margin-left: auto; display: flex; gap: 6px; }
.status { font-size: 12px; color: var(--text-3); min-height: 18px; padding: 6px 6px 2px; }
.status.error { color: var(--danger); }
.channel-list { overflow-y: auto; flex: 1; padding-bottom: 12px; }
.section-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-3); padding: 10px 8px 4px; }
.channel {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 6px 8px; border: 0; border-radius: var(--radius);
  background: transparent; text-align: left;
}
.channel:hover { background: var(--hover); }
.channel.active { background: var(--selected); }
.channel.has-new { background: var(--accent-bg); color: var(--accent-text); font-weight: 600; }
.channel.has-new.active { box-shadow: inset 0 0 0 1.5px var(--accent); }
.channel .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 26px; height: 26px; border-radius: 50%; flex: none; background: var(--surface-alt); object-fit: cover; }
.badge { background: var(--accent); color: var(--on-accent); font-size: 11px; font-weight: 600; border-radius: 10px; padding: 1px 7px; }

/* Controls */
.input {
  width: 100%; height: 34px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--text); font: inherit;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.btn {
  height: 30px; padding: 0 12px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.icon-btn {
  width: 30px; height: 30px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center; font-size: 15px;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toggle { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.toggle button { border: 0; background: var(--surface); padding: 0 12px; height: 32px; }
.toggle button + button { border-left: 1px solid var(--border); }
.toggle button.on { background: var(--selected); font-weight: 600; }

/* Main */
.main { overflow-y: auto; min-width: 0; position: relative; }
.menu-btn { display: none; }
#content { padding: 20px 28px 40px; max-width: 1400px; }
.channel-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.channel-head .avatar { width: 44px; height: 44px; }
.channel-head h1 { font-size: 20px; margin: 0; }
.channel-head .meta { font-size: 12px; color: var(--text-3); }
.channel-head .yt-link { font-size: 12px; color: var(--accent); }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar .input { flex: 1; min-width: 200px; max-width: 460px; }
.toolbar .count { font-size: 12px; color: var(--text-3); }

.empty { color: var(--text-2); padding: 60px 0; text-align: center; }
.empty h2 { color: var(--text); font-size: 18px; margin: 0 0 6px; }
.empty p { margin: 4px 0; }
.empty code { background: var(--surface-alt); padding: 1px 6px; border-radius: 4px; }

/* Videos */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 22px 16px; }
.card .thumb-wrap { position: relative; }
.thumb { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: var(--radius); background: var(--surface-alt); display: block; }
.dur { position: absolute; right: 6px; bottom: 6px; background: rgba(0,0,0,0.8); color: #fff; font-size: 11px; font-weight: 600; padding: 1px 5px; border-radius: 4px; }
.new-tag { position: absolute; left: 6px; top: 6px; background: var(--accent); color: var(--on-accent); font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 4px; }
.card .title { font-weight: 600; margin-top: 8px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .date, .row .date { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.card:hover .title, .row:hover .title { color: var(--accent); }

.list { display: flex; flex-direction: column; }
.row { display: flex; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.row .thumb-wrap { position: relative; width: 168px; flex: none; }
.row .body { min-width: 0; }
.row .title { font-weight: 600; }
.row .desc { font-size: 13px; color: var(--text-2); margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
mark { background: rgba(250, 200, 50, 0.4); color: inherit; border-radius: 2px; }

.more { display: flex; justify-content: center; gap: 10px; padding: 24px 0; color: var(--text-3); font-size: 13px; }

/* Watch page. The three parts are grid children so theater mode can rearrange them
   without moving the player iframe in the DOM (which would restart the video). */
.watch {
  display: grid; gap: 16px 24px;
  grid-template-columns: minmax(0, 1fr) 360px;
  grid-template-areas: "player upnext" "info upnext";
  align-items: start;
}
.player-band { grid-area: player; }
.watch-info { grid-area: info; min-width: 0; }
.upnext { grid-area: upnext; min-width: 0; }
.player-box { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #000; border-radius: 12px; overflow: hidden; }
.player-box iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.player-msg {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 12px;
  align-items: center; justify-content: center; text-align: center; padding: 24px; color: #fff; background: #000;
}
.player-msg[hidden] { display: none; }
.watch-title { font-size: 20px; line-height: 1.3; margin: 0 0 10px; }
.watch-meta { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.watch-meta .date { font-size: 13px; color: var(--text-3); }
.watch-channel { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.watch-channel:hover { color: var(--accent); }
.watch-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.watch-actions .btn { display: inline-flex; align-items: center; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.desc-box {
  margin-top: 14px; padding: 12px 14px; border-radius: var(--radius); background: var(--surface-alt);
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px;
}
.desc-box.collapsed { max-height: 9.5em; overflow: hidden; }
.desc-box a { color: var(--accent); }
.link-btn { border: 0; background: none; padding: 6px 2px; color: var(--text-2); font-weight: 600; font-size: 13px; }
.link-btn:hover { color: var(--text); }
.upnext .section-label { padding: 0 0 8px; }
.up-item { display: flex; gap: 10px; padding: 5px; margin: 0 -5px; border-radius: var(--radius); }
.up-item:hover { background: var(--hover); }
.up-item .thumb-wrap { position: relative; width: 160px; flex: none; }
.up-item .body { min-width: 0; }
.up-item .title { font-size: 13px; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.up-item .date { font-size: 12px; color: var(--text-3); }

/* Theater mode: full-width black band; info and up-next sit side by side underneath */
.app.theater #content { max-width: none; padding-top: 0; }
.app.theater .watch { grid-template-areas: "player player" "info upnext"; }
.app.theater .player-band { background: #000; margin: 0 -28px; }
.app.theater .player-box { width: min(100%, calc((100vh - 110px) * 16 / 9)); margin: 0 auto; border-radius: 0; }

@media (max-width: 1100px) {
  .watch, .app.theater .watch { grid-template-columns: minmax(0, 1fr); grid-template-areas: "player" "info" "upnext"; }
}

/* Drawer mode (narrow screens, or theater mode): the sidebar slides in from the ☰ button */
.app.drawer-mode { grid-template-columns: minmax(0, 1fr); }
.app.drawer-mode .sidebar {
  position: fixed; inset: 0 auto 0 0; width: min(86vw, var(--sidebar-w)); z-index: 10;
  transform: translateX(-100%); transition: transform 0.2s;
}
.app.drawer-mode.drawer-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,0.45); }
.app.drawer-mode .menu-btn { display: inline-flex; position: sticky; top: 10px; margin: 10px 0 10px 16px; z-index: 5; }

@media (max-width: 760px) {
  #content { padding: 0 16px 32px; }
  .app.theater .player-band { margin: 0 -16px; }
  .watch-actions { margin-left: 0; }
  .row .thumb-wrap { width: 120px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); }
}
