:root {
  color-scheme: dark;
  --bg: #111; --panel: #1b1b1b; --line: #2c2c2c; --text: #eee; --muted: #9a9a9a;
  --green: #1b8a3a; --red: #c0392b; --accent: #2d6cdf;
  --nav: 56px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 18px; margin: 0 0 4px; line-height: 1.3; }
h3 { font-size: 13px; margin: 24px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.grow { flex: 1; min-width: 0; }
svg { width: 24px; height: 24px; display: block; }

.view { max-width: 760px; margin: 0 auto; padding-bottom: calc(var(--nav) + env(safe-area-inset-bottom) + 16px); min-height: 100vh; }
.pad { padding: 12px 16px; }

/* Header bar */
.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; padding: 10px 8px 10px 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
.bar #updated { font-size: 13px; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; }
.icon:active { background: var(--panel); }
.icon.on { color: #6ea2ff; }

#ptr { height: 0; overflow: hidden; display: grid; place-items: center; font-size: 14px; }
.status { padding: 10px 16px; font-size: 14px; }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }

/* Video cards */
.card { display: flex; gap: 12px; padding: 10px 16px; }
.card:active { background: var(--panel); }
.thumb { position: relative; flex: 0 0 42%; max-width: 220px; aspect-ratio: 16 / 9; background: #000; border-radius: 8px; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dur { position: absolute; right: 4px; bottom: 4px; padding: 1px 5px; border-radius: 4px; background: rgba(0,0,0,.8); font-size: 12px; font-variant-numeric: tabular-nums; }
.prog { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--red); }
.meta { min-width: 0; flex: 1; }
.title { font-size: 15px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.sub { font-size: 13px; color: var(--muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card.watched { opacity: .4; }

/* Channel rows (search) */
.chan { display: flex; align-items: center; gap: 12px; padding: 10px 16px; width: 100%; text-align: left; }
.chan img { width: 48px; height: 48px; border-radius: 50%; background: #000; flex: none; }
.listhead { padding: 12px 16px 4px; font-weight: 600; }

/* Bottom nav */
#nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; height: calc(var(--nav) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--bg); border-top: 1px solid var(--line); }
#nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); }
#nav a.on { color: var(--text); }

/* Video view */
#stage { position: sticky; top: 0; z-index: 4; width: 100%; aspect-ratio: 16 / 9; max-height: 60vh; background: #000; }
#stage iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
#stage:fullscreen { width: 100vw; height: 100vh; max-height: none; aspect-ratio: auto; }
#skip { position: absolute; right: 12px; bottom: 64px; z-index: 2; display: none; padding: 10px 14px; border-radius: 8px; background: #fff; color: #111; font-weight: 600; }
#exitfs { position: absolute; right: 12px; top: 56px; z-index: 2; display: none; padding: 8px 12px; border-radius: 8px; background: rgba(0,0,0,.6); color: #fff; }
#stage:fullscreen #exitfs { display: block; }
.channel { font-weight: 600; }
.actions { display: flex; gap: 6px; margin: 14px 0 8px; overflow-x: auto; scrollbar-width: none; }
.actions::-webkit-scrollbar { display: none; }
.act { flex: 1 0 auto; display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 12px; border-radius: 22px; background: var(--panel); font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.act svg { width: 20px; height: 20px; }
.act.up svg { color: var(--green); } .act.down svg { color: var(--red); }
.act.on { outline: 2px solid currentColor; outline-offset: -2px; }
.act.up.on { color: #35c05e; } .act.down.on { color: #e8695b; }
.act.done { color: #6ea2ff; }
.ratio { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; margin-bottom: 10px; }
.ratio.has { background: var(--red); }
.ratio i { display: block; height: 100%; width: 0; background: var(--green); }

.chapters { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.chapters button { display: flex; gap: 12px; padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.chapters button:last-child { border-bottom: 0; }
.chapters button.on { background: var(--panel); }
.chapters time { color: #6ea2ff; font-variant-numeric: tabular-nums; flex: 0 0 auto; min-width: 48px; }

.comment { padding: 10px 0; border-bottom: 1px solid var(--line); }
.comment .who { font-size: 13px; color: var(--muted); margin-bottom: 2px; }
.comment .body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; }
.comment .foot { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* Buttons */
.primary { padding: 12px 20px; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 600; }
.primary:disabled { opacity: .5; }
.plain { padding: 10px 14px; border-radius: 10px; background: var(--panel); white-space: nowrap; flex: none; }
.sheet .plain { background: var(--line); }
.wide { width: 100%; margin-top: 12px; }

/* Search */
.searchbox { position: relative; }
.searchbox input { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: inherit; font: inherit; }
.suggest { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 7; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.suggest button { display: block; width: 100%; padding: 10px 12px; text-align: left; }
.suggest button:active { background: var(--line); }

/* Filter sheet */
#backdrop { position: fixed; inset: 0; z-index: 8; background: rgba(0,0,0,.5); }
.sheet { position: fixed; left: 0; right: 0; z-index: 9; max-width: 760px; margin: 0 auto; max-height: 85vh; overflow-y: auto; background: var(--panel); }
.sheet.bottom { bottom: 0; border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom); animation: rise .18s ease-out; }
.sheet.top { top: 0; border-radius: 0 0 16px 16px; box-shadow: 0 8px 24px rgba(0,0,0,.5); animation: drop .18s ease-out; }
.sheethead { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.sheetbody { padding: 4px 16px 20px; }
@keyframes drop { from { transform: translateY(-100%); } }
@keyframes rise { from { transform: translateY(100%); } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none !important; } }
.sheet h3:first-child { margin-top: 12px; }
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt { padding: 9px 14px; border-radius: 20px; border: 1px solid var(--line); font-size: 14px; }
.opt.on { background: var(--text); color: #111; border-color: var(--text); font-weight: 600; }
.sheetfoot { margin-top: 24px; display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; }

/* Sign-in overlay */
.overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: var(--bg); padding: 24px; }
.signin-box { text-align: center; max-width: 320px; }
.signin-box h1 { font-size: 28px; margin: 12px 0 4px; }
.signin-box p { margin: 0 0 20px; }
.signin-box .muted { margin-top: 16px; font-size: 14px; }

#toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--nav) + env(safe-area-inset-bottom) + 12px); z-index: 30; max-width: 500px; margin: 0 auto; padding: 12px 14px; border-radius: 10px; background: #333; box-shadow: 0 4px 16px rgba(0,0,0,.5); font-size: 14px; text-align: center; }

@media (min-width: 600px) {
  .title { font-size: 16px; }
}

/* Search mode toggle */
.modes { display: flex; gap: 8px; padding: 10px 16px 2px; }
.modes .opt { flex: 1; text-align: center; padding: 9px 6px; white-space: nowrap; }

/* Refresh diagnostics in the filter sheet */
.debug { font-size: 13px; color: var(--muted); line-height: 1.5; overflow-wrap: anywhere; }
.sheetbtns { display: flex; gap: 8px; margin-top: 12px; }
.sheetbtns .plain { flex: 1; }

/* Comment replies */
.replybtn { display: block; padding: 6px 0; font-size: 13px; font-weight: 600; color: #6ea2ff; }
.replies { margin: 2px 0 0 4px; padding-left: 12px; border-left: 2px solid var(--line); }
.replies .comment:last-of-type { border-bottom: 0; }
.sheet p { margin: 0 0 4px; }
.sheetbtns .primary { flex: 1; }
#laterCount { font-size: 13px; text-align: right; }

/* Quota meter */
#meter { flex: 0 0 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

.logo { flex: none; width: 30px; height: 23px; }
