:root {
    color-scheme: dark;
    font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
    color: #fff8e7;
    background: #080412;
    --cast-accent: #ff91c9;
    --gold-light: #fff3b8;
    --gold-mid: #f3c458;
    --gold-deep: #9e6b18;
    -webkit-text-size-adjust: 100%;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background:
        radial-gradient(ellipse at 50% 0%, rgba(255, 60, 166, 0.2), transparent 55%),
        radial-gradient(ellipse at 50% 100%, rgba(243, 196, 88, 0.14), transparent 60%),
        #080412;
}

button {
    font: inherit;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
    outline: 3px solid var(--gold-light);
    outline-offset: 2px;
}

button:disabled {
    cursor: default;
}

[hidden] {
    display: none !important;
}

.bj-shell {
    max-width: 450px;
    margin: 0 auto;
    padding: 4px 6px max(10px, env(safe-area-inset-bottom));
}

.bj-table {
    position: relative;
    overflow: hidden;
    border-radius: 22px;
    border: 2px solid #eab94f;
    background:
        radial-gradient(circle at 50% 14%, rgba(255, 212, 102, 0.16), transparent 52%),
        linear-gradient(180deg, #1b0d33 0%, #0d2329 46%, #09151d 100%);
    box-shadow:
        inset 0 0 0 1px rgba(255, 243, 184, 0.35),
        inset 0 0 28px rgba(0, 0, 0, 0.65),
        0 4px 0 #70490f,
        0 12px 32px rgba(0, 0, 0, 0.65),
        0 0 24px rgba(243, 196, 88, 0.18);
}

.bj-table[data-mood="blackjack"],
.bj-table[data-mood="fever"],
.bj-table[data-mood="twentyone"] {
    border-color: #fff2a6;
    box-shadow:
        inset 0 0 0 2px rgba(255, 244, 184, 0.6),
        0 4px 0 #8a5b14,
        0 0 32px rgba(255, 210, 76, 0.48),
        0 0 18px var(--cast-accent);
}

/* Compact HUD inside table top */
.bj-hud {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: linear-gradient(90deg, rgba(16, 8, 32, 0.92), rgba(34, 16, 56, 0.88), rgba(16, 8, 32, 0.92));
    border-bottom: 1px solid rgba(243, 196, 88, 0.32);
}

.hud-chip {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    min-height: 25px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    border: 1px solid rgba(243, 196, 88, 0.42);
    background: rgba(255, 255, 255, 0.06);
    color: #ffeaa7;
}

.hud-streak.is-active {
    background: linear-gradient(135deg, #5d1039, #9c1b56);
    border-color: #ff7cc8;
    color: #fff4fb;
    box-shadow: 0 0 12px rgba(255, 60, 166, 0.45);
}

.hud-multiplier.is-boosted {
    background: linear-gradient(135deg, #5c3d06, #b57c16);
    border-color: #ffe89e;
    color: #fffbe6;
    box-shadow: 0 0 12px rgba(243, 196, 88, 0.45);
}

.hud-best {
    margin-left: auto;
    color: #e6d29f;
    border-color: rgba(230, 210, 159, 0.28);
}

.hud-help {
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid rgba(243, 196, 88, 0.5);
    background: rgba(255, 232, 160, 0.1);
    color: #ffe89e;
    font-size: 12px;
    font-weight: 900;
}

/* Dealer Stage (Large Hero Display at Top) */
.dealer-stage {
    position: relative;
    display: grid;
    grid-template-columns: 128px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    padding: 10px 12px 11px;
    background:
        radial-gradient(circle at 22% 50%, rgba(255, 215, 110, 0.26), transparent 62%),
        linear-gradient(180deg, rgba(35, 14, 58, 0.88), rgba(14, 34, 40, 0.76));
    border-bottom: 2px solid;
    border-image: linear-gradient(90deg, #5e3e12, #f5ca63 28%, #fff5c2 50%, #f5ca63 72%, #5e3e12) 1;
}

.dealer-portrait-wrap {
    position: relative;
    width: 128px;
    height: 128px;
    margin: 0 auto;
    border-radius: 26px;
    padding: 3px;
    background: linear-gradient(135deg, #fff5c0, #e6ad39 45%, #8c590b 80%, #ffdf85);
    box-shadow:
        0 0 0 2px rgba(15, 8, 28, 0.85),
        0 0 22px rgba(243, 196, 88, 0.42),
        0 0 18px var(--cast-accent);
}

.bj-table[data-mood="blackjack"] .dealer-portrait-wrap,
.bj-table[data-mood="twentyone"] .dealer-portrait-wrap,
.bj-table[data-mood="fever"] .dealer-portrait-wrap {
    background: linear-gradient(135deg, #ffffff, #ffe680 35%, #ff2e9d 72%, #ffe680);
    box-shadow:
        0 0 0 2px #fff6c2,
        0 0 28px rgba(255, 214, 70, 0.85),
        0 0 22px rgba(255, 46, 157, 0.75);
}

.bj-table[data-mood="bust"] .dealer-portrait-wrap,
.bj-table[data-mood="lose"] .dealer-portrait-wrap {
    box-shadow:
        0 0 0 2px rgba(28, 10, 18, 0.9),
        0 0 14px rgba(255, 80, 120, 0.32);
}

.dealer-halo {
    position: absolute;
    inset: 3px;
    border-radius: 23px;
    background:
        radial-gradient(circle at 50% 34%, #fffdf2, #f6dfb0 56%, #9c6d3e 100%);
    overflow: hidden;
}

.dealer-portrait {
    position: relative;
    z-index: 1;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 22px;
    filter: drop-shadow(0 3px 4px rgba(42, 20, 8, 0.28));
}

.reaction-badge {
    position: absolute;
    left: 50%;
    bottom: -7px;
    z-index: 2;
    transform: translateX(-50%);
    white-space: nowrap;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 9px;
    font-weight: 900;
    letter-spacing: 0.05em;
    color: #261402;
    background: linear-gradient(180deg, #fff6c2, #f1b93c);
    border: 1px solid #fff9d9;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.55);
}

.bj-table[data-mood="blackjack"] .reaction-badge,
.bj-table[data-mood="twentyone"] .reaction-badge,
.bj-table[data-mood="fever"] .reaction-badge,
.bj-table[data-mood="streak"] .reaction-badge,
.bj-table[data-mood="double"] .reaction-badge {
    color: #fff;
    background: linear-gradient(135deg, #ff2a9d, #ff9900);
    border-color: #fff3b8;
    box-shadow: 0 0 12px rgba(255, 60, 166, 0.8);
}

.dealer-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.dealer-header-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.dealer-name {
    font-size: 15px;
    font-weight: 900;
    color: #fff6db;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
}

.cast-picker {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-left: auto;
}

.cast-btn {
    position: relative;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 50%;
    border: 2px solid rgba(255, 232, 163, 0.38);
    background: #1c122b;
    overflow: hidden;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
}

.cast-btn img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.cast-btn[aria-pressed="true"] {
    border-color: #fff1a8;
    box-shadow:
        0 0 0 2px var(--cast-accent),
        0 0 12px var(--cast-accent);
    transform: scale(1.08);
}

.dealer-speech {
    position: relative;
    min-height: 46px;
    display: flex;
    align-items: center;
    padding: 7px 11px;
    border-radius: 13px;
    border: 1px solid rgba(255, 229, 150, 0.55);
    background: linear-gradient(135deg, rgba(22, 11, 38, 0.92), rgba(40, 18, 58, 0.85));
    color: #fff7e2;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.4;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.14),
        0 4px 12px rgba(0, 0, 0, 0.35);
}

/* Felt Arena */
.felt-arena {
    position: relative;
    padding: 8px 12px 10px;
    background:
        radial-gradient(ellipse at 50% 45%, rgba(28, 122, 96, 0.52), rgba(7, 36, 33, 0.92) 82%),
        repeating-linear-gradient(120deg, rgba(255, 255, 255, 0.015) 0 1px, transparent 1px 5px);
}

.hand-zone {
    position: relative;
    padding: 6px 9px 8px;
    border-radius: 14px;
    border: 1px solid rgba(243, 196, 88, 0.24);
    background: rgba(5, 22, 24, 0.46);
}

.player-zone {
    border-color: rgba(243, 196, 88, 0.42);
    background: linear-gradient(180deg, rgba(14, 38, 40, 0.62), rgba(10, 24, 32, 0.78));
}

.bj-table.is-player-turn .player-zone {
    border-color: #ffe38f;
    box-shadow: inset 0 0 16px rgba(243, 196, 88, 0.14), 0 0 14px rgba(243, 196, 88, 0.18);
}

.hand-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 5px;
}

.hand-label {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.08em;
    color: rgba(235, 220, 184, 0.75);
}

.player-badges {
    display: flex;
    align-items: center;
    gap: 5px;
}

.double-badge {
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 900;
    color: #fff;
    background: linear-gradient(135deg, #ff2e93, #ff8a00);
    border: 1px solid #fff0a8;
    box-shadow: 0 0 10px rgba(255, 46, 147, 0.55);
}

.score-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 42px;
    min-height: 28px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 17px;
    font-weight: 900;
    font-variant-numeric: tabular-nums;
    color: #fff5d6;
    background: rgba(15, 10, 26, 0.78);
    border: 1px solid rgba(243, 196, 88, 0.52);
}

.score-pill.is-twentyone {
    color: #231200;
    background: linear-gradient(135deg, #fff5b8, #f7b733);
    border-color: #fff;
    box-shadow: 0 0 14px rgba(255, 215, 80, 0.75);
}

.score-pill.is-bust {
    color: #ffd9e2;
    background: rgba(128, 18, 46, 0.88);
    border-color: #ff6b8b;
}

/* Each track exposes the top-left rank; the final card stays fully visible. */
.card-row {
    --card-width: 58px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 82px;
    min-width: 0;
    max-width: 100%;
}

.card-row.has-cards {
    display: grid;
    grid-template-columns: repeat(var(--card-gaps), minmax(24px, var(--card-width))) var(--card-width);
    width: max-content;
    max-width: 100%;
    justify-content: start;
    margin-inline: auto;
    gap: 3px;
    /* Very long hands can scroll without shrinking or clipping their ranks. */
    overflow-x: auto;
    padding-bottom: 7px;
    scrollbar-width: thin;
}

.bj-card {
    position: relative;
    flex-shrink: 0;
    width: var(--card-width, 58px);
    height: 82px;
    border-radius: 9px;
    border: 1.5px solid #e6d6a8;
    background: linear-gradient(145deg, #ffffff, #f7efd8 65%, #eadbb5);
    color: #1c2430;
    box-shadow:
        0 3px 0 #9e8a58,
        0 6px 12px rgba(0, 0, 0, 0.48);
    user-select: none;
}

.bj-card.is-red {
    color: #c91e4a;
}

.bj-card.is-drawn {
    border-color: #ffe596;
}

.bj-card.is-golden {
    border-color: #fff2a1;
    background: linear-gradient(145deg, #fffef2, #ffea9f 58%, #f0bd49);
    box-shadow:
        0 3px 0 #9c6b12,
        0 0 16px rgba(255, 216, 89, 0.65);
}

.bj-card__corner {
    position: absolute;
    top: 4px;
    left: 5px;
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1;
}

.bj-card__rank {
    font-size: 16px;
    font-weight: 900;
    letter-spacing: -0.04em;
}

.bj-card__suit-small {
    font-size: 11px;
    margin-top: 1px;
}

.bj-card__center {
    position: absolute;
    right: 6px;
    bottom: 5px;
    font-size: 26px;
    line-height: 1;
    opacity: 0.9;
}

.bj-card.is-hole {
    border-color: #f3c458;
    background:
        radial-gradient(circle at 50% 50%, rgba(255, 224, 130, 0.25), transparent 62%),
        repeating-linear-gradient(45deg, #38124a 0 4px, #220930 4px 8px);
    box-shadow:
        inset 0 0 0 2px rgba(255, 232, 163, 0.35),
        0 3px 0 #6e4812,
        0 6px 12px rgba(0, 0, 0, 0.5);
    display: grid;
    place-items: center;
}

.bj-card.is-hole::after {
    content: "♛";
    font-size: 24px;
    color: #ffe394;
    text-shadow: 0 0 10px rgba(255, 215, 90, 0.7);
}

.card-placeholder {
    font-size: 22px;
    letter-spacing: 0.22em;
    color: rgba(255, 234, 175, 0.22);
}

/* Center Status & Reward Banner */
.center-strip {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 30px;
    margin: 5px 0;
}

.outcome-banner {
    padding: 3px 14px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 0.06em;
    color: #ffeeb8;
    background: rgba(14, 10, 26, 0.72);
    border: 1px solid rgba(243, 196, 88, 0.38);
    text-align: center;
}

.outcome-banner.is-win {
    color: #281500;
    background: linear-gradient(135deg, #fff5bd, #f8bf3c 55%, #e09119);
    border-color: #fff;
    box-shadow: 0 0 18px rgba(255, 206, 68, 0.65);
}

.outcome-banner.is-lose {
    color: #ffd8e2;
    background: linear-gradient(135deg, #521329, #2e0d1d);
    border-color: #ff6b92;
}

.reward-pill {
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 900;
    color: #fff9db;
    background: linear-gradient(135deg, #c97b0c, #ff3ca6);
    border: 1px solid #fff1a8;
    box-shadow: 0 0 14px rgba(255, 60, 166, 0.6);
}

/* In-table Gold Coin & Sparkle Burst Layer */
.coin-burst-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 10;
}

.table-coin-particle {
    position: absolute;
    left: 50%;
    top: 52%;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background:
        radial-gradient(circle at 32% 28%, #fff, transparent 28%),
        linear-gradient(180deg, #fff4ad, #f7b72b 62%, #b56607);
    border: 1px solid #fff7c2;
    box-shadow: 0 0 10px rgba(255, 204, 51, 0.8);
    transform: translate(-50%, -50%);
    animation: table-coin-pop 0.85s cubic-bezier(0.18, 0.78, 0.24, 1) forwards;
}

/* Controls at Bottom */
.bj-controls {
    padding: 8px 10px 10px;
    background: linear-gradient(180deg, #160c28, #0d0718);
    border-top: 1px solid rgba(243, 196, 88, 0.35);
}

.btn-gold {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 50px;
    padding: 8px 16px;
    border-radius: 14px;
    border: 1.5px solid #fff2b2;
    color: #291602;
    background: linear-gradient(125deg, #c48825, #fff0ad 38%, #f2bc46 68%, #b87818);
    box-shadow:
        0 3px 0 #6e4509,
        0 0 20px rgba(243, 196, 88, 0.38),
        inset 0 1px 0 #fffbe0;
}

.btn-main-text {
    font-size: 16px;
    font-weight: 900;
    letter-spacing: 0.08em;
}

.action-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.btn-action {
    display: flex;
    flex-direction: column;
    gap: 2px;
    align-items: center;
    justify-content: center;
    min-height: 50px;
    padding: 6px 3px;
    border-radius: 13px;
    border: 1.5px solid transparent;
    color: #fff8e7;
    font-size: 14px;
    font-weight: 900;
    letter-spacing: 0.04em;
}

.btn-action > span {
    white-space: nowrap;
    font-size: clamp(11px, 3.2vw, 14px);
    letter-spacing: 0;
}

.btn-action > small {
    font-size: 9px;
    line-height: 1.2;
    font-weight: 700;
    letter-spacing: 0;
    white-space: nowrap;
}

.btn-hit {
    background: linear-gradient(145deg, #136f63, #0b443e);
    border-color: #5ef2d6;
    box-shadow: 0 3px 0 #072925, 0 0 14px rgba(44, 240, 255, 0.25);
}

.btn-stand {
    color: #291602;
    background: linear-gradient(135deg, #d4982f, #ffeaa0 48%, #dfa135);
    border-color: #fff2b2;
    box-shadow: 0 3px 0 #70490f, 0 0 14px rgba(243, 196, 88, 0.32);
}

.btn-double {
    background: linear-gradient(145deg, #9e1962, #590d3c);
    border-color: #ff85cb;
    box-shadow: 0 3px 0 #360623, 0 0 16px rgba(255, 60, 166, 0.38);
}

.btn-double.is-recommended:not(:disabled) {
    background: linear-gradient(135deg, #c9186f, #ff7b00 85%);
    border-color: #fff3a6;
    box-shadow:
        0 3px 0 #590d3c,
        0 0 20px rgba(255, 190, 60, 0.72),
        inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.btn-action:disabled {
    opacity: 0.42;
    filter: grayscale(0.5);
    box-shadow: none;
}

/* Rules Dialog */
.bj-dialog {
    width: min(340px, calc(100% - 28px));
    border-radius: 20px;
    border: 1.5px solid #e6b84f;
    padding: 18px 20px;
    color: #fff6df;
    background: radial-gradient(ellipse at 50% 0%, #2d164b, #110920 75%);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
}

.bj-dialog::backdrop {
    background: rgba(6, 3, 14, 0.76);
    backdrop-filter: blur(4px);
}

.bj-dialog h2 {
    margin: 0 0 10px;
    font-size: 18px;
    color: #ffe699;
    text-align: center;
}

.bj-dialog p {
    margin: 0 0 10px;
    font-size: 13px;
    line-height: 1.6;
}

.rules-list {
    margin: 0 0 14px;
    padding-left: 18px;
    font-size: 12px;
    line-height: 1.7;
    color: #ebdcb8;
}

.btn-close-rules {
    min-height: 44px;
    font-size: 14px;
    font-weight: 900;
}

@keyframes table-coin-pop {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.4);
    }
    20% {
        opacity: 1;
        transform: translate(calc(-50% + var(--tx) * 0.45), calc(-50% + var(--ty) * 0.45)) scale(1.15);
    }
    100% {
        opacity: 0;
        transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) scale(0.55);
    }
}

@keyframes dealer-react-pulse {
    0% {
        transform: scale(1);
    }
    40% {
        transform: scale(1.06);
    }
    100% {
        transform: scale(1);
    }
}

@media (prefers-reduced-motion: no-preference) {
    .dealer-portrait-wrap.is-reacting {
        animation: dealer-react-pulse 0.36s ease;
    }
}

@media (max-height: 740px) {
    .dealer-stage {
        grid-template-columns: 106px minmax(0, 1fr);
        padding: 5px 10px;
    }
    .dealer-portrait-wrap {
        width: 106px;
        height: 106px;
    }
    .dealer-speech {
        min-height: 42px;
        padding: 5px 9px;
        font-size: 11px;
    }
    .bj-table[data-phase="player"] .center-strip {
        min-height: 23px;
        margin: 2px 0;
    }
    .bj-table[data-phase="player"] .outcome-banner {
        padding-block: 2px;
        font-size: 11px;
    }
}

/* Keep the expanded cast roster within the play panel. */
.cast-picker { min-width: 0; max-width: 100%; overflow-x: auto; padding-bottom: 10px; }
.cast-picker > button { flex-shrink: 0; }

/* Side totals only when there is room for both the cards and the full score. */
@media (min-width: 390px) {
    .bj-table:not(.has-many-cards) .hand-zone {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        column-gap: 8px;
    }
    .bj-table:not(.has-many-cards) .hand-header { display: contents; }
    .bj-table:not(.has-many-cards) .hand-label { grid-column: 1 / -1; margin-bottom: 3px; }
    .bj-table:not(.has-many-cards) .card-row { grid-column: 1; grid-row: 2; }
    .bj-table:not(.has-many-cards) .score-pill,
    .bj-table:not(.has-many-cards) .player-badges { grid-column: 2; grid-row: 2; }
    .bj-table:not(.has-many-cards) .player-badges { flex-direction: column; }
}

@media (max-height: 620px) {
    .dealer-stage { grid-template-columns: 90px minmax(0, 1fr); gap: 8px; padding-block: 4px; }
    .dealer-portrait-wrap { width: 90px; height: 90px; }
    .dealer-info { gap: 4px; }
    .felt-arena { padding-block: 5px; }
    .hand-zone { padding-block: 4px; }
}
