@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;700&display=swap');

:root {
    --primary-color: #4f46e5;
    --secondary-color: #ec4899;
    --accent-color: #8b5cf6;
    --background-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #312e81 100%);
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --text-color: #f8fafc;
    --text-muted: #94a3b8;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --card-gradient-1: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    --card-gradient-2: linear-gradient(135deg, #3b82f6 0%, #2dd4bf 100%);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

/* PWA: Empêche le zoom accidentel sur iOS Safari */
html {
    touch-action: manipulation;
    -ms-touch-action: manipulation;
}

body {
    background: var(--background-gradient);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--text-color);
    overflow-x: hidden;
}

/* Background Animation */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.15) 0%, transparent 50%),
        radial-gradient(circle, rgba(236, 72, 153, 0.15) 100%, transparent 50%);
    animation: bg-pulse 15s ease-in-out infinite alternate;
    z-index: -1;
    pointer-events: none;
}

@keyframes bg-pulse {
    0% {
        transform: translate(0, 0) scale(1);
    }

    100% {
        transform: translate(-20px, 20px) scale(1.1);
    }
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transform: translateX(400px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: auto;
    min-width: 200px;
}

.toast.show {
    transform: translateX(0);
    opacity: 1;
}

.toast-icon {
    font-size: 1.2rem;
    font-weight: bold;
}

.toast-message {
    font-size: 0.95rem;
    font-weight: 500;
    color: white;
}

.toast-success {
    border-left: 4px solid #10b981;
}

.toast-success .toast-icon {
    color: #10b981;
}

.toast-error {
    border-left: 4px solid #ef4444;
}

.toast-error .toast-icon {
    color: #ef4444;
}

.toast-combo {
    border-left: 4px solid #f59e0b;
    animation: pulse-glow 0.5s ease-in-out;
}

.toast-combo .toast-icon {
    color: #f59e0b;
}

@keyframes pulse-glow {

    0%,
    100% {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }

    50% {
        box-shadow: 0 4px 20px rgba(245, 158, 11, 0.6);
    }
}

.container {
    max-width: 1200px;
    width: 100%;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
}

/* Typography */
h1 {
    font-size: 3.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(to right, #fff, #cbd5e1);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    letter-spacing: -0.02em;
}

.subtitle {
    font-size: 1.25rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    font-weight: 300;
}

/* Progress Bar */
.progress-container {
    margin-top: 1.5rem;
    margin-bottom: 2rem;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
    border-radius: 10px;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.5);
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg,
            transparent,
            rgba(255, 255, 255, 0.3),
            transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }

    100% {
        transform: translateX(100%);
    }
}

.progress-text {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Glassmorphism Cards */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    box-shadow: var(--glass-shadow);
    padding: 2rem;
    width: 100%;
    max-width: 500px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.glass-panel:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.45);
    border-color: rgba(255, 255, 255, 0.2);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 1rem 2rem;
    border-radius: 16px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    text-decoration: none;
    gap: 0.5rem;
    position: relative;
    overflow: hidden;
    /* Responsive Text Fixes */
    white-space: normal;
    text-align: center;
    text-decoration: none;
    /* Added from original .btn */
    gap: 0.5rem;
    /* Added from original .btn */
    white-space: normal;
    /* Added from original .btn */
    text-align: center;
    /* Added from original .btn */
    line-height: 1.2;
    /* Added from original .btn */
    max-width: 100%;
    /* Added from original .btn */
}

/* Screen Reader Only - Accessible but invisible */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
    z-index: 0;
    /* Ensure ripple is behind text */
}

.btn span {
    /* Added to ensure text is above ripple */
    position: relative;
    z-index: 1;
}

.btn:active::before {
    width: 300px;
    height: 300px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
}

.btn:active {
    transform: translateY(0) scale(0.98);
}

@media (max-width: 480px) {
    .btn {
        padding: 0.75rem 1rem;
        font-size: 0.95rem;
        width: 100%;
    }
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.5);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid var(--glass-border);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--primary-color);
}

.w-100 {
    width: 100%;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
    text-align: left;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 500;
}

