:root {
    --bg: #0f1115;
    --panel: #141823;
    --panel-2: #0d1018;
    --text: #e6e9f0;
    --muted: #a9b1c6;
    --accent: #6aa6ff;
    --accent-2: #9b6bff;
    --glow: #ffef9b;
    --danger: #ff6b6b;
    --success: #45d483;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    --radius: 16px;
    --card-w: 220px;
    --card-h: 330px;
}

body.theme-movies { }
body.theme-games {
    --bg: #080a10; --panel: #111424; --panel-2: #090a14;
    --accent: #39ff14; --accent-2: #ff00ff; --glow: #00ffff;
    background-image: repeating-linear-gradient(0deg, rgba(0,0,0,0.15) 0px, rgba(0,0,0,0.15) 2px, transparent 2px, transparent 4px);
}
body.theme-vinyl {
    --bg: #1a1410; --panel: #2c221a; --panel-2: #1e1711;
    --accent: #d4a373; --accent-2: #8b5a2b; --glow: #faedcd;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
    margin: 0; background-color: var(--bg);
    background-image: radial-gradient(1200px 600px at 80% -10%, rgba(255,255,255,0.03) 0%, transparent 55%), radial-gradient(900px 500px at -10% 20%, rgba(255,255,255,0.02) 0%, transparent 45%), linear-gradient(180deg, var(--bg) 0%, #000 100%);
    color: var(--text); font: 16px/1.4 system-ui, -apple-system, sans-serif;
    overflow-x: hidden; transition: background-color 0.4s ease, --accent 0.4s ease;
}

.hex-frame { clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%); }

header {
    position: sticky; top: 0; z-index: 40; backdrop-filter: saturate(1.2) blur(8px);
    background: linear-gradient(180deg, rgba(0,0,0, 0.7), rgba(0,0,0, 0.4));
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.wrap {
    max-width: 1200px; margin: 0 auto; padding: 14px 18px;
    display: flex; align-items: center; gap: 14px; justify-content: space-between;
}

.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 34px; height: 34px; background: conic-gradient(from 230deg, var(--accent), var(--accent-2), var(--accent)); }
.title { font-weight: 800; font-size: 18px; letter-spacing: 1px; }

.menu-toggle { display: none; background: transparent; border: none; font-size: 24px; color: var(--text); padding: 0; box-shadow: none; cursor: pointer; }
.menu-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 90; opacity: 0; transition: opacity 0.3s; }
.mobile-close-btn { display: none; }

