/* Fichier : style.css - Version Redesign Premium avec Glassmorphism */
:root {
    /* Color System */
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --accent-primary: #3b82f6;
    --accent-secondary: #8b5cf6;
    --accent-success: #10b981;
    --accent-warning: #f59e0b;
    --accent-danger: #ef4444;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    /* Board Colors */
    --board-bg: #1a3a5a;
    --square-bg: #c5bda5;
    --square-border: #b1a995;
    --tile-bg: linear-gradient(145deg, #fdf5e6, #e8dcc8);
    --tile-border: #dcd0ba;
    --tile-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);

    /* Player Colors */
    --p1-color: #3b82f6;
    --p1-glow: rgba(59, 130, 246, 0.5);
    --p2-color: #ef4444;
    --p2-glow: rgba(239, 68, 68, 0.5);

    /* Bonus Square Colors */
    --bonus-dl: #7dd3fc;
    --bonus-tl: #38bdf8;
    --bonus-dw: #fca5a5;
    --bonus-tw: #f87171;
    --bonus-start: #fbbf24;

    /* Glass Effect */
    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);

    /* Sizes */
    --tile-size: 40px;
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --border-radius-lg: 16px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;

    /* Background Gradient */
    --body-bg-gradient: linear-gradient(-45deg, #0f172a, #1e3a5f, #0f172a, #1a2744);
}

/* Light Theme */
[data-theme="light"] {
    --bg-primary: #f1f5f9;
    --bg-secondary: #e2e8f0;
    --bg-tertiary: #cbd5e1;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --glass-bg: rgba(0, 0, 0, 0.05);
    --glass-border: rgba(0, 0, 0, 0.1);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    --body-bg-gradient: linear-gradient(-45deg, #f1f5f9, #e2e8f0, #f8fafc, #cbd5e1);
}

html {
    box-sizing: border-box;
}

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

body {
    font-family: 'Segoe UI', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    /* Fixed height */
    width: 100vw;
    margin: 0;
    padding: 0;
    color: var(--text-primary);
    background: var(--body-bg-gradient);
    background-size: 400% 400%;
    animation: gradientShift 15s ease infinite;
    overflow-y: auto;
    /* Allow scroll if needed */
}

@keyframes gradientShift {

    0%,
    100% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }
}

/* Game Wrapper */
#game-wrapper {
    display: flex;
    gap: 20px;
    width: 100%;
    height: 100%;
    /* Full height */
    max-width: 100%;
    animation: fadeIn 0.5s ease;
    justify-content: center;
    padding: 10px;
    /* Add padding here instead of body */
    box-sizing: border-box;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

/* Main Content */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* Center content horizontally */
    height: 100%;
    /* Full height */
    min-width: 0;
    /* Prevent flex overflow */
}

main {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    min-height: 0;
    /* Important for flex scaling */
    padding: 10px 0;
}

/* Glassmorphism Sidebar */
.sidebar {
    width: 300px;
    flex-shrink: 0;
    height: 100%;
    /* Fill full height */
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-lg);
    padding: 20px;
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    gap: 15px;
    box-shadow: var(--glass-shadow);
    position: relative;
}

.sidebar-close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-primary);
    font-size: 1.2em;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    display: none;
}

.sidebar-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

/* Show close button on small screens */
@media (max-width: 1100px) {
    .sidebar-close-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

.history-panel {
    flex-grow: 1;
    /* Take up available space */
    min-height: 0;
    /* Enable scrolling */
    display: flex;
    flex-direction: column;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--glass-border);
}

.stats-panel {
    flex-shrink: 0;
    /* Pinned to bottom, don't shrink */
    padding-top: 10px;
}

.history-panel h3,
.stats-panel h3 {
    margin: 0 0 10px 0;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--accent-primary);
    font-size: 1em;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
}

.stats-panel p {
    margin: 8px 0;
    font-size: 0.9em;
    color: var(--text-secondary);
}

.stats-panel span {
    color: var(--text-primary);
    font-weight: 600;
}

