:root {
  --bg: #0b0b0b;
  --panel: #121212;
  --card: #181818;
  --line: #262626;
  --text: #f3f3f3;
  --muted: #9d9d9d;
  --accent: #ff0033;
  --sb: #f9a825;
  --shadow: none;
  --hover: #212121;
}
html[data-theme="light"] {
  --bg: #f5f5f6;
  --panel: #ffffff;
  --card: #ffffff;
  --line: #e2e2e5;
  --text: #18181b;
  --muted: #616166;
  --accent: #e0002a;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --hover: #eeeeef;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
button { font-family: inherit; }

html { accent-color: var(--accent); }
::selection { background: rgba(255, 0, 51, 0.4); }
*:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 4px; }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
html[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #2e2e2e; border-radius: 6px; border: 2px solid var(--bg); }
html[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: #3f3f3f; }
html[data-theme="light"] ::-webkit-scrollbar-thumb { background: #c9c9cd; border-radius: 6px; border: 2px solid var(--bg); }
html[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: #b3b3b8; }
input:-webkit-autofill { -webkit-box-shadow: 0 0 0 1000px var(--panel) inset; -webkit-text-fill-color: var(--text); }

/* ---------- header ---------- */
header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 18px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; flex: none; }
.name { font-weight: 700; font-size: 1.08rem; letter-spacing: 0.2px; }
.name .yt { color: var(--accent); }

.search { flex: 1; display: flex; max-width: 620px; margin: 0 auto; }
.search input {
  flex: 1;
  min-width: 60px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-right: none;
  border-radius: 999px 0 0 999px;
  padding: 9px 16px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}
.search input:focus { border-color: #52535c; }
.search button {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: none;
  border-radius: 0 999px 999px 0;
  padding: 0 16px;
  color: var(--text);
  cursor: pointer;
}
.search button:hover { background: var(--hover); }

.head-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.sb-on {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 1px;
  cursor: pointer;
}
.sb-on:hover { background: var(--hover); }
.sb-off { opacity: 0.45; }

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--hover); }

/* account */
.acct { position: relative; }
.acct-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--line);
  color: #fff;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.acct-btn:hover { filter: brightness(1.15); }
.menu {
  position: absolute;
  right: 0;
  top: 44px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  min-width: 240px;
  padding: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  z-index: 60;
}
.menu-title { font-size: 0.68rem; letter-spacing: 1px; color: var(--muted); padding: 8px 10px 4px; text-transform: uppercase; }
.m-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.88rem;
  text-align: left;
}
.m-row:hover { background: var(--hover); }
.m-row .dot { width: 26px; height: 26px; border-radius: 50%; flex: none; color: #fff; font-weight: 800; font-size: 0.8rem; display: flex; align-items: center; justify-content: center; }
.m-row .cnt { margin-left: auto; color: var(--muted); font-size: 0.75rem; }
.m-row .x { color: var(--muted); font-size: 0.9rem; padding: 0 2px; }
.m-row .x:hover { color: var(--accent); }
.m-sep { height: 1px; background: var(--line); margin: 5px 4px; }
.acc-form { padding: 8px 10px; }
.acc-form input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 0.88rem;
  outline: none;
  margin-bottom: 8px;
}
.swatches { display: flex; gap: 8px; margin-bottom: 10px; }
.swatches button {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; cursor: pointer;
}
.swatches button.sel { border-color: var(--text); }
.acc-form .save {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px;
  font-weight: 700;
  cursor: pointer;
}

/* ---------- main ---------- */
main { flex: 1; width: 100%; max-width: 1500px; margin: 0 auto; padding: 20px 18px 60px; }

.view { animation: fadein 0.22s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; } }

