/* XemTube v1.0.1
   Layout: fixed top bar; left rail on wide screens (iPad landscape), bottom tab bar on narrow
   (iPad portrait / phones); content grid of 16:9 cards; watch page = player + up-next column.
   Written for Safari 12+ (iPadOS/iOS 12 and newer): no flex `gap`, no `aspect-ratio`. */

:root {
  --bg: #ffffff;
  --bg-elev: #ffffff;
  --surface: #f2f2f2;
  --surface-2: #e5e5e5;
  --hover: rgba(0, 0, 0, 0.05);
  --text: #0f0f0f;
  --text-2: #606060;
  --text-3: #8d8d8d;
  --border: rgba(0, 0, 0, 0.1);
  --accent: #e8102e;
  --accent-2: #c40d27;
  --on-accent: #ffffff;
  --star: #ffc61a;
  --link: #065fd4;
  --chip-on-bg: #0f0f0f;
  --chip-on-fg: #ffffff;
  --scrim: rgba(0, 0, 0, 0.5);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.16);
  --skeleton: #ececec;
  --font: 'Roboto', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  --header-h: 56px;
  --rail-w: 76px;
  --guide-w: 236px;
  --tab-h: 52px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0f0f; --bg-elev: #212121; --surface: #272727; --surface-2: #3d3d3d;
    --hover: rgba(255, 255, 255, 0.1); --text: #f1f1f1; --text-2: #aaaaaa; --text-3: #7a7a7a;
    --border: rgba(255, 255, 255, 0.14); --accent: #ff2d46; --accent-2: #ff5468; --on-accent: #ffffff;
    --link: #3ea6ff; --chip-on-bg: #f1f1f1; --chip-on-fg: #0f0f0f; --scrim: rgba(0, 0, 0, 0.6);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.5); --skeleton: #222222; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f0f0f; --bg-elev: #212121; --surface: #272727; --surface-2: #3d3d3d;
  --hover: rgba(255, 255, 255, 0.1); --text: #f1f1f1; --text-2: #aaaaaa; --text-3: #7a7a7a;
  --border: rgba(255, 255, 255, 0.14); --accent: #ff2d46; --accent-2: #ff5468; --on-accent: #ffffff;
  --link: #3ea6ff; --chip-on-bg: #f1f1f1; --chip-on-fg: #0f0f0f; --scrim: rgba(0, 0, 0, 0.6);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.5); --skeleton: #222222; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  touch-action: manipulation;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; -webkit-appearance: none; appearance: none; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
svg { display: block; }
[hidden] { display: none !important; }
:focus { outline: none; }
.kbd-nav :focus { outline: 2px solid var(--link); outline-offset: 2px; }
.ico { width: 24px; height: 24px; fill: currentColor; flex-shrink: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  box-shadow: inset 0 var(--safe-t) 0 #000; /* dark band behind the phone's status bar */
  height: calc(var(--header-h) + var(--safe-t));
  padding: var(--safe-t) calc(16px + var(--safe-r)) 0 calc(8px + var(--safe-l));
  background: var(--bg);
  display: -webkit-box; display: flex; align-items: center;
}
.topbar .left { display: flex; align-items: center; flex-shrink: 0; }
.topbar .center { flex: 1 1 auto; min-width: 0; display: flex; justify-content: center; padding: 0 16px; }
.topbar .right { display: flex; align-items: center; flex-shrink: 0; }
.topbar .right > * + * { margin-left: 4px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text);
}
.icon-btn:active, .icon-btn:hover { background: var(--hover); }
.logo { display: flex; align-items: center; height: 40px; padding: 0 10px 0 6px; color: var(--text); }
.logo svg { width: 30px; height: 26px; margin-right: 4px; }
.logo .word { font-weight: 700; font-size: 20px; letter-spacing: -0.8px; }
.logo .word span { font-weight: 400; }
.logo sup { font-size: 9px; color: var(--text-2); margin-left: 3px; font-weight: 500; letter-spacing: 0; top: -0.9em; }

.search { display: flex; width: 100%; max-width: 640px; position: relative; }
.search-box {
  flex: 1 1 auto; min-width: 0; display: flex; align-items: center;
  height: 40px; border: 1px solid var(--border); border-right: 0;
  border-radius: 20px 0 0 20px; background: var(--bg); padding: 0 4px 0 16px;
}
.search-box:focus-within { border-color: var(--link); }
.search-box input {
  flex: 1 1 auto; min-width: 0; height: 38px; border: 0; background: transparent;
  font-size: 16px; -webkit-appearance: none; appearance: none; outline: none;
}
.search-box input::-webkit-search-cancel-button { display: none; }
.search-go {
  width: 64px; height: 40px; border: 1px solid var(--border); border-radius: 0 20px 20px 0;
  background: var(--surface); display: flex; align-items: center; justify-content: center;
}
.search-clear { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text-2); }
.suggest {
  position: absolute; top: 44px; left: 0; right: 64px; z-index: 60;
  background: var(--bg-elev); border-radius: 12px; box-shadow: var(--shadow);
  padding: 8px 0; border: 1px solid var(--border);
}
.suggest button {
  display: flex; align-items: center; width: 100%; text-align: left;
  padding: 8px 16px; font-size: 16px; font-weight: 500;
}
.suggest button .ico { width: 20px; height: 20px; margin-right: 14px; color: var(--text-2); }
.suggest button:hover, .suggest button.on { background: var(--hover); }
.search-toggle { display: none; }