.version-info {
    margin: 10px 0 0 0;
    font-size: 0.72em;
    color: var(--text-muted);
    text-align: center;
    letter-spacing: 0.5px;
    opacity: 0.7;
}

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

#history-list li,
.history-list-modal li {
    background: rgba(0, 0, 0, 0.2);
    padding: 10px 12px;
    border-radius: var(--border-radius-sm);
    margin-bottom: 6px;
    font-size: 0.9em;
    transition: var(--transition-fast);
}

#history-list li:hover,
.history-list-modal li:hover {
    background: rgba(0, 0, 0, 0.3);
    transform: translateX(4px);
}

#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 */
.game-header {
    display: grid;
    grid-template-columns: minmax(100px, 150px) 1fr minmax(100px, 150px);
    align-items: center;
    gap: 15px;
    padding: 10px;
    width: 100%;
    box-sizing: border-box;
}

/* Score Panels - Glassmorphism */
.score-panel {
    text-align: center;
    padding: 10px 15px;
    border-radius: var(--border-radius);
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    transition: all var(--transition-normal);
    position: relative;
    flex: 1;
    min-width: 0;
}

.score-panel::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: transparent;
    border-radius: 0 0 var(--border-radius) var(--border-radius);
    transition: var(--transition-normal);
}

.score-panel.active-player {
    transform: scale(1.05);
    box-shadow: 0 0 30px var(--p1-glow);
}

.player-score-panel.active-player::before {
    background: var(--p1-color);
}

.opponent-score-panel.active-player::before {
    background: var(--p2-color);
}

.opponent-score-panel.active-player {
    box-shadow: 0 0 30px var(--p2-glow);
}

.score-panel h2 {
    margin: 0 0 8px 0;
    font-size: 1em;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.score-panel span:not(.spinner) {
    font-size: 2.5em;
    font-weight: 700;
    background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Header Center Section */
.header-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.game-title {
    margin: 0;
    font-size: 1.5em;
    font-weight: 700;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6, #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
}

.header-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    flex-wrap: wrap;
}

.game-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    font-size: 0.9em;
    color: var(--text-secondary);
}

.header-btn {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    font-size: 1.4em;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: var(--border-radius-sm);
    opacity: 0.8;
    transition: all var(--transition-fast);
}

.header-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.15);
    transform: scale(1.1);
}

.game-info {
    font-size: 0.9em;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.game-info span {
    display: flex;
    align-items: center;
    gap: 4px;
}

#tiles-left {
    font-weight: 700;
    color: var(--accent-warning);
}

/* Timer Display */
.timer-display {
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 600;
    padding: 5px 10px;
    border-radius: var(--border-radius-sm);
    background: rgba(0, 0, 0, 0.2);
}

.timer-display.warning {
    color: var(--accent-warning);
    animation: pulse 1s infinite;
}

.timer-display.danger {
    color: var(--accent-danger);
    animation: pulse 0.5s infinite;
}

/* Hints Counter */
.hints-counter {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.9em;
    color: var(--accent-secondary);
}

/* Scrabble/* Board Grid */
/* Scrabble Board */
.scrabble-board {
    display: grid;
    /* 16x16 grid: 1 row/col for labels, 15 for game */
    grid-template-columns: 24px repeat(15, 1fr);
    grid-template-rows: 24px repeat(15, 1fr);

    /* Unified sizing formula for all viewport types:
       - Landscape (wide, short): limited by height
       - Portrait (narrow, tall): limited by width
       - Use 160px overhead for header+footer+padding in landscape
       - Use 220px overhead for header+footer+rack+controls in portrait
    */
    --board-max-portrait: calc(100vw - 40px);
    --board-max-landscape: calc(100vh - 220px);
    width: min(var(--board-max-landscape), var(--board-max-portrait));
    height: min(var(--board-max-landscape), var(--board-max-portrait));

    /* Center the board */
    margin: 0 auto;
    flex-shrink: 0;

    /* Safety constraints */
    max-width: 600px;
    max-height: 600px;
    min-width: 200px;
    min-height: 200px;

    border: 6px solid var(--bg-tertiary);
    background-color: var(--square-border);
    gap: 2px;
    border-radius: var(--border-radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4), inset 0 0 0 2px rgba(255, 255, 255, 0.1);
}

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

