body {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 24px 12px;
}

.game-container {
    width: 100%;
    max-width: 1080px;
}

.game-area {
    background: var(--card-background);
    padding: 28px;
    border-radius: var(--radius-lg, 12px);
    box-shadow: var(--shadow);
    text-align: center;
}

.mode-btn {
    color: var(--text-color);
}

.ai-difficulty {
    margin: 4px auto 8px;
    padding: 12px 16px;
    max-width: 320px;
    width: 100%;
    background: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md, 8px);
}

.ai-difficulty label {
    display: block;
    margin-bottom: 8px;
    font-weight: 700;
    color: var(--secondary-color);
}

.ai-difficulty select {
    width: 100%;
    padding: 10px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md, 8px);
    font-size: 1rem;
    background: var(--card-background);
    color: var(--text-color);
}

.status {
    min-height: 1.6em;
    margin: 8px 0 4px;
    color: var(--secondary-color);
    font-size: 1.2rem;
    font-weight: 700;
}

.online-info,
.ai-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.ai-info.hidden,
.online-info.hidden,
.turn-indicator.hidden {
    display: none;
}

.opponent-name {
    color: var(--text-muted);
    font-weight: 600;
}

.ai-info-label {
    font-weight: 600;
    color: var(--text-muted);
}

.difficulty-btn {
    padding: 6px 14px;
    border: 2px solid var(--primary-color);
    border-radius: var(--radius-pill, 999px);
    background: var(--card-background);
    color: var(--primary-color);
    cursor: pointer;
    font-weight: 600;
    transition: var(--transition);
}

.difficulty-btn.active,
.difficulty-btn:hover {
    background: var(--primary-color);
    color: white;
}

.race-meta {
    display: flex;
    justify-content: center;
    gap: 18px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    font-weight: 600;
    color: var(--text-muted);
}

.race-timer {
    font-variant-numeric: tabular-nums;
}

/* Scoreboard */
.scoreboard {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.score-card {
    background: var(--background-color);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md, 8px);
    padding: 10px 18px;
    min-width: 100px;
    transition: var(--transition);
}

.score-card.me {
    border-color: var(--primary-color);
    box-shadow: 0 2px 8px rgba(41, 128, 185, 0.2);
}

.score-card.finished .player-name::after {
    content: ' ✓';
}

.score-card .player-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--secondary-color);
    margin-bottom: 4px;
}

.score-card .player-score {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* Layout: grid + word list side by side */
.word-search-layout {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 26px;
    flex-wrap: wrap;
    margin: 10px 0 18px;
}

.ws-grid-panel {
    display: flex;
    justify-content: center;
}

.ws-words-panel {
    min-width: 220px;
    max-width: 260px;
    text-align: left;
    background: var(--background-color);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md, 8px);
    padding: 14px 16px;
}

.ws-words-panel h2 {
    margin: 0 0 10px;
    font-size: 1.05rem;
    color: var(--secondary-color);
}

.word-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.word-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
    border-radius: var(--radius-sm, 6px);
    background: var(--card-background);
    border: 1px solid var(--border-color);
    font-weight: 700;
    letter-spacing: 1px;
}

.word-list li .word-text {
    font-family: monospace;
}

.word-list li .word-owner {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0;
    text-align: right;
}

/* Found words are marked with strike-through text + a checkmark badge,
   never by color alone, so the state reads clearly without color vision. */
.word-list li.found .word-text {
    text-decoration: line-through;
    text-decoration-thickness: 2px;
}

.word-list li.found::before {
    content: '✅';
    flex-shrink: 0;
}

.word-list li:not(.found)::before {
    content: '⬜';
    flex-shrink: 0;
    opacity: 0.5;
}

/* Grid */
.ws-grid {
    display: grid;
    grid-template-columns: repeat(10, minmax(0, 1fr));
    grid-template-rows: repeat(10, minmax(0, 1fr));
    gap: 3px;
    background: var(--border-color);
    padding: 3px;
    border-radius: var(--radius-md, 8px);
    width: min(92vw, 460px);
    aspect-ratio: 1 / 1;
    touch-action: none;
    user-select: none;
}

.ws-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--card-background);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-weight: 700;
    font-size: clamp(0.7rem, 2.6vw, 1.1rem);
    line-height: 1;
    cursor: pointer;
    padding: 0;
    box-shadow: none;
    min-height: 0;
    text-transform: uppercase;
    transition: background-color 0.12s ease, border-color 0.12s ease;
}

.ws-cell:hover {
    background: var(--background-color);
    transform: none;
    box-shadow: none;
}

.ws-cell:focus-visible {
    outline: none;
    box-shadow: inset 0 0 0 3px var(--focus-ring-color, #6d5efc);
}

/* Anchor / preview highlighting while selecting — a live, in-progress line. */
.ws-cell--anchor {
    background: var(--warning-color);
    color: #1a1a1a;
    border-color: var(--warning-color);
}

.ws-cell--preview {
    background: #fde9c8;
    border-style: dashed;
}

.ws-cell--miss {
    background: var(--danger-color);
    color: white;
    animation: ws-miss-flash 0.4s ease;
}

@keyframes ws-miss-flash {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(0.92); }
}

/* Found cells: each owner gets a distinct border style + small badge glyph
   so word ownership never relies on color alone. */
.ws-cell--found {
    font-weight: 800;
    border-width: 2px;
}

.ws-cell--found.owner-0 {
    border-style: solid;
    background: #dff5e1;
}

.ws-cell--found.owner-1 {
    border-style: dashed;
    background: #dfeaf9;
}

.ws-cell--found.owner-2 {
    border-style: dotted;
    background: #f6e6ff;
}

.ws-cell--found.owner-3 {
    border-style: double;
    border-width: 4px;
    background: #fff3d6;
}

.ws-cell--found.owner-ai {
    border-style: dashed;
    background: #fde3e3;
}

.ws-cell--found::after {
    position: absolute;
    font-size: 0.55em;
}

.ws-cell {
    position: relative;
}

.ws-cell--found[data-owner-badge]::after {
    content: attr(data-owner-badge);
    top: 1px;
    right: 2px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.guess-feedback {
    min-height: 1.6em;
    margin: 10px auto 0;
    color: #b45309;
    font-weight: 700;
}

.guess-feedback.success {
    color: var(--success-color);
}

.guess-feedback.error {
    color: var(--danger-color);
}

.race-summary {
    margin: 16px auto 0;
    padding: 14px 18px;
    max-width: 480px;
    background: var(--background-color);
    border: 2px solid var(--primary-color);
    border-radius: var(--radius-md, 8px);
    font-weight: 700;
    color: var(--secondary-color);
}

.race-summary.hidden {
    display: none;
}

.game-buttons {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 22px;
}

/* Reduced motion: no flashing/scale feedback, keep the same information via
   the immediate color/border/text change alone. */
@media (prefers-reduced-motion: reduce) {
    .ws-cell--miss {
        animation: none;
    }
}

@media (max-width: 760px) {
    .game-area {
        padding: 18px 10px;
    }

    .word-search-layout {
        gap: 14px;
    }

    .ws-words-panel {
        max-width: 100%;
        width: 100%;
        order: 2;
    }

    .ws-grid {
        width: min(94vw, 420px);
    }
}

@media (max-width: 420px) {
    .ws-grid {
        gap: 2px;
        width: 96vw;
    }

    .score-card {
        min-width: 76px;
        padding: 8px 10px;
    }

    .score-card .player-score {
        font-size: 1.3rem;
    }
}
