/* ============================================
   Chroma Rush - Feuille de styles
   Design responsive et moderne
   ============================================ */

/* --- Reset et base --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

#game-main {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
    color: #e0e0e0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100dvh;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

/* --- Conteneur principal --- */
#game-container {
    width: 100%;
    max-width: 500px;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 15px;
    gap: 6px;
    position: relative;
    overflow: hidden;
}

/* --- En-tête --- */
#game-header {
    width: 100%;
    text-align: center;
    flex-shrink: 0;
}

#game-title {
    font-size: 1.6rem;
    font-weight: 700;
    background: linear-gradient(90deg, #00d2ff, #7b2ff7, #ff6fd8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 4px;
}

/* --- Scores --- */
#scores-container {
    display: flex;
    justify-content: center;
    gap: 30px;
}

.score-box {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.score-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #888;
}

.score-number {
    font-size: 1.4rem;
    font-weight: 700;
    color: #fff;
}

/* --- Barre d'informations --- */
#info-bar {
    width: 100%;
    display: flex;
    justify-content: space-around;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 6px 10px;
    flex-shrink: 0;
}

.info-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.info-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #888;
}

.info-value {
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
}

/* --- Message d'état --- */
#message-container {
    width: 100%;
    text-align: center;
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#game-message {
    font-size: 0.95rem;
    font-weight: 500;
    color: #b0b0ff;
    transition: opacity 0.3s ease;
}

#game-message.fade-out {
    opacity: 0;
}

#game-message.fade-in {
    opacity: 1;
}

#game-message.success {
    color: #00e676;
}

#game-message.error {
    color: #ff5252;
}

/* --- Barre de montée --- */
#rise-bar-container {
    width: 100%;
    flex-shrink: 0;
    min-height: 8px;
}

#rise-bar {
    width: 100%;
    height: 5px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#rise-bar.visible {
    opacity: 1;
}

#rise-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #00d2ff, #7b2ff7);
    border-radius: 3px;
    transition: width 0.1s linear;
}

#rise-fill.warning {
    background: linear-gradient(90deg, #ff9800, #ff5252);
}

/* --- Grille de jeu --- */
#grid-container {
    flex: 1;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
}

#game-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    gap: 3px;
    width: min(90vw, 75vh - 220px, 420px);
    height: min(90vw, 75vh - 220px, 420px);
    max-width: 420px;
    max-height: 420px;
}

/* --- Cases de la grille --- */
.grid-cell {
    border-radius: 5px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
    min-width: 0;
    min-height: 0;
    position: relative;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}

/* --- Couleurs des cases --- */
.cell-empty {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.03);
    cursor: default;
}

.cell-red {
    background: linear-gradient(135deg, #ff4444, #cc0000);
    border-color: rgba(255, 68, 68, 0.5);
    box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.2), 0 1px 4px rgba(255, 68, 68, 0.3);
}

.cell-blue {
    background: linear-gradient(135deg, #448aff, #1565c0);
    border-color: rgba(68, 138, 255, 0.5);
    box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.2), 0 1px 4px rgba(68, 138, 255, 0.3);
}

.cell-green {
    background: linear-gradient(135deg, #44dd44, #2e7d32);
    border-color: rgba(68, 221, 68, 0.5);
    box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.2), 0 1px 4px rgba(68, 221, 68, 0.3);
}

.cell-yellow {
    background: linear-gradient(135deg, #ffdd44, #f9a825);
    border-color: rgba(255, 221, 68, 0.5);
    box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.2), 0 1px 4px rgba(255, 221, 68, 0.3);
}

.cell-purple {
    background: linear-gradient(135deg, #bb44ff, #7b1fa2);
    border-color: rgba(187, 68, 255, 0.5);
    box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.2), 0 1px 4px rgba(187, 68, 255, 0.3);
}

/* --- Case active (pendant le swipe) --- */
.grid-cell.active-swipe {
    transform: scale(1.08);
    z-index: 2;
}

/* --- Case supprimée (clignotement) --- */
.grid-cell.removing {
    animation: blink-remove 0.4s ease;
}

@keyframes blink-remove {
    0%   { opacity: 1; transform: scale(1); }
    25%  { opacity: 0.2; transform: scale(0.95); }
    50%  { opacity: 1; transform: scale(1.05); }
    75%  { opacity: 0.2; transform: scale(0.95); }
    100% { opacity: 0; transform: scale(0.5); }
}

/* --- Animation de montée --- */
.grid-cell.rising {
    animation: rise-up 0.3s ease;
}

@keyframes rise-up {
    from { transform: translateY(100%); opacity: 0.5; }
    to   { transform: translateY(0); opacity: 1; }
}