.square:hover:not(:has(.tile)) {
    background-color: rgba(255, 255, 255, 0.3);
}

.square.selected {
    box-shadow: inset 0 0 0 3px var(--accent-primary);
}

.square::before {
    content: attr(data-bonus);
    position: absolute;
    color: rgba(0, 0, 0, 0.6);
    font-size: 0.9em;
}

.square.dl {
    background-color: var(--bonus-dl);
}

.square.tl {
    background-color: var(--bonus-tl);
    color: white;
}

.square.dw {
    background-color: var(--bonus-dw);
}

.square.tw {
    background-color: var(--bonus-tw);
    color: white;
}

.square.start {
    background: linear-gradient(135deg, var(--bonus-start), #f97316);
}

.square.start::before {
    font-size: clamp(14px, 3vmin, 20px);
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Tiles - Premium 3D Effect */
.tile {
    background: var(--tile-bg);
    border: none;
    border-radius: 6px;
    cursor: grab;
    user-select: none;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #2c1810;
    width: var(--tile-size);
    height: var(--tile-size);
    font-size: clamp(8px, calc(var(--tile-size) / 2.5), 18px);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    box-shadow:
        0 2px 4px rgba(0, 0, 0, 0.2),
        0 4px 8px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.8),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1);
}

.tile:hover:not(.locked) {
    transform: translateY(-3px) scale(1.05);
    box-shadow:
        0 6px 12px rgba(0, 0, 0, 0.3),
        0 8px 16px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.8),
        inset 0 -1px 0 rgba(0, 0, 0, 0.1);
}

.tile.dragging {
    opacity: 0.6;
    transform: scale(1.15) rotate(5deg);
    z-index: 100;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.4);
}

.tile.selected-tile {
    box-shadow:
        0 0 0 3px var(--accent-primary),
        0 4px 12px rgba(59, 130, 246, 0.4);
    transform: translateY(-2px);
}

.tile[data-chosen-letter] span:not(.points) {
    color: var(--p2-color);
}

.tile.locked {
    cursor: default;
}

.tile span:not(.points) {
    font-size: 1.6em;
    font-weight: 800;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}

.tile .points {
    font-size: 0.55em;
    font-weight: 600;
    position: absolute;
    bottom: 2px;
    right: 3px;
    color: #5a4a3a;
}

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

/* Last Played Tile Highlight */
.tile.last-played {
    box-shadow:
        0 0 0 3px var(--accent-warning),
        0 0 10px var(--accent-warning);
    border: 1px solid var(--accent-warning);
    animation: pulseHighlight 2s infinite alternate;
}

@keyframes pulseHighlight {
    0% {
        box-shadow: 0 0 0 2px var(--accent-warning), 0 0 5px var(--accent-warning);
    }

    100% {
        box-shadow: 0 0 0 4px var(--accent-warning), 0 0 15px var(--accent-warning);
    }
}

/* Game Footer */
.game-footer {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    /* Allow wrapping */
    align-items: flex;
    justify-content: center;
    gap: 10px;
    width: 100%;
    flex-shrink: 0;
    /* Don't shrink */
}

/* Player Rack - Glassmorphism */
.player-rack {
    display: flex;
    gap: 6px;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    padding: 12px 15px;
    border-radius: var(--border-radius);
    min-height: calc(var(--tile-size) + 24px);
    flex-grow: 1;
    align-items: center;
    justify-content: center;
    box-shadow: var(--glass-shadow);
}

/* Controls */
.control-btn {
    padding: 8px 4px;
    font-size: 0.8em;
    font-weight: 700;
    border: none;
    border-radius: var(--border-radius-sm);
    color: white;
    cursor: pointer;
    transition: all var(--transition-fast);
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-align: center;
    height: auto;
    min-height: 50px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: relative;
    overflow: hidden;
}

.control-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.control-btn:hover::before {
    left: 100%;
}

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

