body.blackjack-page {
    --surface: #f7fbff;
    --card-w: clamp(3.1rem, 8.5vh, 5rem);
    --card-h: calc(var(--card-w) * 1.42);
}

.blackjack-page [hidden] {
    display: none !important;
}

.app-main > .blackjack-shell {
    display: grid;
    align-items: stretch;
    align-content: stretch;
    width: min(100%, 1400px);
    height: 100%;
    min-height: 0;
    justify-content: stretch;
}

.blackjack-shell {
    width: min(100%, 1400px);
    margin: 8px auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 0.5rem;
    padding: 0.8rem 0.9rem 0.9rem;
    border: 1px solid rgba(15, 118, 110, 0.28);
    border-radius: var(--radius-lg);
    background: linear-gradient(180deg, rgba(15, 118, 110, 0.10), rgba(15, 118, 110, 0.04));
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(22px);
    text-align: center;
    min-height: 0;
    overflow: hidden;
}

#playSurface {
    display: grid;
    width: 100%;
    height: 100%;
    min-height: 0;
    gap: 0.5rem;
    text-align: left;
    grid-template-rows: auto auto auto minmax(0, 1fr) auto auto;
}

.blackjack-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    text-align: left;
}

.blackjack-kicker {
    margin: 0 0 0.1rem;
    color: var(--highlight-color);
    font-weight: 800;
    font-size: 0.7rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.blackjack-subtitle {
    margin: 0;
    color: var(--muted-color);
    font-size: 0.86rem;
}

.blackjack-rules {
    margin: 0.25rem 0 0;
    color: var(--muted-color);
    font-size: 0.74rem;
}

#title {
    margin: 0;
    font-size: clamp(1.35rem, 3.4vh, 1.9rem);
}

.status-pill {
    flex: 0 0 auto;
    padding: 0.55rem 0.75rem;
    border-radius: 999px;
    color: var(--primary-strong);
    background: rgba(37, 99, 235, 0.09);
    font-weight: 800;
    font-size: 0.82rem;
}

.controls,
.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    justify-content: center;
    align-items: center;
}

.match-setup {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.55rem;
    padding: 0.65rem;
    border: 1px solid rgba(15, 118, 110, 0.22);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.72);
}

.setup-label {
    flex: 1 0 100%;
    color: var(--muted-color);
    font-size: 0.82rem;
    font-weight: 800;
    text-align: center;
}

.balance-options {
    display: flex;
    gap: 0.4rem;
}

.balance-option,
.chip-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-height: 48px;
}

.balance-option {
    min-width: 70px;
    color: var(--primary-strong);
    border: 2px solid transparent;
    background: rgba(15, 118, 110, 0.08);
}

.balance-option.is-selected {
    border-color: var(--primary-color);
    background: rgba(15, 118, 110, 0.18);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.button-secondary {
    color: var(--primary-strong);
    background: rgba(15, 118, 110, 0.12);
}

.bankroll-board {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: stretch;
    gap: 0.5rem;
    padding: 0.45rem;
    border: 1px solid rgba(15, 118, 110, 0.22);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.66);
}

.bankroll-panel,
.pot-panel {
    display: grid;
    grid-template-columns: auto auto;
    align-content: center;
    align-items: center;
    justify-content: center;
    gap: 0.1rem 0.45rem;
    min-width: 0;
    padding: 0.25rem 0.35rem;
    border-radius: 12px;
}

.bankroll-panel--player {
    background: rgba(15, 118, 110, 0.08);
}

