/* 
  CINEMATIC BRUTALIST DESIGN
  - Pure Blacks, Blood Reds, High Contrast
  - Monolithic Typography
  - Sharp Edges (0px border-radius)
*/

:root {
    --bg: #000000;
    --surface: #0A0A0A;
    --surface-light: #1A1A1A;
    --red: #E50914;
    --red-dark: #990000;
    --text: #FFFFFF;
    --text-muted: #888888;
    --border: #333333;
    
    --font-display: 'Anton', sans-serif;
    --font-mono: 'Roboto Mono', monospace;
    
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 32px;
    --space-xl: 64px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg);
    color: var(--text);
    font-family: var(--font-mono);
    line-height: 1.5;
    overflow-x: hidden;
    padding-bottom: 80px; /* Mobile nav space */
}

/* Typography */
h1, h2, h3 {
    font-family: var(--font-display);
    text-transform: uppercase;
    letter-spacing: 2px;
    line-height: 1;
}

/* Navbar */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md) var(--space-lg);
    background: var(--bg);
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.brand {
    font-family: var(--font-display);
    font-size: 2rem;
    color: var(--red);
    letter-spacing: 4px;
}

.nav-links {
    display: none;
    gap: var(--space-lg);
}

.nav-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 700;
    transition: color 0.2s;
    font-size: 0.9rem;
}

.nav-links a:hover, .nav-links a.active {
    color: var(--text);
}

/* Hero Section */
.hero {
    position: relative;
    min-height: 70vh;
    display: flex;
    align-items: flex-end;
    padding: var(--space-xl) var(--space-lg);
    border-bottom: 4px solid var(--red);
}

.hero-bg {
    position: absolute;
    inset: 0;
    z-index: 0;
}

.hero-bg img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: grayscale(80%) contrast(120%);
}

.hero-vignette {
    position: absolute;
    inset: 0;
    background: linear-gradient(0deg, rgba(0,0,0,1) 0%, rgba(0,0,0,0.4) 50%, rgba(0,0,0,0.8) 100%);
}

.hero-content {
    position: relative;
    z-index: 1;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.status-badge {
    background: var(--red);
    color: var(--text);
    padding: 4px 8px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 2px;
    display: inline-block;
    align-self: flex-start;
}

.hero h1 {
    font-size: clamp(3rem, 10vw, 7rem);
    color: var(--text);
    text-shadow: 4px 4px 0px var(--red);
}

/* Glitch Effect */
.glitch {
    position: relative;
}
.glitch::before, .glitch::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
}
.glitch::before {
    left: 2px;
    text-shadow: -2px 0 #00ffff;
    clip: rect(24px, 550px, 90px, 0);
    animation: glitch-anim 3s infinite linear alternate-reverse;
}
.glitch::after {
    left: -2px;
    text-shadow: -2px 0 #ff00ff;
    clip: rect(85px, 550px, 140px, 0);
    animation: glitch-anim 2.5s infinite linear alternate-reverse;
}

@keyframes glitch-anim {
    0% { clip: rect(10px, 9999px, 80px, 0); }
    20% { clip: rect(40px, 9999px, 10px, 0); }
    40% { clip: rect(80px, 9999px, 50px, 0); }
    60% { clip: rect(20px, 9999px, 90px, 0); }
    80% { clip: rect(90px, 9999px, 20px, 0); }
    100% { clip: rect(30px, 9999px, 60px, 0); }
}

.synopsis {
    font-size: 1rem;
    color: #CCCCCC;
    max-width: 600px;
}

.action-row {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    margin-top: var(--space-md);
    flex-wrap: wrap;
}

.btn-brutal {
    background: var(--red);
    color: var(--text);
    border: none;
    padding: 16px 32px;
    font-family: var(--font-display);
    font-size: 1.5rem;
    letter-spacing: 2px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    text-transform: uppercase;
    transition: all 0.2s;
    outline: 2px solid transparent;
}

.btn-brutal:hover {
    background: var(--text);
    color: var(--bg);
    outline: 2px solid var(--red);
    outline-offset: 4px;
}

.btn-brutal:active {
    transform: translate(2px, 2px);
}