.control-btn:active {
    transform: translateY(0);
}

#play-word-btn {
    background: linear-gradient(135deg, #10b981, #059669);
}

#play-word-btn:hover {
    background: linear-gradient(135deg, #34d399, #10b981);
}

#shuffle-rack-btn {
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
}

#shuffle-rack-btn:hover {
    background: linear-gradient(135deg, #a78bfa, #8b5cf6);
}

#exchange-btn {
    background: linear-gradient(135deg, #f59e0b, #d97706);
}

#exchange-btn:hover {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
}

#pass-turn-btn {
    background: linear-gradient(135deg, #64748b, #475569);
}

#pass-turn-btn:hover {
    background: linear-gradient(135deg, #94a3b8, #64748b);
}

#undo-btn {
    background: linear-gradient(135deg, #6366f1, #4f46e5);
}

#undo-btn:hover {
    background: linear-gradient(135deg, #818cf8, #6366f1);
}

#hint-btn {
    background: linear-gradient(135deg, #ec4899, #db2777);
}

#hint-btn:hover {
    background: linear-gradient(135deg, #f472b6, #ec4899);
}

#hint-btn:disabled {
    background: linear-gradient(135deg, #6b7280, #4b5563);
    cursor: not-allowed;
    opacity: 0.7;
}

/* Potential Score Bubble */
.potential-score-bubble {
    font-size: 1.1em;
    font-weight: 700;
    padding: 8px 15px;
    border-radius: var(--border-radius-sm);
    background: var(--glass-bg);
    min-width: 80px;
    text-align: center;
}

.potential-score-bubble.valid {
    color: var(--accent-success);
    border: 1px solid var(--accent-success);
}

.potential-score-bubble.invalid {
    color: var(--accent-danger);
    border: 1px solid var(--accent-danger);
}

/* Modals - Glassmorphism */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity var(--transition-normal);
    animation: fadeIn 0.3s ease;
}

.modal-overlay.hidden,
#game-wrapper.hidden {
    display: none;
}

.modal-box {
    background: linear-gradient(135deg, var(--bg-secondary), var(--bg-primary));
    border: 1px solid var(--glass-border);
    padding: 35px 50px;
    border-radius: var(--border-radius-lg);
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.5);
    color: var(--text-primary);
    text-align: center;
    position: relative;
    animation: modalSlideIn 0.3s ease;
    max-width: 90vw;
}

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

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

.modal-box h2 {
    font-size: 1.8em;
    margin: 0 0 20px 0;
    background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal-box button {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    border: none;
    padding: 14px 28px;
    font-size: 1.1em;
    font-weight: 600;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.modal-box button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}

/* Controls */
.controls {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    width: 100%;
    max-width: 800px;
    /* Optional: limit width if needed */
}

/* Mode Selection */
.mode-selection {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-top: 25px;
}

.mode-btn {
    padding: 15px 30px;
    font-size: 1.1em;
}



.difficulty-selection {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 20px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--border-radius);
}

.difficulty-selection p {
    margin: 0;
    font-size: 1.1em;
    color: var(--text-secondary);
}

.difficulty-buttons {
    display: flex;
    gap: 10px;
}

.mode-btn.difficulty {
    padding: 12px 20px;
    font-size: 1em;
    background: linear-gradient(135deg, #64748b, #475569);
}

.mode-btn.difficulty:hover {
    background: linear-gradient(135deg, #94a3b8, #64748b);
}

/* Settings Section in Start Modal */
.settings-section {
    margin-top: 25px;
    padding: 20px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--border-radius);
}

.settings-section h3 {
    margin: 0 0 15px 0;
    font-size: 1em;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
}

.setting-row label {
    color: var(--text-secondary);
}

.setting-row select {
    padding: 8px 15px;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--glass-border);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 1em;
    cursor: pointer;
}

/* Joker Selection */
.joker-selection {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    max-width: 360px;
    justify-content: center;
    margin-top: 15px;
}

