:root {
    --bg: #f5efe6;
    --card-size: 70px;
    --gap: 6px;
    --font: 'Segoe UI', sans-serif;
}

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

body {
    background: #3a2f28;
    font-family: var(--font);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 10px;
    position: relative;
    overflow-x: hidden;
}

.background-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    transition: opacity 2s ease-in-out;
    opacity: 0;
}

.background-layer.visible {
    opacity: 1;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: #fff8f0;
    border-radius: 24px;
    padding: 25px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 20px 40px rgba(0,0,0,0.3);
}

.modal-close {
    position: absolute;
    top: 8px;
    right: 12px;
    background: none;
    border: none;
    font-size: 1.8rem;
    cursor: pointer;
    color: #8b7a62;
    line-height: 1;
}

.modal-close:hover {
    color: #5a4a3a;
}

.modal-content h2 {
    color: #5a4a3a;
    margin-bottom: 12px;
    font-weight: 400;
}

.rules-text h3 {
    color: #8b7a62;
    margin: 10px 0 4px;
    font-weight: 500;
    font-size: 1rem;
}

.rules-text p, .rules-text li {
    color: #5a4a3a;
    font-size: 0.9rem;
    line-height: 1.5;
}

.rules-text ul {
    padding-left: 20px;
    margin: 4px 0;
}

.rules-enjoy {
    text-align: center;
    margin-top: 12px;
    font-style: italic;
    color: #8b7a62;
}

/* Conteneur principal – dimensions fixes */
.game-container {
    background: rgba(255,248,240,0.85);
    backdrop-filter: blur(10px);
    border-radius: 32px;
    padding: 20px 15px 25px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    width: 500px;
    max-width: 95vw;
    height: 750px;
    max-height: 95vh;
    overflow-y: auto;
    text-align: center;
    margin: 0 auto;
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.game-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 5px;
    position: relative;
}

.game-header h1 {
    margin-bottom: 0;
}

h1 {
    font-size: 2rem;
    font-weight: 400;
    color: #5a4a3a;
    letter-spacing: 2px;
}

.subtitle {
    font-size: 0.85rem;
    color: #7a6a5a;
    margin-bottom: 6px;
}

.header-buttons {
    display: flex;
    gap: 6px;
    position: absolute;
    right: 0;
    top: 0;
}

.icon-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1.5px solid #b7a68b;
    background: transparent;
    color: #8b7a62;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s, border-color 0.3s;
    padding: 0;
    line-height: 1;
}

.icon-btn:hover {
    background: rgba(139,122,98,0.12);
    border-color: #8b7a62;
}

.icon-btn.muted {
    background: rgba(200,180,160,0.3);
    border-color: #c0b0a0;
}

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
    padding: 0 5px;
}

.level-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.level-nav-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1.5px solid #b7a68b;
    background: transparent;
    color: #8b7a62;
    font-size: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s, border-color 0.3s;
    padding: 0;
    line-height: 1;
}

.level-nav-btn:hover:not(:disabled) {
    background: rgba(139,122,98,0.12);
    border-color: #8b7a62;
}

.level-nav-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.level-indicator {
    font-size: 0.8rem;
    color: #5a4a3a;
    font-weight: 500;
    min-width: 50px;
    text-align: center;
}

.chrono {
    font-size: 0.85rem;
    color: #8b7a62;
    font-weight: 500;
    background: rgba(255,235,210,0.6);
    padding: 3px 10px;
    border-radius: 20px;
    letter-spacing: 0.5px;
    min-width: 65px;
    text-align: center;
}

.level-dots {
    display: flex;
    justify-content: center;
    gap: 5px;
    margin-bottom: 6px;
}

.level-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #d4cec2;
    cursor: pointer;
    transition: background 0.3s, transform 0.2s;
    border: none;
    padding: 0;
}

.level-dot.active {
    background: #8b7a62;
    transform: scale(1.3);
}

.level-dot.unlocked:not(.active) {
    background: #b7a68b;
}

.level-dot.locked {
    background: #e5e0d8;
    cursor: not-allowed;
}

.time-warning {
    font-size: 0.8rem;
    color: #c0392b;
    font-weight: 500;
    margin-bottom: 6px;
    min-height: 1rem;
}

.stats {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
    font-size: 1.1rem;
    color: #5a4a3a;
}

.petals-counter {
    display: flex;
    align-items: center;
    gap: 5px;
    background: rgba(255,235,210,0.85);
    padding: 5px 14px;
    border-radius: 30px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.05);
}

.petal-icon {
    font-size: 1.3rem;
}

