/* =============================================
   takoTV — Octopus theme (matches UWP native app)
   Palette mirrors takoTV-windows MaterialGlass.xaml + Skins/Octopus.xaml
   Primary: #CB897F, Secondary: #9E8A88, Tertiary: #C45050
   ============================================= */

:root {
    /* === Octopus accent palette === */
    --accent: #CB897F;          /* Primary (dusty rose mauve) */
    --accent-light: #E2A89E;
    --accent-dark: #A06A60;
    --accent-dim: rgba(203, 137, 127, 0.18);
    --secondary: #9E8A88;
    --tertiary: #C45050;        /* Pop accent / cheeks */

    /* === Dark theme (default) — mirrors MaterialGlass.xaml dark === */
    --bg-primary: #0A0A0F;
    --bg-secondary: #12121A;
    --bg-surface: #1A1A25;
    --bg-elevated: #24243A;
    --bg-glass: rgba(24, 24, 42, 0.75);
    --border-glass: rgba(155, 138, 136, 0.18);
    --text-primary: #FFFFFF;
    --text-secondary: #B0B0C0;
    --text-muted: #707085;
    --success: #4CAF50;
    --error: #C45050;
    --warning: #FFA726;

    /* === Spacing scale (breathable) === */
    --space-xxs: 4px;
    --space-xs:  8px;
    --space-s:  12px;
    --space-m:  16px;
    --space-l:  24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* === Radii (mirrors MaterialGlass scale) === */
    --radius-xs: 4px;
    --radius-sm: 8px;
    --radius:    12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-pill: 100px;

    /* === Shadows === */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
    --shadow:    0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.45);

    /* === Layout === */
    --nav-height: 56px;
    --sidebar-width: 240px;
    --top-bar-height: 56px;
    --transition: 0.2s ease;
    --transition-slow: 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}

/* === Light theme === */
/* SYNC: keep these variables identical to [data-theme="auto"] below */
[data-theme="light"] {
    --bg-primary: #F5F5F8;
    --bg-secondary: #FFFFFF;
    --bg-surface: #E8E8EE;
    --bg-elevated: #FFFFFF;
    --bg-glass: rgba(255, 255, 255, 0.85);
    --border-glass: rgba(26, 26, 46, 0.10);
    --text-primary: #1A1A2E;
    --text-secondary: #5A5A70;
    --text-muted: #8A8A9E;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow:    0 8px 24px rgba(0, 0, 0, 0.10);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.14);
}

/* === Auto theme: respect OS preference === */
/* SYNC: keep these variables identical to [data-theme="light"] above */
@media (prefers-color-scheme: light) {
    [data-theme="auto"] {
        --bg-primary: #F5F5F8;
        --bg-secondary: #FFFFFF;
        --bg-surface: #E8E8EE;
        --bg-elevated: #FFFFFF;
        --bg-glass: rgba(255, 255, 255, 0.85);
        --border-glass: rgba(26, 26, 46, 0.10);
        --text-primary: #1A1A2E;
        --text-secondary: #5A5A70;
        --text-muted: #8A8A9E;
        --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
        --shadow:    0 8px 24px rgba(0, 0, 0, 0.10);
        --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.14);
    }
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
    height: 100%;
    /* Dynamic viewport height accounts for mobile URL bar show/hide */
    height: 100dvh;
}
body {
    font-family: 'Segoe UI Variable', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    /* Viewport-bound: never taller than the visible viewport */
    width: 100vw;
    max-width: 100%;
    max-height: 100vh;
    max-height: 100dvh;
}

.hidden { display: none !important; }

/* Screen-reader-only utility */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus visible — keyboard / gamepad navigation support */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-xs);
}
.ch-card:focus-visible,
.vod-card:focus-visible,
.series-card:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 0;
    transform: scale(1.03);
    z-index: 2;
}

/* Window Controls Overlay — native title bar integration for installed PWA */
@media (display-mode: window-controls-overlay) {
    .top-bar {
        padding-left: env(titlebar-area-x, 0);
        width: env(titlebar-area-width, 100%);
        height: env(titlebar-area-height, 56px);
        -webkit-app-region: drag;
    }
    .top-bar button, .top-bar select, .top-bar input, .top-bar a {
        -webkit-app-region: no-drag;
    }
}

/* --- App Layout --- */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    width: 100%;
    overflow: hidden;
}

#main {
    flex: 1 1 auto;
    display: flex;
    overflow: hidden;
    min-height: 0;
    min-width: 0;
}

/* --- Top Bar --- */
.top-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-glass);
    flex-shrink: 0;
    z-index: 50;
}
.top-bar-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--accent-light);
}
.playlist-selector {
    background: var(--bg-surface);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
    cursor: pointer;
    max-width: 250px;
}
.playlist-selector:focus { border-color: var(--accent); }
.top-bar.hidden { display: none !important; }

/* Account button in top bar */
.account-btn-wrap {
    position: relative;
    flex-shrink: 0;
}
.account-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border-glass);
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}
.account-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-dim);
}
.account-btn.signed-in {
    color: var(--accent-light);
    border-color: var(--accent);
    background: var(--accent-dim);
}
.account-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 320px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
    z-index: 200;
    padding: 16px;
    animation: dropIn 0.15s ease-out;
}
@keyframes dropIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}
.account-dropdown.hidden { display: none; }
.account-dropdown h4 {
    margin: 0 0 8px;
    font-size: 14px;
    color: var(--text-primary);
}
.account-dropdown p {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.4;
    margin: 0 0 12px;
}
.account-dropdown .input {
    width: 100%;
    box-sizing: border-box;
    background: var(--bg-surface);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
}
.account-dropdown .input:focus {
    border-color: var(--accent);
}
.account-dropdown .input + .input {
    margin-top: 6px;
}
.account-dropdown .acct-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}
.account-dropdown .acct-btn {
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-glass);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition);
}
.account-dropdown .acct-btn:hover {
    border-color: var(--accent);
}
.account-dropdown .acct-btn.primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.account-dropdown .acct-btn.primary:hover {
    opacity: 0.9;
}
.account-dropdown .acct-btn.danger {
    color: var(--error);
    border-color: var(--error);
}
.account-dropdown .acct-pw-wrap {
    position: relative;
}
.account-dropdown .acct-pw-wrap .input {
    padding-right: 36px;
}
.account-dropdown .acct-pw-toggle {
    position: absolute;
    top: 50%;
    right: 4px;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
}
.account-dropdown .acct-pw-toggle:hover { color: var(--accent); }
.account-dropdown .acct-remember {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}
.account-dropdown .acct-error {
    color: var(--error);
    font-size: 12px;
    margin-top: 4px;
    display: none;
}
.account-dropdown .acct-user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}
.account-dropdown .acct-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-dim);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
.account-dropdown .acct-user-details {
    min-width: 0;
}
.account-dropdown .acct-user-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.account-dropdown .acct-user-email {
    font-size: 12px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Global search bar in the top bar */
.global-search-wrap {
    position: relative;
    flex: 1;
    max-width: 400px;
    margin-left: auto;
}
.global-search {
    width: 100%;
    background: var(--bg-surface);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-pill);
    padding: 6px 14px;
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
    transition: border-color var(--transition);
}
.global-search:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}
.global-search-results {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    left: 0;
    max-height: 60vh;
    overflow-y: auto;
    background: var(--bg-elevated);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 250;
    padding: var(--space-xs) 0;
}
.global-result-section {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent-light);
    padding: var(--space-xs) var(--space-m) 2px;
    font-weight: 700;
}
.global-result-item {
    display: flex;
    align-items: center;
    gap: var(--space-s);
    padding: var(--space-xs) var(--space-m);
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    transition: background var(--transition);
}
.global-result-item:hover { background: var(--accent-dim); }
.global-result-icon { font-size: 14px; flex-shrink: 0; }
.global-result-meta {
    margin-left: auto;
    font-size: 11px;
    color: var(--text-muted);
}
.global-result-empty {
    padding: var(--space-l);
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* --- Bottom Nav --- */
#bottom-nav {
    display: flex;
    align-items: center;
    justify-content: space-around;
    height: var(--nav-height);
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-glass);
    flex-shrink: 0;
    z-index: 100;
}

