.panel-hidden {
    display: none;
}

#bingo-main-container {
    padding: 0;
}

#bingo-game-container {
    width: 100%;
    padding: 20px;
}

.bingo-game {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
    align-items: stretch;
}

.bingo-game > h1 {
    min-height: 52px;
    margin: 0;
    padding: 10px 4px;
    display: grid;
    place-items: center;
    color: var(--main-text);
    background: var(--main-surface);
    border: 1px solid var(--main-border);
    border-radius: 10px;
    font-size: clamp(1.2rem, 3vw, 1.9rem);
    line-height: 1;
}

.bingo-button {
    width: 100%;
    min-width: 0;
    min-height: 0;
    aspect-ratio: 1;
    margin: 0;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--main-text);
    background: var(--main-surface-raised);
    border: 1px solid #414141;
    border-radius: 10px;
    white-space: normal;
    line-height: 1.25;
}

.bingo-button:hover {
    background: var(--main-surface-hover);
    border-color: #626262;
}

.bingo-button.is-marked {
    color: #ffffff;
    background: #286a49;
    border-color: #438864;
}

#bingo-controls {
    width: 100%;
    margin-top: 14px;
    padding: 14px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    background: var(--main-surface);
    border: 1px solid var(--main-border);
    border-radius: 16px;
}

#bingo-controls .bingo-button {
    aspect-ratio: auto;
    min-height: 48px;
    background: #111111;
    border-color: var(--main-border-strong);
}

#bingo-controls .bingo-button:hover {
    background: #2b2b2b;
    border-color: #8a8a8a;
}

@media (max-width: 650px) {
    #bingo-game-container {
        padding: 9px;
        border-radius: 14px;
    }

    .bingo-game {
        gap: 5px;
    }

    .bingo-game > h1 {
        min-height: 42px;
        border-radius: 8px;
    }

    .bingo-button {
        padding: 4px;
        border-radius: 8px;
        font-size: clamp(0.55rem, 2vw, 0.78rem);
    }

    #bingo-controls {
        grid-template-columns: 1fr;
    }
}

/* -------------------------------------------------------------------------
   Bingo viewport fitting
   Keep the entire Bingo interface inside the visible browser height.
   ------------------------------------------------------------------------- */
body.bingo-page {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    padding-bottom: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.bingo-page .top-links,
.bingo-page .top-text {
    flex: 0 0 auto;
}

.bingo-page #bingo-main-container {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    margin-bottom: 10px !important;
}

.bingo-page #bingo-game-container {
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.bingo-page .bingo-game {
    flex: 1 1 auto;
    min-height: 0;
    grid-template-rows: minmax(0, 0.65fr) repeat(5, minmax(0, 1fr));
}

.bingo-page .bingo-game > h1,
.bingo-page .bingo-game > .bingo-button {
    min-height: 0;
    height: 100%;
}

.bingo-page .bingo-game > .bingo-button {
    aspect-ratio: auto;
    overflow: hidden;
}

.bingo-page #bingo-controls {
    flex: 0 0 auto;
}

.bingo-page > br {
    display: none;
}

/* Tighten only this page when vertical space is limited. */
@media (max-height: 850px) {
    .bingo-page .top-links {
        margin-top: 8px;
        margin-bottom: 8px;
        padding: 6px;
    }

    .bingo-page .top-links button {
        min-height: 34px;
        padding: 6px 10px;
    }

    .bingo-page .top-text {
        margin-bottom: 8px;
        padding: 10px 16px;
    }

    .bingo-page .top-text h1 {
        font-size: clamp(1.35rem, 3vw, 2rem);
    }

    .bingo-page .page-subtitle {
        margin-top: 2px;
        line-height: 1.3;
    }

    .bingo-page #bingo-game-container {
        padding: 10px;
    }

    .bingo-page .bingo-game {
        gap: 6px;
    }

    .bingo-page .bingo-game > h1 {
        padding: 4px;
        font-size: clamp(1rem, 2.4vh, 1.5rem);
    }

    .bingo-page .bingo-button {
        padding: 4px;
        font-size: clamp(0.58rem, 1.45vh, 0.84rem);
    }

    .bingo-page #bingo-controls {
        margin-top: 7px;
        padding: 7px;
        gap: 6px;
    }

    .bingo-page #bingo-controls .bingo-button {
        min-height: 34px;
    }
}

