/* Tube: dark-first, mobile-first. Colors live in tokens so the light theme is one override. */

:root {
  color-scheme: dark;
  --bg: #0f0f0f;
  --bg-raised: #212121;
  --bg-menu: #282828;
  --hover: rgba(255, 255, 255, 0.1);
  --press: rgba(255, 255, 255, 0.18);
  --text: #f1f1f1;
  --text-2: #aaaaaa;
  --text-3: #8a8a8a;
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: #303030;
  --chip: rgba(255, 255, 255, 0.1);
  --chip-on-bg: #f1f1f1;
  --chip-on-fg: #0f0f0f;
  --input-bg: #121212;
  --accent: #ff0033;
  --accent-text: #ff4d6d;
  --link: #3ea6ff;
  --danger: #ff6b6b;
  --danger-bg: #e5323c;
  --ok: #4cc26a;
  --focus: #3ea6ff;
  --sk: rgba(255, 255, 255, 0.08);
  --sk-shine: rgba(255, 255, 255, 0.07);
  --scrim: rgba(0, 0, 0, 0.66);
  --header-bg: rgba(15, 15, 15, 0.92);
  --toast-bg: #f1f1f1;
  --toast-fg: #0f0f0f;
  --toast-action: #065fd4;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  --header-h: 56px;
  --top: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --bg-raised: #ffffff;
  --bg-menu: #ffffff;
  --hover: rgba(0, 0, 0, 0.06);
  --press: rgba(0, 0, 0, 0.12);
  --text: #0f0f0f;
  --text-2: #606060;
  --text-3: #707070;
  --line: rgba(0, 0, 0, 0.1);
  --line-strong: #d3d3d3;
  --chip: rgba(0, 0, 0, 0.05);
  --chip-on-bg: #0f0f0f;
  --chip-on-fg: #ffffff;
  --input-bg: #ffffff;
  --accent-text: #c4002a;
  --link: #065fd4;
  --danger: #b3261e;
  --danger-bg: #cc1f1f;
  --ok: #137333;
  --focus: #065fd4;
  --sk: rgba(0, 0, 0, 0.07);
  --sk-shine: rgba(255, 255, 255, 0.55);
  --scrim: rgba(0, 0, 0, 0.45);
  --header-bg: rgba(255, 255, 255, 0.94);
  --toast-bg: #0f0f0f;
  --toast-fg: #f1f1f1;
  --toast-action: #3ea6ff;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.16);
}

@media (prefers-color-scheme: light) {
  :root[data-theme="system"] {
    color-scheme: light;
    --bg: #ffffff;
    --bg-raised: #ffffff;
    --bg-menu: #ffffff;
    --hover: rgba(0, 0, 0, 0.06);
    --press: rgba(0, 0, 0, 0.12);
    --text: #0f0f0f;
    --text-2: #606060;
    --text-3: #707070;
    --line: rgba(0, 0, 0, 0.1);
    --line-strong: #d3d3d3;
    --chip: rgba(0, 0, 0, 0.05);
    --chip-on-bg: #0f0f0f;
    --chip-on-fg: #ffffff;
    --input-bg: #ffffff;
    --accent-text: #c4002a;
    --link: #065fd4;
    --danger: #b3261e;
    --danger-bg: #cc1f1f;
    --ok: #137333;
    --focus: #065fd4;
    --sk: rgba(0, 0, 0, 0.07);
    --sk-shine: rgba(255, 255, 255, 0.55);
    --scrim: rgba(0, 0, 0, 0.45);
    --header-bg: rgba(255, 255, 255, 0.94);
    --toast-bg: #0f0f0f;
    --toast-fg: #f1f1f1;
    --toast-action: #3ea6ff;
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.16);
  }
}