.joker-letter {
    width: 36px;
    height: 36px;
    background: var(--tile-bg);
    color: #2c1810;
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.joker-letter:hover {
    transform: scale(1.15);
    background: linear-gradient(135deg, var(--bonus-start), #f97316);
    color: white;
}

/* Alert Box */
.modal-box.alert-box {
    max-width: 480px;
    min-width: 320px;
    padding: 30px 40px;
}

.alert-box h2 {
    font-size: 1.6em;
    color: var(--accent-warning);
    -webkit-text-fill-color: var(--accent-warning);
}

.alert-box p {
    font-size: 1.1em;
    line-height: 1.7;
    color: var(--text-secondary);
    margin-bottom: 25px;
}

.alert-buttons {
    display: flex;
    justify-content: center;
    gap: 12px;
}

.alert-buttons button {
    padding: 12px 24px;
    font-size: 1em;
    font-weight: 600;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    border: none;
    transition: all var(--transition-fast);
}

#alert-ok-btn,
#alert-confirm-btn {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
}

#alert-ok-btn:hover,
#alert-confirm-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}

.alert-buttons .hidden {
    display: none;
}

.final-score {
    font-size: 1.6em;
    font-weight: bold;
    color: var(--accent-success);
    margin-top: 20px !important;
}

.secondary-btn {
    background: linear-gradient(135deg, #64748b, #475569) !important;
    color: white;
}

.secondary-btn:hover {
    background: linear-gradient(135deg, #94a3b8, #64748b) !important;
}

/* Exchange Rack */
.exchange-rack {
    margin: 20px 0;
    justify-content: center;
    min-height: calc(var(--tile-size) + 24px);
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--border-radius);
}

.exchange-rack .tile {
    cursor: pointer;
    transition: all var(--transition-fast);
    width: var(--tile-size);
    height: var(--tile-size);
}

.exchange-rack .tile.selected {
    transform: translateY(-12px) scale(1.08);
    box-shadow:
        0 8px 20px rgba(16, 185, 129, 0.4),
        0 0 0 3px var(--accent-success);
}

/* Letter Bag Modal */
.letter-bag-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 8px;
    margin: 20px 0;
    max-height: 400px;
    overflow-y: auto;
    padding: 10px;
}

.letter-bag-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--border-radius-sm);
}

.letter-bag-item .letter {
    font-size: 1.4em;
    font-weight: 700;
}

.letter-bag-item .count {
    font-size: 0.9em;
    color: var(--accent-warning);
    font-weight: 600;
}

.letter-bag-item .points-small {
    font-size: 0.75em;
    color: var(--text-muted);
}

.letter-bag-item.empty {
    opacity: 0.4;
}

/* Rules Modal */
.rules-content {
    text-align: left;
    max-height: 60vh;
    overflow-y: auto;
    padding-right: 10px;
}

.rules-content h3 {
    color: var(--accent-primary);
    margin: 20px 0 10px;
}

.rules-content h3:first-child {
    margin-top: 0;
}

.rules-content ul {
    margin: 10px 0;
    padding-left: 20px;
}

.rules-content li {
    margin: 8px 0;
    color: var(--text-secondary);
}

/* Modal Close Button */
.modal-close-btn {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 1.8em;
    color: var(--text-muted);
    cursor: pointer;
    opacity: 0.7;
    transition: all var(--transition-fast);
    line-height: 1;
}

.modal-close-btn:hover {
    opacity: 1;
    color: var(--text-primary);
    transform: rotate(90deg);
}

/* Mobile Only */
.mobile-only {
    display: none !important;
}

/* Game Over State */
.game-over .scrabble-board,
.game-over .game-footer {
    pointer-events: none;
    opacity: 0.5;
    filter: grayscale(30%);
}

/* Blurred State for Turn Transition */
.blurred .main-content {
    filter: blur(20px);
    pointer-events: none;
}

/* Hidden utility */
.hidden {
    display: none !important;
}

/* Animations */
@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(-6px);
    }

    40%,
    80% {
        transform: translateX(6px);
    }
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

