/* --- VARIABLES & RESET --- */
:root {
    --primary: #00f2fe;
    /* Cyan */
    --secondary: #b388ff;
    /* Purple Neon */
    --accent: #ff4757;
    /* Coral Red for warnings/hearts */
    --dark-bg: #050714;
    /* Deep Night Blue */
    --glass-bg: rgba(10, 15, 30, 0.6);
    --glass-border: rgba(0, 242, 254, 0.15);
    --text-main: #ffffff;
    --text-muted: rgba(255, 255, 255, 0.75);
    --font-main: 'Inter', sans-serif;
    --font-title: 'Outfit', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Accessibility: visible focus for keyboard navigation */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: 4px;
}

:focus:not(:focus-visible) {
    outline: none;
}

/* Skip link for screen readers */
.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    background: var(--primary);
    color: #000;
    padding: 12px 24px;
    z-index: 99999;
    font-weight: 700;
    text-decoration: none;
    border-radius: 0 0 8px 0;
    transition: top 0.2s;
}

.skip-link:focus {
    top: 0;
}

/* Touch targets minimum 44px */
.btn-3d {
    min-height: 48px;
    min-width: 44px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

body {
    font-family: var(--font-main);
    background: radial-gradient(circle at center, transparent 0%, var(--dark-bg) 100%),
        url('../assets/images/FondAccueil.webp');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-color: var(--dark-bg);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease;
}

/* --- BACKGROUND 3D --- */
#canvas-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: auto;
    /* Let mouse events reach canvas for interaction */
}

/* Subtile background atmospheric glow overlay */
#canvas-container::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 50% 50%, transparent 40%, rgba(5, 7, 20, 0.8) 100%);
    pointer-events: none;
}

/* --- MAIN UI CARD --- */
.scene-overlay {
    perspective: 1000px;
    z-index: 10;
    pointer-events: none;
    /* Let hover pass through to canvas when not on card */
}

.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(24px) saturate(150%);
    -webkit-backdrop-filter: blur(24px) saturate(150%);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 3rem 4rem;
    width: 100%;
    max-width: 500px;
    text-align: center;
    box-shadow: 0 30px 60px -15px rgba(0, 0, 0, 0.8),
        inset 0 0 20px rgba(0, 242, 254, 0.05);
    /* Inner subtle glow */
    transform-style: preserve-3d;
    transition: transform 0.1s ease;
    pointer-events: auto;
    /* Enable clicks on card */
}

/* --- TYPOGRAPHY & HEADER --- */
.icon-pulse {
    font-size: 3rem;
    color: var(--accent);
    margin-bottom: 1rem;
    animation: heartbeat 2s infinite cubic-bezier(0.4, 0, 0.2, 1);
    text-shadow: 0 0 25px rgba(255, 71, 87, 0.6);
}

@keyframes heartbeat {
    0% {
        transform: scale(1);
    }

    15% {
        transform: scale(1.3);
    }

    30% {
        transform: scale(1);
    }

    45% {
        transform: scale(1.15);
    }

    60% {
        transform: scale(1);
    }
}