.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 11px;
    padding: 6px 16px;
    cursor: pointer;
    transition: color var(--transition);
    text-decoration: none;
}
.nav-btn .nav-icon { font-size: 20px; }
.nav-btn.active { color: var(--accent-light); }
.nav-btn:hover { color: var(--text-primary); }

/* --- Views --- */
/* No view scrolls at the container level. Each view hosts its own internal
   scrollable region (channel grid, vod grid, settings panel, etc.) so we
   never see a body / platform-level scrollbar. */
.view {
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* --- Live View Layout --- */
#view-live {
    display: flex;
    height: 100%;
}

/* Sidebar */
#category-sidebar,
#vod-sidebar,
#series-sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-glass);
    overflow-y: auto;
    padding: 8px;
    flex-shrink: 0;
    position: relative;
}

/* Generic sidebar resize handle (used by TakoSidebarResize) */
.sidebar-resize-handle {
    position: absolute;
    top: 0;
    right: -4px;
    bottom: 0;
    width: 8px;
    cursor: col-resize;
    background: transparent;
    transition: background var(--transition);
    z-index: 5;
}
.sidebar-resize-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    height: 40px;
    border-radius: 2px;
    background: var(--border-glass);
    transition: background var(--transition);
}
.sidebar-resize-handle:hover { background: var(--accent-dim); }
.sidebar-resize-handle:hover::after,
.sidebar-resize-handle:active::after { background: var(--accent); }

.cat-search-input {
    width: 100%;
    padding: 6px 10px;
    margin-bottom: var(--space-xs);
    background: var(--bg-surface);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 12px;
    outline: none;
}
.cat-search-input:focus { border-color: var(--accent); }

.cat-section-header {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent-light);
    padding: 6px 12px 4px;
    font-weight: 700;
}

.cat-btn-row {
    display: flex;
    align-items: stretch;
    gap: 2px;
}
.cat-btn-row .cat-btn { flex: 1; }
.cat-fav-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 14px;
    cursor: pointer;
    padding: 0 8px;
    border-radius: var(--radius-sm);
    transition: color var(--transition);
}
.cat-fav-btn:hover { color: var(--warning); }
.cat-fav-btn.active-fav { color: var(--warning); }

.cat-pin-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    padding: 0 6px;
    border-radius: var(--radius-sm);
    transition: color var(--transition);
    opacity: 0.6;
    filter: grayscale(100%);
}
.cat-pin-btn:hover {
    color: var(--accent);
    opacity: 1;
    filter: none;
}
.cat-pin-btn.active-pin {
    color: var(--accent);
    opacity: 1;
    filter: none;
}

.cat-move-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 10px;
    cursor: pointer;
    padding: 0 4px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    line-height: 1;
}
.cat-move-btn:hover {
    color: var(--accent);
    background: var(--bg-surface);
}

.cat-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 10px 12px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    text-align: left;
    transition: all var(--transition);
}
.cat-btn:hover { background: var(--bg-surface); color: var(--text-primary); }
.cat-btn.active { background: var(--accent-dim); color: var(--accent-light); }
.cat-count { font-size: 11px; color: var(--text-muted); margin-left: 4px; }
.cat-divider { height: 1px; background: var(--border-glass); margin: 8px 4px; }

/* Group button — expandable super-category (e.g. "France" wraps France HD / 4K / SD) */
.cat-group-btn {
    font-weight: 600;
    color: var(--text-primary);
}
.cat-group-chevron {
    display: inline-block;
    margin-right: 6px;
    color: var(--accent-light);
    transition: transform 0.2s ease;
    font-size: 16px;
    line-height: 1;
}
.cat-group-btn.expanded {
    background: var(--accent-dim);
    color: var(--accent-light);
}
.cat-group-btn.expanded .cat-group-chevron {
    transform: rotate(90deg);
}

/* Second-level sidebar — slides in from the right when a group is expanded.
   Inserted as a SIBLING of #category-sidebar inside #view-live so it isn't
   clipped by the main sidebar's overflow. It takes its own flex column and
   pushes the channel grid to the right. */
.cat-subpanel {
    flex-shrink: 0;
    width: var(--sidebar-width, 260px);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-glass);
    padding: 12px 8px;
    overflow-y: auto;
    box-shadow: var(--shadow);
    animation: cat-subpanel-slide 0.25s ease;
}
@keyframes cat-subpanel-slide {
    from { transform: translateX(-20px); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}
.cat-subpanel-back {
    display: block;
    width: 100%;
    padding: 8px 12px;
    margin-bottom: 8px;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border-glass);
    color: var(--accent-light);
    font-size: 13px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    transition: all var(--transition);
}
.cat-subpanel-back:hover {
    background: var(--bg-surface);
}

/* Category sidebar must be a positioning context for the sub-panel */
#category-sidebar {
    position: relative;
}

/* Channel area */
.channel-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Search bar */
.search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-glass);
}
.search-bar input {
    flex: 1;
    background: var(--bg-surface);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color var(--transition);
}
.search-bar input:focus { border-color: var(--accent); }
.search-bar .count { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.search-bar .sort-select {
    background: var(--bg-surface);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    color: var(--text-primary);
    font-size: 12px;
    outline: none;
    cursor: pointer;
    flex-shrink: 0;
    max-width: 160px;
}
.search-bar .sort-select:focus { border-color: var(--accent); }

/* Channel grid */
#channel-grid {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
    align-content: start;
}

.channel-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--bg-glass);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    /* Virtualisation: 'auto Xpx' lets the browser remember the real height */
    content-visibility: auto;
    contain-intrinsic-size: auto 70px;
    min-height: 64px;
}
.channel-card:hover {
    background: var(--bg-surface);
    border-color: var(--accent-dim);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.ch-logo {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    object-fit: contain;
    background: var(--bg-surface);
    flex-shrink: 0;
}
.ch-logo-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    color: var(--accent-light);
}

