/* ============================================
   COMMON.CSS — Design system partagé Sudoo
   Utilisé par le menu (index.html) et tous les jeux
   (sudoku.html, lettro.html...). Ne PAS dupliquer ces
   règles dans les feuilles de style spécifiques à un jeu.
   ============================================ */

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px 20px;
    transition: background 0.3s ease;
}

.container {
    background: white;
    border-radius: 24px;
    padding: 8px;
    box-shadow: 0 25px 70px rgba(0, 0, 0, 0.25), 0 10px 30px rgba(102, 126, 234, 0.15);
    max-width: 600px;
    width: 100%;
    max-height: calc(100vh - 30px);
    max-height: calc(100svh - 8px);
    display: flex;
    flex-direction: column;
    /* Si l'écran est trop bas pour tout afficher, on peut défiler au lieu de perdre les boutons */
    overflow-x: hidden;
    overflow-y: auto;
}

header {
    text-align: center;
    margin-bottom: 0;
    position: relative;
}

h1 {
    color: #667eea;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: 1.75em;
    font-weight: 800;
    letter-spacing: -0.01em;
    margin-bottom: 0;
    filter: drop-shadow(0 2px 3px rgba(102, 126, 234, 0.2));
}

.back-to-menu {
    position: absolute;
    z-index: 5;
    top: 2px;
    left: 0;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 5px 13px;
    font-size: 0.78em;
    font-weight: 600;
    color: #667eea;
    background: #f6f7ff;
    border: 1px solid rgba(102, 126, 234, 0.15);
    border-radius: 20px;
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.1);
    text-decoration: none;
    transition: all 0.2s ease;
}

.back-to-menu:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
    box-shadow: 0 4px 10px rgba(102, 126, 234, 0.3);
    transform: translateX(-2px);
}

.date {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
}

