/* ===== Game board =====
   The board has a fixed pixel size (map tiles * TILE_SIZE). On small screens
   it is scaled visually with transform; the JS coordinates stay untouched. */
#game-board {
    position: relative;
    flex: 0 0 auto;
    overflow: hidden;
    contain: layout style;
    border: 4px solid #16351a;
    background-color: #2f7a38;
    /* Checkerboard floor (one square per tile) so empty tiles stay readable. */
    background-image: conic-gradient(#255f2c 25%, #2f7a38 0 50%, #255f2c 0 75%, #2f7a38 0);
    background-size: 100px 100px;
    transform: scale(var(--board-scale, 1));
    transform-origin: top center;
    /* Collapse the space left empty by the scale to avoid a big gap. */
    margin: 20px 0 calc(20px - 650px * (1 - var(--board-scale, 1)));
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.25), 0 16px 34px rgba(0, 0, 0, 0.45);
}

/* Static entities use left/top, so they share the board's paint surface and
   do not become compositor layers. Only players are promoted (translate3d).
   Paint containment is not a layer hint; it is added below only where an
   entity clips its own contents. */
#game-board .tile,
#game-board .player,
#game-board .bomb,
#game-board .explosion,
#game-board .powerup {
    position: absolute;
    top: 0;
    left: 0;
    box-sizing: border-box;
    /* Animations outrank inline styles, so a rule from another sheet could
       replace the renderer's transform and drag the entity to the origin. */
    animation: none;
}

/* Static tiles. The bevel borders stay so the collision edges remain crisp. */
#game-board .tile.wall {
    background: #45494d;
    background-image: linear-gradient(150deg, rgba(255, 255, 255, 0.09), rgba(0, 0, 0, 0.14));
    border-top: 3px solid #5c6166;
    border-left: 3px solid #5c6166;
    border-right: 3px solid #2b2e31;
    border-bottom: 3px solid #2b2e31;
}

#game-board .tile.block {
    background: #b06a43;
    background-image: linear-gradient(150deg, rgba(255, 255, 255, 0.14), rgba(0, 0, 0, 0.12));
    border-top: 3px solid #cd8a62;
    border-left: 3px solid #cd8a62;
    border-right: 3px solid #7c4527;
    border-bottom: 3px solid #7c4527;
}

/* Players: robot character on a coloured body.
   The body colour is the renderer's inline background (one per player), so it
   stays as the "team colour" behind the emoji - CSS cannot recolour the emoji
   itself. The shading overlay is !important only because the inline
   background shorthand would otherwise set background-image back to none. */
#game-board .player {
    z-index: 10;
    display: grid;
    place-items: center;
    border: 2px solid rgba(255, 255, 255, 0.9);
    border-radius: 0;
    background-image: linear-gradient(150deg, rgba(255, 255, 255, 0.35), rgba(0, 0, 0, 0.28)) !important;
    transition: none;
}

/* The character. A pseudo-element, so the translate3d() the renderer writes on
   the player element is never overwritten. */
#game-board .player::before {
    content: '🤖';
    font-size: 15px;
    line-height: 1;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.55);
}

/* Death reaction: one quick grey-out. Only opacity/filter are animated, never
   transform, so the player keeps its renderer-written position. */
#game-board .player.dead {
    animation: player-down 0.45s ease-out forwards;
}

@keyframes player-down {
    from {
        opacity: 1;
        filter: grayscale(0);
    }
    to {
        opacity: 0.25;
        filter: grayscale(1);
    }
}

/* Bombs: a 💣 emoji with a pulsing danger ring.
   :not(.powerup) keeps these rules off the bomb power-up (it has both classes).
   The bob animation sits on the bomb element itself (bombs use left/top), so a
   whole bomb needs only ONE compositor layer instead of one per pseudo-element.
   The ring pulses by border colour: a paint animation, so no extra layer. */
#game-board .bomb:not(.powerup) {
    z-index: 3;
    display: grid;
    place-items: center;
    background: none;
    border: none;
    contain: layout style paint;
    animation: bomb-bob 0.65s ease-in-out infinite;
}

#game-board .bomb:not(.powerup)::before {
    content: '💣';
    font-size: 34px;
    line-height: 1;
    text-shadow: 0 2px 3px rgba(0, 0, 0, 0.45);
}

