:root {
  --bg: #fff; --fg: #0f0f0f; --fg2: #606060; --chip: #f2f2f2; --line: #e5e5e5; --red: #ff0033;
  --head-h: 56px; --nav-h: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f0f0f; --fg: #f1f1f1; --fg2: #aaa; --chip: #272727; --line: #303030; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body {
  font: 14px/1.4 Roboto, "Segoe UI", system-ui, -apple-system, "Noto Sans Arabic", "Geeza Pro", Tahoma, sans-serif;
  padding-bottom: calc(var(--nav-h) + var(--safe-b));
  -webkit-text-size-adjust: 100%; overscroll-behavior-y: none;
}
a { color: inherit; text-decoration: none; }
img { -webkit-user-drag: none; -webkit-touch-callout: none; user-select: none; }
button { font: inherit; color: inherit; }

/* header */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center;
  height: calc(var(--head-h) + var(--safe-t)); padding: var(--safe-t) 16px 0; background: var(--bg);
}
.logo { display: flex; align-items: center; gap: 3px; direction: ltr; }
.logo svg { width: 29px; height: 20px; display: block; }
.logo b { font-family: "YouTube Sans", Roboto, "Arial Narrow", Arial, sans-serif; font-size: 20px; font-weight: 700; letter-spacing: -1px; }

/* bottom nav */
.bnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: flex;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--bg); border-top: 1px solid var(--line);
}
.bnav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: 10px; }
.bnav svg { width: 24px; height: 24px; }
.bnav .ic { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; }
.bnav .ic-in { fill: currentColor; }
.bnav a.on .ic { fill: currentColor; }
.bnav a.on .ic-in { fill: var(--bg); }