/* ---------- base ---------- */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.43 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.55; }
h1, h2, h3, p { margin: 0; }
img, video { max-width: 100%; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.view:focus { outline: none; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  width: 24px;
  height: 24px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.muted { color: var(--text-2); }

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 50;
  padding: 8px 14px;
  border: 0;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  transform: translateY(-150%);
}
.skip-link:focus { transform: none; }

.noscript { padding: 48px 24px; text-align: center; color: var(--text-2); }

/* ---------- buttons ---------- */

.icon-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
}
.icon-btn:hover { background: var(--hover); }
.icon-btn:active { background: var(--press); }
.icon-btn.sm { width: 32px; height: 32px; }
.icon-btn.sm .icon { width: 18px; height: 18px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: none;
  height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: 18px;
  background: var(--chip);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color 0.15s, opacity 0.15s;
}
.btn .icon { width: 20px; height: 20px; margin-left: -4px; }
.btn:hover { background: var(--press); }
.btn.primary { background: var(--text); color: var(--bg); }
.btn.primary:hover { opacity: 0.86; }
.btn.danger { background: var(--danger-bg); color: #fff; }
.btn.danger:hover { opacity: 0.88; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.danger-text { color: var(--danger); }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn.lg { height: 48px; padding: 0 28px; border-radius: 24px; font-size: 16px; }
.btn.lg .icon { width: 22px; height: 22px; }

.key-copy {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: var(--text-2);
  font: 12px/1.4 var(--mono);
  text-align: left;
  overflow-wrap: anywhere;
}
.key-copy .icon { width: 14px; height: 14px; }
.key-copy:hover { color: var(--text); }
.key-copy.full { font-size: 13px; color: var(--text); }

/* ---------- boot + sign-in ---------- */

.boot {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  background: var(--bg);
}
.boot .icon { width: 56px; height: 56px; color: var(--accent); animation: fade-in 0.3s 0.25s both, pulse 1.4s 0.55s ease-in-out infinite; }

.signin {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(32px, env(safe-area-inset-top)) 20px max(32px, env(safe-area-inset-bottom));
  background: radial-gradient(900px 520px at 50% -12%, rgba(255, 0, 51, 0.2), transparent 65%), var(--bg);
}
.signin-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: min(420px, 100%);
  text-align: center;
  animation: rise 0.35s ease-out;
}
.signin-logo { width: 76px; height: 76px; color: var(--accent); }
.signin h1 { font-size: 40px; font-weight: 800; letter-spacing: -1.2px; line-height: 1.1; }
.lede { max-width: 30ch; color: var(--text-2); font-size: 17px; line-height: 1.5; }
.signin .btn.lg { margin-top: 8px; }
.signin-msg { width: 100%; text-align: left; }
.signin-msg:empty { display: none; }
.signin-foot { color: var(--text-3); font-size: 13px; }

.notice {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--chip);
  font-size: 14px;
  animation: rise 0.25s ease-out;
}
.notice h2 { font-size: 16px; font-weight: 600; }
.notice p { color: var(--text-2); }
.notice ul { display: grid; gap: 8px; margin: 0; padding-left: 20px; color: var(--text-2); }
.notice strong { color: var(--text); font-weight: 600; }
.notice.error { border-color: rgba(229, 50, 60, 0.45); }
.notice .btn { align-self: flex-start; }

