:root {
    --board-bg: #1a6b37;
    --board-border: #145a2d;
    --cell-normal: #5a9b6a;
    --cell-tw: #e74c3c;
    --cell-tw-text: #fff;
    --cell-dw: #e8a0bf;
    --cell-dw-text: #6b2040;
    --cell-tl: #3498db;
    --cell-tl-text: #fff;
    --cell-dl: #85c1e9;
    --cell-dl-text: #1a4060;
    --cell-center: #e8a0bf;
    --tile-bg: #f5deb3;
    --tile-text: #333;
    --tile-border: #c5a55a;
    --tile-shadow: rgba(0,0,0,0.2);
    --tile-pending-border: #ff8c00;
    --tile-pending-glow: rgba(255,140,0,0.5);
    --tile-last-border: #d4880a;
    --tile-last-glow: rgba(212,136,10,0.3);
    --tile-last-bg: #e8c878;
    --rack-bg: #6b3a1f;
    --rack-border: #4a2510;
    --rack-shadow: inset 0 2px 6px rgba(0,0,0,0.3);
    --selected-border: #3273dc;
    --selected-glow: rgba(50,115,220,0.5);
    --info-bg: #f7f7f7;
    --info-border: #ddd;
    --history-bg: #fafafa;
    --score-positive: #2ecc71;
    --score-text: #333;
    --ghost-shadow: rgba(0,0,0,0.35);
    --cell-label-size: 0.55em;
    --cell-font-size: clamp(0.55rem, 2.2vw, 0.95rem);
}

[data-theme="dark"] {
    --board-bg: #0d3520;
    --board-border: #0a2a18;
    --cell-normal: #2d5a3a;
    --cell-tw: #8b2020;
    --cell-tw-text: #ffcccc;
    --cell-dw: #6b2850;
    --cell-dw-text: #f0c0d8;
    --cell-tl: #1a4080;
    --cell-tl-text: #aaccff;
    --cell-dl: #253a60;
    --cell-dl-text: #aaccee;
    --cell-center: #6b2850;
    --tile-bg: #b89a5a;
    --tile-text: #1a1a1a;
    --tile-border: #8a7030;
    --tile-shadow: rgba(0,0,0,0.4);
    --tile-pending-border: #cc7000;
    --tile-pending-glow: rgba(204,112,0,0.5);
    --tile-last-border: #d49830;
    --tile-last-glow: rgba(212,152,48,0.3);
    --tile-last-bg: #d4b478;
    --rack-bg: #3a1a08;
    --rack-border: #2a1005;
    --selected-border: #5a9aff;
    --selected-glow: rgba(90,154,255,0.4);
    --info-bg: #2a2a3a;
    --info-border: #444;
    --history-bg: #252535;
    --score-positive: #22b060;
    --score-text: #e0e0e0;
    --ghost-shadow: rgba(0,0,0,0.6);
}

/* ÜLDPAIGUTUS */
.game-layout {
    display: flex;
    gap: 0.75rem;
    max-width: 1200px;
    margin: 0 auto;
    align-items: flex-start;
}

