:root { 
    --bg: #050505; --surface: #121212; --surface-hover: #1e1e1e;
    --text-main: #ffffff; --text-muted: #a1a1aa;
    --accent: #f43f5e; --accent-glow: rgba(244, 63, 94, 0.4);
    --green: #10b981; --blue: #0ea5e9; --radius: 16px;
    --font: 'Outfit', sans-serif; --ease: cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --border: rgba(255,255,255,0.08); --modal-bg: #18181b; --allocine-yellow: #fecc00;
}

body.matrix-mode {
    --bg: #000000; --surface: #0a1f0a; --surface-hover: #0f2f0f;
    --text-main: #00ff41; --text-muted: #008f11;
    --accent: #00ff41; --accent-glow: rgba(0, 255, 65, 0.4);
    --green: #00ff41; --blue: #00ff41; --border: #003b00; --modal-bg: #051405;
    --font: 'Fira Code', monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
*:focus { outline: none !important; }
/* Keyboard-only focus ring (accessibility) */
*:focus-visible { outline: 2px solid var(--accent) !important; outline-offset: 2px; }

html, body { max-width: 100%; overflow-x: hidden; }

body { 
    font-family: var(--font); background: var(--bg); color: var(--text-main); 
    margin: 0; padding: 0; padding-bottom: 120px;
    -webkit-font-smoothing: antialiased;
    transition: background 0.5s ease, color 0.5s ease, transform 1s ease;
}

.hidden { display: none !important; }
@media (max-width: 640px) { .hide-mobile { display: none !important; } }

/* --- HEADER --- */
header { 
    position: sticky; top: 0; z-index: 50; background: rgba(5, 5, 5, 0.8);
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border); padding: 16px 20px; transition: background 0.3s;
}
body.matrix-mode header { background: rgba(0, 20, 0, 0.9); border-bottom: 1px solid var(--accent); }

.header-content { max-width: 1200px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 16px; }

/* --- TABS NAVIGATION --- */
.tabs-container {
    display: flex; gap: 8px; background: rgba(255,255,255,0.03); padding: 6px; 
    border-radius: 20px; border: 1px solid var(--border); overflow-x: auto;
    max-width: max-content; transition: opacity 0.2s, transform 0.2s;
}
.tab-btn {
    background: transparent; border: 1px solid transparent; color: var(--text-muted); font-family: var(--font);
    font-size: 0.95rem; font-weight: 600; padding: 8px 20px; border-radius: 14px;
    cursor: pointer; transition: 0.2s; display: flex; align-items: center; gap: 8px; white-space: nowrap;
}
@media (max-width: 640px) { .tab-btn { padding: 8px 16px; } }
.tab-btn:hover { color: var(--text-main); background: rgba(255,255,255,0.05); }
.tab-btn.active { background: var(--surface-hover); color: var(--text-main); box-shadow: 0 2px 10px rgba(0,0,0,0.2); border-color: var(--border); }
body.matrix-mode .tab-btn.active { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 10px var(--accent-glow); background: transparent; }

/* --- SEARCH --- */
.header-right { display: flex; align-items: center; gap: 10px; flex: 1; justify-content: flex-end; }
.search-wrapper { position: relative; width: 100%; max-width: 420px; transition: all 0.3s ease; }
.search-box {
    width: 100%; padding: 14px 40px 14px 48px; border-radius: 14px;
    border: 1px solid var(--border); background: var(--surface); color: var(--text-main);
    font-size: 1rem; transition: all 0.2s ease; font-family: var(--font); box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.search-box:focus { border-color: var(--accent); background: var(--surface-hover); box-shadow: 0 0 0 4px var(--accent-glow); }
body.matrix-mode .search-box { border-radius: 0; border: 1px solid var(--accent); box-shadow: none; }
.search-icon { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--text-muted); width: 20px; transition: 0.2s; }
.search-box:focus + .search-icon { color: var(--accent); }
.clear-btn { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); background: transparent; border: none; color: var(--text-muted); border-radius: 50%; width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; cursor: pointer; opacity: 0; pointer-events: none; transition: all 0.2s ease; padding: 0; }
.clear-btn:hover { background: rgba(255, 255, 255, 0.1); color: var(--text-main); }
.clear-btn.visible { opacity: 1; pointer-events: auto; }

.mobile-search-trigger { display: none; background: rgba(255,255,255,0.05); border: 1px solid var(--border); color: white; width: 44px; height: 44px; border-radius: 14px; align-items: center; justify-content: center; cursor: pointer; }
.mobile-search-close { display: none; }

