/* Main stylesheet.
   One file on purpose: it used to be eleven @imports, which the browser can only
   discover after downloading this one — a second round of render-blocking
   requests before anything could paint. The sections below are the old files. */

/* ===== 1. Variables & Base ===== */

/* --- variables.css --- */
:root {
    --bg-color: #0f1115; /* Plus sombre pour le contraste */
    --card-bg: rgba(31, 36, 43, 0.8); /* Semi-transparent */
    --text-color: #9ab;
    --accent-color: #8b5cf6; /* Violet Moderne */
    --accent-hover: #7c3aed;
    --white: #ffffff;
    --border-color: #2c3440;
}

/* Self-hosted and preloaded from index.html. Frick sets the h1, the largest
   thing on screen: without font-display it stayed invisible for up to 3 s.
   Inter used to come from fonts.googleapis.com, a render-blocking stylesheet
   on a third-party origin; it is the variable font, so the 300 and 500
   weights used below now exist instead of falling back to 400.
   Files under /fonts/ are cached as immutable: rename one if it changes. */
@font-face {
    font-family: 'Frick';
    src: url('fonts/frick-0.3.woff2') format('woff2');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 300 700;
    font-display: swap;
    src: url('fonts/inter-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 300 700;
    font-display: swap;
    src: url('fonts/inter-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* --- base.css --- */
* {
    box-sizing: border-box;
}

html, body {
    /* overscroll-behavior-y: none; Removed to allow pull-to-refresh on mobile */
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    min-height: 100vh;
    overflow-x: hidden;
}

header {
    text-align: center;
    margin-bottom: 3rem;
}

/* The big hook line of the hero. The page's h1 is the subtitle under it. */
.hero-title {
    font-family: 'Frick', sans-serif;
    font-weight: bold;
    color: var(--white);
    font-size: 5vw; /* Taille responsive pour remplir la largeur */
    margin: 0;
    letter-spacing: -1px;
    text-shadow: 0 4px 20px rgba(0,0,0,0.5);
    
    /* Largeur de 75% de la page (viewport) */
    width: 75vw;
    
    /* Centrage absolu par rapport au conteneur parent */
    position: relative;
    left: 50%;
    transform: translateX(-50%);
    
    white-space: nowrap; /* Empêche le retour à la ligne */
    text-align: center;
}

.subtitle {
    font-size: 0.9rem;
    font-weight: normal;
    opacity: 0.8;
    margin: 1em 0;
}

/* The h1 and the line after it read as one paragraph, on two lines. */
.subtitle:has(+ .subtitle-follow) {
    margin-bottom: 0;
}

.subtitle-follow {
    margin-top: 0;
}

@media (max-width: 768px) {
    .hero-title {
        font-size: 2rem;
        white-space: normal; /* Autorise le retour à la ligne */
        width: 100%;
        left: 0;
        transform: none;
        line-height: 1.2;
    }
}

/* ===== 2. Layout ===== */

/* --- layout.css --- */
.app-container {
    width: 100%;
    max-width: 900px;
    padding: 2rem;
    position: relative;
    z-index: 1;
}

/* Top Navigation */
.top-nav {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #000;
    border-radius: 50px;
    padding: 5px;
    display: flex;
    gap: 5px;
    z-index: 1000;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.1);
}

.nav-btn {
    background: transparent;
    color: #fff;
    border: none;
    padding: 8px 20px;
    border-radius: 40px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    text-transform: none; /* Override generic button style */
    letter-spacing: normal;
    backdrop-filter: none;
}

.nav-btn:hover {
    background: rgba(255,255,255,0.1);
    transform: none;
    box-shadow: none;
}

.nav-btn.active {
    background: #e5e5e5; /* Softer white */
    color: #000;
}

.nav-btn.active:hover {
    background: #e5e5e5;
    color: #000;
}

@media (max-width: 768px) {
    .top-nav {
        width: 90%;
        max-width: 360px;
        justify-content: space-between;
        top: 15px;
        padding: 4px;
    }

    .nav-btn {
        padding: 8px 0;
        font-size: 0.75rem;
        flex: 1;
        text-align: center;
    }
}

/* Footer */
/* What the page is and a short FAQ, under the tool: closed by default,
   one faint line like the footer's; the text opens on demand. */
.about-section {
    margin-top: 3rem;
    text-align: center;
    font-size: 0.85rem;
    line-height: 1.65;
    color: var(--text-color);
}

.about-toggle {
    display: inline-block;
    padding: 4px 8px;
    font-size: 0.75rem;
    opacity: 0.45;
    cursor: pointer;
    list-style: none;
    transition: opacity 0.3s ease;
}

.about-toggle::-webkit-details-marker {
    display: none;
}

.about-toggle::after {
    content: ' \25BE';
}

.about-section[open] .about-toggle::after {
    content: ' \25B4';
}

.about-toggle:hover,
.about-toggle:focus-visible,
.about-section[open] .about-toggle {
    opacity: 0.8;
}

.about-body {
    margin-top: 1rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    text-align: left;
    opacity: 0.85;
}

.about-section h2 {
    margin: 0 0 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--white);
}

.about-section h3 {
    margin: 1.5rem 0 0.35rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--white);
}

