/* Movie Magic - Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Prevent page shifts and layout recalculation */
*,
*::before,
*::after {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* Stabilize the entire document */
html,
body {
    position: relative;
    overflow-anchor: none;
}

:root {
    --primary-bg: #0a0a0a;
    --card-bg: #1a1a1a;
    --accent: #007aff;
    --text-primary: #ffffff;
    --text-secondary: #b3b3b3;
    --border: #333;
    --radius: 12px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --glass-bg: rgba(0, 0, 0, 0.3);
    --glass-border: rgba(255, 255, 255, 0.1);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    /* Unified glass effect variables */
    --glass-blur-amount: 20px;
    --glass-opacity: 0.8;
    --glass-hover-opacity: 1;
    --glass-hover-bg: rgba(0, 0, 0, 0.5);
}

/* Unified Glass Effect Classes */
.glass-container {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    backdrop-filter: blur(var(--glass-blur-amount));
    -webkit-backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(var(--glass-blur-amount));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    opacity: var(--glass-opacity);
    transition: var(--transition);
}

.glass-container:hover {
    opacity: var(--glass-hover-opacity);
    background: var(--glass-hover-bg);
}

/* Glass container variants */
.glass-container--panel {
    padding: 20px;
    min-width: 250px;
}

.glass-container--compact {
    padding: 15px;
}

.glass-container--large {
    padding: 25px;
}

html {
    scroll-behavior: smooth;
    overflow-y: scroll;
    width: 100%;
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--primary-bg);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    overflow-y: scroll;
    width: 100vw;
    position: relative;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--primary-bg);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* Loading Animation */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    font-size: 1.2rem;
    color: var(--text-secondary);
}

.loading::after {
    content: '';
    width: 20px;
    height: 20px;
    margin-left: 10px;
    border: 2px solid var(--border);
    border-top: 2px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.fade-in {
    opacity: 1;
    transition: opacity 1s ease-in;
}

.fade-out {
    opacity: 0;
    transition: opacity 1s ease-out;
}

img.lazy-image {
    opacity: 0;
    transition: opacity 0.35s ease;
}

img.lazy-image[src] {
    opacity: 1;
}

/* Loading element specific fade classes */
.loading.fade-in {
    opacity: 1;
    transition: opacity 1s ease-in;
}

.loading.fade-out {
    opacity: 0;
    transition: opacity 1s ease-out;
}

.blur-bg {
    backdrop-filter: blur(20px);
    backdrop-filter: blur(var(--glass-blur-amount));
    -webkit-backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(var(--glass-blur-amount));
}

/* GPU Acceleration */
.gpu-accelerated {
    transform: translateZ(0);
    will-change: transform;
}

/* Content Type Segmented Control Styling */
.content-type-segmented {
    width: 200px;
    margin: 0.5rem 0;
    position: relative !important;
    transform: none !important;
}

.content-type-segmented .qui-segment {
    font-size: 14px;
    padding: 0.4rem 0.8rem;
    position: relative !important;
    transform: none !important;
}

/* Ensure content type control stability in settings panel */
.settings-panel .content-type-segmented {
    position: relative !important;
    transform: none !important;
    width: 100% !important;
    max-width: 200px !important;
}

.settings-panel .content-type-segmented * {
    transform: none !important;
    position: relative !important;
}

.settings-panel .content-type-segmented .qui-segment:active,
.settings-panel .content-type-segmented .qui-segment:focus,
.settings-panel .content-type-segmented .qui-segment:hover {
    transform: none !important;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.content-type-segmented .qui-segment:active {
    transform: none !important;
}

.content-type-segmented .qui-segment:focus {
    outline: none;
    transform: none;
}
/* Layout for segmented control containers */
.content-type-segmented,
.sort-quick-segmented {
    display: flex;
    gap: 0.5rem;
}
.content-type-segmented .qui-segment,
.sort-quick-segmented .qui-segment {
    flex: 1;
}

/* Year Slider QuiInterface Integration */
.year-slider-container .year-slider-integration {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
    max-width: none !important;
    width: 100% !important;
}

.year-slider-container .qui-slider-container {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
    max-width: none !important;
    width: 100% !important;
    position: static !important;
}

.year-slider-container .qui-slider-label {
    color: var(--text-primary) !important;
    margin-bottom: 0.5rem;
    font-size: 14px;
    text-align: center;
    font-weight: 500;
    user-select: none;
}

.year-slider-container .qui-slider-value {
    color: var(--accent) !important;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    margin-top: 0.5rem;
    user-select: none;
}

.year-slider-container .qui-slider {
    width: 100% !important;
    position: static !important;
    margin: 0 !important;
    transform: none !important;
}

/* Prevent any unwanted animations or transforms */
.year-slider-container * {
    transform-origin: center center;
}

.year-slider-container .qui-slider:focus {
    outline: none;
}

.year-slider-container .qui-slider::-webkit-slider-thumb:active {
    transform: none !important;
}

/* Settings Panel Stability - Prevent Movement on Click */
.settings-panel {
    position: fixed !important;
    transform-origin: top right !important;

}

.settings-panel * {
    transform-origin: center center;
    will-change: auto;
}

.settings-panel *:active,
.settings-panel *:focus {
    transform: none !important;
}

.settings-panel .qui-segment:active,
.settings-panel .qui-segment:focus,
.settings-panel .qui-segment:hover {
    transform: none !important;
}

.settings-panel select:active,
.settings-panel select:focus {
    transform: none !important;
}

.settings-panel button:active,
.settings-panel button:focus {
    transform: none !important;
}

.settings-panel input:active,
.settings-panel input:focus {
    transform: none !important;
}

/* Prevent the entire settings panel from moving */
.settings-panel.show {
    position: fixed !important;
    transform: translateY(0) !important;
}

/* QuiInterface elements in settings panel should not move */
.settings-panel .qui-segmented-control {
    position: relative !important;
    transform: none !important;
}

.settings-panel .qui-segmented-control * {
    transform: none !important;
    position: relative !important;
}

/* Prevent page layout shifts */
.movie-grid,
.control-center,
.year-slider-container,
.category-sidebar {
    contain: layout style paint;
    will-change: auto;
}

/* Prevent scrollbar-induced shifts */
.movie-grid {
    scrollbar-gutter: stable;
}

/* Prevent focus/active state changes from affecting layout */
*:focus,
*:active {
    outline: none;
    box-shadow: none;
}

/* Ensure fixed elements don't cause shifts */
.control-center {
    position: fixed;
    width: auto;
    contain: layout;
}

/* Intentionally left without containment: allow backdrop-filter to render on settings panel */

/* Prevent text selection from affecting layout */
.control-center,
.settings-panel,
.year-slider-container {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Allow text selection only in specific areas */
.movie-title,
.movie-overview,
input[type="text"],
textarea {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Force scrollbar to always be visible to prevent layout shifts */
html {
    scrollbar-gutter: stable;
    overflow-y: scroll !important;
}

body {
    scrollbar-gutter: stable;
}

/* Prevent any element from causing page width changes */
img, video, canvas, svg {
    max-width: 100%;
}

/* Prevent layout shifts during content loading */
.movie-grid {
    min-height: 100vh;
    contain: layout style;
    will-change: contents;
}

/* Prevent shifts when elements are added/removed */
.movie-card,
.setting-group,
.qui-segment {
    contain: layout style paint;
}

/* Responsive Breakpoints */
@media (max-width: 1200px) {
    :root {
        --content-padding: 1rem;
    }
}

@media (max-width: 768px) {
    :root {
        --content-padding: 0.5rem;
    }
    
    .content-type-segmented {
        width: 160px;
    }
}