/* =========================================================
   LIVE ROOMS SECTION
   ========================================================= */
#live-rooms-section {
    padding: 0 18px 4px;
}

/* Professional dashboard flow: one centered reading column on every device. */
@media (min-width: 800px) {
    #dashboard {
        width: 100%;
        max-width: none;
        margin: 0;
        display: flex;
        flex-direction: column;
        padding: 0 24px 36px;
        overflow-y: auto;
    }

    #dash-header { margin: 0 -24px 18px; padding: 14px 24px; }
    #stats-row { margin-bottom: 18px; }
    #play-options { margin-bottom: 22px; }
    #live-rooms-section { margin-bottom: 16px; }
    #join-code-row { margin-bottom: 24px; }
}

@media (max-width: 600px) {
    #dash-header { gap: 10px; }
    #dash-user, #dash-user > div:last-child { min-width: 0; }
    .dash-name, .dash-phone { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    #header-wallet { gap: 7px; padding-left: 9px; }
    .header-wallet-copy span { display: none; }
    #dash-balance { margin: 0; font-size: 13px; }
    .signout-btn { width: 40px; padding: 0; justify-content: center; }
    .signout-label { display: none; }
}

@media (max-width: 390px) {
    .dash-avatar { width: 38px; height: 38px; }
    .dash-phone { display: none; }
    #header-wallet { border: 0; background: transparent; padding: 0; }
    #dash-balance { font-size: 12px; }
}

.live-room-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    background: #1a1a2e;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, transform 0.15s;
}

.live-room-row:hover {
    border-color: gold;
    background: rgba(255,215,0,0.05);
    transform: translateY(-1px);
}

.live-room-row:active { transform: scale(0.98); }

.live-room-stake {
    font-size: 16px;
    font-weight: bold;
    color: white;
}

.live-room-meta {
    font-size: 11px;
    color: rgba(255,255,255,0.4);
    margin-top: 2px;
}

.live-room-pot {
    font-size: 12px;
    color: gold;
    font-weight: bold;
    text-align: right;
}

.live-room-join {
    font-size: 13px;
    color: rgba(255,255,255,0.5);
    margin-top: 4px;
    text-align: right;
}

/* =========================================================
   GAME SCREEN RESPONSIVE
   ========================================================= */

/* Narrow phones ≤480px */
@media (max-width: 480px) {
    #game-screen {
        padding: 4px 6px 6px;
    }

    #top-bar {
        padding: 5px 8px;
        margin-bottom: 4px;
        gap: 6px;
    }

    #top-bar-left {
        gap: 6px;
    }

    #tb-room-chip, #tb-pot-chip { padding: 4px 8px; }
    #tb-room { font-size: 12px; letter-spacing: 1.5px; }
    #tb-pot  { font-size: 11px; }
    .online-badge { font-size: 10px; padding: 3px 7px; }
    #mute-btn, #settings-btn { width: 32px; height: 32px; font-size: 15px; }

    .online-badge { font-size: 11px; padding: 3px 7px; }

    #player-panels {
        gap: 3px;
        margin-bottom: 4px;
    }

    .panel-avatar { width: 24px; height: 24px; font-size: 10px; }
    .panel-name   { font-size: 11px; }
    .panel-info   { font-size: 10px; }
    .turn-badge   { font-size: 7px; padding: 2px 4px; }

    #controls {
        margin-top: 0;
        margin-bottom: 0;
        padding: 4px 14px;
    }

    #controls::after { width: 60px; }

    #status-bar {
        padding: 4px 10px;
        margin-top: 4px;
        min-height: 28px;
    }

    #status-conn-text { font-size: 10px; }
    #status-text      { font-size: 10px; }

    #toast {
        font-size: 13px;
        padding: 9px 16px;
    }

    #settings-panel { width: 100%; }
}

/* Very small screens ≤360px */
@media (max-width: 360px) {
    .panel-name   { font-size: 10px; }
    .panel-info   { display: none; }
    #current-player { font-size: 11px; }
    #controls::after { width: 50px; }
    #tb-room-chip, #tb-pot-chip { padding: 4px 6px; }
    .chip-label   { display: none; }   /* save space: code + amount only */
    #tb-pot { font-size: 10px; }
}

/* =========================================================
   GAME SCREEN — PC: constrain column width so top bar,
   player panels and controls match the board width.
   ========================================================= */