.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.category-tabs { justify-content: flex-start; gap: 20px; padding-top: 24px; padding-bottom: 0; margin-bottom: -10px; }
.tab-btn {
    background: transparent; border: none; box-shadow: none; color: var(--muted);
    font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 12px;
    padding: 10px 15px 20px; border-bottom: 3px solid transparent; border-radius: 0; opacity: 0.6; transition: all 0.3s;
}
.tab-btn:hover { transform: none; box-shadow: none; opacity: 1; color: var(--text); }
.tab-btn.active { opacity: 1; color: var(--text); border-bottom: 3px solid var(--accent); }
.tab-icon { width: 24px; height: 24px; background: var(--panel-2); }
.tab-btn.active .icon-movies { background: conic-gradient(from 45deg, #6aa6ff, #9b6bff); }
.tab-btn.active .icon-games { background: conic-gradient(from 45deg, #39ff14, #ff00ff); }
.tab-btn.active .icon-vinyl { background: conic-gradient(from 45deg, #d4a373, #8b5a2b); }

button, .btn {
    appearance: none; border: none; outline: none; cursor: pointer;
    color: var(--text); padding: 10px 14px; border-radius: 12px;
    background: linear-gradient(180deg, rgba(255,255,255,0.1), rgba(255,255,255,0.02));
    border: 1px solid rgba(255, 255, 255, 0.08); box-shadow: var(--shadow); transition: .18s ease-out; font-size: 14px; font-weight: 600;
}
button:hover { transform: translateY(-1px); box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45); }
.btn-accent { background: linear-gradient(180deg, var(--accent-2), #1a2542); border-color: rgba(255,255,255,0.2); }
.btn-green { background: linear-gradient(180deg, var(--success), #142820); border-color: rgba(255,255,255,0.2); }
.btn-danger { background: linear-gradient(180deg, var(--danger), #281414); border-color: rgba(255,255,255,0.2); }

.muted { color: var(--muted); }
main { max-width: 1200px; margin: 18px auto 80px; padding: 0 18px; }

.add-section { background: var(--panel); padding: 20px; border-radius: var(--radius); border: 1px solid rgba(255,255,255,0.06); margin-bottom: 24px; display: none; }
.add-section.active { display: block; }
.form-row { display: flex; gap: 10px; margin-bottom: 12px; }
.year-input { width: 100px; }
.upload-row { align-items: center; }
.btn-row { margin-top: 15px; }

input, textarea, select {
    width: 100%; padding: 10px; border-radius: 8px; background: var(--panel-2);
    border: 1px solid rgba(255,255,255,0.1); color: var(--text); font-family: inherit;
}
.thumb-preview { width: 50px; height: 75px; background: #000; border-radius: 4px; overflow: hidden; display: flex; align-items: center; justify-content: center; font-size: 10px; }

.search-results { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 10px; margin-bottom: 15px; }
.search-result-item { width: 100px; flex-shrink: 0; cursor: pointer; text-align: center; font-size: 12px; opacity: 0.7; transition: 0.2s; }
.search-result-item:hover, .search-result-item.selected { opacity: 1; transform: scale(1.05); }
.search-result-item img { width: 100%; border-radius: 6px; }

/* Filter & Stats Row */
.library-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; flex-wrap: wrap; gap: 15px; }
.library-title-group { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.library-title-group h3 { margin: 0; }
.stats-badge { background: rgba(255,255,255,0.05); padding: 6px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; letter-spacing: 0.5px; color: var(--accent); border: 1px solid rgba(255,255,255,0.1); }
.filter-group { display: flex; gap: 10px; flex: 1; justify-content: flex-end; align-items: center; }
.format-select { max-width: 180px; }
.local-search { max-width: 300px; background: rgba(0,0,0,0.3); padding: 10px 15px; }

.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; margin-top: 18px; }
.shelf-item {
    position: relative; border-radius: 14px; overflow: hidden; background: #000;
    border: 1px solid rgba(255, 255, 255, 0.06); aspect-ratio: 2/3; cursor: pointer; transition: transform .18s ease-out;
}
.shelf-item:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: 0 18px 36px rgba(0, 0, 0, 0.45); }
.shelf-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.shelf-item .glow-sweep {
    content: ""; position: absolute; inset: -20%; background: radial-gradient(140px 140px at 50% 50%, var(--glow), transparent 60%);
    filter: blur(8px); opacity: 0; pointer-events: none; transform: scale(0.8); transition: opacity .08s linear, transform .08s linear; z-index: 10;
}
.shelf-item.highlight .glow-sweep { opacity: 0.4; transform: scale(1); }
.shelf-item::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(180deg, transparent 60%, rgba(0,0,0,0.6) 100%); }

#emptyState { text-align: center; padding: 60px 20px; color: var(--muted); display: none; }

.modal-overlay { position: fixed; inset: 0; z-index: 200; background: rgba(0, 0, 0, 0.85); backdrop-filter: blur(10px); display: flex; align-items: center; justify-content: center; padding: 20px; opacity: 0; pointer-events: none; transition: opacity 0.3s ease; }
.modal-overlay.active { opacity: 1; pointer-events: auto; }
.modal-panel { position: relative; background: var(--panel); border: 1px solid var(--accent); border-radius: var(--radius); box-shadow: 0 30px 60px rgba(0, 0, 0, 0.8); width: 100%; max-width: 700px; max-height: 95vh; transform: translateY(20px) scale(0.95); transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); overflow-y: auto; }
.modal-overlay.active .modal-panel { transform: translateY(0) scale(1); }
.modal-close { position: absolute; top: 15px; right: 15px; background: rgba(255, 255, 255, 0.1); border: none; color: white; width: 32px; height: 32px; border-radius: 50%; font-size: 20px; display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 10; transition: background 0.2s; }
.modal-close:hover { background: var(--danger); }
.modal-layout { display: flex; flex-direction: column; }
@media (min-width: 600px) { .modal-layout { flex-direction: row; } }
.modal-poster-wrap { flex: 0 0 250px; background: #000; }
.modal-poster-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.modal-details { padding: 30px; flex: 1; }
.modal-details h2 { margin: 0 0 10px 0; font-size: 24px; color: #fff; }
.modal-badges { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.badge { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; text-shadow: 0 1px 2px rgba(0,0,0,0.5); }
.rating-badge { background: linear-gradient(135deg, #f5c518, #d4a300); color: #000; text-shadow: none; }
.modal-divider { height: 1px; background: linear-gradient(90deg, rgba(255,255,255,0.1), transparent); margin-bottom: 20px; }
.modal-details p { margin: 0; line-height: 1.6; max-height: 200px; overflow-y: auto; }

/* ========================================= */
/* MOBILE OPTIMIZATIONS (Smartphones)        */
/* ========================================= */
@media (max-width: 768px) {
    header { backdrop-filter: none; z-index: 100; background: var(--panel); }
    .header-wrap { padding: 12px 16px; }
    
    .menu-toggle { display: block; }
    .menu-overlay.active { display: block; opacity: 1; }
    
    .controls {
        position: fixed; top: 0; left: -280px; width: 260px; height: 100vh;
        background: #1c2333; border-right: 2px solid var(--accent);
        flex-direction: column; align-items: stretch; padding: 20px;
        transition: left 0.3s cubic-bezier(0.2, 0.8, 0.2, 1); 
        z-index: 101; box-shadow: 15px 0 40px rgba(0,0,0,0.9); overflow-y: auto;
    }
    .controls.active { left: 0; }
    .controls button { padding: 14px; font-size: 15px; text-align: left; justify-content: flex-start; margin-bottom: 8px;}
    
    .mobile-close-btn { display: block; background: transparent; border: 1px solid rgba(255,255,255,0.2); text-align: center !important; margin-bottom: 20px !important; color: var(--muted); }

    .category-tabs { overflow-x: auto; white-space: nowrap; padding-bottom: 12px; }
    .category-tabs::-webkit-scrollbar { display: none; }
    .tab-btn { flex-shrink: 0; padding: 10px 12px; font-size: 16px; }
    
    .form-row { flex-direction: column; gap: 10px; }
    .year-input { width: 100%; }
    
    /* Stack the library header elements nicely on mobile */
    .filter-group { flex-direction: column; width: 100%; align-items: stretch; }
    .format-select, .local-search { max-width: 100%; }
    
    .shelf { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 10px; }
    
    .modal-panel { margin: 15px; width: calc(100% - 30px); }
    .modal-poster-wrap { flex: 0 0 180px; }
    .modal-details { padding: 20px; }
}