.form-input {
    width: 100%;
    padding: 1rem 1.25rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    color: white;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
    background: rgba(0, 0, 0, 0.3);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

/* Game Board */
.game-container {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 2rem;
    width: 100%;
    max-width: 1200px;
    margin-top: 2rem;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.player-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: all 0.3s ease;
}

.player-card.active {
    background: rgba(99, 102, 241, 0.15);
    border-color: var(--primary-color);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.2);
}

.player-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--card-gradient-2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
}

.player-info {
    flex: 1;
}

.player-name {
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
}

.player-score {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.score-badge {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-weight: 700;
    font-size: 1.2rem;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
    perspective: 1000px;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

.card {
    aspect-ratio: 1 / 1;
    position: relative;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    will-change: transform;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Hover effect (desktop only) */
@media (hover: hover) {
    .card:not(.flipped):not(.matched):hover {
        transform: translateY(-4px) scale(1.02);
        box-shadow: 0 8px 24px rgba(99, 102, 241, 0.3);
    }
}

/* Active/Tap effect */
.card:active {
    transform: scale(0.95);
}

/* Keyboard Focus Indicator - Accessibility */
.card:focus {
    outline: 3px solid var(--primary-color);
    outline-offset: 4px;
    box-shadow: 0 0 0 6px rgba(99, 102, 241, 0.2);
}

.card:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 4px;
    box-shadow: 0 0 0 6px rgba(99, 102, 241, 0.3);
}

/* Remove focus on mouse users */
.card:focus:not(:focus-visible) {
    outline: none;
    box-shadow: none;
}

/* Button focus styles */
.btn:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 4px;
}

/* Flipped state with spring animation */
.card.flipped {
    transform: rotateY(180deg);
}

/* Match success - Pulse + Glow animation */
.card.matched {
    animation: matchSuccess 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes matchSuccess {
    0% {
        transform: scale(1) rotateY(180deg);
    }

    30% {
        transform: scale(1.15) rotateY(180deg) rotate(3deg);
        box-shadow: 0 0 30px rgba(34, 197, 94, 0.8);
    }

    60% {
        transform: scale(1.05) rotateY(180deg) rotate(-2deg);
    }

    100% {
        transform: scale(1) rotateY(180deg);
        box-shadow: 0 0 15px rgba(34, 197, 94, 0.4);
    }
}

/* Mismatch - Shake animation */
.card.mismatch {
    animation: shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0) rotateY(180deg);
    }

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-8px) rotateY(180deg);
    }

    20%,
    40%,
    60%,
    80% {
        transform: translateX(8px) rotateY(180deg);
    }
}

/* Card entrance animation */
.card {
    animation: cardEntrance 0.4s ease-out backwards;
    animation-delay: calc(var(--card-index) * 0.03s);
}

@keyframes cardEntrance {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.9);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 3rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.card-front {
    background: var(--glass-bg);
    background-image: repeating-linear-gradient(45deg,
            rgba(255, 255, 255, 0.05) 0px,
            rgba(255, 255, 255, 0.05) 10px,
            transparent 10px,
            transparent 20px);
}

.card-back {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    transform: rotateY(180deg);
    background: rgba(255, 255, 255, 0.95);
}

.card-face i {
    line-height: 1;
    margin: 0;
    padding: 0;
    display: inline-block;
}

/* Timer */
.timer-container {
    position: relative;
    width: 100px;
    height: 100px;
    margin: 0 auto;
}

.timer-svg {
    transform: rotate(-90deg);
    width: 100%;
    height: 100%;
}

.timer-circle-bg {
    fill: none;
    stroke: rgba(255, 255, 255, 0.1);
    stroke-width: 6;
}

.timer-fg {
    fill: none;
    stroke-width: 6;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.1s linear;
}

.timer-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.5rem;
    font-weight: 700;
}

/* Animations */
@keyframes pop-in {
    0% {
        transform: rotateY(180deg) scale(1);
    }

    50% {
        transform: rotateY(180deg) scale(1.1);
    }

    100% {
        transform: rotateY(180deg) scale(1);
    }
}

/* Responsive */
@media (max-width: 900px) {
    .game-container {
        grid-template-columns: 1fr;
    }

    .sidebar {
        flex-direction: row;
        justify-content: center;
        flex-wrap: wrap;
    }

    .player-card {
        flex: 1;
        min-width: 200px;
    }
}

