/* ==========================================================================
   JEU : TARGET AIMING (STYLE SPECIFIQUE - MODES CLASSE ET LIBRE)
   ========================================================================== */

/* --- 1. LAYOUT PRINCIPAL --- */
.math-container.aim-layout {
    width: 100%; 
    height: 100%;
    padding: 1.5rem; 
    display: flex; 
    flex-direction: column; 
    justify-content: space-between; 
    align-items: center;
    position: relative; 
    z-index: 2;
    transition: opacity 0.3s ease;
}

#game-over-overlay.visible ~ .math-container { opacity: 0; pointer-events: none; }

.hint-pause { 
    position: absolute;
    bottom: 5px;      
    left: 0; 
    width: 100%;
    font-size: 0.75rem; 
    color: var(--text-secondary); 
    opacity: 0.4;     
    text-align: center; 
    pointer-events: none; 
    margin: 0;
}

.overlay.visible ~ .math-container .hint-pause { opacity: 0; }
.blurred { filter: blur(10px); opacity: 0.3; pointer-events: none; transition: filter 0.3s ease, opacity 0.3s ease; }

/* FIX : Forcer l'annulation des transitions globales sur les boutons tactiques et leurs icônes */
.icon-btn, 
.settings-btn, 
.icon-btn svg, 
.settings-btn svg,
.back-btn,
.back-btn svg {
    transition: none !important;
    animation: none !important;
}

/* --- OVERLAY DE STATUT (PRÊT ?) --- */
#status-overlay {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 10;
    pointer-events: none; /* Laisse passer les clics vers le workspace */
}
#status-overlay.hidden { display: none !important; opacity: 0; }

.status-main-text {
    font-family: var(--font-heading); 
    font-size: 5.5rem; 
    font-weight: 500; 
    color: var(--text-primary); 
    letter-spacing: -4px; 
    line-height: 1; 
    transition: opacity 0.2s;
}

.status-sub-text {
    display: flex; align-items: center; justify-content: center;
    gap: 10px; margin-top: 1.5rem;
    font-family: var(--font-body); font-size: 1.1rem;
    color: var(--text-secondary); font-weight: 500;
    text-transform: uppercase; letter-spacing: 1px;
}

.status-sub-text svg {
    width: 24px; height: 24px;
    color: var(--text-primary); 
}

.game-board:fullscreen .status-main-text { font-size: 8.5rem; }
.game-board:fullscreen .status-sub-text { font-size: 1.5rem; margin-top: 2rem; }
.game-board:fullscreen .status-sub-text svg { width: 32px; height: 32px; }

/* --- 2. HEADER & TIMER --- */
.game-header {
    padding: 0; 
    margin-bottom: 0;
    flex-shrink: 0; 
    width: 100%;
}

.timer-display {
    display: flex; align-items: center; gap: 12px; 
    height: 100%; font-size: 2.5rem; 
    min-width: 110px; justify-content: center; padding: 0 15px; 
    font-family: var(--font-heading); font-weight: 400;
    color: var(--accent-color); font-variant-numeric: tabular-nums; 
}
.timer-display svg { width: 48px; height: 48px; stroke: none; overflow: visible; }
.timer-text { padding-top: 8px; white-space: nowrap; }

.timer-danger { 
    color: inherit !important; 
    animation: none !important; 
}

/* --- 3. ESPACE DE JEU (Aim Workspace) --- */
.workspace-container.aim-workspace {
    flex-grow: 1; 
    width: 100%;
    margin: 1rem 0; 
    position: relative;
    overflow: hidden; 
    padding: 0;
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    background-color: color-mix(in srgb, var(--card-bg), transparent 50%);
    transition: filter 0.3s ease, opacity 0.3s ease;
    
    /* On cache le curseur natif pour utiliser le custom */
    cursor: none;
    
    /* ANTI-CHEAT: Bloque le pinch-to-zoom et le double-tap sur iOS et autres mobiles */
    touch-action: none;
}