.stats {
    display: flex;
    flex-direction: column;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Database / Episode List */
.database {
    padding: var(--space-xl) var(--space-lg);
    max-width: 1200px;
    margin: 0 auto;
}

.db-header {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
    border-bottom: 2px solid var(--border);
    padding-bottom: var(--space-md);
}

.db-header h2 {
    font-size: 2rem;
    color: var(--text-muted);
}

.season-tabs {
    display: flex;
    gap: var(--space-md);
    overflow-x: auto;
    padding-bottom: 8px;
}

.tab-btn {
    background: transparent;
    border: 2px solid var(--border);
    color: var(--text-muted);
    font-family: var(--font-display);
    font-size: 1.25rem;
    padding: 8px 24px;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 80px;
}

.tab-btn.active, .tab-btn:hover {
    background: var(--text);
    color: var(--bg);
    border-color: var(--text);
}

.episode-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-sm);
}

.ep-row {
    display: flex;
    align-items: stretch;
    background: var(--surface);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
    height: 100px;
}

.ep-row:hover {
    background: var(--surface-light);
    border-color: var(--red);
    transform: translateX(8px);
}

.ep-num {
    width: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--border);
    font-family: var(--font-display);
    font-size: 1.5rem;
    color: var(--text-muted);
}

.ep-row:hover .ep-num {
    background: var(--red);
    color: var(--text);
}

.ep-thumb {
    width: 140px;
    object-fit: cover;
    filter: grayscale(100%);
    transition: filter 0.2s;
    flex-shrink: 0;
}

.ep-row:hover .ep-thumb {
    filter: grayscale(0%);
}

.ep-details {
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex: 1;
    overflow: hidden;
}