.ch-info { flex: 1; min-width: 0; }
.ch-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 6px;
}
.health-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.health-green { background: #4CAF50; box-shadow: 0 0 6px #4CAF50; }
.health-amber { background: #FFA726; box-shadow: 0 0 6px #FFA726; }
.health-red   { background: #C45050; box-shadow: 0 0 6px #C45050; }
.ch-num { font-size: 11px; color: var(--text-muted); }
.ch-now {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
    min-height: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.ch-now .now-dot {
    display: none;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--error);
    box-shadow: 0 0 6px var(--error);
    flex-shrink: 0;
    animation: now-pulse 2s ease-in-out infinite;
}
.ch-now.has-now .now-dot { display: inline-block; }
.ch-now .now-title {
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}
@keyframes now-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%      { opacity: 0.6; transform: scale(0.85); }
}

.fav-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    padding: 4px;
    transition: color var(--transition);
}
.fav-btn:hover { color: var(--warning); }
.fav-btn.fav-active { color: var(--warning); }

/* --- Player View --- */
#view-player {
    display: flex;
    flex-direction: column;
    background: #000;
    height: 100%;
}
/* When player is active, force-hide nav/top/fab */
body.player-active #bottom-nav,
body.player-active #top-bar,
body.player-active #fab-add {
    display: none !important;
}

#player-container {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
}

#main-video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Player loading overlay */
.player-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: rgba(0, 0, 0, 0.6);
    z-index: 3;
    transition: opacity 0.3s;
}
.player-loading.hidden { opacity: 0; pointer-events: none; }
.player-loading span {
    color: #fff;
    font-size: 14px;
    font-weight: 500;
}
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.2);
    border-top-color: var(--accent-light);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Loading skeleton cards */
@keyframes shimmer {
    0% { background-position: -400px 0; }
    100% { background-position: 400px 0; }
}
.skeleton-card {
    background: linear-gradient(90deg, var(--bg-glass) 25%, var(--bg-surface) 50%, var(--bg-glass) 75%);
    background-size: 800px 100%;
    animation: shimmer 1.5s infinite linear;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
}
/* Channel skeleton: same height as .channel-card */
.skeleton-card--channel {
    height: 52px;
}
/* VOD/Series skeleton: poster card shape */
.skeleton-card--poster {
    aspect-ratio: 2/3;
    min-height: 200px;
}

.player-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px 16px;
    background: linear-gradient(transparent, rgba(0,0,0,0.85));
    display: flex;
    flex-direction: column;
    gap: 6px;
    opacity: 0;
    transition: opacity 0.3s;
    /* Never take more than 45% of the container so the video stays visible
       and the top row (Cast, PiP, Fullscreen) is always reachable */
    max-height: 45%;
    overflow-y: auto;
    overflow-x: hidden;
}
#player-container:hover .player-overlay,
.player-overlay:focus-within,
.player-overlay.force-show { opacity: 1; }

/* Volume OSD overlay (shown briefly on volume change via keyboard) */
.volume-osd {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.75);
    color: #fff;
    font-size: 28px;
    font-weight: 700;
    padding: 16px 32px;
    border-radius: var(--radius);
    pointer-events: none;
    z-index: 100;
    transition: opacity 0.4s ease;
}
.volume-osd.fade-out { opacity: 0; }

/* PiP indicator */
.pip-indicator {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: rgba(124, 77, 255, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 20px;
    color: #fff;
    font-size: 12px;
    font-weight: 500;
    z-index: 5;
    animation: pip-pulse 2s ease-in-out infinite;
}
.pip-indicator svg { flex-shrink: 0; }
@keyframes pip-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.player-controls-top,
.player-controls-bottom {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    flex-wrap: wrap;
}
.player-controls-top { flex-wrap: nowrap; min-height: 36px; }
.player-controls-top { margin-bottom: 8px; }
.player-spacer { flex: 1; }

.player-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background var(--transition), color var(--transition);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}
.player-btn:hover { background: rgba(255,255,255,0.15); }
.player-btn.pip-active { color: var(--accent-light); background: rgba(124, 77, 255, 0.2); }
.player-btn svg { display: block; }

#player-channel-name {
    font-size: 14px;
    font-weight: 500;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
}
#player-state {
    font-size: 12px;
    color: var(--accent-light);
    flex-shrink: 0;
}

.seek-slider {
    flex: 1;
    height: 4px;
    accent-color: var(--accent);
    cursor: pointer;
}

.player-time {
    font-size: 12px;
    color: #ccc;
    min-width: 40px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.live-badge {
    background: var(--error);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 1px;
    flex-shrink: 0;
}

.quality-menu {
    position: absolute;
    bottom: 70px;
    right: 60px;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    padding: 4px 0;
    min-width: 160px;
    max-height: 50vh;
    overflow-y: auto;
    z-index: 10;
}
#audio-menu { right: 200px; }
#subs-menu { right: 260px; }
.quality-option {
    padding: 8px 16px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background var(--transition);
}
.quality-option:hover { background: var(--bg-surface); }
.quality-option.active { color: var(--accent-light); }

.channel-info-banner {
    position: absolute;
    top: 20px;
    left: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: var(--radius);
    transition: opacity 0.5s;
    z-index: 5;
}
.banner-logo {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    object-fit: contain;
}
.banner-name {
    font-size: 15px;
    font-weight: 500;
    color: #fff;
}

#vol-slider {
    width: 80px;
    accent-color: var(--accent);
    flex-shrink: 0;
}

/* --- Import View --- */
#view-import {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    overflow-y: auto;
}

.import-wizard {
    max-width: 700px;
    width: 100%;
}
.import-mascot {
    display: flex;
    justify-content: center;
    margin-bottom: var(--space-l);
}
.import-wizard h2 {
    font-size: 28px;
    font-weight: 600;
    margin-bottom: var(--space-l);
    text-align: center;
    color: var(--text-primary);
}

.import-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
}

.import-card {
    background: var(--bg-glass);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    padding: 24px 16px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
}
.import-card:hover {
    border-color: var(--accent);
    background: var(--accent-dim);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}
.import-card.disabled {
    opacity: 0.4;
    pointer-events: none;
}
.import-card-icon { font-size: 36px; margin-bottom: 12px; }
.import-card h3 { font-size: 15px; margin-bottom: 6px; }
.import-card p { font-size: 12px; color: var(--text-secondary); }

/* First-time split landing: 2 columns (import vs signup) */
.first-time-split {
    display: flex;
    gap: 24px;
    max-width: 1000px;
    width: 100%;
    margin: 0 auto;
    padding: 24px 16px;
    align-items: stretch;
}
.first-time-col {
    flex: 1 1 0;
    min-width: 0;
    background: var(--bg-glass);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    padding: 24px;
    display: flex;
    flex-direction: column;
}
.first-time-col h2 {
    font-size: 22px;
    font-weight: 700;
    margin: 0 0 6px;
    color: var(--text-primary);
    text-align: center;
}
.first-time-col .ft-tagline {
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
    margin: 0 0 18px;
    line-height: 1.4;
}
.first-time-col .ft-benefits {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    margin: 12px 0 0;
    line-height: 1.4;
}
.first-time-col .ft-guest-cards {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}
.first-time-col .ft-guest-cards .import-card {
    padding: 16px 12px;
}
.first-time-col .ft-signup-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.first-time-col .ft-signup-form .input {
    width: 100%;
    box-sizing: border-box;
    background: var(--bg-surface);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
}
.first-time-col .ft-signup-form .input:focus { border-color: var(--accent); }
.first-time-col .ft-actions {
    display: flex;
    gap: 8px;
    margin-top: 6px;
    flex-wrap: wrap;
}
.first-time-col .ft-btn {
    flex: 1 1 auto;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-glass);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}