/* --- CURSEUR PERSONNALISÉ (HTML/SVG Dynamique) --- */
/* Variable par défaut, mise à jour par JS */
:root {
    --cursor-size: 4px; 
}

.custom-cursor {
    position: fixed; 
    top: 0;
    left: 0;

    width: calc(var(--cursor-size) * 4);
    height: calc(var(--cursor-size) * 4);
    
    /* Couleur dynamique héritée par le SVG via currentColor */
    color: var(--text-primary); 
    
    pointer-events: none; 
    transform: translate(-50%, -50%);
    z-index: 9999;
    
    /* Caché par défaut, affiché via JS quand on est sur le workspace */
    display: none; 
}

/* Mode 1 : Croix (Par défaut) - Le SVG est visible */
.custom-cursor svg {
    display: block;
    width: 100%;
    height: 100%;
}

/* Mode 2 : Point (Dot) - On cache le SVG et on crée un rond */
.custom-cursor.cursor-dot {
    width: var(--cursor-size);
    height: var(--cursor-size);
    background-color: var(--text-primary);
    border-radius: 50%;
    /* Petit contour pour bien le voir sur fond sombre/clair */
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2); 
}

.custom-cursor.cursor-dot svg {
    display: none;
}

/* ==========================================================================
   UI PARTAGÉE (OVERLAYS, TOGGLE, COURBE DE GAUSS, SETTINGS)
   ========================================================================== */