/* ---------- header ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 4px;
  height: var(--top);
  padding: env(safe-area-inset-top, 0px) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  background: var(--header-bg);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: none;
  height: 40px;
  padding: 0 10px 0 6px;
  border-radius: 20px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.6px;
}
.brand .logo { width: 32px; height: 32px; color: var(--accent); }

.search { display: none; flex: 1 1 auto; max-width: 640px; height: 40px; margin: 0 auto; }
.search input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  border-right: 0;
  border-radius: 20px 0 0 20px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 16px;
}
.search input::placeholder { color: var(--text-3); }
.search input:focus { outline: none; border-color: var(--focus); box-shadow: inset 0 0 0 1px var(--focus); }
.search-btn {
  display: grid;
  place-items: center;
  flex: none;
  width: 60px;
  height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 0 20px 20px 0;
  background: var(--chip);
  color: var(--text);
}
.search-btn:hover { background: var(--press); }
.search-btn .icon { width: 22px; height: 22px; }

.search-back { display: none; }
.actions { display: flex; align-items: center; gap: 2px; margin-left: auto; }

.add-label { display: none; }

.jobs-btn.busy .icon { animation: bob 1.5s ease-in-out infinite; }
.count-badge {
  position: absolute;
  top: 3px;
  right: 1px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  box-shadow: 0 0 0 2px var(--bg);
}

.avatar-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
}

.avatar {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #555;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  user-select: none;
}
.avatar .icon { width: 60%; height: 60%; }
.avatar.md { width: 36px; height: 36px; font-size: 15px; }
.avatar.lg { width: 40px; height: 40px; font-size: 17px; }
.avatar.xl { width: 72px; height: 72px; font-size: 30px; }
.av-0 { background: #c2185b; }
.av-1 { background: #7b1fa2; }
.av-2 { background: #4f46e5; }
.av-3 { background: #1976d2; }
.av-4 { background: #00838f; }
.av-5 { background: #2e7d32; }
.av-6 { background: #ef6c00; }
.av-7 { background: #6d4c41; }

.menu-wrap { position: relative; }
.menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 40;
  width: min(300px, calc(100vw - 16px));
  padding: 8px 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-menu);
  box-shadow: var(--shadow);
  animation: pop 0.14s ease-out;
  transform-origin: top right;
}
.menu-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
  padding: 8px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.menu-who { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.menu-name { font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.menu-role { color: var(--text-2); font-size: 13px; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  height: 44px;
  padding: 0 16px;
  border: 0;
  background: transparent;
  font-size: 14px;
  text-align: left;
}
.menu-item:hover { background: var(--hover); }
.menu-group { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 16px; }
.menu-sep { height: 1px; margin: 8px 0; background: var(--line); }
.seg { display: inline-flex; padding: 2px; border-radius: 9px; background: var(--chip); }
.seg button {
  padding: 5px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
}
.seg button[aria-pressed="true"] { background: var(--bg); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); }

@media (max-width: 599px) {
  .topbar.searching .brand,
  .topbar.searching .actions { display: none; }
  .topbar.searching .search,
  .topbar.searching .search-back { display: flex; }
  .topbar.searching .search-back { display: inline-grid; }
}

@media (min-width: 600px) {
  .topbar { gap: 16px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .search { display: flex; }
  .search-open { display: none; }
  .actions { gap: 6px; margin-left: 0; }
}

@media (min-width: 900px) {
  .add-btn { display: inline-flex; align-items: center; width: auto; height: 36px; gap: 6px; padding: 0 14px 0 10px; border-radius: 18px; background: var(--chip); }
  .add-btn:hover { background: var(--press); }
  .add-label { display: inline; font-weight: 500; }
}

/* ---------- pages ---------- */

.view {
  display: block;
  min-height: calc(100vh - var(--top));
  min-height: calc(100dvh - var(--top));
  padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px));
}
.page { max-width: 2200px; margin: 0 auto; }
.page.narrow { max-width: 760px; padding: 20px 16px 0; }

.page-title { font-size: 22px; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.page-lede { margin-top: 4px; color: var(--text-2); font-size: 15px; }
.section-title { padding: 8px 12px 12px; font-size: 18px; font-weight: 700; }
.search-head { padding: 16px 12px 12px; }

.latest-title { display: none; }
.has-shelf .latest-title { display: block; }

@media (min-width: 600px) {
  .section-title { padding: 8px 16px 16px; font-size: 20px; }
  .search-head { padding: 20px 16px 16px; }
  .page-title { font-size: 26px; }
}
@media (min-width: 1280px) {
  .section-title, .search-head { padding-left: 24px; padding-right: 24px; }
}

/* channel chips */
.chips {
  position: sticky;
  top: var(--top);
  z-index: 10;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 12px 12px;
  background: var(--bg);
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-block;
  flex: none;
  max-width: 220px;
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--chip);
  font-size: 14px;
  font-weight: 500;
  line-height: 32px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background-color 0.15s;
}
.chip:hover { background: var(--press); }
.chip.active { background: var(--chip-on-bg); color: var(--chip-on-fg); }
@media (min-width: 600px) { .chips { padding: 12px 16px; } }
@media (min-width: 1280px) { .chips { padding: 12px 24px; } }