.bankroll-name,
.pot-panel > span {
    color: var(--muted-color);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.bankroll-panel > strong,
.pot-panel > strong {
    color: var(--primary-strong);
    font-size: 1.05rem;
    font-variant-numeric: tabular-nums;
}

.bankroll-meta {
    grid-column: 1 / -1;
    color: var(--muted-color);
    font-size: 0.66rem;
    text-align: center;
}

.pot-panel {
    grid-template-columns: 1fr;
    min-width: 76px;
    color: #7c5700;
    background: rgba(240, 184, 38, 0.17);
    text-align: center;
}

.pot-panel > strong {
    color: #8a5d00;
}

.chip-rack {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 25px;
    max-width: 150px;
    overflow: hidden;
    padding-inline: 0.3rem;
}

.chip-rack .chip + .chip {
    margin-left: -0.42rem;
}

.chip-rack.is-empty::before {
    color: var(--muted-color);
    content: '—';
}

.chip {
    --chip-color: #168447;
    --chip-edge: #0b5b2f;
    display: inline-grid;
    place-items: center;
    width: 2.15rem;
    aspect-ratio: 1;
    flex: 0 0 auto;
    border: 2px solid var(--chip-edge);
    border-radius: 50%;
    color: #fff;
    background:
        radial-gradient(circle, rgba(255, 255, 255, 0.26) 0 18%, transparent 19% 50%, rgba(0, 0, 0, 0.10) 51% 58%, transparent 59%),
        repeating-conic-gradient(from 0deg, rgba(255, 255, 255, 0.78) 0deg 10deg, transparent 10deg 45deg),
        var(--chip-color);
    box-shadow:
        inset 0 0 0 3px var(--chip-color),
        inset 0 0 0 5px rgba(255, 255, 255, 0.62),
        0 2px 4px rgba(15, 23, 42, 0.25);
    font-size: 0.65rem;
    font-weight: 900;
    line-height: 1;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.45);
}

.chip--1 {
    --chip-color: #168447;
    --chip-edge: #075c30;
}

.chip--5 {
    --chip-color: #c8ced7;
    --chip-edge: #717b89;
    color: #17202a;
    text-shadow: 0 1px rgba(255, 255, 255, 0.7);
}

.chip--10 {
    --chip-color: #e6ad18;
    --chip-edge: #9a6700;
    color: #4b3400;
    text-shadow: 0 1px rgba(255, 255, 255, 0.55);
}

.chip-rack .chip {
    width: 1.55rem;
    font-size: 0.52rem;
}

.chip-rack--pot .chip {
    width: 1.4rem;
}

.chip-action {
    min-width: 104px;
    padding: 0.35rem 0.6rem;
}

.chip-action .chip,
.balance-option .chip {
    width: 1.8rem;
}

#controls-bottom {
    min-height: 38px;
}

#status {
    color: var(--secondary-strong);
    font-weight: 800;
    font-size: 0.98rem;
    border-radius: 999px;
    padding: 0.4rem 0.9rem;
    background: rgba(16, 185, 129, 0.14);
    text-align: center;
}

.blackjack-table {
    display: grid;
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0.85rem;
    align-items: center;
    min-height: 0;
    padding: 0.5rem 0;
}

.hand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    min-height: 0;
}