.controls {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

/* Boutons */
.btn {
    flex: 1;
    padding: 9px;
    font-size: 0.95em;
    font-weight: bold;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.25s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #5a67d8 100%);
    color: white;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #5a67d8 0%, #4c51bf 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.btn-secondary {
    background: #9e9e9e;
    color: white;
}

.btn-secondary:hover {
    background: #757575;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(158, 158, 158, 0.4);
}

.btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-success {
    background: #66bb6a;
    color: white;
}

.btn-success:hover {
    background: #4caf50;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 187, 106, 0.4);
}

.btn-danger {
    background: linear-gradient(135deg, #667eea 0%, #5a67d8 100%);
    color: white;
}

.btn-danger:hover {
    background: linear-gradient(135deg, #5a67d8 0%, #4c51bf 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.btn-danger:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-notes {
    background: #ab47bc;
    color: white;
}

.btn-notes:hover {
    background: #8e24aa;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(171, 71, 188, 0.4);
}

.btn-notes:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-warning {
    background: linear-gradient(135deg, #ffa726 0%, #fb8c00 100%);
    color: white;
}

.btn-warning:hover {
    background: linear-gradient(135deg, #fb8c00 0%, #f57c00 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(251, 140, 0, 0.3);
}

.btn-warning:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-leaderboard {
    background: #ffa726;
    color: white;
    padding: 10px 24px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: bold;
    margin: 10px 0 14px;
    box-shadow: 0 3px 10px rgba(255, 167, 38, 0.3);
    transition: all 0.3s;
}

.btn-leaderboard:hover {
    background: #fb8c00;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(255, 167, 38, 0.4);
}

/* Barre de contrôle générique (timer / stats) réutilisable par tous les jeux */
.game-controls-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    row-gap: 4px;
    gap: 8px;
    margin-bottom: 6px;
    padding: 6px 0;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 10px;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
    width: 100%;
    box-sizing: border-box;
}

.timer, .stat-badge {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 1em;
    white-space: nowrap;
}

.timer-label {
    font-size: 1.2em;
}

#timer {
    color: #667eea;
    font-weight: bold;
    font-size: 1.1em;
    transition: all 0.3s ease;
}

#timer.penalty-flash {
    animation: penaltyFlash 1s ease;
}

@keyframes penaltyFlash {
    0%, 100% { color: #667eea; transform: scale(1); }
    50% { color: #ef5350; transform: scale(1.15); }
}

.stat-badge-value {
    color: #ffa726;
    font-weight: bold;
    font-size: 1.1em;
}

.message {
    text-align: center;
    padding: 8px;
    border-radius: 8px;
    font-weight: bold;
    font-size: 0.95em;
    min-height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 6px;
}

.message.success {
    background: #e8f5e9;
    color: #2e7d32;
}

.message.error {
    background: #ffebee;
    color: #c62828;
}

.message.info {
    background: #e3f2fd;
    color: #1565c0;
}

/* Modales */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    animation: fadeIn 0.3s;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.modal-content {
    background-color: #fefefe;
    margin: auto;
    padding: 30px;
    border: none;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 500px;
    animation: slideIn 0.3s;
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-content h2 {
    color: #667eea;
    text-align: center;
    margin-bottom: 20px;
}

.modal-content p {
    text-align: center;
    font-size: 1.1em;
    margin-bottom: 20px;
    color: #666;
}

.close-btn {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 20px;
}

.close-btn:hover,
.close-btn:focus {
    color: #000;
}

.time-display {
    text-align: center;
    font-size: 1.3em;
    margin: 20px 0;
    padding: 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 10px;
    color: white;
}

.final-time {
    font-weight: bold;
    font-size: 1.5em;
    margin-left: 10px;
}

.name-input-container {
    margin: 20px 0;
}

.name-input-container label {
    display: block;
    margin-bottom: 10px;
    color: #333;
    font-weight: 600;
}

.name-input-container input {
    width: 100%;
    padding: 12px;
    font-size: 1.1em;
    border: 2px solid #667eea;
    border-radius: 8px;
    box-sizing: border-box;
    transition: all 0.3s;
}

.name-input-container input:focus {
    outline: none;
    border-color: #764ba2;
    box-shadow: 0 0 10px rgba(102, 126, 234, 0.3);
}

.name-input-container input.invalid {
    border-color: #ef5350;
    box-shadow: 0 0 10px rgba(239, 83, 80, 0.3);
    animation: nameShake 0.35s ease;
}

.name-error {
    margin-top: 6px;
    color: #d32f2f;
    font-size: 0.85em;
    font-weight: 600;
}

@keyframes nameShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

/* Classement */
.leaderboard-content {
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
}

.user-rank {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    font-size: 1.3em;
    font-weight: bold;
    margin-bottom: 20px;
}

.leaderboard-header {
    display: grid;
    grid-template-columns: 80px 1fr 120px 120px;
    gap: 10px;
    padding: 15px;
    background: #f5f5f5;
    border-radius: 8px;
    font-weight: bold;
    color: #333;
    margin-bottom: 10px;
}

.leaderboard-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
    justify-content: center;
}

.leaderboard-tab {
    flex: 1;
    max-width: 200px;
    padding: 12px 24px;
    font-size: 1em;
    font-weight: 600;
    border: 2px solid #ddd;
    border-radius: 10px;
    background: white;
    color: #666;
    cursor: pointer;
    transition: all 0.3s ease;
}

.leaderboard-tab:hover {
    background: #f5f5f5;
    transform: translateY(-2px);
}

.leaderboard-tab.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.leaderboard-tab-icon {
    width: 18px;
    height: 18px;
    vertical-align: -4px;
    margin-right: 4px;
    border-radius: 4px;
    object-fit: contain;
}

.leaderboard-list {
    max-height: 400px;
    overflow-y: auto;
    transition: opacity 0.15s ease;
}

.leaderboard-list.loading-fade {
    opacity: 0.4;
}

.leaderboard-item {
    display: grid;
    grid-template-columns: 80px 1fr 120px 120px;
    gap: 10px;
    padding: 15px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    margin-bottom: 10px;
    transition: all 0.3s;
}

.leaderboard-item:hover {
    background: #f9f9f9;
    transform: translateX(5px);
}

.leaderboard-item.user-entry {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    border: 2px solid #667eea;
    font-weight: bold;
}

.leaderboard-item.top-3 {
    background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
}

.leaderboard-item.top-3:nth-child(2) {
    background: linear-gradient(135deg, #c0c0c0 0%, #e8e8e8 100%);
}

.leaderboard-item.top-3:nth-child(3) {
    background: linear-gradient(135deg, #cd7f32 0%, #e6a86a 100%);
}

.rank-col, .time-col, .date-col {
    text-align: center;
}

.name-col {
    text-align: left;
    font-weight: 600;
}

.loading {
    text-align: center;
    padding: 30px;
    color: #999;
    font-style: italic;
}

.lost-text {
    color: #e53e3e;
    font-weight: bold;
}

@media screen and (max-width: 480px) {
    h1 {
        font-size: 1.3em;
    }

    .leaderboard-header, .leaderboard-item {
        grid-template-columns: 50px 1fr 80px 70px;
        gap: 5px;
        padding: 10px;
        font-size: 0.85em;
    }
}

@media screen and (max-height: 720px) {
    body {
        padding: 4px 8px !important;
    }
    .container {
        padding: 4px 8px !important;
        max-height: calc(100vh - 8px) !important;
        max-height: calc(100svh - 4px) !important;
        border-radius: 14px !important;
    }
    h1:not(.menu-title) {
        font-size: 1.15em !important;
    }
}

.lb-time {
    font-size: 0.85em;
    opacity: 0.75;
    font-weight: 600;
}