/* channel header */
.channel-head { display: flex; align-items: center; gap: 16px; padding: 16px 12px 20px; }
.channel-text { min-width: 0; }
.channel-name { font-size: 24px; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.channel-sub { margin-top: 4px; color: var(--text-2); font-size: 14px; }
.channel-links:not(:empty) { margin-top: 12px; }
@media (min-width: 600px) {
  .channel-head { gap: 24px; padding: 24px 16px 28px; }
  .channel-head .avatar.xl { width: 104px; height: 104px; font-size: 42px; }
  .channel-name { font-size: 32px; }
}
@media (min-width: 1280px) { .channel-head { padding-left: 24px; padding-right: 24px; } }

/* ---------- video grid + cards ---------- */

.grid { display: grid; grid-template-columns: minmax(0, 1fr); column-gap: 16px; }
@media (min-width: 600px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 0 16px; } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1280px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 0 24px; } }

.card { position: relative; display: flex; flex-direction: column; gap: 12px; min-width: 0; margin-bottom: 24px; }
@media (min-width: 600px) { .card { margin-bottom: 36px; } }

.thumb {
  position: relative;
  display: block;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--sk);
}
@media (min-width: 600px) { .card .thumb { border-radius: var(--radius); } }
.thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.thumb img.loaded { opacity: 1; }
.thumb-empty { display: grid; place-items: center; width: 100%; height: 100%; color: var(--text-3); }
.thumb-empty .icon { width: 40px; height: 40px; stroke-width: 1.5; }

.duration {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  line-height: 18px;
  letter-spacing: 0.3px;
  font-variant-numeric: tabular-nums;
}
.thumb:has(.watched) .duration { bottom: 12px; }
.watched {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 4px;
  background: rgba(255, 255, 255, 0.35);
}
.watched span {
  display: block;
  height: 100%;
  background: var(--accent);
  transform: scaleX(var(--p, 0));
  transform-origin: left;
}

.card-meta { display: flex; gap: 12px; min-width: 0; padding: 0 12px; }
.card-meta > .avatar { margin-top: 2px; }
.card-text { display: flex; flex: 1; flex-direction: column; gap: 4px; min-width: 0; }
.card-title {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  font-size: 16px;
  font-weight: 500;
  line-height: 22px;
  overflow-wrap: anywhere;
}
.card-sub {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 4px;
  min-width: 0;
  color: var(--text-2);
  font-size: 12px;
  line-height: 18px;
}
.card-sub > * + *::before { content: "\00b7"; margin-right: 4px; }
.card-channel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
a.card-channel:hover { color: var(--text); }
/* The whole card opens the video, as on YouTube: the title link stretches over it and the
   channel link sits above. Scoped to .card: in .shelf-card it would cover the remove button. */
.card .card-title::after { content: ""; position: absolute; inset: 0; }
.card a.card-channel { position: relative; z-index: 1; }

@media (min-width: 600px) {
  .card-meta { padding: 0; }
  .card-sub { flex-direction: column; align-items: flex-start; font-size: 14px; line-height: 20px; }
  .card-sub > * + *::before { content: none; }
}

/* compact cards: related list on the watch page */
.related { display: flex; flex-direction: column; gap: 8px; padding: 0 12px; }
.card.compact { flex-direction: row; gap: 10px; margin-bottom: 0; }
.card.compact .thumb { flex: 0 0 160px; width: 160px; border-radius: 8px; }
.card.compact .card-meta { padding: 0; }
.card.compact .card-title { font-size: 14px; line-height: 20px; }
.card.compact .card-sub { flex-direction: column; align-items: flex-start; font-size: 12px; line-height: 18px; }
.card.compact .card-sub > * + *::before { content: none; }
.card.compact .duration { right: 4px; bottom: 4px; }
@media (min-width: 1000px) {
  .related { padding: 0; }
  .card.compact .thumb { flex-basis: 168px; width: 168px; }
}