/* The ring stays inside the tile: paint containment clips the bomb's children
   to its 50px box anyway. */
#game-board .bomb:not(.powerup)::after {
    content: '';
    position: absolute;
    inset: 6%;
    border: 3px solid rgba(255, 70, 70, 0.85);
    border-radius: 50%;
    animation: bomb-pulse 0.65s ease-out infinite;
}

@keyframes bomb-bob {
    0%,
    100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.12);
    }
}

@keyframes bomb-pulse {
    from {
        border-color: rgba(255, 70, 70, 0.85);
    }
    to {
        border-color: rgba(255, 70, 70, 0.15);
    }
}

/* Explosions: warm fire gradient. The pop runs on the tile itself (explosions
   use left/top), so each active blast tile needs one compositor layer instead
   of one for the tile plus one for a nested flash. */
#game-board .explosion {
    z-index: 4;
    border-radius: 10px;
    contain: layout style paint;
    background:
        radial-gradient(circle, #fff6c4 0%, #ffb300 45%, #ff5722 78%, #b71c1c 100%);
    box-shadow: 0 0 10px rgba(255, 152, 0, 0.75);
    animation: blast-pop 0.3s ease-out both;
}

@keyframes blast-pop {
    from {
        transform: scale(0.45);
    }
    to {
        transform: scale(1);
    }
}

/* Power-ups: one colour and icon per kind (type class comes from the renderer) */
#game-board .powerup {
    z-index: 2;
    display: grid;
    place-items: center;
    contain: layout style paint;
    border: 2px solid rgba(0, 0, 0, 0.35);
    border-radius: 8px;
    font-size: 24px;
    line-height: 1;
    background: #ffca28;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

/* The icon breathes on its own pseudo-element, so the item's renderer-written
   translate3d() is never overwritten. */
#game-board .powerup::after {
    animation: powerup-breathe 1.6s ease-in-out infinite;
}

@keyframes powerup-breathe {
    0%,
    100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.12);
    }
}

#game-board .powerup.bomb {
    background: #ffca28;
    border-color: #f57f17;
}

/* Respect reduced-motion: keep the looks, drop the moving effects. */
@media (prefers-reduced-motion: reduce) {
    #game-board .bomb:not(.powerup),
    #game-board .bomb:not(.powerup)::after,
    #game-board .powerup::after,
    #game-board .explosion {
        animation: none;
    }

    #game-board .player.dead {
        animation: none;
        opacity: 0.25;
        filter: grayscale(1);
    }
}

#game-board .powerup.flame {
    background: #ff8a65;
    border-color: #d84315;
}

#game-board .powerup.speed {
    background: #4fc3f7;
    border-color: #0277bd;
}

#game-board .powerup.bomb::after { content: '💣'; }
#game-board .powerup.flame::after { content: '🔥'; }
#game-board .powerup.speed::after { content: '⚡'; }

/* ===== Game screen shell (board + HUD + chat) ===== */
.game-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 820px;
    min-width: 0;
}

/* In-game status message (e.g. "You Lose") pinned above the top bar. */
.player-status {
    width: 100%;
    padding: 8px 12px;
    text-align: center;
    font-weight: 700;
    letter-spacing: 1px;
    color: #fff;
    background: rgba(183, 28, 28, 0.92);
    border: 1px solid #ff5252;
    border-radius: 10px;
}

.game-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    width: 100%;
}

/* Chat / Leave buttons share one row with consistent spacing. */
.game-top-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

/* The buttons themselves come from .btn in lobby.css; only the press feedback
   and a visible keyboard focus ring are added for the game controls. */
.game-top-actions .btn:focus-visible {
    outline: 2px solid #00e676;
    outline-offset: 2px;
}

.game-top-actions .btn:active {
    transform: translateY(1px);
}

/* Hold the fixed-size board and clip its unscaled box while it is scaled. */
.board {
    --board-scale: 1;
    width: 100%;
    display: flex;
    justify-content: center;
    overflow: hidden;
}

