:root {
    --sidebar-bg: #0d1b2a;
    --sidebar-text: #e0e1dd;
    --main-bg: #f4f6f9;
    --primary-color: #1a65d6;
    --primary-hover: #1450a3;
    --success-color: #27ae60;
    --danger-color: #e74c3c;
    --panel-bg: #ffffff;
    --border-color: #e2e8f0;
}

* { box-sizing: border-box; }
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; margin: 0; display: flex; height: 100vh; height: 100dvh; background: var(--main-bg); overflow: hidden; position: relative; }

/* Sidebar - Gauche */
.sidebar { width: 320px; flex-shrink: 0; background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; overflow-y: auto; z-index: 100; box-shadow: 2px 0 10px rgba(0,0,0,0.1); transition: margin-left 0.3s ease; }
.sidebar.collapsed { margin-left: -320px; }

.sidebar-header { position: relative; padding: 15px 15px 10px; text-align: center; border-bottom: 1px solid rgba(255,255,255,0.1); }
.btn-close-sidebar { display: none; }
.sidebar-header h1 { margin: 0; color: #f1c40f; font-size: 24px; line-height: 1.2; font-weight: 800; }
.sidebar-header h1 span { color: white; display: block; font-size: 18px; }

.section-title { font-size: 12px; font-weight: bold; text-transform: uppercase; color: #8ba1b7; margin: 15px 15px 8px; display: flex; align-items: center; gap: 8px; }

.setting-group { padding: 0 15px; margin-bottom: 10px; }
.setting-label { font-size: 13px; margin-bottom: 5px; display: block; }

.btn-group { display: flex; gap: 4px; background: rgba(255,255,255,0.05); padding: 3px; border-radius: 6px; flex-wrap: wrap; }
.btn-group button { flex: 1; background: transparent; border: none; color: #a0aec0; padding: 6px 0; border-radius: 4px; cursor: pointer; font-size: 13px; font-weight: 600; transition: 0.2s; min-width: 60px; }
.btn-group button.active { background: #2c3e50; color: white; }

input[type="number"], input[type="text"] { width: 100%; padding: 8px; border-radius: 6px; border: 1px solid rgba(255,255,255,0.2); background: rgba(255,255,255,0.05); color: white; font-size: 14px; outline: none; }
input[type="text"] { background: white; color: #2d3748; border-color: #cbd5e0; }

/* Grille d'options */
.options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 0 15px;
    margin-bottom: 15px;
}

.option-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    user-select: none;
}

.option-card:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.option-card:has(input:checked) {
    background: rgba(39, 174, 96, 0.15);
    border-color: var(--success-color);
    box-shadow: 0 0 10px rgba(39, 174, 96, 0.25);
}

.option-card .option-emoji {
    font-size: 24px;
    margin-bottom: 6px;
    transition: transform 0.2s ease;
}

.option-card:active .option-emoji {
    transform: scale(1.2);
}

.option-card .option-text {
    font-size: 11px;
    font-weight: 700;
    color: #a0aec0;
    line-height: 1.2;
}

.option-card:has(input:checked) .option-text {
    color: #27ae60;
}

.option-card:has(input:disabled) {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-sidebar-action { background: #34495e; color: white; border: none; padding: 8px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 600; width: calc(100% - 30px); margin: 5px 15px; transition: 0.2s; text-align: center; }
.btn-sidebar-action:hover { background: #415b76; }

.btn-tuto { background: #8e44ad; color: white; border: none; padding: 10px; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: bold; width: calc(100% - 30px); margin: 5px 15px; transition: 0.2s; display: flex; justify-content: center; align-items: center; gap: 8px; }
.btn-tuto:hover { background: #9b59b6; }

.btn-nouvelle { background: var(--primary-color); color: white; border: none; padding: 12px; border-radius: 8px; cursor: pointer; font-size: 15px; font-weight: bold; width: calc(100% - 30px); margin: auto 15px 15px; transition: 0.2s; display: flex; justify-content: center; align-items: center; gap: 8px; }
.btn-nouvelle:hover { background: var(--primary-hover); }

/* Leaderboard - Droite */
.leaderboard { width: 450px; background: white; position: absolute; right: 0; top: 0; bottom: 0; box-shadow: -2px 0 15px rgba(0,0,0,0.15); z-index: 90; transition: right 0.3s ease; display: flex; flex-direction: column; }
.leaderboard.collapsed { right: -470px; }
.leaderboard-header { padding: 15px 20px; background: var(--primary-color); display: flex; justify-content: space-between; align-items: center; }
.leaderboard-header h2 { margin: 0; font-size: 20px; color: white; }
.leaderboard-content { padding: 15px; overflow-y: auto; flex: 1; }

.leaderboard-actions {
    padding: 12px 15px;
    display: flex;
    gap: 10px;
    border-bottom: 1px solid var(--border-color);
    background: #f8fafc;
}

.btn-leaderboard-action {
    flex: 1;
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background-color 0.2s, transform 0.1s;
}

.btn-leaderboard-action:hover {
    background: var(--primary-hover);
}

.btn-leaderboard-action.secondary {
    background: #4a5568;
}

.btn-leaderboard-action.secondary:hover {
    background: #2d3748;
}

.btn-leaderboard-action:active {
    transform: scale(0.98);
}

.score-table { width: 100%; border-collapse: collapse; font-size: 13px; text-align: center; }
.score-table th, .score-table td { border: 1px solid #cbd5e0; padding: 8px 4px; }
.score-table th { background: #f8fafc; color: #2d3748; font-weight: bold; }
.score-table td.total-col { font-weight: bold; color: var(--primary-color); background: #f0f4f8; }

/* Main Content */
.main { flex: 1; display: flex; flex-direction: column; padding: 20px; position: relative; height: 100%; min-width: 0; transition: box-shadow 0.2s, margin-right 0.3s ease; }
.main.leaderboard-open { margin-right: 450px; }
.main.flash-red { animation: flashRed 1s infinite; }
@keyframes flashRed { 0% { box-shadow: inset 0 0 0px transparent; } 50% { box-shadow: inset 0 0 40px var(--danger-color); } 100% { box-shadow: inset 0 0 0px transparent; } }

.top-bar { display: flex; justify-content: space-between; align-items: center; background: var(--panel-bg); padding: 15px 25px; border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,0.03); margin-bottom: 20px; z-index: 20; }
.top-bar-left { display: flex; align-items: center; gap: 15px; }
.top-bar h2 { margin: 0; font-size: 22px; color: #2d3748; font-weight: 700; }

.btn-icon { background: #e2e8f0; border: none; color: #4a5568; font-size: 20px; cursor: pointer; border-radius: 8px; width: 44px; height: 44px; display: flex; justify-content: center; align-items: center; transition: 0.2s; }
.btn-icon:hover { background: #cbd5e0; }
.btn-icon.active { background: var(--primary-color); color: white; }

.stats { display: flex; gap: 15px; align-items: center; }
.stat-box { background: #f8fafc; padding: 10px 20px; border-radius: 8px; text-align: center; box-shadow: inset 0 0 0 1px var(--border-color); min-width: 90px; }
.stat-box .label { font-size: 12px; color: #718096; text-transform: uppercase; font-weight: bold; margin-bottom: 4px; }
.stat-box .value { font-size: 18px; color: #2d3748; font-weight: 800; display: flex; align-items: center; justify-content: center; gap: 5px;}

.stat-box.timer-box { background: #fff5f5; box-shadow: inset 0 0 0 1px #feb2b2; }
.stat-box.timer-box .value { color: #e53e3e; }
.btn-pause { background: none; border: none; cursor: pointer; font-size: 18px; padding: 0; color: #e53e3e; transition: transform 0.1s; }
.btn-pause:hover { transform: scale(1.2); }

/* Canvas Area */
.canvas-wrapper { flex: 1; background: var(--panel-bg); border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,0.03); overflow: hidden; position: relative; display: flex; justify-content: center; align-items: center; z-index: 10; }
canvas { cursor: crosshair; max-width: 100%; max-height: 100%; display: block; touch-action: none; }

/* Bottom Control Area */
.bottom-panel { background: #ffffff; border: 1px solid var(--border-color); border-radius: 12px; padding: 15px 25px; margin-top: 20px; display: flex; align-items: center; justify-content: space-between; box-shadow: 0 2px 10px rgba(0,0,0,0.03); min-height: 85px; z-index: 20;}
.feedback-text { font-size: 16px; color: #4a5568; font-weight: 500; flex: 1;}
.controls-right { display: flex; gap: 10px; align-items: center; }

.btn-joker { background: #f39c12; color: white; border: none; padding: 12px 15px; border-radius: 8px; cursor: pointer; font-size: 15px; font-weight: bold; transition: 0.2s; display: flex; align-items: center; gap: 8px; }
.btn-joker:hover:not(:disabled) { background: #e67e22; }
.btn-joker:disabled { background: #fdebd0; cursor: not-allowed; color: #d35400; }

.btn-joker-line { background: #9b59b6; color: white; border: none; padding: 12px 15px; border-radius: 8px; cursor: pointer; font-size: 15px; font-weight: bold; transition: 0.2s; display: flex; align-items: center; gap: 8px; }
.btn-joker-line:hover:not(:disabled) { background: #8e44ad; }
.btn-joker-line:disabled { background: #e8daef; cursor: not-allowed; color: #6c3483; }

.btn-action { background: var(--primary-color); color: white; border: none; padding: 14px 25px; border-radius: 8px; cursor: pointer; font-size: 16px; font-weight: bold; transition: 0.2s; min-width: 200px; }
.btn-action:hover:not(:disabled) { background: var(--primary-hover); }
.btn-action:disabled { background: #cbd5e0; cursor: not-allowed; }
.btn-action.success { background: var(--success-color); }
.btn-action.success:hover { background: #1e8449; }

.watermark { position: absolute; bottom: 15px; right: 25px; opacity: 0.25; font-size: 13px; color: #718096; pointer-events: none; z-index: 30; font-weight: bold; }

/* Custom Modals */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.6); display: none; justify-content: center; align-items: center; z-index: 1000; opacity: 0; transition: opacity 0.3s; }
.modal-overlay.visible { display: flex; opacity: 1; }
.modal-content { background: white; padding: 30px; border-radius: 15px; text-align: center; max-width: 500px; box-shadow: 0 10px 30px rgba(0,0,0,0.2); transform: translateY(20px); transition: transform 0.3s; }
.modal-overlay.visible .modal-content { transform: translateY(0); }
.modal-title { font-size: 24px; color: #2d3748; margin-top: 0; }
.modal-body { font-size: 18px; color: #4a5568; margin: 20px 0; line-height: 1.5; }
.modal-btn { background: var(--primary-color); color: white; border: none; padding: 12px 30px; border-radius: 8px; cursor: pointer; font-size: 16px; font-weight: bold; transition: 0.2s; }
.modal-btn:hover { background: var(--primary-hover); }

/* End Screen */
.end-screen {
    flex: 1;
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.05);
    display: none;
    flex-direction: column;
    align-items: center;
    padding: 30px;
    overflow-y: auto;
    z-index: 10;
}
.table-bilan { width: 100%; max-width: 800px; border-collapse: collapse; background: white; box-shadow: 0 4px 15px rgba(0,0,0,0.05); border-radius: 8px; overflow: hidden; margin-bottom: 10px; }
.table-bilan th, .table-bilan td { padding: 12px 15px; border-bottom: 1px solid #e2e8f0; text-align: center; font-size: 14px; }
.table-bilan th { background: var(--primary-color); color: white; text-transform: uppercase; font-size: 14px; }
.table-bilan tr:last-child td { border-bottom: none; }

/* Tuto Screen */
.tuto-screen { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: var(--main-bg); z-index: 60; display: none; flex-direction: column; padding: 20px; }
.tuto-header { display: flex; justify-content: space-between; align-items: center; background: white; padding: 15px 25px; border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,0.05); margin-bottom: 20px; }
.tuto-header h2 { margin: 0; font-size: 24px; color: #2d3748; }
.tuto-grid { display: flex; gap: 20px; flex: 1; height: calc(100% - 100px); }
.tuto-box { flex: 1; background: white; border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,0.05); display: flex; flex-direction: column; overflow: hidden; transition: flex 0.3s; }
.tuto-box h3 { display: flex; justify-content: space-between; align-items: center; padding: 15px 20px; margin: 0; background: #f8fafc; border-bottom: 1px solid #e2e8f0; color: #4a5568; }
.tuto-box.collapsed h3 { padding: 15px 0; justify-content: center; border-bottom: none; }
.tuto-box.collapsed .tuto-title-text { display: none; }
.tuto-canvas-container { flex: 1; position: relative; }
.tuto-canvas-container canvas { width: 100%; height: 100%; display: block; }
.btn-return { background: var(--danger-color); color: white; border: none; padding: 12px 25px; border-radius: 8px; font-weight: bold; cursor: pointer; font-size: 16px; transition: 0.2s; }
.btn-return:hover { background: #c0392b; }

/* Responsive Design pour Mobile et Tablettes */
@media (max-width: 768px) {
    /* Mise en page globale */
    body {
        position: relative;
    }

    /* Barre latérale gauche (Sidebar) */
    .sidebar {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 500;
        width: 280px;
        box-shadow: 4px 0 15px rgba(0, 0, 0, 0.3);
    }
    .sidebar.collapsed {
        margin-left: -280px;
    }
    .btn-close-sidebar {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        right: 15px;
        top: 15px;
        background: rgba(255, 255, 255, 0.1);
        border: none;
        color: white;
        font-size: 16px;
        width: 32px;
        height: 32px;
        border-radius: 50%;
        cursor: pointer;
        transition: background-color 0.2s;
    }
    .btn-close-sidebar:hover {
        background: rgba(255, 255, 255, 0.2);
    }

    /* Zone principale */
    .main {
        padding: 8px;
    }
    .main.leaderboard-open {
        margin-right: 0; /* Pas de décalage sur mobile */
    }

    /* Barre supérieure (Top Bar) */
    .top-bar {
        padding: 6px 10px;
        margin-bottom: 8px;
        flex-direction: column;
        gap: 6px;
        align-items: stretch;
    }
    .top-bar-left {
        justify-content: space-between;
        width: 100%;
        gap: 8px;
    }
    .top-bar-left h2 {
        font-size: 14px;
        line-height: 1.3;
        flex: 1;
        margin: 0;
    }
    .btn-icon {
        width: 36px;
        height: 36px;
        font-size: 16px;
        border-radius: 6px;
    }
    .stats {
        width: 100%;
        justify-content: space-between;
        gap: 6px;
    }
    .stat-box {
        padding: 6px 8px;
        min-width: 60px;
        flex: 1;
    }
    .stat-box .label {
        font-size: 9px;
        margin-bottom: 2px;
    }
    .stat-box .value {
        font-size: 13px;
    }
    .stat-box.timer-box .value {
        font-size: 13px;
    }
    .btn-pause {
        font-size: 13px;
    }

    /* Classement (Leaderboard) */
    .leaderboard {
        width: 100%;
        max-width: 100%;
        z-index: 400;
    }
    .leaderboard.collapsed {
        right: -105%;
    }
    .leaderboard-header {
        padding: 12px 15px;
    }
    .leaderboard-header h2 {
        font-size: 18px;
    }
    .leaderboard-actions {
        padding: 8px 10px;
        gap: 8px;
    }
    .btn-leaderboard-action {
        padding: 8px 10px;
        font-size: 12px;
    }
    .score-table {
        font-size: 11px;
    }
    .score-table th, .score-table td {
        padding: 6px 3px;
    }

    /* Canvas et conteneur */
    .canvas-wrapper {
        margin-bottom: 8px;
        border-radius: 8px;
    }

    /* Bandeau inférieur (contrôles) */
    .bottom-panel {
        padding: 8px 12px;
        min-height: auto;
        margin-top: 8px;
        border-radius: 8px;
        flex-direction: column;
        gap: 6px;
        align-items: center;
        text-align: center;
    }
    .feedback-text {
        font-size: 13px;
        margin-bottom: 2px;
    }
    .controls-right {
        width: 100%;
        display: flex;
        justify-content: center;
        gap: 8px;
    }
    .btn-joker, .btn-joker-line {
        padding: 8px 10px;
        font-size: 12px;
        gap: 4px;
    }
    .btn-action {
        padding: 8px 16px;
        font-size: 13px;
        min-width: 120px;
    }

    /* Écran bilan de fin de partie */
    .end-screen {
        padding: 15px;
        border-radius: 8px;
    }
    .end-screen h2 {
        font-size: 22px !important;
        margin-bottom: 15px !important;
    }
    .table-bilan {
        font-size: 11px;
    }
    .table-bilan th, .table-bilan td {
        padding: 8px 4px;
    }
    #saveScoreContainer {
        padding: 12px;
        margin-top: 15px;
        gap: 8px;
    }
    #saveScoreContainer span {
        font-size: 13px !important;
    }
    #playerNameInput {
        padding: 8px;
        font-size: 13px;
    }

    /* Écran du Tutoriel */
    .tuto-screen {
        padding: 10px;
    }
    .tuto-header {
        padding: 10px 15px;
        margin-bottom: 10px;
    }
    .tuto-header h2 {
        font-size: 16px;
    }
    .btn-return {
        padding: 8px 16px;
        font-size: 13px;
    }
    .tuto-grid {
        flex-direction: column;
        gap: 15px;
        overflow-y: auto;
    }
    .tuto-box {
        flex: none;
        height: 320px;
    }
    .tuto-box h3 {
        padding: 10px 15px;
        font-size: 14px;
    }
}
