* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100vh;
    /* 100dvh (dynamic viewport height) accounts for mobile browser
       chrome (address bar) showing/hiding; 100vh alone leaves a
       cut-off or scrollable gap on many phones. Browsers that don't
       support dvh keep the 100vh above. */
    height: 100dvh;
    background: #202020;
    font-family: -apple-system, "Segoe UI", Arial, Helvetica, sans-serif;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
}

#app {
    position: relative;
    width: 100%;
    height: 100%;
}

/* ============================================================
   MENU
   ============================================================ */

.menu-frame {
    position: absolute;
    inset: 0;
    background: linear-gradient(rgba(20, 20, 20, 0.35), rgba(20, 20, 20, 0.35)),
        url("assets/img.png") center / cover no-repeat, #202020;
    /*
     * The original menu tried to load asset/img.png as a
     * resizing background (resize_background()), falling back to
     * a plain #202020 background if it wasn't found. That image
     * wasn't part of the upload, so the fallback style is used
     * here - drop a background image in and reference it below
     * to restore it, no JS resize code needed (background-size:
     * cover replaces resize_background() entirely):
     *
     * background-image: url("assets/img.png");
     * background-size: cover;
     * background-position: center;
     */
}

/* The menu frame scrolls and the panel centres itself with auto
   margins. The old absolute + translate(-50%, -50%) centring clipped
   the top/bottom of the panel (and made it unreachable) on short
   screens such as a phone in landscape, or when the on-screen
   keyboard is open. Auto margins centre it when there is room and
   let it scroll when there isn't. */
.menu-frame {
    display: flex;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
        max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.menu-panel {
    position: relative;
    flex: 0 0 auto;
    margin: auto;
    background: #262626;
    padding: 32px 36px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: min(340px, 90vw);
    box-sizing: border-box;
    border-radius: 14px;
    border: 1px solid #3a3a3a;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.menu-title {
    font-family: "Times New Roman", serif;
    font-size: clamp(24px, 7vw, 30px);
    font-weight: bold;
    color: gold;
    text-align: center;
    margin-bottom: 26px;
}

.menu-label {
    color: #cfcfcf;
    font-size: 11px;
    font-weight: bold;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    margin-top: 12px;
    margin-bottom: 5px;
}

.menu-select {
    width: 100%;
    min-height: 46px;
    padding: 10px 12px;
    margin: 8px 0;
    background: #2C2C2C;
    color: white;
    border: 1px solid #4a4a4a;
    border-radius: 8px;
    /* 16px stops iOS Safari zooming the page when a select/input
       is focused. */
    font-size: 16px;
}

.menu-button {
    width: 100%;
    min-height: 46px;
    padding: 11px;
    margin: 8px 0;
    background: #3A3A3A;
    color: white;
    border: 1px solid #555;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.menu-button:hover {
    background: #474747;
}

.menu-button:active {
    background: #525252;
}

.menu-exit-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 18px;
}

/* ============================================================
   SEARCHING OVERLAY
   ============================================================ */

.searching-frame {
    position: absolute;
    inset: 0;
    background: #151515;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    padding: 24px;
}

.searching-label {
    color: white;
    font-size: clamp(17px, 5vw, 22px);
    font-weight: bold;
    text-align: center;
}

.searching-frame .menu-button {
    width: auto;
    min-width: 140px;
    padding: 11px 28px;
}

/* ============================================================
   BOARD
   ============================================================ */

.board-container {
    position: absolute;
    inset: 0;
    display: flex;
    background: #202020;
}

.board-canvas-wrap {
    flex: 1 1 auto;
    position: relative;
    min-width: 0;
}

.board-canvas-wrap canvas {
    display: block;
    background: #202020;
    /* Prevents the double-tap-to-zoom delay/gesture on touch
       devices from swallowing taps meant for piece selection, and
       stops pinch-zoom on the board itself. */
    touch-action: manipulation;
}