/* ---------- navigation: rail / guide / tab bar ---------- */
.rail {
  position: fixed; z-index: 30; left: 0; bottom: 0;
  top: calc(var(--header-h) + var(--safe-t));
  width: calc(var(--rail-w) + var(--safe-l)); padding: 4px 4px 0 calc(4px + var(--safe-l));
  background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.rail a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 74px; border-radius: 10px; font-size: 10px; color: var(--text); text-align: center;
}
.rail a .ico { margin-bottom: 6px; }
.rail a:hover { background: var(--hover); }
.rail a.on .ico { color: var(--accent); }
.rail a.on { font-weight: 500; }
.rail .guide-only { display: none; }

body.guide .rail { width: calc(var(--guide-w) + var(--safe-l)); padding: 12px 12px 24px calc(12px + var(--safe-l)); }
body.guide .rail a {
  flex-direction: row; justify-content: flex-start; height: 40px; padding: 0 12px;
  font-size: 14px; text-align: left;
}
body.guide .rail a .ico { margin: 0 22px 0 0; }
body.guide .rail a.on { background: var(--surface); }
body.guide .rail .guide-only { display: block; }
.rail hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }
.rail h4 { margin: 4px 12px 8px; font-size: 15px; font-weight: 500; }
.rail .ch-link { font-size: 14px; }
.rail .ch-link .av { width: 24px; height: 24px; margin-right: 22px; font-size: 11px; }

.tabbar {
  position: fixed; z-index: 30; left: 0; right: 0; bottom: 0;
  height: calc(var(--tab-h) + var(--safe-b)); padding: 0 var(--safe-r) var(--safe-b) var(--safe-l);
  background: var(--bg); border-top: 1px solid var(--border);
  display: none;
}
.tabbar a {
  flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 10px; color: var(--text); min-width: 0;
}
.tabbar a .ico { margin-bottom: 3px; }
.tabbar a.on .ico { color: var(--accent); }
.tabbar a.on { font-weight: 500; }

.main {
  padding-top: calc(var(--header-h) + var(--safe-t));
  padding-left: calc(var(--rail-w) + var(--safe-l));
  padding-right: var(--safe-r);
  min-height: 100vh;
}
body.guide .main { padding-left: calc(var(--guide-w) + var(--safe-l)); }
.view { padding: 8px 24px 48px; max-width: 2200px; margin: 0 auto; }

@media (max-width: 899px) {
  .rail { display: none; }
  .tabbar { display: flex; }
  .main, body.guide .main { padding-left: var(--safe-l); padding-bottom: calc(var(--tab-h) + var(--safe-b)); }
  .view { padding: 4px 16px 40px; }
}
@media (max-width: 640px) {
  .topbar .center { display: none; }
  .topbar.searching .center { display: flex; position: absolute; left: 0; right: 0; top: var(--safe-t); height: var(--header-h); background: var(--bg); padding: 8px 12px; align-items: center; z-index: 2; }
  .topbar.searching .center .search-back { display: flex; }
  .search-toggle { display: flex; }
  .logo sup { display: none; }
}
.search-back { display: none; margin-right: 8px; }

/* ---------- notices ---------- */
.notice {
  display: flex; align-items: flex-start; margin: 8px 0 12px; padding: 12px 14px;
  border-radius: 12px; background: var(--surface); font-size: 13px; color: var(--text-2);
}
.notice b { color: var(--text); display: block; font-size: 14px; margin-bottom: 2px; font-weight: 500; }
.notice .ico { color: var(--accent); margin-right: 12px; margin-top: 2px; }
.notice > div { flex: 1 1 auto; min-width: 0; }
.notice .icon-btn { width: 32px; height: 32px; margin: -4px -6px -4px 8px; }
.note { color: var(--text-2); font-size: 13px; margin: 2px 0 14px; }

/* ---------- chips & tabs ---------- */
.chips {
  position: -webkit-sticky; position: sticky; z-index: 20;
  top: calc(var(--header-h) + var(--safe-t));
  background: var(--bg); margin: 0 -24px; padding: 10px 24px 12px;
  white-space: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chips.static { position: relative; top: 0; z-index: 1; }
@media (max-width: 899px) { .chips { margin: 0 -16px; padding: 8px 16px 10px; } }
.chip {
  display: inline-block; vertical-align: middle; height: 32px; line-height: 32px; padding: 0 12px;
  border-radius: 8px; background: var(--surface); font-size: 14px; font-weight: 500; margin-right: 12px;
  color: var(--text);
}
.chip:last-child { margin-right: 0; }
.chip.on { background: var(--chip-on-bg); color: var(--chip-on-fg); }
.chip .av { display: inline-block; vertical-align: middle; width: 22px; height: 22px; margin: -2px 8px 0 -4px; font-size: 10px; line-height: 22px; }
.seg { display: inline-flex; border-radius: 10px; background: var(--surface); padding: 3px; margin: 0 12px 0 0; vertical-align: middle; }
.seg button, .seg a { display: inline-block; height: 30px; line-height: 30px; padding: 0 14px; border-radius: 8px; font-size: 14px; font-weight: 500; color: var(--text-2); white-space: nowrap; }
.seg button.on, .seg a.on { background: var(--bg); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18); }
.chips .seg { margin-right: 12px; }
.page-head .seg { margin: 0; }
.lang-badge { font-weight: 700; font-size: 12px; border: 1.5px solid currentColor; border-radius: 6px; padding: 1px 4px; line-height: 14px; letter-spacing: 0.3px; }