@media (max-width: 640px) {
    .mobile-search-trigger { display: flex; transition: opacity 0.2s; }
    .search-wrapper { 
        position: absolute; top: 16px; right: 20px; width: 44px; height: 44px; max-width: none;
        opacity: 0; pointer-events: none; display: flex; align-items: center; z-index: 60;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    .header-content.search-active .search-wrapper { opacity: 1; pointer-events: auto; width: calc(100% - 40px); }
    .header-content.search-active .tabs-container { opacity: 0; pointer-events: none; transform: scale(0.95); }
    .header-content.search-active .mobile-search-trigger { opacity: 0; pointer-events: none; }
    .mobile-search-close { display: flex; align-items: center; justify-content: center; background: transparent; border: none; color: var(--text-muted); width: 44px; height: 44px; cursor: pointer; position: absolute; right: 0; top: 0; }
    .search-box { padding-left: 16px; padding-right: 44px; } 
    .clear-btn { right: 40px; } 
    #search-results { top: calc(100% + 10px); }
}

#search-results { position: absolute; top: 115%; left: 0; right: 0; background: var(--surface); z-index: 100; max-height: 60vh; overflow-y: auto; border-radius: 14px; display: none; box-shadow: 0 20px 60px rgba(0,0,0,0.6); border: 1px solid var(--border); }
body.matrix-mode #search-results { border: 1px solid var(--accent); border-radius: 0; }

/* Empty search state */
.result-empty { padding: 20px 16px; text-align: center; color: var(--text-muted); font-size: 0.95rem; }
.result-empty strong { color: var(--text-main); }

.result-item { padding: 12px; border-bottom: 1px solid var(--border); cursor: pointer; display: flex; gap: 14px; align-items: center; transition: 0.2s; }
.result-item:last-child { border-bottom: none; }
.result-item:hover, .result-item:focus { background: var(--surface-hover); }
.result-item img { width: 48px; height: 72px; object-fit: cover; border-radius: 6px; background: #1a1a1a; }
body.matrix-mode .result-item img { filter: grayscale(100%) sepia(100%) hue-rotate(90deg); border: 1px solid var(--accent); border-radius: 0; }
.result-info { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.result-year { font-size: 0.85rem; color: var(--text-muted); display:flex; align-items:center; gap: 6px; }
.media-tag { font-size: 0.6rem; padding: 2px 6px; border-radius: 4px; background: rgba(255,255,255,0.1); text-transform: uppercase; letter-spacing: 1px; font-weight: bold; }
.in-library-badge { font-size: 0.7rem; padding: 4px 8px; border-radius: 10px; font-weight: 700; display: inline-flex; align-items: center; gap: 4px; margin-left: auto; white-space: nowrap; }

/* --- MAIN LAYOUT --- */
.container { max-width: 1200px; margin: 0 auto; padding: 30px 20px; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; flex-wrap: wrap; gap: 16px; }
.header-left, .header-controls { display: flex; align-items: center; gap: 10px; }
.header-left { gap: 12px; flex-wrap: wrap; }
.count-badge { font-size: 0.75rem; color: var(--text-muted); background: rgba(255,255,255,0.06); padding: 4px 12px; border-radius: 20px; font-weight: 500; border: 1px solid var(--border); }
.active-filter-chip { display: flex; align-items: center; gap: 8px; background: var(--accent-glow); border: 1px solid var(--accent); color: var(--accent); padding: 4px 12px; border-radius: 20px; font-size: 0.85rem; font-weight: 600; cursor: pointer; transition: 0.2s; animation: popIn 0.3s ease; }
.active-filter-chip:hover { opacity: 0.8; }

/* --- STATS DASHBOARD --- */
#stats-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    animation: fadeIn 0.4s ease;
    margin-bottom: 30px;
}
.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    border: 1px solid var(--border);
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
    overflow: hidden;
    transition: transform 0.3s, box-shadow 0.3s;
}
.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
    border-color: rgba(255,255,255,0.15);
}
body.matrix-mode .stat-card { border-radius: 2px; border-color: var(--accent); }
.stat-card.wide { grid-column: 1 / -1; }
.stat-card.medium { grid-column: span 2; }
@media(max-width: 768px) { .stat-card.medium { grid-column: 1 / -1; } }