/* --- Animation de chute (gravité) --- */
.grid-cell.falling {
    animation: fall-down 0.2s ease;
}

@keyframes fall-down {
    from { transform: translateY(-100%); opacity: 0.6; }
    to   { transform: translateY(0); opacity: 1; }
}

/* --- Animation score popup --- */
.score-popup {
    position: absolute;
    font-size: 0.9rem;
    font-weight: 700;
    color: #ffdd44;
    text-shadow: 0 0 8px rgba(255, 221, 68, 0.6);
    pointer-events: none;
    z-index: 10;
    animation: popup-float 0.8s ease forwards;
}

@keyframes popup-float {
    0%   { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-40px) scale(1.3); }
}

/* --- Animation chaos --- */
.grid-cell.chaos-flash {
    animation: chaos-pulse 0.5s ease;
}

@keyframes chaos-pulse {
    0%   { filter: brightness(1); }
    50%  { filter: brightness(2.5); }
    100% { filter: brightness(1); }
}

/* --- Grille inactive --- */
#game-grid.inactive .grid-cell {
    cursor: default;
    opacity: 0.4;
}

#game-grid.inactive .grid-cell:active {
    transform: none;
}

/* --- Animations --- */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

.shake {
    animation: shake 0.4s ease;
}

/* --- Option Chaos toggle --- */
#options-container {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 6px 0 2px;
    flex-shrink: 0;
}

.chaos-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.chaos-toggle input {
    display: none;
}

.chaos-slider {
    position: relative;
    width: 44px;
    height: 24px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    transition: background 0.3s ease;
}

.chaos-slider::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    background: #aaa;
    border-radius: 50%;
    transition: transform 0.3s ease, background 0.3s ease;
}

.chaos-toggle input:checked + .chaos-slider {
    background: rgba(255, 87, 34, 0.5);
}

.chaos-toggle input:checked + .chaos-slider::after {
    transform: translateX(20px);
    background: #ff5722;
    box-shadow: 0 0 8px rgba(255, 87, 34, 0.6);
}

.chaos-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.7);
    letter-spacing: 0.5px;
    transition: color 0.3s ease;
}

.chaos-toggle input:checked ~ .chaos-label {
    color: #ff5722;
}

/* --- Boutons --- */
#controls-container {
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 15px;
    padding: 8px 0;
    flex-shrink: 0;
}

