/* VERSION: 3.0.0 */
/* PLAYER STAGE, VIDEO, AND CONTROLS */
/* Mobile/Touch optimized */

#player-stage {
    position: relative;
    flex: 1;
    background-color: var(--bg-main, #0a0c10);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    min-width: 0;
    min-height: 0;
    /* Prevent iOS bounce/overscroll */
    overscroll-behavior: contain;
    /* Prevent double-tap zoom on iOS */
    touch-action: manipulation;
}

#main-video {
    width: 100%;
    height: calc(100% - var(--controls-height, 86px));
    margin-bottom: var(--controls-height, 86px);
    object-fit: contain;
    transform: translateZ(0); 
    will-change: transform;
    transition: height 0.25s ease, margin-bottom 0.25s ease;
    /* iOS video fixes */
    -webkit-playsinline: true;
    /* Prevent context menu on long press */
    -webkit-touch-callout: none;
}

#player-stage:has(.controls-wrapper.fade-out) #main-video,
#player-stage.controls-hidden #main-video,
:fullscreen #main-video,
:-webkit-full-screen #main-video {
    height: 100%;
    margin-bottom: 0;
}

#web-embed-frame {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: calc(100% - var(--controls-height, 86px));
    border: none;
    background: #000;
    z-index: 4;
    transition: height 0.25s ease;
}

#player-stage:has(.controls-wrapper.fade-out) #web-embed-frame,
#player-stage.controls-hidden #web-embed-frame,
:fullscreen #web-embed-frame,
:-webkit-full-screen #web-embed-frame {
    height: 100%;
}

/* Subtitles */
#subtitle-overlay {
    position: absolute; 
    bottom: calc(var(--controls-height, 86px) + 12px); 
    width: 100%; 
    text-align: center; 
    pointer-events: none; 
    padding: 0 20px; 
    z-index: 5;
    transition: bottom 0.25s ease;
    
    /* Default Accessibility Variables */
    --sub-font-size: 1.5rem;
    --sub-color: #ffffff;
    --sub-bg-opacity: 0.6;
}

#player-stage:has(.controls-wrapper.fade-out) #subtitle-overlay,
#player-stage.controls-hidden #subtitle-overlay,
:fullscreen #subtitle-overlay,
:-webkit-full-screen #subtitle-overlay {
    bottom: 24px;
}

.subtitle-line {
    background: rgba(0, 0, 0, var(--sub-bg-opacity));
    color: var(--sub-color);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: var(--sub-font-size);
    line-height: 1.4;
    text-shadow: 0 1px 2px #000;
    /* Security: Handle newlines safely without innerHTML <br> */
    white-space: pre-wrap; 
}

/* Center Status Icon (Removed as requested - visualization only) */
#center-icon {
    display: none !important;
}

/* Seek Animations */
.seek-anim {
    position: absolute; top: 50%; width: 100px; height: 100px; background: rgba(0,0,0,0.5); border-radius: 50%; display: flex; flex-direction: column; justify-content: center; align-items: center; color: #fff; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 15;
}
.seek-anim.left { left: 10%; }
.seek-anim.right { right: 10%; }
.seek-anim.animate { opacity: 1; transform: scale(1.2); }
.seek-anim svg { width: 40px; height: 40px; fill: currentColor; }

/* Controls Container - Full Width Glassmorphic Dock */
.controls-wrapper {
    position: absolute; 
    bottom: 0; 
    left: 0;
    width: 100%;
    height: var(--controls-height, 86px);
    box-sizing: border-box;
    padding: 8px 16px 10px 16px; 
    background: var(--bg-surface-glass, rgba(14, 18, 28, 0.88));
    backdrop-filter: blur(28px) saturate(190%);
    -webkit-backdrop-filter: blur(28px) saturate(190%);
    border-top: 1px solid var(--glass-border, rgba(255, 255, 255, 0.12));
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.6), var(--glass-rim-top, inset 0 1px 0 rgba(255, 255, 255, 0.18));
    z-index: 10; 
    opacity: 1; 
    transition: opacity 0.3s ease, visibility 0.3s ease;
    display: flex; 
    flex-direction: column; 
    gap: 8px; 
    visibility: visible;
}

/* Progress Bar Container - Interaction Area */
.progress-area {
    position: relative; 
    width: 100%; 
    height: 18px;
    cursor: pointer; 
    touch-action: none;
    display: flex;
    align-items: center;
}