.stat-label { font-size: 0.85rem; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: 1px; display: flex; align-items: center; gap: 8px;}
.stat-value { font-size: 2.2rem; font-weight: 800; color: white; line-height: 1.1; }
body.matrix-mode .stat-value { color: var(--accent); text-shadow: 0 0 10px var(--accent); }
.stat-subtext { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

/* Chart wrapper: taller on mobile for doughnut legend room */
.chart-wrapper { position: relative; height: 260px; width: 100%; margin-top: 10px; }
@media (max-width: 640px) {
    .stat-card.medium .chart-wrapper { height: 320px; }
}

.stat-icon-bg { position: absolute; right: -10px; bottom: -10px; opacity: 0.05; color: white; }
body.matrix-mode .stat-icon-bg { color: var(--accent); opacity: 0.1; }

/* --- CONTINUE WATCHING CAROUSEL --- */
.continue-watching-container { margin-bottom: 24px; display: flex; flex-direction: column; gap: 12px; }
.horizontal-carousel { display: flex; gap: 16px; overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x mandatory; scrollbar-width: none; }
.horizontal-carousel::-webkit-scrollbar { display: none; }
.cw-card { flex: 0 0 280px; aspect-ratio: 16/9; background: var(--surface); border-radius: 12px; position: relative; overflow: hidden; cursor: pointer; scroll-snap-align: start; border: 1px solid rgba(255,255,255,0.05); box-shadow: 0 4px 15px rgba(0,0,0,0.3); transition: transform 0.3s; }
.cw-card:hover { transform: scale(1.03); }
body.matrix-mode .cw-card { border-radius: 0; border-color: var(--accent); }
.cw-card img { width: 100%; height: 100%; object-fit: cover; }
body.matrix-mode .cw-card img { filter: grayscale(100%) sepia(100%) hue-rotate(90deg) contrast(1.2); }
.cw-overlay { position: absolute; inset: 0; background: linear-gradient(to top, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.4) 50%, transparent 100%); display: flex; flex-direction: column; justify-content: flex-end; padding: 16px; padding-bottom: 20px; }
.cw-title { font-size: 1.1rem; font-weight: 700; color: white; margin-bottom: 4px; text-shadow: 0 2px 4px black; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.matrix-mode .cw-title { color: var(--accent); }
.cw-info { font-size: 0.8rem; color: #d4d4d8; font-weight: 500; display: flex; justify-content: space-between; align-items: center; }
.cw-progress-bg { position: absolute; bottom: 0; left: 0; right: 0; height: 4px; background: rgba(255,255,255,0.2); }
.cw-progress-fill { height: 100%; background: var(--blue); box-shadow: 0 0 10px var(--blue); border-radius: 0 4px 4px 0; }
body.matrix-mode .cw-progress-fill { background: var(--accent); box-shadow: 0 0 10px var(--accent); }

/* --- CONTROLS --- */
.sort-btn { background: var(--surface); border: 1px solid var(--border); color: var(--text-muted); height: 42px; border-radius: 12px; cursor: pointer; transition: 0.2s; font-family: var(--font); font-size: 0.9rem; display: flex; align-items: center; justify-content: center; padding: 0 16px; gap: 8px; outline: none; }
.sort-btn.icon-only { width: 42px; padding: 0; }
.sort-btn:hover { background: var(--surface-hover); border-color: rgba(255,255,255,0.2); color: var(--text-main); }
.sort-btn.active { background: var(--accent-glow); color: var(--accent); border-color: var(--accent); }
body.matrix-mode .sort-btn { border-radius: 0; border: 1px solid var(--accent); }

.sort-wrapper { position: relative; display: inline-flex; }
.hidden-select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; appearance: none; -webkit-appearance: none; }

/* --- GRID --- */
.movie-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 24px 20px; perspective: 1000px; }
.history-list { display: flex; flex-direction: column; gap: 16px; max-width: 800px; margin: 0 auto; }

.genre-header { grid-column: 1 / -1; font-size: 1.1rem; font-weight: 700; color: var(--accent); margin-top: 32px; padding-bottom: 12px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; letter-spacing: 0.02em; text-transform: uppercase; }
.genre-header:first-child { margin-top: 0; }

/* --- CARD --- */
.movie-card { background: var(--surface); border-radius: var(--radius); overflow: hidden; position: relative; cursor: pointer; aspect-ratio: 2/3; transition: transform 0.4s var(--ease), box-shadow 0.4s var(--ease), border-color 0.4s; border: 1px solid rgba(255,255,255,0.05); box-shadow: 0 4px 20px rgba(0,0,0,0.2); }
body.matrix-mode .movie-card { border-radius: 2px; border: 1px solid var(--accent); }
@media (hover: hover) {
    .movie-card:hover { transform: translateY(-8px) scale(1.02); box-shadow: 0 20px 40px rgba(0,0,0,0.5); z-index: 5; border-color: rgba(255,255,255,0.3); }
    body.matrix-mode .movie-card:hover { border-color: var(--accent); box-shadow: 0 0 15px var(--accent-glow); }
}
.movie-card img { width: 100%; height: 100%; object-fit: cover; transition: 0.5s; pointer-events: none; }
body.matrix-mode .movie-card img { filter: grayscale(100%) sepia(100%) hue-rotate(90deg) contrast(1.2); }

.movie-card.is-watched { opacity: 0.48; filter: saturate(0.55) brightness(0.78); }
@media (hover: hover) { .movie-card.is-watched:hover { opacity: 0.72; } }