.about-section p {
    margin: 0 0 0.75rem;
}

.about-section a {
    color: inherit;
    text-underline-offset: 3px;
}

.about-section a:hover {
    color: var(--white);
}

.about-section .faq {
    margin-top: 1.5rem;
}

.site-footer {
    margin-top: auto;
    padding: 40px 0 20px;
    text-align: center;
    opacity: 0.6;
    transition: opacity 0.3s ease;
}

.site-footer:hover {
    opacity: 1;
}

.social-links {
    display: flex;
    justify-content: center;
    gap: 20px;
}

.social-links a {
    color: var(--text-color);
    text-decoration: none;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.social-links a:hover {
    color: var(--white);
    transform: translateY(-2px);
}

.social-links svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* The sister site, under the icons and in their colour. */
.sister-link {
    margin: 14px 0 0;
    font-size: 0.8rem;
    color: var(--text-color);
}

.sister-link a {
    color: inherit;
    text-underline-offset: 3px;
}

.sister-link a:hover {
    color: var(--white);
}

@media (max-width: 768px) {

    .app-container {
        padding: 1rem;
    }
}

/* ===== 3. Components ===== */

/* --- ui.css --- */
/* Results Area */
.hidden {
    display: none;
}

/* Read by screen readers and search engines, not drawn: labels whose role
   the layout already shows (the username field's placeholder). */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.status-bar {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.tooltip {
    font-size: 0.7em;
    color: #667;
    font-weight: normal !important;
    margin-left: 5px;
}

/* Info Icons & Tooltips */
.label-with-icon {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 0.8rem;
    color: var(--white);
    font-weight: 600;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* --- background.css --- */
/* Background Posters */
#background-posters {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 60vh;
    z-index: -1;
    overflow: hidden;
    mask-image: linear-gradient(to bottom, black 0%, black 60%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, black 0%, black 60%, transparent 100%);
    display: flex;
    justify-content: center;
    gap: 15px; /* Espace entre les colonnes */
    will-change: transform; /* Optimization for parallax */
}

#background-posters::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, rgba(15, 17, 21, 0.3), rgba(15, 17, 21, 0.8) 90%, var(--bg-color));
}

/* Each column is one composited layer, moved by a transform animation. */
.poster-column {
    display: flex;
    flex-direction: column;
    gap: 15px; /* Espace vertical entre les films */
    /* The loop moves the column by -50% of its own height, which must be one
       full set of posters (6 posters + 6 gaps). Without flex-start the column
       is stretched to the container's 60vh, -50% is only 30vh, and every loop
       ends with a visible jump; the padding adds the 12th gap. */
    align-self: flex-start;
    padding-bottom: 15px;
    width: 140px;
    flex-shrink: 0;
    animation: verticalScroll linear infinite;
    will-change: transform;
    /* A column moves 0.2-0.4 px per frame. A pure translation gets snapped to
       whole pixels by some browsers, so it moved in 1 px steps every few
       frames; a tiny rotation (under 1 px across the whole column) keeps it
       drawn at sub-pixel positions. 0.0001deg was too small to count. */
    transform: translateY(0) rotate(0.02deg);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* The posters themselves are plain images inside their column's layer: the
   grayscale and the 85% opacity are baked into the files
   (scripts/build_posters.py) instead of being filtered on every frame, and a
   layer per poster (translateZ) was ~170 extra GPU textures. */
.bg-poster {
    width: 100%;
    height: auto;
    border-radius: 6px;
    display: block;
}

#background-posters.paused .poster-column {
    animation-play-state: paused;
}

@media (prefers-reduced-motion: reduce) {
    .poster-column {
        animation: none;
    }
}

@keyframes verticalScroll {
    from { transform: translateY(0) rotate(0.02deg); }
    to { transform: translateY(-50%) rotate(0.02deg); }
}

@media (max-width: 768px) {
    #background-posters {
        height: 40vh; /* Arrêt plus tôt */
        mask-image: linear-gradient(to bottom, black 0%, black 40%, transparent 100%);
        -webkit-mask-image: linear-gradient(to bottom, black 0%, black 40%, transparent 100%);
    }

    .poster-column {
        width: 80px; /* Plus petits */
        gap: 10px;
        padding-bottom: 10px;
    }
}