@media (max-width: 650px) {
    .bingo-page #bingo-controls {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-height: 650px) {
    .bingo-page .page-subtitle {
        display: none;
    }

    .bingo-page .top-links {
        margin-top: 4px;
        margin-bottom: 4px;
    }

    .bingo-page .top-text {
        margin-bottom: 4px;
        padding-top: 6px;
        padding-bottom: 6px;
    }

    .bingo-page #bingo-main-container {
        margin-bottom: 4px !important;
    }
}

/* The shared mobile nav normally makes every button full-width. On Bingo,
   keep it compact so the board still has usable vertical space. */
@media (max-width: 520px) {
    .bingo-page .top-links button {
        width: auto;
        flex: 1 1 110px;
    }
}

/* -------------------------------------------------------------------------
   Bingo navigation: keep identical geometry logged in or logged out.
   The shared site nav uses wrapping flexbox, so the longer "Login with Twitch"
   label can otherwise change the layout of every top button.
   ------------------------------------------------------------------------- */
.bingo-page .top-links {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: stretch;
}

.bingo-page .top-links button {
    width: 100%;
    min-width: 0;
    height: 42px;
    min-height: 42px;
    margin: 0;
    padding: 5px 8px;
}

.bingo-page .top-links button > a {
    width: 100%;
    height: 100%;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: normal;
    overflow-wrap: normal;
    word-break: normal;
    line-height: 1.05;
    text-align: center;
}

/* On narrow phones all five buttons stay in one equal row.  The text is
   allowed to wrap inside its button instead of making the nav reflow. */
@media (max-width: 520px) {
    .bingo-page .top-links {
        gap: 5px;
        padding: 7px;
    }

    .bingo-page .top-links button {
        width: 100%;
        height: 40px;
        min-height: 40px;
        padding: 3px;
        font-size: clamp(0.55rem, 2.45vw, 0.72rem);
    }
}

/* -------------------------------------------------------------------------
   Streamer-scoped randomized Bingo additions
   ------------------------------------------------------------------------- */
.bingo-free-space {
    overflow: hidden;
    cursor: default;
    background: var(--main-surface-raised);
    border: 1px solid #414141;
}

.bingo-free-space img {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    display: block;
    object-fit: cover;
}

.bingo-status {
    flex: 0 0 auto;
    margin: 0 0 10px;
    padding: 8px 12px;
    border: 1px solid var(--main-border);
    border-radius: 10px;
    background: var(--main-surface);
    color: var(--main-text);
    font-size: 0.86rem;
    text-align: left;
}

.bingo-status[data-kind="pending"] {
    border-color: #7a6b32;
    background: #2f2a16;
}

.bingo-status[data-kind="success"] {
    border-color: #438864;
    background: #173325;
}

.bingo-status[data-kind="error"] {
    border-color: #874848;
    background: #351b1b;
}

.bingo-page .bingo-game > .bingo-free-space {
    min-height: 0;
    height: 100%;
    aspect-ratio: auto;
}

.bingo-page .bingo-button:disabled {
    cursor: default;
    opacity: 0.75;
}


/* -------------------------------------------------------------------------
   /bingo streamer directory
   ------------------------------------------------------------------------- */
.bingo-directory-page {
    min-height: 100vh;
}

.bingo-directory-page .directory-shell {
    width: var(--site-width);
    margin: 0 auto;
}

.bingo-directory-page .directory-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 14px;
}

.bingo-directory-page .streamer-card {
    min-width: 0;
    padding: 16px;
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr);
    align-items: center;
    gap: 14px;
    color: var(--main-text);
    background: rgba(20, 20, 20, 0.92);
    border: 1px solid var(--main-border);
    border-radius: 16px;
    text-decoration: none;
    text-align: left;
}

.bingo-directory-page .streamer-card:hover {
    background: var(--main-surface-raised);
    border-color: var(--main-border-strong);
}

