/**
 * STIMULUDO ENGINE CSS (v1.2.0)
 * Design System unifié pour tous les jeux Stimuludo.
 * 100% conforme aux styles officiels de Stimuludo.
 */

/* ==========================================================================
   1. STRUCTURE DU CONTENEUR DE JEU (Game Container)
   ========================================================================== */
.game-container {
    width: 100%;
    height: 100%;
    padding: 1.5rem;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    position: relative;
    z-index: 102;
    transition: opacity 0.3s ease;
    cursor: default;
}

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

/* Zone de travail / Arène centrale */
.workspace-container {
    flex-grow: 1;
    width: 100%;
    margin: 0;
    padding: 20px 0 8px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    transition: filter 0.3s ease, opacity 0.3s ease;
    touch-action: manipulation;
}

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

/* ==========================================================================
   2. HUD & SCORE BOX / TIMER
   ========================================================================== */
.score-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    min-width: 72px;
    max-width: 72px;
    flex-shrink: 0;
    gap: 2px;
    padding: 0;
    box-sizing: border-box;
}

.label-small {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    font-weight: 700;
    line-height: 1;
}

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

.timer-display {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 100%;
    font-size: 2.5rem;
    min-width: 110px;
    justify-content: center;
    padding: 0px 15px;
    font-family: var(--font-heading);
    font-weight: 400;
    color: var(--accent-color);
    font-variant-numeric: tabular-nums;
    justify-self: center;
}

.timer-display svg {
    width: 48px;
    height: 48px;
    stroke: none;
    overflow: visible;
}

.timer-text {
    padding-top: 8px;
    white-space: nowrap;
}

@media (max-width: 700px) {
    .timer-display svg {
        width: 40px;
        height: 40px;
    }
}

/* ==========================================================================
   3. ÉCRAN DE PRÉ-DÉMARRAGE & PAUSE (Status Overlay)
   ========================================================================== */
.status-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    z-index: 100;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: opacity 0.2s ease;
    background: transparent;
}

.status-overlay.hidden {
    display: none !important;
    opacity: 0;
    pointer-events: none;
}

.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;
    text-transform: uppercase;
}

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

/* ==========================================================================
   4. PANNEAU DE CONFIGURATION & SLIDER DE MODE
   ========================================================================== */
html.global-opaque #settings-panel,
#settings-panel.opaque-mode {
    background-color: var(--card-bg);
}

.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;
    user-select: none;
}

.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="ranked"]:checked ~ .mode-slider {
    transform: translateX(100%);
}

.mode-switch-wrapper input[value="sandbox"]:checked ~ .mode-slider {
    transform: translateX(0);
}

/* Select & Inputs dans les Paramètres avec Fix Safari / WebKit */
.settings-select,
.input-select,
#settings-panel select,
select {
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
    height: 42px !important;
    min-height: 42px !important;
    max-height: 42px !important;
    background-color: var(--bg-main);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0 32px 0 16px !important;
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    outline: none;
    min-width: 140px;
    max-width: 200px;
    text-align: center;
    text-align-last: center;
    box-sizing: border-box !important;
    display: inline-block;
    vertical-align: middle;
    line-height: 40px !important;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

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


/* ==========================================================================
   5. DISTRIBUTION GAUSSIENNE (KDE) & STATS DE JEU
   ========================================================================== */
.distribution-chart-container {
    width: 100%;
    max-width: 600px;
    height: 180px;
    position: relative;
    margin: 1.5rem auto;
    border-bottom: 2px solid var(--border-color);
    cursor: crosshair;
}

.curve-svg {
    width: 100%;
    height: 100%;
    overflow: visible;
}

.curve-fill {
    fill: var(--accent-color);
    opacity: 0.2;
}

.curve-path {
    fill: none;
    stroke: var(--accent-color);
    stroke-width: 2;
    vector-effect: non-scaling-stroke;
}

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

.score-marker.hidden {
    display: none !important;
}

.marker-current {
    color: var(--accent-color);
    z-index: 2;
}

.marker-best {
    color: var(--record-color, #FFA914);
    z-index: 1;
    opacity: 1;
}

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

.chart-tooltip.hidden {
    display: none !important;
    opacity: 0;
    visibility: hidden;
}

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

.hover-line.hidden {
    display: none !important;
    opacity: 0;
    visibility: hidden;
}

/* ==========================================================================
   6. STATS SANDBOX & HISTORIQUE
   ========================================================================== */
.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;
    flex: 1;
}

.stat-box-small .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-box-small .stat-value {
    font-family: var(--font-heading);
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--text-primary);
}

.history-chart {
    display: flex;
    align-items: stretch;
    justify-content: center;
    gap: 14px;
    height: 120px;
    width: fit-content;
    max-width: 100%;
    margin: 0 auto 1.5rem auto;
    padding: 0 20px;
    border-bottom: 2px solid var(--border-color);
    overflow-x: auto;
    scrollbar-width: none;
    box-sizing: border-box;
}
.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: 0;
    width: 45px;
}

