body {
    min-height: 100vh;
}

.game-container {
    max-width: 1180px;
}

.game-area,
.setup-screen {
    background: var(--card-background);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.game-area {
    padding: 24px;
}

.setup-screen {
    text-align: center;
}

#back-to-modes,
#back-to-modes-from-setup {
    margin-top: 14px;
}

.bot-summary {
    margin: 0 0 18px;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--background-color);
    color: var(--text-muted);
    font-weight: 600;
}

.status {
    min-height: 1.6em;
    margin: 0 0 14px;
    color: var(--secondary-color);
    font-size: 1.15rem;
    font-weight: 700;
    text-align: center;
}

/* Reconnect banner shown on the mode-selection screen */
.reconnect-banner {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--primary-color);
    border-radius: 12px;
    background: var(--background-color);
    text-align: center;
}

.reconnect-banner p {
    margin: 0 0 10px;
    color: var(--secondary-color);
    font-weight: 600;
}

.reconnect-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.jigsaw-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 22px;
    align-items: start;
}

.board-panel {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.stats-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.stat-chip {
    padding: 6px 14px;
    border-radius: 999px;
    background: #edf6ff;
    color: #24527a;
    font-weight: 700;
    font-size: 0.92rem;
    white-space: nowrap;
}

/* The board: a CSS grid of tiles, each showing a slice of the built-in
   geometric scene art (assigned inline via background-image/background-size
   / background-position in jigsaw_party.js). aspect-ratio keeps tiles square
   regardless of the 4x3 / 4x4 preset chosen. */
.jigsaw-board {
    --cols: 4;
    --rows: 3;
    display: grid;
    grid-template-columns: repeat(var(--cols), 1fr);
    grid-template-rows: repeat(var(--rows), 1fr);
    gap: 4px;
    width: min(560px, 92vw);
    aspect-ratio: var(--cols) / var(--rows);
    padding: 8px;
    border: 3px solid #32475b;
    border-radius: 14px;
    background: #1a2330;
    box-shadow: inset 0 0 0 4px rgba(255,255,255,0.12), var(--shadow);
    touch-action: manipulation;
}

.jigsaw-tile {
    position: relative;
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    padding: 4px;
    border: 2px solid rgba(15, 23, 33, 0.55);
    border-radius: 6px;
    background-repeat: no-repeat;
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease, outline-color 0.12s ease;
    user-select: none;
}

.jigsaw-tile:hover {
    transform: scale(1.025);
    z-index: 2;
}

.jigsaw-tile.selected {
    outline: 3px solid #ffce45;
    outline-offset: -3px;
    box-shadow: 0 0 0 3px rgba(255,206,69,0.35);
    transform: scale(1.04);
    z-index: 3;
}

.jigsaw-tile.correct {
    outline: 2px solid rgba(39,174,96,0.9);
    outline-offset: -2px;
}

.jigsaw-tile:focus-visible {
    outline: 3px solid var(--focus-ring-color, #6d5efc);
    outline-offset: 2px;
}

.jigsaw-tile.locked {
    cursor: not-allowed;
}

.tile-index {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 999px;
    background: rgba(0,0,0,0.55);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 800;
    line-height: 1;
    pointer-events: none;
}

.jigsaw-tile.correct .tile-index {
    background: rgba(39,174,96,0.85);
}

.hint-text {
    color: var(--text-muted);
    font-size: 0.9rem;
    text-align: center;
}

.control-panel {
    display: grid;
    gap: 14px;
    text-align: left;
    align-content: start;
}

.rivals-panel {
    display: grid;
    gap: 8px;
}

.rival-card {
    display: grid;
    gap: 6px;
    padding: 10px;
    border: 2px solid transparent;
    border-radius: 10px;
    background: white;
}

.rival-card.you {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(41,128,185,0.12);
}

.rival-card.finished {
    border-color: var(--success-color);
    background: #effaf2;
}

.rival-card-header {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-weight: 800;
}

.rival-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.rival-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.rival-p1 { background: #d94f4f; }
.rival-p2 { background: #2f80d1; }
.rival-p3 { background: #28a76f; }
.rival-p4 { background: #d59a24; }

.rival-progress-track {
    width: 100%;
    height: 10px;
    border-radius: 999px;
    background: var(--border-color);
    overflow: hidden;
}

.rival-progress-fill {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #4da3e0, #27ae60);
    transition: width 0.25s ease;
}

.rival-card.finished .rival-progress-fill {
    background: var(--success-color);
}

.rival-card small {
    color: var(--text-muted);
}

.message-log {
    min-height: 52px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: #5f4714;
    background: #fff8df;
    font-size: 0.92rem;
}

.game-buttons {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 22px;
}

.online-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 12px;
}

.opponent-name {
    color: var(--text-muted);
    font-weight: 700;
}

.celebrate {
    animation: celebratePulse 0.8s ease-in-out 3;
}

@keyframes celebratePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.04); }
}

.jigsaw-tile.swap-pop {
    animation: swapPop 0.22s ease;
}

@keyframes swapPop {
    0% { transform: scale(1); }
    50% { transform: scale(0.92); }
    100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    .jigsaw-tile,
    .jigsaw-tile.selected,
    .jigsaw-tile:hover {
        transition: none;
        transform: none;
    }

    .jigsaw-tile.swap-pop {
        animation: none;
    }
}

@media (max-width: 860px) {
    .jigsaw-layout {
        grid-template-columns: 1fr;
    }

    .control-panel {
        text-align: center;
    }

    .rival-card {
        text-align: left;
    }
}

@media (max-width: 560px) {
    .game-area {
        padding: 14px;
    }

    .jigsaw-board {
        width: min(420px, 94vw);
        padding: 6px;
        border-width: 2px;
        gap: 3px;
    }

    .header {
        align-items: flex-start;
    }
}
