/*
 * tv.brave.lv — web client.
 * Written to work on old and new browsers alike (iPhone Safari from iOS 12, Android 7+, desktop):
 * no aspect-ratio, inset, flex gap or clamp()-only values; modern features always have a fallback.
 * Brand accent is set by the --accent variable.
 */
:root {
  --bg: #000;
  --surface: #141414;
  --surface-2: #1d1d1d;
  --line: #2b2b2b;
  --text: #f4f4f4;
  --muted: #a7a7a7;
  --dim: #707070;
  --accent: #ffffff;
  --radius: 5px;
  --pad: 4vw;              /* side padding: 16px … 60px, see media queries at the end */
  --card-w: 21vw;          /* card width: 150px … 310px */
  --card-h: calc(var(--card-w) * .5625);
  --font: "Onest", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  --logo-font: "Arimo", "Helvetica Neue", Helvetica, Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; background: #000; background: var(--bg); color: #f4f4f4; color: var(--text); font-family: var(--font); -webkit-font-smoothing: antialiased; }
body { overflow-x: hidden; -webkit-tap-highlight-color: transparent; }
body.no-scroll { overflow: hidden; }
a { color: inherit; text-decoration: none; }
button { -webkit-appearance: none; appearance: none; font: inherit; color: inherit; cursor: pointer; border: 0; border-radius: 0; background: none; padding: 0; margin: 0; }
img { display: block; max-width: 100%; }
svg { flex: none; -webkit-flex-shrink: 0; }
:focus { outline: none; }
:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- Header ---------- */
.hdr {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  display: flex; align-items: center;
  padding: 16px var(--pad) 16px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  background: linear-gradient(180deg, rgba(0,0,0,.8) 10%, rgba(0,0,0,0));
  transition: background-color .35s;
}
.hdr.solid { background-color: rgba(0,0,0,.94); }
.hdr .brand-logo { margin-right: 32px; }
.brand-logo { margin: 0; font-family: var(--logo-font); font-weight: 700; font-size: 1.5rem; letter-spacing: -.035em; line-height: 1; color: #fff; white-space: nowrap; }
.brand-logo--xl { font-size: 3.6rem; font-size: clamp(2.8rem, 11vw, 5rem); }

/* ---------- App states ---------- */
body.booting .hdr, body.booting #app,
body.signed-out .hdr, body.signed-out #app { display: 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; }

/* ---------- Sign in ---------- */
.auth { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px 20px; padding-bottom: calc(32px + env(safe-area-inset-bottom, 0px)); }
.auth .brand-logo { margin-bottom: 52px; }
.auth-form { width: 100%; max-width: 340px; display: flex; flex-direction: column; }
.auth-form input { display: block; width: 100%; height: 54px; margin: 0 0 12px; padding: 0 18px; border: 1px solid #333; border-radius: 6px; background: #121212; color: #fff; font: inherit; font-size: 16px; -webkit-appearance: none; appearance: none; transition: border-color .2s; }
.auth-form input::-webkit-input-placeholder { color: #8a8a8a; }
.auth-form input::placeholder { color: #8a8a8a; }
.auth-form input:focus { outline: none; border-color: #fff; }
.btn-signin { display: block; width: 100%; height: 54px; margin-top: 8px; border-radius: 6px; background: #fff; color: #000; font-size: 16px; font-weight: 700; transition: background-color .2s; }
.btn-signin:hover { background: #dcdcdc; }
.btn-signin:disabled { opacity: .7; cursor: default; }
.btn-signin:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.auth-error { min-height: 1.4em; margin: 14px 0 0; color: #ff8f8f; font-size: .92rem; text-align: center; }
.auth-note { margin: 0 0 20px; color: var(--muted); text-align: center; }
.auth-retry { max-width: 340px; }
.boot-fail { max-width: 420px; text-align: center; color: #cfcfcf; line-height: 1.5; }
.boot-fail code { display: block; margin: 14px 0; padding: 10px; border-radius: 6px; background: #151515; color: #ff9b9b; font-size: .8rem; text-align: left; word-break: break-word; }

/* ---------- Account menu ---------- */
.user { position: relative; margin-left: 14px; }
.user-btn { display: flex; align-items: center; justify-content: center; }
.avatar { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 4px; background: #fff; color: #000; font-weight: 700; font-size: .95rem; }
.user-pop { position: absolute; right: 0; top: 44px; min-width: 200px; padding: 8px 0; border: 1px solid #2f2f2f; border-radius: 6px; background: rgba(12,12,12,.97); box-shadow: 0 12px 30px rgba(0,0,0,.6); }
.user-pop[hidden] { display: none; }
.user-name { padding: 8px 16px 10px; color: var(--muted); font-size: .88rem; border-bottom: 1px solid #262626; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-pop button { display: block; width: 100%; padding: 9px 16px; text-align: left; font-size: .92rem; }
.user-pop button:hover { background: #1f1f1f; text-decoration: underline; }
.user-pop button:focus-visible { background: #1f1f1f; outline: none; text-decoration: underline; }
.nav { display: flex; font-size: .93rem; color: #cfcfcf; }
.nav a { margin-right: 20px; transition: color .2s; white-space: nowrap; }
.nav a:last-child { margin-right: 0; }
.nav a:hover { color: #fff; }
.nav a.active { color: #fff; font-weight: 600; }
.search { margin-left: auto; display: flex; align-items: center; padding: 5px 6px; border: 1px solid transparent; border-radius: 4px; transition: border-color .25s, background-color .25s; }
.search.open { border-color: rgba(255,255,255,.85); background: rgba(0,0,0,.75); }
.search-btn { display: flex; width: 26px; height: 26px; align-items: center; justify-content: center; }
.search-btn svg { width: 22px; height: 22px; }
.search input { width: 0; margin-left: 4px; padding: 0; border: 0; border-radius: 0; outline: 0; background: transparent; color: #fff; font: inherit; font-size: 16px; -webkit-appearance: none; appearance: none; transition: width .3s; }
.search.open input { width: 240px; padding: 2px 6px; }
.search input::-webkit-search-decoration { -webkit-appearance: none; }
.search input::-webkit-search-cancel-button { filter: invert(1); }

@media (max-width: 720px) {
  .hdr { flex-wrap: wrap; }
  .hdr .brand-logo { font-size: 1.3rem; margin-right: 14px; }
  .nav { -webkit-order: 3; order: 3; width: 100%; margin-top: 10px; font-size: .88rem; }
  .nav a { margin-right: 14px; }
  .search.open input { width: 46vw; }
}

/* ---------- Hero ---------- */
.hero { position: relative; height: 84vh; max-height: 900px; min-height: 460px; overflow: hidden; background: var(--surface); }
.hero-slide { position: absolute; top: 0; right: 0; bottom: 0; left: 0; opacity: 0; visibility: hidden; transition: opacity 1.2s ease, visibility 0s 1.2s; }
.hero-slide.active { opacity: 1; visibility: visible; transition: opacity 1.2s ease; }
.hero-img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 25%; }
.hero-slide::after {
  content: ""; position: absolute; top: 0; right: 0; bottom: 0; left: 0;
  background:
    linear-gradient(77deg, rgba(0,0,0,.85) 0%, rgba(0,0,0,.45) 35%, rgba(0,0,0,0) 65%),
    linear-gradient(0deg, #000 0%, rgba(0,0,0,0) 30%);
}
.hero-content { position: absolute; z-index: 2; left: var(--pad); bottom: 130px; bottom: max(130px, 18vh); width: 86vw; max-width: 560px; }
.hero h1 { margin: 0 0 16px; font-size: 3rem; font-size: clamp(2.2rem, 5.4vw, 4.4rem); font-weight: 800; line-height: .98; letter-spacing: -.025em; }
.hero-desc { margin: 0 0 24px; font-size: 1.05rem; font-size: clamp(.98rem, 1.25vw, 1.15rem); line-height: 1.5; color: #e2e2e2; text-shadow: 0 1px 2px rgba(0,0,0,.5);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.hero-dots { position: absolute; z-index: 3; right: var(--pad); bottom: 140px; bottom: max(140px, 19vh); display: flex; }
.hero-dots i { width: 14px; height: 3px; margin-left: 6px; background: rgba(255,255,255,.35); border-radius: 2px; transition: background-color .4s, width .4s; }
.hero-dots i.active { width: 26px; background: #fff; }

.meta { display: flex; flex-wrap: wrap; align-items: center; margin-bottom: 8px; font-size: .95rem; color: #d6d6d6; }
.meta > * { margin: 0 14px 6px 0; }
.badge { padding: 0 6px; border: 1px solid rgba(255,255,255,.45); border-radius: 3px; font-size: .8rem; line-height: 1.5; }

.actions { display: flex; flex-wrap: wrap; align-items: center; margin-bottom: -10px; }
.actions > * { margin: 0 10px 10px 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; padding: .72em 1.7em .72em 1.4em; border-radius: 4px; font-weight: 700; font-size: 1.05rem; line-height: 1.2; transition: background-color .2s, transform .1s; white-space: nowrap; }
.btn:active { transform: scale(.97); }
.btn svg { width: 1.45em; height: 1.45em; margin-right: 10px; }
.btn-play { background: #fff; color: #000; }
.btn-play:hover { background: rgba(255,255,255,.78); }
.btn-ghost { background: rgba(109,109,110,.7); color: #fff; }
.btn-ghost:hover { background: rgba(109,109,110,.45); }
.btn.disabled { opacity: .6; pointer-events: none; }
.btn-round { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; border: 2px solid rgba(255,255,255,.55); background: rgba(30,30,30,.6); transition: border-color .2s; }
.btn-round:hover { border-color: #fff; }
.btn-round svg { width: 22px; height: 22px; }

@media (max-width: 560px) {
  .hero { height: 78vh; }
  .hero-content { bottom: 120px; bottom: max(120px, 15vh); }
  .hero .btn { padding: .62em 1.25em .62em 1.05em; font-size: .95rem; }
  .hero-dots { display: none; }
  .hero-desc { -webkit-line-clamp: 2; }
}

/* ---------- Rows ---------- */
.rows { position: relative; z-index: 3; margin-top: -100px; padding-bottom: 40px; }
.rows.no-hero { margin-top: 0; padding-top: 110px; }
.row { margin-bottom: 32px; }
.row-title { margin: 0 var(--pad) 4px; font-size: 1.2rem; font-size: clamp(1.02rem, 1.4vw, 1.4rem); font-weight: 600; }
.row-wrap { position: relative; }
.row-track {
  display: flex; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
  -webkit-scroll-snap-type: x mandatory; scroll-snap-type: x mandatory; scroll-padding-left: var(--pad);
  padding: 14px var(--pad); scrollbar-width: none;
}
.row-track::-webkit-scrollbar { display: none; }
.row-track > * { margin-right: 8px; }
.row-track::after { content: ""; flex: 0 0 1px; -webkit-flex: 0 0 1px; margin-left: calc(var(--pad) - 9px); } /* right padding inside a scroller (Safari ignores it otherwise) */
.row-arrow {
  position: absolute; top: 14px; bottom: 14px; z-index: 4; width: calc(var(--pad) - 6px); min-width: 34px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.55); font-size: 2.6rem; line-height: 1; opacity: 0; transition: opacity .2s;
}
.row-arrow.left { left: 0; border-radius: 0 4px 4px 0; }
.row-arrow.right { right: 0; border-radius: 4px 0 0 4px; }
.row-wrap:hover .row-arrow { opacity: 1; }
.row-arrow:hover { background: rgba(0,0,0,.75); }
@media (hover: none) { .row-arrow { display: none; } }

/* 16:9 cards without aspect-ratio: the ::before spacer sets the height, content is positioned over it */
.card {
  position: relative; display: block; -webkit-flex: 0 0 var(--card-w); flex: 0 0 var(--card-w); width: var(--card-w);
  scroll-snap-align: start; border-radius: var(--radius); overflow: hidden; background: var(--surface-2);
  transition: transform .28s ease, box-shadow .28s ease; -webkit-transform: translateZ(0); /* Safari: clip children to rounded corners */
}
.card::before { content: ""; display: block; padding-top: 56.25%; }
.card img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }
.card-fallback { position: absolute; top: 0; right: 0; bottom: 0; left: 0; display: flex; align-items: center; justify-content: center; padding: 14px 14px 40px; text-align: center; font-weight: 700; font-size: 1.05rem; color: #8f8f8f; background: linear-gradient(140deg, #262626, #121212); }
.card-info { position: absolute; left: 0; right: 0; bottom: 0; padding: 34px 10px 8px; background: linear-gradient(0deg, rgba(0,0,0,.88), rgba(0,0,0,0)); }
.card.has-progress .card-info { padding-bottom: 16px; }
.card-title { font-size: .9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { margin-top: 1px; font-size: .74rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-progress { position: absolute; left: 10px; right: 10px; bottom: 7px; height: 3px; border-radius: 2px; background: rgba(255,255,255,.28); }
.card-progress i { display: block; height: 100%; border-radius: 2px; background: var(--accent); }
@media (hover: hover) {
  .card:hover { transform: scale(1.07); z-index: 2; box-shadow: 0 12px 28px rgba(0,0,0,.7); }
}
.card:focus-visible { transform: scale(1.07); z-index: 2; outline: 3px solid #fff; outline-offset: 0; box-shadow: 0 12px 28px rgba(0,0,0,.7); }
.row-track .card:first-child { transform-origin: left center; }

/* ---------- Grid pages ---------- */
.page { padding: 120px var(--pad) 60px; min-height: 70vh; }
.page h1 { margin: 0 0 24px; font-size: 1.7rem; font-size: clamp(1.4rem, 2.2vw, 2rem); font-weight: 700; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); grid-gap: 26px 10px; gap: 26px 10px; }
@media (max-width: 560px) { .grid { grid-template-columns: 1fr 1fr; grid-gap: 18px 8px; gap: 18px 8px; } }
.grid .card { -webkit-flex: none; flex: none; width: auto; }
.empty { padding: 140px 20px 80px; text-align: center; color: var(--muted); }
.empty h2 { margin: 0 0 8px; color: var(--text); font-size: 1.5rem; }
.empty .btn { margin-top: 20px; }

/* ---------- Title details (modal) ---------- */
.modal-overlay { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 100; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 30px 10px 40px; padding-top: calc(30px + env(safe-area-inset-top, 0px)); background: rgba(0,0,0,.72); animation: fade .2s ease; }
.modal { position: relative; max-width: 880px; margin: 0 auto; overflow: hidden; border-radius: 9px; background: #181818; box-shadow: 0 24px 70px rgba(0,0,0,.75); animation: pop .28s cubic-bezier(.2,.8,.3,1); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(16px) scale(.97); } }
.modal-close { position: absolute; top: 14px; right: 14px; z-index: 5; width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; border-radius: 50%; background: #181818; }
.modal-close svg { width: 20px; height: 20px; }
.modal-hero { position: relative; width: 100%; height: 56.25vw; max-height: 495px; background: #0d0d0d; }
.modal-hero img { width: 100%; height: 100%; object-fit: cover; }
.modal-hero::after { content: ""; position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: linear-gradient(0deg, #181818 0%, rgba(24,24,24,0) 55%); }
.modal-hero-content { position: absolute; z-index: 2; left: 32px; right: 32px; bottom: 28px; }
.modal-hero h2 { margin: 0 0 18px; font-size: 2.4rem; font-size: clamp(1.7rem, 4.4vw, 3rem); font-weight: 800; line-height: 1; letter-spacing: -.02em; }
.modal-body { padding: 6px 32px 44px; }
.modal-cols { display: grid; grid-template-columns: 1.8fr 1fr; grid-gap: 32px; gap: 32px; }
.modal-desc { margin: 0; line-height: 1.6; color: #e8e8e8; }
.side p { margin: 0 0 12px; font-size: .9rem; line-height: 1.5; color: #e0e0e0; }
.side span { color: var(--dim); }
.side a, .ep-license a { color: inherit; text-decoration: underline; }
@media (max-width: 640px) {
  .modal-hero-content { left: 18px; right: 18px; bottom: 16px; }
  .modal-body { padding: 6px 18px 36px; }
  .modal-cols { grid-template-columns: 1fr; grid-gap: 12px; gap: 12px; }
}

.episodes { margin-top: 38px; }
.episodes-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.episodes-head h3 { margin: 0 16px 0 0; font-size: 1.45rem; font-weight: 700; }
.season-select { padding: 9px 12px; border: 1px solid #4d4d4d; border-radius: 4px; background: #242424; color: #fff; font: inherit; font-size: 16px; font-weight: 600; }
.season-tabs { display: flex; flex-wrap: wrap; margin-bottom: 12px; }
.season-tab { margin: 0 8px 8px 0; padding: 6px 14px; border: 1px solid #4d4d4d; border-radius: 20px; font-weight: 600; }
.season-tab.active { border-color: #fff; }
.ep { display: grid; grid-template-columns: 30px 150px 1fr; align-items: center; grid-gap: 18px; gap: 18px; padding: 18px 16px; border-bottom: 1px solid var(--line); border-radius: 6px; transition: background-color .2s; }
.ep:first-child { border-top: 1px solid var(--line); }
.ep:hover { background: #2a2a2a; }
.ep:focus-visible { background: #2a2a2a; }
.ep-num { font-size: 1.45rem; color: var(--muted); text-align: center; }
.ep-img { position: relative; height: 84px; overflow: hidden; border-radius: 4px; background: #2a2a2a; }
.ep-img img { width: 100%; height: 100%; object-fit: cover; }
.ep-img .card-progress { left: 0; right: 0; bottom: 0; border-radius: 0; }
.ep-head { display: flex; justify-content: space-between; margin-bottom: 6px; font-weight: 600; }
.ep-head span { -webkit-flex: none; flex: none; margin-left: 12px; color: var(--muted); font-weight: 400; font-size: .9rem; }
.ep-desc { margin: 0; font-size: .88rem; line-height: 1.45; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.ep-license { margin: 6px 0 0; font-size: .78rem; color: var(--dim); }
@media (max-width: 560px) {
  .ep { grid-template-columns: 116px 1fr; grid-gap: 12px; gap: 12px; padding: 14px 6px; }
  .ep-num { display: none; }
  .ep-img { height: 65px; }
}

/* ---------- Player ---------- */
.player { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 200; background: #000; }
.player video { display: block; width: 100%; height: 100%; background: #000; }
.player-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; padding: 18px 22px 50px; padding-top: calc(18px + env(safe-area-inset-top, 0px)); background: linear-gradient(180deg, rgba(0,0,0,.75), rgba(0,0,0,0)); transition: opacity .35s; pointer-events: none; }
.player-top > * { pointer-events: auto; }
.player-back { -webkit-flex: none; flex: none; width: 46px; height: 46px; margin-right: 14px; display: flex; align-items: center; justify-content: center; border-radius: 50%; transition: background-color .2s; }
.player-back:hover { background: rgba(255,255,255,.14); }
.player-back svg { width: 28px; height: 28px; }
.player-title { font-size: 1.1rem; font-weight: 600; text-shadow: 0 1px 3px #000; }
.player-title span { display: block; margin-top: 2px; font-size: .88rem; font-weight: 400; color: #cfcfcf; }
.player-next { position: absolute; right: 28px; bottom: 96px; font-size: 1rem; transition: opacity .35s; }
.player-next svg { margin: 0 0 0 10px; }
.player.idle { cursor: none; }
.player.idle .player-top, .player.idle .player-next { opacity: 0; }
.player-msg { position: absolute; top: 0; right: 0; bottom: 0; left: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; text-align: center; color: #cfcfcf; }
.player-msg p { margin: 0 0 18px; max-width: 520px; line-height: 1.5; }
.spinner { width: 48px; height: 48px; border: 3px solid rgba(255,255,255,.18); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Loading ---------- */
.skel { background: linear-gradient(90deg, #121212 0%, #1c1c1c 50%, #121212 100%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
.skel-hero { height: 84vh; max-height: 900px; min-height: 460px; }
.skel-card { position: relative; -webkit-flex: 0 0 var(--card-w); flex: 0 0 var(--card-w); width: var(--card-w); border-radius: var(--radius); }
.skel-card::before { content: ""; display: block; padding-top: 56.25%; }
.grid .skel-card { width: auto; }
.skel-line { height: 18px; width: 180px; margin: 0 var(--pad) 4px; border-radius: 4px; }
.modal .skel-hero { height: 56.25vw; max-height: 495px; min-height: 0; }
@keyframes shimmer { to { background-position: -200% 0; } }

.footer { padding: 30px var(--pad) 40px; padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px)); font-size: .8rem; color: var(--dim); }
.footer p { margin: 0 0 6px; }
.footer-note { max-width: 760px; line-height: 1.5; }

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

/* ---------- Sizes by screen width (instead of clamp(), which old Safari doesn't know) ---------- */
@media (max-width: 400px)  { :root { --pad: 16px; } }
@media (min-width: 1500px) { :root { --pad: 60px; } }
@media (max-width: 714px)  { :root { --card-w: 150px; } }
@media (min-width: 1476px) { :root { --card-w: 310px; } }
@media (min-width: 1100px) { .hdr .brand-logo { margin-right: 44px; } .nav a { margin-right: 24px; } }
@media (min-width: 1800px) {
  :root { --card-w: 17vw; }
  html { font-size: 19px; }
}
@media (min-width: 2353px) { :root { --card-w: 400px; } }
