/* Qivo TV – iOS / mobile PWA styles. Palette and artwork follow the TV app
   (css/variables.css, style.css, homepage.css): navy background image, teal focus #004E64,
   blue accents #1c6f96 / #4664d7, yellow favourites. */

@font-face { font-family: 'Roboto'; src: url('../fonts/roboto-regular-webfont.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Roboto'; src: url('../fonts/roboto-medium-webfont.woff2') format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Roboto'; src: url('../fonts/roboto-bold-webfont.woff2') format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Font Awesome 5 Free'; src: url('../fonts/fa-solid-900.woff2') format('woff2'); font-weight: 900; font-display: block; }

:root {
    --bg: #0b111a;
    --bg-2: #121b27;
    --panel: rgba(18, 27, 39, 0.86);
    --panel-solid: #16212f;
    --line: rgba(255, 255, 255, 0.09);
    --focus: #004E64;
    --focus-strong: #00708f;
    --accent: #1c6f96;
    --accent-2: #4664d7;
    --orange: #ff7a1f;
    --yellow: #ffd600;
    --text: #ffffff;
    --text-2: #c9d2dc;
    --muted: #8c99a8;
    --danger: #ff5b5b;
    --radius: 12px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --topbar-h: 52px;
    --vh: 1vh;
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
    margin: 0; height: 100%; background: var(--bg); color: var(--text);
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 15px; line-height: 1.4;
    -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
    overflow: hidden;
}
body { position: fixed; inset: 0; width: 100%; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible, a:focus-visible, input:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--focus-strong); outline-offset: 2px; }
img { max-width: 100%; }
a { color: var(--orange); }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-weight: 400; }

/* Font Awesome subset */
.fa { font-family: 'Font Awesome 5 Free'; font-weight: 900; font-style: normal; display: inline-block; line-height: 1; -webkit-font-smoothing: antialiased; font-variant: normal; text-rendering: auto; }
.fa-arrow-left:before{content:"\f060"} .fa-audio-description:before{content:"\f29e"} .fa-backward:before{content:"\f04a"}
.fa-check:before{content:"\f00c"} .fa-chevron-down:before{content:"\f078"} .fa-chevron-left:before{content:"\f053"}
.fa-chevron-right:before{content:"\f054"} .fa-closed-captioning:before{content:"\f20a"} .fa-compress:before{content:"\f066"}
.fa-copy:before{content:"\f0c5"} .fa-expand:before{content:"\f065"} .fa-film:before{content:"\f008"}
.fa-forward:before{content:"\f04e"} .fa-globe:before{content:"\f0ac"} .fa-layer-group:before{content:"\f5fd"}
.fa-list:before{content:"\f03a"} .fa-lock:before{content:"\f023"} .fa-pause:before{content:"\f04c"}
.fa-play:before{content:"\f04b"} .fa-plus-square:before{content:"\f0fe"} .fa-search:before{content:"\f002"}
.fa-share-square:before{content:"\f14d"} .fa-star:before{content:"\f005"} .fa-step-backward:before{content:"\f048"}
.fa-step-forward:before{content:"\f051"} .fa-th-large:before{content:"\f009"} .fa-times:before{content:"\f00d"}
.fa-tv:before{content:"\f26c"} .fa-user:before{content:"\f007"} .fa-volume-mute:before{content:"\f6a9"}
.fa-volume-up:before{content:"\f028"} .fa-clock:before{content:"\f017"} .fa-redo:before{content:"\f01e"}
.svg-icon { width: 22px; height: 22px; fill: currentColor; display: block; }

/* ------------------------------------------------------------------ app shell */
#app {
    position: absolute; inset: 0;
    background: var(--bg) url('../images/background.jpg') center / cover no-repeat;
}
.screen {
    position: absolute; inset: 0; display: none; flex-direction: column;
    overflow: hidden;
    padding-left: var(--safe-left); padding-right: var(--safe-right);
}
.screen.active { display: flex; animation: screen-in 0.18s ease-out; }
@keyframes screen-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .screen.active { animation: none; } }

.scroll-y { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }

.top-bar {
    flex: 0 0 auto; display: flex; align-items: center; gap: 8px;
    min-height: calc(var(--topbar-h) + var(--safe-top));
    padding: var(--safe-top) 10px 0 4px;
    background: rgba(8, 13, 20, 0.92);
    border-bottom: 1px solid var(--line);
    position: relative; z-index: 5;
}
.top-bar.transparent { background: transparent; border: 0; position: absolute; top: 0; left: var(--safe-left); right: var(--safe-right); }
.top-bar-title { flex: 1 1 auto; min-width: 0; font-size: 17px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
    min-width: 44px; height: 44px; border-radius: 22px; display: inline-flex; align-items: center; justify-content: center;
    font-size: 18px; color: var(--text); flex: 0 0 auto; transition: background 0.15s, transform 0.1s;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.14); transform: scale(0.94); }
