/* ========================================
   Player + Shaka UI Overrides
   ======================================== */

/* Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Theme Variables */
:root {
    --transition: 0.2s ease;
}

[data-theme="dark"] {
    --bg: #1c1c1e;
    --surface: #2c2c2e;
    --surface-hover: #3a3a3c;
    --border: rgba(255, 255, 255, 0.12);
    --text: #ffffff;
    --text-dim: rgba(255, 255, 255, 0.6);
    --accent: #636366;
}

[data-theme="light"] {
    --bg: #f5f3ef;
    --surface: #e8e5df;
    --surface-hover: #ddd9d2;
    --border: rgba(0, 0, 0, 0.15);
    --text: #1c1c1e;
    --text-dim: rgba(0, 0, 0, 0.6);
    --accent: #48484a;
}

/* Base */
body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    transition: background var(--transition), color var(--transition);
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 24px;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.back-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-dim);
    text-decoration: none;
    transition: all var(--transition);
}

.back-btn:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.back-btn svg {
    width: 18px;
    height: 18px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 18px;
    font-weight: 600;
}

.logo svg {
    width: 20px;
    height: 20px;
    color: var(--accent);
}

.logo span {
    color: var(--accent);
}

/* Video Player */
.player-wrapper {
    background: #000;
    border-radius: 16px;
    overflow: hidden;
    aspect-ratio: 16/9;
    margin-bottom: 20px;
    position: relative;
}

/* Fullscreen fixes - Target all possible containers */
.player-wrapper:fullscreen,
.player-wrapper:-webkit-full-screen,
#player:fullscreen,
#player:-webkit-full-screen,
[data-shaka-player-container]:fullscreen,
[data-shaka-player-container]:-webkit-full-screen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    border-radius: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    background: #000 !important;
    z-index: 2147483647 !important;
}

/* Ensure video fills fullscreen */
:fullscreen video,
:-webkit-full-screen video,
#video:fullscreen,
#video:-webkit-full-screen {
    width: 100% !important;
    height: 100% !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    object-fit: contain !important;
}

/* Shaka video container in fullscreen */
.shaka-video-container:fullscreen,
.shaka-video-container:-webkit-full-screen {
    width: 100% !important;
    height: 100% !important;
}

/* Fix for Shaka controls in fullscreen */
:fullscreen .shaka-bottom-controls,
:-webkit-full-screen .shaka-bottom-controls {
    position: absolute !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
}

#player {
    width: 100%;
    height: 100%;
}

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

/* ── Hide Shaka's native overflow menu (replaced by custom panel) ── */
.shaka-overflow-menu,
.shaka-settings-menu {
    display: none !important;
}

.shaka-overflow-menu-button {
    display: none !important;
}

/* ── Custom Settings Gear Button ── */
.custom-settings-btn {
    background: none !important;
    border: none !important;
    color: #fff;
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.85;
    transition: opacity 0.2s;
}

.custom-settings-btn:hover {
    opacity: 1;
}

.custom-settings-btn .material-icons-round {
    font-size: 22px;
}

/* ── Settings Panel Backdrop ── */
.settings-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 9998;
}

.settings-backdrop.open {
    display: block;
}

/* ── Settings Panel (Desktop: floating card, positioned by JS) ── */
.settings-panel {
    display: none;
    position: fixed;
    z-index: 9999;
    width: 340px;
    background: rgba(18, 18, 20, 0.97);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6);
    overflow: hidden;
    font-family: 'Inter', sans-serif;
}

.settings-panel.open {
    display: block;
}

.settings-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.settings-panel-title {
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    letter-spacing: 0.01em;
}

.settings-panel-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    transition: all 0.2s;
    line-height: 1;
}

.settings-panel-close:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

.settings-panel-body {
    padding: 12px 20px 20px;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    gap: 12px;
}

.settings-row+.settings-row {
    border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.speed-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
}

.settings-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.85);
    white-space: nowrap;
}

.settings-icon {
    font-size: 18px !important;
    color: rgba(255, 255, 255, 0.5);
}

/* ── Custom Select (replaces native <select>) ── */
.custom-select {
    position: relative;
    min-width: 120px;
    user-select: none;
    -webkit-user-select: none;
}

