:root {
    color-scheme: dark;
    --bg: #04110e;
    --panel: rgba(8, 27, 22, 0.86);
    --panel-border: rgba(255, 255, 255, 0.08);
    --felt: #0a5d43;
    --felt-dark: #063e2f;
    --gold: #f6c65b;
    --gold-dark: #a46b13;
    --text: #f6f8f7;
    --muted: #9eb4ac;
    --danger: #ff6b70;
    --success: #72e2a9;
    --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
    margin: 0;
}

body {
    min-height: 100vh;
    background:
        radial-gradient(circle at 50% -20%, rgba(19, 119, 83, 0.42), transparent 45%),
        linear-gradient(160deg, #071915 0%, var(--bg) 55%, #020806 100%);
    color: var(--text);
    overflow-x: hidden;
}

button,
input {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

.ambient {
    position: fixed;
    z-index: -1;
    width: 280px;
    height: 280px;
    border-radius: 50%;
    filter: blur(90px);
    opacity: 0.14;
    pointer-events: none;
}

.ambient-one {
    top: 10%;
    left: -140px;
    background: #18d58a;
}

.ambient-two {
    right: -140px;
    bottom: 0;
    background: #f6c65b;
}

.app-shell {
    width: min(100%, 760px);
    margin: 0 auto;
    padding: max(16px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom));
}

.glass-panel {
    border: 1px solid var(--panel-border);
    background: var(--panel);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 18px;
    border-radius: 22px;
}

.eyebrow {
    margin: 0 0 2px;
    color: var(--gold);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.2em;
}

h1 {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(28px, 8vw, 42px);
    line-height: 1;
}

.balance-box {
    min-width: 126px;
    padding: 10px 14px;
    border: 1px solid rgba(246, 198, 91, 0.24);
    border-radius: 16px;
    background: rgba(246, 198, 91, 0.08);
    text-align: right;
}

.balance-box span,
.bet-now span {
    display: block;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.balance-box strong {
    display: block;
    margin-top: 2px;
    color: var(--gold);
    font-size: 18px;
}

.notice {
    margin: 12px 2px 0;
    padding: 12px 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    background: rgba(255, 255, 255, 0.06);
    font-size: 14px;
    line-height: 1.4;
}

.notice.success {
    border-color: rgba(114, 226, 169, 0.35);
    background: rgba(114, 226, 169, 0.09);
    color: #c9ffe2;
}

.notice.error {
    border-color: rgba(255, 107, 112, 0.35);
    background: rgba(255, 107, 112, 0.09);
    color: #ffd5d6;
}

.table-wrap {
    padding: 14px 0;
}

.table-surface {
    position: relative;
    min-height: 480px;
    padding: 22px 18px;
    overflow: hidden;
    border: 9px solid #382716;
    border-radius: 44% 44% 24px 24px / 18% 18% 24px 24px;
    background:
        radial-gradient(circle at center, rgba(255, 255, 255, 0.05), transparent 55%),
        repeating-radial-gradient(circle at 30% 40%, rgba(255,255,255,0.018) 0 1px, transparent 1px 4px),
        linear-gradient(180deg, var(--felt) 0%, var(--felt-dark) 100%);
    box-shadow:
        inset 0 0 0 2px rgba(246, 198, 91, 0.28),
        inset 0 -30px 80px rgba(0, 0, 0, 0.25),
        0 24px 70px rgba(0, 0, 0, 0.48);
}

.table-ring {
    position: absolute;
    inset: 30px 24px 24px;
    border: 1px solid rgba(246, 198, 91, 0.35);
    border-bottom: none;
    border-radius: 50% 50% 0 0 / 26% 26% 0 0;
    pointer-events: none;
}

.hand-zone {
    position: relative;
    z-index: 2;
}

.hand-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.hand-heading .label {
    display: block;
    color: rgba(255, 255, 255, 0.62);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.hand-heading strong {
    font-size: 23px;
}

.rule-chip {
    padding: 6px 9px;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 999px;
    background: rgba(0,0,0,0.16);
    color: rgba(255,255,255,0.7);
    font-size: 11px;
    font-weight: 800;
}

.cards-row {
    display: flex;
    justify-content: center;
    min-height: 128px;
    padding: 4px 22px;
}

.playing-card {
    position: relative;
    width: 84px;
    height: 122px;
    flex: 0 0 auto;
    margin-left: -18px;
    border: 1px solid rgba(0,0,0,0.25);
    border-radius: 12px;
    background: linear-gradient(145deg, #fff 0%, #e9eceb 100%);
    box-shadow: 0 12px 24px rgba(0,0,0,0.28);
    color: #18201e;
    transform: rotate(var(--card-rotation, 0deg));
    animation: deal-card 0.44s cubic-bezier(.2,.8,.2,1) both;
}

.playing-card:first-child {
    margin-left: 0;
}

.playing-card.red {
    color: #c62d35;
}

.playing-card .corner {
    position: absolute;
    top: 7px;
    left: 8px;
    display: grid;
    justify-items: center;
    font-family: Georgia, serif;
    font-size: 18px;
    font-weight: 700;
    line-height: 0.9;
}

.playing-card .corner small {
    margin-top: 4px;
    font-size: 16px;
}

.playing-card .suit-large {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-family: Georgia, serif;
    font-size: 44px;
}

.playing-card.card-back {
    border: 3px solid #f2e3bd;
    background:
        linear-gradient(45deg, transparent 42%, rgba(255,255,255,0.16) 42% 58%, transparent 58%),
        linear-gradient(-45deg, transparent 42%, rgba(255,255,255,0.12) 42% 58%, transparent 58%),
        #5d1226;
    background-size: 14px 14px;
    box-shadow: inset 0 0 0 3px #8f2841, 0 12px 24px rgba(0,0,0,0.3);
}

.center-mark {
    display: grid;
    place-items: center;
    min-height: 92px;
    color: rgba(246, 198, 91, 0.64);
    text-align: center;
    text-shadow: 0 1px 0 rgba(0,0,0,0.3);
}

.center-mark span {
    font-family: Georgia, serif;
    font-size: clamp(15px, 4.8vw, 22px);
    font-weight: 700;
    letter-spacing: 0.08em;
}

.center-mark small {
    margin-top: 5px;
    font-size: 10px;
    letter-spacing: 0.16em;
}

.player-heading {
    margin-top: 12px;
    margin-bottom: 0;
}

.bet-now {
    text-align: right;
}

.bet-now strong {
    color: var(--gold);
    font-size: 18px;
}

.control-panel {
    padding: 16px;
    border-radius: 24px;
}

.section-title {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
}

.section-title span {
    font-weight: 800;
}

.section-title small {
    color: var(--muted);
}

.chips {
    display: grid;
    grid-template-columns: repeat(5, minmax(48px, 1fr));
    gap: 8px;
    margin-bottom: 14px;
}

.chip {
    position: relative;
    aspect-ratio: 1;
    padding: 0;
    border: 4px dashed rgba(255,255,255,0.75);
    border-radius: 50%;
    box-shadow: inset 0 0 0 4px rgba(0,0,0,0.18), 0 7px 14px rgba(0,0,0,0.24);
    color: white;
    cursor: pointer;
    transition: transform .16s ease, filter .16s ease;
}

.chip:active,
.chip.selected {
    transform: translateY(2px) scale(0.94);
    filter: brightness(1.2);
}

.chip span {
    display: grid;
    width: 64%;
    height: 64%;
    margin: auto;
    place-items: center;
    border: 1px solid rgba(255,255,255,0.42);
    border-radius: 50%;
    font-size: clamp(10px, 3vw, 14px);
    font-weight: 900;
}

.chip-gold { background: #bd8318; }
.chip-blue { background: #1d63a8; }
.chip-red { background: #a12735; }
.chip-purple { background: #653694; }
.chip-dark { background: #202925; }

.custom-bet {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    padding: 11px 13px;
    border: 1px solid rgba(255,255,255,0.09);
    border-radius: 15px;
    background: rgba(255,255,255,0.035);
}

.custom-bet span {
    color: var(--muted);
    font-size: 13px;
}

.custom-bet input {
    width: 130px;
    padding: 8px 10px;
    border: 1px solid rgba(246, 198, 91, 0.24);
    border-radius: 10px;
    outline: none;
    background: rgba(0,0,0,0.22);
    color: var(--gold);
    font-weight: 800;
    text-align: right;
}

.primary-button,
.action-button {
    width: 100%;
    border: none;
    border-radius: 15px;
    color: white;
    cursor: pointer;
    font-weight: 900;
    transition: transform .14s ease, opacity .14s ease, filter .14s ease;
}

.primary-button {
    min-height: 52px;
    background: linear-gradient(180deg, #d49a2d, #8f5a0e);
    box-shadow: inset 0 1px 0 rgba(255,255,255,.26), 0 10px 24px rgba(143,90,14,.28);
    font-size: 16px;
}

.primary-button:active,
.action-button:active {
    transform: translateY(2px);
}

button:disabled {
    cursor: not-allowed;
    filter: grayscale(.45);
    opacity: .48;
}

.game-controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 9px;
}

.action-button {
    min-height: 58px;
    padding: 8px 4px;
    font-size: 13px;
}

.action-icon {
    display: block;
    margin-bottom: 2px;
    font-size: 17px;
}

.hit-button { background: linear-gradient(180deg, #248a62, #13563f); }
.stand-button { background: linear-gradient(180deg, #9a3b43, #5f1e26); }
.double-button { background: linear-gradient(180deg, #9a7627, #624712); }

.finished-controls {
    display: grid;
}

.link-button {
    display: block;
    margin: 13px auto 0;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    text-decoration: underline;
    cursor: pointer;
}

footer {
    display: flex;
    justify-content: center;
    gap: 18px;
    padding: 14px 6px 0;
    color: var(--muted);
    font-size: 11px;
}

footer b {
    color: #dbe7e2;
}

.loader-overlay {
    position: fixed;
    z-index: 20;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(2, 9, 7, 0.84);
    backdrop-filter: blur(10px);
    transition: opacity .25s ease, visibility .25s ease;
}

.loader-overlay.hidden {
    visibility: hidden;
    opacity: 0;
}

.loader-card {
    display: grid;
    justify-items: center;
    width: min(100%, 330px);
    padding: 26px;
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 22px;
    background: #0a1e18;
    box-shadow: var(--shadow);
    text-align: center;
}

.loader-card span {
    margin-top: 6px;
    color: var(--muted);
    font-size: 12px;
}

.spinner {
    width: 44px;
    height: 44px;
    margin-bottom: 16px;
    border: 4px solid rgba(246,198,91,.16);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

.hidden {
    display: none !important;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes deal-card {
    from {
        opacity: 0;
        transform: translateY(-40px) rotate(var(--card-rotation, 0deg)) scale(.72);
    }
    to {
        opacity: 1;
        transform: translateY(0) rotate(var(--card-rotation, 0deg)) scale(1);
    }
}

@media (min-width: 620px) {
    .app-shell {
        padding-top: 24px;
    }

    .table-surface {
        min-height: 540px;
        padding: 28px 36px;
    }

    .cards-row {
        min-height: 145px;
    }

    .playing-card {
        width: 96px;
        height: 140px;
    }
}