/* --- search.css --- */
/* Hero Section */
.hero-section {
    text-align: center;
    margin-bottom: 4rem;
    /* Positionnement demandé : texte au niveau de la fin du carrousel (60vh) */
    padding-top: 35vh; 
}

/* --- Search Bar Reset & Redesign --- */
.search-wrapper {
    /* Layout Container */
    display: flex;
    align-items: center;
    justify-content: space-between;
    
    /* Dimensions & Spacing */
    width: 100%;
    max-width: 480px;
    height: 60px; /* Hauteur fixe pour éviter les écrasements */
    margin: 3rem auto 0;
    padding: 5px; /* Padding interne pour le bouton */
    
    /* Visual Style (Glassmorphism) */
    background: rgba(20, 20, 25, 0.6); /* Fond sombre semi-transparent */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 100px; /* Pill shape */
    
    /* Shadow & Depth */
    box-shadow: 
        0 4px 24px -1px rgba(0, 0, 0, 0.2),
        0 0 0 1px rgba(0, 0, 0, 0.1);
        
    transition: all 0.3s ease;
    z-index: 100;
}

.search-wrapper:focus-within {
    background: rgba(20, 20, 25, 0.8);
    border-color: var(--accent-color);
    box-shadow: 
        0 8px 32px -4px rgba(0, 0, 0, 0.3),
        0 0 0 2px rgba(139, 92, 246, 0.2); /* Glow violet */
    transform: translateY(-2px);
}

.search-input {
    /* Flex behavior */
    flex: 1; /* Prend tout l'espace restant */
    min-width: 0; /* Empêche le débordement flex */
    
    /* Reset complet */
    background: transparent;
    border: none;
    outline: none;
    
    /* Typography */
    color: var(--white);
    font-size: 1.1rem;
    font-weight: 500;
    
    /* Spacing */
    height: 100%;
    padding: 0 24px; /* Espace à gauche */
}

.search-input::placeholder {
    color: rgba(156, 163, 175, 0.8);
    font-weight: 400;
    font-style: italic;
}

.search-btn {
    /* Dimensions */
    width: 50px;
    height: 50px;
    flex-shrink: 0;
    
    /* Appearance - Force reset */
    background: transparent !important;
    border: none;
    border-radius: 50%;
    padding: 0;
    box-shadow: none !important; /* Ensure no shadow on the button itself */
    
    /* Flex centering */
    display: flex;
    align-items: center;
    justify-content: center;
    
    cursor: pointer;
    transition: transform 0.2s ease;
    
    /* Mobile fix */
    -webkit-tap-highlight-color: transparent;
}

.search-btn svg {
    width: 24px;
    height: 24px;
    /* Force white for visibility */
    stroke: #ffffff !important; 
    stroke-width: 2;
    fill: none !important;
    opacity: 0.8;
    transition: all 0.3s ease;
    /* Ensure no initial filter */
    filter: none;
}

/* Hover State */
@media (hover: hover) {
    .search-btn:hover svg {
        transform: scale(1.15);
        opacity: 1;
        /* Glow très doux et diffus */
        filter: drop-shadow(0 0 12px rgba(139, 92, 246, 0.6));
    }
}

/* Active State */
.search-btn:active {
    transform: scale(0.95);
}

.search-btn:active svg {
    stroke: var(--accent-color) !important;
    /* Glow un peu plus intense au clic */
    filter: drop-shadow(0 0 5px rgba(139, 92, 246, 0.8));
}

