:root {
    --bg: #070a12;
    --bg-elevated: #0d1220;
    --card: #121826;
    --card-hover: #1a2234;
    --border: #1e293b;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-soft: rgba(99, 102, 241, 0.15);
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 10px 40px -10px rgba(0,0,0,0.5);
    --font: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --header-h: 64px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; transition: color 0.15s; }
a:hover { color: var(--accent-hover); }
img { max-width: 100%; display: block; }

.container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.site-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: rgba(7, 10, 18, 0.92);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
}
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-h);
    gap: 16px;
    position: relative;
}
.logo {
    font-size: 1.35rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    z-index: 1002;
}
.logo span { color: var(--accent); }

/* Desktop nav */
.nav {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    justify-content: center;
}
.nav > a,
.nav-dropdown-btn {
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}
.nav > a:hover,
.nav > a.active,
.nav-dropdown-btn:hover,
.nav-dropdown-btn.active {
    color: var(--text);
    background: var(--accent-soft);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    z-index: 1002;
}
.user-login {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Hamburger — hidden on desktop */
.mobile-toggle {
    display: none;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    z-index: 1003;
    -webkit-tap-highlight-color: transparent;
}

/* Cabinet dropdown */
.nav-dropdown { position: relative; display: inline-flex; align-items: center; }
.nav-caret { font-size: 0.7rem; opacity: 0.8; margin-left: 4px; }
.nav-badge {
    background: var(--accent);
    color: #fff;
    padding: 1px 7px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-left: 4px;
}
.nav-dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 200px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    box-shadow: var(--shadow);
    z-index: 1100;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.nav-dropdown-menu[hidden] { display: none !important; }
.nav-dropdown-menu a {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 500;
}
.nav-dropdown-menu a:hover { background: var(--accent-soft); }
.nav-dropdown-menu .nav-logout {
    border-top: 1px solid var(--border);
    margin-top: 4px;
    padding-top: 12px;
    color: var(--text-muted);
}
.nav-mobile-only { display: none; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    font-family: inherit;
    min-height: 40px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; min-height: 36px; }

/* Hero / search */
.hero {
    padding: 40px 0 24px;
    background: linear-gradient(180deg, rgba(99,102,241,0.08) 0%, transparent 100%);
}
.search-bar {
    display: flex;
    gap: 12px;
    max-width: 640px;
    margin: 0 auto;
}
.search-bar input {
    flex: 1;
    padding: 14px 18px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1rem;
}
.search-bar input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 16px 0 24px;
    align-items: center;
}
.filters select {
    padding: 8px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.875rem;
    cursor: pointer;
}
.filters select:focus { outline: none; border-color: var(--accent); }

/* Catalog */
.catalog-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 20px;
    padding-bottom: 48px;
}
@media (min-width: 768px) {
    .catalog-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}
.card {
    background: var(--card);
    border-radius: var(--radius);
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid transparent;
    color: inherit;
}
.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow);
    border-color: var(--border);
}
.card-poster {
    position: relative;
    aspect-ratio: 2/3;
    background: var(--bg-elevated);
    overflow: hidden;
}
.card-poster img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s;
}
.card:hover .card-poster img { transform: scale(1.05); }
.card-badge {
    position: absolute;
    top: 8px; left: 8px;
    padding: 3px 8px;
    background: rgba(0,0,0,0.75);
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 600;
    color: #fff;
}
.card-rating {
    position: absolute;
    top: 8px; right: 8px;
    padding: 3px 8px;
    background: rgba(0,0,0,0.75);
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    color: #fbbf24;
}
.card-body { padding: 12px; }
.card-title {
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: var(--text);
}
.card-meta { font-size: 0.75rem; color: var(--text-muted); }

/* Content page */
.content-page { padding: 32px 0 64px; }
.content-header {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 32px;
    margin-bottom: 32px;
}
@media (max-width: 640px) {
    .content-header { grid-template-columns: 1fr; }
}
.content-poster {
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.content-poster img { width: 100%; }
.content-info h1 {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 8px;
}
.content-original { color: var(--text-muted); font-size: 1rem; margin-bottom: 16px; }
.meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}
.meta-tag {
    padding: 4px 10px;
    background: var(--accent-soft);
    border-radius: 6px;
    color: var(--accent-hover);
    font-weight: 500;
}
.content-desc {
    color: var(--text-muted);
    line-height: 1.7;
    margin-bottom: 24px;
    max-width: 720px;
}
.player-wrap {
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    aspect-ratio: 16/9;
    margin-bottom: 32px;
    position: relative;
}
.player-wrap iframe,
.player-wrap video {
    width: 100%;
    height: 100%;
    border: 0;
}