@keyframes glow {

    0%,
    100% {
        box-shadow: 0 0 5px var(--accent-primary);
    }

    50% {
        box-shadow: 0 0 20px var(--accent-primary), 0 0 30px var(--accent-primary);
    }
}

@keyframes confetti {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: translateY(-100vh) rotate(720deg);
        opacity: 0;
    }
}

.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;
}

.player-rack .tile:nth-child(1) {
    animation-delay: 0.05s;
}

.player-rack .tile:nth-child(2) {
    animation-delay: 0.1s;
}

.player-rack .tile:nth-child(3) {
    animation-delay: 0.15s;
}

.player-rack .tile:nth-child(4) {
    animation-delay: 0.2s;
}

.player-rack .tile:nth-child(5) {
    animation-delay: 0.25s;
}

.player-rack .tile:nth-child(6) {
    animation-delay: 0.3s;
}

.player-rack .tile:nth-child(7) {
    animation-delay: 0.35s;
}

.shake-animation {
    animation: shake 0.4s ease-in-out;
}

.pulse-animation {
    animation: pulse 0.5s ease-out;
}

/* Spinner */
.spinner {
    width: 22px;
    height: 22px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
    position: absolute;
    top: 10px;
    right: 10px;
}

.spinner.hidden {
    display: none;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Responsive: Hide sidebar on small screens, show as overlay on toggle */
@media (max-width: 1100px) {
    .sidebar {
        position: fixed;
        right: -300px;
        top: 12.5vh;
        height: 75vh;
        width: 280px;
        z-index: 1000;
        transition: right 0.3s ease;
        box-shadow: -5px 0 20px rgba(0, 0, 0, 0.3);
        overflow-y: auto;
        border-radius: var(--border-radius-lg) 0 0 var(--border-radius-lg);
    }

    .sidebar.visible {
        right: 0;
    }

    /* Overlay backdrop when sidebar is open */
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

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

    #game-wrapper {
        grid-template-columns: 1fr;
    }
}

/* Score Icons */
.score-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 auto 8px auto;
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.score-panel.active-player .score-icon {
    background: rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 10px var(--p1-glow);
}

.opponent-score-panel.active-player .score-icon {
    box-shadow: 0 0 10px var(--p2-glow);
}

/* On larger screens, hide the sidebar toggle button */
@media (min-width: 1101px) {
    #sidebar-toggle-btn {
        display: none;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    :root {
        --glass-bg: rgba(0, 0, 0, 0.8);
        --glass-border: rgba(255, 255, 255, 0.5);
    }

    .tile {
        border: 2px solid #000;
    }
}

/* Reduced motion */
/* Reduced motion */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    body {
        animation: none;
        background-size: 100% 100%;
    }
}