.first-time-col .ft-btn:hover { border-color: var(--accent); }
.first-time-col .ft-btn.primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.first-time-col .ft-btn.primary:hover { opacity: 0.9; }
.first-time-col .ft-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.first-time-col .ft-link {
    background: none;
    border: none;
    color: var(--accent);
    text-decoration: underline;
    font-size: 12px;
    padding: 4px;
    cursor: pointer;
    text-align: center;
    margin-top: 6px;
}
.first-time-col .ft-error {
    color: var(--error);
    font-size: 12px;
    margin-top: 4px;
    min-height: 16px;
}
.first-time-col .ft-success {
    text-align: center;
    padding: 20px 0;
}
.first-time-col .ft-success .ft-check {
    font-size: 40px;
    color: var(--accent);
    margin-bottom: 12px;
}
.first-time-col .ft-success .ft-user {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}
.first-time-col .ft-success .ft-email {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 14px;
}
.ft-hidden { display: none !important; }

.first-time-col .ft-pw-wrap {
    position: relative;
}
.first-time-col .ft-pw-wrap .input {
    padding-right: 40px;
}
.first-time-col .ft-pw-toggle {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
}
.first-time-col .ft-pw-toggle:hover { color: var(--accent); background: var(--accent-dim); }

@media (max-width: 768px) {
    .first-time-split {
        flex-direction: column;
        gap: 16px;
        padding: 16px 12px;
    }
    /* Order: signup first, guest second — prioritize recommended path on mobile */
    .first-time-col.ft-signup { order: 1; }
    .first-time-col.ft-guest  { order: 2; }
    .first-time-col { padding: 20px 16px; }
    .first-time-col h2 { font-size: 19px; }
}

/* Import form */
.import-form { padding: 24px 0; }
.drop-zone {
    border: 2px dashed var(--border-glass);
    border-radius: var(--radius);
    padding: 48px 24px;
    text-align: center;
    transition: all var(--transition);
}
.drop-zone.active, .drag-over .drop-zone {
    border-color: var(--accent);
    background: var(--accent-dim);
}
.drop-zone p { margin-bottom: 12px; color: var(--text-secondary); }

.url-form { display: flex; flex-direction: column; gap: 12px; }
.url-form label { font-size: 13px; color: var(--text-secondary); }

.input {
    background: var(--bg-surface);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    width: 100%;
}
.input:focus { border-color: var(--accent); }

.btn {
    border: none;
    border-radius: var(--radius-sm);
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}
.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover { background: var(--accent-light); }

/* Progress */
.import-progress { text-align: center; padding: 32px 0; }
.progress-container { max-width: 400px; margin: 0 auto; }
.progress-bar {
    height: 4px;
    background: var(--bg-surface);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 12px;
}
.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    width: 0;
    transition: width 0.3s;
    animation: progress-indeterminate 1.5s ease-in-out infinite;
}
@keyframes progress-indeterminate {
    0% { transform: translateX(-100%); width: 40%; }
    50% { transform: translateX(60%); width: 40%; }
    100% { transform: translateX(200%); width: 40%; }
}
#progress-text { font-size: 13px; color: var(--text-secondary); }

.error-msg {
    color: var(--error);
    padding: 16px;
    background: rgba(248, 81, 73, 0.1);
    border-radius: var(--radius-sm);
    font-size: 13px;
}

/* --- Empty State --- */
.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 64px 24px;
    color: var(--text-secondary);
}
.empty-state p { margin-bottom: 8px; }
.empty-hint { font-size: 13px; color: var(--text-muted); }

/* --- FAB --- */
.fab {
    position: fixed;
    bottom: calc(var(--nav-height) + 16px);
    right: 16px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    font-size: 24px;
    cursor: pointer;
    box-shadow: var(--shadow);
    z-index: 50;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}
.fab:hover { background: var(--accent-light); transform: scale(1.05); }

/* --- Resume last channel banner --- */
.resume-banner {
    position: fixed;
    top: calc(var(--top-bar-height) + 12px);
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    display: flex;
    align-items: center;
    gap: var(--space-s);
    padding: var(--space-s) var(--space-m);
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--accent);
    border-radius: var(--radius-pill);
    box-shadow: var(--shadow);
    z-index: 220;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    max-width: 90vw;
}
.resume-banner.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.resume-banner-text {
    font-size: 13px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 280px;
}
.resume-banner-text strong { color: var(--accent-light); }
.resume-banner-btn {
    background: var(--accent);
    border: none;
    color: #fff;
    padding: 6px 14px;
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition);
}
.resume-banner-btn:hover { background: var(--accent-light); }
.resume-banner-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.resume-banner-close:hover { color: var(--text-primary); }

/* --- Context menu (right-click on channel cards) --- */
.context-menu {
    position: fixed;
    background: var(--bg-elevated);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    padding: 4px 0;
    box-shadow: var(--shadow);
    z-index: 250;
    min-width: 160px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}
.context-item {
    padding: 8px 16px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background var(--transition);
}
.context-item:hover {
    background: var(--accent-dim);
    color: var(--accent-light);
}

/* --- Mini-player (persistent floating dock) --- */
.mini-player {
    position: fixed;
    right: 20px;
    bottom: calc(var(--nav-height) + 20px);
    width: 320px;
    max-width: 90vw;
    aspect-ratio: 16/9;
    background: #000;
    border: 2px solid var(--accent);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    z-index: 180;
    cursor: default;
}
.mini-player video {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain;
    display: block;
}
.mini-player-handle {
    position: absolute;
    top: 0;
    left: 0;
    right: 80px;
    height: 32px;
    cursor: move;
    background: linear-gradient(180deg, rgba(0,0,0,0.7), transparent);
    z-index: 2;
}
.mini-player-controls {
    position: absolute;
    top: 4px;
    right: 4px;
    display: flex;
    gap: 4px;
    z-index: 3;
}
.mini-player-btn {
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}
.mini-player-btn:hover { background: var(--accent); }
.mini-player.hidden { display: none !important; }

/* PiP mode: keep the dock in the render tree (so video decoding continues
   and PiP frames update) but invisible to the user — the PiP window shows
   the stream instead. We use opacity + 1px size rather than display:none
   or visibility:hidden since both of those pause video rendering in
   Chromium, causing a black PiP window. */
.mini-player.pip-mode {
    width: 1px !important;
    height: 1px !important;
    min-width: 0 !important;
    min-height: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    opacity: 0.01;
    pointer-events: none;
    overflow: hidden;
    border: none;
    box-shadow: none;
    background: transparent;
}
.mini-player.pip-mode video {
    width: 100% !important;
    height: 100% !important;
}
.mini-player.pip-mode .mini-player-handle,
.mini-player.pip-mode .mini-player-controls {
    display: none !important;
}