.page-head { display: flex; align-items: center; margin: 16px 0 6px; }
.page-head h1 { font-size: 24px; font-weight: 700; margin: 0; letter-spacing: -0.3px; }
.page-head .ico-badge {
  width: 44px; height: 44px; border-radius: 50%; margin-right: 14px; flex-shrink: 0;
  background: var(--accent); color: var(--on-accent); display: flex; align-items: center; justify-content: center;
}
.page-head .spacer { flex: 1 1 auto; }
.section-title { font-size: 20px; font-weight: 700; margin: 28px 0 14px; display: flex; align-items: center; }
.section-title .spacer { flex: 1 1 auto; }
.section-title a, .section-title button { font-size: 14px; font-weight: 500; color: var(--link); }

/* ---------- video grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  grid-gap: 32px 16px; gap: 32px 16px;
}
@media (max-width: 599px) { .grid { grid-template-columns: 1fr; grid-gap: 24px; gap: 24px; } }
.card { cursor: pointer; min-width: 0; position: relative; }
.thumb {
  position: relative; width: 100%; padding-top: 56.25%; border-radius: 12px; overflow: hidden;
  background: var(--surface);
}
.thumb img, .thumb .ph {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover;
}
.thumb .ph {
  display: flex; align-items: flex-end; padding: 10px 12px; color: #fff; font-weight: 700; font-size: 13px; line-height: 1.25;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
.card:hover .thumb img { opacity: 0.92; }
.badge {
  position: absolute; right: 8px; bottom: 8px; padding: 1px 5px; border-radius: 5px;
  background: rgba(0, 0, 0, 0.8); color: #fff; font-size: 12px; font-weight: 500; line-height: 18px;
  font-variant-numeric: tabular-nums;
}
.badge.live { background: #e8102e; letter-spacing: 0.3px; }
.badge.short { background: rgba(0, 0, 0, 0.8); }
.rank {
  position: absolute; left: 8px; top: 8px; min-width: 30px; height: 30px; padding: 0 8px; border-radius: 8px;
  background: rgba(0, 0, 0, 0.78); color: #fff; font-weight: 700; font-size: 15px; line-height: 30px; text-align: center;
  font-variant-numeric: tabular-nums;
}
.rank.top3 { background: var(--accent); }
.progress { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255, 255, 255, 0.35); }
.progress i { display: block; height: 100%; background: #ff1a33; }
.meta { display: flex; padding-top: 12px; }
.meta .info { flex: 1 1 auto; min-width: 0; padding-right: 4px; }
.title {
  margin: 0 0 4px; font-size: 16px; font-weight: 500; line-height: 22px; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  word-break: break-word;
}
.sub { font-size: 14px; color: var(--text-2); line-height: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub a:hover { color: var(--text); }
.kebab { width: 32px; height: 32px; margin: -4px -8px 0 0; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text); flex-shrink: 0; opacity: 0.85; }
.kebab .ico { width: 20px; height: 20px; }
.kebab:active { background: var(--hover); }

.av {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 500; font-size: 15px; text-transform: uppercase; background: #6b6b6b;
}
.av { position: relative; }
.av img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }
.meta .av { margin-right: 12px; }

/* list rows (search, up next, library) */
.rows > * + * { margin-top: 12px; }
.row { display: flex; cursor: pointer; position: relative; }
.row .thumb { width: 168px; padding-top: 94.5px; flex-shrink: 0; border-radius: 8px; }
.row .badge { right: 4px; bottom: 4px; font-size: 11px; }
.row .info { flex: 1 1 auto; min-width: 0; padding: 0 4px 0 10px; }
.row .title { font-size: 14px; line-height: 20px; }
.row .sub { font-size: 12px; line-height: 18px; }
.rows.big .row .thumb { width: 360px; padding-top: 202.5px; border-radius: 12px; }
.rows.big .row .info { padding-left: 16px; }
.rows.big .row .title { font-size: 18px; line-height: 26px; }
.rows.big .row .sub { font-size: 13px; }
.rows.big > * + * { margin-top: 16px; }
.row .desc { font-size: 12px; color: var(--text-2); margin-top: 8px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row .ch-line { display: flex; align-items: center; margin: 10px 0 0; font-size: 12px; color: var(--text-2); }
.row .ch-line .av { width: 24px; height: 24px; font-size: 11px; margin-right: 8px; }
@media (max-width: 899px) {
  .rows.big .row .thumb { width: 46%; padding-top: 25.9%; }
  .rows.big .row .title { font-size: 16px; line-height: 22px; }
}
@media (max-width: 599px) {
  .rows.big .row .thumb { width: 160px; padding-top: 90px; }
  .rows.big .row .desc, .rows.big .row .ch-line .av { display: none; }
}

/* horizontal shelf */
.shelf {
  display: flex; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
  margin: 0 -24px; padding: 0 24px 4px;
}
.shelf::-webkit-scrollbar { display: none; }
.shelf .card { width: 248px; flex-shrink: 0; }
.shelf .card + .card { margin-left: 14px; }
.shelf .title { font-size: 14px; line-height: 20px; }
.shelf .sub { font-size: 12px; line-height: 18px; }
.shelf .meta .av { display: none; }
@media (max-width: 899px) { .shelf { margin: 0 -16px; padding: 0 16px 4px; } .shelf .card { width: 220px; } }

/* channel strip */
.chstrip { display: flex; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; margin: 0 -24px; padding: 4px 24px 8px; }
.chstrip::-webkit-scrollbar { display: none; }
.chstrip .ch { width: 104px; flex-shrink: 0; text-align: center; cursor: pointer; }
.chstrip .ch + .ch { margin-left: 8px; }
.chstrip .ch .av { width: 64px; height: 64px; margin: 0 auto 8px; font-size: 24px; }
.chstrip .ch .n { font-size: 12px; line-height: 16px; height: 32px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.chstrip .ch .btn-sub { margin-top: 6px; height: 28px; padding: 0 12px; font-size: 12px; }
@media (max-width: 899px) { .chstrip { margin: 0 -16px; padding: 4px 16px 8px; } }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; height: 36px; padding: 0 16px;
  border-radius: 18px; background: var(--surface); font-size: 14px; font-weight: 500; white-space: nowrap; color: var(--text);
}
.btn .ico { width: 22px; height: 22px; margin: 0 6px 0 -4px; }
.btn:active, .btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--text); color: var(--bg); }
.btn.accent { background: var(--accent); color: var(--on-accent); }
.btn.on { background: var(--surface); }
.btn-sub { display: inline-flex; align-items: center; justify-content: center; height: 36px; padding: 0 16px; border-radius: 18px; font-weight: 500; background: var(--text); color: var(--bg); white-space: nowrap; }
.btn-sub.on { background: var(--surface); color: var(--text); }
.btn-row > * + * { margin-left: 8px; }
.center-msg { text-align: center; padding: 64px 16px; color: var(--text-2); }
.center-msg h2 { color: var(--text); font-size: 20px; font-weight: 500; margin: 12px 0 6px; }
.center-msg p { max-width: 420px; margin: 0 auto 18px; }
.center-msg .big-ico { width: 72px; height: 72px; margin: 0 auto; color: var(--text-3); }
.more-wrap { text-align: center; margin: 28px 0 8px; }