.input-select {
    background: var(--bg-main, #2a2a2a);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px;
    border-radius: var(--radius-md, 4px);
    font-family: var(--font-body, sans-serif);
    font-size: 0.9rem;
    outline: none;
    cursor: pointer;
    min-width: 150px; 
    text-align: left;
}

.input-select:focus { border-color: var(--accent-color); box-shadow: 0 0 0 2px var(--accent-glow); }

.mode-switch-wrapper {
    display: flex; position: relative; background-color: var(--bg-main);
    border: 1px solid var(--border-color); border-radius: var(--radius-md);
    padding: 4px; margin-bottom: 1.5rem;
}
.mode-switch-wrapper input[type="radio"] { display: none; }
.mode-switch-wrapper label {
    flex: 1; text-align: center; padding: 10px 0; font-family: var(--font-heading); font-weight: 600; font-size: 0.9rem;
    color: var(--text-secondary); cursor: pointer; z-index: 2; margin: 0; transition: color 0.3s ease; text-transform: uppercase; letter-spacing: 1px;
}
.mode-switch-wrapper input:checked + label { color: var(--text-primary); }
.mode-slider {
    position: absolute; top: 4px; bottom: 4px; width: calc(50% - 4px);
    background-color: var(--card-bg); border-radius: 6px; z-index: 1;
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1); box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.mode-switch-wrapper input[value="sandbox"]:checked ~ .mode-slider { transform: translateX(100%); }

.setting-row.skin-row {
    margin-top: 15px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}
.setting-row.skin-row label {
    align-self: flex-start;
    margin-bottom: 8px;
    width: 100%;
}

/* --- VUES DE RÉSULTATS --- */
.results-view { width: 100%; display: flex; flex-direction: column; align-items: center; }
.results-view.hidden { display: none !important; }

#game-over-overlay .overlay-content { justify-content: center; gap: 1.5rem; }

.centered-score-item { text-align: center; margin-bottom: 3rem; }
.centered-score-item .res-label { font-size: 1.2rem; font-weight: 600; text-transform: uppercase; letter-spacing: 2px; opacity: 0.7; display: block; margin-bottom: 0.8rem; }
.big-score-container { display: flex; align-items: baseline; justify-content: center; position: relative; }
.res-value.big { 
    font-size: 5.5rem; font-weight: 700; line-height: 1; font-family: var(--font-heading); color: var(--accent-color);
}

/* --- STATS SANDBOX --- */
.sandbox-stats {
    display: flex; flex-wrap: wrap; justify-content: center; gap: 1rem; 
    margin: 1.5rem 0 0.5rem 0; width: 100%; max-width: 600px;
}
.stat-box-small {
    background: transparent; border: 1px solid var(--border-color); padding: 12px 20px;
    border-radius: var(--radius-md); display: flex; flex-direction: column; align-items: center; min-width: 120px;
}
.stat-title { font-family: var(--font-heading); font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 5px; }
.stat-value { font-family: var(--font-heading); font-size: 1.4rem; font-weight: 600; color: var(--text-primary); }

.full-width-item {
    grid-column: 1 / -1;
    display: flex; flex-direction: column; align-items: center; width: 100%;
}
.precision-visualizer {
    margin-top: 15px;
    width: 200px; height: 200px;
    position: relative;
    display: flex; align-items: center; justify-content: center;
}
.analysis-target {
    width: 100%; height: 100%;
    border-radius: 50%;
    border: 2px solid var(--text-secondary);
    background: transparent;
    position: relative;
    overflow: hidden;
}
.analysis-center {
    position: absolute;
    top: 50%; left: 50%;
    width: 4px; height: 4px;
    background: var(--text-primary);
    border-radius: 50%;
    transform: translate(-50%, -50%);
}
.impact-point {
    position: absolute;
    width: 6px; height: 6px;
    background-color: var(--accent-color);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    opacity: 0.8;
}

/* --- GRAPHIQUE COURBE DE GAUSS --- */
.distribution-chart-container {
    position: relative; width: 100%; max-width: 650px; height: 180px;
    margin: 1.5rem 0 2rem 0;
    border-bottom: 2px solid var(--border-color); cursor: crosshair;
}
.curve-svg { width: 100%; height: 100%; overflow: visible; }
.axis-label { position: absolute; bottom: -25px; font-family: var(--font-body); font-size: 0.8rem; color: var(--text-secondary); }
.axis-label.left { left: 0; }
.axis-label.right { right: 0; }
.hover-line { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--text-primary); transform: translateX(-50%); pointer-events: none; opacity: 0.3; z-index: 3; transition: opacity 0.2s ease; }
.chart-tooltip { position: absolute; top: -55px; transform: translateX(-50%); background: var(--card-bg); border: 1px solid var(--border-color); padding: 6px 12px; border-radius: var(--radius-md); font-family: var(--font-body); font-size: 0.9rem; color: var(--text-primary); pointer-events: none; white-space: nowrap; z-index: 10; box-shadow: var(--shadow-card); text-align: center; line-height: 1.4; transition: opacity 0.2s ease, visibility 0.2s ease; }
.hover-line.hidden, .chart-tooltip.hidden { opacity: 0 !important; visibility: hidden !important; }
.score-marker { position: absolute; top: 0; bottom: 0; display: flex; flex-direction: column; align-items: center; transform: translateX(-50%); pointer-events: none; transition: left 0.5s ease-out; }
.marker-line { width: 2px; height: 100%; border-left: 2px dashed currentColor; }
.marker-label { position: absolute; font-family: var(--font-heading); font-size: 0.8rem; font-weight: 700; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; white-space: nowrap; }
.marker-current { color: var(--accent-color); z-index: 2; }
.marker-current .marker-label { bottom: 100%; margin-bottom: 5px; background: var(--bg-main); border: 1px solid currentColor;}
.marker-best { color: var(--text-tertiary); z-index: 1; opacity: 1;}
.marker-best .marker-label { top: 100%; margin-top: 5px; color: var(--text-secondary); }

#restart-btn { margin-top: 2rem; } 

/* ==========================================================================
   STYLES DES SKINS DE CIBLE ET MENU
   ========================================================================== */