/* --- Multiview (2-up / 4-up) --- */
.multiview-root {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 300;
    display: flex;
    flex-direction: column;
}
.multiview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-s) var(--space-m);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
    border-bottom: 1px solid var(--border-glass);
    flex-shrink: 0;
}
.multiview-close {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 24px;
    cursor: pointer;
    padding: 0 var(--space-s);
    line-height: 1;
}
.multiview-close:hover { color: var(--accent-light); }
.multiview-grid {
    flex: 1;
    display: grid;
    gap: 4px;
    background: #000;
    padding: 4px;
}
.multiview-2 .multiview-grid { grid-template-columns: 1fr 1fr; }
.multiview-4 .multiview-grid { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.multiview-tile {
    position: relative;
    background: #000;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color var(--transition);
}
.multiview-tile:hover { border-color: var(--accent); }
.multiview-tile video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}
.multiview-label {
    position: absolute;
    bottom: 8px;
    left: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.multiview-audio {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    opacity: 0.4;
    transition: opacity var(--transition);
}
.multiview-audio.active {
    opacity: 1;
    background: var(--accent);
    box-shadow: 0 0 12px var(--accent);
}
body.multiview-active { overflow: hidden; }

/* --- Stream stats overlay (press S during playback) --- */
.stats-overlay {
    position: fixed;
    top: 80px;
    right: 20px;
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    font-family: 'Cascadia Code', Consolas, monospace;
    font-size: 11px;
    padding: var(--space-s) var(--space-m);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    z-index: 240;
    min-width: 220px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}
.stats-row {
    display: flex;
    justify-content: space-between;
    gap: var(--space-m);
    padding: 2px 0;
}
.stats-key {
    color: var(--accent-light);
    font-weight: 600;
}

/* --- Numeric channel entry overlay (typing 0-9 to jump to channel) --- */
.numeric-overlay {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.85);
    background: rgba(10, 10, 15, 0.85);
    color: var(--accent-light);
    font-size: 96px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    padding: var(--space-l) var(--space-2xl);
    border: 2px solid var(--accent);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 250;
    opacity: 0;
    pointer-events: none;
    transition: all 0.15s ease;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.numeric-overlay.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* --- Toast --- */
#toast {
    position: fixed;
    bottom: calc(var(--nav-height) + 72px);
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-surface);
    color: var(--text-primary);
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s;
    z-index: 200;
    box-shadow: var(--shadow);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --- Placeholder Views --- */
.view-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 14px;
}

/* --- Load More --- */
.load-more {
    grid-column: 1 / -1;
    text-align: center;
    padding: 12px;
    color: var(--accent-light);
    cursor: pointer;
    font-size: 13px;
}
.load-more:hover { text-decoration: underline; }

/* --- Responsive --- */
@media (max-width: 768px) {
    :root { --sidebar-width: 0px; }
    #category-sidebar { display: none; }
    #channel-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

@media (max-width: 480px) {
    #channel-grid { grid-template-columns: 1fr; }
    .import-cards { grid-template-columns: 1fr; }
}

/* --- Scrollbar --- */
/* Scrollbars sized for stylus / touch input — 6px is impossible to grab
   on a Surface pen. Keep them wide but visually discreet via translucent
   thumbs. Mobile (touch-only) falls back to narrow overlays via a media
   query below. */
::-webkit-scrollbar { width: 14px; height: 14px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 7px;
    border: 3px solid transparent;
    background-clip: content-box;
    min-height: 48px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
    background-clip: content-box;
    border: 3px solid transparent;
}
::-webkit-scrollbar-corner { background: transparent; }
/* Firefox */
* { scrollbar-width: auto; scrollbar-color: var(--text-muted) transparent; }

/* Smaller viewports: go back to thin overlay-style */
@media (max-width: 768px) {
    ::-webkit-scrollbar { width: 6px; height: 6px; }
    ::-webkit-scrollbar-thumb {
        border: none;
        background-clip: border-box;
    }
    * { scrollbar-width: thin; }
}

/* (Light theme is defined at the top of this file with all theme variables) */

/* --- Settings Page --- */
#view-settings {
    overflow-y: auto;
    overflow-x: hidden;
}

.settings-page {
    max-width: 600px;
    margin: 0 auto;
    padding: 24px 16px;
}

.settings-section {
    background: var(--bg-glass);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.settings-section h3 {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
    font-size: 14px;
    color: var(--text-primary);
}

.settings-row + .settings-row {
    border-top: 1px solid var(--border-glass);
}

.settings-row label {
    flex: 1;
    color: var(--text-primary);
}

.settings-row-btns {
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
}

.settings-select {
    width: auto;
    min-width: 120px;
    flex-shrink: 0;
}

.settings-range {
    width: 140px;
    accent-color: var(--accent);
    flex-shrink: 0;
}

.settings-value {
    color: var(--text-secondary);
    font-size: 13px;
}

.settings-link {
    color: var(--accent-light);
    text-decoration: none;
    font-size: 14px;
}
.settings-link:hover { text-decoration: underline; }

.settings-empty {
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
    padding: 16px 0;
}

.settings-btn {
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--bg-surface);
    color: var(--text-primary);
}
.settings-btn:hover {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent-light);
}
.settings-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.settings-btn.danger {
    color: var(--error);
    border-color: rgba(248, 81, 73, 0.3);
}
.settings-btn.danger:hover {
    background: rgba(248, 81, 73, 0.1);
    border-color: var(--error);
    color: var(--error);
}

/* Profile items */
.profile-item {
    display: flex;
    align-items: center;
    gap: var(--space-s);
    padding: var(--space-s);
    border-radius: var(--radius);
    border: 1px solid var(--border-glass);
    background: var(--bg-surface);
    margin-bottom: var(--space-xs);
    cursor: pointer;
    transition: all var(--transition);
}
.profile-item:hover {
    border-color: var(--accent);
    background: var(--accent-dim);
}
.profile-item.active {
    border-color: var(--accent);
    background: var(--accent-dim);
    box-shadow: 0 0 0 1px var(--accent);
}
.profile-avatar {
    font-size: 28px;
    line-height: 1;
    flex-shrink: 0;
}
.profile-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    flex: 1;
}
.profile-locked {
    font-size: 14px;
}
.profile-active-badge {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent-light);
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    font-weight: 600;
}

/* Playlist items */
.playlist-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    flex-wrap: wrap;
}

.playlist-item + .playlist-item {
    border-top: 1px solid var(--border-glass);
}

.playlist-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.playlist-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.playlist-count {
    font-size: 12px;
    color: var(--text-muted);
}

.playlist-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.playlist-sync,
.playlist-auto {
    font-size: 11px;
    color: var(--text-muted);
    padding: 2px 8px;
    background: var(--bg-surface);
    border-radius: 99px;
    flex-shrink: 0;
}
.playlist-auto {
    color: var(--accent-light);
    background: var(--accent-dim);
}