.hand-label {
    font-size: 0.78rem;
    font-weight: 800;
    color: var(--muted-color);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.hand-cards {
    display: flex;
    justify-content: flex-start;
    justify-content: safe center;
    align-items: flex-start;
    gap: 0.3rem;
    width: 100%;
    min-height: var(--card-h);
    max-width: 100%;
    min-width: 0;
    padding: 0.5rem;
    border-radius: 12px;
    background: rgba(15, 118, 110, 0.14);
    box-shadow: inset 0 0 0 1px rgba(15, 118, 110, 0.25);
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-inline: contain;
    touch-action: pan-x;
    scrollbar-width: thin;
}

.hand-cards .card {
    flex: 0 0 var(--card-w);
    margin: 0;
    touch-action: pan-x;
}

/* Card faces intentionally match the visual treatment in solitaire/game.css. */
.card {
    position: relative;
    display: grid;
    place-items: center;
    width: var(--card-w);
    height: var(--card-h);
    margin-inline: auto;
    overflow: hidden;
    isolation: isolate;
    z-index: 0;
    border: 1px solid #b8b4ad;
    border-radius: 8px;
    background-color: #fffefb;
    background: linear-gradient(145deg, #fffefb 0%, #f4f0e8 100%);
    opacity: 1;
    box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.95),
        0 2px 4px rgba(15, 23, 42, 0.18),
        0 1px 1px rgba(15, 23, 42, 0.12);
    font-family: Georgia, 'Times New Roman', serif;
    font-weight: 700;
    user-select: none;
    touch-action: none;
}

.card::before {
    position: absolute;
    inset: 0.2rem;
    z-index: 0;
    border: 1px solid rgba(132, 126, 115, 0.42);
    border-radius: 5px;
    content: '';
    pointer-events: none;
}

.card > * {
    z-index: 1;
}

.card-corner {
    position: absolute;
    top: 0.34rem;
    left: 0.35rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 0.9;
    font-size: 0.74rem;
    font-variant-numeric: tabular-nums;
    z-index: 3;
}

.card-corner small {
    font-size: 0.82em;
    line-height: 0.9;
}

.card-corner--br {
    top: auto;
    left: auto;
    right: 0.35rem;
    bottom: 0.34rem;
    transform: rotate(180deg);
}

.card-pip-area {
    position: absolute;
    inset: 1.42rem 0.35rem 1.42rem;
}

.number-art {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(5, 1fr);
    align-items: center;
    justify-items: center;
}

.card-pip {
    display: grid;
    place-items: center;
    width: 1em;
    height: 1em;
    font-size: calc(var(--card-w) * 0.19);
    line-height: 1;
}

.rank-1 .card-pip {
    font-size: calc(var(--card-w) * 0.38);
}

.suit-mark {
    display: block;
    width: 1em;
    height: 1em;
    overflow: visible;
    fill: currentColor;
}

.card-corner .suit-mark {
    width: 0.95em;
    height: 0.95em;
    margin-top: 0.05em;
}

.face-suit .suit-mark {
    width: 1em;
    height: 1em;
    margin: 0 auto;
}

.face-card-area {
    display: grid;
    place-items: center;
}

.face-art {
    position: relative;
    width: 76%;
    height: 90%;
    overflow: hidden;
    border: 1px solid currentColor;
    border-radius: 4px;
    background:
        linear-gradient(135deg, transparent 47%, rgba(255, 255, 255, 0.46) 48% 52%, transparent 53%),
        linear-gradient(45deg, transparent 47%, rgba(255, 255, 255, 0.32) 48% 52%, transparent 53%),
        #f6e9c8;
    background-color: #f6e9c8;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.78);
}

.face-art::before {
    position: absolute;
    inset: 50% 0 auto;
    border-top: 1px solid currentColor;
    content: '';
    opacity: 0.28;
}

.face-art::after {
    position: absolute;
    inset: 0.16rem;
    border: 1px solid currentColor;
    border-radius: 2px;
    content: '';
    opacity: 0.38;
}

.card.rank-11 { --face-a: #2c79a9; --face-b: #d8a63c; }
.card.rank-12 { --face-a: #b63b5c; --face-b: #e0ae38; }
.card.rank-13 { --face-a: #55418d; --face-b: #d49b32; }

.face-crown {
    position: absolute;
    top: 7%;
    left: 0;
    width: 100%;
    color: var(--face-b);
    font-family: Georgia, 'Times New Roman', serif;
    font-size: calc(var(--card-w) * 0.16);
    line-height: 1;
    text-align: center;
    z-index: 1;
}

.face-j .face-crown::before { content: '♞'; }
.face-q .face-crown::before { content: '♛'; }
.face-k .face-crown::before { content: '♚'; }

.face-head {
    position: absolute;
    top: 24%;
    left: 36%;
    width: 28%;
    aspect-ratio: 1;
    border: 1px solid rgba(91, 51, 35, 0.45);
    border-radius: 50%;
    background: radial-gradient(circle at 38% 35%, #ffe6c6 0 25%, #e4a77f 27% 100%);
    z-index: 1;
}

.face-body {
    position: absolute;
    bottom: 6%;
    left: 16%;
    width: 68%;
    height: 48%;
    border: 1px solid rgba(40, 32, 38, 0.42);
    border-radius: 52% 52% 8% 8%;
    background: linear-gradient(90deg, var(--face-a) 0 30%, var(--face-b) 31% 69%, var(--face-a) 70% 100%);
    z-index: 1;
}

.face-body::before {
    position: absolute;
    top: -1px;
    left: 35%;
    width: 30%;
    height: 38%;
    border-right: 1px solid rgba(40, 32, 38, 0.42);
    border-bottom: 1px solid rgba(40, 32, 38, 0.42);
    background: #fff8e8;
    content: '';
    transform: rotate(45deg);
}

.face-suit {
    position: absolute;
    top: 54%;
    left: 0;
    width: 100%;
    color: rgba(255, 255, 255, 0.88);
    font-size: calc(var(--card-w) * 0.15);
    line-height: 1;
    text-align: center;
    text-shadow: 0 1px rgba(0, 0, 0, 0.2);
    z-index: 2;
}

.face-initial {
    position: absolute;
    right: 0.18rem;
    bottom: 0.12rem;
    color: var(--face-b);
    font-size: calc(var(--card-w) * 0.12);
    line-height: 1;
    z-index: 3;
}

.card.red,
.card.suit-hearts,
.card.suit-diamonds { color: #c41e3a; }

.card.black,
.card.suit-spades,
.card.suit-clubs { color: #111827; }

.card.back {
    color: transparent;
    border-color: #173b63;
    background:
        radial-gradient(circle at center, transparent 0 35%, rgba(255, 255, 255, 0.16) 36% 39%, transparent 40%),
        repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.12) 0 1px, transparent 1px 7px),
        repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.12) 0 1px, transparent 1px 7px),
        linear-gradient(135deg, #174d7c, #0d3158);
    box-shadow:
        inset 0 0 0 3px rgba(255, 255, 255, 0.36),
        inset 0 0 0 5px rgba(13, 49, 88, 0.8),
        0 2px 4px rgba(15, 23, 42, 0.22);
}

#actions {
    justify-content: center;
    margin-top: 0.5rem;
}

#hit,
#stand,
#double {
    min-width: 96px;
}

#double {
    background: linear-gradient(135deg, var(--secondary-color), var(--secondary-strong));
}

#hit:disabled,
#stand:disabled,
#double:disabled,
.chip-action:disabled,
#stayBet:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

@media (max-width: 760px) {
    .app-main > .blackjack-shell {
        min-height: 0;
        padding: 0.6rem;
        border-radius: 22px;
        overflow-y: auto;
    }

    #playSurface {
        gap: 0.38rem;
    }

    .blackjack-header {
        align-items: center;
        text-align: center;
        justify-content: center;
        flex-direction: column;
        gap: 0.4rem;
    }

    .status-pill {
        display: none;
    }

    .controls {
        gap: 0.4rem;
    }
}