.side-panel {
    flex: 0 0 250px;
    width: 250px;
    background: #262626;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 0 15px;
    overflow-y: auto;
    border-left: 1px solid #3a3a3a;
}

.mode-title {
    color: white;
    font-size: 20px;
    font-weight: bold;
    text-align: center;
    padding: 20px 0;
}

.player-list-frame {
    padding: 10px 0;
}

.players-heading {
    color: #9a9a9a;
    font-size: 12px;
    font-weight: bold;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.player-label {
    color: white;
    background: #313131;
    font-size: 12px;
    padding: 7px 10px;
    margin: 3px 0;
    border-radius: 6px;
    border: 1px solid transparent;
}

.player-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.player-name {
    min-width: 0;
}

.player-time {
    flex: 0 0 auto;
    font-variant-numeric: tabular-nums;
    opacity: 0.85;
}

.player-label.active {
    background: #43403a;
    border-color: gold;
}

.back-button {
    margin-top: auto;
    margin-bottom: 20px;
}

/* ============================================================
   PLACEMENT PHASE (6-player mode)
   ============================================================ */

.placement-title {
    padding-top: 20px;
    padding-bottom: 6px;
}

.placement-timer {
    color: gold;
    font-size: 28px;
    font-weight: bold;
    text-align: center;
    font-variant-numeric: tabular-nums;
    padding-bottom: 14px;
}

.placement-status-list {
    max-height: 160px;
    overflow-y: auto;
    padding-bottom: 6px;
}

.placement-status-row {
    font-size: 12px;
}

.placement-tray {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-bottom: 10px;
    max-height: 220px;
    overflow-y: auto;
}

.placement-tray-item {
    width: 100%;
    text-align: left;
    padding: 9px 12px;
    background: #313131;
    color: white;
    border: 1px solid #4a4a4a;
    border-radius: 6px;
    font-size: 13px;
    text-transform: capitalize;
    cursor: pointer;
}

.placement-tray-item:hover {
    background: #3a3a3a;
}

.placement-tray-item.armed {
    background: #43402a;
    border-color: gold;
    color: gold;
}

.placement-tray-empty {
    color: #9a9a9a;
    font-size: 12px;
    font-style: italic;
    padding: 4px 2px;
}

.placement-confirm-button {
    background: #2f4a32;
    border-color: #3f6b43;
}

.placement-confirm-button:hover {
    background: #385938;
}

.placement-clear-button {
    background: #3a3a3a;
}

/* ============================================================
   MOBILE / NARROW SCREENS
   ============================================================ */
/*
 * Below MOBILE_BREAKPOINT_PX (board.js), the side panel becomes a
 * slim, app-like toolbar docked under the board: game mode on the
 * left, a horizontally-scrolling strip of player chips in the
 * middle, and the Back button pinned on the right - rather than
 * the old wrapping grid of pills, which read as cramped/cluttered
 * on a small screen.
 */

@media (max-width: 700px) {
    .board-container {
        flex-direction: column;
    }

    .board-canvas-wrap {
        flex: 1 1 auto;
        min-height: 0;
        width: 100%;
    }

    .side-panel {
        flex: 0 0 auto;
        width: 100%;
        height: 60px;
        flex-direction: row;
        align-items: center;
        padding: 0 10px;
        gap: 10px;
        border-left: none;
        border-top: 1px solid #3a3a3a;
        overflow-x: hidden;
        overflow-y: hidden;
    }

    .mode-title {
        flex: 0 0 auto;
        display: block;
        padding: 0;
        font-size: 13px;
        font-weight: bold;
        color: #9a9a9a;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        border-right: 1px solid #3a3a3a;
        padding-right: 10px;
        white-space: nowrap;
    }

    .player-list-frame {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        gap: 6px;
        padding: 0;
        flex: 1 1 auto;
        min-width: 0;
        overflow-x: auto;
        overflow-y: hidden;
        /* Hide the scrollbar itself (still scrollable by touch) so
           this reads as a toolbar, not a visible scroll widget. */
        scrollbar-width: none;
    }

    .player-list-frame::-webkit-scrollbar {
        display: none;
    }

    .players-heading {
        display: none;
    }

    .player-label {
        flex: 0 0 auto;
        font-size: 11px;
        padding: 6px 10px;
        margin: 0;
        white-space: nowrap;
    }

    .back-button {
        flex: 0 0 auto;
        width: auto;
        min-height: 38px;
        margin: 0;
        padding: 8px 18px;
        background: #4a2f2f;
        border-color: #6b3f3f;
    }

    .back-button:hover {
        background: #593838;
    }

    /* The placement panel (timer, scrollable player list, piece
       tray, Confirm/Clear/Back) needs real vertical room - it
       can't fit the compact horizontal toolbar above, so it opts
       out of that layout entirely and becomes a tall scrollable
       panel docked below the board instead. */
    .side-panel.placement-mode {
        flex-direction: column;
        align-items: stretch;
        height: auto;
        max-height: 52vh;
        overflow-y: auto;
        padding: 14px 16px;
        gap: 0;
    }

    .side-panel.placement-mode .placement-title {
        padding-top: 4px;
    }

    .side-panel.placement-mode .back-button {
        width: 100%;
        margin-top: 10px;
    }

    .winner-card {
        width: min(340px, 88vw);
        padding: 24px 20px;
    }

    .disconnect-banner-frame {
        width: min(360px, 92vw);
    }

    .disconnect-label {
        font-size: 12px;
        text-align: center;
    }
}

@media (max-width: 380px) {
    .menu-panel {
        padding: 24px 20px;
    }

    .player-label {
        font-size: 10px;
        padding: 5px 8px;
    }

    .mode-title {
        font-size: 11px;
        padding-right: 8px;
    }
}

/* ============================================================
   DISCONNECT BANNER
   ============================================================ */

.disconnect-banner-frame {
    position: absolute;
    top: 2%;
    left: 50%;
    transform: translateX(-50%);
    background: #5A1F1F;
    display: flex;
    flex-direction: column;
    align-items: center;
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    overflow: hidden;
}

.disconnect-label {
    color: white;
    font-weight: bold;
    font-size: 13px;
    padding: 8px 16px;
    margin: 2px 0;
}

/* ============================================================
   WINNER OVERLAY
   ============================================================ */

.winner-overlay {
    position: absolute;
    inset: 0;
    background: rgba(32, 32, 32, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.winner-card {
    background: #2C2C2C;
    padding: 30px 45px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    border-radius: 14px;
    border: 1px solid #3a3a3a;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    max-width: 92vw;
}

.winner-trophy {
    font-size: 45px;
    color: gold;
    margin-bottom: 5px;
}

.winner-heading {
    color: white;
    font-size: clamp(18px, 5vw, 22px);
    font-weight: bold;
}

.winner-subheading {
    color: white;
    font-size: clamp(14px, 4vw, 17px);
    margin: 10px 0;
}

.winner-reason {
    color: #BBBBBB;
    font-size: 12px;
    margin-bottom: 15px;
}

/* ============================================================
   CHAT (online 4-player) - desktop: chat | board | players
   ============================================================ */

.pl-num-short {
    display: none;
}

.board-container.with-chat .chat-dock {
    order: 0;
}

.board-container.with-chat .board-canvas-wrap {
    order: 1;
}

.board-container.with-chat .side-panel {
    order: 2;
}

.chat-dock {
    flex: 0 0 300px;
    width: 300px;
    position: relative;
    min-height: 0;
    background: #262626;
    border-right: 1px solid #3a3a3a;
}

.chat-panel {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: #262626;
}

.chat-panel [hidden] {
    display: none !important;
}

.chat-handle,
.chat-preview {
    display: none;
}

.chat-tabs {
    flex: 0 0 auto;
    display: flex;
    gap: 4px;
    padding: 8px;
    overflow-x: auto;
    border-bottom: 1px solid #3a3a3a;
    scrollbar-width: none;
}

.chat-tabs::-webkit-scrollbar {
    display: none;
}

.chat-tab {
    position: relative;
    flex: 0 0 auto;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: #313131;
    color: #ddd;
    font-size: 12px;
    cursor: pointer;
}

.chat-tab.active {
    background: #43403a;
    border-color: gold;
    color: #fff;
}

.chat-tab .badge {
    display: inline-block;
    min-width: 16px;
    margin-left: 6px;
    padding: 0 4px;
    border-radius: 8px;
    background: #d33;
    color: #fff;
    font-size: 10px;
    line-height: 16px;
    text-align: center;
}

.chat-pinned {
    flex: 0 0 auto;
    margin: 8px 8px 0;
    padding: 8px 10px;
    border: 1px solid gold;
    border-radius: 8px;
    background: #3b3420;
    color: #fff;
    font-size: 12px;
    word-break: break-word;
}

.chat-pinned .pin-head {
    margin-bottom: 3px;
    font-weight: bold;
    color: gold;
}

.chat-messages {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.chat-msg {
    align-self: flex-start;
    max-width: 88%;
    padding: 6px 9px;
    border-radius: 10px;
    background: #333;
    color: #eee;
    font-size: 13px;
    word-break: break-word;
}

.chat-msg.mine {
    align-self: flex-end;
    background: #3f4b3a;
}

.chat-msg .who,
.chat-msg .note {
    display: block;
    font-size: 10px;
    opacity: 0.7;
}

.chat-msg .who {
    margin-bottom: 2px;
}

.chat-msg .note {
    margin-top: 2px;
    color: #ff8a80;
}

.chat-alliance-btn {
    flex: 0 0 auto;
    margin: 0 8px 6px;
    padding: 8px;
    border: 1px solid #6b5a1f;
    border-radius: 8px;
    background: #3b3420;
    color: gold;
    font-size: 13px;
    cursor: pointer;
}

.chat-input-row {
    flex: 0 0 auto;
    display: flex;
    gap: 6px;
    padding: 8px;
    border-top: 1px solid #3a3a3a;
}

.chat-input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid #4a4a4a;
    border-radius: 8px;
    background: #2c2c2c;
    color: #fff;
    font-size: 16px;
}

.chat-send {
    flex: 0 0 auto;
    padding: 0 14px;
    border: 1px solid #555;
    border-radius: 8px;
    background: #3a3a3a;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
}

/* ============================================================
   CHAT (online 4-player) - mobile: players on top, board, drawer
   ============================================================ */

@media (max-width: 700px) {
    .board-container.with-chat .side-panel {
        order: 0;
        height: auto;
        min-height: 58px;
        padding: 6px 8px;
        gap: 8px;
        overflow: visible;
        border-top: none;
        border-bottom: 1px solid #3a3a3a;
    }

    .board-container.with-chat .board-canvas-wrap {
        order: 1;
    }

    .board-container.with-chat .chat-dock {
        order: 2;
        flex: 0 0 88px;
        width: 100%;
        height: 88px;
        border-right: none;
        border-top: 1px solid #3a3a3a;
    }

    .board-container.with-chat .mode-title {
        display: none;
    }

    .board-container.with-chat .player-list-frame {
        display: grid;
        grid-auto-flow: column;
        grid-auto-columns: minmax(0, 1fr);
        gap: 4px;
        flex: 1 1 auto;
        min-width: 0;
        overflow: visible;
    }

    .board-container.with-chat .player-label {
        flex-direction: column;
        justify-content: center;
        align-items: stretch;
        gap: 1px;
        min-width: 0;
        padding: 4px 3px;
        font-size: 11px;
        text-align: center;
    }

    .board-container.with-chat .player-name {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .board-container.with-chat .pl-num-long,
    .board-container.with-chat .pl-sep1,
    .board-container.with-chat .pl-sep2,
    .board-container.with-chat .player-label.has-name .pl-col {
        display: none;
    }

    .board-container.with-chat .pl-num-short {
        display: inline;
        margin-right: 4px;
        font-weight: bold;
    }

    .board-container.with-chat .player-time {
        font-size: 13px;
        opacity: 1;
    }

    .board-container.with-chat .back-button {
        min-height: 40px;
        padding: 8px 12px;
    }

    .chat-panel {
        inset: auto 0 0 0;
        height: 100%;
        z-index: 20;
        border-top: 1px solid #3a3a3a;
        box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.4);
        transition: height 0.22s ease;
    }

    .chat-panel.expanded {
        height: min(68vh, 460px);
        height: min(68dvh, 460px);
    }

    .chat-handle {
        position: relative;
        display: block;
        flex: 0 0 18px;
        cursor: pointer;
        touch-action: none;
    }

    .chat-handle::after {
        content: "";
        position: absolute;
        top: 7px;
        left: 50%;
        width: 36px;
        height: 4px;
        margin-left: -18px;
        border-radius: 2px;
        background: #5a5a5a;
    }

    .chat-tabs {
        padding: 2px 8px 4px;
        border-bottom: none;
    }

    .chat-tab .tn {
        display: none;
    }

    .chat-preview {
        display: block;
        flex: 0 0 auto;
        padding: 2px 10px 8px;
        overflow: hidden;
        color: #bbb;
        font-size: 12px;
        text-overflow: ellipsis;
        white-space: nowrap;
        cursor: pointer;
    }

    .chat-preview.empty {
        color: #777;
    }

    .chat-panel.expanded .chat-preview {
        display: none;
    }

    .chat-panel:not(.expanded) .chat-pinned,
    .chat-panel:not(.expanded) .chat-messages,
    .chat-panel:not(.expanded) .chat-alliance-btn,
    .chat-panel:not(.expanded) .chat-input-row {
        display: none;
    }

    .chat-panel.expanded .chat-tabs {
        border-bottom: 1px solid #3a3a3a;
    }
}
/* ============================================================
   MOBILE REFINEMENTS
   ============================================================ */
/*
 * Kept last so it can refine the earlier rules. Safe-area insets
 * need  <meta name="viewport" content="width=device-width,
 * initial-scale=1, viewport-fit=cover">  in index.html; without
 * viewport-fit=cover, env() resolves to 0 and these are harmless.
 */

/* No accidental text selection / callout menus while tapping or
   long-pressing the board and controls. */
.board-container,
.menu-button,
.placement-tray-item,
.chat-tab {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.chat-messages,
.chat-input {
    -webkit-user-select: text;
    user-select: text;
}

.menu-button,
.menu-select,
.placement-tray-item,
.chat-tab,
.chat-send,
.chat-alliance-btn {
    touch-action: manipulation;
}

.disconnect-banner-frame {
    top: max(2%, env(safe-area-inset-top));
}

@media (max-width: 700px) {
    /* ---- Bottom toolbar: clear the home indicator, bigger tap
          targets, and a fade hinting that the chip strip scrolls. */
    .side-panel {
        height: calc(62px + env(safe-area-inset-bottom));
        padding: 0 max(10px, env(safe-area-inset-right)) env(safe-area-inset-bottom)
            max(10px, env(safe-area-inset-left));
    }

    .player-list-frame {
        padding-right: 16px;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
        -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 16px), transparent);
        mask-image: linear-gradient(to right, #000 calc(100% - 16px), transparent);
    }

    .player-label {
        scroll-snap-align: center;
        min-height: 34px;
        display: flex;
        align-items: center;
        font-size: 12px;
        gap: 6px;
    }

    .back-button {
        min-height: 44px;
        min-width: 64px;
    }

    /* ---- Placement panel: tray items wrap as compact chips instead
          of a tall one-per-row list, so the board keeps more room. */
    .side-panel.placement-mode {
        height: auto;
        max-height: 44vh;
        max-height: 44dvh;
        padding: 10px max(14px, env(safe-area-inset-right))
            calc(10px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
        -webkit-overflow-scrolling: touch;
    }

    .side-panel.placement-mode .placement-title {
        padding-top: 2px;
        font-size: 16px;
    }

    .side-panel.placement-mode .placement-timer {
        font-size: 22px;
        padding-bottom: 8px;
    }

    .side-panel.placement-mode .placement-status-list {
        max-height: 84px;
    }

    .side-panel.placement-mode .placement-tray {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
        max-height: none;
        overflow: visible;
    }

    .side-panel.placement-mode .placement-tray-item {
        width: auto;
        flex: 1 1 calc(33.333% - 6px);
        min-height: 40px;
        padding: 8px 6px;
        text-align: center;
        font-size: 13px;
    }

    .side-panel.placement-mode .menu-button {
        min-height: 44px;
        margin: 4px 0;
    }

    .winner-card {
        padding: 22px 18px;
    }

    .winner-overlay {
        padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
    }

    /* ---- Chat variant: keep the top player bar below the notch and
          the chat drawer above the home indicator. */
    .board-container.with-chat .side-panel {
        height: auto;
        padding-top: max(6px, env(safe-area-inset-top));
        padding-bottom: 6px;
    }

    .board-container.with-chat .chat-dock {
        flex-basis: calc(88px + env(safe-area-inset-bottom));
        height: calc(88px + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
        background: #262626;
    }

    .chat-panel {
        bottom: env(safe-area-inset-bottom);
    }

    .chat-tab {
        min-height: 34px;
    }

    .chat-send {
        min-width: 56px;
        min-height: 40px;
    }
}

/* ---- Phones in landscape: a bottom toolbar would steal a third of
        the height, and the board is height-limited, so dock the panel
        as a slim column on the right instead. ---- */
@media (max-width: 950px) and (max-height: 480px) and (orientation: landscape) {
    .board-container,
    .board-container.with-chat {
        flex-direction: row;
    }

    .board-container .board-canvas-wrap {
        flex: 1 1 auto;
        width: auto;
        height: 100%;
    }

    .board-container .side-panel {
        flex: 0 0 168px;
        width: 168px;
        height: 100%;
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        gap: 0;
        padding: 6px max(10px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) 10px;
        border-top: none;
        border-left: 1px solid #3a3a3a;
        border-bottom: none;
        overflow-x: hidden;
        overflow-y: auto;
    }

    .board-container.with-chat .side-panel {
        order: 2;
        height: 100%;
        min-height: 0;
        padding: 6px max(10px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) 10px;
        overflow-x: hidden;
        overflow-y: auto;
        border-bottom: none;
        border-left: 1px solid #3a3a3a;
    }

    .board-container.with-chat .mode-title {
        display: block;
    }

    .board-container .mode-title {
        display: block;
        padding: 6px 0;
        border-right: none;
        font-size: 12px;
        text-align: center;
    }

    .board-container .player-list-frame {
        display: block;
        flex: 0 1 auto;
        padding: 4px 0;
        overflow: visible;
        -webkit-mask-image: none;
        mask-image: none;
    }

    .board-container .player-label {
        margin: 2px 0;
        min-height: 30px;
        padding: 4px 8px;
        font-size: 11px;
    }

    .board-container .back-button {
        width: 100%;
        margin: auto 0 4px;
        min-height: 40px;
    }

    /* Placement panel keeps the same column layout, just scrolls. */
    .board-container .side-panel.placement-mode {
        flex: 0 0 230px;
        width: 230px;
        max-height: none;
        height: 100%;
    }

    /* Chat is a left drawer-free column here; hide the handle UI and
       show the panel as a narrow left column. */
    .board-container.with-chat .chat-dock {
        order: 0;
        flex: 0 0 210px;
        width: 210px;
        height: 100%;
        padding-bottom: 0;
        border-top: none;
        border-right: 1px solid #3a3a3a;
    }

    .board-container.with-chat .chat-panel {
        inset: 0;
        height: 100%;
        bottom: 0;
        box-shadow: none;
        border-top: none;
    }

    .board-container.with-chat .chat-handle,
    .board-container.with-chat .chat-preview {
        display: none;
    }

    .board-container.with-chat .chat-panel:not(.expanded) .chat-pinned,
    .board-container.with-chat .chat-panel:not(.expanded) .chat-messages,
    .board-container.with-chat .chat-panel:not(.expanded) .chat-alliance-btn,
    .board-container.with-chat .chat-panel:not(.expanded) .chat-input-row {
        display: flex;
    }

    .board-container.with-chat .chat-panel:not(.expanded) .chat-pinned {
        display: block;
    }

    .board-container.with-chat .player-list-frame {
        display: block;
    }

    .board-container.with-chat .player-label {
        flex-direction: row;
        text-align: left;
    }

    .board-container.with-chat .pl-num-long,
    .board-container.with-chat .pl-sep1,
    .board-container.with-chat .pl-sep2 {
        display: inline;
    }

    .board-container.with-chat .pl-num-short {
        display: none;
    }

    .menu-panel {
        padding: 18px 22px;
    }

    .menu-title {
        margin-bottom: 12px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .chat-panel {
        transition: none;
    }

    .menu-button {
        transition: none;
    }
}

/* ============================================================
   PLAYER NAME DIALOG (reuses the winner overlay/card)
   ============================================================ */

.name-prompt-overlay {
    z-index: 50;
    background: rgba(21, 21, 21, 0.78);
}

.winner-card.name-prompt-card {
    width: min(360px, 92vw);
}

.name-input {
    width: 100%;
    min-height: 46px;
    margin: 12px 0 6px;
    padding: 10px 12px;
    background: #2C2C2C;
    color: #fff;
    border: 1px solid #4a4a4a;
    border-radius: 8px;
    /* 16px stops iOS Safari zooming the page on focus. */
    font-size: 16px;
    text-align: center;
    -webkit-user-select: text;
    user-select: text;
}

.name-input:focus {
    outline: none;
    border-color: gold;
}

.name-prompt-error {
    min-height: 18px;
    margin: 2px 0 4px;
    color: #ff8a80;
    font-size: 12px;
}

.name-prompt-actions {
    display: flex;
    gap: 10px;
    width: 100%;
    margin-top: 10px;
}

.name-prompt-actions .menu-button {
    flex: 1 1 0;
    margin: 0;
}

.name-prompt-actions .name-prompt-primary {
    background: #43402a;
    border-color: gold;
    color: gold;
}
/* ============================================================
   NOTICE DIALOG, BOT BANNER, CHAT TOGGLE
   ============================================================ */

.name-prompt-card .notice-message {
    width: 100%;
    max-height: 55vh;
    max-height: 55dvh;
    margin: 10px 0 15px;
    overflow-y: auto;
    font-size: 13px;
    line-height: 1.45;
    text-align: left;
    white-space: pre-line;
}

.name-prompt-card > .name-prompt-primary {
    width: 100%;
    margin: 0;
}

.disconnect-banner-frame.bot-fallback-banner {
    background: #1f3a5a;
}

.chat-toggle {
    flex: 0 0 auto;
    margin: 8px 8px 0;
    padding: 6px 10px;
    border: 1px solid #4a4a4a;
    border-radius: 6px;
    background: #313131;
    color: #ddd;
    font-size: 12px;
    cursor: pointer;
    touch-action: manipulation;
}

.chat-panel.chat-off > :not(.chat-handle):not(.chat-toggle) {
    display: none !important;
}

@media (max-width: 700px) {
    .chat-panel:not(.expanded) .chat-toggle {
        display: none;
    }
}

@media (max-width: 950px) and (max-height: 480px) and (orientation: landscape) {
    .board-container.with-chat .chat-panel .chat-toggle {
        display: block;
    }
}

/* ============================================================
   SETTINGS BUTTON + DIALOG
   ============================================================ */

.settings-fab {
    position: fixed;
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    z-index: 40;
    width: 40px;
    height: 40px;
    padding: 0;
    background: #2C2C2C;
    color: #ddd;
    border: 1px solid #4a4a4a;
    border-radius: 10px;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}

.settings-fab:hover {
    border-color: gold;
    color: gold;
}

.settings-row {
    display: flex;
    gap: 8px;
    width: 100%;
    margin: 12px 0 4px;
}

.settings-row .menu-button {
    flex: 1 1 0;
    min-width: 0;
    margin: 0;
    padding-left: 4px;
    padding-right: 4px;
    font-size: 13px;
}

/* ============================================================
   COLLECTOR TUTORIAL BOX + SAMPLE BOARD
   ============================================================ */

.searching-frame.has-sample {
    isolation: isolate;
    background: #151515;
}

.sample-board {
    position: absolute;
    inset: 0;
    z-index: -1;
}

.sample-board canvas {
    display: block;
    opacity: 0.5;
}

.collector-tip-overlay {
    position: fixed;
    inset: 0;
    z-index: 45;
    cursor: pointer;
    background: rgba(0, 0, 0, 0.25);
}

.collector-tip {
    position: fixed;
    box-sizing: border-box;
    padding: 20px 14px 10px;
    background: #2C2C2C;
    border: 2px solid gold;
    border-radius: 14px;
    box-shadow: 0 6px 22px rgba(0, 0, 0, 0.55);
    color: #fff;
    text-align: center;
    pointer-events: none;
}

.collector-tip-badge {
    position: absolute;
    top: -17px;
    left: 50%;
    transform: translateX(-50%);
    width: 34px;
    height: 34px;
    line-height: 34px;
    font-size: 20px;
    background: #43402a;
    border: 2px solid gold;
    border-radius: 50%;
}

.collector-tip-chip {
    display: inline-block;
    padding: 1px 8px;
    background: gold;
    color: #202020;
    border-radius: 8px;
    font-size: 10px;
    font-weight: bold;
    letter-spacing: 0.08em;
}

.collector-tip-title {
    margin: 4px 0 4px;
    color: gold;
    font-size: 16px;
    font-weight: bold;
}

.collector-tip-body {
    font-size: 12.5px;
    line-height: 1.4;
}

.collector-tip-foot {
    margin-top: 8px;
    color: #aaa;
    font-size: 10.5px;
}

/* ============================================================
   PROGRESSION + PLAY AGAIN
   ============================================================ */

.menu-progress {
    margin: -10px 0 18px;
    padding: 10px 12px;
    background: #2e2e2e;
    border: 1px solid #3a3a3a;
    border-radius: 10px;
}

.menu-progress-top {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    color: gold;
    font-size: 13px;
    font-weight: bold;
}

.menu-progress-top span:last-child {
    color: #cfcfcf;
    font-weight: normal;
}

.menu-progress-stats {
    margin-top: 6px;
    color: #9a9a9a;
    font-size: 11px;
    text-align: center;
}

.xp-bar {
    height: 7px;
    margin-top: 7px;
    overflow: hidden;
    background: #1c1c1c;
    border-radius: 4px;
}

.xp-bar span {
    display: block;
    height: 100%;
    background: gold;
    border-radius: 4px;
    transition: width 0.6s ease;
}

.winner-card > .xp-bar {
    width: min(240px, 70vw);
    margin: 4px 0 8px;
}

.winner-xp {
    margin-top: 4px;
    color: gold;
    font-size: 18px;
    font-weight: bold;
}

.winner-level {
    margin-bottom: 8px;
    color: #cfcfcf;
    font-size: 12px;
}

.winner-level.level-up {
    color: gold;
    font-size: 14px;
    font-weight: bold;
}

.winner-card > .rematch-button {
    width: 100%;
    margin: 10px 0 0;
    background: #43402a;
    border-color: gold;
    color: gold;
}