/* Visual Track Background */
.progress-bg {
    position: absolute;
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.14);
    border-radius: 3px;
    transition: height 0.15s ease;
}

/* Visual Fill Bar */
.progress-fill { 
    position: absolute; 
    height: 4px; 
    background: linear-gradient(90deg, var(--accent, #6366f1), #ffffff);
    width: 0%; 
    border-radius: 3px; 
    transition: height 0.15s ease;
    z-index: 1;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.4);
}

/* Hover States: Thicken the bar */
.progress-area:hover .progress-bg,
.progress-area:hover .progress-fill {
    height: 6px;
}

/* Thumb Handle */
.progress-thumb { 
    position: absolute; 
    width: 14px; 
    height: 14px; 
    background: #ffffff; 
    border-radius: 50%; 
    top: 50%; 
    transform: translate(-50%, -50%) scale(0); 
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.9), 0 2px 4px rgba(0, 0, 0, 0.6);
    transition: transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275); 
    z-index: 2;
}
.progress-area:hover .progress-thumb { 
    transform: translate(-50%, -50%) scale(1); 
}

.buttons-row { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
}
.left-group, .right-group { 
    display: flex; 
    align-items: center; 
    gap: 8px; 
}

/* Unified Greyscale Icon Colors */
.controls-wrapper .icon-btn {
    color: var(--icon-base, rgba(240, 246, 252, 0.72));
}

.controls-wrapper .icon-btn:hover {
    color: var(--icon-hover, #ffffff);
    filter: var(--icon-glow, drop-shadow(0 0 6px rgba(255, 255, 255, 0.45)));
}

/* Tactile Platinum Play Button */
#btn-play {
    background: rgba(255, 255, 255, 0.10);
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 50%;
    width: 42px;
    height: 42px;
    min-width: 42px;
    min-height: 42px;
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#btn-play:hover {
    background: rgba(255, 255, 255, 0.20);
    border-color: rgba(255, 255, 255, 0.45);
    transform: scale(1.06);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.8), 0 0 12px rgba(255, 255, 255, 0.3);
}

#btn-play:active {
    transform: scale(0.96);
}

#btn-play svg {
    fill: currentColor;
    stroke: none;
}

/* Volume Slider */
.volume-container { 
    display: flex; 
    align-items: center; 
    gap: 6px; 
    width: 110px; 
    margin-right: 6px; 
    flex-shrink: 0; 
}
.volume-container input[type=range] { 
    -webkit-appearance: none; 
    width: 100%; 
    background: transparent; 
    cursor: pointer; 
    height: 20px; 
    display: flex; 
    align-items: center;
    touch-action: manipulation;
}
.volume-container input[type=range]::-webkit-slider-runnable-track { 
    width: 100%; 
    height: 4px; 
    background: rgba(255, 255, 255, 0.16); 
    border-radius: 2px; 
    border: none; 
}
.volume-container input[type=range]::-webkit-slider-thumb { 
    -webkit-appearance: none; 
    height: 14px; 
    width: 14px; 
    border-radius: 50%; 
    background: #f8fafc; 
    margin-top: -5px; 
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.8); 
    border: 1px solid rgba(255, 255, 255, 0.4); 
    transition: transform 0.12s ease, background 0.12s ease; 
}
.volume-container input[type=range]:hover::-webkit-slider-thumb { 
    transform: scale(1.2); 
    background: #ffffff; 
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.7);
}
.volume-container input[type=range]::-moz-range-track { 
    width: 100%; 
    height: 4px; 
    background: rgba(255, 255, 255, 0.16); 
    border-radius: 2px; 
    border: none; 
}
.volume-container input[type=range]::-moz-range-thumb { 
    height: 14px; 
    width: 14px; 
    border-radius: 50%; 
    background: #f8fafc; 
    border: 1px solid rgba(255, 255, 255, 0.4); 
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.8); 
}

/* Time Display - High Contrast Silver */
#time-display { 
    font-size: 0.82rem;
    margin-left: 8px;
    color: var(--text-muted, #94a3b8);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.5px;
}

