@font-face {
      font-family: "Vazirmatn";
      src: url("assets/Vazirmatn.ttf") format("truetype");
      font-weight: 100 900;
      font-display: swap;
    }
    /* The app's palette: the system colours, plus YouTube Red #FF0033. */
    :root {
      --bg: #ffffff;
      --label: #000000;
      --secondary: rgba(60, 60, 67, 0.6);
      --tertiary: rgba(60, 60, 67, 0.3);
      --fill: rgba(120, 120, 128, 0.16);
      --block: rgba(0, 0, 0, 0.09);
      --separator: rgba(60, 60, 67, 0.29);
      --bar: rgba(249, 249, 249, 0.86);
      --red: #ff0033;
      color-scheme: light dark;
    }
    @media (prefers-color-scheme: dark) {
      :root {
        --bg: #000000;
        --label: #ffffff;
        --secondary: rgba(235, 235, 245, 0.6);
        --tertiary: rgba(235, 235, 245, 0.3);
        --fill: rgba(120, 120, 128, 0.32);
        --block: rgba(255, 255, 255, 0.09);
        --separator: rgba(84, 84, 88, 0.6);
        --bar: rgba(22, 22, 22, 0.86);
      }
    }
    * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
    [hidden] { display: none !important; }
    html, body { margin: 0; background: var(--bg); color: var(--label); }
    body {
      font: 15px/1.4 "Vazirmatn", -apple-system, system-ui, sans-serif;
      padding-bottom: calc(64px + env(safe-area-inset-bottom));
      -webkit-font-smoothing: antialiased;
    }
    body.watching { overflow: hidden; }
    button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
    svg { width: 24px; height: 24px; fill: currentColor; display: block; }

    /* Navigation bar: the logo on the leading side, search on the trailing. */
    .nav {
      position: sticky; top: calc(48px + env(safe-area-inset-top)); z-index: 10;
      padding: 0 8px 0 12px;
      background: var(--bar); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
    }
    .navrow { height: 44px; display: flex; align-items: center; justify-content: space-between; }
    .navactions { display: flex; align-items: center; }
    .shield-icon { fill: none; stroke: currentColor; stroke-width: 1.7; }
    .logo { height: 40px; display: block; margin-inline-start: -6px; }
    .logo.dark { display: none; }
    @media (prefers-color-scheme: dark) {
      .logo.light { display: none; }
      .logo.dark { display: block; }
    }
    .navtitle { font-weight: 700; font-size: 17px; }
    .iconbtn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; }

    /* Chips, pinned under the bar the way the app pins them. */
    .chips { display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px 10px; scrollbar-width: none; }
    .chips::-webkit-scrollbar { display: none; }
    .chip {
      flex: none; padding: 8px 12px; border-radius: 999px; background: var(--fill);
      font-weight: 500; font-size: 14px; white-space: nowrap; line-height: 1.2;
    }
    .chip.on { background: var(--label); color: var(--bg); }

    /* Full-bleed 16:9 cards: avatar, title, "channel • views • age". */
    .card { display: block; width: 100%; text-align: start; }
    .thumb { position: relative; aspect-ratio: 16 / 9; background: var(--block); overflow: hidden; }
    .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
    .badge {
      position: absolute; bottom: 8px; right: 8px; direction: ltr;
      background: rgba(0, 0, 0, 0.8); color: #fff; border-radius: 4px;
      font: 600 12px/1 -apple-system, sans-serif; padding: 3px 4px;
    }
    .badge.live { background: var(--red); }
    .meta { display: flex; gap: 12px; padding: 12px 12px 16px; align-items: flex-start; }
    .avatar { width: 36px; height: 36px; border-radius: 50%; flex: none; background: var(--block); object-fit: cover; }
    .lines { min-width: 0; flex: 1; display: grid; gap: 4px; }
    .title {
      font-size: 15px; font-weight: 500; line-height: 1.35;
      text-align: left;
      display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
    }
    .sub { font-size: 12px; color: var(--secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

    /* Compact rows for search results and up next. */
    .row { display: flex; gap: 12px; padding: 8px 12px; width: 100%; text-align: start; align-items: flex-start; }
    .row .thumb { width: 160px; flex: none; border-radius: 8px; }
    .row .title { font-size: 13.5px; }

    .skel .thumb, .skel .avatar, .bar-skel { animation: pulse 1.1s ease-in-out infinite alternate; }
    .bar-skel { height: 12px; border-radius: 6px; background: var(--block); }
    @keyframes pulse { to { opacity: 0.45; } }

    .empty { padding: 56px 28px; text-align: center; display: grid; gap: 12px; justify-items: center; color: var(--secondary); }
    .empty svg { width: 44px; height: 44px; color: var(--tertiary); }
    .empty h2 { margin: 0; font-size: 20px; color: var(--label); }
    .empty p { margin: 0; max-width: 300px; }
    .button {
      padding: 10px 18px; border-radius: 999px; background: var(--red); color: #fff; font-weight: 600;
    }
    .button.plain { background: var(--fill); color: var(--label); }

    .searchfield {
      display: flex; align-items: center; gap: 8px; height: 38px; margin: 6px 12px 10px; padding: 0 12px;
      border-radius: 10px; background: var(--fill); color: var(--secondary);
    }
    .searchfield svg { width: 18px; height: 18px; }
    .searchfield input {
      flex: 1; border: 0; background: none; color: var(--label); font: 16px "Vazirmatn", -apple-system, sans-serif; outline: none;
    }

    /* Tab bar. */
    .tabs {
      position: fixed; z-index: 10; bottom: 0; inset-inline: 0;
      display: grid; grid-template-columns: repeat(4, 1fr);
      padding: 6px 4px env(safe-area-inset-bottom);
      background: var(--bar); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
      border-top: 0.5px solid var(--separator);
    }
    .tab { display: grid; justify-items: center; gap: 2px; padding: 4px 0 6px; font-size: 10.5px; color: var(--secondary); }
    .tab.on { color: var(--label); }

    /* Account: the tab wears the picture; channels and shelves scroll sideways. */
    .tabavatar { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; }
    .tab.on .tabavatar { outline: 1.5px solid var(--label); outline-offset: 1px; }
    .chans, .tiles { display: flex; gap: 12px; overflow-x: auto; padding: 8px 12px 14px; scrollbar-width: none; }
    .chans::-webkit-scrollbar, .tiles::-webkit-scrollbar { display: none; }
    .chan { width: 64px; flex: none; display: grid; gap: 6px; justify-items: center; font-size: 11px; color: var(--secondary); }
    .chan img { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; background: var(--block); }
    .chan span { width: 64px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; }
    .tile { width: 168px; flex: none; display: grid; gap: 6px; text-align: start; align-content: start; }
    .tile .thumb { border-radius: 8px; }
    .tile .title { font-size: 13px; }
    .profile { display: flex; gap: 14px; align-items: center; padding: 16px 12px 4px; }
    .profile img { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; background: var(--block); }
    .profile h2 { margin: 0; font-size: 22px; }
    .profile p { margin: 2px 0 0; color: var(--secondary); font-size: 13px; direction: ltr; text-align: left; }
    .foot { display: grid; gap: 12px; justify-items: start; padding: 20px 12px 28px; color: var(--secondary); font-size: 12.5px; }
    .tunnel-settings { display: grid; gap: 20px; padding: 24px 16px; max-width: 560px; margin-inline: auto; }
    .tunnel-settings h2, .tunnel-settings p { margin: 0; }
    .tunnel-settings h2 { font-size: 22px; }
    .tunnel-settings .button { justify-self: start; min-height: 44px; }
    .tunnel-toggle { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 16px; border-radius: 12px; background: var(--fill); }
    .tunnel-switch { appearance: none; width: 48px; height: 28px; margin: 0; border-radius: 999px; background: var(--tertiary); position: relative; flex: none; }
    .tunnel-switch::before { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--bg); }
    .tunnel-switch:disabled { opacity: .6; }
    .tunnel-notice { color: var(--secondary); line-height: 1.7; text-align: left; }

    /* Watch page: the player pinned at the top, then title, channel, up next. */
    .watch { position: fixed; inset: 0; z-index: 50; background: var(--bg); overflow-y: auto; }
    .player {
      position: sticky; top: 0; z-index: 2; background: #000;
      padding-top: 0;
    }
    .player .frame { aspect-ratio: 16 / 9; }
    .player iframe { width: 100%; height: 100%; border: 0; display: block; }
    .watchbar { display: flex; justify-content: space-between; align-items: center; padding: 4px 8px 0 12px; }
    .watchbar .button { padding: 8px 14px; font-size: 13px; text-decoration: none; }
    .wtitle { margin: 8px 12px 4px; font-size: 18px; font-weight: 700; line-height: 1.35; text-align: left; }
    .wstats { margin: 0 12px 12px; font-size: 12px; color: var(--secondary); }
    .owner { display: flex; gap: 12px; align-items: center; padding: 4px 12px 12px; }
    .owner b { display: block; font-size: 15px; }
    .owner span { font-size: 12px; color: var(--secondary); }
    .desc {
      margin: 0 12px 12px; padding: 12px; border-radius: 12px; background: var(--fill);
      font-size: 13px; white-space: pre-wrap; max-height: 6em; overflow: hidden;
    }
    .desc.open { max-height: none; }
    .section { margin: 8px 12px 6px; font-size: 17px; font-weight: 700; }
    .note { margin: 0 12px 12px; font-size: 12px; color: var(--secondary); }
  
    body { padding-top: calc(48px + env(safe-area-inset-top)); }
    .greeting { position: fixed; top: 0; inset-inline: 0; z-index: 100; height: calc(48px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); display: grid; place-items: center; background: var(--bg); border-bottom: .5px solid var(--separator); font-size: 18px; }
    .watch { top: calc(48px + env(safe-area-inset-top)); padding-top: 0; }
    #playerHost { width: 100%; height: 100%; }
    .player iframe { aspect-ratio: 16 / 9; }
    .watchbar { flex-wrap: wrap; gap: 8px; }
    .watchbar .button { min-height: 44px; }
    .description { margin: 12px; padding: 12px; background: var(--fill); border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; text-align: left; }
    .description summary { cursor: pointer; }
    .searchfield { height: auto; min-height: 44px; }
    .searchfield input { min-width: 0; min-height: 44px; }
    .searchfield button { padding: 10px; min-height: 44px; }
    button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--red); outline-offset: 3px; }
    @media (prefers-reduced-motion: reduce) { .skel .thumb, .skel .avatar, .bar-skel { animation: none; } }