.history-bar {
    width: 100%;
    background-color: var(--accent-color);
    opacity: 0.85;
    border-radius: 6px 6px 0 0;
    position: relative;
    min-height: 4px;
    transition: opacity 0.15s ease, filter 0.15s ease !important;
}

.history-bar-wrapper:hover .history-bar {
    opacity: 1;
    filter: brightness(1.25);
}

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

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

/* --- Palier Medium : 11 à 18 barres (ex: Grille de Schulte 4x4 = 16 barres) --- */
.history-chart.medium-chart {
    height: 120px;
    gap: 8px;
    padding: 0 10px;
    margin: 0 auto 1.5rem auto;
}

.history-chart.medium-chart .history-bar-wrapper {
    flex: 0 0 auto;
}

.history-chart.medium-chart .history-bar {
    width: 100%;
    min-width: 2px;
    border-radius: 5px 5px 0 0;
}

.history-chart.medium-chart .bar-label {
    font-size: 0.72rem;
    margin-bottom: 5px;
    letter-spacing: -0.3px;
}

.history-chart.medium-chart .bar-index {
    display: block;
    position: absolute;
    top: 100%;
    margin-top: 6px;
    font-size: 0.72rem;
    font-family: var(--font-heading);
    color: var(--text-secondary);
}

@media (max-width: 600px) {
    .history-chart.medium-chart {
        gap: 5px;
        padding: 0 4px;
    }
    .history-chart.medium-chart .history-bar {
        width: 100%;
    }
    .history-chart.medium-chart .bar-label {
        font-size: 0.65rem;
    }
    .history-chart.medium-chart .bar-index {
        font-size: 0.65rem;
    }
}

/* --- Palier Large : 19 à 28 barres (ex: Grille de Schulte 5x5 = 25 barres) --- */
.history-chart.large-chart {
    height: 120px;
    gap: 5px;
    padding: 0 10px;
    margin: 0 auto 1.5rem auto;
}

.history-chart.large-chart .history-bar-wrapper {
    flex: 0 0 auto;
}

.history-chart.large-chart .history-bar {
    width: 100%;
    min-width: 2px;
    border-radius: 4px 4px 0 0;
}

.history-chart.large-chart .bar-label {
    font-size: 0.58rem;
    margin-bottom: 5px;
    letter-spacing: -0.4px;
}

.history-chart.large-chart .bar-index {
    display: block;
    position: absolute;
    top: 100%;
    margin-top: 6px;
    font-size: 0.65rem;
    font-family: var(--font-heading);
    color: var(--text-secondary);
}

@media (max-width: 600px) {
    .history-chart.large-chart {
        gap: 3px;
        padding: 0 4px;
    }
    .history-chart.large-chart .history-bar {
        width: 100%;
    }
    .history-chart.large-chart .bar-label {
        font-size: 0.52rem;
        letter-spacing: -0.5px;
    }
    .history-chart.large-chart .bar-index {
        font-size: 0.55rem;
    }
}

/* --- Palier Compact : 29 à 50 barres (ex: Grille de Schulte 6x6 = 36 barres, Target Aiming) --- */
.history-chart.compact-chart {
    width: fit-content;
    max-width: 100%;
    height: 120px;
    gap: 3px;
    padding: 0 10px;
    justify-content: center;
    box-sizing: border-box;
    overflow: visible;
    position: relative;
    margin: 0 auto 1.5rem auto;
}

.history-bar-wrapper.compact {
    flex: 0 0 auto;
    cursor: pointer;
    position: relative;
}

.history-bar-wrapper.compact .history-bar {
    width: 100%;
    min-width: 2px;
    border-radius: 2px 2px 0 0;
}

.history-bar-wrapper.compact .bar-index {
    display: none;
}