/* Fit the board onto narrower windows. */
@media (max-width: 806px) { .board { --board-scale: 0.86; } }
@media (max-width: 700px) { .board { --board-scale: 0.72; } }
@media (max-width: 594px) { .board { --board-scale: 0.6; } }
@media (max-width: 503px) { .board { --board-scale: 0.48; } }
@media (max-width: 412px) { .board { --board-scale: 0.38; } }
@media (max-width: 336px) { .board { --board-scale: 0.3; } }

/* ===== HUD ===== */
.hud {
    flex: 1;
    min-width: 0;
}

.hud-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.hud-players {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.hud-player {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: #182029;
    border: 1px solid #26323d;
    border-radius: 999px;
    font-size: 0.85rem;
}

.hud-player.local {
    border-color: #00e676;
}

/* Colour chip per player; the order matches PLAYER_COLORS in Renderer.js. */
.hud-player::before {
    content: '';
    width: 10px;
    height: 10px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: #9fb0c0;
}

.hud-player:nth-child(1)::before { background: #e53935; }
.hud-player:nth-child(2)::before { background: #1e88e5; }
.hud-player:nth-child(3)::before { background: #43a047; }
.hud-player:nth-child(4)::before { background: #fdd835; }

.hud-name {
    color: #e8eef5;
}

.lives {
    color: #ff5252;
    letter-spacing: 1px;
}

.hud-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #9fb0c0;
    font-size: 0.85rem;
}

.hud-label {
    color: #9fb0c0;
}

.countdown {
    color: #00e676;
    font-weight: 700;
}

.hud-value {
    color: #00e676;
    font-weight: 700;
}

/* Phones: the HUD has to stay a thin strip. Sharing the first row with the
   buttons squeezed it to ~180px, so every player chip wrapped onto its own
   row and the header ended up taller than the board. */
@media (max-width: 560px) {
    .game-top {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .game-top-actions {
        justify-content: flex-end;
        margin-left: 0;
    }

    .hud-player {
        gap: 4px;
        padding: 3px 8px;
        font-size: 0.75rem;
    }

    .hud-players {
        gap: 6px;
    }

    .hud-meta {
        gap: 8px;
        font-size: 0.78rem;
    }

    /* "Players" costs a whole wrapped row on a phone. */
    .hud-label {
        display: none;
    }
}

/* ===== Game over overlay ===== */
.game-over {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: grid;
    place-items: center;
    background: rgba(9, 12, 17, 0.8);
}

.game-over-box {
    padding: 28px 32px;
    text-align: center;
    background: #182029;
    border: 1px solid #26323d;
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.game-over-title {
    margin: 0 0 6px;
    color: #00e676;
}

.game-over-winner {
    margin: 0 0 16px;
    color: #9fb0c0;
}

/* ===== Chat (classes come from ChatBox.js) ===== */
.chat {
    width: 100%;
}

.chat-modal-wrapper.active {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    background: rgba(9, 12, 17, 0.75);
}

.chat-window {
    width: min(440px, 90vw);
    max-height: 60vh;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    background: #182029;
    border: 1px solid #26323d;
    border-radius: 14px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
    color: #e8eef5;
}

.close-btn {
    padding: 2px 8px;
    font-size: 0.9rem;
    font-weight: 700;
    color: #9fb0c0;
    background: none;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.close-btn:hover,
.close-btn:focus-visible {
    color: #ff5252;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 0;
    padding: 0;
    list-style: none;
    max-height: 220px;
    overflow-y: auto;
    overscroll-behavior: contain;
    font-size: 0.85rem;
}

.chat-msg {
    color: #e8eef5;
    word-break: break-word;
}

.chat-msg.own {
    color: #00e676;
}

.chat-author {
    color: #9fb0c0;
}

.chat-error {
    margin: 0;
    min-height: 1em;
    color: #ff5252;
    font-size: 0.8rem;
}

.chat-form {
    display: flex;
    gap: 8px;
}

.chat-input {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    color: inherit;
    background: #0f141a;
    border: 1px solid #33424f;
    border-radius: 10px;
}

.chat-input:focus {
    outline: 2px solid #00e676;
    border-color: transparent;
}

.chat-form button {
    padding: 10px 16px;
    font-weight: 700;
    color: #06231a;
    background: #00e676;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.chat-form button:hover,
.chat-form button:focus-visible {
    background: #33eb8f;
}

/* ===== Shared helper: hide a screen or overlay ===== */
.hidden {
    display: none !important;
}