.card-watched-indicator {
    position: absolute; top: 10px; left: 10px; z-index: 5; width: 20px; height: 20px; border-radius: 999px;
    display: flex; align-items: center; justify-content: center;
    background: rgba(12, 18, 28, 0.82); color: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.28); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}
body.matrix-mode .card-watched-indicator { border-color: var(--accent); color: var(--accent); }

.card-fav-indicator { position: absolute; top: 12px; right: 12px; z-index: 5; color: var(--accent); filter: drop-shadow(0 2px 4px rgba(0,0,0,0.8)); display: flex; align-items: center; justify-content: center; }
.card-fav-indicator svg { width: 18px; height: 18px; }

.card-rating { position: absolute; top: 10px; left: 10px; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); padding: 1px 4px; border-radius: 6px; font-size: 0.7rem; font-weight: 600; color: rgba(255,255,255,0.9); z-index: 4; border: 1px solid rgba(255,255,255,0.1); display: flex; align-items: center; gap: 3px; opacity: 0; transition: opacity 0.3s ease; pointer-events: none; }
.card-rating svg { width: 12px; height: 12px; color: white; }
@media (hover: hover) { .movie-card:hover .card-rating { opacity: 1; } }
@media (hover: none) { .card-rating { opacity: 1; } }
body.show-titles .movie-card .card-rating { opacity: 1 !important; }

.card-overlay { position: absolute; inset: 0; background: linear-gradient(to top, rgba(0,0,0,0.95) 10%, rgba(0,0,0,0.7) 40%, transparent 100%); display: flex; flex-direction: column; justify-content: flex-end; padding: 16px; transition: 0.3s; }
@media (hover: hover) { .card-overlay { opacity: 0; transform: translateY(10px); } .movie-card:hover .card-overlay { opacity: 1; transform: translateY(0); } }
body.show-titles .movie-card .card-overlay { opacity: 1 !important; transform: translateY(0) !important; }

.card-progress-badge { font-size: 0.75rem; font-weight: 700; background: rgba(14, 165, 233, 0.9); color: white; padding: 2px 8px; border-radius: 12px; align-self: center; margin-bottom: 6px; box-shadow: 0 2px 4px rgba(0,0,0,0.5); border: 1px solid rgba(255,255,255,0.2); }
.card-title { font-size: 1rem; font-weight: 700; text-align: center; text-shadow: 0 2px 4px black; line-height: 1.3; margin-bottom: 6px; color: white; }
body.matrix-mode .card-title { color: var(--accent); text-shadow: 0 0 5px var(--accent); }
.card-meta { font-size: 0.75rem; color: #d4d4d8; display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 500; opacity: 0.9; }
.meta-dot { width: 3px; height: 3px; background: var(--accent); border-radius: 50%; }

/* --- SKELETON LOADING --- */
.skeleton-card {
    background: var(--surface); border-radius: var(--radius); aspect-ratio: 2/3; position: relative; overflow: hidden; border: 1px solid rgba(255,255,255,0.05);
}
body.matrix-mode .skeleton-card { border-radius: 2px; border-color: var(--accent); }

.skeleton-shimmer {
    position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.05), transparent); transform: translateX(-100%); animation: shimmer 1.5s infinite;
}
body.matrix-mode .skeleton-shimmer { background: linear-gradient(90deg, transparent, rgba(0, 255, 65, 0.1), transparent); }
@keyframes shimmer { 100% { transform: translateX(100%); } }