.history-bar-wrapper.compact .bar-label {
    display: block;
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    background: var(--bg-card, #1c1d22);
    border: 1px solid var(--border-color, rgba(255,255,255,0.2));
    color: var(--text-primary, #ffffff);
    font-size: 0.72rem;
    font-family: var(--font-heading);
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 50;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

.history-bar-wrapper.compact:hover .bar-label {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.history-bar-wrapper.compact:hover .history-bar {
    opacity: 1;
    filter: brightness(1.3);
}

/* --- Palier Dense : > 50 barres --- */
.history-chart.dense-chart {
    height: 120px;
    gap: 2px;
    padding: 0 6px;
    margin: 0 auto 1.5rem auto;
}

.history-chart.dense-chart .history-bar {
    width: 100%;
    min-width: 2px;
    border-radius: 2px 2px 0 0;
}

.history-chart.dense-chart .bar-index {
    display: none;
}

/* ==========================================================================
   7. RÉSULTATS OVERLAY
   ========================================================================== */
.centered-score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.centered-score-item .res-label,
.res-label,
#score-label {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-secondary);
    opacity: 0.75;
    display: block;
    margin-bottom: 0.8rem;
}

.big-score-container {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 6px;
}

#results-ranked .res-value.big,
#results-sandbox .res-value.big {
    font-family: var(--font-heading);
    font-size: 5rem;
    font-weight: 700;
    line-height: 1;
    color: var(--accent-color);
}

.score-unit {
    font-family: var(--font-heading);
    font-size: 2.2rem;
    font-weight: 600;
    color: var(--accent-color);
    margin-left: 4px;
}

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

.results-view.hidden {
    display: none !important;
}

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

/* ==========================================================================
   8. LIVES DISPLAY (CŒURS / VIES)
   ========================================================================== */
.lives-display {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 8px;
    height: 100%;
    padding-top: 5px;
}

.heart-icon {
    height: 5.5vh;
    width: auto;
    min-height: 40px;
    max-height: 55px;
    overflow: visible !important;
    transition: all 0.3s;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.heart-icon.heart-lost .heart-bg {
    fill: var(--border-color) !important;
}

.heart-icon.heart-lost .heart-overlay {
    fill: transparent !important;
}

.heart-icon.heart-lost {
    opacity: 0.5;
    transform: scale(0.9);
    filter: none;
}

.lives-display .lives-count {
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
    align-self: center;
}

/* ==========================================================================
   9. RESPONSIVE POUR TOUS LES JEUX
   ========================================================================== */
@media (max-width: 900px) {
    .status-main-text { font-size: 5rem; }
}

@media (max-width: 700px) {
    .score-box {
        width: 60px !important;
        height: 60px !important;
        min-width: 60px !important;
        max-width: 60px !important;
        padding: 0 !important;
    }
    .game-container {
        padding: 1rem !important;
    }
    .status-main-text { font-size: 4rem; }
    .status-sub-text { font-size: 0.9rem; flex-wrap: wrap; }
    .stat-box { font-size: 1.5rem; }
    #results-ranked .res-value.big, #results-sandbox .res-value.big { font-size: 3.5rem; }
    .score-unit { font-size: 1.2rem; }
    .distribution-chart-container { height: 140px; margin-top: 1.5rem; margin-bottom: 2.5rem; }

    .sandbox-stats { gap: 0.5rem; margin: 1.5rem 0 2rem 0; flex-direction: column; align-items: center; }
    .stat-box-small { padding: 10px; min-width: 100px; }
    .stat-value { font-size: 1.2rem; }

    .history-chart { gap: 8px; height: 100px; padding: 0 40px; }
    .history-bar { width: 35px; }
    .bar-label { font-size: 0.75rem; }

    .lives-display .lives-count {
        font-size: 2.5rem !important;
    }
}

/* ==========================================================================
   10. PLEIN ÉCRAN UNIFIÉ (Fullscreen & iOS-Fullscreen)
   ========================================================================== */
.game-board:fullscreen,
.ios-fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
    border-radius: 0 !important;
    border: none !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
    background-color: var(--bg-main) !important;
    padding: 0 !important;
    margin: 0 !important;
    position: fixed !important;
    inset: 0 !important;
    z-index: 9999 !important;
}

.game-board:fullscreen .game-container,
.ios-fullscreen .game-container,
.game-board:fullscreen .math-container,
.ios-fullscreen .math-container,
.game-board:fullscreen .memory-container,
.ios-fullscreen .memory-container {
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    padding: 1.25rem !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    align-items: center !important;
    box-sizing: border-box !important;
}

@media (max-width: 700px) {
    .game-board:fullscreen .game-container,
    .ios-fullscreen .game-container,
    .game-board:fullscreen .math-container,
    .ios-fullscreen .math-container,
    .game-board:fullscreen .memory-container,
    .ios-fullscreen .memory-container {
        padding: 10px 12px !important;
    }
}

.game-board:fullscreen .workspace-container,
.ios-fullscreen .workspace-container {
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
    max-width: none !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

.game-board:fullscreen .game-header,
.ios-fullscreen .game-header {
    width: 100%;
    max-width: none !important;
    padding: 0 !important;
}

.game-board:fullscreen .game-actions-row,
.ios-fullscreen .game-actions-row {
    width: 100%;
    max-width: none !important;
    padding: 0 !important;
}

.game-board:fullscreen .exit-fs-btn,
.ios-fullscreen .exit-fs-btn {
    display: block !important;
}

/* Plein écran - Agrandissement proportionnel du Timer et des éléments HUD */
.game-board:fullscreen .timer-display,
.ios-fullscreen .timer-display {
    font-size: 3.5rem;
    gap: 16px;
}

.game-board:fullscreen .timer-display svg,
.ios-fullscreen .timer-display svg {
    width: 60px;
    height: 60px;
}

.game-board:fullscreen .timer-box,
.ios-fullscreen .timer-box {
    font-size: 2.8rem;
    min-width: 140px;
    height: 85px;
}

.game-board:fullscreen .score-box,
.ios-fullscreen .score-box {
    width: 72px;
    height: 72px;
    min-width: 72px;
    max-width: 72px;
    padding: 0;
}