.glitch-title {
    font-family: var(--font-title);
    font-size: 3.5rem;
    font-weight: 800;
    letter-spacing: 2px;
    margin-bottom: 0.2rem;
    background: linear-gradient(135deg, #ffffff, var(--primary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    position: relative;
    text-shadow: 0 0 30px rgba(0, 242, 254, 0.3);
}

.subtitle {
    color: var(--secondary);
    font-size: 1.1rem;
    font-weight: 500;
    letter-spacing: 2px;
    margin-bottom: 2.5rem;
    text-transform: uppercase;
}

/* --- 3D BUTTONS --- */
.button-container {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.btn-3d {
    position: relative;
    background: rgba(10, 15, 30, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: white;
    font-family: var(--font-title);
    font-weight: 600;
    font-size: 1rem;
    padding: 1.2rem 2rem;
    border-radius: 12px;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.btn-content {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, var(--secondary), var(--primary));
    opacity: 0.8;
    z-index: 1;
    transform: translateX(-101%);
    transition: transform 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.btn-3d:hover {
    border-color: var(--primary);
    transform: translateY(-4px);
    box-shadow: 0 10px 25px rgba(0, 242, 254, 0.3),
        0 0 10px rgba(179, 136, 255, 0.4);
}

.btn-3d:hover .btn-layer {
    transform: translateX(0);
}

/* Specific button styles */
.btn-3d.primary .btn-layer {
    background: linear-gradient(90deg, #00c6ff, var(--primary));
}

.btn-3d.primary:hover {
    box-shadow: 0 0 30px rgba(0, 242, 254, 0.5);
}

.btn-3d.secondary .btn-layer {
    background: linear-gradient(90deg, #9b51e0, var(--secondary));
}

.btn-3d.secondary:hover {
    box-shadow: 0 0 30px rgba(179, 136, 255, 0.4);
    border-color: var(--secondary);
}

.btn-3d.tertiary .btn-layer {
    background: linear-gradient(90deg, #4facfe, #00f2fe);
}

.disclaimer {
    margin-top: 2rem;
    font-size: 0.75rem;
    font-weight: 300;
    color: rgba(255, 255, 255, 0.4);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 1rem;
}

/* --- MODAL --- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-backdrop.active {
    opacity: 1;
    pointer-events: all;
}

.modal-glass {
    background: #1a1f2e;
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    width: 90%;
    max-width: 500px;
    padding: 2rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.modal-backdrop.active .modal-glass {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 1rem;
}

.modal-header h2 {
    font-family: var(--font-title);
    color: var(--primary);
}

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

.close-icon:hover {
    color: var(--accent);
}

/* Difficulty Selector */
.difficulty-selector {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-top: 1.2rem;
    align-items: stretch;
    /* Force same height */
}

.diff-option {
    display: flex;
    flex: 1;
}

.diff-option input {
    display: none;
}

.diff-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.04);
    padding: 24px 15px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
    border: 2px solid transparent;
    width: 100%;
    min-height: 140px;
    /* Stronger guarantee */
    flex: 1;
    text-align: center;
    box-sizing: border-box;
}

.diff-card i {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.diff-card span {
    font-weight: bold;
    font-size: 0.9rem;
}

.diff-card small {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.diff-option input:checked+.diff-card.green {
    border-color: #2ecc71;
    background: rgba(46, 204, 113, 0.1);
    color: #2ecc71;
}

.diff-option input:checked+.diff-card.blue {
    border-color: #3498db;
    background: rgba(52, 152, 219, 0.1);
    color: #3498db;
}

.diff-option input:checked+.diff-card.red {
    border-color: #e74c3c;
    background: rgba(231, 76, 60, 0.1);
    color: #e74c3c;
}

.btn-flat {
    width: 100%;
    padding: 12px;
    margin-top: 20px;
    border: none;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    font-family: var(--font-title);
}

.btn-flat.save {
    background: var(--primary);
    color: #000;
}

.btn-flat.save:hover {
    background: #fff;
    box-shadow: 0 0 15px var(--primary);
}

/* Switch Toggle */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
}

input:checked+.slider {
    background-color: var(--primary);
}

input:focus+.slider {
    box-shadow: 0 0 1px var(--primary);
}

input:checked+.slider:before {
    transform: translateX(20px);
}

.slider.round {
    border-radius: 24px;
}

.slider.round:before {
    border-radius: 50%;
}

/* --- LEADERBOARD --- */
.leaderboard-panel {
    position: absolute;
    right: 40px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--glass-bg);
    backdrop-filter: blur(24px) saturate(150%);
    -webkit-backdrop-filter: blur(24px) saturate(150%);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 1.5rem;
    width: 320px;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5), inset 0 0 15px rgba(0, 242, 254, 0.05);
    pointer-events: auto;
    z-index: 15;
    animation: slideInRight 0.8s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translate(50px, -50%);
    }

    to {
        opacity: 1;
        transform: translate(0, -50%);
    }
}

.leaderboard-header {
    margin-bottom: 1rem;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.8rem;
}

.leaderboard-header h3 {
    font-family: var(--font-title);
    color: #ffd700;
    font-size: 1.2rem;
    letter-spacing: 1px;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.leaderboard-list {
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-right: 5px;
}

/* Scrollbar personnalisée */
.leaderboard-list::-webkit-scrollbar {
    width: 4px;
}

.leaderboard-list::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

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

.leaderboard-item {
    display: flex;
    align-items: center;
    padding: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    transition: all 0.2s ease;
}

.leaderboard-item:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateX(-5px);
    border-color: rgba(0, 242, 254, 0.3);
}

.lb-rank {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: bold;
    font-size: 0.9rem;
    margin-right: 12px;
    background: rgba(0, 0, 0, 0.3);
    color: rgba(255, 255, 255, 0.7);
    flex-shrink: 0;
}

/* Styles pour le Top 3 */
.leaderboard-item.rank-1 .lb-rank {
    background: linear-gradient(135deg, #ffd700, #ffaa00);
    color: #000;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.leaderboard-item.rank-2 .lb-rank {
    background: linear-gradient(135deg, #e0e0e0, #9e9e9e);
    color: #000;
}

.leaderboard-item.rank-3 .lb-rank {
    background: linear-gradient(135deg, #cd7f32, #a0522d);
    color: #fff;
}

.lb-info {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.lb-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lb-role {
    font-size: 0.7rem;
    color: var(--primary);
    opacity: 0.8;
}

.lb-xp {
    font-weight: 800;
    color: var(--secondary);
    font-size: 0.9rem;
    text-shadow: 0 0 5px rgba(179, 136, 255, 0.3);
    white-space: nowrap;
}

@media (max-width: 1000px) {
    body {
        flex-direction: column;
        justify-content: flex-start;
        align-items: center;
        /* Garantit le centrage horizontal des enfants */
        overflow-y: auto;
        height: auto;
        min-height: 100vh;
        padding: 5.5rem 1rem 3rem 1rem;
    }

    /* Centrage du badge utilisateur sur mobile */
    #user-badge-top {
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%);
        width: fit-content;
        max-width: 95%;
        white-space: nowrap;
        margin: 0 auto;
    }

    .scene-overlay {
        height: auto;
        min-height: unset;
        width: 100%;
        max-width: 500px;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-bottom: 2rem;
    }

    .glass-card {
        width: 100%;
        max-width: 500px;
    }

    .leaderboard-panel {
        position: relative;
        right: auto;
        top: auto;
        transform: none;
        width: 100%;
        max-width: 500px;
        margin: 0 auto;
        max-height: 500px;
        animation: none;
        /* Removed horizontal slide animation for mobile */
    }
}

/* Responsive pour mobiles plus petits */
@media (max-width: 600px) {
    body {
        padding: 6rem 0.8rem 2rem 0.8rem;
    }

    #user-badge-top {
        padding: 6px 12px 6px 8px !important;
        font-size: 0.85rem !important;
        width: 90%;
        /* Prend plus de place sur petit écran pour éviter le wrap */
        justify-content: center;
    }

    .glitch-title {
        font-size: 2.2rem;
    }

    .glass-card {
        padding: 2rem 1.2rem;
        max-width: 400px;
    }

    .leaderboard-panel {
        max-width: 400px;
        padding: 1.2rem;
    }

    .difficulty-selector {
        grid-template-columns: 1fr;
    }

    .diff-card {
        flex-direction: row;
        justify-content: space-between;
        padding: 15px 25px;
    }

    .diff-card i {
        margin-bottom: 0;
        margin-right: 10px;
    }
}

/* --- ADDED FOR PSEUDONYM SETTING --- */
.setting-input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 15px;
    margin-bottom: 25px;
}

.setting-input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 12px 16px;
    color: #fff;
    font-family: var(--font-main);
    font-size: 0.95rem;
    transition: all 0.3s;
}

.setting-input:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 10px rgba(0, 242, 254, 0.2);
}

.setting-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: rgba(255, 255, 255, 0.02);
}

.setting-info {
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.4);
    margin-top: 4px;
    line-height: 1.4;
}

.setting-label {
    font-weight: 600;
    font-size: 0.9rem;
    color: #fff;
    font-family: var(--font-title);
    display: flex;
    align-items: center;
    gap: 8px;
}