@media (max-width: 520px) {
    body.blackjack-page {
        --card-w: clamp(2.7rem, 16vw, 3.75rem);
        --card-h: calc(var(--card-w) * 1.42);
    }

    .app-main > .blackjack-shell {
        gap: 0.4rem;
        padding: 0.4rem;
    }

    .blackjack-kicker,
    .blackjack-subtitle,
    .blackjack-rules {
        display: none;
    }

    body.blackjack-page .app-select {
        min-height: 44px;
    }

    body.blackjack-page .brand-mark {
        min-width: 44px;
        min-height: 44px;
        justify-content: center;
    }

    .match-setup {
        gap: 0.4rem;
        padding: 0.5rem;
    }

    .balance-option {
        min-width: 64px;
        padding: 0.3rem 0.45rem;
    }

    .bankroll-board {
        gap: 0.25rem;
        padding: 0.3rem;
        border-radius: 12px;
    }

    .bankroll-panel,
    .pot-panel {
        gap: 0.05rem 0.25rem;
        padding: 0.18rem;
    }

    .pot-panel {
        min-width: 62px;
    }

    .chip-rack {
        min-height: 21px;
        max-width: 104px;
        padding-inline: 0.15rem;
    }

    .chip-rack .chip {
        width: 1.3rem;
        font-size: 0.44rem;
    }

    .bankroll-name,
    .pot-panel > span,
    .bankroll-meta {
        font-size: 0.58rem;
    }

    #bettingActions {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        width: 100%;
        gap: 0.3rem;
    }

    .chip-action,
    #stayBet {
        min-width: 0;
        min-height: 48px;
        padding: 0.25rem 0.15rem;
        font-size: 0.66rem;
    }

    .chip-action {
        flex-direction: column;
        gap: 0.12rem;
    }

    .chip-action .chip {
        width: 1.55rem;
    }

    .blackjack-table {
        gap: 0.45rem;
        padding: 0.2rem 0;
    }

    #title {
        font-size: 1.3rem;
    }

    #actions {
        width: 100%;
    }

    #hit,
    #stand,
    #double {
        flex: 1 1 0;
        min-width: 0;
        font-size: 0.9rem;
    }

    .hand-label {
        font-size: 0.68rem;
    }
}

@media (max-width: 380px) {
    body.blackjack-page {
        --card-w: clamp(2.55rem, 18vw, 3.2rem);
    }
}

@media (max-width: 520px) and (max-height: 740px) {
    body.blackjack-page .app-footer {
        display: none;
    }
}