/* Mobile */
@media (max-width: 768px) {
    #player-stage { 
        width: 100%; 
        flex: none;
        /* Prevent pull-to-refresh on mobile */
        overscroll-behavior-y: contain;
    }
    #btn-toggle-playlist { display: none; }
    .controls-wrapper { 
        padding: 0 10px 15px 10px; 
        bottom: 0; 
        background: linear-gradient(to top, rgba(0,0,0,0.98) 0%, rgba(0,0,0,0.9) 70%, rgba(0,0,0,0) 100%);
        /* Safe area for notched phones */
        padding-bottom: max(15px, env(safe-area-inset-bottom));
    }
    .buttons-row { flex-direction: column; gap: 12px; align-items: stretch; }
    .left-group, .right-group { width: 100%; justify-content: space-between; }
    .volume-container { width: 80px; }
    #subtitle-overlay { bottom: 120px; padding: 0 10px; }
    .subtitle-line { font-size: 1.1rem; }
    
    /* Larger touch targets for mobile buttons */
    .icon-btn {
        min-width: 44px;
        min-height: 44px;
    }
    
    /* Progress bar styling on mobile */
    .progress-area {
        height: 30px; /* Larger hit area */
        margin: -10px 0;
    }
    
    /* Ensure visible bars remain thin on mobile unless hovered/dragged */
    .progress-bg, .progress-fill {
        height: 3px; 
    }
}

/* FIX: Placed at the very end to ensure it overrides all other styles */
/* Uses !important to force hidden state and visibility hidden to stop mouse interactions */
.controls-wrapper.fade-out { 
    opacity: 0 !important; 
    visibility: hidden !important;
    pointer-events: none !important;
}

/* FIX: Aggressive cursor hiding for Fullscreen */
#player-stage.no-cursor, 
#player-stage.no-cursor * { 
    cursor: none !important; 
}

/* ==========================================================================
   DYNAMIC MUSIC VISUALIZER & AUDIO STAGE
   ========================================================================== */
.visualizer-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
    opacity: 0;
    transition: opacity 0.35s ease;
}

.visualizer-canvas.visible {
    opacity: 1;
}

/* Singularity Helix 3D WAAPI Stage */
#visualizer-waapi {
    perspective: 1200px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.waapi-container {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    pointer-events: none;
}

.waapi-prism {
    width: 22px;
    height: 44px;
    position: absolute;
    left: 50%;
    top: 50%;
    margin-left: -11px;
    margin-top: -22px;
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
    mix-blend-mode: screen;
    will-change: transform, opacity;
    backface-visibility: visible;
}

.waapi-core {
    position: absolute;
    width: 48px;
    height: 48px;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 3;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 0 50px var(--accent, #6366f1);
    pointer-events: none;
    transition: transform 0.1s ease-out, box-shadow 0.1s ease-out;
}

/* Audio Stage Info (Removed as requested - visualization only) */
.audio-stage-info {
    display: none !important;
}

#btn-visualizer.active svg {
    stroke: var(--accent, #6366f1);
    filter: drop-shadow(0 0 6px var(--accent, #6366f1));
}

/* ==========================================================================
   NETWORK STREAM MODAL ENHANCEMENTS
   ========================================================================== */
.stream-badge-pill {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text-muted, #a1a1aa);
}

.stream-badge-pill[data-type="youtube"] {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.3);
}

.stream-badge-pill[data-type="vimeo"] {
    background: rgba(14, 165, 233, 0.15);
    color: #38bdf8;
    border-color: rgba(14, 165, 233, 0.3);
}

.stream-badge-pill[data-type="soundcloud"] {
    background: rgba(249, 115, 22, 0.15);
    color: #fb923c;
    border-color: rgba(249, 115, 22, 0.3);
}

.stream-badge-pill[data-type="hls"] {
    background: rgba(34, 197, 94, 0.15);
    color: #4ade80;
    border-color: rgba(34, 197, 94, 0.3);
}

.stream-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted, #a1a1aa);
    margin-bottom: 6px;
}

.stream-presets-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    margin-bottom: 12px;
}