@media (max-width: 768px) {
    .hero-section {
        padding-top: 30vh;
    }

    .search-wrapper {
        height: 50px;
        margin-top: 2rem;
    }
    
    /* Ensure touch target is comfortable */
    .search-btn {
        width: 48px;
        height: 48px;
    }
}

/* --- settings.css --- */
/* Configuration Panel */
.config-panel {
    background: rgba(15, 17, 21, 0.8); /* Darker background */
    padding: 1.5rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-bottom: 2rem;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

button {
    background: transparent;
    color: var(--accent-color);
    border: 1px solid var(--accent-color);
    padding: 12px 28px;
    border-radius: 50px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 1px;
    backdrop-filter: blur(4px);
}

button:hover {
    background: var(--accent-color);
    color: var(--white);
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.3);
    transform: translateY(-1px);
}

button:active {
    transform: translateY(0);
}

button:disabled {
    border-color: var(--border-color);
    color: var(--text-color);
    cursor: not-allowed;
    box-shadow: none;
    background: rgba(255,255,255,0.05);
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.checkbox-item input[type="checkbox"] {
    width: 20px; 
    height: 20px; 
    accent-color: var(--accent-color);
    cursor: pointer;
}

.setting-item label {
    display: flex;
    justify-content: space-between;
    color: var(--text-color);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.setting-item span {
    color: var(--white);
    font-weight: bold;
}

.setting-item input[type="range"] {
    width: 100%;
    height: 6px;
    background: #2c3440;
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
    accent-color: var(--accent-color);
}

.setting-item input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent-color);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.1s;
}

.setting-item input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.settings-grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    align-items: end;
}

.settings-checkbox-group {
    display: flex;
    flex-direction: row;
    gap: 20px;
    align-items: center;
    height: 100%;
}

@media (min-width: 769px) {
    /* rp3beta branch: two settings only, side by side */
    .settings-grid-container {
        grid-template-columns: 2fr 1fr;
        align-items: center;
    }

    .settings-checkbox-group {
        justify-content: center;
    }
}

@media (max-width: 768px) {
    .config-panel {
        padding: 1rem;
    }

    .settings-checkbox-group {
        grid-column: span 1; /* Revient à 1 colonne sur mobile */
        flex-wrap: wrap; /* Autorise l'empilement si nécessaire */
    }
}

/* --- cards.css --- */
.movie-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    grid-auto-flow: dense;
}

.movie-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 12px;
    text-decoration: none;
    cursor: pointer;
    background-color: transparent;
    border: none;
    overflow: visible;
    min-height: auto;
}

.poster-container {
    position: relative;
    width: 100%;
    aspect-ratio: 2/3;
    border-radius: 12px;
    overflow: hidden;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), border-color 0.3s, box-shadow 0.3s;
}

/* A real <img> rather than a background-image: it can be lazy-loaded, pick
   its size from srcset, and decode off the main thread. */
.poster-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* The few films TMDB has no artwork for (mostly web shorts and episodes). */
.poster-fallback {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    text-align: center;
    font-family: 'Frick', sans-serif;
    font-size: 1.1rem;
    line-height: 1.2;
    color: var(--white);
    background: linear-gradient(160deg, #2a2340, var(--card-bg) 70%);
}

.bento-medium .poster-container {
    aspect-ratio: 16/9;
}

.movie-card:hover .poster-container {
    transform: scale(1.03);
    z-index: 10;
    border-color: var(--accent-color);
    box-shadow: 0 10px 30px -10px rgba(139, 92, 246, 0.5);
}

/* Shine Effect */
.shine-effect {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(
        0deg,
        transparent,
        rgba(255, 255, 255, 0.1) 40%,
        rgba(255, 255, 255, 0.4) 50%,
        rgba(255, 255, 255, 0.1) 60%,
        transparent
    );
    transform: translateY(-100%);
    transition: transform 0.6s;
    pointer-events: none;
    z-index: 5;
}

.movie-card:hover .shine-effect {
    transform: translateY(100%);
    transition: transform 0.6s;
}

.movie-logo {
    position: absolute;
    bottom: 20px; /* Higher */
    right: 20px; /* More padding */
    max-width: 180px; /* Bigger */
    max-height: 90px; /* Bigger */
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.8));
    z-index: 2;
}

.match-score {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.6);
    color: rgba(255, 255, 255, 0.9);
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
    border: 1px solid rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(4px);
    z-index: 5;
    cursor: default;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    transition: background 0.2s;
}