/* Zone de la grille – dimensions fixes calquées sur le plus grand niveau (6x6) */
.grid-wrapper {
    width: 100%;
    max-width: 450px;
    height: 450px;
    margin: 0 auto 15px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.grid {
    display: grid;
    gap: var(--gap);
}

.card {
    width: var(--card-size);
    height: var(--card-size);
    perspective: 600px;
    cursor: pointer;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.5s ease;
    transform-style: preserve-3d;
}

.card.flipped .card-inner {
    transform: rotateY(180deg);
}

.card.matched {
    cursor: default;
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.7rem;
}

.card-back {
    background-color: #b7a68b;
    background-image: linear-gradient(135deg, #c7b59a, #a58d71);
    color: #f5efe6;
    box-shadow: 0 6px 10px rgba(0,0,0,0.15);
}

.card-back::after {
    content: "🌿";
    opacity: 0.5;
    font-size: 1.3rem;
}

.card-front {
    background-color: #faf3e8;
    background-image: radial-gradient(circle at 30% 40%, #fff 0%, #f0e6d8 90%);
    transform: rotateY(180deg);
    box-shadow: 0 6px 10px rgba(0,0,0,0.15);
}

.card.matched .card-front {
    box-shadow: 0 0 12px 4px rgba(76, 175, 80, 0.6);
    background-color: #e0f0d8;
}

.card.sun .card-front {
    box-shadow: 0 0 18px 6px rgba(255, 200, 0, 0.7);
    background-color: #fff8e0;
}

.card.withered .card-front {
    box-shadow: 0 0 10px 3px rgba(160, 120, 80, 0.5);
    background-color: #e8d8c8;
}

/* Zone de message – hauteur réservée */
.message {
    font-size: 0.95rem;
    min-height: 3.5em;
    margin: 8px 0;
    color: #5a4a3a;
    font-weight: 500;
    line-height: 1.4;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn {
    border: none;
    padding: 8px 20px;
    border-radius: 40px;
    font-size: 0.9rem;
    color: #fff;
    background: #8b7a62;
    cursor: pointer;
    transition: background 0.3s, transform 0.2s;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    font-family: var(--font);
    margin-top: auto;
}

.btn:hover {
    background: #6b5d4a;
    transform: translateY(-2px);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

.bee {
    position: fixed;
    z-index: 10;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s ease;
    will-change: transform, left, top;
}

.bee.visible {
    opacity: 1;
}

.bee img {
    width: 20px;
    height: auto;
    display: block;
}

/* --- RESPONSIVE --- */
@media (min-width: 700px) {
    :root {
        --card-size: 70px;
        --gap: 6px;
    }
}

@media (max-width: 699px) {
    :root {
        --card-size: 55px;
        --gap: 5px;
    }
    .game-container {
        width: auto;
        height: auto;
        max-height: 95vh;
        padding: 15px 10px 20px;
    }
    .grid-wrapper {
        max-width: 100%;
        height: auto;
        aspect-ratio: 1 / 1;
    }
    h1 {
        font-size: 1.6rem;
    }
    .card-face {
        font-size: 1.4rem;
    }
    .card-back::after {
        font-size: 1.1rem;
    }
    .icon-btn {
        width: 28px;
        height: 28px;
        font-size: 0.9rem;
    }
    .chrono {
        font-size: 0.75rem;
        padding: 2px 8px;
        min-width: 60px;
    }
}

@media (max-width: 480px) {
    :root {
        --card-size: 42px;
        --gap: 4px;
    }
    .game-container {
        padding: 10px 5px 15px;
        border-radius: 20px;
    }
    .grid-wrapper {
        aspect-ratio: 1 / 1;
    }
    h1 {
        font-size: 1.3rem;
    }
    .subtitle {
        font-size: 0.7rem;
    }
    .card-face {
        font-size: 1.1rem;
    }
    .card-back::after {
        font-size: 0.9rem;
    }
    .level-nav-btn {
        width: 20px;
        height: 20px;
        font-size: 0.6rem;
    }
    .level-indicator {
        font-size: 0.7rem;
    }
    .chrono {
        font-size: 0.7rem;
        padding: 2px 6px;
    }
    .stats {
        font-size: 1rem;
    }
    .btn {
        padding: 6px 16px;
        font-size: 0.8rem;
    }
    .message {
        font-size: 0.85rem;
        min-height: 2.5em;
    }
}

@media (max-width: 360px) {
    :root {
        --card-size: 36px;
        --gap: 3px;
    }
    .game-container {
        padding: 8px 2px 12px;
    }
    h1 {
        font-size: 1.1rem;
    }
    .card-face {
        font-size: 0.9rem;
    }
    .card-back::after {
        font-size: 0.7rem;
    }
    .icon-btn {
        width: 24px;
        height: 24px;
        font-size: 0.8rem;
    }
}