@media (max-width: 600px) {
    .game-board {
        grid-template-columns: repeat(3, 1fr);
        gap: 1rem;
    }

    h1 {
        font-size: 2.5rem;
    }
}

@media (max-width: 400px) {
    .game-board {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Utilities */
.text-center {
    text-align: center;
}

.mb-4 {
    margin-bottom: 1.5rem;
}

.mt-4 {
    margin-top: 1.5rem;
}

.w-100 {
    width: 100%;
}

.d-none {
    display: none !important;
}

/* Toast */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
}

.toast {
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1rem;
    color: white;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 300px;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: safe center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 1rem 0;
}

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

.modal-content {
    background: #1e1b4b;
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 2.5rem;
    max-width: 500px;
    width: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 3rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}

.card-front {
    background: var(--glass-bg);
    background-image: repeating-linear-gradient(45deg,
            rgba(255, 255, 255, 0.05) 0px,
            rgba(255, 255, 255, 0.05) 10px,
            transparent 10px,
            transparent 20px);
}

.card-back {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    transform: rotateY(180deg);
    background: rgba(255, 255, 255, 0.95);
}

/* Timer */
.timer-container {
    position: relative;
    width: 100px;
    height: 100px;
    margin: 0 auto;
}

.timer-svg {
    transform: rotate(-90deg);
    width: 100%;
    height: 100%;
}

.timer-circle-bg {
    fill: none;
    stroke: rgba(255, 255, 255, 0.1);
    stroke-width: 6;
}

.timer-fg {
    fill: none;
    stroke-width: 6;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.1s linear;
}

.timer-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.5rem;
    font-weight: 700;
}

/* Animations */
@keyframes pop-in {
    0% {
        transform: rotateY(180deg) scale(1);
    }

    50% {
        transform: rotateY(180deg) scale(1.1);
    }

    100% {
        transform: rotateY(180deg) scale(1);
    }
}

