/* ==========================================================================
   JEU : RECONNAISSANCE DE COULEUR
   ========================================================================== */

.memory-container {
    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;
    cursor: pointer;
}

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

.icon-btn,
.settings-btn,
.icon-btn svg,
.settings-btn svg,
.back-btn,
.back-btn svg {
    transition: none !important;
    animation: none !important;
}

#status-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 10;
    cursor: pointer;
}

#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; }

.blurred { filter: blur(10px); opacity: 0.3; pointer-events: none; }

/* --- Zone centrale --- */
/* UTILISATION DE CSS GRID POUR SUPERPOSER PARFAITEMENT LES PHASES */
.couleur-game-wrapper {
    flex-grow: 1;
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    place-items: center; 
    min-height: 0;
}

.couleur-phase {
    grid-column: 1 / -1;
    grid-row: 1 / -1;
    width: 100%;
    max-width: 800px;
    height: 100%; 
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 1rem 0;
}

.couleur-phase.hidden {
    display: none !important;
}

.time-instruction {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 0.75rem;
}

/* Phase 1 : Mémorisation */
.target-color-block {
    width: 100%;
    max-width: 500px;
    aspect-ratio: 1 / 1;
    border-radius: var(--radius-md);
    border: 2px solid var(--border-color);
    box-shadow: var(--shadow-card);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.couleur-phase-hint {
    font-family: var(--font-body);
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    line-height: 1.4;
    max-width: 340px;
}

/* Phase 2 : Picker 2D */
.inline-color-picker.couleur-inline-picker {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
    max-width: 100%;
    flex: 1;
    align-items: stretch;
}

.game-map-2d {
    width: 100%;
    flex: 1; 
    min-height: 200px;
    position: relative;
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewbox='0 0 16 16'%3E%3Cg stroke='%23ffffff' stroke-width='2'%3E%3Cline x1='8' y1='0' x2='8' y2='16'/%3E%3Cline x1='0' y1='8' x2='16' y2='8'/%3E%3C/g%3E%3C/svg%3E") 8 8, crosshair;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
    box-shadow: var(--shadow-card);
}

.overlay-white {
    position: absolute; inset: 0;
    background: linear-gradient(to bottom, #ffffff 0%, rgba(255,255,255,0) 50%);
    pointer-events: none;
}

.overlay-black {
    position: absolute; inset: 0;
    background: linear-gradient(to top, #000000 0%, rgba(0,0,0,0) 50%);
    pointer-events: none;
}

/* --- Réticules Précis (Croix fines) --- */
.picker-cursor, .target-cursor {
    width: 16px;
    height: 16px;
    position: absolute;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 10;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    filter: drop-shadow(0 0 2px rgba(0,0,0,0.8));
}

.picker-cursor.hidden {
    display: none !important;
}

/* Ligne horizontale */
.picker-cursor::before, .target-cursor::before {
    content: '';
    position: absolute;
    top: 7px; left: -2px; right: -2px; height: 2px;
    background: #ffffff;
    box-shadow: 0 0 1px rgba(0,0,0,0.4); 
}

/* Ligne verticale */
.picker-cursor::after, .target-cursor::after {
    content: '';
    position: absolute;
    top: -2px; bottom: -2px; left: 7px; width: 2px;
    background: #ffffff;
    box-shadow: 0 0 1px rgba(0,0,0,0.4);
}

.target-cursor {
    z-index: 9;
    animation: pulse-target 1.5s infinite;
}

/* Cible distincte en blanc */
.target-cursor::before, .target-cursor::after {
    background: #ffffff;
    box-shadow: 0 0 2px rgba(0,0,0,0.8); /* Ombre plus forte pour le différencier de la croix normale */
}

.target-cursor.hidden {
    display: none !important;
}

@keyframes pulse-target {
    0% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.15); }
    100% { transform: translate(-50%, -50%) scale(1); }
}

/* Ligne SVG de distance */
.distance-line-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 8;
    pointer-events: none;
}
.distance-line-svg.hidden {
    display: none !important;
}
.distance-line {
    stroke: #ffffff;
    stroke-width: 2.5;
    stroke-dasharray: 3, 4; 
    filter: drop-shadow(0px 1px 2px rgba(0,0,0,0.8));
    opacity: 0.8;
}