.custom-select-trigger {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: #fff;
    font-size: 13px;
    padding: 8px 28px 8px 12px;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: border-color 0.2s;
    /* Arrow */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='white' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

.custom-select.open .custom-select-trigger {
    border-color: rgba(255, 255, 255, 0.25);
}

.custom-select-options {
    display: none;
    position: fixed;
    /* Changed from absolute to fixed to break out of overflow */
    min-width: 100%;
    width: auto;
    max-width: 300px;
    max-height: 200px;
    overflow-y: auto;
    background: rgba(30, 30, 32, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    z-index: 10002;
    /* Higher than settings panel */
    padding: 4px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

/* Scrollbar styling */
.custom-select-options::-webkit-scrollbar {
    width: 4px;
}

.custom-select-options::-webkit-scrollbar-track {
    background: transparent;
}

.custom-select-options::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

.custom-select.open .custom-select-options {
    display: block;
}

.custom-select-option {
    padding: 8px 12px;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.75);
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.15s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.custom-select-option:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.custom-select-option.selected {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-weight: 500;
}

/* ── Speed Preset Buttons ── */
.speed-presets {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    width: 100%;
}

.speed-btn {
    flex: 1;
    min-width: 44px;
    padding: 8px 4px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.04);
    color: rgba(255, 255, 255, 0.7);
    font-size: 12px;
    font-weight: 500;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.speed-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.speed-btn.active {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.5);
    color: #fff;
    font-weight: 600;
}

.shaka-controls-button-panel {
    gap: 4px;
}

/* Shaka Control Bar - Simple styling */
.shaka-bottom-controls {
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.6)) !important;
}

/* ── Double-Tap Seek Zones ── */
.seek-zone {
    position: absolute;
    top: 0;
    bottom: 60px;
    /* above controls */
    width: 50%;
    z-index: 10;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}

.seek-zone-left {
    left: 0;
    border-radius: 0 50% 50% 0;
}

.seek-zone-right {
    right: 0;
    border-radius: 50% 0 0 50%;
}

.seek-zone.active {
    opacity: 1;
    pointer-events: auto;
}

.seek-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    position: relative;
}

.seek-text {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
    z-index: 2;
    font-family: 'Inter', sans-serif;
    letter-spacing: 0.02em;
}

.seek-ripple {
    position: absolute;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    z-index: 1;
}

.seek-ripple.animate {
    animation: seekRipple 0.5s ease-out forwards;
}

@keyframes seekRipple {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0.6;
    }

    100% {
        transform: translate(-50%, -50%) scale(2);
        opacity: 0;
    }
}

/* HIDE SEEK INDICATOR ON ALL DEVICES (Desktop + Mobile) */
/* Note: Shaka has a typo in their class - 'foward' instead of 'forward' */
/* Targeting all variants: children + parent wrappers */
.shaka-forward-rewind-container-icon,
.shaka-fast-forward-container,
.shaka-fast-foward-container,
/* Shaka's typo variant */
.shaka-rewind-container,
.shaka-hidden-fast-forward-container,
/* Parent wrapper */
.shaka-hidden-rewind-container {
    /* Parent wrapper */
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* HIDE CENTRAL PLAY BUTTON (appears as white 4x4px dot) */
.shaka-play-button-container {
    display: none !important;
}

/* ── Loading Overlay ────────────────────────────── */
.player-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.6) 0%, rgba(0, 0, 0, 0.85) 100%);
    z-index: 10;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.player-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* Glassmorphism card */
.loader-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 36px 48px;
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(24px) saturate(120%);
    -webkit-backdrop-filter: blur(24px) saturate(120%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 24px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
}

/* ── Orbital Spinner ────────────────────────────── */
.orbital-spinner {
    position: relative;
    width: 64px;
    height: 64px;
}

.orbit {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid transparent;
}

.orbit-1 {
    border-top-color: rgba(255, 255, 255, 0.7);
    animation: spin 1.2s linear infinite;
    filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.3));
}

.orbit-2 {
    inset: 6px;
    border-right-color: rgba(255, 255, 255, 0.4);
    animation: spin 1.8s linear infinite reverse;
    filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.15));
}

.orbit-3 {
    inset: 12px;
    border-bottom-color: rgba(255, 255, 255, 0.2);
    animation: spin 2.4s linear infinite;
}

.orbit-core {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 8px;
    height: 8px;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 50%;
    animation: pulse-core 1.6s ease-in-out infinite;
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.5);
}

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