/* Synopsis skeleton — shown while modal fetches data */
.synopsis-skeleton {
    display: block;
    background: linear-gradient(90deg, var(--surface-hover) 25%, rgba(255,255,255,0.06) 50%, var(--surface-hover) 75%);
    background-size: 200% 100%;
    animation: shimmer-text 1.4s ease infinite;
    border-radius: 8px;
    height: 1em;
    width: 85%;
    margin-bottom: 8px;
}
.synopsis-skeleton::after {
    content: '';
    display: block;
    height: 1em;
    width: 60%;
    margin-top: 10px;
    background: inherit;
    border-radius: 8px;
    animation: shimmer-text 1.4s ease 0.15s infinite;
}
@keyframes shimmer-text {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* --- EMPTY STATE --- */
.empty-state-wrapper {
    grid-column: 1 / -1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 80px 20px; text-align: center; background: linear-gradient(145deg, rgba(255,255,255,0.02) 0%, rgba(255,255,255,0.0) 100%); border: 1px dashed rgba(255,255,255,0.1); border-radius: 24px; margin-top: 20px; box-shadow: inset 0 0 40px rgba(0,0,0,0.2);
}
body.matrix-mode .empty-state-wrapper { border-color: var(--accent); border-radius: 0; }
.empty-state-icon { width: 72px; height: 72px; margin-bottom: 24px; color: var(--text-muted); opacity: 0.4; animation: float 6s ease-in-out infinite; }
body.matrix-mode .empty-state-icon { color: var(--accent); }
.empty-state-title { font-size: 1.5rem; font-weight: 700; color: white; margin-bottom: 12px; }
body.matrix-mode .empty-state-title { color: var(--accent); }
.empty-state-text { color: var(--text-muted); max-width: 400px; margin-bottom: 32px; line-height: 1.6; }
.empty-state-btn { background: var(--accent-glow); color: var(--accent); border: 1px solid var(--accent); padding: 12px 24px; border-radius: 14px; font-weight: 600; font-family: var(--font); cursor: pointer; display: flex; align-items: center; gap: 10px; transition: 0.2s var(--ease); }
.empty-state-btn:hover { background: var(--accent); color: white; transform: translateY(-3px); box-shadow: 0 10px 20px rgba(244, 63, 94, 0.3); }
body.matrix-mode .empty-state-btn { border-radius: 0; }
@keyframes float { 0% { transform: translateY(0px); } 50% { transform: translateY(-10px); } 100% { transform: translateY(0px); } }

/* --- HISTORY LIST --- */
.history-month-header { font-size: 1.4rem; font-weight: 800; color: white; margin: 24px 0 12px 0; border-bottom: 1px solid var(--border); padding-bottom: 8px; text-transform: capitalize; }
.history-month-header:first-child { margin-top: 0; }
.history-card { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; padding: 12px 16px; gap: 20px; align-items: center; transition: 0.2s;}
.history-card:hover { background: var(--surface-hover); border-color: rgba(255,255,255,0.2); cursor: pointer;}

/* Weekday label now uses accent color (was neutral "Jour") */
.history-day { font-size: 1.6rem; font-weight: 800; color: var(--text-muted); min-width: 44px; text-align: center; display:flex; flex-direction:column; line-height: 1; }
.history-day span { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--accent); margin-bottom: 4px; }

.history-card img { width: 60px; height: 90px; border-radius: 8px; object-fit: cover; box-shadow: 0 4px 10px rgba(0,0,0,0.3); background: #1a1a1a; }
.history-info { flex: 1; display:flex; flex-direction: column; gap: 6px; justify-content: center; }
.history-title { font-size: 1.15rem; font-weight: 700; color: white; display:flex; align-items:center; gap: 8px;}
.history-subtitle { font-size: 0.9rem; color: var(--text-muted); font-weight: 500; display:flex; align-items:center; gap: 8px;}
.history-badge { padding: 2px 8px; border-radius: 6px; font-size: 0.75rem; font-weight: 700; background: rgba(244, 63, 94, 0.1); color: var(--accent); border: 1px solid rgba(244, 63, 94, 0.3);}
.history-badge.tv { background: rgba(14, 165, 233, 0.1); color: var(--blue); border-color: rgba(14, 165, 233, 0.3); }

/* --- RANDOMIZER PANEL --- */
.fab-random { 
    position: fixed; bottom: 30px; right: 30px; 
    background: rgba(244, 63, 94, 0.15); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(244, 63, 94, 0.3); color: var(--accent); 
    width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center; 
    box-shadow: 0 8px 32px rgba(0,0,0,0.4); cursor: pointer; z-index: 90; 
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); outline: none;
}
.fab-random:hover { transform: translateY(-5px) scale(1.05); background: rgba(244, 63, 94, 0.25); border-color: rgba(244, 63, 94, 0.5); }
.fab-random:active { transform: scale(0.95); }
body.matrix-mode .fab-random { background: rgba(0, 255, 65, 0.15); border-color: rgba(0, 255, 65, 0.3); }
body.matrix-mode .fab-random:hover { background: rgba(0, 255, 65, 0.25); border-color: rgba(0, 255, 65, 0.5); }

@keyframes fabShake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px) rotate(-8deg); background: rgba(244, 63, 94, 0.5); }
    40%, 80% { transform: translateX(6px) rotate(8deg); }
}
.fab-shake { animation: fabShake 0.5s ease-in-out; }

.randomizer-panel {
    position: fixed; bottom: 100px; right: 30px; width: 360px;
    background: rgba(20, 20, 24, 0.85); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--border); border-radius: 24px; padding: 24px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.1);
    z-index: 95; transform-origin: bottom right; transition: all 0.4s var(--ease);
    opacity: 0; pointer-events: none; transform: scale(0.9) translateY(20px);
}
body.matrix-mode .randomizer-panel { border-color: var(--accent); border-radius: 0; }
.randomizer-panel.open { opacity: 1; pointer-events: auto; transform: scale(1) translateY(0); }