/* Responsive */
@media (min-width: 768px) {
    .game-board {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Responsive Mobile Optimization (No-Scroll) */
@media (max-width: 900px) {

    /* Global Mobile Fixes */
    .container {
        padding: 0.5rem;
    }

    h1 {
        font-size: 1.5rem;
        margin-bottom: 0;
    }

    .subtitle {
        display: none;
    }

    /* --- GAME PAGE SPECIFIC (No Scroll) --- */
    body.game-page {
        overflow: hidden !important;
        overscroll-behavior: none;
        -webkit-overflow-scrolling: auto;
    }

    body.game-page .container {
        height: 100dvh;
        max-height: 100dvh;
        padding: 0.4rem;
        padding-bottom: calc(0.4rem + env(safe-area-inset-bottom, 0.5rem));
        display: flex;
        flex-direction: column;
        overflow: hidden !important;
    }

    body.game-page header {
        margin-bottom: 0 !important;
        flex-shrink: 0;
    }

    body.game-page h1 {
        font-size: 1rem;
        margin: 0;
    }

    /* CRITICAL: Hide tour indicator - not needed on mobile */
    #tour-indicator {
        display: none !important;
    }

    body.game-page .glass-panel {
        padding: 0.4rem;
        margin: 0 !important;
    }

    /* --- HOME PAGE SPECIFIC (Allow Scroll) --- */
    body.home-page {
        overflow-y: auto;
    }

    body.home-page .container {
        min-height: 100vh;
        height: auto;
        justify-content: center;
        padding: 2rem 1rem;
    }

    body.home-page .glass-panel {
        margin: 1rem 0;
        padding: 1.5rem;
        width: 100%;
        max-width: 100%;
    }

    body.home-page .subtitle {
        display: block;
        font-size: 1rem;
        margin-bottom: 1.5rem;
    }





    /* Game Container - Flexible Layout */
    .game-container {
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
        flex: 1;
        width: 100%;
        margin: 0;
        overflow: hidden;
        min-height: 0;
    }

    /* Solo mode: even more compact */
    body.solo-mode .game-container {
        gap: 0.2rem !important;
    }

    /* Sidebar - Compact Grid */
    .sidebar {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto;
        width: 100%;
        padding: 0;
        gap: 0.2rem;
        flex-shrink: 0;
        overflow: hidden;
    }

    .sidebar>*:nth-child(1) {
        grid-row: 1;
        grid-column: 1;
        justify-self: start;
    }

    .sidebar>*:nth-child(2) {
        grid-row: 2;
        grid-column: 1;
        width: 100%;
    }

    .sidebar>*:nth-child(3) {
        grid-row: 2;
        grid-column: 2;
        width: 100%;
    }

    .sidebar>*:nth-child(4) {
        grid-row: 1;
        grid-column: 2;
        justify-self: end;
        width: auto !important;
    }

    .sidebar .glass-panel {
        padding: 0.2rem 0.4rem !important;
        margin: 0 !important;
        min-height: 30px;
    }

    .sidebar>div[id^="player"] {
        display: flex;
    }

    .sidebar p {
        display: none !important;
    }

    /* Ultra Compact Timer */
    .timer-container {
        width: 35px;
        height: 35px;
        margin: 0;
    }

    #countdown {
        font-size: 0.9rem !important;
    }

    /* Compact Button */
    #quitter-btn {
        width: auto;
        padding: 0.3rem 0.6rem;
        font-size: 0.75rem;
        margin: 0;
    }

    /* Game Board - CRITICAL: Takes remaining space */
    .game-board {
        flex: 1;
        width: 100%;
        min-height: 0 !important;
        overflow: hidden;
        display: grid !important;
        align-content: center;
        padding-bottom: env(safe-area-inset-bottom, 0.3rem);
    }

    /* CRITICAL: Force Square Cards */
    .card {
        aspect-ratio: 1 / 1 !important;
        width: 100%;
        height: auto !important;
    }

    .card-face {
        font-size: 1.5rem !important;
    }

    .card-face i {
        font-size: 0.9rem !important;
    }

    /* Ultra Compact Player Cards */
    .player-card {
        padding: 0.2rem;
        border-radius: 6px;
        font-size: 0.7rem;
    }

    .player-avatar {
        width: 20px;
        height: 20px;
        font-size: 0.6rem;
    }

    .player-name {
        font-size: 0.7rem;
    }

    .player-score {
        font-size: 0.65rem;
    }

    /* Misc Optimizations */
    .score-badge {
        font-size: 0.7rem !important;
        padding: 0.2rem 0.4rem !important;
    }

    header div {
        gap: 0.4rem !important;
    }

    /* SOLO MODE: Additional optimizations */
    body.game-page.solo-mode .container {
        padding: 0.3rem !important;
        padding-bottom: calc(0.3rem + env(safe-area-inset-bottom, 0.5rem)) !important;
    }

    body.game-page.solo-mode header {
        margin-bottom: 0.2rem !important;
    }

    /* SOLO MODE: Compact horizontal layout */
    .solo-sidebar {
        display: flex !important;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 0 !important;
        padding: 0 !important;
        grid-template-columns: none !important;
        margin: 0 !important;
    }

    .solo-sidebar .glass-panel {
        width: 100%;
        padding: 0.25rem 0.4rem !important;
        display: flex !important;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 0.3rem;
        min-height: 35px !important;
        margin: 0 !important;
    }

    /* Timer Section - Horizontal & Ultra Compact */
    .solo-sidebar .glass-panel .mb-4:first-child {
        margin: 0 !important;
        display: flex;
        align-items: center;
        gap: 0.25rem;
        flex: 0 0 auto;
    }

    .solo-sidebar .glass-panel .mb-4:first-child i {
        font-size: 0.9rem !important;
        margin: 0;
    }

    .solo-sidebar .glass-panel #timer-text {
        font-size: 0.85rem !important;
        font-weight: 700;
        margin: 0 !important;
        line-height: 1;
    }

    /* Moves Section - Horizontal & Ultra Compact */
    .solo-sidebar .glass-panel .mb-4:nth-child(2) {
        margin: 0 !important;
        display: flex;
        align-items: center;
        gap: 0.25rem;
        flex: 0 0 auto;
    }

    .solo-sidebar .glass-panel .mb-4:nth-child(2) p {
        margin: 0 !important;
        font-size: 0.65rem;
        display: inline-block !important;
        line-height: 1;
    }

    .solo-sidebar .glass-panel #moves-count {
        font-size: 0.85rem !important;
        font-weight: 700;
        margin: 0 !important;
        line-height: 1;
    }

    /* Quit Button - Ultra Compact */
    .solo-sidebar .glass-panel #quitter-btn {
        width: auto !important;
        padding: 0.3rem 0.6rem;
        font-size: 0.65rem;
        margin: 0;
        flex-shrink: 0;
        line-height: 1.2;
    }

    .solo-sidebar .glass-panel #quitter-btn i {
        margin-right: 0.15rem;
        font-size: 0.65rem;
    }

    /* Ensure game board takes remaining space in solo */
    .solo-sidebar+.game-board {
        flex: 1;
        min-height: 0 !important;
    }

}