/* --- BASE COMMUNE POUR TOUTES LES CIBLES --- */
.aim-target {
    /* CALCUL DYNAMIQUE DE L'EPAISSEUR */
    --line-thick: clamp(1px, calc(var(--target-diameter) * 0.04), 4px);

    position: absolute;
    box-sizing: border-box;
    cursor: inherit;
    user-select: none;
    
    display: flex;
    align-items: center;
    justify-content: center;

    border-radius: 50%;
    border: var(--line-thick) solid var(--accent-color);
    
    background-color: color-mix(in srgb, var(--accent-color), transparent 85%);
    
    transform: scale(0);
    animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* --- SKIN 2 : CONTOUR + POINT FIN (.skin-smalldot) --- */
.aim-target.skin-smalldot::before {
    content: '';
    width: max(2px, calc(var(--line-thick) * 1.5));
    height: max(2px, calc(var(--line-thick) * 1.5));
    background-color: var(--accent-color);
    border-radius: 50%;
}

/* --- SKIN 3 : VISEUR SIMPLE (.skin-reticle) --- */
.aim-target.skin-reticle::before,
.aim-target.skin-reticle::after {
    content: '';
    position: absolute;
    background-color: var(--accent-color);
}
.aim-target.skin-reticle::before { width: 100%; height: var(--line-thick); }
.aim-target.skin-reticle::after { width: var(--line-thick); height: 100%; }

/* --- SKIN 4 : VISEUR + CERCLE CONCENTRIQUE (.skin-reticle_circle) --- */
.aim-target.skin-reticle_circle::before {
    content: '';
    position: absolute;
    width: 50%;
    height: 50%;
    border-radius: 50%;
    border: var(--line-thick) solid var(--accent-color);
    box-sizing: border-box;
    z-index: 2;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.aim-target.skin-reticle_circle::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background: 
        linear-gradient(to right, 
            transparent calc(50% - (var(--line-thick) / 2)), 
            var(--accent-color) calc(50% - (var(--line-thick) / 2)), 
            var(--accent-color) calc(50% + (var(--line-thick) / 2)), 
            transparent calc(50% + (var(--line-thick) / 2))
        ),
        linear-gradient(to bottom, 
            transparent calc(50% - (var(--line-thick) / 2)), 
            var(--accent-color) calc(50% - (var(--line-thick) / 2)), 
            var(--accent-color) calc(50% + (var(--line-thick) / 2)), 
            transparent calc(50% + (var(--line-thick) / 2))
        );
}


/* --- ANIMATIONS --- */
@keyframes popIn {
    to { transform: scale(1); }
}

.aim-target.hit {
    animation: popOut 0.1s ease-in forwards;
    pointer-events: none;
    background-color: var(--accent-color) !important;
    opacity: 0.8;
}

@keyframes popOut {
    to { transform: scale(1.4); opacity: 0; }
}


/* --- 5. ACTIONS (FOOTER) --- */
.game-actions-row {
    padding: 0; 
    margin: 0;
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    width: 100%;
}

/* --- ANIMATION FEEDBACK PAUSE --- */
.workspace-container.aim-workspace.blurred {
    pointer-events: auto !important; 
    cursor: default; 
}

.icon-btn.flash-alert {
    color: var(--accent-color-secondary) !important;
    transform: scale(1.2);
    transition: all 0.1s ease-in-out;
}

html.global-opaque .workspace-container.aim-workspace { background-color: var(--card-bg); }

/* --- STYLE DES SLIDERS (DESIGN SETTINGS) --- */

.slider {
    -webkit-appearance: none; 
    appearance: none;
    flex: 1; 
    width: 100%; 
    height: 24px !important; 
    border-radius: 6px; 
    cursor: pointer; 
    outline: none; 
    margin: 0;
    background-color: transparent; 
    background-image: linear-gradient(to right, 
        var(--accent-color) 0%, 
        var(--accent-color) var(--val-percent, 0%), 
        var(--dot-color, rgba(125,125,125,0.2)) var(--val-percent, 0%), 
        var(--dot-color, rgba(125,125,125,0.2)) 100%);
    background-size: 100% 6px; 
    background-repeat: no-repeat; 
    background-position: center; 
    position: relative; 
    z-index: 2; 
}

/* Thumb (Le bouton) - Chrome/Safari */
.slider::-webkit-slider-thumb {
    -webkit-appearance: none; 
    appearance: none;
    width: 20px; 
    height: 20px;
    background: #ffffff; 
    border: 2px solid var(--accent-color);
    border-radius: 6px;
    cursor: grab;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    transition: transform 0.2s cubic-bezier(0.3, 1.5, 0.7, 1), background 0.2s;
    margin-top: 0 !important; 
}

/* Thumb - Firefox */
.slider::-moz-range-thumb {
    width: 20px; 
    height: 20px;
    background: #ffffff; 
    border: 2px solid var(--accent-color);
    border-radius: 6px; 
    cursor: grab;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    transition: transform 0.2s cubic-bezier(0.3, 1.5, 0.7, 1);
    box-sizing: border-box;
}

/* États Interactifs */
.slider:hover::-webkit-slider-thumb { 
    transform: scale(1.1); 
}

.slider:active::-webkit-slider-thumb { 
    cursor: grabbing; 
    transform: scale(0.9); 
    background: var(--accent-color); 
    border-color: #ffffff; 
}

.slider:active::-moz-range-thumb { 
    cursor: grabbing; 
    transform: scale(0.9); 
    background: var(--accent-color); 
    border-color: #ffffff; 
}

.slider-container {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
    width: 100%;
}

.slider-value-badge {
    font-family: var(--font-heading, sans-serif);
    font-weight: 600;
    color: var(--text-primary);
    min-width: 45px;
    text-align: right;
    font-size: 1rem;
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-color, #444);
}

/* Rend l'input invisible et désactive tous les styles globaux */
.slider-value-badge input[type="number"] {
    all: unset;
    display: inline-block;
    box-sizing: border-box;
    background: transparent !important;
    border: none !important;
    border-bottom: 1px solid transparent !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
    color: inherit;
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
    text-align: right;
    width: 2.5ch !important; 
    min-width: 0 !important;
    max-width: 3ch !important;
    transition: border-color 0.2s;
    -moz-appearance: textfield;
    appearance: textfield;
}

.slider-value-badge input[type="number"]:focus {
    border-bottom: 1px solid var(--accent-color);
}

.slider-value-badge input[type="number"]::-webkit-outer-spin-button,
.slider-value-badge input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}