/* Short Landscape Layout (Height < 700px and Landscape) */
@media (max-height: 700px) and (orientation: landscape) and (min-width: 600px) {
    #game-wrapper {
        align-items: center;
        /* Center vertically */
    }

    .main-content {
        display: grid;
        grid-template-columns: 1fr 320px;
        /* Board takes Left, UI Panel takes Right */
        grid-template-rows: auto 1fr;
        /* Header top right, Footer bottom right */
        grid-template-areas:
            "board header"
            "board footer";
        gap: 15px;
        width: 100%;
        max-width: 1000px;
        /* Constrain width for very wide screens */
        padding: 5px;
        align-items: center;
        justify-content: center;
    }

    /* Board Area */
    main {
        grid-area: board;
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100%;
        width: 100%;
    }

    /* Maximize board height since header/footer are on side */
    .scrabble-board {
        --board-max-landscape: calc(100vh - 40px);
        /* Only padding */
        width: min(var(--board-max-landscape), var(--board-max-portrait));
        height: min(var(--board-max-landscape), var(--board-max-portrait));
        margin: 0;
    }

    /* Header (Scores & Tools) moved to Top Right */
    .game-header {
        grid-area: header;
        display: flex;
        flex-wrap: wrap;
        /* Allow wrapping */
        justify-content: space-between;
        gap: 5px;
        /* Reduced gap */
        width: 100%;
        padding: 5px;
    }

    /* Reorder elements: Scores first, Center (tools) last */
    .player-score-panel {
        order: 1;
        flex: 1 1 40%;
        padding: 6px;
        /* Compact padding */
    }

    .opponent-score-panel {
        order: 2;
        flex: 1 1 40%;
        padding: 6px;
        /* Compact padding */
    }

    .header-center {
        order: 3;
        flex: 1 1 100%;
        /* Full width row */
        margin-top: 5px;
    }

    .game-title {
        display: none;
        /* Hide title to save space */
    }

    .header-controls {
        justify-content: center;
        width: 100%;
        gap: 4px;
        /* Reduced gap */
    }

    .header-btn {
        padding: 5px 8px;
        /* Smaller header buttons */
        font-size: 1.2em;
    }

    .logo-container {
        display: none;
        /* Hide logo to save space */
    }

    /* Footer (Rack & Controls) moved to Bottom Right */
    .game-footer {
        grid-area: footer;
        flex-direction: column;
        justify-content: flex-start;
        align-items: center;
        gap: 6px;
        /* Reduced gap */
        width: 100%;
        margin-top: 0;
    }

    /* Adjust Rack to fit in side panel */
    .player-rack {
        flex-wrap: wrap;
        /* Allow wrapping if needed */
        justify-content: center;
        gap: 3px;
        /* Reduced gap */
        padding: 8px 10px;
        /* Reduced padding */
        min-height: auto;
    }

    .tile {
        /* Smaller tiles in rack for side panel */
        --tile-size: 34px;
    }

    /* Controls adaptation */
    .controls {
        grid-template-columns: repeat(3, 1fr);
        /* 2 rows of 3 buttons */
        grid-template-rows: repeat(2, auto);
        width: 100%;
        gap: 4px;
        /* Reduced gap */
    }

    .control-btn {
        min-height: 35px;
        /* Shorter buttons */
        font-size: 0.7em;
        padding: 5px 2px;
    }

    /* Force Sidebar (History/Stats) to be hidden/overlay */
    .sidebar {
        position: fixed;
        right: -300px;
        top: 0;
        height: 100vh;
        width: 280px;
        z-index: 1000;
        transition: right 0.3s ease;
        box-shadow: -5px 0 20px rgba(0, 0, 0, 0.3);
        overflow-y: auto;
    }

    .sidebar.visible {
        right: 0;
    }

    .sidebar-overlay {
        display: block;
        /* Ensure it can be shown */
        pointer-events: none;
        opacity: 0;
    }

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

    /* Ensure toggle button is visible */
    #sidebar-toggle-btn {
        display: flex !important;
    }

    .sidebar-close-btn {
        display: flex;
        /* Show close button */
        align-items: center;
        justify-content: center;
    }

    /* Compact Score Icons for short screens */
    .score-icon {
        width: 32px;
        height: 32px;
        margin-bottom: 4px;
    }

    .score-icon svg {
        width: 20px;
        height: 20px;
    }
}

.large-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
    margin: 20px auto;
}

.coord-label {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 14px;
    font-family: 'Roboto Mono', monospace;
    color: var(--text-secondary);
    user-select: none;
    pointer-events: none;
    /* Ignore clicks */
}

html[data-theme="dark"] .coord-label {
    color: #ffffff !important;
    font-weight: bold;
    opacity: 1;
}

/* Enforce Landscape on Mobile */
@media screen and (max-width: 768px) and (orientation: portrait) {
    #rotate-message {
        display: flex !important;
    }

    #game-wrapper,
    #start-modal,
    #turn-transition-overlay,
    #joker-modal,
    #custom-alert-modal,
    #end-game-modal,
    #exchange-modal,
    #history-modal,
    #loading-modal,
    #letter-bag-modal,
    #rules-modal {
        display: none !important;
    }
}

/* Updated Rules Modal Styles */
.rules-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    max-height: 70vh;
    overflow-y: auto;
    padding-right: 5px;
}

@media (max-width: 768px) {
    .rules-content {
        grid-template-columns: 1fr;
    }
}