@media (min-width: 800px) {
    #game-screen {
        align-items: center;
        justify-content: center;
        padding: 10px 16px;
    }

    #top-bar,
    #player-panels,
    #chat-feed-anchor,
    #game-container,
    #controls,
    #status-bar {
        max-width: min(720px, calc(100vh - 140px));
        width: 100%;
    }

    #game-container {
        flex: 1;
        min-height: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* =========================================================
   DASHBOARD — PC TWO-COLUMN LAYOUT
   On wide screens use both columns so everything fits
   without scroll at 100% zoom.
   ========================================================= */
@media (min-width: 800px) {
    #dashboard {
        width: 100%;
        max-width: none;
        margin: 0;
        display: flex;
        flex-direction: column;
        padding: 0 24px 36px;
        overflow-y: auto;
    }

    /* Reset mobile margins — row-gap handles vertical spacing */
    #dash-header,
    #stats-row,
    #play-options,
    #live-rooms-section,
    #join-code-row,
    #recent-games { margin: 0; }

    /* Explicit row + column for every item so auto-placement never fires */
    #dash-header { margin: 0 -24px 18px; padding: 14px 24px; }
    #stats-row { margin-bottom: 18px; }
    #play-options { margin-bottom: 22px; padding: 0; }
    #live-rooms-section { margin-bottom: 16px; padding: 0; }
    #join-code-row { margin-bottom: 24px; }
    #recent-games { padding: 0; }
}

/* Full-screen desktop dashboard. The page itself stays still; only match results
   may scroll when enough public matches are available. */
@media (min-width: 800px) and (min-height: 650px) {
    #dashboard {
        width: 100%;
        max-width: none;
        height: 100dvh;
        max-height: 100dvh;
        padding: 0 22px 14px;
        overflow: hidden;
        gap: 10px;
    }

    #dash-header {
        flex: 0 0 70px;
        margin: 0 -22px;
        padding: 10px 22px;
    }

    .dash-brand { display: flex; align-items: center; gap: 8px; color: #fff; white-space: nowrap; }
    .dash-brand-mark { display: grid; place-items: center; width: 42px; height: 42px; }
    .dash-brand-mark img { display: block; width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 5px 10px rgba(255,190,0,.2)); }
    .dash-brand strong { font-size: 14px; }
    .dash-nav { display: flex; align-items: center; gap: 3px; margin-right: auto; }
    .dash-nav a { padding: 9px 10px; border-radius: 9px; color: rgba(255,255,255,.55); font-size: 11px; font-weight: 700; text-decoration: none; }
    .dash-nav a:hover, .dash-nav a:focus-visible { background: rgba(255,255,255,.07); color: #fff; outline: none; }
    #dash-user { gap: 8px; }
    .dash-avatar { width: 36px; height: 36px; font-size: 14px; }
    .dash-name { max-width: 120px; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .dash-phone { font-size: 10px; }
    #header-wallet { min-height: 42px; }
    .signout-btn { min-height: 40px; }

    #active-game-banner { flex: 0 0 auto; margin: 0 !important; }

    #dashboard-hero { flex: 0 0 clamp(210px,28vh,285px); min-height: 0; margin: 0; }
    .dashboard-hero-content { min-height: 100%; }
    #play-options { flex: 0 0 72px; gap: 10px; margin: 0; }
    .play-card { display: grid; grid-template-columns: 38px auto; grid-template-rows: auto auto; align-content: center; column-gap: 10px; padding: 10px 16px; border-radius: 13px; text-align: left; }
    .play-card-icon { grid-row: 1 / span 2; align-self: center; margin: 0; font-size: 25px; text-align: center; }
    .play-card-title { align-self: end; font-size: 13px; }
    .play-card-sub { align-self: start; margin-top: 2px; font-size: 10px; }

    #live-rooms-section { display: flex; flex: 1 1 auto; flex-direction: column; min-height: 128px; margin: 0; padding: 10px 12px; overflow: hidden; border: 1px solid rgba(255,255,255,.08); border-radius: 15px; background: rgba(10,10,14,.78); }
    #live-rooms-section .section-title { margin-bottom: 4px; }
    .quick-match-help { margin: 0 0 7px; }
    .quick-match-filters { flex: 0 0 38px; margin-bottom: 7px; }
    .quick-match-grid { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
    .quick-match-empty { height: 100%; min-height: 72px; justify-content: center; padding: 10px 16px; }
    .quick-match-pagination { flex: 0 0 30px; min-height: 30px; margin-top: 3px; }

    #join-code-row { flex: 0 0 42px; margin: 0; }
    #join-code-row .lobby-input, #join-code-row .lobby-btn { min-height: 42px; height: 42px; }

    #stats-row { flex: 0 0 56px; margin: 0; gap: 10px; }
    .stat-card { display: flex; align-items: center; justify-content: center; gap: 9px; padding: 8px 12px; }
    .stat-value { margin-top: 0; font-size: 15px; }

    #recent-games { flex: 0 0 78px; min-height: 0; padding: 0; overflow: hidden; }
    #recent-games .section-title { display: flex; align-items: center; gap: 8px; margin: 0 0 3px; font-size: 11px; }
    .section-caption { color: rgba(255,255,255,.28); font-size: 9px; font-weight: 400; letter-spacing: 0; text-transform: none; }
    #recent-games-list { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 14px; }
    .game-history-row { min-width: 0; gap: 8px; padding: 5px 0; }
    .history-icon { width: 30px; height: 30px; font-size: 13px; }
    .history-result, .history-amount { font-size: 11px; }
    .history-date { font-size: 9px; }
}

@media (max-width: 1020px) and (min-width: 800px) {
    .dash-brand strong, .dash-phone, .signout-label { display: none; }
    .signout-btn { width: 40px; padding: 0; justify-content: center; }
}

@media (max-width: 799px) {
    .dash-brand, .dash-nav { display: none; }

    #dashboard { padding-bottom: 82px; }
    #mobile-dashboard-nav {
        position: fixed;
        left: 0; right: 0; bottom: 0;
        z-index: 80;
        display: grid;
        grid-template-columns: repeat(4,1fr);
        min-height: 64px;
        padding: 6px max(8px,env(safe-area-inset-right)) max(6px,env(safe-area-inset-bottom)) max(8px,env(safe-area-inset-left));
        border-top: 1px solid rgba(255,255,255,.1);
        background: rgba(9,12,18,.96);
        backdrop-filter: blur(14px);
    }
    #mobile-dashboard-nav a,
    #mobile-dashboard-nav button {
        display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
        border: 0; background: transparent; color: rgba(255,255,255,.55);
        font: inherit; font-size: 9px; text-decoration: none; cursor: pointer;
    }
    #mobile-dashboard-nav span { font-size: 18px; line-height: 1; }
    #mobile-dashboard-nav a:first-child,
    #mobile-dashboard-nav button { color: #ffd700; }
}