.game-btn {
    padding: 12px 36px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    letter-spacing: 1px;
    text-transform: uppercase;
    transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

.game-btn:active {
    transform: scale(0.95);
}

.btn-play {
    background: linear-gradient(135deg, #00d2ff, #7b2ff7);
    color: #fff;
    box-shadow: 0 4px 15px rgba(0, 210, 255, 0.3);
}

.btn-play:hover {
    box-shadow: 0 6px 20px rgba(0, 210, 255, 0.5);
}

.btn-stop {
    background: linear-gradient(135deg, #ff5252, #d50000);
    color: #fff;
    box-shadow: 0 4px 15px rgba(255, 82, 82, 0.3);
}

.btn-stop:hover {
    box-shadow: 0 6px 20px rgba(255, 82, 82, 0.5);
}

.btn-rules {
    background: linear-gradient(135deg, #ff6fd8, #7b2ff7);
    color: #fff;
    box-shadow: 0 4px 15px rgba(123, 47, 247, 0.3);
}

.btn-rules:hover {
    box-shadow: 0 6px 20px rgba(123, 47, 247, 0.5);
}

/* --- Modal Règles --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 15px;
    animation: fadeIn 0.25s ease;
}

.modal-overlay.hidden {
    display: none !important;
}

.modal-content {
    background: linear-gradient(135deg, #1a1a3e, #2a2a5e);
    border: 1px solid rgba(123, 47, 247, 0.4);
    border-radius: 16px;
    padding: 24px 20px;
    max-width: 440px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

.modal-close {
    position: absolute;
    top: 10px;
    right: 14px;
    background: none;
    border: none;
    color: #aaa;
    font-size: 1.8rem;
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
    transition: color 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.modal-close:hover {
    color: #fff;
}

.modal-title {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 14px;
    background: linear-gradient(90deg, #00d2ff, #7b2ff7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-align: center;
}

.modal-body {
    font-size: 0.88rem;
    line-height: 1.6;
    color: #ccc;
}

.modal-body h3 {
    font-size: 0.95rem;
    color: #b0b0ff;
    margin: 14px 0 6px;
    font-weight: 600;
}

.modal-body p {
    margin-bottom: 8px;
}

.modal-body ol,
.modal-body ul {
    padding-left: 20px;
    margin-bottom: 8px;
}

.modal-body li {
    margin-bottom: 4px;
}

/* --- Mini-grille d'exemple dans le modal --- */
.modal-example-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 3px;
    width: 160px;
    height: 64px;
    margin: 10px auto;
}

.ex-cell {
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.ex-cell.ex-red {
    background: linear-gradient(135deg, #ff4444, #cc0000);
}

.ex-cell.ex-blue {
    background: linear-gradient(135deg, #448aff, #1565c0);
}

.ex-cell.ex-green {
    background: linear-gradient(135deg, #44dd44, #2e7d32);
}

.ex-cell.ex-yellow {
    background: linear-gradient(135deg, #ffdd44, #f9a825);
}

.ex-cell.ex-purple {
    background: linear-gradient(135deg, #bb44ff, #7b1fa2);
}

.modal-example-caption {
    text-align: center;
    font-size: 0.8rem;
    color: #999;
    font-style: italic;
}

/* --- Game Over Overlay --- */
.gameover-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.5s ease;
}

.gameover-overlay.hidden {
    display: none !important;
}

.gameover-content {
    text-align: center;
    animation: slideUp 0.5s ease;
}

.gameover-title {
    font-size: 2.5rem;
    font-weight: 800;
    background: linear-gradient(90deg, #ff5252, #ff6fd8, #7b2ff7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-transform: uppercase;
    letter-spacing: 3px;
    margin-bottom: 16px;
}

.gameover-score {
    font-size: 1.4rem;
    color: #fff;
    font-weight: 600;
}

.gameover-record {
    font-size: 1.1rem;
    color: #ffdd44;
    font-weight: 700;
    margin-top: 10px;
    animation: pulse-glow-text 1s ease-in-out infinite alternate;
}

@keyframes pulse-glow-text {
    0%   { text-shadow: 0 0 5px rgba(255, 221, 68, 0.3); }
    100% { text-shadow: 0 0 20px rgba(255, 221, 68, 0.8); }
}

.gameover-replay-btn {
    margin-top: 20px;
    padding: 14px 48px;
    font-size: 1.1rem;
}

/* --- Utilitaires --- */
.hidden {
    display: none !important;
}

/* --- Responsive : petits écrans --- */
@media (max-height: 600px) {
    #game-container {
        padding: 4px 10px;
        gap: 3px;
    }

    #game-title {
        font-size: 1.2rem;
        margin-bottom: 2px;
    }

    .score-number {
        font-size: 1.1rem;
    }

    #info-bar {
        padding: 4px 8px;
    }

    .info-label {
        font-size: 0.6rem;
    }

    .info-value {
        font-size: 0.85rem;
    }

    #game-message {
        font-size: 0.8rem;
    }

    #message-container {
        min-height: 22px;
    }

    .game-btn {
        padding: 10px 24px;
        font-size: 0.85rem;
    }
}

/* --- Responsive : grands écrans / tablettes --- */
@media (min-width: 768px) {
    #game-container {
        padding: 20px;
        gap: 10px;
    }

    #game-title {
        font-size: 2rem;
    }

    .score-number {
        font-size: 1.8rem;
    }

    #game-grid {
        gap: 4px;
    }

    .grid-cell {
        border-radius: 7px;
    }
}

/* --- Mode paysage mobile --- */
@media (orientation: landscape) and (max-height: 500px) {
    #game-container {
        flex-direction: row;
        flex-wrap: wrap;
        padding: 5px 10px;
        gap: 3px;
        max-width: 100%;
        justify-content: center;
    }

    #game-header {
        width: 50%;
        order: 1;
    }

    #game-title {
        font-size: 1rem;
        margin-bottom: 2px;
    }

    .score-number {
        font-size: 1rem;
    }

    #info-bar {
        width: 50%;
        order: 2;
        padding: 3px 6px;
    }

    #message-container {
        width: 100%;
        order: 3;
        min-height: 18px;
    }

    #game-message {
        font-size: 0.75rem;
    }

    #rise-bar-container {
        width: 100%;
        order: 4;
    }

    #grid-container {
        order: 5;
        flex: 0 0 auto;
        width: auto;
    }

    #game-grid {
        width: min(50vw, 80vh - 60px, 300px);
        height: min(50vw, 80vh - 60px, 300px);
    }

    #controls-container {
        order: 6;
        width: auto;
        flex-direction: column;
        padding: 0 10px;
    }

    .game-btn {
        padding: 8px 18px;
        font-size: 0.8rem;
    }
}
