/* =================== VARIABLES & THEMING =================== */
:root {
    /* Light Theme (Default fallback) */
    --bg-main: #f3f4f6;
    --bg-secondary: rgba(255, 255, 255, 0.8);
    --bg-glass: rgba(255, 255, 255, 0.4);
    --text-main: #111827;
    --text-muted: #4b5563;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --success: #10b981;
    --danger: #ef4444;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-glass: 0 8px 32px 0 rgba(31, 38, 135, 0.1);
    --border-glass: rgba(255, 255, 255, 0.3);
    --overlay: rgba(0, 0, 0, 0.5);
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Outfit', sans-serif;
}

body.theme-dark {
    --bg-main: #0f172a;
    --bg-secondary: rgba(30, 41, 59, 0.8);
    --bg-glass: rgba(15, 23, 42, 0.6);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --primary: #818cf8;
    --primary-hover: #6366f1;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    --border-glass: rgba(255, 255, 255, 0.1);
    --overlay: rgba(0, 0, 0, 0.8);
}

/* =================== RESET & GLOBAL =================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    overflow-x: hidden;
    transition: background-color 0.4s ease, color 0.4s ease;
    -webkit-font-smoothing: antialiased;
}

/* =================== UTILITIES =================== */
.hidden { display: none !important; }
.glass-card {
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-glass);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-glass);
}

/* =================== HEADER =================== */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 3rem;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-glass);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 50;
    transition: all 0.3s ease;
}

.logo {
    font-weight: 700;
    font-size: 1.5rem;
    color: var(--primary);
    cursor: pointer;
    letter-spacing: -0.5px;
}

.nav-links {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    background: rgba(0, 0, 0, 0.05);
    padding: 0.25rem;
    border-radius: 12px;
    border: 1px solid var(--border-glass);
}

body.theme-dark .nav-links {
    background: rgba(255, 255, 255, 0.05);
}

.nav-btn {
    background: transparent;
    border: none;
    color: var(--text-main);
    font-family: inherit;
    font-weight: 500;
    font-size: 0.95rem;
    cursor: pointer;
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-btn:hover {
    background: var(--bg-secondary);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.nav-btn:active {
    transform: translateY(0);
}

.theme-toggle {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: transform 0.3s ease;
}

.theme-toggle:hover {
    transform: rotate(30deg) scale(1.1);
}

/* =================== SCREENS =================== */
#appContainer {
    min-height: calc(100vh - 70px);
    position: relative;
    padding: 2rem;
}

.screen {
    max-width: 1200px;
    margin: 0 auto;
    animation: fadeIn 0.4s ease forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* =================== HOME SCREEN =================== */
.hero {
    text-align: center;
    margin-bottom: 3rem;
    padding: 3rem 0 1rem;
}

.hero h2 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--primary), #a855f7);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
}

.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
}

.category-card {
    position: relative;
    border-radius: var(--border-radius);
    overflow: hidden;
    height: 300px;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.category-card:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: var(--shadow-lg);
}

.card-bg {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    transition: transform 0.5s ease;
}

.category-card:hover .card-bg {
    transform: scale(1.1);
}

.card-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0.2) 100%);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 1.5rem;
    color: white;
}

.card-overlay h3 { font-size: 1.5rem; font-weight: 600; }
.card-overlay .count { font-size: 0.9rem; opacity: 0.8; }

/* =================== BUTTONS & INPUTS =================== */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg-glass);
    color: var(--text-main);
    border: 1px solid var(--border-glass);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-secondary:hover {
    background: var(--bg-secondary);
}

input[type="text"], input[type="url"], select {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-glass);
    background: var(--bg-glass);
    color: var(--text-main);
    outline: none;
    font-family: var(--font-body);
}

input:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

/* =================== MODALS =================== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: var(--overlay);
    backdrop-filter: blur(5px);
    animation: fadeIn 0.3s ease;
}

.modal-content {
    position: relative;
    z-index: 101;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    padding: 2rem;
    overflow-y: auto;
    animation: slideUp 0.4s ease;
}

@keyframes slideUp {
    from { opacity: 0; transform: scale(0.95) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s;
}
.modal-close:hover { color: var(--danger); }

/* Global Image Modal specific */
.image-modal-content {
    background: transparent;
    box-shadow: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0;
    max-width: 90vw;
}
.image-modal-content img {
    max-width: 100%;
    max-height: 85vh;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-2xl);
    object-fit: contain;
}
.image-modal-content .modal-close {
    position: absolute;
    top: -40px;
    right: 0;
    color: white;
    font-size: 2rem;
}

/* =================== GALLERY =================== */
.gallery-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 2rem;
    justify-content: space-between;
}

.filter-pills {
    display: flex;
    gap: 0.5rem;
}

.pill {
    padding: 0.5rem 1rem;
    border-radius: 999px;
    border: 1px solid var(--border-glass);
    background: var(--bg-glass);
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.2s ease;
}