/* channel cards */
.chs { display: flex; gap: 6px; overflow-x: auto; padding: 4px 12px 14px; scrollbar-width: none; }
.chs::-webkit-scrollbar { display: none; }
.ch { flex: 0 0 auto; width: 88px; padding: 6px 4px; text-align: center; border-radius: 12px; }
.ch:active { background: var(--chip); }
.ch .av, .ch .av0 { width: 64px; height: 64px; margin: 0 auto; }
.ch span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 6px; font-size: 12px; line-height: 1.3; }
.av { display: block; border-radius: 50%; object-fit: cover; background: var(--chip); flex: none; }
.av0 { display: flex; align-items: center; justify-content: center; border-radius: 50%; background: #c00; color: #fff; font-weight: 700; flex: none; }

/* video grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 28px 16px; padding: 4px 16px 28px; }
.vc { display: block; min-width: 0; }
.thumb { position: relative; aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden; background: var(--chip); }
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.dur {
  position: absolute; bottom: 6px; inset-inline-end: 6px; padding: 1px 5px; border-radius: 4px;
  background: rgba(0,0,0,.8); color: #fff; font-size: 12px; font-weight: 500; direction: ltr;
}
.meta { display: flex; gap: 12px; margin-top: 10px; }
.meta .av, .meta .av0 { width: 36px; height: 36px; font-size: 14px; }
.txt { min-width: 0; }
.txt h3 { margin: 0; font-size: 15px; font-weight: 500; line-height: 1.38; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.txt p { margin: 3px 0 0; color: var(--fg2); font-size: 12.5px; }
@media (max-width: 599px) {
  .grid { grid-template-columns: 1fr; padding: 0 0 24px; gap: 22px; }
  .grid .thumb { border-radius: 0; }
  .grid .meta { padding: 0 12px; }
}

/* shorts shelf */
.shelf { padding: 4px 0 26px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.shelf h2 { display: flex; align-items: center; gap: 8px; margin: 0 16px 12px; font-size: 18px; font-weight: 700; }
.shelf h2 svg { width: 26px; height: 26px; }
.row { display: flex; gap: 8px; overflow-x: auto; padding: 0 16px; scrollbar-width: none; }
.row::-webkit-scrollbar { display: none; }
.sc { flex: 0 0 auto; width: min(44vw, 200px); }
.sc .thumb { aspect-ratio: 9 / 16; border-radius: 12px; }
.sc h3 { margin: 6px 0 0; font-size: 14px; font-weight: 500; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.sc p { margin: 2px 0 0; color: var(--fg2); font-size: 12px; }

/* channel page */
.chead { display: flex; align-items: center; gap: 16px; padding: 12px 16px 20px; }
.chead .av, .chead .av0 { width: 72px; height: 72px; font-size: 28px; }
.chead h1 { margin: 0; font-size: 22px; font-weight: 700; }
.chead p { margin: 4px 0 0; color: var(--fg2); font-size: 13px; }

.empty { padding: 80px 24px; text-align: center; color: var(--fg2); font-size: 15px; }

/* watch */
.watch { display: grid; grid-template-columns: minmax(0, 1fr); }
.pwrap { position: sticky; top: calc(var(--head-h) + var(--safe-t)); z-index: 10; aspect-ratio: 16 / 9; background: #000; }
.pwrap iframe, .pwrap .pl { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.shield { position: absolute; top: 0; left: 0; right: 0; height: 20%; z-index: 2; }
.endscr {
  position: absolute; inset: 0; z-index: 3; display: none; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap;
  padding: 12px; background: rgba(0,0,0,.88); color: #fff;
}
.pwrap.ended .endscr, .pwrap.failed .endscr { display: flex; }
.endscr .again { display: flex; flex-direction: column; align-items: center; gap: 6px; background: none; border: 0; cursor: pointer; font-size: 13px; }
.endscr .again svg { width: 54px; height: 54px; fill: #fff; }
.endscr .nx { width: min(34%, 220px); color: #fff; }
.endscr .nx .thumb { border-radius: 8px; }
.endscr .nx h3 { margin: 6px 0 0; font-size: 12.5px; font-weight: 500; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.endscr .msg { width: 100%; text-align: center; font-size: 14px; }
.winfo { padding: 12px 12px 4px; }
.winfo h1 { margin: 0; font-size: 18px; font-weight: 700; line-height: 1.35; }
.winfo .wm { margin: 6px 0 0; color: var(--fg2); font-size: 12.5px; }
.wch { display: flex; align-items: center; gap: 12px; padding: 14px 12px; }
.wch .av, .wch .av0 { width: 40px; height: 40px; }
.wch b { font-size: 15px; font-weight: 600; }
.side { padding: 8px 0 24px; display: grid; gap: 20px; }
@media (min-width: 600px) and (max-width: 999px) {
  .side { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); padding: 8px 12px 24px; gap: 24px 14px; }
}
@media (max-width: 599px) {
  .side .thumb { border-radius: 0; }
  .side .meta { padding: 0 12px; }
}
@media (min-width: 1000px) {
  .watch { grid-template-columns: minmax(0, 1fr) 400px; grid-template-rows: auto 1fr; gap: 0 24px; padding: 8px 24px 24px; }
  .pwrap { position: relative; top: 0; border-radius: 12px; overflow: hidden; }
  .wmain { grid-column: 1; }
  .side { grid-column: 2; grid-row: 1 / span 2; padding: 0; gap: 10px; align-content: start; }
  .side .vc { display: flex; gap: 8px; }
  .side .thumb { width: 168px; flex: none; border-radius: 8px; }
  .side .meta { margin-top: 0; }
  .side .meta .av, .side .meta .av0 { display: none; }
  .side .txt h3 { font-size: 14px; }
  .winfo { padding: 14px 0 0; }
  .wch { padding: 14px 0; }
}

/* shorts player */
body.mode-shorts { background: #000; color: #fff; }
body.mode-shorts .top { display: none; }
body.mode-shorts .bnav { background: #0f0f0f; border-top-color: #222; color: #fff; --bg: #0f0f0f; }
.shorts {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 18px;
  height: calc(100vh - var(--nav-h) - var(--safe-b)); height: calc(100dvh - var(--nav-h) - var(--safe-b));
  padding-top: var(--safe-t); background: #000; overflow: hidden; touch-action: none;
}
.stage { position: relative; height: 100%; aspect-ratio: 9 / 16; max-width: 100%; overflow: hidden; background: #000; }
@media (min-width: 600px) { .shorts { padding-block: 14px; } .stage { border-radius: 16px; } }
@media (max-width: 599px) { .stage { width: 100%; aspect-ratio: auto; } }
.stage .pl, .stage iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; z-index: 1; }
.stage .bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 2; pointer-events: none; transition: opacity .25s; }
.stage.started .bg { opacity: 0; }
.stage .big {
  position: absolute; top: 50%; left: 50%; z-index: 3; width: 72px; height: 72px; margin: -36px 0 0 -36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.55); pointer-events: none;
}
.stage .big svg { width: 40px; height: 40px; fill: #fff; margin-left: 4px; }
.stage.started .big { display: none; }
.stage .touch { position: absolute; inset: 0 0 64px; z-index: 4; pointer-events: none; touch-action: none; }
.stage.armed .touch { pointer-events: auto; }
.stage .info {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 5; padding: 60px 16px 16px; pointer-events: none;
  background: linear-gradient(transparent, rgba(0,0,0,.65)); color: #fff;
}
.stage .info a { pointer-events: auto; display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
.stage .info .av, .stage .info .av0 { width: 32px; height: 32px; }
.stage .info p { margin: 8px 0 0; font-size: 14px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.stage .flash {
  position: absolute; top: 50%; left: 50%; z-index: 6; width: 64px; height: 64px; margin: -32px 0 0 -32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.5); opacity: 0; pointer-events: none; transition: opacity .35s;
}
.stage .flash.show { opacity: 1; transition: none; }
.stage .flash svg { width: 34px; height: 34px; fill: #fff; }
.snav { display: flex; flex-direction: column; gap: 16px; }
.snav button {
  width: 52px; height: 52px; border: 0; border-radius: 50%; background: #272727; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.snav button:disabled { opacity: .35; }
.snav svg { width: 28px; height: 28px; fill: #fff; }
@media (max-width: 599px) {
  .snav { position: absolute; inset-inline-start: 10px; top: 50%; transform: translateY(-50%); z-index: 7; gap: 12px; }
  .snav button { width: 40px; height: 40px; background: rgba(40,40,40,.55); }
  .snav svg { width: 24px; height: 24px; }
}