/* continue watching shelf */
.shelf-wrap { padding: 4px 0 4px; }
.shelf {
  display: grid;
  grid-auto-columns: 72%;
  grid-auto-flow: column;
  gap: 12px;
  overflow-x: auto;
  padding: 0 12px 16px;
  scroll-padding: 0 12px;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}
.shelf::-webkit-scrollbar { display: none; }
.shelf-card { position: relative; display: flex; flex-direction: column; gap: 8px; min-width: 0; scroll-snap-align: start; }
.shelf-card .thumb { border-radius: 10px; }
.shelf-card .card-title { font-size: 14px; line-height: 20px; }
.shelf-card .card-sub { font-size: 12px; }
.shelf-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
}
.shelf-remove:hover { background: rgba(0, 0, 0, 0.82); }
@media (hover: hover) {
  .shelf-remove { opacity: 0; transition: opacity 0.15s; }
  .shelf-card:hover .shelf-remove, .shelf-remove:focus-visible { opacity: 1; }
}
@media (min-width: 600px) { .shelf { grid-auto-columns: 40%; padding: 0 16px 20px; scroll-padding: 0 16px; } }
@media (min-width: 900px) { .shelf { grid-auto-columns: 28%; } }
@media (min-width: 1280px) { .shelf { grid-auto-columns: 21%; padding: 0 24px 20px; scroll-padding: 0 24px; } }
@media (min-width: 1800px) { .shelf { grid-auto-columns: 16%; } }

/* feed status, empty and error states */
.feed-status:empty { display: none; }
.feed-end { padding: 8px 16px 24px; color: var(--text-3); font-size: 13px; text-align: center; }

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 420px;
  margin: 0 auto;
  padding: 56px 24px;
  text-align: center;
  animation: rise 0.3s ease-out;
}
.empty-icon {
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  margin-bottom: 8px;
  border-radius: 50%;
  background: var(--chip);
  color: var(--text-2);
}
.empty-icon .icon { width: 44px; height: 44px; stroke-width: 1.5; }
.empty h2 { font-size: 20px; font-weight: 600; }
.empty p { color: var(--text-2); font-size: 15px; }
.empty .btn { margin-top: 8px; }
.empty.error .empty-icon { color: var(--danger); }

/* new videos pill */
.new-pill {
  position: fixed;
  top: calc(var(--top) + 64px);
  left: 50%;
  z-index: 25;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px 0 12px;
  border: 0;
  border-radius: 18px;
  background: #065fd4; /* not var(--link): the dark theme's light blue is too pale under white text */
  color: #fff;
  font-weight: 600;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
  animation: drop 0.25s ease-out;
}
.new-pill .icon { width: 18px; height: 18px; }

/* skeletons */
.sk { position: relative; overflow: hidden; background: var(--sk); border-radius: 6px; }
.sk::after {
  position: absolute;
  inset: 0;
  content: "";
  background: linear-gradient(90deg, transparent, var(--sk-shine), transparent);
  transform: translateX(-100%);
  animation: shimmer 1.3s ease-in-out infinite;
}
.thumb.sk { border-radius: 0; }
@media (min-width: 600px) { .card .thumb.sk { border-radius: var(--radius); } }
.card.compact .thumb.sk { border-radius: 8px; }
.sk-line { width: 92%; height: 14px; margin: 3px 0; }
.sk-line.short { width: 58%; }
.sk-line.tiny { width: 36%; }
.sk-title { display: inline-block; width: 220px; max-width: 70vw; height: 30px; vertical-align: middle; }
.sk-avatar { width: 36px; height: 36px; border-radius: 50%; flex: none; }
.sk-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.sk-row .card-text { gap: 6px; }
.watch-main .sk-row { padding: 4px 0; }
.page.narrow .section-title { padding-left: 0; padding-right: 0; }

/* ---------- watch page ---------- */