.pill.active, .pill:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;
}

.char-item {
    border-radius: var(--border-radius);
    overflow: hidden;
    cursor: pointer;
    position: relative;
    aspect-ratio: 9/16;
    box-shadow: var(--shadow-md);
}

.char-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s;
}
.char-item:hover img { transform: scale(1.05); }

.char-item-info {
    position: absolute;
    bottom: 0;
    width: 100%;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 0.75rem;
    backdrop-filter: blur(4px);
}
.char-item-info strong { display: block; font-size: 1rem; }
.char-item-info span { font-size: 0.8rem; opacity: 0.8; }

/* =================== GAME CONFIG =================== */
.config-container { padding: 3rem; text-align: center; max-width: 500px; margin: 4rem auto; }
.rounds-selector { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: center; margin: 2rem 0; }
.rounds-selector label { cursor: pointer; }
.rounds-selector input { display: none; }
.rounds-selector span {
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    border: 2px solid var(--border-glass);
    display: inline-block;
    transition: all 0.2s;
}
.rounds-selector input:checked + span {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
    font-weight: 600;
}

/* =================== GAMEPLAY =================== */
.game-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.progress-bar {
    flex-grow: 1;
    height: 8px;
    background: var(--bg-glass);
    border-radius: 4px;
    overflow: hidden;
    max-width: 400px;
}

#gameProgressFill {
    height: 100%;
    background: var(--primary);
    width: 0%;
    transition: width 0.3s ease;
}

.stats { display: flex; gap: 1rem; }
.stat-round, .stat-streak {
    padding: 0.5rem 1rem;
    border-radius: 8px;
    background: var(--bg-glass);
    font-weight: 600;
}
.stat-streak { color: var(--success); }

.game-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
}

.image-frame {
    width: 100%;
    max-width: 400px;
    aspect-ratio: 9/16;
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-frame img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
    object-fit: cover;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
}

.options-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    max-width: 400px;
}

.opt-btn {
    padding: 1rem;
    font-size: 1.1rem;
    border-radius: 12px;
    border: 2px solid var(--border-glass);
    background: var(--bg-glass);
    color: var(--text-main);
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}
.opt-btn:hover:not(:disabled) {
    border-color: var(--primary);
    transform: translateY(-2px);
}
.opt-btn.correct {
    background: var(--success);
    border-color: var(--success);
    color: white;
}
.opt-btn.incorrect {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
}

/* =================== RESULTS =================== */
.results-card {
    max-width: 600px;
    margin: 2rem auto;
    padding: 3rem;
    text-align: center;
}

.metrics {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin: 2rem 0;
    flex-wrap: wrap;
}

.metric {
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    padding: 1rem 2rem;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}

.metric span { font-size: 0.9rem; color: var(--text-muted); }
.metric strong { font-size: 1.8rem; font-weight: 700; color: var(--primary); }

.mistakes-review {
    text-align: left;
    margin-bottom: 2rem;
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 12px;
}

.mistakes-review h3 { margin-bottom: 1rem; }

.mistake-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-glass);
}

.mistake-item img {
    width: 50px;
    height: 50px;
    border-radius: 8px;
    object-fit: cover;
    cursor: pointer;
}

.mistake-info {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}
.mistake-info .wrong { color: var(--danger); text-decoration: line-through; font-size: 0.9em;}
.mistake-info .right { color: var(--success); font-weight: 600; }

/* =================== TOAST =================== */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--bg-secondary);
    color: var(--text-main);
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideInRight 0.3s ease forwards;
    border-left: 4px solid var(--primary);
    backdrop-filter: blur(10px);
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
.toast.fade-out { animation: fadeOutRight 0.3s ease forwards; }

@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes fadeOutRight {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}

/* =================== MANAGER MODAL =================== */
.manager-body {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.data-actions {
    display: flex;
    gap: 1rem;
}

.add-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 8px;
}

.character-list {
    max-height: 300px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.character-list::-webkit-scrollbar { width: 6px; }
.character-list::-webkit-scrollbar-thumb { background: var(--border-glass); border-radius: 4px; }

.manager-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border-radius: 6px;
    border: 1px solid var(--border-glass);
}
.manager-item-info {
    display: flex;
    align-items: center;
    gap: 10px;
}
.manager-item-info img {
    width: 40px; height: 40px; border-radius: 4px; object-fit: cover;
}
.manager-item-actions button {
    background: transparent;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-weight: 600;
}

#confettiCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

/* =================== RESPONSIVE =================== */
@media (max-width: 600px) {
    .app-header { flex-direction: column; gap: 1rem; }
    .nav-links { width: 100%; justify-content: space-between; }
    .hero h2 { font-size: 2rem; }
    .metrics { flex-direction: column; gap: 1rem; }
    .metric { width: 100%; }
}