/* Auth */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: radial-gradient(ellipse at top, #1e1b4b 0%, var(--bg) 60%);
}
.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 36px;
    box-shadow: var(--shadow);
}
.auth-card h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
    text-align: center;
}
.auth-card .subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 28px;
    font-size: 0.95rem;
}
.form-group { margin-bottom: 18px; }
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}
.form-group input {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 1rem;
}
.form-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.auth-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 0.9rem;
}
.alert-error { background: rgba(239,68,68,0.12); border: 1px solid var(--danger); color: #fca5a5; }
.alert-success { background: rgba(34,197,94,0.12); border: 1px solid var(--success); color: #86efac; }
.alert-info { background: var(--accent-soft); border: 1px solid var(--accent); color: var(--accent-hover); }

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 24px 0 48px;
    flex-wrap: wrap;
}
.pagination a, .pagination span {
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    background: var(--card);
    color: var(--text-muted);
    border: 1px solid var(--border);
    min-width: 44px;
    text-align: center;
}
.pagination a:hover { border-color: var(--accent); color: var(--text); }
.pagination .current {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.empty {
    text-align: center;
    padding: 64px 20px;
    color: var(--text-muted);
}
.empty h3 { font-size: 1.25rem; margin-bottom: 8px; color: var(--text); }

.site-footer {
    border-top: 1px solid var(--border);
    padding: 24px 0;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Focus */
:focus { outline: none; }
:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
}
.card:focus-visible {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 0 0 3px var(--accent), var(--shadow);
}

a, button, .card, select { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

/* Admin */
.admin-wrap { padding: 24px 0 48px; }
.admin-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 32px;
}
.admin-card {
    background: var(--card);
    padding: 20px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.admin-card h2 { font-size: 1.05rem; margin-bottom: 14px; }
.admin-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    min-width: 520px;
}
.admin-table th, .admin-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.admin-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}
.admin-nav a {
    padding: 10px 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
}
.admin-nav a:hover, .admin-nav a.active {
    border-color: var(--accent);
    color: var(--text);
    background: var(--accent-soft);
}

/* ========== MOBILE ========== */
@media (max-width: 768px) {
    :root { --header-h: 56px; }
    .container { padding: 0 14px; }
    .header-inner { height: var(--header-h); }

    .mobile-toggle {
        display: inline-flex !important;
    }

    /* Hide desktop nav by default on mobile */
    .nav {
        display: none;
        position: absolute;
        top: var(--header-h);
        left: 0;
        right: 0;
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        background: var(--bg-elevated);
        border-bottom: 1px solid var(--border);
        padding: 8px 12px 16px;
        gap: 4px;
        max-height: min(75vh, 520px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        box-shadow: 0 16px 40px rgba(0,0,0,0.45);
        z-index: 1001;
    }

    /* Open state — class on #mainNav */
    .nav.is-open {
        display: flex !important;
    }

    .nav > a {
        display: flex;
        align-items: center;
        padding: 14px 12px;
        min-height: 48px;
        font-size: 1rem;
        border-radius: var(--radius-sm);
    }

    .nav-dropdown {
        display: flex;
        flex-direction: column;
        width: 100%;
        align-items: stretch;
    }
    .nav-dropdown-btn {
        width: 100%;
        justify-content: space-between;
        padding: 14px 12px;
        min-height: 48px;
        font-size: 1rem;
        display: flex;
        align-items: center;
    }
    .nav-dropdown-menu {
        position: static;
        min-width: 0;
        width: 100%;
        box-shadow: none;
        border: none;
        background: rgba(0,0,0,0.2);
        padding: 4px 0 4px 8px;
        margin-top: 0;
        border-radius: var(--radius-sm);
    }
    .nav-dropdown-menu:not([hidden]) {
        display: flex !important;
    }
    .nav-dropdown-menu a {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .nav-mobile-only { display: flex !important; }
    .user-login { display: none; }

    .hero { padding: 20px 0 12px; }
    .search-bar { flex-direction: column; gap: 8px; }
    .search-bar input { font-size: 16px; }
    .search-bar .btn { width: 100%; }
    .filters form { flex-direction: column; width: 100%; }
    .filters select { width: 100%; font-size: 16px; padding: 12px; }
    .catalog-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 12px;
    }
    .content-poster { max-width: 200px; margin: 0 auto; }
    .content-info h1 { font-size: 1.35rem; }
    .auth-card { padding: 24px 18px; }
    .admin-grid { grid-template-columns: 1fr; }
    .admin-nav {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .admin-nav a { white-space: nowrap; flex-shrink: 0; }
}

@media (max-width: 400px) {
    .catalog-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}

/* Desktop: ensure nav visible, hide hamburger */
@media (min-width: 769px) {
    .mobile-toggle { display: none !important; }
    .nav {
        display: flex !important;
        position: static;
        flex-direction: row;
        max-height: none;
        overflow: visible;
        background: transparent;
        border: none;
        box-shadow: none;
        padding: 0;
        width: auto;
    }
}

/* Android TV */
@media (min-width: 960px) and (pointer: coarse),
       (min-width: 1280px) and (hover: none) {
    body { font-size: 18px; }
    .header-inner { height: 80px; }
    .logo { font-size: 1.6rem; }
    .nav > a, .nav-dropdown-btn {
        padding: 14px 20px;
        font-size: 1.1rem;
        min-height: 52px;
    }
    .btn { padding: 14px 28px; font-size: 1.05rem; min-height: 52px; }
    .catalog-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 24px;
    }
    .card:focus-visible { transform: scale(1.06); z-index: 2; }
}

@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
    .site-header { padding-top: max(0px, env(safe-area-inset-top)); }
    .site-footer { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}