.stream-presets-title {
    font-size: 0.72rem;
    color: var(--text-muted, #a1a1aa);
    font-weight: 600;
    margin-right: 4px;
}

.stream-preset-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-main, #f4f4f5);
    font-size: 0.72rem;
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.stream-preset-btn:hover {
    background: var(--accent, #6366f1);
    border-color: var(--accent, #6366f1);
    color: #fff;
}

.stream-resolver-accordion {
    margin-top: 8px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    padding: 6px 10px;
    font-size: 0.78rem;
}

.stream-resolver-accordion summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text-muted, #a1a1aa);
    user-select: none;
}

.stream-resolver-accordion summary:hover {
    color: var(--text-main, #f4f4f5);
}

.stream-resolver-body {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stream-resolver-body input {
    width: 100%;
    padding: 6px 8px;
    background: var(--bg-main, #18181b);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 4px;
    color: var(--text-main, #f4f4f5);
    font-size: 0.75rem;
}

.resolver-hint {
    font-size: 0.7rem;
    color: var(--text-muted, #71717a);
}

.btn-secondary {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text-main, #f4f4f5);
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.08);
}

.btn-primary {
    background: var(--accent, #6366f1);
    border: 1px solid var(--accent, #6366f1);
    color: #fff;
    padding: 6px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
}

.btn-primary:hover {
    background: var(--accent-hover, #818cf8);
}

.highlight-pulse {
    animation: ringPulse 1.5s infinite;
}

@keyframes ringPulse {
    0% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.6); }
    70% { box-shadow: 0 0 0 8px rgba(99, 102, 241, 0); }
    100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0); }
}

/* ==========================================================================
   A/B Loop Engine Styling (Item 1)
   ========================================================================== */
.ab-loop-controls {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    padding: 2px 4px;
}

.ab-btn {
    font-size: 0.72rem;
    font-weight: 800;
    min-width: 22px;
    height: 22px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    color: var(--text-muted, #94a3b8);
    transition: all 0.15s ease;
}

.ab-btn.set {
    background: color-mix(in srgb, var(--accent, #7aa2f7) 30%, transparent);
    color: var(--accent, #7aa2f7);
    border: 1px solid var(--accent, #7aa2f7);
}

.ab-loop-range {
    position: absolute;
    top: 0;
    bottom: 0;
    background: color-mix(in srgb, var(--accent, #7aa2f7) 40%, transparent);
    border-left: 2px solid var(--accent, #7aa2f7);
    border-right: 2px solid var(--accent, #7aa2f7);
    border-radius: 2px;
    pointer-events: none;
    z-index: 3;
}

.ab-loop-badge {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--accent, #7aa2f7);
    padding: 0 4px;
    white-space: nowrap;
}

/* ==========================================================================
   Scrub Bar Thumbnail Preview & Chapter Markers (Items 3, 4)
   ========================================================================== */
.chapter-markers-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 4;
}

.chapter-tick {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: rgba(255, 255, 255, 0.75);
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.8);
    pointer-events: auto;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease;
}

.chapter-tick:hover {
    background: var(--accent, #7aa2f7);
    transform: scaleX(2.5);
}

.scrub-preview-tooltip {
    position: absolute;
    bottom: calc(100% + 10px);
    transform: translateX(-50%);
    background: var(--bg-card, #1e222d);
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.2));
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.7);
    padding: 4px;
    pointer-events: none;
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.scrub-preview-tooltip canvas {
    display: block;
    width: 160px;
    height: 90px;
    border-radius: 4px;
    background: #000;
}

.scrub-preview-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-main, #fff);
}

.scrub-preview-chapter {
    color: var(--accent, #7aa2f7);
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ==========================================================================
   Accessibility: Dyslexia Mode & ARIA Announcements (Items 14, 15)
   ========================================================================== */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.dyslexia-mode,
.dyslexia-mode #subtitle-overlay,
#subtitle-overlay.dyslexia-font {
    font-family: 'OpenDyslexic', 'Atkinson Hyperlegible', sans-serif !important;
    letter-spacing: 0.12em !important;
    word-spacing: 0.18em !important;
    line-height: 1.6 !important;
    font-weight: 700 !important;
}

#subtitle-overlay {
    cursor: move;
    user-select: none;
}

/* ==========================================================================
   Eco Mode (Item 24)
   ========================================================================== */
html.eco-mode *,
html.eco-mode *::before,
html.eco-mode *::after {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    transition-duration: 0.05s !important;
}

#btn-eco.active {
    color: #22c55e !important;
    background: rgba(34, 197, 94, 0.15) !important;
    border-color: rgba(34, 197, 94, 0.5) !important;
}