.chips { display: flex; flex-wrap: wrap; gap: 9px; margin-bottom: 26px; }
.chips button {
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 15px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: 0.15s;
}
.chips button:hover { background: var(--hover); border-color: #3a3a3a; }

.section-title { font-size: 1.25rem; margin: 10px 0 16px; }

/* channel hero (from @handle search) */
.chan-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.ch-av {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  flex: none;
  background: var(--card);
  border: 1px solid var(--line);
}
.ch-av.letter { display: flex; align-items: center; justify-content: center; font-size: 1.5rem; font-weight: 800; color: var(--muted); }
.ch-info { min-width: 0; }
.ch-info b { font-size: 1.2rem; }
.ch-info p { font-size: 0.85rem; margin-top: 2px; }
.chan-hero .sub { margin-left: auto; flex: none; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 20px 16px;
}

/* channel group (subscriptions home) */
.group { margin-bottom: 30px; }
.group-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.g-av { width: 44px; height: 44px; border-radius: 50%; background: var(--panel); border: 1px solid var(--line); object-fit: cover; flex: none; }
.g-av.letter { display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1.05rem; color: #fff; }
.group-head b { font-size: 1rem; cursor: pointer; }
.group-head b:hover { color: var(--accent); }
.group-head .g-subs { margin-left: auto; color: var(--muted); font-size: 0.8rem; }

/* ---------- video card ---------- */
.card { cursor: pointer; }
.card .thumb-box {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  margin-bottom: 9px;
}
.card img.thumb { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.25s ease; }
.card:hover img.thumb { transform: scale(1.035); }
.dur-badge {
  position: absolute;
  right: 7px;
  bottom: 7px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 6px;
}
.card h3 { font-size: 0.93rem; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .card-chan { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.card .c-av { width: 22px; height: 22px; border-radius: 50%; background: var(--panel); object-fit: cover; flex: none; }
.card .c-av.letter { display: flex; align-items: center; justify-content: center; font-size: 0.6rem; font-weight: 800; color: #fff; }
.card p { color: var(--muted); font-size: 0.82rem; }

.empty { text-align: center; padding: 50px 0; color: var(--text); line-height: 2; }
.empty .muted { font-size: 0.9rem; }

/* ---------- watch ---------- */
.watch-col { max-width: 1200px; margin: 0 auto; }

.back {
  background: none;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 18px;
  margin-bottom: 13px;
  cursor: pointer;
  font-size: 0.85rem;
}
.back:hover { background: var(--card); }

.player-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  max-height: 72vh;
}
.player-wrap video { width: 100%; height: 100%; display: block; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(0, 0, 0, 0.5);
  z-index: 5;
  text-align: center;
  padding: 20px;
  pointer-events: none;
}
.overlay p { color: #fff; font-size: 0.95rem; }
.spinner {
  width: 46px;
  height: 46px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.overlay.err .spinner { display: none; }
.overlay.err p { color: #ffb3b3; }

/* custom player controls */
.ctrl {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  padding: 26px 12px 8px;
  z-index: 6;
  opacity: 0;
  transition: opacity 0.25s;
}
.ctrl.show { opacity: 1; }

.prog { position: relative; height: 14px; display: flex; align-items: center; cursor: pointer; }
.pbuf, .pplay, .psb, .prog input {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 4px;
  border-radius: 2px;
}
.pbuf { width: 0; background: rgba(255, 255, 255, 0.35); }
.pplay { width: 0; background: var(--accent); }
.psb { pointer-events: none; }
.psb i {
  position: absolute;
  top: 0;
  width: 3px;
  height: 4px;
  border-radius: 2px;
  background: var(--sb);
}
.psb i.big { width: 8px; }
.prog:hover .pbuf, .prog:hover .pplay, .prog:hover .psb, .prog:hover .psb i { height: 6px; }
.prog input {
  width: 100%;
  height: 14px;
  opacity: 0;
  cursor: pointer;
  margin: 0;
  z-index: 2;
}

.cbtns { display: flex; align-items: center; gap: 10px; margin-top: 2px; }
.pc {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pc:hover { color: var(--accent); }
.time { color: #fff; font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.space { flex: 1; }
.vol {
  width: 72px;
  height: 4px;
  accent-color: #fff;
  cursor: pointer;
}

/* meta under player */
.meta { margin-top: 20px; }
.meta h1 { font-size: clamp(1.05rem, 2.4vw, 1.5rem); line-height: 1.3; }
.meta-row { display: flex; align-items: center; gap: 13px; margin-top: 13px; flex-wrap: wrap; }
.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--line);
  object-fit: cover;
  flex: none;
}
.avatar.letter { display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1.1rem; color: var(--muted); }
.chan { min-width: 0; }
.chan-name {
  background: none;
  border: none;
  color: var(--text);
  font-weight: 700;
  font-size: 0.98rem;
  cursor: pointer;
  padding: 0;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chan-name:hover { color: var(--accent); }
.chan p { font-size: 0.82rem; margin-top: 2px; }
.sub {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 9px 20px;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
}
.sub:hover { filter: brightness(1.12); }
.sub.done { background: var(--card); color: var(--muted); border: 1px solid var(--line); }
.sub.done:hover { color: var(--accent); border-color: var(--accent); }
.origin {
  margin-left: auto;
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 15px;
  font-size: 0.82rem;
}
.origin:hover { background: var(--card); }

.desc {
  margin-top: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 15px;
}
.desc summary { cursor: pointer; font-size: 0.9rem; font-weight: 600; }
.desc pre {
  margin-top: 10px;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: inherit;
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text);
  max-height: 260px;
  overflow-y: auto;
}

/* ---------- toast / footer ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: #22110a;
  border: 1px solid var(--sb);
  color: #ffd9a8;
  padding: 11px 20px;
  border-radius: 12px;
  font-size: 0.84rem;
  z-index: 100;
  max-width: 90vw;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
  font-size: 0.76rem;
  padding: 18px;
}

@media (max-width: 680px) {
  .name, .sb-on, .vol { display: none; }
  main { padding: 14px 10px 50px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
}