:root {
  --bg: #f6f6f7;
  --panel: #ffffff;
  --text: #17181a;
  --muted: #62656b;
  --border: #dcdde0;
  --accent: #d92b2b;
  --accent-text: #ffffff;
  --started: #e3a008;
  --finished: #1f9d55;
  --chip: #ececee;
  --yt-track: #909090;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f10;
    --panel: #1b1b1d;
    --text: #ececee;
    --muted: #9a9ca2;
    --border: #2f3034;
    --accent: #ff4e45;
    --chip: #2a2b2e;
    --yt-track: #717171;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: inherit; }
button, input, select {
  font: inherit;
  color: inherit;
}

/* Header */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand .logo { width: 26px; height: 18px; border-radius: 5px; background: var(--accent); position: relative; }
.brand .logo::after {
  content: ""; position: absolute; left: 10px; top: 4.5px;
  border-left: 8px solid #fff; border-top: 4.5px solid transparent; border-bottom: 4.5px solid transparent;
}
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { text-decoration: none; padding: 6px 12px; border-radius: 8px; color: var(--muted); }
.topbar nav a.active, .topbar nav a:hover { background: var(--chip); color: var(--text); }
.topbar .spacer { flex: 1; }
.sync-status { color: var(--muted); font-size: 13px; }
.app-version { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Buttons & inputs */
.btn {
  border: 1px solid var(--border); background: var(--panel);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-block;
}
.btn:hover { background: var(--chip); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.small { padding: 3px 9px; font-size: 12px; }
input[type=text], input[type=search], input[type=number], input[type=password], select, textarea {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
}
textarea { width: 100%; font: 13px/1.4 ui-monospace, Consolas, monospace; color: var(--text); }

/* Browse layout */
.layout { display: grid; grid-template-columns: 260px 1fr; gap: 20px; padding: 20px; max-width: 1800px; margin: 0 auto; }
.filters {
  position: sticky; top: 72px; align-self: start;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px;
  display: flex; flex-direction: column; gap: 16px;
  max-height: calc(100vh - 92px); overflow: auto;
}
.filters h3 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.filters input[type=search], .filters select { width: 100%; }
.row { display: flex; gap: 8px; align-items: center; }
.row input[type=number] { width: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--chip); cursor: pointer; user-select: none; border: 1px solid transparent; }
.chip input { display: none; }
.chip:has(input:checked) { background: var(--text); color: var(--bg); }
.check { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.unwatched { background: var(--muted); }
.dot.started { background: var(--started); }
.dot.finished { background: var(--finished); }

.results-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.results-head .count { color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; }

/* Video card */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.thumb { position: relative; display: block; aspect-ratio: 16 / 9; background: var(--chip); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card.finished .thumb img { opacity: 0.55; }
.badge { position: absolute; right: 6px; bottom: 8px; background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 12px; font-weight: 600; padding: 1px 4px; border-radius: 4px; }
.badge.left { left: 6px; right: auto; top: 6px; bottom: auto; }
.badge.finished { background: var(--finished); }
.badge.started { background: var(--started); color: #111; }
/* Bottom row of the thumbnail, matching youtube.com: a rounded progress bar
   that runs up to the duration badge. */
.thumb-bottom { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: flex-end; justify-content: flex-end; }
.thumb-bottom .badge { position: static; margin: 0 8px 8px 0; }
.bar { flex: 1; height: 4px; margin: 0 4px 12px 8px; border-radius: 2px; background: var(--yt-track); overflow: hidden; display: flex; }
.bar > div { background: linear-gradient(90deg, #f03 80%, #ff2791); }
.card .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.card .title { font-weight: 600; text-decoration: none; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .title:hover { text-decoration: underline; }
.card .meta { color: var(--muted); font-size: 13px; }
.card .meta a { text-decoration: none; }
.card .meta a:hover { text-decoration: underline; }
.card .actions { display: flex; gap: 6px; margin-top: auto; padding-top: 8px; flex-wrap: wrap; }

.empty { padding: 60px 20px; text-align: center; color: var(--muted); background: var(--panel); border: 1px dashed var(--border); border-radius: 12px; }
.more { display: flex; justify-content: center; margin: 24px 0; }

/* Settings */
.page { max-width: 900px; margin: 0 auto; padding: 24px 20px 60px; display: flex; flex-direction: column; gap: 20px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; }
.panel h2 { margin: 0 0 4px; font-size: 18px; }
.panel h3 { margin: 18px 0 6px; font-size: 15px; }
.panel p, .panel li { color: var(--muted); }
.panel p strong, .panel li strong { color: var(--text); }
.field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }
.field input[type=text], .field input[type=password] { width: 100%; }
.msg { margin-top: 8px; font-size: 13px; white-space: pre-wrap; }
.msg.ok { color: var(--finished); }
.msg.err { color: var(--accent); }
details summary { cursor: pointer; font-weight: 600; }
table { width: 100%; border-collapse: collapse; }
td, th { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
td img { width: 28px; height: 28px; border-radius: 50%; vertical-align: middle; }
code { background: var(--chip); padding: 1px 5px; border-radius: 4px; }

/* Watch */
.watch { max-width: 1200px; margin: 0 auto; padding: 20px; }
.player-wrap { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: 12px; overflow: hidden; }
.player-wrap > div, .player-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; }
.watch h1 { font-size: 20px; margin: 14px 0 4px; }
.watch .meta { color: var(--muted); }
.watch .actions { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; align-items: center; }
.watch .desc { white-space: pre-wrap; color: var(--muted); background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; padding: 12px; }
  .filters { position: static; max-height: none; }
  .topbar { padding: 10px 12px; gap: 10px; flex-wrap: wrap; }
}

/* Channels page */
.channels-page { max-width: 760px; gap: 12px; }
.channels-head { display: flex; gap: 12px; align-items: center; }
.channels-head input { flex: 1; font-size: 15px; padding: 9px 12px; }
.channels-head .count { color: var(--muted); white-space: nowrap; }
.letters {
  position: sticky; top: 57px; z-index: 5;
  display: flex; flex-wrap: wrap; gap: 2px; padding: 6px 0;
  background: var(--bg);
}
.letters a, .letters span { min-width: 24px; text-align: center; padding: 2px 4px; border-radius: 6px; font-weight: 600; text-decoration: none; }
.letters a:hover { background: var(--chip); }
.letters span { color: var(--border); }
.letter-group h2 { margin: 14px 0 6px; font-size: 14px; color: var(--muted); scroll-margin-top: 110px; }
.channel-list { list-style: none; margin: 0; padding: 0; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.channel-list li + li { border-top: 1px solid var(--border); }
.channel-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; text-decoration: none; }
.channel-row:hover { background: var(--chip); }
.channel-row img, .channel-row .avatar { width: 40px; height: 40px; border-radius: 50%; flex: none; background: var(--chip); }
.channel-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.channel-text .meta, .channel-row > .meta { color: var(--muted); font-size: 13px; }
.chev { color: var(--muted); font-size: 22px; }

/* Single-channel view on the Browse page */
.channel-banner { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; padding: 14px 16px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; }
.channel-banner img { width: 56px; height: 56px; border-radius: 50%; }
.channel-banner h1 { margin: 0; font-size: 20px; }
.channel-banner .meta { color: var(--muted); font-size: 13px; }
.channel-banner .grow { flex: 1; min-width: 200px; }
.channel-banner .actions { display: flex; gap: 8px; flex-wrap: wrap; }