/* --- Astuce pour préserver la taille du bloc "Deviner" lors du Feedback --- */
#phase-pick .time-instruction[style*="none"] {
    display: block !important;
    visibility: hidden !important;
}

.color-result-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    transition: opacity 0.2s ease, visibility 0.2s ease; 
}
.color-result-group.hidden {
    display: flex !important;
    visibility: hidden !important;
}

.couleur-preview-choice {
    width: 80px;
    height: 80px;
    align-self: center;
    border-radius: var(--radius-md);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    border: 2px solid var(--border-color);
}

/* --- Bouton de validation --- */
.validate-btn-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0 10px; 
}

.validate-btn-wrapper .hidden {
    display: none !important;
}

.couleur-validate-btn {
    width: 100%;
    max-width: 280px;
    height: 100%;
    min-height: 72px;
    padding: 0 1.5rem;
    font-size: 1.25rem;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

#phase-pick {
    cursor: default;
}

/* --- Écran de distance (Positionné au-dessus de l'espace vide) --- */
#phase-feedback {
    position: absolute;
    bottom: 4rem; 
    left: 0;
    right: 0;
    margin: 0 auto; 
    flex: none; 
    height: auto;
    z-index: 50;
    padding: 0;
}

#phase-feedback .time-instruction {
    margin-bottom: 0.25rem;
}

.feedback-distance {
    font-family: var(--font-heading);
    font-size: 3rem;
    font-weight: 700;
    color: var(--accent-color);
    line-height: 1;
    margin: 0.25rem 0 0.5rem;
}

.couleur-continue-hint {
    font-size: 1rem;
    margin-top: 0.25rem;
    margin-bottom: 0;
}

/* --- Header : score + barre de vie --- */
.game-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.score-box {
    flex-direction: column;
    width: 72px;
    height: 72px;
    min-width: 72px;
    flex-shrink: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

.label-small {
    font-size: 0.6rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    font-weight: 700;
    margin-bottom: 2px;
}

.stat-box {
    font-family: var(--font-heading);
    color: var(--text-primary);
    font-size: 1.5rem;
    font-weight: 500;
    line-height: 1;
}

.gauge-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-grow: 1;
    width: 100%;
    max-width: 500px;
    margin: 0 2rem;
}

.gauge-label {
    width: 100%;
    display: flex;
    justify-content: space-between;
    font-family: var(--font-heading);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

#gauge-value-text {
    color: var(--text-primary);
}

.gauge-bar-wrapper {
    width: 100%;
    height: 20px;
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    overflow: hidden;
    position: relative;
}

.gauge-bar-fill {
    height: 100%;
    width: 100%;
    background-color: var(--accent-color);
    transition: width 0.3s ease-out, background-color 0.3s ease-out;
}

.game-actions-row {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: auto;
    margin-bottom: 0;
}

.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; }

.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;
}

select.settings-select,
#couleur-life-pool,
#sandbox-memorize-ms {
    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: 1rem;
    cursor: pointer;
    outline: none;
    width: 100%;
}

#sandbox-memorize-ms { cursor: text; }

select.settings-select:focus,
#couleur-life-pool:focus,
#sandbox-memorize-ms: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%); }

.history-chart {
    display: flex;
    align-items: stretch;
    justify-content: center;
    gap: 16px;
    height: 120px;
    width: max-content;
    max-width: 100%;
    margin: 0 auto;
    padding: 0 60px;
    border-bottom: 2px solid var(--border-color);
    overflow-x: auto;
    scrollbar-width: none;
}

.history-chart::-webkit-scrollbar { display: none; }

.history-bar-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
    position: relative;
    flex-shrink: 1;
}

.history-bar {
    width: 45px;
    background-color: var(--accent-color-secondary);
    opacity: 0.8;
    border-radius: 6px 6px 0 0;
    position: relative;
    transition: none !important;
}