/* skeletons */
.sk { background: var(--skeleton); border-radius: 8px; -webkit-animation: pulse 1.4s ease-in-out infinite; animation: pulse 1.4s ease-in-out infinite; }
.sk.thumb { border-radius: 12px; }
.sk-line { height: 14px; margin-top: 10px; border-radius: 4px; }
@-webkit-keyframes pulse { 50% { opacity: 0.5; } }
@keyframes pulse { 50% { opacity: 0.5; } }

/* ---------- watch page ---------- */
.watch { display: grid; grid-template-columns: minmax(0, 1fr) 400px; grid-gap: 24px; gap: 24px; max-width: 1760px; margin: 0 auto; padding-top: 16px; }
@media (max-width: 1099px) { .watch { grid-template-columns: minmax(0, 1fr); } }
.player-slot { position: relative; width: 100%; padding-top: 56.25%; border-radius: 12px; background: #000; }
@media (max-width: 599px) { .view.watching { padding-left: 0; padding-right: 0; } .view.watching .w-body, .view.watching .w-side { padding-left: 12px; padding-right: 12px; } .player-slot { border-radius: 0; } }
.w-title { font-size: 20px; line-height: 28px; font-weight: 700; margin: 12px 0 8px; word-break: break-word; }
.w-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.w-owner { display: flex; align-items: center; min-width: 0; margin: 4px 16px 8px 0; }
.w-owner .av { width: 40px; height: 40px; margin-right: 12px; cursor: pointer; }
.w-owner .nm { font-weight: 500; font-size: 16px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.w-owner .sub { font-size: 12px; }
.w-owner .btn-sub { margin-left: 20px; }
.w-actions { display: flex; flex-wrap: wrap; margin: 4px 0 8px; }
.w-actions > * { margin: 0 8px 6px 0; }
.w-actions .btn.on .ico { color: var(--accent); }
.w-desc { background: var(--surface); border-radius: 12px; padding: 12px; margin-top: 8px; font-size: 14px; }
.w-desc .stats { font-weight: 500; margin-bottom: 4px; }
.w-desc .txt { white-space: pre-wrap; word-break: break-word; }
.w-desc .txt.clamp { max-height: 60px; overflow: hidden; }
.w-desc .txt a { color: var(--link); }
.w-desc button { font-weight: 500; margin-top: 6px; }
.w-side-head { display: flex; align-items: center; justify-content: space-between; margin: 0 0 12px; }
.w-side-head h2 { font-size: 16px; font-weight: 500; margin: 0; }
.switch { display: inline-flex; align-items: center; font-size: 14px; color: var(--text-2); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .tr { width: 36px; height: 20px; border-radius: 10px; background: var(--surface-2); position: relative; margin-left: 10px; -webkit-transition: background 0.2s; transition: background 0.2s; }
.switch .tr:after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); -webkit-transition: -webkit-transform 0.2s; transition: transform 0.2s; }
.switch input:checked + .tr { background: var(--accent); }
.switch input:checked + .tr:after { -webkit-transform: translateX(16px); transform: translateX(16px); }

/* persistent player (moves between watch page and mini player without reloading) */
.ph { position: absolute; z-index: 25; background: #000; overflow: hidden; border-radius: 12px; }
.ph.hidden { display: none; }
.ph-video { position: absolute; top: 0; left: 0; right: 0; bottom: 0; }
.ph-video iframe, #ph-target { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0; }
.ph-cover {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 3;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  color: #fff; padding: 24px; background-color: #000; background-size: cover; background-position: center;
}
.ph-cover:before { content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.62); }
.ph-cover > * { position: relative; max-width: 460px; }
.ph-cover .play-ring { width: 68px; height: 68px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; margin-bottom: 14px; }
.ph-cover .play-ring .ico { width: 36px; height: 36px; color: #fff; }
.ph-cover b { font-size: 17px; font-weight: 500; display: block; margin-bottom: 6px; }
.ph-cover p { margin: 0 0 14px; font-size: 14px; color: rgba(255, 255, 255, 0.85); }
.ph-cover .btn { background: rgba(255, 255, 255, 0.16); color: #fff; }
.ph-cover .btn + .btn { margin-left: 8px; }
.ph-count {
  position: absolute; z-index: 4; left: 0; right: 0; bottom: 0; top: 0; background: rgba(0, 0, 0, 0.78);
  display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; text-align: center; padding: 16px;
}
.ph-count .t { font-size: 13px; color: rgba(255, 255, 255, 0.75); }
.ph-count .n { font-size: 18px; font-weight: 500; margin: 6px 0 14px; max-width: 520px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ph-count .btn { background: rgba(255, 255, 255, 0.18); color: #fff; }
.ph-count .btn.primary { background: #fff; color: #0f0f0f; }
.ph-mini-tap, .ph-mini-bar { display: none; }
.ph.mini {
  position: fixed; z-index: 45; width: 340px; height: auto; top: auto; left: auto;
  right: calc(16px + var(--safe-r)); bottom: calc(16px + var(--safe-b));
  background: var(--bg-elev); box-shadow: var(--shadow); border-radius: 12px;
}
.ph.mini .ph-video { position: relative; width: 100%; padding-top: 56.25%; }
.ph.mini .ph-video > * { position: absolute; }
.ph.mini .ph-mini-tap { display: block; position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 5; }
.ph.mini .ph-mini-bar { display: flex; align-items: center; height: 56px; padding: 0 4px 0 12px; }
.ph.mini .ph-cover b, .ph.mini .ph-cover p, .ph.mini .ph-cover .btn-row { display: none; }
.ph.mini .ph-cover .play-ring { width: 44px; height: 44px; margin: 0; }
.ph-mini-info { flex: 1 1 auto; min-width: 0; cursor: pointer; }
.ph-mini-info b { display: block; font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ph-mini-info span { display: block; font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 899px) { .ph.mini { bottom: calc(var(--tab-h) + 10px + var(--safe-b)); right: calc(10px + var(--safe-r)); width: 300px; } }
@media (max-width: 599px) { .ph.mini { left: 8px; right: 8px; width: auto; display: flex; align-items: center; } .ph.mini .ph-video { width: 120px; padding-top: 67.5px; flex-shrink: 0; } .ph.mini .ph-mini-bar { flex: 1 1 auto; min-width: 0; } }

/* ---------- channel page ---------- */
.ch-head { display: flex; align-items: center; padding: 24px 0 8px; flex-wrap: wrap; }
.ch-head .av { width: 120px; height: 120px; font-size: 48px; margin-right: 24px; }
.ch-head h1 { font-size: 30px; font-weight: 700; margin: 0 0 6px; letter-spacing: -0.4px; }
.ch-head .sub { white-space: normal; }
.ch-head .btn-row { margin-top: 14px; }
@media (max-width: 599px) { .ch-head .av { width: 72px; height: 72px; font-size: 30px; margin-right: 16px; } .ch-head h1 { font-size: 22px; } }

/* ---------- library ---------- */
.lib-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); grid-gap: 12px; gap: 12px; margin: 16px 0 8px; }
.lib-tile { display: flex; align-items: center; padding: 14px 16px; border-radius: 12px; background: var(--surface); cursor: pointer; }
.lib-tile .ico { margin-right: 14px; }
.lib-tile b { display: block; font-weight: 500; }
.lib-tile span { font-size: 12px; color: var(--text-2); }
.row .rm { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text-2); flex-shrink: 0; }

/* ---------- settings ---------- */
.settings { max-width: 760px; }
.set-group { margin: 26px 0 0; }
.set-group h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-2); font-weight: 500; margin: 0 0 8px 4px; }
.set-card { background: var(--surface); border-radius: 14px; overflow: hidden; }
.set-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; min-height: 52px; }
.set-row + .set-row, .set-row + .set-block, .set-block + .set-row, .set-block + .set-block { border-top: 1px solid var(--border); }
.set-row > span { margin-right: 16px; }
.set-row .seg { margin: 0; background: var(--surface-2); flex-shrink: 0; }
.set-block { padding: 14px 16px; }
.set-block p { margin: 6px 0 0; font-size: 13px; color: var(--text-2); }
.set-block .field { display: flex; margin-top: 10px; }
.set-block .field input {
  flex: 1 1 auto; min-width: 0; height: 40px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); padding: 0 12px; font-size: 16px; -webkit-appearance: none; appearance: none;
}
.set-block .field .btn { margin-left: 8px; }
.checks { display: flex; flex-wrap: wrap; margin-top: 10px; }
.checks label { display: inline-flex; align-items: center; margin: 0 8px 8px 0; padding: 6px 12px; border-radius: 8px; background: var(--surface-2); font-size: 13px; cursor: pointer; }
.checks input { margin: 0 6px 0 0; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; background: #20b15a; vertical-align: middle; }
.status-dot.warn { background: var(--star); }
.btn.danger { color: var(--accent); }

/* ---------- overlays ---------- */
.menu-pop {
  position: absolute; z-index: 70; min-width: 220px; padding: 8px 0; border-radius: 12px;
  background: var(--bg-elev); box-shadow: var(--shadow); border: 1px solid var(--border);
}
.menu-pop button, .menu-pop a { display: flex; align-items: center; width: 100%; height: 40px; padding: 0 16px; font-size: 14px; text-align: left; }
.menu-pop .ico { margin-right: 14px; width: 22px; height: 22px; }
.menu-pop button:hover, .menu-pop a:hover { background: var(--hover); }
.toast {
  position: fixed; z-index: 90; left: 50%; bottom: calc(24px + var(--safe-b));
  -webkit-transform: translate(-50%, 20px); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); border-radius: 8px; padding: 12px 18px; font-size: 14px;
  opacity: 0; pointer-events: none; -webkit-transition: opacity 0.2s, -webkit-transform 0.2s; transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100% - 32px); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}
