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

:root {
    --line-height-base: 1.55;
    --grid-gap: clamp(4px, 0.8vw, 7px);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 2.5rem;
    --space-8: 3rem;
    --badge-text-color: #fff;
    --button-text-color: #fff;
    --cell-height: clamp(68px, min(11.5vw, calc((100dvh - 220px) / 4)), 160px);
    --header-col-w: clamp(72px, min(15vw, 17vh), 112px);
    --img-size: clamp(24px, min(4.5vw, 5.5vh), 40px);
    --label-size: clamp(0.6rem, 1.15vw, 0.78rem);
}

.material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

body {
    font-family: var(--font-family-base);
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: var(--line-height-base);
    min-height: 100dvh;
}

/* ── Game Container ─────────────────────────────── */
.game-container {
    max-width: 900px;
    margin: 0 auto;
    padding: clamp(0.5rem, 2vw, 1.25rem) clamp(0.75rem, 3vw, 1.25rem);
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}

/* ── Header ─────────────────────────────────────── */
.game-header {
    text-align: center;
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
}

.game-header h1 {
    font-family: var(--font-family-heading);
    font-size: clamp(1.35rem, 4vw, 2.2rem);
    font-weight: 800;
    color: var(--primary-color);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    line-height: 1.1;
    margin-bottom: var(--space-1);
}

.game-description {
    color: var(--text-muted);
    font-size: clamp(0.78rem, 1.8vw, 0.9rem);
    margin-bottom: var(--space-3);
}

.game-date {
    font-size: 0.72rem;
    color: var(--text-muted);
    padding: 2px var(--space-2);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    white-space: nowrap;
}

.game-meta {
    display: flex;
    gap: var(--space-2);
    justify-content: center;
    flex-wrap: wrap;
}