/* ==========================================================================
   Bouton pour quitter le plein écran (Fix d'affichage global)
   ========================================================================== */
.exit-fs-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: none; 
    padding: 8px;
    z-index: 10000;
    transition: color var(--transition-fast);
}
.exit-fs-btn svg { width: 32px; height: 32px; }
.exit-fs-btn:hover { color: var(--accent-color-secondary); }
.game-board:fullscreen .exit-fs-btn { display: block; }
.ios-fullscreen .exit-fs-btn { display: block !important; }

/* ==========================================================================
   RESPONSIVE SPÉCIFIQUE & FALLBACK PLEIN ECRAN
   ========================================================================== */

/* Layout d'étirement global (Desktop et Mobile) */
.game-page .main-content {
    display: flex;
    flex-direction: column;
}

.game-board {
    flex: 1 0 auto; 
    display: flex;
    flex-direction: column;
    min-height: 600px;
    margin-bottom: 0 !important; 
}

#game-over-overlay .overlay-content {
    height: auto;
    min-height: 100%;
    padding: 4rem 0; 
}

@media (max-width: 900px) {
    .math-container.aim-layout { padding: 1rem; }
    .timer-display { font-size: 2rem; }
    .timer-display svg { width: 40px; height: 40px; }
    .status-main-text { font-size: 4rem; }
}