.match-score:hover {
    background: rgba(0, 0, 0, 0.8);
}

.score-tooltip {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    width: 140px;
    background: rgba(20, 20, 25, 0.95);
    color: #ccc;
    padding: 8px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: normal;
    margin-top: 5px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-align: right;
    z-index: 20;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

.match-score:hover .score-tooltip,
.match-score.active .score-tooltip {
    display: block;
}

.rank {
    position: absolute;
    bottom: 10px;
    left: 10px;
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--accent-color);
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
    z-index: 2;
    background: rgba(0,0,0,0.7);
    padding: 2px 8px;
    border-radius: 6px;
    backdrop-filter: blur(4px);
}

.movie-title {
    color: var(--white);
    font-weight: 600;
    font-size: 1rem;
    line-height: 1.3;
    text-align: center;
    margin: 0;
    text-shadow: none;
    width: 100%;
    max-width: 100%;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    transition: color 0.2s;
}

.movie-card:hover .movie-title {
    color: var(--accent-color);
}

.bento-medium .movie-title {
    max-width: 100%;
}

/* "Because you loved X": the card's biggest source (js/explain.js). */
.because-line {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: -4px;
    min-width: 0;
    font-size: 0.75rem;
    line-height: 1.3;
    color: var(--text-color);
}

.because-thumbs {
    display: flex;
    flex-shrink: 0;
}

.because-thumbs img,
.because-thumb-fallback {
    width: 16px;
    height: 24px;
    border-radius: 3px;
    object-fit: cover;
    background: var(--card-bg);
    box-shadow: 0 0 0 1.5px var(--bg-color);
}

.because-thumbs > * + * {
    margin-left: -6px;
}

.because-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.because-text strong {
    color: #d5dce4;
    font-weight: 500;
}

.because-more {
    opacity: 0.7;
}

.movie-card:hover .because-text strong {
    color: var(--white);
}

/* "Why this film?" dialog */
.why-dialog {
    width: min(560px, calc(100vw - 32px));
    max-height: min(88vh, 820px);
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 18px;
    background: #14171c;
    color: var(--text-color);
    box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(139, 92, 246, 0.08);
    overflow: hidden;
}

.why-dialog[open] {
    display: flex;
    animation: why-in 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.why-dialog::backdrop {
    background: rgba(5, 6, 9, 0.72);
    backdrop-filter: blur(6px);
    animation: why-fade 0.28s ease;
}

@keyframes why-in {
    from { opacity: 0; transform: translateY(16px) scale(0.98); }
}

@keyframes why-fade {
    from { opacity: 0; }
}

body:has(.why-dialog[open]) {
    overflow: hidden;
}

.why-panel {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #3a414c transparent;
}

.why-hero {
    position: relative;
    flex-shrink: 0;
    aspect-ratio: 16 / 7;
    min-height: 170px;
    background: linear-gradient(160deg, #2a2340, #14171c 75%);
    overflow: hidden;
}

.why-hero-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.why-hero::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, #14171c 4%, rgba(20, 23, 28, 0.55) 45%, rgba(20, 23, 28, 0.1));
}

.why-close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 2;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: var(--white);
    letter-spacing: 0;
}

.why-close:hover {
    background: rgba(0, 0, 0, 0.8);
    color: var(--white);
    box-shadow: none;
    transform: none;
}

.why-hero-text {
    position: absolute;
    left: 24px;
    right: 24px;
    bottom: 14px;
    z-index: 1;
}

.why-meta {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.why-rank,
.why-match {
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    backdrop-filter: blur(4px);
}

.why-rank {
    background: rgba(0, 0, 0, 0.6);
    color: var(--accent-color);
}

.why-match {
    background: rgba(139, 92, 246, 0.22);
    border: 1px solid rgba(139, 92, 246, 0.45);
    color: #e4dcff;
}

.why-hero h2 {
    margin: 0;
    font-family: 'Frick', sans-serif;
    font-weight: normal;
    font-size: clamp(1.5rem, 4.5vw, 2.1rem);
    line-height: 1.1;
    color: var(--white);
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}

.why-year {
    font-family: 'Inter', sans-serif;
    font-size: 0.5em;
    font-weight: 400;
    color: var(--text-color);
    text-shadow: none;
}

.why-body {
    padding: 8px 24px 4px;
}

.why-heading {
    margin: 0 0 4px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent-color);
}