/* Sketch-inspired desktop workspace: a wide match browser with smaller,
   related panels beside it. All content remains backed by live game data. */
@media (min-width: 1000px) and (min-height: 720px) {
    #dashboard {
        display: grid;
        grid-template-columns: minmax(0,1.65fr) minmax(340px,.85fr);
        grid-template-rows: 70px clamp(215px,27vh,285px) auto auto auto minmax(78px,1fr);
        grid-template-areas:
            "header header"
            "hero hero"
            "matches stats"
            "matches active"
            "matches private"
            "matches recent";
        gap: 10px 12px;
        width: 100%; height: 100dvh;
        padding: 0 18px 14px;
        overflow: hidden;
    }

    #dash-header { grid-area: header; margin: 0 -18px; padding: 10px 18px; }
    #dashboard-hero { grid-area: hero; min-height: 0; height: 100%; margin: 0; }
    #stats-row { grid-area: stats; display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 7px; margin: 0; }
    .stat-card { min-width: 0; justify-content: flex-start; padding: 9px 10px; border: 1px solid rgba(255,255,255,.06); background: rgba(18,22,30,.9); }
    .stat-label { font-size: 9px; }
    .stat-value { font-size: 13px; }

    #active-game-banner { grid-area: active; margin: 0 !important; padding: 10px 12px !important; }
    #live-rooms-section { grid-area: matches; min-height: 0; height: 100%; margin: 0; padding: 12px; }
    .quick-match-grid { min-height: 0; }
    #private-room-panel { grid-area: private; min-width: 0; margin: 0; padding: 12px; overflow: hidden; }
    #recent-games { grid-area: recent; min-width: 0; min-height: 0; margin: 0; padding: 10px 12px; border: 1px solid rgba(255,255,255,.08); border-radius: 15px; background: rgba(10,13,19,.86); }
    #recent-games-list { display: block; }
    .game-history-row { padding: 5px 0; }
    .game-history-row:nth-child(n+4) { display: none; }
}
