/* Fichier : style.css - Version corrigée pour cohérence des tailles */
:root {
    --board-bg: #1a3a5a;
    --square-bg: #c5bda5;
    --square-border: #b1a995;
    --tile-bg: #fdf5e6;
    --tile-border: #dcd0ba;
    --text-dark: #3a3a3a;
    --text-light: #ffffff;
    --p1-color: #3498db;
    --p2-color: #e74c3c;
    --bonus-dl: #a2c8ec;
    --bonus-tl: #4a90e2;
    --bonus-dw: #f5baba;
    --bonus-tw: #e15f5f;
    --bonus-start: #f8e71c;
    --success-color: #2ecc71;
    --tile-size: 40px; /* Valeur par défaut ; mise à jour par JS */
}

html {
    box-sizing: border-box;
}

*, *:before, *:after {
    box-sizing: inherit;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: var(--board-bg);
    color: var(--text-dark);
    margin: 0;
    padding: 20px;
}

#game-wrapper {
    display: flex;
    gap: 20px;
    width: 100%;
    max-width: 1200px;
}

.main-content {
    flex-grow: 1;
}

.sidebar {
    width: 280px;
    flex-shrink: 0;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 15px;
    color: var(--text-light);
    display: flex;
    flex-direction: column;
}

.history-panel {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.stats-panel {
    flex-shrink: 0;
}

.history-panel h3, .stats-panel h3 {
    border-bottom: 2px solid var(--p1-color);
    padding-bottom: 5px;
    margin-top: 0;
}

#history-list,
.history-list-modal {
    list-style-type: none;
    padding: 0;
    margin: 0;
    overflow-y: auto;
    text-align: left;
}

#history-list li,
.history-list-modal li {
    background-color: rgba(0, 0, 0, 0.2);
    padding: 8px;
    border-radius: 4px;
    margin-bottom: 5px;
    font-size: 0.9em;
}

#history-list .p1, .history-list-modal .p1 { border-left: 4px solid var(--p1-color); }
#history-list .p2, .history-list-modal .p2 { border-left: 4px solid var(--p2-color); }

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    color: var(--text-light);
}

.score-panel {
    text-align: center;
    padding: 10px 20px;
    border-radius: 8px;
    background-color: rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    border-bottom: 4px solid transparent;
    position: relative;
}

.score-panel.active-player {
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.5);
}
.player-score-panel.active-player { border-bottom-color: var(--p1-color); }
.opponent-score-panel.active-player { border-bottom-color: var(--p2-color); }

.score-panel h2 { margin: 0 0 5px 0; font-size: 1.2em; }
.score-panel span { font-size: 2em; font-weight: bold; }