.bar-label {
    font-size: 0.85rem;
    font-family: var(--font-body);
    color: var(--text-primary);
    margin-bottom: 6px;
    font-weight: 600;
}

.bar-index {
    position: absolute;
    top: 100%;
    margin-top: 6px;
    font-size: 0.8rem;
    font-family: var(--font-heading);
    color: var(--text-secondary);
}

.results-view { width: 100%; display: flex; flex-direction: column; align-items: center; }
.results-view.hidden { display: none !important; }

.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);
}

.score-unit {
    font-size: 1.4rem;
    color: var(--accent-color);
    margin-left: 8px;
    font-family: var(--font-heading);
    font-weight: 500;
}

.sandbox-stats {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem;
    margin: 1.5rem 0 2rem 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);
}

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

/* ==========================================================================
   GRAPHIQUE DISTRIBUTION (RANKED)
   ========================================================================== */

.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); }

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

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

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

@media (max-width: 900px) {
    .status-main-text { font-size: 5rem; }
}

@media (max-width: 700px) {
    .score-box {
        width: 60px !important;
        height: 60px !important;
        min-width: unset !important;
        padding: 0 !important;
    }

    .label-small { font-size: 0.5rem; margin-bottom: 1px; }
    .stat-box { font-size: 1.2rem; }

    body.game-page { overscroll-behavior: none; }

    #settings-panel {
        touch-action: auto;
        overscroll-behavior: contain;
    }

    .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;
    }

    .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;
    }

    #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;
    }

    .game-page .game-board:fullscreen .memory-container,
    .ios-fullscreen .memory-container {
        padding-top: 3rem !important;
        padding-bottom: 2rem !important;
    }

    .status-main-text { font-size: 4rem; }
    .status-sub-text { font-size: 0.9rem; flex-wrap: wrap; }

    .gauge-display { max-width: none; margin: 0 1rem; }
    .gauge-bar-wrapper { height: 16px; }

    .res-value.big { font-size: 4.5rem; }
    .score-unit { font-size: 1.2rem; }
    .distribution-chart-container { height: 140px; margin-top: 1.5rem; margin-bottom: 2.5rem; }

    #phase-feedback {
        bottom: 2.5rem; 
    }

    .feedback-distance {
        font-family: var(--font-heading);
        font-size: 2.5rem;
        font-weight: 700;
        color: var(--accent-color);
        line-height: 1.2;
        margin: 0.25rem 0 0.5rem;
    }

    .inline-color-picker.couleur-inline-picker {
        gap: 1rem; 
    }

    .game-map-2d { height: 250px; }
    
    .couleur-preview-choice { 
        width: 72px; 
        height: 72px; 
    }

    .history-chart { gap: 8px; height: 100px; padding: 0 40px; }
    .history-bar { width: 35px; }

    .couleur-validate-btn {
        min-height: 60px;
        font-size: 1.1rem;
        padding: 0 1rem;
    }
}

/* ==========================================================================
   FULLSCREEN DESKTOP TWEAKS & ÉLARGISSEMENT
   ========================================================================== */

@media (min-width: 701px) {
    .couleur-phase {
        max-width: 900px;
    }
    .inline-color-picker.couleur-inline-picker {
        max-width: 800px;
    }
    .couleur-preview-choice {
        width: 96px;
        height: 96px;
    }
    .game-board:fullscreen .couleur-phase {
        max-width: 1200px;
    }
    .game-board:fullscreen .inline-color-picker.couleur-inline-picker {
        max-width: 1000px;
    }
    .game-board:fullscreen .target-color-block {
        max-width: 600px;
    }
    .game-board:fullscreen .game-map-2d {
        height: 450px;
    }
    .game-board:fullscreen .couleur-preview-choice {
        width: 120px;
        height: 120px;
    }
}

/* ==========================================================================
   FALLBACK PLEIN ECRAN (BULLDOZER)
   ========================================================================== */

.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; }

.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;
}