.rand-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.rand-header h3 { margin: 0; font-size: 1.2rem; color: white; font-weight: 700; }
.rand-section { margin-bottom: 16px; }
.rand-label { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 8px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }

.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-group.scrollable { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 8px; margin-bottom: -8px; scrollbar-width: none; }
.chip-group.scrollable::-webkit-scrollbar { display: none; }

.chip { background: rgba(255,255,255,0.05); border: 1px solid var(--border); color: var(--text-muted); padding: 6px 14px; border-radius: 20px; font-size: 0.85rem; font-family: var(--font); cursor: pointer; transition: 0.2s; white-space: nowrap; outline: none; }
body.matrix-mode .chip { border-radius: 2px; }
.chip:hover { background: rgba(255,255,255,0.1); color: white; border-color: rgba(255,255,255,0.2); }
.chip.active { background: var(--accent-glow); color: var(--accent); border-color: var(--accent); font-weight: 600; }

/* --- MODAL --- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 1000; display: none; align-items: center; justify-content: center; padding: 20px; opacity: 0; transition: opacity 0.3s; backdrop-filter: blur(8px); overflow: hidden; }
.modal-overlay.open { opacity: 1; }
.modal-ambient-bg { position: absolute; inset: -50px; background-size: cover; background-position: center; filter: blur(60px) saturate(110%) brightness(0.35); opacity: 0; transition: opacity 0.6s ease; z-index: -1; transform: scale(1.1); pointer-events: none; }
.modal-overlay.open .modal-ambient-bg { opacity: 0.6; }

.modal-content { background: var(--modal-bg); width: 100%; max-width: 500px; border-radius: 24px; position: relative; box-shadow: 0 40px 80px rgba(0,0,0,0.8); border: 1px solid var(--border); transform: translateY(20px) scale(0.95); transition: all 0.4s var(--ease); max-height: 85vh; display: flex; flex-direction: column; overflow: hidden; }
body.matrix-mode .modal-content { border-radius: 0; border: 1px solid var(--accent); box-shadow: 0 0 20px var(--accent-glow); }
.modal-overlay.open .modal-content { transform: translateY(0) scale(1); }
.modal-content.shuffling { border: 2px solid var(--accent); box-shadow: 0 0 50px var(--accent-glow); }

.modal-scroll-wrapper { flex: 1; overflow-y: auto; overflow-x: hidden; position: relative; scroll-behavior: smooth; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
.modal-hero { height: 360px; position: relative; width: 100%; background: #000; }
.modal-hero::after { content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 220px; background: linear-gradient(to bottom, transparent 0%, var(--modal-bg) 95%); pointer-events: none; z-index: 1; }
.modal-backdrop { width: 100%; height: 100%; object-fit: cover; }
body.matrix-mode .modal-backdrop { filter: grayscale(100%) sepia(100%) hue-rotate(90deg); }

.modal-body { padding: 0 28px 28px; position: relative; z-index: 2; margin-top: -80px; }

.sticky-sentinel { height: 1px; width: 100%; margin-bottom: -1px; pointer-events: none; position: absolute; top: -1px; }
.sticky-header { position: sticky; top: 0; z-index: 50; padding: 20px 28px; margin: 0 -28px 24px -28px; transition: background 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; border-bottom: 1px solid transparent; transform: translateZ(0); }
.sticky-header.is-stuck { background: rgba(24, 24, 27, 0.95); backdrop-filter: blur(16px); border-bottom: 1px solid rgba(255,255,255,0.1); box-shadow: 0 10px 30px rgba(0,0,0,0.5); }

.header-text-group { flex: 1; padding-right: 40px; }
.modal-title { font-size: 2.2rem; margin: 0 0 8px 0; font-weight: 800; line-height: 1.1; text-shadow: 0 4px 10px rgba(0,0,0,0.8); letter-spacing: -0.02em; color: white; transition: color 0.3s ease, text-shadow 0.3s ease; }
body.matrix-mode .modal-title { color: var(--accent); text-shadow: 0 0 10px var(--accent); }
.sticky-header.is-stuck .modal-title { font-size: 1.5rem; text-shadow: none; margin-bottom: 4px; }

.sticky-meta { display: flex; align-items: center; gap: 10px; opacity: 1; transition: 0.3s; flex-wrap: wrap; font-size: 0.9rem; color: var(--text-muted); font-weight: 500;}
.meta-divider { width: 3px; height: 3px; background: #555; border-radius: 50%; }

.modal-actions-top { position: absolute; top: 15px; right: 15px; z-index: 100; display:flex; gap: 10px; }
.circle-btn {
    background: rgba(24, 24, 27, 0.72);
    border: 1px solid rgba(255,255,255,0.12);
    color: var(--text-main);
    width: 38px;
    height: 38px;
    border-radius: 999px;
    cursor: pointer;
    padding: 0;
    display: grid;
    place-items: center;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: 0 10px 24px rgba(0,0,0,0.28);
    transition: transform 0.2s var(--ease), background 0.2s var(--ease), border-color 0.2s var(--ease), color 0.2s var(--ease), box-shadow 0.2s var(--ease);
    outline:none;
}
.circle-btn:hover {
    background: rgba(255,255,255,0.08);
    border-color: rgba(255,255,255,0.22);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 14px 28px rgba(0,0,0,0.34);
}
.btn-fav.is-fav { background: rgba(244, 63, 94, 0.18); color: var(--accent); border-color: rgba(244, 63, 94, 0.45); }
.btn-fav.is-fav:hover { background: rgba(244, 63, 94, 0.28); color: white; border-color: var(--accent); }

.modal-details { animation: fadeIn 0.5s ease; }
.genre-text { font-size: 0.95rem; color: var(--accent); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.director-text { font-size: 0.95rem; color: var(--text-muted); margin-bottom: 20px; }
.director-name { color: white; font-weight: 500; }
.modal-desc { line-height: 1.6; color: #d4d4d8; font-size: 1rem; margin-bottom: 24px; }

.smart-link { cursor: pointer; transition: 0.2s; display: inline-block; }
.smart-link:hover { color: white; text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 4px; }
body.matrix-mode .smart-link:hover { color: var(--accent); }

.seasons-container { display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px; }
.season-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: rgba(255,255,255,0.03); border-radius: 12px; border: 1px solid var(--border); transition: 0.2s; cursor:pointer;}
.season-row:hover { background: rgba(255,255,255,0.06); }
.season-row.watched { background: rgba(16, 185, 129, 0.1); border-color: rgba(16, 185, 129, 0.3); }
.season-info { font-weight: 600; color: white; display: flex; align-items: center; gap: 10px;}
.season-count { font-size: 0.8rem; color: var(--text-muted); font-weight: normal;}

.action-row { display: flex; gap: 12px; margin-top: auto; width: 100%; }
.btn {
    border: 1px solid rgba(255,255,255,0.1);
    padding: 16px 20px;
    border-radius: 18px;
    font-weight: 700;
    cursor: pointer;
    font-size: 1rem;
    font-family: var(--font);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: transform 0.2s var(--ease), background 0.2s var(--ease), border-color 0.2s var(--ease), color 0.2s var(--ease), box-shadow 0.2s var(--ease), opacity 0.2s var(--ease);
    flex: 1;
    outline:none;
    min-height: 52px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 12px 28px rgba(0,0,0,0.22);
}
body.matrix-mode .btn { border-radius: 2px; }
.btn:hover { transform: translateY(-2px); box-shadow: 0 16px 32px rgba(0,0,0,0.28); }
.btn-primary {
    background: linear-gradient(180deg, rgba(255,255,255,0.14) 0%, rgba(255,255,255,0.06) 100%);
    color: var(--text-main);
}
.btn-primary:hover { background: linear-gradient(180deg, rgba(255,255,255,0.18) 0%, rgba(255,255,255,0.08) 100%); border-color: rgba(255,255,255,0.18); }
.btn-primary.watched { background: rgba(39, 39, 42, 0.9); color: var(--text-muted); border: 1px solid rgba(255,255,255,0.08); }
.btn-allocine {
    background: linear-gradient(180deg, rgba(254, 204, 0, 0.98) 0%, rgba(234, 179, 8, 0.92) 100%);
    color: #1f2937;
    font-weight: 800;
    text-decoration: none;
    border-color: rgba(255,255,255,0.08);
}
.btn-allocine:hover { background: linear-gradient(180deg, rgba(254, 204, 0, 1) 0%, rgba(245, 158, 11, 0.96) 100%); }
.btn-danger {
    background: rgba(239, 68, 68, 0.06);
    color: #f87171;
    width: 100%;
    margin-top: 16px;
    font-size: 0.92rem;
    opacity: 0.9;
    padding: 12px 14px;
    border-color: rgba(239, 68, 68, 0.2);
}
.btn-danger:hover { opacity: 1; background: rgba(239, 68, 68, 0.12); border-color: rgba(239, 68, 68, 0.28); }

#preview-actions {
    margin-top: 16px;
}

#preview-actions .btn {
    flex: 1;
}

#btn-add-media {
    background: linear-gradient(180deg, rgba(16, 185, 129, 0.22) 0%, rgba(16, 185, 129, 0.12) 100%);
    color: #d1fae5;
    border-color: rgba(16, 185, 129, 0.34);
    box-shadow: 0 12px 28px rgba(16, 185, 129, 0.12), 0 12px 28px rgba(0,0,0,0.24);
    text-shadow: none;
}

#btn-add-media:hover {
    background: linear-gradient(180deg, rgba(16, 185, 129, 0.3) 0%, rgba(16, 185, 129, 0.18) 100%);
    border-color: rgba(16, 185, 129, 0.5);
    color: white;
    box-shadow: 0 16px 32px rgba(16, 185, 129, 0.18), 0 14px 30px rgba(0,0,0,0.28);
}

#toast { position: fixed; bottom: 30px; left: 50%; transform: translate(-50%, 40px); background: rgba(25, 25, 25, 0.9); backdrop-filter: blur(10px); border: 1px solid #333; color: white; padding: 12px 24px; border-radius: 50px; font-weight: 500; box-shadow: 0 20px 40px rgba(0,0,0,0.6); opacity: 0; pointer-events: none; transition: 0.4s; z-index: 2000; display: flex; align-items: center; gap: 12px; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@keyframes popIn { 0% { transform: scale(0); } 70% { transform: scale(1.2); } 100% { transform: scale(1); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Custom Date Picker Modal */
.date-prompt-modal { position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 2000; display: none; align-items: center; justify-content: center; padding: 20px; opacity: 0; transition: opacity 0.2s; backdrop-filter: blur(4px); }
.date-prompt-modal.open { opacity: 1; }
.date-prompt-content { background: var(--surface); padding: 24px; border-radius: 20px; border: 1px solid var(--border); box-shadow: 0 20px 40px rgba(0,0,0,0.5); width: 100%; max-width: 320px; text-align: center; transform: scale(0.95); transition: 0.2s; }
.date-prompt-modal.open .date-prompt-content { transform: scale(1); }
.date-input { width: 100%; padding: 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-hover); color: white; color-scheme: dark; font-family: var(--font); font-size: 1rem; margin-bottom: 20px; outline: none; }
.date-input:focus { border-color: var(--accent); }