.game-title {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.game-title h1 { margin-bottom: 5px; }

.header-controls {
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-btn {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 1.8em;
    cursor: pointer;
    padding: 0 10px;
    opacity: 0.7;
    transition: opacity 0.2s, transform 0.2s;
}

.header-btn:hover {
    opacity: 1;
    transform: rotate(90deg);
}

#fullscreen-btn:hover {
    transform: scale(1.1);
}

.scrabble-board {
    display: grid;
    grid-template-columns: repeat(15, 1fr);
    grid-template-rows: repeat(15, 1fr);
    width: 100%;
    max-width: 700px;
    aspect-ratio: 1 / 1;
    border: 5px solid #333;
    background-color: var(--square-border);
    gap: 1px;
}

.square {
    background-color: var(--square-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    font-size: clamp(8px, 2vmin, 10px);
    font-weight: bold;
    text-align: center;
    white-space: pre-wrap;
    overflow: hidden;
}

.square::before {
    content: attr(data-bonus);
    position: absolute;
    color: var(--text-dark);
}

.square.dl { background-color: var(--bonus-dl); }
.square.tl { background-color: var(--bonus-tl); }
.square.dw { background-color: var(--bonus-dw); }
.square.tw { background-color: var(--bonus-tw); }
.square.start { background-color: var(--bonus-start); }
.square.start::before { font-size: clamp(12px, 3vmin, 16px); }

.tile {
    background-color: var(--tile-bg);
    border: 1px solid var(--tile-border);
    border-radius: 4px;
    cursor: grab;
    user-select: none;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-dark);
    width: var(--tile-size);
    height: var(--tile-size);
    font-size: clamp(8px, calc(var(--tile-size) / 2.5), 18px);
    transition: transform 0.2s, opacity 0.2s;
}
.tile.dragging { opacity: 0.4; transform: scale(1.1); z-index: 100; }
.tile[data-chosen-letter] span:not(.points) { color: var(--p2-color); }
.tile.locked { cursor: default; }

.tile span:not(.points) {
    font-size: 1.8em;
    font-weight: bold;
}
.tile .points {
    font-size: 0.6em;
    position: absolute;
    bottom: 0.05em;
    right: 0.1em;
}

.tile[data-letter="Joker"] span:not(.points) {
    font-size: 1em !important;
}

.game-footer {
    margin-top: 15px;
    display: flex;
    align-items: center;
    gap: 20px;
}

.player-rack {
    display: flex;
    gap: 5px;
    background-color: rgba(0, 0, 0, 0.2);
    padding: 10px;
    border-radius: 8px;
    min-height: calc(var(--tile-size) + 20px);
    flex-grow: 1;
    align-items: center;
    justify-content: center;
}

.controls { display: flex; gap: 10px; align-items: center; }
.control-btn { padding: 12px 20px; font-size: 1em; border: none; border-radius: 5px; color: white; cursor: pointer; transition: background-color 0.2s; }
#play-word-btn { background-color: #27ae60; }
#play-word-btn:hover { background-color: #2ecc71; }
#shuffle-btn { background-color: #f39c12; }
#shuffle-btn:hover { background-color: #f1c40f; }
#pass-turn-btn { background-color: #95a5a6; }
#pass-turn-btn:hover { background-color: #bdc3c7; }
.potential-score-bubble { font-size: 1.2em; font-weight: bold; color: white; padding: 10px; }

.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.85); display: flex; justify-content: center; align-items: center; z-index: 1000; transition: opacity 0.3s ease-in-out; }
.modal-overlay.hidden, #game-wrapper.hidden { display: none; }
.modal-box { background-color: #2c3e50; padding: 40px 60px; border-radius: 15px; box-shadow: 0 10px 30px rgba(0,0,0,0.5); color: white; text-align: center; position: relative; }
.modal-box h2 { font-size: 2em; margin-bottom: 20px; }
.modal-box button { background-color: var(--p1-color); color: white; border: none; padding: 15px 30px; font-size: 1.2em; border-radius: 8px; cursor: pointer; transition: background-color 0.2s; }
.modal-box button:hover { background-color: #5dade2; }
.mode-selection { display: flex; flex-wrap: wrap; justify-content: center; gap: 20px; margin-top: 30px; }
.difficulty-selection { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.difficulty-selection p { margin: 0; font-size: 1.1em; color: rgba(255, 255, 255, 0.8); }
.difficulty-buttons { display: flex; gap: 10px; }
.mode-btn.difficulty { padding: 10px 20px; font-size: 1em; background-color: #6c757d; }
.mode-btn.difficulty:hover { background-color: #5a6268; }
.joker-selection { display: flex; flex-wrap: wrap; gap: 5px; max-width: 300px; justify-content: center; }
.joker-letter { width: 30px; height: 30px; background-color: var(--tile-bg); color: var(--text-dark); border-radius: 4px; display: flex; justify-content: center; align-items: center; font-weight: bold; cursor: pointer; transition: transform 0.2s; }
.joker-letter:hover { transform: scale(1.1); background-color: var(--bonus-start); }
.modal-box.alert-box { max-width: 450px; min-width: 300px; padding: 30px; }
.alert-box h2 { font-size: 1.8em; color: var(--bonus-start); margin-top: 0; }
.alert-box p { font-size: 1.1em; line-height: 1.6; color: rgba(255, 255, 255, 0.9); margin-bottom: 30px; }
#exchange-info-text { transition: color 0.3s ease; }
#exchange-info-text.error { color: var(--p2-color); font-weight: bold; animation: shake 0.4s ease-in-out; }
.alert-buttons { display: flex; justify-content: center; gap: 15px; }
.alert-buttons button { padding: 12px 25px; font-size: 1em; font-weight: bold; border-radius: 8px; cursor: pointer; border: 2px solid transparent; transition: all 0.2s ease-in-out; }
#alert-ok-btn, #alert-confirm-btn { background-color: var(--p1-color); color: white; }
#alert-ok-btn:hover, #alert-confirm-btn:hover { background-color: white; color: var(--p1-color); border-color: var(--p1-color); }
.alert-buttons .hidden { display: none; }
.final-score { font-size: 1.5em; font-weight: bold; color: white; margin-top: 20px !important; }
.game-over .scrabble-board, .game-over .game-footer { pointer-events: none; opacity: 0.6; }
.secondary-btn { background-color: #6c757d; color: white; }
.secondary-btn:hover { background-color: #5a6268; border-color: transparent !important; }
.exchange-rack { margin: 20px 0; justify-content: center; min-height: calc(var(--tile-size) + 20px); display: flex; flex-wrap: wrap; gap: 5px; }
.exchange-rack .tile { cursor: pointer; transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out; width: var(--tile-size); height: var(--tile-size); }
.exchange-rack .tile.selected { transform: translateY(-10px) scale(1.05); box-shadow: 0 5px 15px rgba(46, 204, 113, 0.7); border: 2px solid var(--success-color); }
.modal-close-btn { position: absolute; top: 10px; right: 20px; font-size: 2em; color: white; cursor: pointer; opacity: 0.7; }
.modal-close-btn:hover { opacity: 1; }
.mobile-only { display: none !important; }

@keyframes pop-in { 0% { transform: scale(0.5); opacity: 0; } 70% { transform: scale(1.1); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
@keyframes slide-in { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
@keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.15); } 100% { transform: scale(1); } }
.square .tile:not(.newly-placed):not(.dragging) { animation: pop-in 0.3s ease-out; }
.player-rack .tile { animation: slide-in 0.4s ease-out backwards; }
.shake-animation { animation: shake 0.4s ease-in-out; }
.pulse-animation { animation: pulse 0.5s ease-out; }

.spinner { width: 20px; height: 20px; border: 3px solid rgba(255, 255, 255, 0.3); border-radius: 50%; border-top-color: #fff; animation: spin 1s ease-in-out infinite; position: absolute; top: 10px; right: 10px; }
.spinner.hidden { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
    body { padding: 5px; }
    #game-wrapper { flex-direction: column; max-height: none; gap: 5px; padding: 5px; box-sizing: border-box; }
    .desktop-only { display: none !important; }
    .mobile-only { display: flex !important; }
    .scrabble-board { width: 100%; max-width: 95vw; height: auto; max-height: none; }
    .game-header { margin-bottom: 5px; }
    .game-footer { margin-top: 5px; gap: 5px; flex-direction: column; }
    .score-panel { padding: 5px 10px; }
    .score-panel h2 { font-size: 0.9em; }
    .score-panel span { font-size: 1.5em; }
    .header-btn { font-size: 1.5em; }
    .game-info { font-size: 0.8em; }
    .controls { width: 100%; justify-content: space-around; }
    .control-btn { padding: 15px 10px; font-size: 0.9em; flex-grow: 1; }
    .player-rack { min-height: calc(var(--tile-size) + 10px); padding: 5px; width: 100%; box-sizing: border-box; justify-content: center; }
    .history-list-modal { max-height: 50vh; }
    .modal-box { width: 80%; padding: 20px; }
    .potential-score-bubble { position: static; padding: 0 10px; }
    .tile[data-letter="Joker"] span:not(.points) { font-size: 1em !important; }
    .square.dl::before { content: 'LD'; }
    .square.tl::before { content: 'LT'; }
    .square.dw::before { content: 'MD'; }
    .square.tw::before { content: 'MT'; }
}