.ep-details h4 {
    font-family: var(--font-display);
    font-size: 1.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ep-details p {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* Video Player */
.player-section {
    background: var(--bg);
    padding: var(--space-lg);
    border-bottom: 4px solid var(--red);
}

.player-section.hidden {
    display: none;
}

.player-header {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.player-title-row {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.player-title-row h2 {
    font-size: 1.2rem;
    color: var(--red);
    flex: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-ep-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-family: var(--font-display);
    font-size: 0.8rem;
    padding: 6px 14px;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 1px;
    white-space: nowrap;
    min-height: 36px;
}

.nav-ep-btn:hover {
    background: var(--red);
    color: var(--text);
    border-color: var(--red);
}

.player-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
}

.player-header h2 {
    font-size: 1.5rem;
    color: var(--red);
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 8px;
}

.btn-icon:hover {
    color: var(--red);
}

.video-wrapper {
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
    border: 2px solid var(--border);
}

video {
    width: 100%;
    height: 100%;
    outline: none;
}

/* Mobile Nav */
.mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg);
    border-top: 2px solid var(--border);
    display: flex;
    justify-content: space-around;
    padding: var(--space-md) 0;
    z-index: 100;
}

.mobile-nav a {
    color: var(--text-muted);
    padding: 8px 24px;
}

.mobile-nav a.active {
    color: var(--red);
}

/* Server Switch */
.player-controls {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.server-switch {
    display: flex;
    border: 1px solid var(--border);
}

.server-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 700;
    padding: 8px 12px;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 1px;
    min-height: 44px;
}

.server-btn.active {
    background: var(--red);
    color: var(--text);
}

.server-btn.unavailable {
    opacity: 0.3;
    cursor: not-allowed;
}

.server-btn:not(.active):hover:not(.unavailable) {
    background: var(--surface-light);
    color: var(--text);
}

/* Server Tags on Episodes */
.server-tag {
    display: inline-block;
    padding: 1px 6px;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 1px;
    margin-left: 4px;
    vertical-align: middle;
}

.gdrive-tag {
    background: #0f5132;
    color: #75b798;
}

.agg-tag {
    background: var(--surface-light);
    color: var(--text-muted);
}

/* Nav Right (settings gear) */
.nav-right {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

@media (min-width: 768px) {
    .nav-links {
        display: flex;
    }
    .mobile-nav {
        display: none;
    }
    body {
        padding-bottom: 0;
    }
    .db-header {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
    .episode-list {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-md);
    }
}

/* ============================
   PLAYER CONTAINER
   ============================ */
.player-container {
    position: relative;
    width: 100%;
    height: 100%;
}

/* Skip Intro / Outro Buttons */
.skip-btn {
    position: absolute;
    bottom: 80px;
    right: 20px;
    z-index: 50;
    background: rgba(229, 9, 20, 0.9);
    color: #fff;
    border: 2px solid #fff;
    padding: 10px 24px;
    font-family: var(--font-display);
    font-size: 1rem;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all 0.2s;
    animation: skipFadeIn 0.3s ease-out;
}

.skip-btn:hover {
    background: #fff;
    color: #000;
    border-color: var(--red);
}

.skip-outro {
    bottom: 80px;
}

.skip-btn.hidden {
    display: none;
}

@keyframes skipFadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Auto-Next Overlay */
.auto-next-overlay {
    position: absolute;
    inset: 0;
    z-index: 60;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 16px;
    animation: fadeIn 0.3s ease;
}

.auto-next-overlay.hidden {
    display: none;
}

.auto-next-overlay p {
    font-family: var(--font-display);
    font-size: 1.8rem;
    letter-spacing: 2px;
    color: var(--text);
}

.auto-next-overlay p span {
    color: var(--red);
    font-size: 2.5rem;
}

.auto-next-overlay .skip-btn {
    position: static;
    font-size: 1.2rem;
    padding: 14px 32px;
}

.cancel-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 8px 20px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.cancel-btn:hover {
    border-color: var(--text);
    color: var(--text);
}

/* Next Episode Button (iframe mode) */
.next-ep-btn {
    position: absolute;
    bottom: 12px;
    right: 12px;
    z-index: 50;
    background: var(--red);
    color: #fff;
    border: none;
    padding: 10px 20px;
    font-family: var(--font-display);
    font-size: 0.9rem;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all 0.2s;
    opacity: 0.7;
}

.next-ep-btn:hover {
    opacity: 1;
    background: #fff;
    color: #000;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ============================
   SETTINGS PANEL
   ============================ */
.settings-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 320px;
    max-width: 90vw;
    height: 100vh;
    background: var(--surface);
    border-left: 2px solid var(--border);
    z-index: 200;
    animation: slideIn 0.2s ease-out;
    overflow-y: auto;
}

.settings-panel.hidden {
    display: none;
}

@keyframes slideIn {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

.settings-inner {
    padding: var(--space-lg);
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-md);
    border-bottom: 2px solid var(--border);
}

.settings-header h3 {
    font-family: var(--font-display);
    font-size: 1.3rem;
    color: var(--red);
    letter-spacing: 2px;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}

.setting-row label {
    font-size: 0.85rem;
    color: var(--text);
    font-weight: 700;
}

/* Toggle Switch */
.toggle {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--border);
    transition: 0.3s;
}

.toggle-slider::before {
    content: "";
    position: absolute;
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background: var(--text);
    transition: 0.3s;
}

.toggle input:checked + .toggle-slider {
    background: var(--red);
}

.toggle input:checked + .toggle-slider::before {
    transform: translateX(22px);
}

/* Language Select */
.setting-select {
    background: var(--surface-light);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 6px 10px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    cursor: pointer;
    outline: none;
    min-width: 100px;
}

.setting-select:focus {
    border-color: var(--red);
}

.settings-note {
    margin-top: var(--space-lg);
    font-size: 0.7rem;
    color: var(--text-muted);
    line-height: 1.6;
}

/* ============================
   EPISODE WATCH PROGRESS BAR
   ============================ */
.ep-progress {
    width: 100%;
    height: 3px;
    background: var(--border);
    margin-top: 6px;
}

.ep-progress-fill {
    height: 100%;
    background: var(--red);
    transition: width 0.3s;
}

/* ============================
   THEATER / FULL-WINDOW MODE
   ============================ */
body.theater-active {
    overflow: hidden;
}

body.theater-active .navbar,
body.theater-active .hero,
body.theater-active .database,
body.theater-active .mobile-nav {
    display: none !important;
}

body.theater-active #player-section {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    padding: var(--space-sm);
    margin: 0;
    background: #000;
    border-bottom: none;
    display: flex;
    flex-direction: column;
}

body.theater-active .player-header {
    margin-bottom: var(--space-sm);
    flex-shrink: 0;
}

body.theater-active .video-wrapper {
    flex-grow: 1;
    height: calc(100vh - 85px) !important;
    aspect-ratio: auto;
    border: none;
}

/* ============================
   MOBILE IFRAME SCALING FIX 
   Bypasses Server 2's mobile CSS that hides quality/audio buttons
   ============================ */
@media screen and (max-width: 610px) {
    .video-wrapper iframe#hx-iframe {
        width: 610px !important;
        height: 343.125px !important; /* 610 * 9/16 */
        transform-origin: top left;
        transform: scale(calc(100vw / 610)) !important;
    }
    
    /* Ensure the wrapper collapses to the scaled height */
    .video-wrapper {
        height: calc(100vw * 9 / 16) !important;
    }

    body.theater-active .video-wrapper iframe#hx-iframe {
        /* In theater mode portrait, we also scale */
        width: 610px !important;
        /* Calculate height to fill the available screen area */
        height: calc(610px * (100vh - 85px) / 100vw) !important;
        transform: scale(calc(100vw / 610)) !important;
    }
}