/* Transform Tour Indicator */
#tour-indicator {
    padding: 0.5rem;
    margin-bottom: 0.5rem !important;
    font-size: 1rem;
}

#tour-text {
    font-size: 1rem !important;
}

/* Compact Player Cards */
.player-card {
    padding: 0.5rem;
    min-width: auto;
    flex: 1;
    border-radius: 12px;
}

.player-avatar {
    width: 30px;
    height: 30px;
    font-size: 0.8rem;
}

.player-name {
    font-size: 0.9rem;
}

.player-score {
    font-size: 0.8rem;
}

/* Compact Timer */
.timer-container {
    width: 40px;
    height: 40px;
}

.timer-text {
    font-size: 0.8rem;
}

.sidebar .glass-panel p {
    display: none;
    /* Hide "Temps restant" label */
}

/* Game Board - maximize space */
.game-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    width: 100%;
    height: 100%;
    max-height: 100%;
    /* Force it to stay within flex container */
    gap: 2vmin;
    padding: 2vmin;
    align-items: center;
    /* Center cards in their cells */
    justify-items: center;
    overflow-y: auto;
    /* allow scrolling within board if needed */
    flex-grow: 1;
    /* Take all remaining space */
}

/* Force Players to be compact side-by-side in the middle column if needed */


.player-card {
    padding: 0.25rem;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8rem;
}

.player-info {
    min-width: 0;
    /* Enable truncation in flex item */
    flex: 1;
}

.player-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.8rem;
    margin: 0;
    max-width: 100%;
}

.player-score {
    font-size: 0.75rem;
    white-space: nowrap;
}


.card {
    width: 100%;
    height: 100%;
    aspect-ratio: 1 / 1;
    max-height: unset;
    /* Remove arbitrary limit */
}

/* Ensure card content fits */
.card-face {
    font-size: 8vmin;
}

.card-face {
    border-radius: 8px;
    /* Slightly less rounded */
    font-size: 8vmin;
    /* Dynamic font size for icons */
}

/* Modal Fixes for Mobile */
@media (max-width: 600px) {
    .modal-content {
        padding: 1.2rem;
        width: 92%;
        border-radius: 16px;
    }

    .modal-content h2 {
        font-size: 1.3rem;
        margin-bottom: 0.75rem;
    }

    .modal-content p {
        font-size: 0.9rem;
        margin-bottom: 1rem;
    }

    .modal-content .fa-3x {
        font-size: 1.8rem !important;
    }

    .modal-content .mb-4 {
        margin-bottom: 0.75rem;
    }

    #code-attente {
        font-size: 1.5rem !important;
        word-break: break-all;
    }
}

/* Transform Tour Indicator */
#tour-indicator {
    display: none !important;
}

/* Compact Player Cards */


/* Compact Timer */
.timer-container {
    width: 40px;
    height: 40px;
}

.timer-text {
    font-size: 0.8rem;
}

.sidebar .glass-panel p {
    display: none;
    /* Hide "Temps restant" label */
}

/* Game Board - maximize space */
.game-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    width: 100%;
    height: 100%;
    max-height: 100%;
    /* Force it to stay within flex container */
    gap: 2vmin;
    padding: 2vmin;
    align-items: center;
    /* Center cards in their cells */
    justify-items: center;
    overflow: hidden;
    /* Prevent scrolling */
    flex-grow: 1;
    /* Take all remaining space */
}