.watch { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; max-width: 1760px; margin: 0 auto; }
.watch-main { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.watch-main > :not(.player) { margin: 0 12px; }

.player { position: sticky; top: var(--top); z-index: 15; background: #000; }
.player video {
  display: block;
  width: 100%;
  max-height: 70vh;
  aspect-ratio: 16 / 9;
  background: #000;
  object-fit: contain;
}
.player.vertical { position: relative; top: auto; }
.player.vertical video { aspect-ratio: 9 / 16; max-height: 78vh; }
.player.sk { aspect-ratio: 16 / 9; border-radius: 0; }

/* One column: .watch-main steps aside so the sticky player's container is the whole page,
   and it stays pinned while the related list scrolls under it. */
@media (max-width: 999px) {
  .watch { gap: 12px; }
  .watch-main { display: contents; }
  .watch-side { margin-top: 8px; }
}
/* Landscape phones: a pinned player would leave almost no room, so it scrolls with the page. */
@media (max-width: 999px) and (max-height: 500px) {
  .player { position: relative; top: auto; }
  .player video { max-height: calc(100vh - var(--top)); max-height: calc(100dvh - var(--top)); }
}
.player-error {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  padding: 16px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  text-align: center;
}
.player-error .icon { width: 36px; height: 36px; }
.player-error .btn { background: rgba(255, 255, 255, 0.16); color: #fff; }
.player-error .btn:hover { background: rgba(255, 255, 255, 0.26); }
.player-error .btn .icon { width: 20px; height: 20px; }

.watch-title { font-size: 18px; font-weight: 600; line-height: 26px; overflow-wrap: anywhere; }
.watch-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.watch-channel { display: flex; align-items: center; gap: 12px; min-width: 0; }
.watch-channel-text { display: flex; flex-direction: column; min-width: 0; }
.watch-channel-name { font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.watch-channel-name:hover { text-decoration: underline; }
.watch-sub { color: var(--text-2); font-size: 12px; }
.watch-actions {
  display: flex;
  gap: 8px;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.watch-actions::-webkit-scrollbar { display: none; }

.desc {
  padding: 12px;
  border-radius: 12px;
  background: var(--chip);
  font-size: 14px;
  line-height: 20px;
  transition: background-color 0.15s;
}
.desc.collapsed { cursor: pointer; }
.desc.collapsed:hover { background: var(--press); }
.desc-facts { margin-bottom: 4px; font-weight: 600; }
.desc-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.desc.collapsed .desc-text {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
}
.desc-text a, .ts { color: var(--link); }
.desc-text a:hover, .ts:hover { text-decoration: underline; }
.ts { padding: 0; border: 0; background: none; font: inherit; }
.desc-more { margin-top: 6px; padding: 0; border: 0; background: none; color: var(--text); font-weight: 600; }

.watch-side { min-width: 0; }
.watch-side .section-title { font-size: 16px; }

@media (min-width: 1000px) {
  .watch { grid-template-columns: minmax(0, 1fr) 402px; gap: 24px; padding: 24px 24px 0; }
  .watch-main > :not(.player) { margin: 0; }
  .player { position: relative; top: auto; overflow: hidden; border-radius: var(--radius); }
  .player.sk { border-radius: var(--radius); }
  .player video { max-height: calc(100vh - 170px); }
  .watch-title { font-size: 20px; line-height: 28px; }
  .watch-side .section-title { padding: 0 0 12px; }
}

/* ---------- dialogs + sheet ---------- */

dialog { color: var(--text); }
dialog::backdrop { background: var(--scrim); }

.dialog {
  width: min(480px, calc(100vw - 24px));
  max-width: none;
  max-height: calc(100dvh - 48px);
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: var(--bg-raised);
  box-shadow: var(--shadow);
}
.dialog[open] { animation: pop 0.18s ease-out; }
.dialog-body { display: flex; flex-direction: column; gap: 12px; padding: 24px; }
.dialog h2 { font-size: 20px; font-weight: 600; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.confirm-text { color: var(--text-2); overflow-wrap: anywhere; }
@media (max-width: 599px) {
  #add-dialog { margin-top: max(10vh, 16px); }
}

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 14px; font-weight: 500; }
.field-row { display: flex; gap: 8px; }
.input {
  width: 100%;
  min-width: 0;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 16px;
}
.input::placeholder { color: var(--text-3); }
.input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 1px var(--focus); }
.field-row .input { flex: 1; }
.field-row .btn { height: 44px; border-radius: 10px; }
select.input, .role-select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23909090' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-position: right 10px center;
  background-repeat: no-repeat;
  background-size: 18px;
}
.hint { color: var(--text-2); font-size: 13px; }
.field-error { color: var(--danger); font-size: 13px; }
.field-error:empty { display: none; }
.bot-line { padding: 12px; border-radius: 10px; background: var(--chip); color: var(--text-2); font-size: 13px; }
.bot-line .key-copy { display: inline; color: var(--text); }
.bot-line .key-copy .icon { margin-left: 4px; vertical-align: -2px; }

.sheet {
  position: fixed;
  inset: auto 0 0 0;
  width: 100%;
  max-width: 100%;
  height: auto;
  max-height: 85vh;
  max-height: 85dvh;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 18px 18px 0 0;
  background: var(--bg-raised);
  box-shadow: var(--shadow);
}
.sheet[open] { display: flex; flex-direction: column; animation: sheet-up 0.24s cubic-bezier(0.2, 0.8, 0.2, 1); }
.sheet-body { display: flex; flex: 1; flex-direction: column; min-height: 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
.sheet-grip { width: 36px; height: 4px; margin: 8px auto 0; border-radius: 2px; background: var(--text-3); opacity: 0.5; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 8px 20px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-size: 18px; font-weight: 600; }
@media (min-width: 700px) {
  .sheet { inset: 0 0 0 auto; width: 420px; height: 100%; max-height: 100%; border-radius: 18px 0 0 18px; }
  .sheet[open] { animation-name: sheet-left; }
  .sheet-grip { display: none; }
  .sheet-head { padding-top: 12px; }
}

/* jobs */
.jobs { flex: 1; min-height: 0; margin: 0; padding: 0; overflow-y: auto; overscroll-behavior: contain; list-style: none; }
.job { display: flex; flex-direction: column; gap: 6px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.job-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.job-title {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  font-weight: 500;
  overflow-wrap: anywhere;
}
a.job-title { color: var(--text); }
a.job-title:hover { text-decoration: underline; }
.job-status {
  flex: none;
  padding: 2px 9px;
  border-radius: 10px;
  background: var(--chip);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.job.is-downloading .job-status, .job.is-processing .job-status { color: var(--link); }
.job.is-done .job-status { color: var(--ok); }
.job.is-error .job-status { color: var(--danger); }
@supports (background: color-mix(in srgb, red 10%, transparent)) {
  .job.is-downloading .job-status, .job.is-processing .job-status { background: color-mix(in srgb, var(--link) 16%, transparent); }
  .job.is-done .job-status { background: color-mix(in srgb, var(--ok) 16%, transparent); }
  .job.is-error .job-status { background: color-mix(in srgb, var(--danger) 16%, transparent); }
}
.job-bar { height: 4px; overflow: hidden; border-radius: 2px; background: var(--chip); }
.job-bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
  transform: scaleX(var(--p, 0));
  transform-origin: left;
  transition: transform 0.4s ease;
}
.job-bar.indeterminate > span { width: 35%; transform: none; animation: slide 1.2s ease-in-out infinite; }
.job-detail { color: var(--text-2); font-size: 13px; overflow-wrap: anywhere; }
.job.is-error .job-detail { color: var(--danger); }
.job-foot { color: var(--text-3); font-size: 12px; }
.jobs-empty { padding: 48px 24px; color: var(--text-2); text-align: center; }
.jobs-empty .icon { width: 36px; height: 36px; margin-bottom: 8px; color: var(--text-3); stroke-width: 1.5; }

/* ---------- people ---------- */

.card-form {
  display: grid;
  gap: 14px;
  margin: 20px 0 28px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--chip);
}
.card-form .btn { justify-self: start; height: 44px; border-radius: 22px; }
@media (min-width: 700px) {
  .card-form { grid-template-columns: minmax(0, 2fr) minmax(0, 1.2fr) minmax(0, 1.4fr) auto; align-items: end; }
  .card-form .field-error { grid-column: 1 / -1; }
}
.people-list { margin: 0 0 24px; padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 16px; list-style: none; }
.person { display: flex; align-items: center; gap: 12px; padding: 12px 10px 12px 16px; border-bottom: 1px solid var(--line); }
.person:last-child { border-bottom: 0; }
.person-text { display: flex; flex: 1; flex-direction: column; gap: 2px; min-width: 0; }
.person-name { overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.person-you { color: var(--text-2); font-weight: 400; }
.role-pill { flex: none; padding: 4px 10px; border-radius: 12px; background: rgba(255, 0, 51, 0.14); color: var(--accent-text); font-size: 12px; font-weight: 600; }
.role-select {
  flex: none;
  height: 34px;
  padding-left: 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background-color: var(--input-bg);
  color: var(--text);
  font-size: 16px; /* under 16px, iOS Safari zooms the page when the control gets focus */
}
/* Narrow screens: name, key and the remove button on the first line, access below the name.
   Keeping the button up top leaves the 16px select room to fit even at 320px. */
@media (max-width: 480px) {
  .person { flex-wrap: wrap; }
  .person-text { flex-basis: calc(100% - 108px); }
  .person .role-select, .person .role-pill { order: 1; margin-left: 52px; }
}

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  inset: auto auto calc(16px + env(safe-area-inset-bottom, 0px)) 50%;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(560px, calc(100vw - 24px));
  height: auto;
  margin: 0;
  padding: 0;
  overflow: visible;
  border: 0;
  background: transparent;
  color: inherit;
  transform: translateX(-50%);
  pointer-events: none;
}
.toasts:empty { display: none; }
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 6px 6px 6px 16px;
  border-radius: 10px;
  background: var(--toast-bg);
  color: var(--toast-fg);
  font-size: 14px;
  box-shadow: var(--shadow);
  pointer-events: auto;
  animation: toast-in 0.22s ease-out;
}
.toast.leaving { animation: toast-out 0.2s ease-in forwards; }
.toast > .icon { width: 20px; height: 20px; color: #e5323c; }
.toast-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast-action {
  flex: none;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--toast-action);
  font-weight: 600;
}
.toast-action:hover { background: rgba(127, 127, 127, 0.16); }
.toast .icon-btn { color: inherit; }
.toast .icon-btn:hover { background: rgba(127, 127, 127, 0.16); }

/* ---------- touch screens: tap targets of about 40px ---------- */

/* Where a bigger box would shift the layout, padding plus an equal negative margin
   grows the hit area and leaves everything where it was. */
@media (pointer: coarse) {
  .btn, .btn.sm { height: 40px; border-radius: 20px; }
  /* not .shelf-remove: it sits on the thumbnail, and a bigger one gets hit by accident */
  .icon-btn.sm:not(.shelf-remove) { width: 40px; height: 40px; }
  .seg button { padding: 11px 12px; }
  .chip { height: 40px; line-height: 40px; border-radius: 10px; }
  .role-select { height: 40px; }
  .key-copy { padding: 11px 0; margin: -9px 0; }
  .desc-more { margin: 0 0 -10px; padding: 6px 16px 10px 0; }
}
/* Phone cards: the channel name is one 18px line under the title. Grow its hit area into
   the gap below the card, not up into the title. */
@media (pointer: coarse) and (max-width: 599px) {
  .card:not(.compact) a.card-channel { padding: 4px 0 18px; margin: -4px 0 -18px; }
}

/* ---------- motion ---------- */

@keyframes shimmer { to { transform: translateX(100%); } }
@keyframes slide { 0% { transform: translateX(-110%); } 100% { transform: translateX(310%); } }
@keyframes bob { 0%, 100% { transform: translateY(-1px); } 50% { transform: translateY(2px); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes drop { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes sheet-left { from { transform: translateX(100%); } to { transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