.icon-btn.small { min-width: 34px; height: 34px; font-size: 14px; }
.icon-btn.big { min-width: 56px; height: 56px; font-size: 22px; }
.icon-btn.huge { min-width: 72px; height: 72px; font-size: 30px; background: rgba(0, 0, 0, 0.35); border-radius: 36px; }

.btn {
    min-height: 46px; padding: 10px 20px; border-radius: 10px; font-weight: 500; font-size: 16px;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    border: 2px solid transparent; transition: background 0.15s, transform 0.1s;
    text-decoration: none; /* also used on <a> (external player links) */
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--focus); border-color: var(--accent); color: #fff; }
.btn-primary:active { background: var(--focus-strong); }
.btn-secondary { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.18); color: #fff; }
.btn-sm { min-height: 38px; padding: 6px 16px; font-size: 14px; }
.btn-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.btn-row .btn { flex: 1 1 130px; max-width: 220px; }

.text-input {
    width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.2); background: rgba(0, 0, 0, 0.35); color: #fff;
    font: inherit; font-size: 16px; /* ≥16px prevents iOS zoom on focus */
    -webkit-appearance: none; appearance: none;
}
.text-input:focus { border-color: var(--accent); outline: none; background: rgba(0, 0, 0, 0.5); }
.search-box { position: relative; display: flex; align-items: center; }
.search-box .fa { position: absolute; left: 12px; color: var(--muted); font-size: 14px; pointer-events: none; }
.search-box .text-input { padding-left: 34px; }
.search-box.compact { flex: 0 1 220px; min-width: 120px; }
.search-box.compact .text-input { min-height: 38px; padding-top: 6px; padding-bottom: 6px; }
input[type=search]::-webkit-search-decoration { -webkit-appearance: none; }