/* --- EASTER EGGS STYLES --- */
.vhs-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06)); background-size: 100% 2px, 3px 100%; pointer-events: none; z-index: 9999; opacity: 0; transition: opacity 0.5s; }
body.vhs-mode #main-content { filter: sepia(0.4) contrast(1.2) brightness(1.2) hue-rotate(-10deg); }
body.vhs-mode .modal-content { filter: sepia(0.4) contrast(1.2) brightness(1.2) hue-rotate(-10deg); }
body.vhs-mode #toast { filter: sepia(0.4) contrast(1.2) brightness(1.2) hue-rotate(-10deg); }
body.vhs-mode .fab-random { filter: sepia(0.4) contrast(1.2) brightness(1.2) hue-rotate(-10deg); }
body.vhs-mode .vhs-overlay { opacity: 1; }
body.vhs-mode * { text-shadow: 1px 0 2px red, -1px 0 2px blue; }

body.noir-mode #main-content { filter: grayscale(100%) contrast(1.3); }
body.noir-mode .modal-content { filter: grayscale(100%) contrast(1.3); }
body.noir-mode #toast { filter: grayscale(100%) contrast(1.3); }
body.noir-mode .fab-random { filter: grayscale(100%) contrast(1.3); }

#matrix-canvas { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -1; opacity: 0; transition: opacity 1s; pointer-events: none; }
body.matrix-mode #matrix-canvas { opacity: 0.3; }