/* Edit playlist modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    padding: 16px;
    animation: modal-fade-in 0.2s ease;
}
@keyframes modal-fade-in { from { opacity: 0 } to { opacity: 1 } }
.modal-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 480px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 8px;
    animation: modal-pop 0.2s ease;
}
@keyframes modal-pop {
    from { opacity: 0; transform: translateY(8px) scale(0.98) }
    to { opacity: 1; transform: translateY(0) scale(1) }
}
.modal-card h3 {
    font-size: 18px;
    margin-bottom: 8px;
}
.modal-card label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 8px;
    display: block;
}
.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}
.modal-actions .btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.modal-actions .btn-primary:hover {
    background: var(--accent-light);
}

/* Feedback form */
.feedback-card textarea {
    background: var(--bg-surface);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 14px;
    color: var(--text-primary);
    outline: none;
    width: 100%;
    resize: vertical;
    min-height: 120px;
    font-family: inherit;
    box-sizing: border-box;
}
.feedback-card textarea:focus { border-color: var(--accent); }
.feedback-card select {
    background: var(--bg-surface);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 14px;
    color: var(--text-primary);
    width: 100%;
    box-sizing: border-box;
}
.feedback-char-count {
    font-size: 11px;
    color: var(--text-muted);
    text-align: right;
    margin-top: 2px;
}
.feedback-char-count.over { color: var(--error); }
.input.input-error,
.feedback-card textarea.input-error,
.feedback-card select.input-error {
    border-color: var(--error);
}

/* Auth forms */
.account-section #auth-forms .input {
    width: 100%;
    box-sizing: border-box;
}
.account-section #auth-forms .hidden { display: none; }
#sync-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
#sync-row em {
    font-style: normal;
    color: var(--text-muted);
}

/* Shortcut help modal */
.shortcut-help-card .shortcut-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    margin-top: var(--space-s);
}
.shortcut-row {
    display: flex;
    align-items: center;
    gap: var(--space-m);
    padding: var(--space-xs) 0;
    border-bottom: 1px solid var(--border-glass);
    font-size: 14px;
}
.shortcut-row:last-child { border-bottom: none; }
.shortcut-row kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    padding: 4px 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-glass);
    border-bottom-width: 2px;
    border-radius: var(--radius-xs);
    font-family: 'Cascadia Code', Consolas, monospace;
    font-size: 12px;
    color: var(--accent-light);
    font-weight: 600;
}
.shortcut-row span {
    color: var(--text-secondary);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.03em;
    flex-shrink: 0;
}
.badge-file {
    background: rgba(63, 185, 80, 0.15);
    color: #3fb950;
    border: 1px solid rgba(63, 185, 80, 0.3);
}
.badge-url {
    background: rgba(124, 77, 255, 0.15);
    color: var(--accent-light);
    border: 1px solid rgba(124, 77, 255, 0.3);
}
.badge-xtream {
    background: rgba(210, 153, 34, 0.15);
    color: var(--warning);
    border: 1px solid rgba(210, 153, 34, 0.3);
}

/* VOD View */
#view-vod { display: flex; height: 100%; }

#vod-sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-glass);
    overflow-y: auto;
    padding: 8px;
    flex-shrink: 0;
}

.vod-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#vod-grid,
#series-grid {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    align-content: start;
    justify-content: stretch;
}

.vod-card {
    background: var(--bg-glass);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    display: flex;
    flex-direction: column;
    /* Virtualisation: 'auto 320px' lets the browser remember the real height */
    content-visibility: auto;
    contain-intrinsic-size: auto 320px;
    min-height: 280px;
}
.vod-card:hover {
    border-color: var(--accent-dim);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.vod-poster {
    aspect-ratio: 2 / 3;
    background: var(--bg-surface);
    position: relative;
    overflow: hidden;
    width: 100%;
    flex-shrink: 0;
    /* Fallback height in case aspect-ratio is unsupported or fights flex */
    min-height: 240px;
}
.vod-poster img {
    width: 100%;
    height: 100%;
    /* cover so the poster fills the card without letterbox; better for portrait artwork */
    object-fit: cover;
    object-position: center top;
    position: relative;
    z-index: 2;
    background: var(--bg-surface);
    display: block;
}
.vod-poster-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    background: linear-gradient(135deg, var(--bg-surface) 0%, var(--bg-elevated) 100%);
    z-index: 1;
    opacity: 1;
    transition: opacity 0.25s ease;
}
.vod-poster-icon {
    width: 48px;
    height: 48px;
    opacity: 0.5;
}
/* Hide the placeholder once the real image has loaded (set via onload) */
.vod-poster.loaded .vod-poster-placeholder {
    opacity: 0;
    pointer-events: none;
}
/* Failed/empty state: tint the placeholder with the accent for visual interest */
.vod-poster.failed {
    background: linear-gradient(135deg, var(--bg-surface) 0%, var(--bg-elevated) 100%);
}
.vod-poster.failed .vod-poster-icon {
    color: var(--accent-dim, var(--accent));
    opacity: 0.45;
}

/* Resume progress bar at the bottom of the poster */
.vod-progress {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 4px;
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent);
    z-index: 2;
    transition: width 0.3s;
}

.vod-info { padding: 8px 10px; }
.vod-title {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.vod-meta {
    display: flex;
    gap: 8px;
    margin-top: 4px;
    font-size: 11px;
    color: var(--text-muted);
}

.vod-card .fav-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(0,0,0,0.5);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (max-width: 768px) {
    #vod-sidebar { display: none; }
    #vod-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}

/* --- Series View --- */
#view-series { display: flex; height: 100%; }

#series-sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-glass);
    overflow-y: auto;
    padding: 8px;
    flex-shrink: 0;
}

.series-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Series card — shares .vod-poster / .vod-info / .vod-title / .vod-meta with VOD */
.series-card {
    background: var(--bg-glass);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    display: flex;
    flex-direction: column;
    content-visibility: auto;
    contain-intrinsic-size: auto 320px;
    min-height: 280px;
}
.series-card:hover {
    border-color: var(--accent-dim);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}
.series-card .fav-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(0,0,0,0.5);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Series detail */
.series-detail {
    padding: 16px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
}
.series-detail .back-btn {
    background: none;
    border: none;
    color: var(--accent-light);
    cursor: pointer;
    font-size: 14px;
    padding: 8px 0;
    margin-bottom: 12px;
    display: block;
}
.series-detail .back-btn:hover { text-decoration: underline; }

.series-detail-header { display: flex; gap: 16px; margin-bottom: 16px; align-items: flex-start; }
.series-cover { width: 120px; border-radius: var(--radius); object-fit: cover; flex-shrink: 0; }
.series-title { font-size: 20px; font-weight: 600; margin-bottom: 8px; }
.series-plot { font-size: 13px; color: var(--text-secondary); line-height: 1.5; }

/* Series detail body — split layout: seasons sidebar + episode pane */
.series-detail-body {
    display: flex;
    gap: 0;
    align-items: stretch;
    min-height: 320px;
}

.season-sidebar {
    position: relative;
    flex-shrink: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    padding: 12px 0 12px 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-width: 280px;
    max-width: 700px;
    margin-right: 12px;
    transition: width 0.2s ease, min-width 0.2s ease, padding 0.2s ease, margin 0.2s ease, opacity 0.2s ease;
}
.season-sidebar.collapsed {
    width: 0 !important;
    min-width: 0;
    padding: 0;
    margin-right: 0;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
    border: none;
}
.season-sidebar-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: 0 12px 8px 4px;
    flex-shrink: 0;
}
.season-collapse-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 6px;
    font-size: 12px;
    border-radius: var(--radius-xs);
    transition: all var(--transition);
}
.season-collapse-btn:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}
.season-sidebar-reopen {
    position: absolute;
    top: 20px;
    left: 4px;
    z-index: 10;
    background: var(--bg-glass);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition);
}
.season-sidebar-reopen:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.season-sidebar-reopen.hidden {
    display: none !important;
}
.season-list {
    overflow-y: auto;
    padding-right: 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.season-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all var(--transition);
}
.season-item:hover {
    border-color: var(--accent);
    color: var(--text-primary);
    background: var(--accent-dim);
}
.season-item.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.season-resize-handle {
    position: absolute;
    top: 0;
    right: -6px;
    bottom: 0;
    width: 14px;
    cursor: col-resize;
    background: transparent;
    transition: background var(--transition);
    z-index: 5;
    touch-action: none;
}
.season-resize-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 5px;
    height: 80px;
    border-radius: 3px;
    background: var(--border-glass);
    transition: all var(--transition);
}
.season-resize-handle:hover::after,
.season-resize-handle:active::after {
    background: var(--accent);
    height: 120px;
    width: 6px;
}
.season-resize-handle:hover,
.season-resize-handle:active {
    background: var(--accent-dim);
}
.season-resize-handle:hover::after,
.season-resize-handle:active::after {
    background: var(--accent);
}
.episode-pane {
    flex: 1;
    min-width: 0;
    padding: 0 16px;
}