.spinner {
    width: 44px; height: 44px; border-radius: 50%;
    border: 4px solid rgba(255, 255, 255, 0.15); border-top-color: var(--orange);
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ boot */
#screen-boot { justify-content: center; align-items: center; overflow-y: auto; }
.boot-inner {
    width: 100%; max-width: 560px; padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
    text-align: center; margin: auto;
}
.boot-logo { width: min(62vw, 300px); margin-bottom: 18px; }
.boot-tagline { color: var(--text-2); font-size: 16px; margin-bottom: 26px; }
#boot-progress .spinner { margin: 0 auto; }
.boot-status { margin-top: 16px; color: var(--muted); min-height: 1.4em; font-size: 14px; }
.issue-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px 18px; text-align: center; }
.issue-text { font-size: 16px; line-height: 1.55; color: var(--text-2); }
.issue-text .expire-date { color: var(--orange); font-weight: 500; }
.device-info-card {
    margin: 16px auto 0; padding: 12px 14px; border: 3px solid var(--accent); border-radius: 14px;
    display: inline-grid; grid-template-columns: auto auto auto; gap: 6px 10px; align-items: center; text-align: left;
}
.device-info-card .label { color: var(--muted); }
.device-info-card .value { color: var(--orange); font-weight: 700; font-size: 17px; letter-spacing: 0.5px; font-variant-numeric: tabular-nums; }
.more-info { margin-top: 14px; font-size: 14px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.more-info a { word-break: break-all; }

/* ------------------------------------------------------------------ home */
#screen-home { overflow-y: auto; -webkit-overflow-scrolling: touch; }
#screen-home.active { display: flex; flex-direction: column; }
.home-header {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: calc(14px + var(--safe-top)) 18px 6px;
}
.home-logo { width: 130px; }
.home-clock { text-align: right; }
.home-clock .current-time { font-size: 22px; font-weight: 500; }
.home-clock .current-date { font-size: 13px; color: var(--muted); }
.home-device-info {
    margin: 8px 18px 0; padding: 8px 14px; border: 3px solid var(--accent); border-radius: 14px; color: #ddd;
    display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: 14px; justify-content: center;
}
.home-device-info .value { color: #fff; font-weight: 700; letter-spacing: 0.3px; font-variant-numeric: tabular-nums; }
.install-hint {
    margin: 10px 18px 0; padding: 8px 6px 8px 14px; border-radius: 12px; background: rgba(70, 100, 215, 0.25);
    border: 1px solid rgba(70, 100, 215, 0.5); display: flex; align-items: center; gap: 10px; font-size: 14px;
}
.install-hint span { flex: 1; }
.home-playlists { padding: 14px 0 0; }
.playlist-error {
    margin: 0 18px 10px; padding: 10px 14px; border-radius: 10px; color: var(--danger);
    background: rgba(255, 91, 91, 0.12); border: 1px solid rgba(255, 91, 91, 0.35); text-align: center;
}
.playlist-error-message { font-weight: 500; }
.playlist-error-details { margin-top: 4px; font-size: 12px; color: var(--text-2); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.playlist-error .btn { margin-top: 8px; }
.home-playlists-wrapper {
    display: flex; gap: 10px; overflow-x: auto; padding: 2px 18px 4px; scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.home-playlists-wrapper::-webkit-scrollbar { display: none; }
.playlist-chip {
    flex: 0 0 auto; display: flex; align-items: center; gap: 10px; max-width: 70vw;
    padding: 10px 16px; border-radius: 24px; background: rgba(255, 255, 255, 0.07);
    border: 2px solid rgba(255, 255, 255, 0.12); scroll-snap-align: start;
}
.playlist-chip.playing { border-color: var(--accent); background: var(--focus); }
.playlist-chip .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.playlist-state { width: 10px; height: 10px; border-radius: 50%; background: rgba(255, 255, 255, 0.25); flex: 0 0 auto; }
.playing .playlist-state { background: #3ee07b; box-shadow: 0 0 8px #3ee07b; }
.home-menu {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px 6px;
    padding: 16px 12px 8px; max-width: 760px; width: 100%; margin: auto;
}
.menu-item {
    aspect-ratio: 433 / 439; width: 100%; background-size: 100% 100%; background-repeat: no-repeat;
    position: relative; transition: transform 0.15s;
}
.menu-item:active, .menu-item:focus-visible { transform: scale(1.06); }
.menu-item.live { background-image: url('../images/jlive_tv.png'); }
.menu-item.live:active, .menu-item.live:focus-visible { background-image: url('../images/jlive_tv2.png'); }
.menu-item.vod { background-image: url('../images/jmovies.png'); }
.menu-item.vod:active, .menu-item.vod:focus-visible { background-image: url('../images/jmovies2.png'); }
.menu-item.series { background-image: url('../images/jtv_series.png'); }
.menu-item.series:active, .menu-item.series:focus-visible { background-image: url('../images/jtv_series2.png'); }
.menu-item.settings { background-image: url('../images/jsettings.png'); }
.menu-item.settings:active, .menu-item.settings:focus-visible { background-image: url('../images/jsettings2.png'); }
.menu-item.catchup { background-image: url('../images/jcatchup.png'); }
.menu-item.catchup:active, .menu-item.catchup:focus-visible { background-image: url('../images/jcatchup1.png'); }
.menu-item.reload { background-image: url('../images/jreload.png'); }
.menu-item.reload:active, .menu-item.reload:focus-visible { background-image: url('../images/jreload1.png'); }
@media (hover: hover) {
    .menu-item:hover { transform: scale(1.06); }
    .menu-item.live:hover { background-image: url('../images/jlive_tv2.png'); }
    .menu-item.vod:hover { background-image: url('../images/jmovies2.png'); }
    .menu-item.series:hover { background-image: url('../images/jtv_series2.png'); }
    .menu-item.settings:hover { background-image: url('../images/jsettings2.png'); }
    .menu-item.catchup:hover { background-image: url('../images/jcatchup1.png'); }
    .menu-item.reload:hover { background-image: url('../images/jreload1.png'); }
}
/* The tile artwork already carries its label; keep text for screen readers only. */
.menu-item-txt { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.home-footer { text-align: center; padding: 10px 16px calc(14px + var(--safe-bottom)); color: var(--text-2); font-size: 14px; }
.playlist-expire-date { color: var(--orange); font-weight: 500; }

/* ------------------------------------------------------------------ player containers */
.player-container { position: relative; background: #000; overflow: hidden; }
.player-container video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
#main-video { display: block; }
body > #main-video { display: none; }
.video-loader { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.25); z-index: 2; pointer-events: none; }
.video-error { position: absolute; inset: 0; z-index: 3; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; background: #000; text-align: center; padding: 10px; }
.video-error img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0.55; }
.video-error-msg, .video-error .btn, .external-player { position: relative; }
.external-player { display: flex; flex-direction: column; align-items: center; gap: 6px; max-width: 92%; }
.external-player .btn-row { margin-top: 0; }
.external-player-text { font-size: 14px; text-shadow: 0 1px 3px #000; }
.external-store, .external-note a { color: var(--orange); font-size: 13px; }
.external-note { font-size: 13px; color: var(--text-2); margin: -6px 0 12px; }
.video-error-msg { font-size: 14px; color: #fff; text-shadow: 0 1px 3px #000; max-width: 90%; }
.tap-to-play {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 4;
    width: 76px; height: 76px; border-radius: 50%; background: rgba(0, 78, 100, 0.9); border: 3px solid var(--accent);
    font-size: 30px; display: flex; align-items: center; justify-content: center; padding-left: 5px;
}
.video-progress { height: 4px; background: rgba(255, 255, 255, 0.18); border-radius: 2px; overflow: hidden; }
.video-progress .progress-amount { height: 100%; width: 0; background: var(--orange); transition: width 0.4s; }

/* ------------------------------------------------------------------ live TV */
.live-layout { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.live-player-col { flex: 0 0 auto; }
.live-player { width: 100%; aspect-ratio: 16 / 9; max-height: 42vh; }
.channel-information { padding: 8px 12px 6px; background: rgba(8, 13, 20, 0.7); border-bottom: 1px solid var(--line); }
.channel-title-row { display: flex; align-items: center; gap: 6px; }
#channel-title { margin: 6px 0 2px; font-size: 16px; font-weight: 500; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#next-program-container { font-size: 13px; color: var(--text-2); max-height: 64px; overflow: hidden; }
.next-program-item { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 1px 0; }
.next-program-item.current { color: var(--yellow); }
.program-time { color: var(--muted); margin-right: 8px; font-variant-numeric: tabular-nums; }
.next-program-item.current .program-time { color: var(--yellow); }
.live-list-col { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.category-select {
    display: flex; align-items: center; gap: 10px; width: calc(100% - 20px); margin: 8px 10px 6px; padding: 10px 14px;
    border-radius: 10px; background: var(--focus); border: 2px solid var(--accent); text-align: left; font-weight: 500;
}
.category-select-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-columns { flex: 1 1 auto; display: flex; min-height: 0; }
.category-list { display: none; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.category-item {
    display: block; width: 100%; text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line);
    font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.category-item.current { background: var(--focus); }
.category-item .count { color: var(--muted); font-size: 12px; margin-left: 6px; }
.channel-list { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding-bottom: var(--safe-bottom); }
.channel-item {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 4px 6px 12px; min-height: 56px;
    border-bottom: 1px solid var(--line); text-align: left;
}
.channel-item.current { background: var(--focus); }
.channel-item:active { background: rgba(0, 78, 100, 0.6); }
.channel-number { width: 34px; flex: 0 0 auto; color: var(--muted); font-size: 13px; text-align: right; font-variant-numeric: tabular-nums; }
.channel-icon-wrapper { width: 52px; height: 38px; flex: 0 0 auto; display: flex; align-items: center; justify-content: center; background: rgba(255, 255, 255, 0.05); border-radius: 6px; overflow: hidden; }
.channel-icon { max-width: 100%; max-height: 100%; object-fit: contain; }
.channel-name { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.fav-toggle { color: rgba(255, 255, 255, 0.25); }
.fav-toggle.favourite { color: var(--yellow); }
.hint-bar { display: none; }
.hint-dot { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.hint-dot.yellow { background: var(--yellow); }

.live-overlay { position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; justify-content: space-between; background: linear-gradient(rgba(0,0,0,0.65), rgba(0,0,0,0) 30%, rgba(0,0,0,0) 55%, rgba(0,0,0,0.85)); }
.live-overlay-top { display: flex; align-items: center; gap: 4px; padding: calc(4px + var(--safe-top)) calc(8px + var(--safe-right)) 0 calc(4px + var(--safe-left)); }
.full-screen-channel-name { flex: 1; min-width: 0; font-size: 17px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-overlay-center { display: flex; justify-content: center; gap: 28px; }
.full-screen-information { padding: 0 calc(14px + var(--safe-right)) calc(12px + var(--safe-bottom)) calc(14px + var(--safe-left)); }
.fs-programmes { display: grid; grid-template-columns: auto 1fr 1fr; gap: 12px; align-items: start; margin-top: 10px; }
.full-screen-channel-logo { width: 64px; height: 48px; object-fit: contain; background: rgba(255,255,255,0.06); border-radius: 6px; }
.fs-programme-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.fs-programme.current .fs-name { color: var(--yellow); }
.fs-name { font-weight: 500; font-size: 15px; }
.fs-time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.fs-desc { color: var(--text-2); font-size: 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* Expanded ("full screen" on the TV) live player */
#screen-live.expanded .live-player {
    position: fixed; inset: 0; width: 100%; height: 100%; max-height: none; aspect-ratio: auto; z-index: 50;
}
#screen-live.expanded .live-player video { object-fit: contain; }
#screen-live:not(.expanded) .live-overlay { display: none !important; }

/* ------------------------------------------------------------------ search modal */
.search-modal { position: fixed; inset: 0; z-index: 80; background: rgba(0, 0, 0, 0.6); display: flex; justify-content: center; align-items: flex-start; padding: calc(10px + var(--safe-top)) 10px calc(10px + var(--safe-bottom)); }
.search-modal-card { width: 100%; max-width: 620px; max-height: 100%; display: flex; flex-direction: column; background: var(--panel-solid); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.search-modal-head { display: flex; gap: 6px; padding: 10px; align-items: center; }
.search-modal-head .search-box { flex: 1; }
.search-results { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.search-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 12px 14px; border-top: 1px solid var(--line); text-align: left; }
.search-item:active { background: var(--focus); }

/* ------------------------------------------------------------------ grid (movies / series / catch-up) */
.grid-layout { flex: 1 1 auto; display: flex; min-height: 0; }
.grid-main { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.poster-grid {
    flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 12px 10px; align-content: start;
    padding: 4px 10px calc(16px + var(--safe-bottom));
}
.poster-grid.channels { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.list-sentinel { grid-column: 1 / -1; height: 1px; }
.poster { position: relative; display: block; width: 100%; text-align: left; border-radius: 10px; }
.poster-img-wrap { position: relative; aspect-ratio: 2 / 3; border-radius: 10px; overflow: hidden; background: rgba(255, 255, 255, 0.06); border: 2px solid transparent; transition: border-color 0.15s, transform 0.12s; }
.channels .poster-img-wrap { aspect-ratio: 16 / 10; display: flex; align-items: center; justify-content: center; }
.poster-img-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.channels .poster-img-wrap img { object-fit: contain; width: 80%; height: 80%; }
.poster:active .poster-img-wrap { border-color: var(--accent); transform: scale(0.97); }
.poster-title { margin-top: 5px; font-size: 13px; color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.3; }
.favourite-badge { position: absolute; top: 6px; right: 6px; z-index: 1; width: 26px; height: 26px; border-radius: 13px; background: rgba(0, 0, 0, 0.65); color: var(--yellow); display: flex; align-items: center; justify-content: center; font-size: 13px; }
.empty-state { padding: 40px 20px; text-align: center; color: var(--muted); }
.grid-categories { width: 260px; flex: 0 0 auto; border-right: 1px solid var(--line); background: rgba(8, 13, 20, 0.55); padding-bottom: var(--safe-bottom); }

/* ------------------------------------------------------------------ detail screens */
.detail-screen { overflow-y: auto; -webkit-overflow-scrolling: touch; display: none; }
.detail-screen.active { display: block; }
.detail-backdrop { position: fixed; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0.35; filter: blur(2px); }
.detail-backdrop-overlay { position: fixed; inset: 0; background: linear-gradient(rgba(11,17,26,0.55), rgba(11,17,26,0.95) 70%); }
.detail-content {
    position: relative; display: flex; flex-direction: column; align-items: center; gap: 18px;
    padding: calc(var(--topbar-h) + var(--safe-top)) 18px calc(24px + var(--safe-bottom)); max-width: 1100px; margin: 0 auto;
}
.detail-left { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.detail-poster { width: 180px; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.6); background: rgba(255,255,255,0.06); }
.detail-right { width: 100%; }
.detail-name { font-size: 22px; margin: 0 0 10px; font-weight: 700; text-align: center; overflow-wrap: anywhere; }
.detail-info { display: grid; gap: 4px; font-size: 14px; color: var(--text-2); }
.detail-info .label { color: var(--muted); }
.detail-meta { font-size: 14px; color: var(--text-2); text-align: center; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0; }
.detail-actions .btn { flex: 1 1 150px; }
.detail-description { color: var(--text-2); font-size: 15px; line-height: 1.55; white-space: pre-line; overflow-wrap: anywhere; }
.detail-description.clamp { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.rating { position: relative; display: inline-block; font-size: 15px; letter-spacing: 1px; line-height: 1; }
.rating-lower { color: rgba(255, 255, 255, 0.25); }
.rating-upper { position: absolute; top: 0; left: 0; overflow: hidden; white-space: nowrap; color: var(--yellow); width: 0; }
.season-tabs { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.season-tabs::-webkit-scrollbar { display: none; }
.season-tab { flex: 0 0 auto; padding: 8px 14px; border-radius: 20px; background: rgba(255, 255, 255, 0.08); border: 2px solid rgba(255, 255, 255, 0.12); text-align: center; }
.season-tab .count { display: block; font-size: 11px; color: var(--muted); }
.season-tab.current { background: var(--focus); border-color: var(--accent); }
.episode-list { display: flex; flex-direction: column; gap: 8px; }
.episode-item { display: flex; gap: 12px; align-items: flex-start; padding: 8px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); text-align: left; width: 100%; border: 2px solid transparent; }
.episode-item.current { border-color: var(--accent); background: rgba(0, 78, 100, 0.45); }
.episode-item:active { background: var(--focus); }
.episode-img { width: 124px; aspect-ratio: 16 / 9; flex: 0 0 auto; border-radius: 8px; object-fit: cover; background: rgba(255,255,255,0.06); }
.episode-text { min-width: 0; }
.episode-title { font-weight: 500; font-size: 15px; }
.episode-desc { font-size: 12px; color: var(--muted); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.episode-progress { height: 3px; background: rgba(255,255,255,0.15); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.episode-progress > div { height: 100%; background: var(--orange); }

/* ------------------------------------------------------------------ catch-up EPG */
.epg-title-logo { width: 40px; height: 30px; object-fit: contain; }
.epg-layout { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.epg-dates { display: flex; gap: 8px; overflow-x: auto; padding: 10px; flex: 0 0 auto; scrollbar-width: none; }
.epg-dates::-webkit-scrollbar { display: none; }
.epg-date { flex: 0 0 auto; min-width: 92px; padding: 8px 12px; border-radius: 12px; background: rgba(255,255,255,0.07); border: 2px solid rgba(255,255,255,0.12); text-align: center; }
.epg-date.current { background: var(--focus); border-color: var(--accent); }
.epg-date-day { font-weight: 500; font-size: 14px; }
.epg-date-date { font-size: 12px; color: var(--muted); }
.epg-date.current .epg-date-date { color: var(--text-2); }
.epg-programmes { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 0 10px calc(14px + var(--safe-bottom)); }
.epg-programme { display: flex; gap: 10px; align-items: flex-start; width: 100%; text-align: left; padding: 12px; border-bottom: 1px solid var(--line); }
.epg-programme:active, .epg-programme.current { background: var(--focus); border-radius: 10px; }
.epg-programme-time { flex: 0 0 auto; width: 48px; color: var(--orange); font-weight: 500; font-variant-numeric: tabular-nums; }
.epg-clock-icon { width: 18px; height: 18px; flex: 0 0 auto; margin-top: 1px; }
.epg-programme-text { flex: 1; min-width: 0; }
.epg-programme-title { font-size: 15px; }
.epg-programme-desc { font-size: 12px; color: var(--muted); margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.epg-programme.open .epg-programme-desc { -webkit-line-clamp: unset; display: block; }

/* ------------------------------------------------------------------ VOD / series player */
#screen-player { background: #000; padding: 0; }
.vod-player { position: absolute; inset: 0; }
.vod-controls {
    position: absolute; inset: 0; z-index: 6; display: flex; flex-direction: column; justify-content: space-between;
    background: linear-gradient(rgba(0,0,0,0.7), rgba(0,0,0,0) 28%, rgba(0,0,0,0) 62%, rgba(0,0,0,0.85));
    transition: opacity 0.25s;
}
.vod-controls.hidden { opacity: 0; pointer-events: none; }
.vod-controls-top { display: flex; align-items: center; gap: 4px; padding: calc(4px + var(--safe-top)) calc(8px + var(--safe-right)) 0 calc(4px + var(--safe-left)); }
.vod-title { flex: 1; min-width: 0; font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vod-title .player-epg-title-time { color: var(--muted); font-size: 13px; margin-left: 6px; }
.vod-controls-center { display: flex; align-items: center; justify-content: center; gap: 6px; }
.vod-controls-bottom { padding: 0 calc(12px + var(--safe-right)) calc(8px + var(--safe-bottom)) calc(12px + var(--safe-left)); }
.progress-row { display: flex; align-items: center; gap: 10px; font-size: 13px; font-variant-numeric: tabular-nums; }
.seek-bar { position: relative; flex: 1; height: 28px; display: flex; align-items: center; touch-action: none; cursor: pointer; }
.seek-bar::before { content: ''; position: absolute; left: 0; right: 0; height: 4px; border-radius: 2px; background: rgba(255,255,255,0.25); }
.seek-buffer { position: absolute; left: 0; height: 4px; border-radius: 2px; background: rgba(255,255,255,0.4); width: 0; }
.seek-bar .progress-amount { position: absolute; left: 0; height: 4px; border-radius: 2px; background: var(--orange); width: 0; }
.seek-thumb { position: absolute; width: 16px; height: 16px; border-radius: 50%; background: #fff; transform: translateX(-50%); left: 0; box-shadow: 0 1px 4px rgba(0,0,0,0.6); }
.seek-bar.dragging .seek-thumb { width: 22px; height: 22px; }
.seek-bar.disabled { opacity: 0.4; pointer-events: none; }
.tool-row { display: flex; align-items: center; gap: 2px; margin-top: 2px; }
.tool-row .spacer { flex: 1; }
.volume-slider { width: 110px; accent-color: var(--orange); }
.resume-card { text-align: center; }
.resume-time { font-size: 28px; font-weight: 700; color: var(--orange); margin: 8px 0; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ settings */
.settings-layout { flex: 1 1 auto; display: flex; min-height: 0; }
.settings-menu { flex: 1 1 auto; overflow-y: auto; padding: 8px 0 calc(8px + var(--safe-bottom)); }
.settings-menu-item {
    display: flex; align-items: center; gap: 14px; width: 100%; padding: 15px 18px; text-align: left;
    border-bottom: 1px solid var(--line); font-size: 16px;
}
.settings-menu-item .fa:first-child { width: 22px; text-align: center; color: var(--accent-2); }
.settings-menu-item span { flex: 1; }
.settings-menu-item .fa-chevron-right { color: var(--muted); font-size: 13px; }
.settings-menu-item.current { background: var(--focus); }
.settings-detail { display: none; flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px 18px calc(20px + var(--safe-bottom)); }
#screen-settings.detail-open .settings-menu { display: none; }
#screen-settings.detail-open .settings-detail { display: block; }
.section-title { font-size: 20px; margin: 0 0 14px; font-weight: 500; }
.form-stack { display: flex; flex-direction: column; gap: 8px; max-width: 420px; }
.form-stack .btn { margin-top: 10px; }
.field-label { color: var(--text-2); font-size: 14px; margin-top: 4px; }
.form-error { color: var(--danger); font-size: 14px; }
.check-list { display: flex; flex-direction: column; }
.check-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 13px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.check-item .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.check-box { width: 22px; height: 22px; border-radius: 6px; border: 2px solid rgba(255,255,255,0.35); display: flex; align-items: center; justify-content: center; font-size: 12px; flex: 0 0 auto; }
.check-item.checked .check-box { background: var(--focus); border-color: var(--accent); }
.check-item:not(.checked) .check-box .fa { visibility: hidden; }
.account-list { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; margin: 0; align-items: center; }
.account-list dt { color: var(--muted); }
.account-list dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ trailer */
#screen-trailer { background: #000; }
.trailer-frame { position: absolute; inset: 0; padding: calc(var(--topbar-h) + var(--safe-top)) 0 var(--safe-bottom); display: flex; align-items: center; }
.trailer-frame iframe { width: 100%; height: 100%; border: 0; }
#screen-trailer .top-bar { z-index: 2; }

/* ------------------------------------------------------------------ modals / toast / loader */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 100; background: rgba(0, 0, 0, 0.6); display: flex; align-items: center; justify-content: center;
    padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
    opacity: 0; transition: opacity 0.18s;
}
.modal-backdrop.show { opacity: 1; }
.modal-backdrop.closing { pointer-events: none; }
/* Error state: keep only the top bar (Back) above the error overlay so Retry is tappable. */
.has-error .vod-controls { background: none; pointer-events: none; opacity: 1 !important; }
.has-error .vod-controls-center, .has-error .vod-controls-bottom { visibility: hidden; }
.has-error .vod-controls-top { pointer-events: auto; }
.has-error .live-overlay-center, .has-error .full-screen-information { visibility: hidden; }
.modal-card {
    width: 100%; max-width: 440px; max-height: 100%; display: flex; flex-direction: column; overflow: hidden;
    background: var(--panel-solid); border: 1px solid rgba(28, 111, 150, 0.6); border-radius: 18px; box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.modal-title { padding: 16px 18px 8px; font-size: 18px; font-weight: 500; }
.modal-body { padding: 8px 18px 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-body .form-stack { max-width: none; }
.modal-backdrop.sheet { align-items: flex-end; padding: calc(40px + var(--safe-top)) 0 0; }
.modal-backdrop.sheet .modal-card { max-width: 640px; height: 100%; border-radius: 18px 18px 0 0; border-bottom: 0; }
.modal-backdrop.sheet .modal-body { display: flex; flex-direction: column; gap: 10px; flex: 1; min-height: 0; padding-bottom: 0; }
.sheet-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding-bottom: var(--safe-bottom); }
.sheet-item { display: flex; gap: 10px; align-items: center; width: 100%; padding: 13px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.sheet-item.current { background: var(--focus); border-radius: 8px; }
.sheet-item-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.sheet-item-count { color: var(--muted); font-size: 13px; }
.option-list { display: flex; flex-direction: column; gap: 4px; max-height: 50vh; overflow-y: auto; }
.option-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 8px; border-radius: 10px; text-align: left; }
.option-item.selected { background: rgba(0, 78, 100, 0.55); }
.radio-dot { width: 20px; height: 20px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.5); flex: 0 0 auto; position: relative; }
.option-item.selected .radio-dot { border-color: var(--orange); }
.option-item.selected .radio-dot::after { content: ''; position: absolute; inset: 3px; border-radius: 50%; background: var(--orange); }
.toast {
    position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translate(-50%, 20px); z-index: 200;
    max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 14px; background: rgba(22, 33, 47, 0.97); border: 1px solid var(--accent);
    text-align: center; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; display: flex; flex-direction: column; gap: 2px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast span { color: var(--text-2); font-size: 14px; }
#global-loader { position: fixed; inset: 0; z-index: 150; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.35); }
.noscript { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--bg); color: #fff; }

/* ------------------------------------------------------------------ wider / landscape layouts */
@media (min-width: 600px) {
    .home-menu { grid-template-columns: repeat(6, 1fr); max-width: 1100px; gap: 8px; }
    .home-logo { width: 170px; }
    .poster-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 16px 14px; }
}
/* Two-column layouts like the TV app when there is room (tablets, phones in landscape). */
@media (min-width: 900px), (orientation: landscape) and (min-width: 640px) {
    .live-layout { flex-direction: row-reverse; }
    .live-player-col { flex: 0 0 56%; display: flex; flex-direction: column; border-left: 1px solid var(--line); overflow-y: auto; }
    .live-player { max-height: none; }
    #next-program-container { max-height: none; }
    .live-list-col { flex: 1 1 44%; min-width: 0; }
    .category-select { display: none; }
    .live-columns .category-list { display: block; flex: 0 0 42%; border-right: 1px solid var(--line); background: rgba(8,13,20,0.55); }
    .grid-categories { display: block; }
    #grid-category-btn { display: none; }
    .poster-grid { padding-top: 12px; }
    .detail-content { flex-direction: row; align-items: flex-start; gap: 28px; }
    .detail-content .detail-left { position: sticky; top: calc(var(--topbar-h) + var(--safe-top)); }
    .detail-poster { width: 220px; }
    .detail-name { text-align: left; }
    .detail-meta { text-align: left; }
    .settings-menu { flex: 0 0 300px; border-right: 1px solid var(--line); }
    .settings-detail { display: block; }
    #screen-settings.detail-open .settings-menu { display: block; }
    .settings-menu-item .fa-chevron-right { display: none; }
    .epg-layout { flex-direction: row; }
    .epg-dates { flex-direction: column; overflow-y: auto; overflow-x: hidden; width: 190px; border-right: 1px solid var(--line); padding-bottom: calc(10px + var(--safe-bottom)); }
    .epg-date { text-align: left; }
}
@media (orientation: landscape) and (max-height: 500px) {
    :root { --topbar-h: 44px; }
    .home-header { padding-top: calc(6px + var(--safe-top)); }
    .home-menu { grid-template-columns: repeat(6, 1fr); padding-top: 8px; max-width: 820px; }
    .home-playlists { padding-top: 8px; }
    .live-player-col { flex-basis: 52%; }
    .live-columns .category-list { flex-basis: 38%; }
    .channel-number { display: none; }
    .channel-icon-wrapper { width: 40px; height: 30px; }
    .channel-item { padding-left: 8px; gap: 8px; }
    .detail-poster { width: 150px; }
    .icon-btn.big { min-width: 50px; height: 50px; }
}
@media (min-width: 1200px) {
    .live-player-col { flex-basis: 62%; }
    .hint-bar { display: flex; gap: 16px; padding: 8px 14px; border-top: 1px solid var(--line); color: var(--text-2); font-size: 13px; }
}

.external-chooser-text { margin: 0 0 4px; color: var(--text-2); }
.external-chooser-store { text-align: center; margin: 12px 0 0; font-size: 13px; }
.external-chooser-store a { color: var(--orange); }