.rule-card {
    background: rgba(255, 255, 255, 0.05);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.rule-card h3 {
    margin-top: 0;
    color: var(--primary-color);
    font-size: 1.1em;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 8px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.rule-card ul {
    padding-left: 20px;
    margin: 0;
}

.rule-card li {
    margin-bottom: 6px;
    font-size: 0.9em;
    color: var(--text-secondary);
}

.rule-card p {
    font-size: 0.9em;
    color: var(--text-secondary);
    margin: 0;
}

.bonus-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 0.85em;
    color: #fff;
    margin-right: 5px;
    background: rgba(0, 0, 0, 0.3);
}

.shortcut-key {
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Hidden Utility */
.hidden {
    display: none !important;
}

/* AI Progress Timer */
.ai-progress-container {
    width: 100%;
    max-width: 300px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    margin-top: 5px;
}

.ai-timer-text {
    font-size: 0.9em;
    color: var(--accent-secondary);
    font-weight: 600;
}

.ai-progress-bar {
    height: 6px;
    background: linear-gradient(90deg, var(--accent-success), var(--accent-warning));
    border-radius: 3px;
    width: 0%;
    /* Transition handled in JS */
}

/* Start Modal Tabs & Stats UI */
.start-modal-box {
    width: 550px !important;
    max-width: 95vw;
    padding: 30px 40px !important;
}

.start-modal-tabs {
    display: flex;
    justify-content: center;
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 25px;
    gap: 10px;
}

.start-modal-tabs .tab-btn {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    padding: 10px 20px;
    font-size: 1.1em;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    border-radius: 0;
    transition: all var(--transition-fast);
}

.start-modal-tabs .tab-btn:hover {
    color: var(--text-primary);
    transform: none;
    box-shadow: none;
}

.start-modal-tabs .tab-btn.active {
    color: var(--text-primary);
    border-bottom-color: var(--accent-primary);
    font-weight: 600;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-bottom: 25px;
}

.stat-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.stat-label {
    font-size: 0.8em;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-val {
    font-size: 1.6em;
    font-weight: 700;
    color: var(--text-primary);
}

.history-table-container {
    max-height: 220px;
    overflow-y: auto;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.2);
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
    text-align: left;
}

.history-table th, .history-table td {
    padding: 12px 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.history-table th {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
}

.history-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.8em;
    font-weight: 600;
    text-align: center;
}

.badge.win {
    background: rgba(16, 185, 129, 0.2);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge.loss {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge.draw {
    background: rgba(148, 163, 184, 0.2);
    color: #cbd5e1;
    border: 1px solid rgba(148, 163, 184, 0.3);
}

/* Word Lookup Modal */
.word-info-box {
    width: 450px !important;
    max-width: 90vw;
    padding: 25px 35px !important;
}

.word-details-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    padding: 20px;
    margin-top: 15px;
    text-align: left;
}

.word-tiles-display {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin: 20px 0;
    flex-wrap: wrap;
}

.tile.mini-tile {
    width: 32px !important;
    height: 32px !important;
    font-size: 0.8em !important;
    border-radius: 6px !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2) !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    position: relative;
}

.tile.mini-tile .tile-letter {
    font-size: 1.1em !important;
    font-weight: 700 !important;
}

.tile.mini-tile .tile-points {
    font-size: 0.55em !important;
    position: absolute;
    bottom: 2px !important;
    right: 2px !important;
}

li.history-item .lookup-word-trigger {
    cursor: pointer;
    text-decoration: underline dotted var(--accent-primary);
    transition: color var(--transition-fast);
}

li.history-item .lookup-word-trigger:hover {
    color: var(--accent-primary);
}

/* Confetti Animation */
.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 10000;
    overflow: hidden;
}

.confetti-piece {
    position: absolute;
    width: 10px;
    height: 20px;
    background: #ffd700;
    top: -20px;
    opacity: 0.9;
    animation: fall 3s linear infinite;
}

@keyframes fall {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(105vh) rotate(360deg);
        opacity: 0;
    }
}