/* Force Players to be compact side-by-side in the middle column if needed */



.card {
    width: 100%;
    height: 100%;
    aspect-ratio: unset;
    /* Allow flexible shape to fill grid */
    min-height: 0;
    max-height: 100%;
}

/* Ensure card content fits */
.card-face {
    border-radius: 8px;
    font-size: clamp(1rem, 5vmin, 2rem);
    /* Dynamic font size */
}

/* Modal Fixes for Mobile */
@media (max-width: 600px) {
    .modal-content {
        padding: 1.2rem;
        width: 92%;
        border-radius: 16px;
    }

    .modal-content h2 {
        font-size: 1.3rem;
        margin-bottom: 0.75rem;
    }

    .modal-content p {
        font-size: 0.9rem;
        margin-bottom: 1rem;
    }

    .modal-content .fa-3x {
        font-size: 1.8rem !important;
    }

    .modal-content .mb-4 {
        margin-bottom: 0.75rem;
    }

    #code-attente {
        font-size: 1.5rem !important;
        word-break: break-all;
    }
}

/* Compact Button */
#quitter-btn {
    padding: 0.5rem;
    font-size: 0.9rem;
}




/* Very small screens adjustment */
@media (max-width: 380px) {
    h1 {
        font-size: 1.2rem;
    }

    .player-name {
        display: none;
    }

    /* Show only avatar/score */
}

/* Toast */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
}

.toast {
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1rem;
    color: white;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 300px;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: safe center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 1rem 0;
}

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

.modal-content {
    background: #1e1b4b;
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 2.5rem;
    max-width: 500px;
    width: 90%;
    text-align: center;
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    flex-shrink: 0;
}

.modal.show .modal-content {
    transform: scale(1);
}

/* Professional Polish */
.btn {
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.card {
    transition: transform 0.6s cubic-bezier(0.4, 0.0, 0.2, 1), box-shadow 0.3s ease;
}

.card:hover {
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.2);
}

.glass-panel {
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

#quitter-btn {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #ff6b6b;
}

#quitter-btn:hover {
    background: rgba(239, 68, 68, 0.25);
    border-color: rgba(239, 68, 68, 0.5);
    color: #ff8787;
}

/* Fix for 3D flip issue */
.card-back {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

/* New UX Animations */

/* 1. Shake Animation for Mismatch */
@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-5px);
    }

    20%,
    40%,
    60%,
    80% {
        transform: translateX(5px);
    }
}

@keyframes shake-flipped {

    0%,
    100% {
        transform: rotateY(180deg) translateX(0);
    }

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: rotateY(180deg) translateX(-5px);
    }

    20%,
    40%,
    60%,
    80% {
        transform: rotateY(180deg) translateX(5px);
    }
}

.shake {
    animation: shake 0.5s cubic-bezier(.36, .07, .19, .97) both;
    border-color: var(--danger-color) !important;
}

.card.flipped.shake {
    animation-name: shake-flipped;
}

/* 2. Winner / Match Glow */
@keyframes glow-pulse {
    0% {
        box-shadow: 0 0 5px var(--success-color);
    }

    50% {
        box-shadow: 0 0 20px var(--success-color), 0 0 10px var(--success-color);
    }

    100% {
        box-shadow: 0 0 5px var(--success-color);
    }
}

.card.matched {
    border-color: var(--success-color);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
}

/* 3. Active Turn Indicator */
@keyframes active-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(79, 70, 229, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(79, 70, 229, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(79, 70, 229, 0);
    }
}

.player-card.active-turn {
    border: 2px solid var(--primary-color);
    background: rgba(79, 70, 229, 0.1);
    animation: active-pulse 2s infinite;
}

/* 4. Custom Modal Styling (replacement for confirm) */
.custom-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

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

.custom-modal {
    background: var(--background-gradient);
    border: 1px solid var(--glass-border);
    padding: 2rem;
    border-radius: 20px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.custom-modal-overlay.active .custom-modal {
    transform: scale(1);
}

.custom-modal h3 {
    margin-bottom: 1rem;
    color: white;
}

.custom-modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 1.5rem;
}