.bingo-directory-page .streamer-card img {
    width: 64px;
    height: 64px;
    display: block;
    object-fit: cover;
    border-radius: 50%;
    border: 1px solid var(--main-border-strong);
}

.bingo-directory-page .streamer-card-copy {
    min-width: 0;
}

.bingo-directory-page .streamer-card h2 {
    margin: 0 0 3px;
    font-size: 1rem;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.bingo-directory-page .streamer-card p {
    margin: 0;
    color: var(--site-muted);
    font-size: 0.78rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.bingo-directory-page .directory-empty,
.bingo-directory-page .directory-error {
    padding: 24px;
    color: var(--site-muted);
    background: rgba(20, 20, 20, 0.92);
    border: 1px solid var(--main-border);
    border-radius: 16px;
    text-align: center;
}

.bingo-directory-page .directory-error {
    border-color: #874848;
    color: var(--main-text);
}

@media (max-width: 520px) {
    .bingo-directory-page .directory-grid {
        grid-template-columns: 1fr;
    }
}

/* -------------------------------------------------------------------------
   Player called-options drawer
   ------------------------------------------------------------------------- */
.called-drawer-toggle {
    position: fixed;
    right: 0;
    top: 15%;
    z-index: 70;
    min-width: 0;
    min-height: 42px;
    padding: 9px 10px;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 7px;
    border-radius: 10px 0 0 10px;
    background: #111111;
    border: 1px solid var(--main-border-strong);
    border-right: 0;
    color: var(--main-text);
}

.called-drawer-toggle span {
    min-width: 22px;
    height: 22px;
    padding: 0 5px;
    display: inline-grid;
    place-items: center;
    border-radius: 999px;
    background: var(--main-surface-raised);
    color: var(--main-text);
    font-size: 0.72rem;
    line-height: 1;
}

.called-drawer {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 90;
    width: min(380px, calc(100vw - 42px));
    height: 100vh;
    padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    background: rgba(18, 18, 18, 0.985);
    border-left: 1px solid var(--main-border-strong);
    transform: translateX(102%);
    transition: transform 0.2s ease;
    text-align: left;
    color: var(--main-text);
}

.called-drawer.is-open {
    transform: translateX(0);
}

.called-drawer-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 13px;
    border-bottom: 1px solid var(--main-border);
}

.called-drawer-header h2,
.called-drawer-header p {
    margin: 0;
}

.called-drawer-header h2 {
    font-size: 1.2rem;
}

.called-drawer-header p {
    margin-top: 3px;
    color: var(--site-muted);
    font-size: 0.75rem;
}

.called-history-list {
    min-height: 0;
    margin: 12px 0 0;
    padding: 0;
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    list-style: none;
}

.called-history-item {
    min-width: 0;
    padding: 11px 12px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    background: var(--main-surface-raised);
    border: 1px solid var(--main-border);
    border-radius: 10px;
}

.called-history-text {
    min-width: 0;
    flex: 1 1 auto;
    overflow-wrap: anywhere;
    line-height: 1.35;
}

.called-history-time {
    flex: 0 0 auto;
    color: var(--site-muted);
    font-size: 0.72rem;
    white-space: nowrap;
}

.called-history-empty {
    margin: 14px 0 0;
    color: var(--site-muted);
    text-align: center;
}

.called-drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 80;
    background: rgba(0, 0, 0, 0.46);
}

@media (max-width: 520px) {
    .called-drawer-toggle {
        /*bottom: auto;*/
        top: max(115px, env(safe-area-inset-bottom));
        transform: none;
        font-size: 0.72rem;
    }

    .called-drawer {
        width: min(340px, calc(100vw - 24px));
    }
}

