:root {
    --bg: #141414;
    --surface: #181818;
    --surface-2: #222222;
    --surface-3: #2f2f2f;
    --accent: #e50914;
    --text: #ffffff;
    --muted: #aaaaaa;
    --danger: #ff4d57;
    --nav-h: 68px;
    --page-x: clamp(16px, 4vw, 72px);
    --radius: 8px;
    --shadow: 0 16px 40px rgba(0, 0, 0, .55);
    --focus: 0 0 0 3px rgba(255, 255, 255, .92), 0 0 0 6px rgba(229, 9, 20, .75);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    scroll-behavior: smooth;
}

body {
    min-width: 320px;
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
}

body.modal-open {
    overflow: hidden;
}

button,
input,
a {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    border: 0;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
summary:focus-visible {
    outline: none;
    box-shadow: var(--focus);
}

[hidden] {
    display: none !important;
}

.brand {
    color: var(--accent);
    font-weight: 950;
    letter-spacing: -.05em;
    font-size: clamp(1.5rem, 2.6vw, 2.25rem);
    line-height: 1;
}

.brand--auth {
    font-size: clamp(2.4rem, 8vw, 4rem);
    margin-bottom: 18px;
}

.eyebrow {
    color: var(--muted);
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .14em;
}

.muted {
    color: var(--muted);
}

.button {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 750;
    transition: transform .16s ease, background .16s ease, opacity .16s ease;
}

.button:active {
    transform: scale(.98);
}

.button:disabled {
    opacity: .48;
    cursor: not-allowed;
}

.button--primary {
    background: var(--accent);
    color: white;
}

.button--primary:hover {
    background: #f6121d;
}

.button--light {
    background: white;
    color: #111;
}

.button--light:hover {
    background: rgba(255, 255, 255, .8);
}

.button--secondary {
    background: rgba(109, 109, 110, .72);
    color: white;
    backdrop-filter: blur(10px);
}

.button--secondary:hover {
    background: rgba(109, 109, 110, .9);
}

.button--ghost {
    background: var(--surface-2);
    color: white;
}

.button--full {
    width: 100%;
}

.auth-shell,
.status-page {
    min-height: 100svh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 20% 10%, rgba(229, 9, 20, .18), transparent 32%),
        linear-gradient(180deg, #0a0a0a 0%, var(--bg) 60%);
}

.auth-card {
    width: min(100%, 460px);
    padding: clamp(28px, 5vw, 52px);
    background: rgba(0, 0, 0, .78);
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.auth-card h1 {
    margin: 4px 0 8px;
    font-size: clamp(2rem, 6vw, 2.8rem);
}

.auth-form {
    display: grid;
    gap: 10px;
    margin-top: 24px;
}

.auth-form label {
    margin-top: 8px;
    color: #d5d5d5;
    font-size: .9rem;
    font-weight: 650;
}

.auth-form input,
.search input {
    color: var(--text);
    background: #252525;
    border: 1px solid #3d3d3d;
    border-radius: 6px;
}

.auth-form input {
    min-height: 52px;
    padding: 0 14px;
}

.alert {
    padding: 12px 14px;
    border-radius: 6px;
    margin-top: 18px;
}

.alert--error {
    color: #fff;
    border: 1px solid rgba(255, 77, 87, .5);
    background: rgba(255, 77, 87, .14);
}

.topbar {
    position: fixed;
    inset: 0 0 auto;
    z-index: 1000;
    min-height: var(--nav-h);
    display: flex;
    align-items: center;
    gap: clamp(16px, 3vw, 36px);
    padding:
        max(10px, env(safe-area-inset-top))
        var(--page-x)
        10px;
    background: linear-gradient(180deg, rgba(0, 0, 0, .88), rgba(0, 0, 0, .2), transparent);
    transition: background .25s ease, backdrop-filter .25s ease;
}

.topbar.is-solid {
    background: rgba(20, 20, 20, .96);
    backdrop-filter: blur(12px);
}

.main-nav {
    display: flex;
    align-items: center;
    gap: clamp(10px, 2vw, 24px);
    font-size: .95rem;
}

.main-nav a {
    color: #e5e5e5;
    transition: color .15s ease;
    white-space: nowrap;
}

.main-nav a:hover,
.main-nav a.is-active {
    color: white;
    font-weight: 700;
}

.topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.search {
    width: clamp(42px, 20vw, 260px);
    min-height: 40px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    border: 1px solid rgba(255, 255, 255, .28);
    background: rgba(0, 0, 0, .52);
    border-radius: 6px;
}

.search input {
    width: 100%;
    min-width: 0;
    border: 0;
    background: transparent;
    outline: 0;
}

.profile-menu {
    position: relative;
}

.profile-menu summary {
    list-style: none;
    cursor: pointer;
}

.profile-menu summary::-webkit-details-marker {
    display: none;
}

.avatar {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 6px;
    background: var(--accent);
    color: white;
    font-weight: 900;
}

.profile-popover {
    position: absolute;
    right: 0;
    top: 48px;
    width: 220px;
    display: grid;
    gap: 8px;
    padding: 16px;
    color: white;
    background: rgba(18, 18, 18, .98);
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.profile-popover span {
    color: var(--muted);
    font-size: .86rem;
}

.hero {
    position: relative;
    min-height: clamp(500px, 72svh, 920px);
    display: flex;
    align-items: flex-end;
    overflow: clip;
    background: #0d0d0d;
}

.hero-backdrop {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 70% 40%, rgba(229, 9, 20, .12), transparent 30%),
        linear-gradient(135deg, #252525, #0d0d0d 65%);
    background-size: cover;
    background-position: center 28%;
    transform: scale(1.01);
    transition: opacity .3s ease;
}

.hero-gradient {
    position: absolute;
    inset: 0;
    background:
        linear-gradient(90deg, rgba(20,20,20,.96) 0%, rgba(20,20,20,.65) 36%, rgba(20,20,20,.08) 70%),
        linear-gradient(0deg, var(--bg) 0%, rgba(20,20,20,.92) 7%, transparent 38%);
}

.hero-content {
    position: relative;
    z-index: 1;
    width: min(760px, 86vw);
    padding: 0 var(--page-x) clamp(72px, 11vw, 150px);
}

.hero-kicker {
    color: var(--accent);
    font-size: clamp(.72rem, 1.2vw, .9rem);
    font-weight: 900;
    letter-spacing: .16em;
}

.hero h1 {
    max-width: 15ch;
    margin: 10px 0;
    font-size: clamp(2.4rem, 7vw, 6.3rem);
    line-height: .96;
    letter-spacing: -.04em;
    text-wrap: balance;
}

.hero-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    color: #d7d7d7;
    font-weight: 650;
}

.hero-description {
    max-width: 62ch;
    color: #e0e0e0;
    font-size: clamp(.95rem, 1.4vw, 1.14rem);
    line-height: 1.55;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.hero-actions {
    display: flex;
    gap: 12px;
    margin-top: 22px;
}

.catalog,
.search-results {
    position: relative;
    z-index: 10;
    margin-top: clamp(-74px, -7vw, -42px);
    padding: 0 0 52px;
}

.row-section {
    position: relative;
    margin: 0 0 clamp(20px, 3vw, 42px);
}

.row-heading {
    margin: 0 var(--page-x) 10px;
    font-size: clamp(1.05rem, 2vw, 1.55rem);
    letter-spacing: -.015em;
}

.media-row {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: clamp(150px, 18vw, 320px);
    gap: clamp(6px, .8vw, 12px);
    overflow-x: auto;
    overflow-y: visible;
    padding: 8px var(--page-x) 26px;
    scroll-padding-inline: var(--page-x);
    scroll-snap-type: x mandatory;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
}

.media-row::-webkit-scrollbar {
    display: none;
}

.media-card {
    position: relative;
    min-width: 0;
    cursor: pointer;
    scroll-snap-align: start;
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 5px 15px rgba(0, 0, 0, .24);
    transition: transform .2s cubic-bezier(.2,.8,.2,1), box-shadow .2s ease;
    transform-origin: center;
}

.media-card__image-wrap {
    position: relative;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    border-radius: var(--radius);
    background: linear-gradient(135deg, #2b2b2b, #171717);
}

.media-card[data-type="movies"] .media-card__image-wrap,
.media-card[data-type="series"] .media-card__image-wrap {
    aspect-ratio: 16 / 9;
}

.media-card img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    background: #222;
}

.media-card__fallback {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 12px;
    color: #cfcfcf;
    text-align: center;
    font-weight: 800;
}

.media-card__body {
    padding: 10px 10px 12px;
}

.media-card__title {
    margin: 0;
    overflow: hidden;
    font-size: clamp(.83rem, 1.2vw, 1rem);
    font-weight: 750;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.media-card__meta {
    margin-top: 5px;
    color: var(--muted);
    font-size: .76rem;
}

@media (hover: hover) and (pointer: fine) {
    .media-card:hover {
        z-index: 20;
        transform: scale(1.08);
        box-shadow: var(--shadow);
    }
}

.loading-state,
.empty-state {
    min-height: 220px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 12px;
    color: var(--muted);
    padding: 30px var(--page-x);
}

.spinner {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid #333;
    border-top-color: var(--accent);
    animation: spin .8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.player-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: grid;
    place-items: center;
    padding: clamp(0px, 2vw, 24px);
}

.player-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.82);
    backdrop-filter: blur(7px);
}

.player-modal__panel {
    position: relative;
    z-index: 1;
    width: min(1180px, 100%);
    max-height: min(94svh, 960px);
    overflow: auto;
    background: #101010;
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.player-modal__header {
    position: sticky;
    top: 0;
    z-index: 5;
    min-height: 68px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 14px 18px;
    background: rgba(16,16,16,.95);
    backdrop-filter: blur(12px);
}

.player-modal__header h2 {
    margin: 3px 0 0;
    font-size: clamp(1.15rem, 2vw, 1.6rem);
}

.icon-button {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: #282828;
    color: white;
    font-size: 1.7rem;
    cursor: pointer;
}

.video-wrap {
    position: relative;
    aspect-ratio: 16 / 9;
    background: black;
}

.video-wrap video {
    width: 100%;
    height: 100%;
    display: block;
    background: black;
}

.player-message {
    position: absolute;
    inset: auto 16px 16px;
    padding: 12px 14px;
    border-radius: 6px;
    background: rgba(0,0,0,.82);
    color: white;
    border: 1px solid rgba(255,255,255,.12);
}

.player-details {
    padding: 18px;
}

.episode-list {
    display: grid;
    gap: 8px;
    margin-top: 18px;
}

.episode-button {
    width: 100%;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 12px;
    padding: 12px;
    color: white;
    text-align: left;
    background: #1d1d1d;
    border-radius: 7px;
    cursor: pointer;
}

.episode-button:hover {
    background: #292929;
}

.toast {
    position: fixed;
    z-index: 3000;
    right: max(18px, env(safe-area-inset-right));
    bottom: max(18px, env(safe-area-inset-bottom));
    width: min(420px, calc(100vw - 36px));
    padding: 12px 14px;
    border-radius: 8px;
    color: white;
    background: #2d2d2d;
    box-shadow: var(--shadow);
}

.noscript {
    position: fixed;
    inset: auto 0 0;
    z-index: 9999;
    padding: 12px;
    text-align: center;
    background: var(--accent);
    color: white;
}

.status-page {
    text-align: center;
}

.status-page h1 {
    margin: 18px 0 0;
    font-size: clamp(5rem, 20vw, 12rem);
    line-height: 1;
}

@media (max-width: 860px) {
    :root {
        --nav-h: 60px;
    }

    .topbar {
        gap: 12px;
    }

    .main-nav {
        order: 3;
        position: fixed;
        inset: auto 0 0;
        z-index: 1000;
        height: calc(58px + env(safe-area-inset-bottom));
        justify-content: space-around;
        gap: 0;
        padding: 0 8px env(safe-area-inset-bottom);
        background: rgba(16,16,16,.97);
        border-top: 1px solid rgba(255,255,255,.08);
    }

    .main-nav a {
        min-width: 68px;
        display: grid;
        place-items: center;
        min-height: 52px;
        font-size: .77rem;
    }

    .topbar .brand {
        font-size: 1.55rem;
    }

    .install-button {
        display: none !important;
    }

    .search {
        width: min(42vw, 220px);
    }

    .hero {
        min-height: 68svh;
    }

    .hero-gradient {
        background:
            linear-gradient(90deg, rgba(20,20,20,.83), rgba(20,20,20,.25)),
            linear-gradient(0deg, var(--bg) 0%, rgba(20,20,20,.86) 12%, transparent 52%);
    }

    .hero-content {
        width: 100%;
        padding-bottom: 88px;
    }

    .catalog,
    .search-results {
        padding-bottom: 82px;
    }

    .media-row {
        grid-auto-columns: clamp(152px, 42vw, 240px);
    }
}

@media (max-width: 520px) {
    .topbar-actions {
        gap: 6px;
    }

    .search {
        width: 42px;
        padding: 0 11px;
        transition: width .2s ease;
    }

    .search:focus-within {
        position: absolute;
        right: 58px;
        width: calc(100vw - 132px);
        background: #111;
    }

    .search input {
        opacity: 0;
        pointer-events: none;
    }

    .search:focus-within input {
        opacity: 1;
        pointer-events: auto;
    }

    .hero h1 {
        font-size: clamp(2.2rem, 12vw, 3.9rem);
    }

    .hero-description {
        -webkit-line-clamp: 2;
    }

    .hero-actions .button {
        flex: 1;
        padding-inline: 10px;
    }

    .player-modal {
        padding: 0;
    }

    .player-modal__panel {
        min-height: 100svh;
        max-height: 100svh;
        border-radius: 0;
    }

    .episode-button {
        grid-template-columns: auto 1fr;
    }
}

@media (min-width: 1800px) {
    :root {
        --page-x: clamp(72px, 4vw, 120px);
    }

    .media-row {
        grid-auto-columns: clamp(280px, 15vw, 420px);
    }
}

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