body.barrel-roll { animation: roll 1s ease-in-out; }
@keyframes roll { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

.emoji-rain { position: fixed; top: -50px; font-size: 40px; z-index: 9999; animation: fall linear forwards; pointer-events: none; }
@keyframes fall { to { transform: translateY(110vh) rotate(360deg); } }

/* Spin animation for loading icons */
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.spin { animation: spin 1s linear infinite; display: inline-block; }

@media (max-width: 640px) {
    .movie-grid { grid-template-columns: repeat(2, 1fr); gap: 16px; }
    .container { padding: 20px 16px; }
    .modal-overlay { align-items: flex-end; padding: 0; }
    .modal-content { border-radius: 24px 24px 0 0; transform: translateY(100%); max-height: 92vh; margin: 0; border-bottom: none; }
    .modal-overlay.open .modal-content { transform: translateY(0); }
    #btn-toggle-titles { display: none !important; }
    
    .header-right { justify-content: flex-end; }
    .fab-random { right: 16px; bottom: 16px; width: 52px; height: 52px; border-radius: 16px; }
    
    .randomizer-panel {
        bottom: 0; right: 0; width: 100%; border-radius: 32px 32px 0 0; padding: 24px 20px 40px 20px;
        transform-origin: bottom center; transform: translateY(100%);
    }
    .randomizer-panel.open { transform: translateY(0); }
    .randomizer-panel::before {
        content: ''; position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
        width: 40px; height: 4px; background: rgba(255,255,255,0.2); border-radius: 4px;
    }
}