.sport-badge,
.league-badge,
.difficulty-badge {
    padding: 3px var(--space-3);
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.sport-badge {
    background: var(--primary-color);
    color: var(--badge-text-color);
}

.league-badge {
    background: var(--surface-container-high);
    color: var(--text-color);
    outline: 1px solid var(--border-subtle);
}

.difficulty-easy   { background: #16a34a; color: #fff; }
.difficulty-medium { background: #d97706; color: #fff; }
.difficulty-hard   { background: #dc2626; color: #fff; }

/* ── Grid ───────────────────────────────────────── */
.grid-wrapper {
    max-width: 680px;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 0;
    user-select: none;
}

.grid-header,
.grid-row {
    display: grid;
    grid-template-columns: var(--header-col-w) repeat(3, 1fr);
    gap: var(--grid-gap);
    margin-bottom: var(--grid-gap);
}

.grid-cell {
    height: var(--cell-height);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: clamp(4px, 1vw, 10px);
    text-align: center;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.15s ease;
}

/* Corner — invisible */
.corner-cell {
    background: transparent;
    border: none;
    height: var(--cell-height);
}

/* Header cells */
.header-cell {
    background: var(--surface-container-high);
    border: 1px solid var(--border-subtle);
    font-size: var(--label-size);
    font-weight: 700;
    color: var(--text-color);
    gap: 4px;
}

/* Column headers: accent bar on bottom */
.column-header {
    border-bottom: 2px solid var(--primary-color);
}

/* Row headers: accent bar on right */
.row-header {
    border-right: 2px solid var(--primary-color);
}

.criterion-image {
    width: var(--img-size);
    height: var(--img-size);
    object-fit: contain;
    flex-shrink: 0;
}

.criterion-label {
    font-size: var(--label-size);
    line-height: 1.2;
    max-width: 100%;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* Answer cells */
.answer-cell {
    background: var(--surface-container-lowest);
    border: 1px solid var(--border-subtle);
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.answer-cell::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
    pointer-events: none;
}

.answer-cell:hover:not(.answered) {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary-color) 30%, transparent);
    transform: scale(1.035);
    z-index: 1;
}

.answer-cell.answered {
    cursor: default;
}

/* Correct answer */
.answer-cell.correct {
    border-color: var(--success-color);
    background: color-mix(in srgb, var(--success-color) 12%, var(--surface-container-low));
}

/* Wrong answer shake */
.answer-cell.incorrect {
    animation: shake 0.42s ease;
    border-color: var(--error-color);
}

@keyframes shake {
    0%,100% { transform: translateX(0); }
    20%      { transform: translateX(-6px); }
    40%      { transform: translateX(6px); }
    60%      { transform: translateX(-4px); }
    80%      { transform: translateX(4px); }
}

/* Cell content */
.cell-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.cell-placeholder {
    font-size: clamp(1rem, 3vw, 1.5rem);
    color: var(--border-color);
    font-weight: 300;
}

.cell-player-image {
    width: clamp(36px, 8vw, 56px);
    height: clamp(36px, 8vw, 56px);
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border-color);
}

.cell-player-initials {
    width: clamp(36px, 8vw, 56px);
    height: clamp(36px, 8vw, 56px);
    border-radius: 50%;
    background: var(--primary-color);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(0.85rem, 2.5vw, 1.25rem);
    font-weight: 700;
    flex-shrink: 0;
}

.cell-player-name {
    font-size: clamp(0.58rem, 1.2vw, 0.72rem);
    font-weight: 600;
    color: var(--text-color);
    line-height: 1.2;
    max-width: 100%;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.cell-rarity {
    font-size: clamp(0.5rem, 1vw, 0.6rem);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

.rarity-legendary .cell-rarity { background: linear-gradient(90deg, #f59e0b, #ef4444); color: #000; }
.rarity-epic      .cell-rarity { background: linear-gradient(90deg, #a855f7, #ec4899); color: #fff; }
.rarity-rare      .cell-rarity { background: #3b82f6; color: #fff; }
.rarity-uncommon  .cell-rarity { background: #10b981; color: #fff; }
.rarity-common    .cell-rarity { background: #6b7280; color: #fff; }

/* ── Stats Bar ──────────────────────────────────── */
.game-stats {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--space-5);
    padding: var(--space-2) var(--space-5);
    background: var(--surface-container-high);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    max-width: 680px;
    margin: auto auto var(--space-3);
    width: 100%;
}

.stat-item {
    display: flex;
    align-items: baseline;
    gap: var(--space-1);
    font-size: 0.88rem;
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    color: var(--primary-color);
    font-weight: 800;
    font-size: 1.35rem;
    line-height: 1;
}

.stat-total {
    color: var(--text-muted);
    font-size: 0.78rem;
}

/* ── Modal ──────────────────────────────────────── */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface-container);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
    max-width: 480px;
    width: 100%;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    animation: modal-in 0.18s ease;
}

@keyframes modal-in {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.modal-header h2 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-color);
}

.modal-close {
    background: var(--surface-container-high);
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.modal-close:hover {
    background: var(--surface-container-highest);
    color: var(--text-color);
}

.modal-body {
    padding: var(--space-4) var(--space-5);
    overflow-y: auto;
    flex: 1;
}

.player-search-input {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    background: var(--surface-container-low);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-color);
    font-size: 0.95rem;
    font-family: var(--font-family-base);
    margin-bottom: var(--space-4);
    transition: border-color 0.15s;
}

.player-search-input::placeholder {
    color: var(--text-muted);
}

.player-search-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.player-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    max-height: 340px;
    overflow-y: auto;
}

.player-list-empty,
.player-list-error {
    text-align: center;
    padding: var(--space-6) var(--space-4);
    color: var(--text-muted);
    font-size: 0.9rem;
}

.player-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    background: var(--surface-container-low);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.12s;
}

.player-item:hover {
    background: var(--surface-container-high);
    border-color: var(--primary-color);
    transform: translateX(3px);
}

.player-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--surface-container-high);
}

.player-info {
    flex: 1;
    min-width: 0;
}

.player-name {
    font-weight: 600;
    font-size: 0.92rem;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-meta {
    display: flex;
    gap: var(--space-1);
    margin-top: 3px;
    flex-wrap: wrap;
}

.player-nationality,
.player-position {
    font-size: 0.72rem;
    padding: 1px var(--space-2);
    background: var(--surface-container-high);
    border-radius: 4px;
    color: var(--text-muted);
}

/* ── Complete Modal ──────────────────────────────── */
.game-complete-modal .modal-body {
    text-align: center;
    padding: var(--space-6) var(--space-5);
}

.complete-stats {
    display: flex;
    justify-content: space-around;
    margin: var(--space-5) 0;
    gap: var(--space-4);
}

.complete-stat-value {
    font-size: 2.8rem;
    font-weight: 800;
    color: var(--primary-color);
    line-height: 1;
    margin-bottom: var(--space-1);
}

.complete-stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-color);
    color: var(--button-text-color);
    border: none;
    padding: var(--space-3) var(--space-6);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: filter 0.15s, transform 0.12s;
    letter-spacing: 0.02em;
}

.btn-primary:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

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

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-md);
    font-family: var(--font-family-base);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.btn-secondary:hover {
    background: var(--surface-container-highest);
    color: var(--text-color);
}

.btn-secondary[hidden] {
    display: none;
}

/* ── Grid navigation ─────────────────────────────── */
.game-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-2);
}