/* Difficulty Selection Modal */
.difficulty-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    width: 100%;
    max-width: 600px;
}

.difficulty-btn {
    background: var(--glass-bg);
    border: 2px solid var(--glass-border);
    border-radius: 16px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--text-color);
    touch-action: manipulation;
}

/* Étoiles sur une seule ligne */
.difficulty-stars {
    display: flex;
    flex-direction: row;
    gap: 0.2rem;
    justify-content: center;
}

.difficulty-btn:hover {
    background: rgba(99, 102, 241, 0.15);
    border-color: var(--primary-color);
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.4);
}

.difficulty-btn i {
    color: var(--warning-color);
    font-size: 1.2rem;
}

.difficulty-label {
    font-size: 1.2rem;
    font-weight: 700;
    margin-top: 0.5rem;
}

.difficulty-cards {
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* =============================================
   V2 MOBILE-FIRST GRID SYSTEM
   Garantit que les cartes ne débordent JAMAIS
   du viewport, de l'iPhone SE (375×667) au 4K.
   ============================================= */

/* --- Mobile-first (default < 600px) --- */
.game-board.cards-8 {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: clamp(0.25rem, 1.5vmin, 0.5rem);
}

.game-board.cards-16 {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: clamp(0.2rem, 1vmin, 0.4rem);
}

.game-board.cards-24 {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(6, 1fr);
    gap: clamp(0.15rem, 0.8vmin, 0.3rem);
}

.game-board.cards-32 {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(8, 1fr);
    gap: clamp(0.1rem, 0.6vmin, 0.25rem);
}

/* Card emoji sizing — scales with viewport */
.game-board.cards-8 .card-face { font-size: clamp(1.8rem, 8vmin, 3.5rem); }
.game-board.cards-16 .card-face { font-size: clamp(1.4rem, 6vmin, 3rem); }
.game-board.cards-24 .card-face { font-size: clamp(1rem, 4.5vmin, 2.5rem); }
.game-board.cards-32 .card-face { font-size: clamp(0.8rem, 3.5vmin, 2rem); }

/* --- Small phones (< 380px, iPhone SE) --- */
@media (max-width: 380px) {
    .game-board.cards-24 .card-face { font-size: clamp(0.85rem, 3.5vmin, 1.5rem); }
    .game-board.cards-24 { gap: 0.12rem; }

    body.game-page h1 {
        font-size: 0.85rem;
    }
}

/* --- Tablets (>= 600px) --- */
@media (min-width: 600px) {
    .game-board.cards-8 {
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: repeat(2, 1fr);
        gap: clamp(0.5rem, 2vmin, 1rem);
    }

    .game-board.cards-16 {
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: repeat(4, 1fr);
        gap: clamp(0.4rem, 1.5vmin, 0.8rem);
    }

    .game-board.cards-24 {
        grid-template-columns: repeat(6, 1fr);
        grid-template-rows: repeat(4, 1fr);
        gap: clamp(0.3rem, 1.2vmin, 0.7rem);
    }

    .game-board.cards-32 {
        grid-template-columns: repeat(8, 1fr);
        grid-template-rows: repeat(4, 1fr);
        gap: clamp(0.25rem, 1vmin, 0.6rem);
    }

    body.game-page h1 {
        font-size: 0.9rem;
    }
}

/* --- Desktop (>= 1200px) --- */
@media (min-width: 1200px) {
    .game-board.cards-8 { gap: 1.5rem; }
    .game-board.cards-16 { gap: 1.2rem; }
    .game-board.cards-24 { gap: 1rem; }
    .game-board.cards-32 { gap: 0.8rem; }
}

/* --- Ultra-wide / 4K (>= 2000px) — cap card size --- */
@media (min-width: 2000px) {
    .game-board {
        max-width: 1400px;
        margin-inline: auto;
    }
}

/* Difficulty modal responsive */
@media (max-width: 900px) {
    .difficulty-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .difficulty-btn {
        padding: 0.75rem 0.5rem;
        border-radius: 12px;
        gap: 0.2rem;
    }

    .difficulty-label {
        font-size: 1rem;
    }

    .difficulty-cards {
        font-size: 0.75rem;
    }
}