.toast.show { opacity: 1; -webkit-transform: translate(-50%, 0); transform: translate(-50%, 0); }
@media (max-width: 899px) { .toast, .install { bottom: calc(var(--tab-h) + 12px + var(--safe-b)); } }
.install {
  position: fixed; z-index: 80; left: 50%; bottom: calc(16px + var(--safe-b)); width: 360px; max-width: calc(100% - 24px);
  -webkit-transform: translateX(-50%); transform: translateX(-50%);
  background: var(--bg-elev); border-radius: 16px; box-shadow: var(--shadow); padding: 16px; display: flex; align-items: center;
}
.install .app-ico { width: 52px; height: 52px; border-radius: 12px; margin-right: 14px; flex-shrink: 0; }
.install b { display: block; font-weight: 500; font-size: 15px; }
.install span { font-size: 13px; color: var(--text-2); }
.install span .ico { display: inline-block; vertical-align: -5px; width: 20px; height: 20px; color: var(--link); }
.install .btn { margin-left: 8px; }

@media (prefers-reduced-motion: reduce) {
  * { -webkit-animation: none !important; animation: none !important; -webkit-transition: none !important; transition: none !important; }
}
@media (max-width: 899px) { .install { bottom: calc(var(--tab-h) + 12px + var(--safe-b)); } }