.why-lede {
    margin: 0 0 16px;
    font-size: 0.88rem;
    line-height: 1.5;
}

.why-lede em {
    font-style: normal;
    color: var(--white);
}

.why-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.why-source {
    display: grid;
    grid-template-columns: 44px 1fr auto;
    align-items: center;
    gap: 14px;
    padding: 8px 10px 8px 8px;
    border-radius: 12px;
    border: 1px solid transparent;
    transition: background 0.2s, border-color 0.2s;
}

.why-source:hover {
    background: rgba(255, 255, 255, 0.03);
    border-color: var(--border-color);
}

.why-source.is-top {
    background: rgba(139, 92, 246, 0.08);
    border-color: rgba(139, 92, 246, 0.25);
}

.why-source-poster {
    display: grid;
    place-items: center;
    width: 44px;
    aspect-ratio: 2 / 3;
    border-radius: 6px;
    overflow: hidden;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--white);
    font-family: 'Frick', sans-serif;
    text-decoration: none;
}

.why-source-poster img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.why-source-main {
    min-width: 0;
}

.why-source-title {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--white);
    font-weight: 600;
    font-size: 0.92rem;
    text-decoration: none;
}

.why-source-title:hover {
    color: var(--accent-color);
}

.why-source-year {
    font-weight: 400;
    color: var(--text-color);
    font-size: 0.8rem;
}

.why-stars {
    margin-top: 1px;
    font-size: 0.78rem;
    letter-spacing: 1px;
    color: #00c030; /* Letterboxd green */
}

.why-bar {
    height: 5px;
    margin-top: 7px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    overflow: hidden;
}

.why-bar span {
    display: block;
    height: 100%;
    width: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent-hover), #a78bfa);
    transition: width 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.why-source:nth-child(2) .why-bar span { transition-delay: 0.05s; }
.why-source:nth-child(3) .why-bar span { transition-delay: 0.1s; }
.why-source:nth-child(4) .why-bar span { transition-delay: 0.15s; }
.why-source:nth-child(5) .why-bar span { transition-delay: 0.2s; }

.why-dialog.is-ready .why-bar span {
    width: var(--w);
}

.why-rank-num {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    min-width: 3.4em;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
    cursor: help;
}

.why-rank-num strong {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--white);
}

.why-source.is-top .why-rank-num strong {
    color: #c4b5fd;
}

.why-rank-num small {
    white-space: nowrap;
    font-size: 0.68rem;
    color: var(--text-color);
}

.why-actions {
    display: flex;
    justify-content: flex-end;
    padding: 18px 24px 22px;
}

.why-lb {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 999px;
    background: var(--accent-color);
    color: var(--white);
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.2s, box-shadow 0.2s;
}

.why-lb:hover {
    background: var(--accent-hover);
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.35);
}