/* Legacy season-pills selector kept for backwards compatibility (no longer used) */
.season-pills { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.season-pill {
    padding: 6px 16px;
    border-radius: 20px;
    border: 1px solid var(--border-glass);
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    transition: all var(--transition);
}
.season-pill:hover { border-color: var(--accent); color: var(--text-primary); }
.season-pill.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.episode-list { display: flex; flex-direction: column; gap: 4px; }
.episode-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}
.episode-item:hover { background: var(--bg-surface); }
.ep-num { font-weight: 600; color: var(--accent-light); min-width: 32px; font-size: 13px; }
.ep-title { flex: 1; font-size: 13px; }
.ep-watched { color: var(--success); font-size: 14px; min-width: 16px; text-align: center; }
.ep-play-btn {
    background: var(--accent);
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition);
}
.ep-play-btn:hover { background: var(--accent-light); }

@media (max-width: 768px) {
    #series-sidebar { display: none; }
    #series-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
    .series-detail-header { flex-direction: column; }
    .series-cover { width: 100px; }
    .series-detail-body { flex-direction: column; }
    .season-sidebar {
        width: 100% !important;
        max-width: none;
        max-height: 200px;
        margin-bottom: 12px;
    }
    .season-resize-handle { display: none; }
    .episode-pane { padding: 0; }
}

/* --- EPG Guide --- */
#view-guide { display: flex; flex-direction: column; height: 100%; }

#guide-container { display: flex; flex-direction: column; height: 100%; }

.guide-header {
    display: flex; align-items: center; gap: 12px;
    padding: 8px 16px; background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-glass); flex-shrink: 0;
}
.guide-date-label { font-size: 14px; font-weight: 600; min-width: 120px; text-align: center; }
.guide-status { font-size: 12px; color: var(--text-muted); margin-left: auto; }
.guide-search {
    flex: 0 1 240px;
    padding: 6px 12px;
    font-size: 13px;
}
.guide-layout {
    flex: 0 0 auto;
    padding: 6px 10px;
    font-size: 13px;
    cursor: pointer;
}

/* List layout */
.guide-list {
    padding: var(--space-m);
    overflow-y: auto;
    max-height: 100%;
}
.guide-list-channel {
    margin-bottom: var(--space-l);
}
.guide-list-channel-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--accent-light);
    border-bottom: 1px solid var(--border-glass);
    padding-bottom: var(--space-xs);
    margin-bottom: var(--space-xs);
}
.guide-list-program {
    display: flex;
    gap: var(--space-m);
    padding: var(--space-xs) var(--space-s);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition);
}
.guide-list-program:hover { background: var(--accent-dim); }
.guide-list-time {
    flex-shrink: 0;
    width: 120px;
    color: var(--text-muted);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}
.guide-list-title {
    flex: 1;
    color: var(--text-primary);
    font-size: 13px;
}

/* Now & Next layout */
.guide-nownext {
    padding: var(--space-m);
    overflow-y: auto;
    max-height: 100%;
}
.guide-nownext-row {
    display: grid;
    grid-template-columns: 200px 1fr 1fr;
    gap: var(--space-m);
    padding: var(--space-s) var(--space-m);
    border-bottom: 1px solid var(--border-glass);
    align-items: center;
}
.guide-nownext-channel {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 13px;
}
.guide-nownext-now {
    color: var(--text-primary);
    font-size: 13px;
}
.guide-nownext-now strong { color: var(--accent-light); }
.guide-nownext-now span { color: var(--text-muted); font-size: 11px; }
.guide-nownext-next {
    color: var(--text-secondary);
    font-size: 12px;
}
.guide-nownext-empty { color: var(--text-muted); }

.guide-search-results {
    position: absolute;
    top: 76px;
    right: var(--space-m);
    width: 380px;
    max-height: 60vh;
    overflow-y: auto;
    background: var(--bg-elevated);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 100;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}
.search-result {
    padding: var(--space-s) var(--space-m);
    border-bottom: 1px solid var(--border-glass);
    cursor: pointer;
    transition: background var(--transition);
}
.search-result:hover { background: var(--accent-dim); }
.search-result-title {
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
    margin-bottom: 2px;
}
.search-result-meta {
    font-size: 11px;
    color: var(--text-muted);
}
.search-empty {
    padding: var(--space-l);
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}
.popup-reminder-btn {
    margin-top: 8px;
    width: 100%;
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-glass);
}
.popup-reminder-btn:hover {
    background: var(--accent-dim);
    border-color: var(--accent);
}

.guide-body { flex: 1; display: flex; overflow: hidden; }

.guide-channel-col {
    width: 180px; flex-shrink: 0; overflow-y: hidden;
    background: var(--bg-secondary); border-right: 1px solid var(--border-glass);
}

.guide-channel-item {
    display: flex; align-items: center; gap: 8px;
    height: 48px; padding: 0 10px; border-bottom: 1px solid var(--border-glass);
    font-size: 12px; overflow: hidden;
}
.guide-channel-item img { width: 28px; height: 28px; border-radius: 4px; object-fit: contain; flex-shrink: 0; }
.guide-ch-initial {
    width: 28px; height: 28px; border-radius: 4px; background: var(--accent-dim);
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 600; color: var(--accent-light); flex-shrink: 0;
}
.guide-ch-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.guide-timeline-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.guide-time-header {
    display: flex; height: 28px; flex-shrink: 0;
    background: var(--bg-secondary); border-bottom: 1px solid var(--border-glass);
    overflow: hidden; position: relative;
}
.guide-time-slot {
    width: 240px; flex-shrink: 0; padding: 4px 8px;
    font-size: 11px; color: var(--text-muted); border-right: 1px solid var(--border-glass);
}