@media (max-width: 700px) {
    .res-value.big { font-size: 4.5rem; }
    .distribution-chart-container { height: 140px; margin-top: 1.5rem; margin-bottom: 2.5rem; }
    #restart-btn { margin-top: 1rem; }
    .sandbox-stats { gap: 0.5rem; margin: 1.5rem 0 1rem 0; flex-direction: column; align-items: center; }
    .stat-box-small { padding: 10px; min-width: 100px; }
    .stat-value { font-size: 1.2rem; }
    .status-main-text { font-size: 3.5rem; }
    .status-sub-text { font-size: 0.9rem; flex-wrap: wrap; }
    
    body.game-page { overscroll-behavior: none; }
    #settings-panel { touch-action: auto; overscroll-behavior: contain; }

    /* FIX 1 : Main Content aligné en HAUT (Mobile) */
    .game-page .main-content {
        display: flex !important;
        flex-direction: column !important;
        justify-content: flex-start !important; 
        height: auto !important; 
        min-height: calc(100svh - 80px) !important;
        padding-top: 80px !important;
        padding-bottom: 0 !important; 
        padding-left: 0 !important; 
        padding-right: 0 !important;
    }

    /* FIX 2 : Plateau remplit tout jusqu'au footer */
    .game-board { 
        flex: 1 1 100% !important;     
        display: flex !important;      
        flex-direction: column !important; 
        height: auto !important;
        min-height: calc(100svh - 80px) !important; 
        max-height: none !important;
        margin: 0 !important;          
        border-radius: 0;              
    }

    /* FIX 3 : Overlay de fin avec padding réel (Scroll possible si petit écran) */
    #game-over-overlay { overflow-y: auto !important; }
    #game-over-overlay .overlay-content {
        height: auto !important;
        min-height: 100% !important;
        padding: 4rem 0 3rem 0 !important; 
        justify-content: center !important;
        gap: 2.5rem !important;
    }

    /* Ajustement du padding quand on passe en plein écran ou faux plein écran */
    .game-page .game-board:fullscreen .math-container.aim-layout,
    .ios-fullscreen .math-container.aim-layout {
        padding-top: 3rem !important; 
        padding-bottom: 2rem !important;
    }
    #custom-cursor {
        display: none !important;
    }
    /* On s'assure de rétablir un comportement normal pour le workspace sur mobile */
    .workspace-container.aim-workspace {
        cursor: crosshair; 
    }
}

/* Fullscreen Natif PC : Fixe les bases */
.game-board:fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
    border-radius: 0 !important;
    border: none !important;
    background-color: var(--bg-main);
    display: flex !important;
    flex-direction: column !important;
}

.ios-fullscreen {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    max-width: none !important;
    max-height: none !important;
    z-index: 9999 !important;
    border-radius: 0 !important;
    border: none !important;
    background-color: var(--bg-main) !important;
    display: flex !important;
    flex-direction: column !important;
}

.ios-fullscreen .exit-fs-btn { display: block !important; }
.ios-fullscreen ~ * #icon-expand { display: none !important; }
.ios-fullscreen ~ * #icon-compress { display: block !important; }


/* ==========================================================================
   AFFICHAGE DU NOUVEAU RECORD
   ========================================================================== */
.new-record, 
#new-record-msg {
    color: var(--record-color, #FFA914) !important;
}

.new-record svg {
    color: var(--record-color, #FFA914) !important;
}

.input-select, select {
    background-color: var(--bg-main); color: var(--text-primary);
    border: 1px solid var(--border-color); padding: 8px; border-radius: var(--radius-md);
    font-family: var(--font-body); font-size: 0.95rem; cursor: pointer; outline: none;
    width: auto; min-width: 140px; max-width: 200px;
    text-align: center;
    text-align-last: center;
}