/* ---------- Shorts: shelf on Home + vertical swipe viewer ---------- */
.section-title > .ico { color: var(--accent); margin-right: 8px; }
.sshelf .scard { width: 176px; flex-shrink: 0; cursor: pointer; min-width: 0; }
.sshelf .scard + .scard { margin-left: 12px; }
.sthumb { position: relative; width: 100%; padding-top: 177.78%; border-radius: 12px; overflow: hidden; background: var(--surface); }
.sthumb img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }
.scard .title { font-size: 15px; line-height: 21px; margin: 8px 0 2px; }
.scard .sub { font-size: 13px; }
@media (max-width: 599px) { .sshelf .scard { width: 150px; } }

.view.shorts-view { padding: 0; max-width: none; }
body.on-shorts { overflow: hidden; }
.shorts {
  position: relative; height: var(--sh, 600px); overflow-y: scroll; overflow-x: hidden;
  -webkit-overflow-scrolling: touch; scroll-snap-type: y mandatory; scrollbar-width: none; overscroll-behavior: contain;
}
.shorts::-webkit-scrollbar { display: none; }
.sh-slide {
  position: relative; height: var(--sh, 600px); scroll-snap-align: start; scroll-snap-stop: always;
  display: flex; align-items: center; justify-content: center; padding: 12px 0;
}
.sh-card {
  position: relative; height: 100%; width: calc((var(--sh, 600px) - 24px) * 0.5625); max-width: calc(100% - 120px);
  border-radius: 14px; overflow: hidden; background: #000; flex-shrink: 0;
}
.sh-card.sk { background: var(--skeleton); }
.sh-img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }
.sh-frame {
  position: absolute; z-index: 1; top: 0; left: 0; width: 0; height: 0; border-radius: 14px; overflow: hidden; background: #000;
  opacity: 0; -webkit-transition: opacity 0.2s; transition: opacity 0.2s; pointer-events: none;
}
.sh-frame.on { opacity: 1; }
.sh-frame iframe, #sh-target { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0; }
.shorts.plain .sh-frame { pointer-events: auto; }
.shorts.plain .sh-tap { display: none; }
.sh-tap { position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 2; cursor: pointer; }
.sh-paused {
  position: absolute; z-index: 3; top: 50%; left: 50%; width: 72px; height: 72px; margin: -36px 0 0 -36px; border-radius: 50%;
  background: rgba(0, 0, 0, 0.5); color: #fff; display: flex; align-items: center; justify-content: center; pointer-events: none;
}
.sh-paused .ico { width: 40px; height: 40px; }
.sh-hint {
  position: absolute; z-index: 4; left: 50%; bottom: 120px; -webkit-transform: translateX(-50%); transform: translateX(-50%);
  display: flex; align-items: center; white-space: nowrap; pointer-events: none;
  padding: 8px 14px 8px 10px; border-radius: 20px; background: rgba(0, 0, 0, 0.7); color: #fff; font-size: 13px; font-weight: 500;
}
.sh-hint .ico { width: 20px; height: 20px; margin-right: 8px; }
/* When the device asks for one tap to allow sound, let that tap reach YouTube's play button. */
.shorts.needs-tap .sh-frame { pointer-events: auto; z-index: 3; }
.shorts.needs-tap .sh-tap { display: none; }
.shorts.needs-tap .sh-meta { z-index: 4; }
.sh-demo {
  position: absolute; z-index: 4; top: 12px; left: 12px; right: 12px; padding: 8px 10px; border-radius: 10px;
  background: rgba(0, 0, 0, 0.66); color: #fff; font-size: 12px; line-height: 16px;
}
.sh-meta {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 3; padding: 56px 14px 18px; color: #fff;
  background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.72)); pointer-events: none;
}
.sh-meta [data-act], .sh-meta button { pointer-events: auto; }
.sh-ch { display: flex; align-items: center; margin-bottom: 8px; }
.sh-ch .av { width: 32px; height: 32px; font-size: 13px; margin-right: 8px; cursor: pointer; }
.sh-ch b { font-weight: 500; margin-right: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; cursor: pointer; }
.sh-ch .btn-sub { height: 30px; padding: 0 12px; font-size: 13px; background: #fff; color: #0f0f0f; flex-shrink: 0; }
.sh-ch .btn-sub.on { background: rgba(255, 255, 255, 0.22); color: #fff; }
.sh-title { font-size: 15px; line-height: 20px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.sh-views { font-size: 12px; opacity: 0.82; margin-top: 4px; }
.sh-prog { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; z-index: 4; background: rgba(255, 255, 255, 0.25); }
.sh-prog i { display: block; width: 0; height: 100%; background: var(--accent); }
.sh-actions { align-self: flex-end; width: 68px; margin-left: 14px; padding-bottom: 6px; }
.sh-act { display: flex; flex-direction: column; align-items: center; width: 100%; font-size: 12px; color: var(--text); text-align: center; margin-top: 14px; }
.sh-ico { width: 48px; height: 48px; border-radius: 50%; background: var(--surface); display: flex; align-items: center; justify-content: center; margin-bottom: 5px; }
.sh-act.on .sh-ico { background: var(--text); color: var(--bg); }
.sh-nav { position: fixed; z-index: 15; right: calc(28px + var(--safe-r)); top: 50%; -webkit-transform: translateY(-50%); transform: translateY(-50%); }
.sh-nav .icon-btn { width: 54px; height: 54px; background: var(--surface); margin: 10px 0; }
.sh-nav .icon-btn .ico { width: 30px; height: 30px; }
@media (max-width: 1099px) { .sh-nav { display: none; } }
@media (max-width: 599px) {
  .sh-slide { padding: 0; }
  .sh-card, .sh-frame { width: 100%; max-width: none; border-radius: 0; }
  .sh-actions { position: absolute; right: 6px; bottom: 96px; z-index: 5; width: 60px; margin: 0; }
  .sh-act { color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }
  .sh-ico { background: rgba(0, 0, 0, 0.45); }
  .sh-act.on .sh-ico { background: #fff; color: #0f0f0f; }
  .sh-meta { padding-right: 76px; }
}

/* ---------- Phones: full-screen Shorts, pinned player, sideways = full-screen video ---------- */
.sh-top { display: none; }
body.immersive .topbar, body.immersive .tabbar { display: none; }
body.immersive .main { padding: 0; }
body.immersive, body.immersive .shorts { background: #000; }
body.immersive .sh-top {
  display: flex; align-items: center; position: fixed; z-index: 20; top: 0; left: 0; right: 0;
  padding: calc(6px + var(--safe-t)) calc(8px + var(--safe-r)) 6px calc(4px + var(--safe-l)); color: #fff; pointer-events: none;
  background: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0));
}
body.immersive .sh-top .icon-btn { color: #fff; pointer-events: auto; }
body.immersive .sh-top b { font-size: 18px; font-weight: 700; margin-left: 4px; }
body.immersive .sh-top .spacer { flex: 1 1 auto; }
body.immersive .sh-slide { padding: 0; }
body.immersive .sh-card, body.immersive .sh-frame { border-radius: 0; }
body.immersive .sh-meta { padding-bottom: calc(18px + var(--safe-b)); }
body.immersive .sh-prog { bottom: var(--safe-b); }
body.immersive .sh-actions { position: absolute; right: calc(6px + var(--safe-r)); bottom: calc(96px + var(--safe-b)); z-index: 5; width: 60px; margin: 0; }
body.immersive .sh-act { color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }
body.immersive .sh-ico { background: rgba(0, 0, 0, 0.45); }
body.immersive .sh-act.on .sh-ico { background: #fff; color: #0f0f0f; }
body.immersive .sh-meta { padding-right: 76px; }
body.immersive .sh-demo { top: calc(56px + var(--safe-t)); }
body.immersive .sh-nav { display: none; }
@media (max-width: 599px) { body.immersive .sh-card { width: 100%; max-width: none; } }

.ph-back {
  display: none; position: absolute; z-index: 6; top: 8px; left: 8px; width: 36px; height: 36px; border-radius: 50%;
  background: rgba(0, 0, 0, 0.45); color: #fff; align-items: center; justify-content: center;
}
.ph.pinned .ph-back, .ph.full .ph-back { display: flex; }
.ph.pinned { position: fixed; z-index: 35; top: var(--safe-t); left: 0; right: 0; width: 100%; height: 56.25vw; border-radius: 0; }
.ph.full { position: fixed; z-index: 70; top: 0; left: 0; right: 0; bottom: 0; width: 100%; height: 100%; border-radius: 0; }
.ph.full .ph-back { top: calc(8px + var(--safe-t)); left: calc(8px + var(--safe-l)); }
body.phone-watch .topbar, body.phone-watch .tabbar, body.video-full .topbar, body.video-full .tabbar { display: none; }
body.phone-watch .main { padding-top: var(--safe-t); padding-bottom: var(--safe-b); }
body.phone-watch .watch { padding-top: 0; }
body.phone-watch:before { content: ''; position: fixed; z-index: 36; top: 0; left: 0; right: 0; height: var(--safe-t); background: #000; }
body.video-full { overflow: hidden; background: #000; }

@media (max-width: 599px) {
  .grid .thumb { width: auto; margin: 0 -16px; padding-top: calc(56.25% + 18px); border-radius: 0; }
  .grid { grid-gap: 22px; gap: 22px; }
  .view.watching .watch { grid-gap: 16px; gap: 16px; }
  .w-title { font-size: 18px; line-height: 24px; margin-top: 10px; }
  .w-owner { width: 100%; margin-right: 0; }
  .w-owner > div { flex: 1 1 auto; }
  .w-actions { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; margin: 4px -12px 8px; padding: 0 12px; }
  .w-actions::-webkit-scrollbar { display: none; }
  .w-actions > * { flex-shrink: 0; }
  .page-head h1 { font-size: 21px; }
  .page-head .ico-badge { width: 38px; height: 38px; margin-right: 12px; }
  .section-title { font-size: 18px; margin: 22px 0 12px; }
  .ch-head { padding-top: 16px; }
  .settings .set-row { flex-wrap: wrap; }
  .settings .set-row > span { margin-bottom: 6px; }
}
@media (max-width: 399px) {
  .topbar { padding-right: calc(8px + var(--safe-r)); }
  .topbar .icon-btn { width: 36px; height: 36px; }
  .logo .word { font-size: 18px; }
  .logo svg { width: 26px; height: 23px; }
  .seg button, .seg a { padding: 0 10px; }
}
body.video-full .install, body.immersive .install, body.phone-watch .install { display: none; }
.topbar .right { margin-left: auto; }

/* Repeat / Shuffle on the watch page */
.w-side-head { flex-wrap: wrap; }
.w-modes { display: flex; align-items: center; }
.mode-btn {
  display: inline-flex; align-items: center; height: 32px; padding: 0 10px 0 6px; margin-right: 8px; border-radius: 16px;
  color: var(--text-2); font-size: 13px; font-weight: 500; background: var(--surface);
}
.mode-btn .ico { width: 20px; height: 20px; margin-right: 4px; }
.mode-btn.on { background: var(--text); color: var(--bg); }
.w-modes .switch { margin-left: 4px; }
@media (max-width: 420px) { .mode-btn span { display: none; } .mode-btn { padding: 0 6px; } .mode-btn .ico { margin-right: 0; } }