/* Keep the /bingo directory nav geometry stable when Login with Twitch is shown. */
.bingo-directory-page .top-links {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.bingo-directory-page .top-links button {
    width: 100%;
    min-width: 0;
}

.bingo-directory-page .top-links button > a {
    min-width: 0;
    display: block;
    white-space: normal;
}


/* -------------------------------------------------------------------------
   Bingo info drawer tabs: Called + Possible Options
   ------------------------------------------------------------------------- */
.bingo-drawer-tabs {
    flex: 0 0 auto;
    margin-top: 12px;
    padding: 4px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    background: #101010;
    border: 1px solid var(--main-border);
    border-radius: 10px;
}

.bingo-drawer-tab {
    min-width: 0;
    min-height: 40px;
    padding: 8px 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    color: var(--site-muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    font-size: 0.78rem;
    white-space: normal;
}

.bingo-drawer-tab:hover {
    background: var(--main-surface-raised);
    border-color: var(--main-border);
}

.bingo-drawer-tab.is-active {
    color: var(--main-text);
    background: var(--main-surface-raised);
    border-color: var(--main-border-strong);
}

.bingo-drawer-tab span {
    min-width: 21px;
    height: 21px;
    padding: 0 5px;
    display: inline-grid;
    place-items: center;
    border-radius: 999px;
    color: var(--main-text);
    background: #101010;
    border: 1px solid var(--main-border);
    font-size: 0.68rem;
    line-height: 1;
}

.bingo-drawer-panel {
    min-height: 0;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
}

.bingo-drawer-panel[hidden] {
    display: none !important;
}

.bingo-drawer-panel-note {
    flex: 0 0 auto;
    margin: 10px 0 0;
    color: var(--site-muted);
    font-size: 0.72rem;
    line-height: 1.4;
}

.possible-options-list {
    min-height: 0;
    margin: 10px 0 0;
    padding: 0;
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    list-style: none;
}

.possible-option-item {
    min-width: 0;
    padding: 11px 12px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    background: var(--main-surface-raised);
    border: 1px solid var(--main-border);
    border-radius: 10px
}

.possible-option-item.is-called {
    border-color: #438864;
    background: #173325;
}

.possible-option-text {
    min-width: 0;
    flex: 1 1 auto;
    overflow-wrap: anywhere;
    line-height: 1.35;
}

.possible-option-status {
    flex: 0 0 auto;
    padding: 3px 7px;
    color: var(--site-muted);
    background: #111;
    border: 1px solid var(--main-border);
    border-radius: 999px;
    font-size: 0.66rem;
    white-space: nowrap;
}

.possible-option-item.is-called .possible-option-status {
    color: #9ce8b2;
    border-color: #438864;
    background: #10291d;
}

@media (max-width: 520px) {
    .bingo-drawer-tab {
        min-height: 38px;
        padding: 7px 6px;
        font-size: 0.7rem;
    }
}

.bingo-page {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.bingo-page .main-shell {
    flex: 1 1 auto;
    min-height: 0;
    margin: 10px auto !important;

    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Title */
.bingo-page .main-shell > .main-panel:first-child {
    flex: 0 0 auto;
    min-height: 0;
    margin: 0;
    padding: 10px;
}

/* Remaining viewport goes to Bingo */
.bingo-page #bingo-main-container {
    flex: 1 1 0;
    min-height: 0;
    margin: 0 !important;
    padding: 0;

    display: flex;
}

/* IMPORTANT: must actually fill the parent */
.bingo-page #bingo-game-container {
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
    min-height: 0;
    padding: 10px;

    display: flex;
    flex-direction: column;
    align-items: stretch;
}

/* Board consumes everything except controls */
.bingo-page .bingo-game {
    flex: 1 1 0;
    width: 100%;
    min-height: 0;

    grid-template-rows:
        minmax(0, 0.65fr)
        repeat(5, minmax(0, 1fr));
}

/* Each grid item fills its assigned row */
.bingo-page .bingo-game > h1,
.bingo-page .bingo-game > .bingo-button {
    min-height: 0;
    height: 100%;
}

.bingo-page .bingo-game > .bingo-button {
    aspect-ratio: auto;
}

/* Controls stay at bottom */
.bingo-page #bingo-controls {
    flex: 0 0 auto;
    margin-top: 7px;
}

.bingo-page .bingo-game .bingo-button span {
    display: block;
    width: 100%;
    max-width: 100%;
    max-height: 100%;

    line-height: 1.1;
    text-align: center;

    white-space: normal;
    overflow-wrap: normal;
    word-break: normal;

    overflow: hidden;
}