.why-dialog a:focus-visible,
.why-dialog button:focus-visible,
.movie-card:focus-visible .poster-container {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* Handle and floating close button of the phone sheet (hidden on desktop). */
.why-grabber {
    display: none;
}

@media (max-width: 768px) {
    /* Cards: let the "Because you loved" line wrap instead of widening the
       2-column grid (1fr columns grow to fit unbreakable text otherwise). */
    .movie-card {
        min-width: 0;
    }

    .because-line {
        align-items: flex-start;
        gap: 6px;
        margin-top: -6px;
        font-size: 0.7rem;
        line-height: 1.35;
    }

    .because-thumbs img,
    .because-thumb-fallback {
        width: 14px;
        height: 21px;
    }

    .because-text {
        white-space: normal;
        text-align: left;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
    }

    /* A bottom sheet on phones. */
    .why-dialog {
        position: fixed;
        width: 100%;
        max-width: 100%;
        max-height: 92vh;
        max-height: calc(100dvh - 32px - env(safe-area-inset-top, 0px));
        margin: auto 0 0;
        border-radius: 20px 20px 0 0;
        border: none;
        border-top: 1px solid var(--border-color);
        box-shadow: 0 -20px 60px -10px rgba(0, 0, 0, 0.7);
        transition: transform 0.24s cubic-bezier(0.4, 0, 1, 1);
        touch-action: pan-y;
    }

    .why-dialog[open] {
        animation-name: why-up;
        animation-duration: 0.32s;
    }

    @keyframes why-up {
        from { transform: translateY(100%); }
    }

    .why-dialog.is-dragging {
        transition: none;
    }

    .why-dialog.is-closing {
        transform: translateY(100%);
    }

    /* Stays at the top of the sheet while the content scrolls under it. */
    .why-grabber {
        display: block;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 56px;
        z-index: 4;
        pointer-events: none;
        background: linear-gradient(rgba(10, 11, 14, 0.55), transparent);
        border-bottom: 1px solid transparent;
        transition: background-color 0.2s, border-color 0.2s;
    }

    .why-dialog.is-scrolled .why-grabber {
        background: #14171c;
        border-bottom-color: var(--border-color);
    }

    .why-grabber-title {
        position: absolute;
        left: 60px;
        right: 60px;
        top: 22px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        text-align: center;
        font-family: 'Frick', sans-serif;
        font-size: 1rem;
        color: var(--white);
        opacity: 0;
        transform: translateY(4px);
        transition: opacity 0.2s, transform 0.2s;
    }

    .why-dialog.is-scrolled .why-grabber-title {
        opacity: 1;
        transform: none;
    }

    .why-handle {
        position: absolute;
        top: 8px;
        left: 50%;
        width: 40px;
        height: 5px;
        margin-left: -20px;
        border-radius: 999px;
        background: rgba(255, 255, 255, 0.75);
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
    }

    .why-grabber .why-close {
        pointer-events: auto;
        top: 12px;
        right: 12px;
        width: 40px;
        height: 40px;
    }

    .why-hero .why-close {
        display: none;
    }

    .why-panel {
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }

    .why-panel::-webkit-scrollbar {
        display: none;
    }

    .why-hero {
        aspect-ratio: 16 / 9;
        min-height: 0;
        max-height: 34vh;
    }

    .why-hero-text {
        left: 16px;
        right: 16px;
        bottom: 12px;
    }

    .why-meta {
        margin-bottom: 6px;
    }

    .why-hero h2 {
        font-size: clamp(1.4rem, 7.5vw, 1.9rem);
        text-wrap: balance;
    }

    .why-body {
        padding: 6px 16px 0;
    }

    .why-lede {
        font-size: 0.82rem;
        line-height: 1.5;
        margin-bottom: 12px;
    }

    .why-list {
        gap: 4px;
    }

    .why-source {
        grid-template-columns: 40px minmax(0, 1fr) auto;
        gap: 12px;
        padding: 8px;
        min-height: 72px;
    }

    .why-source:hover {
        background: transparent;
        border-color: transparent;
    }

    .why-source.is-top,
    .why-source.is-top:hover {
        background: rgba(139, 92, 246, 0.08);
        border-color: rgba(139, 92, 246, 0.25);
    }

    .why-source-poster {
        width: 40px;
    }

    /* Two lines rather than an ellipsis: long titles stay readable. */
    .why-source-title {
        white-space: normal;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        font-size: 0.9rem;
        line-height: 1.25;
    }

    .why-bar {
        margin-top: 6px;
    }

    .why-rank-num {
        min-width: 2.6em;
    }

    .why-rank-num strong {
        font-size: 1.05rem;
    }

    /* Always reachable: pinned to the bottom of the sheet. */
    .why-actions {
        position: sticky;
        bottom: 0;
        z-index: 3;
        margin-top: 8px;
        padding: 20px 16px calc(14px + env(safe-area-inset-bottom, 0px));
        background: linear-gradient(transparent, #14171c 28%);
    }

    .why-lb {
        flex: 1;
        justify-content: center;
        min-height: 48px;
        font-size: 0.92rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .why-dialog[open],
    .why-dialog::backdrop {
        animation: none;
    }

    .why-bar span {
        transition: none;
    }
}

/* Bento Classes */
.bento-medium {
    grid-column: span 2;
    grid-row: span 1;
    aspect-ratio: auto; /* Wide */
}

.bento-small {
    grid-column: span 1;
    grid-row: span 1;
}

@media (max-width: 768px) {
    .movie-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px; /* Espace augmenté pour plus de clarté */
        padding-bottom: 2rem; /* Marge en bas de page */
    }

    .movie-card {
        min-height: 220px;
    }

    .bento-medium {
        grid-column: span 1;
        grid-row: span 1;
    }
}

/* --- loader.css --- */
/* Loader */
#loader {
    text-align: center;
    padding: 2rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

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