@keyframes pulse-core {

    0%,
    100% {
        opacity: 0.4;
        transform: translate(-50%, -50%) scale(0.8);
    }

    50% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.2);
    }
}

/* ── Loader Text ────────────────────────────────── */
.loader-text {
    font-size: 15px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.8);
    letter-spacing: 0.02em;
    text-align: center;
    transition: opacity 0.3s ease;
}

.loader-detail {
    font-size: 12px;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.4);
    text-align: center;
    min-height: 16px;
    transition: opacity 0.3s ease;
}

/* Shaka Player Subtitle Positioning */
.shaka-text-container {
    --subtitle-position-v: 5%;
    --subtitle-position-h: 0%;
    bottom: var(--subtitle-position-v) !important;
    left: 50% !important;
    transform: translateX(calc(-50% + var(--subtitle-position-h))) !important;
    transition: bottom 0.2s ease, transform 0.2s ease;
}

/* Key Status Panel FAB */
#keyStatusFab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    min-width: 56px;
    height: 56px;
    padding: 0 16px;
    border-radius: 28px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    cursor: grab;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: all var(--transition);
    z-index: 1000;
    user-select: none;
    -webkit-user-select: none;
    white-space: nowrap;
}

#keyStatusFab:active {
    cursor: grabbing;
}

#keyStatusFab.visible {
    display: flex;
}

#keyStatusFab:hover {
    background: var(--surface-hover);
    transform: scale(1.05);
}

#keyStatusFab.all-matched {
    background: rgba(52, 199, 89, 0.2);
    border-color: rgba(52, 199, 89, 0.5);
}

#keyStatusFab.has-warning {
    background: rgba(255, 159, 10, 0.2);
    border-color: rgba(255, 159, 10, 0.5);
}

/* Key Status Panel */
#keyStatusPanel {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 400px;
    max-width: calc(100vw - 48px);
    max-height: 60vh;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    display: none;
    flex-direction: column;
    gap: 12px;
    z-index: 1001;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

#keyStatusPanel.visible {
    display: flex;
}

#keyStatusPanel .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: grab;
    user-select: none;
}

#keyStatusPanel .panel-header:active {
    cursor: grabbing;
}

#keyStatusPanel .panel-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

#closeKeyStatus {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 20px;
    padding: 4px;
}

#keyMatchSummary {
    font-size: 13px;
}

.key-match-summary.all-matched {
    color: #34c759;
}

.key-match-summary.partial {
    color: #ff9f0a;
}

.key-match-summary.none {
    color: #ff453a;
}

#keyMatchList {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 300px;
    overflow-y: auto;
}

.key-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg);
    border-radius: 6px;
    font-family: 'Menlo', 'Monaco', monospace;
    font-size: 11px;
}

.key-item.matched {
    border-left: 3px solid #34c759;
}

.key-item.missing {
    border-left: 3px solid #ff453a;
}

.key-item-text {
    word-break: break-all;
    color: var(--text-dim);
}

.key-item-icon {
    margin-left: 8px;
    flex-shrink: 0;
}

/* ── Mobile Responsive ──────────────────────────── */
@media (max-width: 600px) {

    /* Smaller loading overlay */
    .loader-card {
        padding: 20px 28px;
        gap: 14px;
        border-radius: 16px;
    }

    .orbital-spinner {
        width: 40px;
        height: 40px;
    }

    .orbit-2 {
        inset: 4px;
    }

    .orbit-3 {
        inset: 8px;
    }

    .orbit-core {
        width: 6px;
        height: 6px;
    }

    .loader-text {
        font-size: 13px;
    }

    .loader-detail {
        font-size: 11px;
    }

    /* Settings panel — bottom sheet on portrait mobile */
    .settings-panel.mobile-portrait {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        width: 100% !important;
        max-height: 60vh;
        border-radius: 20px 20px 0 0;
        border: none;
        border-top: 1px solid rgba(255, 255, 255, 0.08);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }



    .settings-panel-body {
        padding: 12px 16px 28px;
    }

    /* Smaller container padding */
    .container {
        padding: 16px;
    }

    /* Player wrapper */
    .player-wrapper {
        border-radius: 12px;
        margin-bottom: 16px;
    }
}

/* Settings panel — side-sheet on landscape mobile (outside media query, class-based) */
.settings-panel.mobile-landscape {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    left: auto !important;
    width: 300px !important;
    max-height: 100vh;
    border-radius: 20px 0 0 20px;
    border: none;
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}