.game-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.game-info-panel {
    width: 220px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.game-actions-panel {
    width: 140px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.actions-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.actions-group .button {
    font-size: 0.85rem;
}

.actions-divider {
    margin: 0.25rem 0;
    border: none;
    border-top: 1px solid var(--info-border);
}

.resign-link {
    margin-top: auto;
    padding-top: 0.5rem;
    text-align: center;
}

.resign-link a {
    font-size: 0.75rem;
    color: var(--text-muted, #999);
    text-decoration: none;
    opacity: 0.7;
    transition: opacity 0.2s, color 0.2s;
}

.resign-link a:hover {
    opacity: 1;
    color: var(--cell-tw);
}

/* SKOORITABEL */
.score-panel {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.score-player {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    background: var(--info-bg);
    border: 2px solid var(--info-border);
    font-weight: 600;
    font-size: 0.95rem;
    transition: border-color 0.3s;
}

.score-player .player-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.score-player.active-turn {
    border-color: var(--score-positive);
    box-shadow: 0 0 8px rgba(46,204,113,0.3);
}

.score-player.time-warning-bg {
    border-color: #e67e22;
    box-shadow: 0 0 8px rgba(230,126,34,0.3);
    animation: scoreWarningPulse 1.5s ease-in-out infinite;
}

.score-player.time-critical-bg {
    border-color: #e74c3c;
    box-shadow: 0 0 12px rgba(231,76,60,0.4);
    animation: scoreCriticalPulse 0.6s ease-in-out infinite;
}

@keyframes scoreWarningPulse {
    0%, 100% { background: var(--info-bg); }
    50% { background: rgba(230,126,34,0.15); }
}

@keyframes scoreCriticalPulse {
    0%, 100% { background: var(--info-bg); }
    50% { background: rgba(231,76,60,0.2); }
}

.score-player .score-value {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--score-positive);
    flex-shrink: 0;
}

.mobile-only {
    display: none !important;
}

.score-player .player-clock {
    font-size: 0.95rem;
    font-weight: 700;
    font-family: 'Courier New', monospace;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    background: rgba(0,0,0,0.08);
    min-width: 3.5em;
    text-align: center;
}

[data-theme="dark"] .score-player .player-clock {
    background: rgba(255,255,255,0.08);
}

.player-clock.time-warning {
    color: #e67e22;
    background: rgba(230,126,34,0.15);
}

.player-clock.time-critical {
    color: #e74c3c;
    background: rgba(231,76,60,0.15);
    animation: timePulse 0.5s ease-in-out infinite;
}

.player-clock.time-overtime {
    color: #e74c3c;
    background: rgba(231,76,60,0.2);
    font-weight: 800;
}

@keyframes timePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}


/* MÄNGULAUD */
.board-wrapper {
    width: 100%;
    max-width: min(600px, calc(100vh - 170px));
    position: relative;
}

.board-wrapper.board-finished {
    max-width: min(600px, calc(100vh - 100px));
}

.scrabble-board {
    display: grid;
    grid-template-columns: repeat(15, 1fr);
    grid-template-rows: repeat(15, 1fr);
    gap: 1px;
    aspect-ratio: 1;
    width: 100%;
    background: var(--board-border);
    border: 3px solid var(--board-border);
    border-radius: 6px;
    user-select: none;
    -webkit-user-select: none;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}

.board-cell {
    background: var(--cell-normal);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--cell-font-size);
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.15s;
    overflow: hidden;
    touch-action: none;
}

.board-cell::before {
    content: attr(data-label);
    position: absolute;
    font-size: var(--cell-label-size);
    font-weight: 600;
    text-transform: uppercase;
    line-height: 1;
    opacity: 0.5;
    pointer-events: none;
    text-align: center;
    width: 100%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.board-cell.tw { background: var(--cell-tw); color: var(--cell-tw-text); }
.board-cell.dw { background: var(--cell-dw); color: var(--cell-dw-text); }
.board-cell.tl { background: var(--cell-tl); color: var(--cell-tl-text); }
.board-cell.dl { background: var(--cell-dl); color: var(--cell-dl-text); }

.board-cell.center-star::before {
    content: '\2605';
    font-size: 1.4em;
    opacity: 1;
}

.board-cell.drop-target {
    outline: 2.5px solid var(--tile-pending-border);
    outline-offset: -2px;
    background-color: rgba(255,200,0,0.45);
    box-shadow: inset 0 0 8px rgba(255,140,0,0.4);
}

/* KIVID LAUAL */
.board-tile {
    width: 90%;
    height: 90%;
    background: var(--tile-bg);
    color: var(--tile-text);
    border: 1.5px solid var(--tile-border);
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1em;
    position: relative;
    box-shadow: 1px 1px 2px var(--tile-shadow);
    z-index: 1;
}

.board-tile .tile-points {
    position: absolute;
    bottom: 0;
    right: 1px;
    font-size: 0.45em;
    font-weight: 500;
    line-height: 1;
    opacity: 0.7;
}

.board-tile.pending {
    border-color: var(--tile-pending-border);
    box-shadow: 0 0 6px var(--tile-pending-glow);
    cursor: grab;
    touch-action: none;
}

.board-tile.board-dragging {
    opacity: 0.2;
    border-style: dashed;
}

.board-tile.opponent-invalid {
    background: #f5c6c6;
    border-color: #d44;
    box-shadow: 0 0 8px rgba(220, 50, 50, 0.5);
    color: #a22;
    pointer-events: none;
    animation: invalidFadeOut 3s ease-out forwards;
}

.board-tile.opponent-invalid .tile-points {
    color: #c55;
}

[data-theme="dark"] .board-tile.opponent-invalid {
    background: #5c2020;
    border-color: #d44;
    color: #f88;
}

[data-theme="dark"] .board-tile.opponent-invalid .tile-points {
    color: #e77;
}

@keyframes invalidFadeOut {
    0%, 60% { opacity: 1; }
    100% { opacity: 0; }
}

/* Korduses kuvatav vale katse (view.php) — punane, ilma hajumiseta */
.board-tile.invalid-tile {
    background: #f5c6c6;
    border-color: #d44;
    border-style: dashed;
    box-shadow: 0 0 8px rgba(220, 50, 50, 0.5);
    color: #a22;
    opacity: 0.92;
}
.board-tile.invalid-tile .tile-points {
    color: #c55;
}
[data-theme="dark"] .board-tile.invalid-tile {
    background: #5c2020;
    border-color: #d44;
    color: #f88;
}
[data-theme="dark"] .board-tile.invalid-tile .tile-points {
    color: #e77;
}

.board-tile.last-placed {
    background: var(--tile-last-bg);
    border-color: var(--tile-last-border);
}

.board-tile.blank-tile {
    font-style: italic;
}

/* Mängija esiletõstmine lõppseisul (view.php) — klõps mängija nimel */
.scrabble-board.highlight-me .board-tile.tile-me,
.scrabble-board.highlight-opp .board-tile.tile-opp {
    background: var(--tile-last-bg);
    border-color: var(--tile-last-border);
}
.scrabble-board.highlight-me .board-tile.tile-opp,
.scrabble-board.highlight-opp .board-tile.tile-me {
    filter: brightness(0.78);
}

.player-row-hover {
    transition: background-color 0.15s;
}
.player-row-hover:hover {
    background-color: var(--bg-hover, rgba(0,0,0,0.04));
}

/* Replay kontrollid */
.replay-controls {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-card, #fff);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 6px;
}
.replay-buttons {
    display: flex;
    gap: 0.35rem;
    justify-content: center;
    margin-bottom: 0.5rem;
}
.replay-slider-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.replay-slider-row input[type="range"] {
    flex: 1;
    cursor: pointer;
}
.replay-counter {
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
    color: var(--text-secondary, #666);
    min-width: 60px;
    text-align: right;
}
.replay-info {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary, #666);
    text-align: center;
    min-height: 1.2em;
}
.replay-info.replay-info-invalid {
    color: #c0392b;
    font-weight: 600;
}
[data-theme="dark"] .replay-info.replay-info-invalid {
    color: #f88;
}

/* Järelvaate käeribad — mõlema mängija käik-eelne käsi */
.replay-racks {
    margin-top: 0.6rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}
.replay-rack-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.replay-rack-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary, #666);
    min-width: 5rem;
    flex: 0 0 auto;
}
.replay-rack-tiles {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
    align-items: center;
    min-height: 1.8rem;
}
.replay-rack-tile {
    width: 1.8rem;
    height: 1.8rem;
    background: var(--tile-bg);
    color: var(--tile-text);
    border: 1.5px solid var(--tile-border);
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.95rem;
    position: relative;
    box-shadow: 1px 1px 2px var(--tile-shadow);
}
.replay-rack-tile .tile-points {
    position: absolute;
    bottom: 0;
    right: 1px;
    font-size: 0.5em;
    font-weight: 500;
    line-height: 1;
    opacity: 0.7;
}
.replay-rack-tile.blank-tile {
    border-style: dashed;
}
.replay-rack-tile.replay-rack-tile-used {
    opacity: 0.4;
    outline: 2px solid var(--tile-last-border);
    outline-offset: -1px;
}
.replay-rack-empty {
    color: var(--text-muted, #999);
    font-size: 0.85rem;
}

/* Käiguanalüüs (parim võimalik käik) */
.analysis-row {
    margin-top: 0.6rem;
}
.analysis-panel {
    margin-top: 0.5rem;
    padding: 0.6rem 0.75rem;
    background: var(--bg-card, #fff);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 6px;
    font-size: 0.88rem;
    color: var(--text-primary, #333);
}
.analysis-panel .analysis-summary {
    font-weight: 600;
    margin-bottom: 0.4rem;
}
.analysis-panel .analysis-best-list {
    margin: 0;
    padding: 0;
    list-style: none;
}
.analysis-panel .analysis-best-list li {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.15rem 0.3rem;
    border-top: 1px solid var(--border-light, #eee);
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.12s;
}
.analysis-panel .analysis-best-list li:hover {
    background: var(--bg-hover, #f1f5f9);
}
.analysis-panel .analysis-best-list li.is-active-best {
    background: rgba(46, 158, 91, 0.15);
}
[data-theme="dark"] .analysis-panel .analysis-best-list li.is-active-best {
    background: rgba(46, 158, 91, 0.28);
}
.analysis-stats .stats-row {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.15rem 0;
    border-top: 1px solid var(--border-light, #eee);
}
.analysis-stats .stats-row:first-of-type {
    border-top: none;
}
.analysis-panel .analysis-best-list li .ab-words {
    font-weight: 600;
    word-break: break-word;
}
.analysis-panel .analysis-best-list li .ab-score {
    flex: 0 0 auto;
    color: var(--score-positive, #2ecc71);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.analysis-panel .analysis-note {
    margin-top: 0.4rem;
    font-size: 0.8rem;
    color: var(--text-muted, #999);
}
.analysis-verdict-better { color: var(--score-positive, #2ecc71); }
.analysis-verdict-miss { color: #e67e22; }
[data-theme="dark"] .analysis-verdict-miss { color: #f0a050; }
/* Järelvaade desktopis: laud jääb kerides nähtavale, analüüs/nupud on kõrval (mitte all) */
@media screen and (min-width: 1024px) {
    .review-board-col {
        position: sticky;
        top: 1rem;
        align-self: flex-start;
    }
}
/* Parima käigu eelvaade laual */
.board-tile.best-play {
    background: #2e9e5b;
    color: #fff;
    border-color: #1e7d44;
    box-shadow: 0 0 6px rgba(46,158,91,0.6);
    opacity: 0.92;
}
.board-tile.best-play .tile-points { opacity: 0.85; }
[data-theme="dark"] .board-tile.best-play {
    background: #2b8a52;
    border-color: #1c6b3e;
}
@media (max-width: 480px) {
    .replay-rack-tile { width: 1.6rem; height: 1.6rem; font-size: 0.85rem; }
    .replay-rack-name { min-width: 0; flex-basis: 100%; }
}

/* RIIULID */
.rack-area {
    width: 100%;
    max-width: min(600px, calc(100vh - 170px));
    margin-top: 0.5rem;
}

.tile-rack {
    display: flex;
    gap: 5px;
    justify-content: center;
    padding: 8px 14px;
    background: var(--rack-bg);
    border: 2px solid var(--rack-border);
    border-radius: 10px;
    min-height: 50px;
    box-shadow: var(--rack-shadow);
    flex-wrap: nowrap;
}

.rack-tile {
    width: clamp(36px, 11vw, 52px);
    height: clamp(42px, 13vw, 60px);
    background: var(--tile-bg);
    color: var(--tile-text);
    border: 2px solid var(--tile-border);
    border-radius: 5px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: clamp(1rem, 4vw, 1.4rem);
    font-weight: 700;
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    position: relative;
    box-shadow: 2px 2px 4px var(--tile-shadow);
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s, order 0.15s;
}

.rack-tile:hover {
    transform: translateY(-3px);
    box-shadow: 3px 5px 8px var(--tile-shadow);
}

.rack-tile.selected {
    border-color: var(--selected-border);
    box-shadow: 0 0 10px var(--selected-glow);
    transform: translateY(-5px);
}

.rack-tile .rack-tile-points {
    font-size: 0.5em;
    font-weight: 500;
    line-height: 1;
    opacity: 0.6;
    position: absolute;
    bottom: 2px;
    right: 3px;
}

.rack-tile.blank-display {
    font-style: italic;
    opacity: 0.85;
}

.rack-tile.rack-empty {
    opacity: 0.15;
    border-style: dashed;
    cursor: default;
}

.rack-tile.rack-empty:hover {
    transform: none;
    box-shadow: 2px 2px 4px var(--tile-shadow);
}

.tile-rack.has-selection .rack-tile.rack-empty {
    opacity: 0.35;
    border-color: var(--selected-border);
    cursor: pointer;
}

.rack-tile.rack-dragging {
    opacity: 0.2;
    transform: scale(0.85);
    border-style: dashed;
}

.rack-tile.rack-drop-target {
    border-color: var(--tile-pending-border);
    box-shadow: 0 0 8px var(--tile-pending-glow);
    transform: translateY(-3px) scale(1.05);
}

.tile-rack.rack-return-target {
    border-color: var(--score-positive);
    box-shadow: var(--rack-shadow), 0 0 12px rgba(46,204,113,0.4);
}

/* TEGEVUSNUPUD (mobiilne) */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    justify-content: center;
    margin-top: 0.5rem;
}

.mobile-btn-row {
    display: flex;
    gap: 0.4rem;
    justify-content: center;
    flex-wrap: wrap;
}

.action-buttons .button {
    min-width: 70px;
}

.action-buttons .button.is-light,
.game-actions-panel .button.is-light {
    border: 1px solid var(--info-border);
}

/* PAUSI OVERLAY */
.board-pause-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--board-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    z-index: 10;
}

.board-pause-overlay span {
    font-size: 2.5rem;
    font-weight: 800;
    color: #fff;
    text-shadow: 0 2px 12px rgba(0,0,0,0.4);
    letter-spacing: 0.1em;
    opacity: 0.85;
}

.rack-wrapper {
    position: relative;
}

.rack-paused-wrapper .tile-rack {
    opacity: 0.4;
    pointer-events: none;
}

.rack-pause-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--rack-bg);
    border-radius: 10px;
    z-index: 10;
}

/* MOBIILNE KÄIKUDE AJALUGU */
.mobile-history-toggle {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8rem;
    color: var(--text-link, #3273dc);
    user-select: none;
    -webkit-user-select: none;
}

.mobile-history-toggle i {
    transition: transform 0.2s;
}

.mobile-history-toggle.expanded i {
    transform: rotate(180deg);
}

.last-move-toggle {
    cursor: pointer;
    align-items: center;
    margin-left: auto; /* joonda info-kastis paremale */
    color: var(--text-link, #3273dc);
    opacity: 0.8;
    user-select: none;
    -webkit-user-select: none;
}

.last-move-toggle:hover {
    opacity: 1;
}

.last-move-toggle.is-off {
    opacity: 0.35;
}

.mobile-history-panel {
    display: none;
    background: var(--history-bg);
    border: 1px solid var(--info-border);
    border-radius: 8px;
    max-height: 200px;
    overflow-y: auto;
    font-size: 0.8rem;
}

.mobile-history-panel.expanded {
    display: block;
}

/* Püsivalt nähtav viimase käigu riba — ainult mobiilis (töölaual on terve ajalugu kõrvalribal) */
.last-move-bar {
    display: none;
    align-items: center;
    gap: 0.5rem;
    background: var(--info-bg);
    border: 1px solid var(--info-border);
    border-top: 1px dashed var(--info-border);
    border-radius: 0 0 8px 8px;
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
    color: var(--score-text);
    margin-top: -0.5rem; /* sulgeb game-info-panel'i gap'i, et riba haakuks "Kotis kive" kasti külge */
}

.last-move-bar.is-hidden {
    display: none;
}

.last-move-bar .last-move-tag {
    flex-shrink: 0;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    opacity: 0.55;
    font-weight: 600;
}

.last-move-bar .last-move-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.last-move-bar .history-words {
    font-weight: 600;
}

.last-move-bar .history-score {
    color: var(--score-positive);
    font-weight: 700;
    flex-shrink: 0;
}

.last-move-bar .history-action {
    opacity: 0.6;
    font-style: italic;
}

/* LÕPUEKRAAN */
.finished-bottom-panel {
    text-align: center;
    padding: 1rem 0;
    margin-top: 0.5rem;
}

.finished-scores {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.finished-score-item {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--score-text);
}

.finished-score-item.winner {
    color: var(--score-positive);
}

/* LOHISTAMISE GHOST */
.drag-ghost {
    position: fixed;
    pointer-events: none;
    z-index: 10000;
    width: 40px;
    height: 44px;
    background: var(--tile-bg);
    color: var(--tile-text);
    border: 2px solid var(--tile-pending-border);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 700;
    box-shadow: 0 4px 12px var(--ghost-shadow);
    transform: translate(-50%, -110%);
    opacity: 0.9;
}

@media screen and (min-width: 769px) {
    .drag-ghost {
        transform: translate(-50%, -70%);
    }
}

/* TÜHJA KIVI MODAAL */
.blank-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.blank-modal {
    background: var(--info-bg);
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 360px;
    width: 90%;
    box-shadow: 0 8px 30px rgba(0,0,0,0.3);
}

.blank-modal h3 {
    margin: 0 0 1rem;
    text-align: center;
    font-size: 1.1rem;
    color: var(--score-text);
}

.blank-letters-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
}

.blank-letter-btn {
    padding: 8px 4px;
    background: var(--tile-bg);
    color: var(--tile-text);
    border: 2px solid var(--tile-border);
    border-radius: 5px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s;
}

.blank-letter-btn:hover {
    border-color: var(--selected-border);
    transform: scale(1.1);
}

/* OOTEEKRAAN */
.waiting-screen {
    text-align: center;
    padding: 3rem 1rem;
}

.waiting-screen .game-code-display {
    font-size: 2.8rem;
    font-weight: 800;
    letter-spacing: 0.35em;
    color: var(--score-positive);
    margin: 0.25rem 0;
    font-family: 'Courier New', monospace;
    cursor: pointer;
}

.waiting-screen .invite-section {
    max-width: 500px;
    margin: 1.5rem auto 0;
}

.waiting-screen .waiting-spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 3px solid var(--info-border);
    border-top-color: var(--score-positive);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-top: 1rem;
}

.qr-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qr-modal-content {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 2rem;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* KÄIKUDE AJALUGU */
.history-panel {
    background: var(--history-bg);
    border: 1px solid var(--info-border);
    border-radius: 8px;
    max-height: 300px;
    overflow-y: auto;
}

.history-panel .panel-heading {
    background: var(--info-bg);
    border-bottom: 1px solid var(--info-border);
    padding: 0.5rem 0.75rem;
    font-weight: 600;
    font-size: 0.85rem;
    position: sticky;
    top: 0;
    z-index: 1;
    color: var(--score-text);
}

.history-item {
    padding: 0.35rem 0.75rem;
    border-bottom: 1px solid var(--info-border);
    font-size: 0.8rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--score-text);
}

.history-item:last-child {
    border-bottom: none;
}

.history-item .history-words {
    font-weight: 600;
}

.history-item .history-score {
    color: var(--score-positive);
    font-weight: 700;
}

.history-item .history-action {
    opacity: 0.6;
    font-style: italic;
}

/* INFO PANEEL */
.info-panel {
    background: var(--info-bg);
    border: 1px solid var(--info-border);
    border-radius: 8px;
    padding: 0.75rem;
    color: var(--score-text);
}

.info-panel .info-row {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0;
    font-size: 0.85rem;
}

.info-panel .info-row .info-label {
    opacity: 0.7;
}

.info-panel .info-row .info-value {
    font-weight: 600;
}

/* MÄNGU LÕPUEKRAAN */
.game-over-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    z-index: 8000;
    display: flex;
    align-items: center;
    align-items: safe center;
    justify-content: center;
    overflow-y: auto;
    padding: 1rem 0.5rem;
    box-sizing: border-box;
}

.game-over-card {
    background: var(--info-bg);
    border-radius: 16px;
    padding: 2rem;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 8px 40px rgba(0,0,0,0.4);
    animation: popIn 0.3s ease-out;
}

.game-over-card .button.is-light {
    border: 1px solid var(--info-border);
}

@keyframes popIn {
    0% { transform: scale(0.85); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.game-over-card .result-icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

.game-over-card .result-title {
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 1rem;
    color: var(--score-text);
}

.game-over-card .final-scores {
    margin-bottom: 1.5rem;
}

.game-over-card .final-score-row {
    display: flex;
    justify-content: space-between;
    padding: 0.4rem 1rem;
    font-size: 1.1rem;
    color: var(--score-text);
}

.game-over-card .final-score-row.winner {
    font-weight: 700;
    color: var(--score-positive);
}

@media (max-width: 600px) {
    .game-over-overlay {
        padding: 0.5rem 0.25rem;
    }

    .game-over-card {
        padding: 1rem 0.9rem;
        width: 100%;
        max-width: 420px;
    }

    .game-over-card .result-icon {
        font-size: 2rem;
        margin-bottom: 0.1rem;
    }

    .game-over-card .result-title {
        font-size: 1.2rem;
        margin-bottom: 0.4rem;
    }

    .game-over-card > p {
        margin-bottom: 0.4rem !important;
        font-size: 0.85rem;
    }

    .game-over-card .final-scores {
        margin-bottom: 0.5rem !important;
        margin-top: 0.25rem !important;
    }

    .game-over-card .final-score-row {
        padding: 0.2rem 0.5rem;
        font-size: 0.95rem;
    }

    .game-over-card #gameOverButtons {
        gap: 0.35rem !important;
    }

    .game-over-card #gameOverButtons .button {
        font-size: 0.85rem;
        padding: 0.4em 0.7em;
        height: auto;
    }
}

/* VAHETUSDIALOOG */
.exchange-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.exchange-modal {
    background: var(--info-bg);
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 8px 30px rgba(0,0,0,0.3);
    text-align: center;
    color: var(--score-text);
}

.exchange-tiles {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin: 1rem 0;
    flex-wrap: wrap;
}

.exchange-tile {
    width: 44px;
    height: 50px;
    background: var(--tile-bg);
    color: var(--tile-text);
    border: 2px solid var(--tile-border);
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
}

.exchange-tile.selected-exchange {
    border-color: var(--cell-tw);
    background: #ffe0e0;
    transform: scale(0.9);
}

[data-theme="dark"] .exchange-tile.selected-exchange {
    background: #5a2020;
}

/* KÄIGU INDIKAATOR */
.turn-indicator {
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
}

.turn-indicator.my-turn {
    background: rgba(46,204,113,0.15);
    color: var(--score-positive);
    border: 1px solid rgba(46,204,113,0.3);
}

.turn-indicator.opponent-turn {
    background: rgba(52,152,219,0.15);
    color: #3498db;
    border: 1px solid rgba(52,152,219,0.3);
}

.turn-indicator.paused {
    background: rgba(255,165,0,0.15);
    color: #e67e22;
    border: 1px solid rgba(255,165,0,0.3);
}

/* DESKTOP: väiksem padding et laud mahuks */
@media screen and (min-width: 769px) {
    .section {
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
    }
}

/* MOBIILNE VAADE */
@media screen and (max-width: 768px) {
    .container {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .game-layout {
        flex-direction: column;
        align-items: stretch;
    }

    .game-info-panel {
        width: 100%;
    }

    .game-actions-panel {
        display: none;
    }

    .score-panel {
        flex-direction: row;
        gap: 0.5rem;
    }

    .score-player {
        flex: 1;
        padding: 0.3rem 0.5rem;
        font-size: 0.8rem;
        min-width: 0;
    }

    .score-player .player-name {
        max-width: 80px;
    }

    .game-info-panel .turn-indicator {
        display: none;
    }

    .game-info-panel .info-panel {
        display: flex;
        flex-wrap: wrap;
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
    }

    .game-info-panel .info-panel .info-row {
        display: inline-flex;
        gap: 0.3rem;
        padding: 0.1rem 0.8rem 0.1rem 0;
        font-size: 0.8rem;
    }

    .game-info-panel .history-panel {
        display: none;
    }

    .game-info-panel .info-panel .info-row.mobile-only {
        display: inline-flex !important;
    }

    .mobile-history-panel {
        margin-bottom: 0.25rem;
    }

    /* Vähenda nimede kohal olevat tühja ruumi, et viimase käigu ribale ruumi teha */
    .section {
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
    }

    .last-move-bar {
        display: flex;
    }

    /* Kui viimase käigu riba on olemas, ühenda see "Kotis kive" kastiga:
       kasti alanurgad sirgeks ja alumine joon ära, et eraldajaks jääks vaid riba punktiirjoon */
    .game-info-panel:has(.last-move-bar:not(.is-hidden)) .info-panel {
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
        border-bottom: none;
    }

    .game-info-panel .resign-link {
        display: none;
    }

    .mobile-only {
        display: flex !important;
    }

    .board-wrapper,
    .rack-area {
        max-width: none;
        width: 100%;
    }

    .scrabble-board {
        border-radius: 4px;
        border-width: 2px;
    }

    .board-cell::before {
        font-size: 0.9em;
        opacity: 0.5;
    }

    .board-cell.center-star::before {
        font-size: 1.1em;
    }

    .rack-tile {
        width: clamp(34px, 12vw, 48px);
        height: clamp(40px, 14vw, 55px);
    }

    .action-buttons .button {
        min-width: 55px;
        font-size: 0.8rem;
        padding: 0.4em 0.6em;
    }

    .mobile-btn-row {
        gap: 0.3rem;
    }

    .section {
        padding: 0.75rem 0.25rem;
    }
}

@media screen and (max-width: 400px) {
    .tile-rack {
        gap: 3px;
        padding: 8px 10px;
    }

    .rack-tile {
        width: 38px;
        height: 44px;
        font-size: 1rem;
    }

    .board-cell {
        font-size: clamp(0.4rem, 2vw, 0.6rem);
    }
}

/* KORRA MÄRGUANNE */
.board-wrapper.turn-flash {
    animation: turnFlashAnim 2s ease-out;
}

@keyframes turnFlashAnim {
    0% { box-shadow: 0 0 0 5px rgba(46, 204, 113, 0.9); }
    30% { box-shadow: 0 0 20px 8px rgba(46, 204, 113, 0.5); }
    100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); }
}

/* VAHETAMISE NUPP KEELATUD */
.is-exchange-disabled {
    opacity: 0.45 !important;
    cursor: not-allowed !important;
}

/* ANIMATSIOONID */
.tile-place-anim {
    animation: tileDrop 0.2s ease-out;
}

@keyframes tileDrop {
    0% { transform: scale(1.2); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

.rack-tile.tile-appear-anim {
    animation: tileAppear 0.25s ease-out both;
}

@keyframes tileAppear {
    0% { transform: translateY(-20px) scale(0.5); opacity: 0; }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}

.score-popup {
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--score-positive);
    pointer-events: none;
    animation: scoreFloat 1.5s ease-out forwards;
    z-index: 100;
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

@keyframes scoreFloat {
    0% { opacity: 1; transform: translateX(-50%) translateY(0); }
    100% { opacity: 0; transform: translateX(-50%) translateY(-40px); }
}

/* SÕNA DEFINITSIOONI NUPP AJALOOS */
.word-def-btn {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    font: inherit;
    color: inherit;
    cursor: pointer;
    text-decoration: underline dotted;
    text-underline-offset: 2px;
    text-decoration-color: var(--accent-color, #3273dc);
    text-decoration-thickness: 1px;
}
.word-def-btn:hover {
    color: var(--accent-color, #3273dc);
    text-decoration-style: solid;
}

/* SÕNA DEFINITSIOONI MODAL */
.def-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.def-modal-content {
    background: var(--bg-card, #fff);
    color: var(--text-primary, #222);
    border-radius: 12px;
    width: 100%;
    max-width: 460px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
    overflow: hidden;
}
.def-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.9rem 1.1rem;
    border-bottom: 1px solid var(--border-color, #e5e5e5);
    background: var(--bg-secondary, #f8f9fa);
}
.def-modal-word {
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: 0.02em;
}
.def-modal-close {
    background: none;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text-secondary, #666);
    padding: 0 0.25rem;
}
.def-modal-close:hover {
    color: var(--text-primary, #222);
}
.def-modal-body {
    padding: 1rem 1.1rem;
    overflow-y: auto;
    flex: 1;
}
.def-modal-loading {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--text-secondary, #666);
    font-size: 0.9rem;
}
.def-modal-loading .loader {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-color, #ccc);
    border-top-color: var(--accent-color, #3273dc);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
.def-modal-list {
    margin: 0;
    padding-left: 1.25rem;
    line-height: 1.5;
}
.def-modal-list li {
    margin-bottom: 0.4rem;
}
.def-modal-list li:last-child {
    margin-bottom: 0;
}
.def-modal-lemma {
    margin: 0 0 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary, #666);
}
.def-modal-empty {
    color: var(--text-secondary, #666);
    font-style: italic;
    margin: 0;
}
.def-modal-footer {
    padding: 0.7rem 1.1rem;
    border-top: 1px solid var(--border-color, #e5e5e5);
    background: var(--bg-secondary, #f8f9fa);
    text-align: right;
    font-size: 0.88rem;
}
.def-modal-footer a {
    color: var(--accent-color, #3273dc);
    text-decoration: none;
}
.def-modal-footer a:hover {
    text-decoration: underline;
}

@media (max-width: 500px) {
    .def-modal-content { max-width: 100%; }
    .def-modal-header { padding: 0.75rem 0.9rem; }
    .def-modal-body { padding: 0.85rem 0.9rem; }
    .def-modal-footer { padding: 0.6rem 0.9rem; }
}

/* AKTIIVSED MÄNGUD AVALEHEL */
.active-games-section {
    max-width: 700px;
    margin: 0 auto 2rem;
    padding: 0 0.5rem;
}

.active-games-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.4rem;
}

.active-games-title .icon {
    color: var(--accent-color);
}

.active-games-count {
    background: var(--accent-color);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    margin-left: 0.25rem;
}

.active-games-hint {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.active-games-hint i {
    opacity: 0.6;
}

.active-game-row {
    position: relative;
    margin-bottom: 0.6rem;
}

.active-game-remove {
    position: absolute;
    top: -0.5rem;
    right: -0.5rem;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 0.8rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-card);
    transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.15s;
    z-index: 3;
}

.active-game-remove:hover {
    background: #f14668;
    border-color: #f14668;
    color: #fff;
    transform: scale(1.1);
}

.active-game-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    margin-bottom: 0;
    text-decoration: none !important;
    color: var(--text-primary);
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.active-game-card:hover {
    border-color: var(--accent-color);
    transform: translateY(-1px);
    box-shadow: var(--shadow-hover);
    color: var(--text-primary);
}

.active-game-card.is-my-turn {
    border-left: 4px solid #48c774;
    padding-left: calc(1rem - 3px);
}

.active-game-card.is-paused {
    opacity: 0.85;
}

.active-game-info {
    flex: 1;
    min-width: 0;
}

.active-game-title-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
    flex-wrap: wrap;
}

.active-game-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.active-game-name i {
    color: var(--text-secondary);
    opacity: 0.7;
}

.active-game-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: flex;
    gap: 0.85rem;
    align-items: center;
    flex-wrap: wrap;
}

.active-game-score {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.active-game-time {
    opacity: 0.7;
}

.active-game-action {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    background: var(--accent-color);
    color: #fff;
    font-weight: 600;
    font-size: 0.9rem;
    border-radius: 6px;
    white-space: nowrap;
    transition: background 0.15s;
}

.active-game-card:hover .active-game-action {
    background: var(--accent-hover);
}

@media (max-width: 600px) {
    .active-game-card {
        flex-direction: column;
        align-items: stretch;
        gap: 0.6rem;
        padding: 0.75rem;
    }

    .active-game-card.is-my-turn {
        padding-left: calc(0.75rem - 3px);
    }

    .active-game-action {
        justify-content: center;
        padding: 0.55rem 1rem;
    }

    .active-game-name {
        font-size: 0.95rem;
    }
}