.guide-programs-scroll { flex: 1; overflow: auto; position: relative; }
.guide-programs { position: relative; min-height: 100%; }

.guide-row {
    position: relative; height: 48px;
    border-bottom: 1px solid var(--border-glass);
}

.guide-program {
    position: absolute; top: 2px; height: 44px;
    background: var(--accent-dim); border: 1px solid var(--border-glass);
    border-radius: var(--radius-xs); padding: 4px 8px;
    overflow: hidden; cursor: pointer; transition: background var(--transition);
    display: flex; flex-direction: column; justify-content: center;
}
.guide-program:hover { background: var(--accent); border-color: var(--accent); }
.guide-program:hover .guide-program-title,
.guide-program:hover .guide-program-time { color: #fff; }
.guide-program-title { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.guide-program-time { font-size: 10px; color: var(--text-muted); }

.guide-now-line {
    position: absolute; top: 0; bottom: 0; width: 2px;
    background: var(--error); z-index: 5; pointer-events: none;
}

/* Program detail popup */
.guide-popup {
    position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
    background: var(--bg-surface); border: 1px solid var(--border-glass);
    border-radius: var(--radius); padding: 20px; max-width: 400px; width: 90%;
    box-shadow: var(--shadow); z-index: 200;
}
.guide-popup-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 199;
}
.guide-popup h3 { margin-bottom: 8px; }
.guide-popup .popup-time { font-size: 13px; color: var(--accent-light); margin-bottom: 8px; }
.guide-popup .popup-desc { font-size: 13px; color: var(--text-secondary); line-height: 1.5; }
.guide-popup .popup-category { font-size: 12px; color: var(--text-muted); margin-top: 8px; }
.guide-popup .popup-close {
    position: absolute; top: 8px; right: 8px; background: none; border: none;
    color: var(--text-secondary); font-size: 18px; cursor: pointer;
}
.popup-catchup-btn { margin-top: 12px; width: 100%; }

@media (max-width: 768px) {
    .guide-channel-col { width: 100px; }
    .guide-channel-item img { display: none; }
    .guide-ch-initial { display: none; }
}

/* =============================================
   Octopus mascot — animated SVG (port of TakoMascot.xaml)
   ============================================= */
.tako-mascot {
    display: inline-block;
    width: 96px;
    height: 96px;
    color: var(--accent);
    /* The whole creature does a slow breathing bounce */
    animation: tako-bounce 2.4s ease-in-out infinite;
}
.tako-mascot.size-sm { width: 48px; height: 48px; }
.tako-mascot.size-lg { width: 160px; height: 160px; }
.tako-mascot.size-xl { width: 240px; height: 240px; }

.tako-mascot .body { fill: currentColor; }
.tako-mascot .cheek { fill: var(--tertiary); opacity: 0.55; }
.tako-mascot .eye-white { fill: #FFFFFF; }
.tako-mascot .pupil {
    fill: #1A1A2E;
    transform-origin: center;
    animation: tako-blink 6s ease-in-out infinite;
}
.tako-mascot .tentacle {
    fill: currentColor;
    transform-origin: 50% 12%;
    animation: tako-tentacle 3.2s ease-in-out infinite;
}
.tako-mascot .tentacle:nth-child(odd)  { animation-delay: 0.2s; }
.tako-mascot .tentacle:nth-child(even) { animation-delay: 0.6s; }

@keyframes tako-bounce {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-8px); }
}
@keyframes tako-blink {
    0%, 92%, 100% { transform: scaleY(1); }
    94%, 96%      { transform: scaleY(0.1); }
}
@keyframes tako-tentacle {
    0%, 100% { transform: rotate(0deg); }
    25%      { transform: rotate(8deg); }
    75%      { transform: rotate(-8deg); }
}

/* Loading-state mascot variant: faster wave */
.tako-mascot.loading {
    animation-duration: 0.8s;
}
.tako-mascot.loading .tentacle {
    animation-duration: 1s;
}

/* Empty-state mascot — bigger, centred */
.empty-state .tako-mascot {
    margin: 0 auto var(--space-m);
    display: block;
    opacity: 0.85;
}

/* =============================================
   Breathable spacing — apply to common containers
   ============================================= */
.settings-page {
    padding: var(--space-l) var(--space-m);
    max-width: 720px;
}
.settings-section {
    padding: var(--space-l);
    margin-bottom: var(--space-m);
    border-radius: var(--radius-lg);
}
.settings-section h3 {
    margin-bottom: var(--space-m);
}
.settings-row {
    padding: var(--space-s) 0;
}

/* =============================================
   Responsive — mobile / tablet / desktop / TV
   ============================================= */

/* Tablet (portrait) */
@media (min-width: 600px) and (max-width: 1023px) {
    :root {
        --sidebar-width: 220px;
    }
    #channel-grid {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    }
    #vod-grid,
    #series-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }
}

/* Desktop */
@media (min-width: 1024px) and (max-width: 1599px) {
    :root {
        --sidebar-width: 260px;
    }
    #channel-grid {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    }
    #vod-grid,
    #series-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
}

/* Large desktop / TV */
@media (min-width: 1600px) {
    :root {
        --sidebar-width: 300px;
    }
    #channel-grid {
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    }
    #vod-grid,
    #series-grid {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
        gap: var(--space-l);
    }
}

/* Extra-small phones */
@media (max-width: 479px) {
    .top-bar {
        padding: var(--space-xs) var(--space-s);
    }
    .top-bar-title { display: none; }
    .playlist-selector { max-width: none; flex: 1; }

    #channel-grid {
        grid-template-columns: 1fr 1fr;
        gap: var(--space-xs);
        padding: var(--space-xs);
    }
    #vod-grid,
    #series-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: var(--space-s);
        padding: var(--space-s);
    }
    .channel-card {
        padding: var(--space-xs) var(--space-s);
    }
    .ch-logo { width: 36px; height: 36px; }
    .nav-btn { padding: var(--space-xs) var(--space-s); font-size: 10px; }
    .nav-btn .nav-icon { font-size: 18px; }

    .modal-card { padding: var(--space-m); }
    .settings-page { padding: var(--space-m) var(--space-xs); }
    .settings-section { padding: var(--space-m); }
}

/* TV / large landscape: 10-foot UI hint, scale focus rings */
@media (min-width: 1920px) {
    body { font-size: 16px; }
    .nav-btn { padding: var(--space-s) var(--space-l); font-size: 13px; }
    .nav-btn .nav-icon { font-size: 24px; }
}

/* Pointer-coarse (touch): bigger tap targets */
@media (pointer: coarse) {
    .nav-btn { min-height: 48px; }
    .player-btn { padding: var(--space-s); }
    .settings-btn { min-height: 40px; padding: var(--space-xs) var(--space-m); }
    .fab { width: 56px; height: 56px; }
}

/* --- No-playlist state: disable content nav tabs --- */
body.no-playlist .nav-btn[data-nav="live"],
body.no-playlist .nav-btn[data-nav="guide"],
body.no-playlist .nav-btn[data-nav="vod"],
body.no-playlist .nav-btn[data-nav="series"] {
    opacity: 0.3;
    pointer-events: none;
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
    .tako-mascot, .tako-mascot * { animation: none !important; }
}