.game-nav-dates {
    display: flex;
    gap: var(--space-1);
}

.game-nav-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
}

.game-nav-link:hover {
    background: var(--surface-container-high);
    color: var(--text-color);
}

.game-nav-link .material-symbols-outlined {
    font-size: 1.2rem;
}

/* ── How to play ─────────────────────────────────── */
.howto-open {
    background: none;
    border: 1px solid var(--border-color);
    font-family: inherit;
    cursor: pointer;
    min-width: 28px;
    justify-content: center;
}

.howto-rules {
    margin: 0 0 var(--space-4);
    padding-left: var(--space-5);
    display: grid;
    gap: var(--space-2);
    color: var(--text-color);
    line-height: 1.5;
}

.howto-modal .btn-primary {
    width: 100%;
}

/* ── Finished / used states ──────────────────────── */
.is-finished .answer-cell:not(.answered) {
    opacity: 0.55;
}

.player-item.is-used {
    opacity: 0.5;
    cursor: not-allowed;
}

.player-used {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--error-color);
}

/* ── Answers reveal ──────────────────────────────── */
.answers-note {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: var(--space-4);
}

.game-complete-modal .btn-secondary {
    margin-bottom: var(--space-4);
}

.answers-list {
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
    max-height: 40vh;
    overflow-y: auto;
}

.answers-list[hidden] {
    display: none;
}

.answers-cell {
    padding: var(--space-2) var(--space-3);
    background: var(--surface-container-low);
    border-radius: var(--radius-sm);
}

.answers-cell-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.answers-cell-players {
    font-size: 0.85rem;
}

/* ── Dark mode: lighten primary where used as text ── */
@media (prefers-color-scheme: dark) {
    .game-header h1,
    .stat-value,
    .complete-stat-value {
        color: color-mix(in srgb, var(--primary-color) 55%, white);
    }
}

/* ── Responsive tweaks ───────────────────────────── */
@media (max-width: 480px) {
    :root {
        --cell-height: clamp(72px, calc((100dvh - 236px) / 4), 160px);
        --header-col-w: clamp(68px, 20vw, 96px);
        --img-size: clamp(20px, 5.5vw, 32px);
        --label-size: clamp(0.55rem, 2.6vw, 0.72rem);
    }

    .game-description {
        display: none;
    }

    .game-header {
        margin-bottom: var(--space-1);
    }

    .grid-wrapper {
        margin-top: var(--space-2);
    }

    .game-stats {
        gap: var(--space-4);
        padding: var(--space-2) var(--space-4);
    }

    .stat-value {
        font-size: 1.1rem;
    }
}
