/* Blackjack 21 — Classic Casino Felt Style */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    /* Felt / table */
    --felt-deep:    #0a3a24;
    --felt-mid:     #0f5132;
    --felt-light:   #146140;

    /* Gold accents */
    --gold:         #d4af37;
    --gold-light:   #f0d77a;
    --gold-dark:    #b8941f;

    /* Cards */
    --card-white:   #fdfdfd;
    --card-red:     #c8102e;
    --card-black:   #1a1a1a;
    --card-back:    #5b2129;
    --card-back-2:  #8a2f3a;

    /* Outcomes */
    --win-color:    #22c55e;
    --lose-color:   #ef4444;
    --push-color:   #facc15;

    /* Text */
    --text-white:   #f5f5f5;
    --text-muted:   #b0c8b8;

    /* Sizing */
    --card-w:        4.25rem;
    --card-h:        6rem;
    --card-radius:   0.45rem;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 16px;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    background:
        radial-gradient(ellipse at 50% 30%, var(--felt-light) 0%, var(--felt-mid) 45%, var(--felt-deep) 100%);
    min-height: calc(100dvh - 3.5rem);
    color: var(--text-white);
}

/* ============ SCREENS (loading / login) ============ */
.screen {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: var(--felt-deep);
    color: var(--text-white);
    z-index: 1000;
}

.screen.hidden { display: none; }

.loading-spinner {
    width: 3.25rem;
    height: 3.25rem;
    border: 0.2rem solid rgba(212, 175, 55, 0.18);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: spinAnim 1s linear infinite;
}

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

#loading-screen p {
    margin-top: 1rem;
    color: var(--gold);
    font-size: 0.95rem;
    letter-spacing: 0.06rem;
}

.login-content { text-align: center; }
.login-icon { font-size: 3.5rem; margin-bottom: 1rem; }
.login-content h2 { color: var(--gold); margin-bottom: 0.5rem; }
.login-content p { color: var(--text-muted); }

/* ============ GAME CONTAINER ============ */
#game-container {
    width: 100%;
    max-width: 31rem;
    height: 100%;
    max-height: 56rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5rem 0.75rem 0.75rem;
    position: relative;
    z-index: 1;
}

#game-container.hidden { display: none; }

/* ============ HEADER ============ */
#game-header {
    width: 100%;
    padding: 0.4rem 0 0.6rem;
    display: flex;
    justify-content: center;
}

.balance-display {
    background: linear-gradient(180deg, rgba(212, 175, 55, 0.18) 0%, rgba(184, 148, 31, 0.08) 100%);
    border: 0.09rem solid var(--gold-dark);
    border-radius: 1.25rem;
    padding: 0.4rem 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    box-shadow: 0 0 1rem rgba(212, 175, 55, 0.18);
}

.balance-label { color: var(--text-muted); font-size: 0.75rem; letter-spacing: 0.03rem; }

#balance-value {
    color: var(--gold);
    font-size: 1.2rem;
    font-weight: 700;
    min-width: 4.4rem;
    text-align: right;
    text-shadow: 0 0 0.6rem rgba(212, 175, 55, 0.45);
}

.balance-currency { color: var(--gold-dark); font-size: 0.7rem; }

/* ============ TABLE / FELT FRAME ============ */
#table {
    flex: 1;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0.4rem 0;
    min-height: 0;
}

.felt-frame {
    position: relative;
    width: 100%;
    min-height: 22rem;
    background:
        radial-gradient(ellipse at 50% 50%, var(--felt-light) 0%, var(--felt-mid) 60%, var(--felt-deep) 100%);
    border: 0.18rem solid var(--gold-dark);
    border-radius: 1rem;
    box-shadow:
        inset 0 0 1.5rem rgba(0, 0, 0, 0.45),
        0 0.5rem 2rem rgba(0, 0, 0, 0.45),
        0 0 0 0.05rem rgba(212, 175, 55, 0.25);
    padding: 0.8rem 0.7rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 0.6rem;
    overflow: hidden;
}

/* subtle top gold inner highlight */
.felt-frame::before {
    content: '';
    position: absolute;
    inset: 0.25rem;
    border: 0.05rem solid rgba(212, 175, 55, 0.25);
    border-radius: 0.75rem;
    pointer-events: none;
}

/* ============ DECK (top-right) ============ */
#deck-pile {
    position: absolute;
    top: 0.7rem;
    right: 0.8rem;
    width: var(--card-w);
    height: var(--card-h);
    z-index: 2;
    pointer-events: none;
}

.deck-card {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: var(--card-radius);
    background:
        repeating-linear-gradient(45deg,
            var(--card-back) 0, var(--card-back) 0.25rem,
            var(--card-back-2) 0.25rem, var(--card-back-2) 0.5rem);
    border: 0.12rem solid var(--gold-dark);
    box-shadow: 0 0.15rem 0.4rem rgba(0, 0, 0, 0.5);
}

.deck-card:nth-child(1) { transform: translate(0.18rem, 0.18rem); }
.deck-card:nth-child(2) { transform: translate(0.09rem, 0.09rem); }
.deck-card:nth-child(3) { transform: translate(0, 0); }

/* ============ HAND ROWS ============ */
.hand-row {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.3rem 0.4rem;
    min-height: calc(var(--card-h) + 0.4rem);
}

.dealer-row { justify-content: flex-start; }
.player-row { justify-content: flex-end; }

.hand-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    min-width: 3.4rem;
    z-index: 1;
}

.hand-label {
    color: var(--gold);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.12rem;
    text-shadow: 0 0 0.4rem rgba(0, 0, 0, 0.6);
}

.hand-score {
    background: rgba(0, 0, 0, 0.45);
    border: 0.09rem solid var(--gold-dark);
    border-radius: 0.75rem;
    padding: 0.15rem 0.6rem;
    color: var(--gold-light);
    font-size: 1rem;
    font-weight: 700;
    min-width: 2.4rem;
    text-align: center;
}

.hand {
    display: flex;
    align-items: center;
    gap: -0.5rem;
    flex: 1;
    min-height: var(--card-h);
}

/* overlap cards slightly */
.hand .card + .card {
    margin-left: -1.6rem;
}

.hand.win  { animation: handWin 0.6s ease; }
.hand.lose { animation: handLose 0.5s ease; }
.hand.push { animation: handPush 0.5s ease; }
.hand.bust { animation: handBust 0.45s ease; }

@keyframes handWin {
    0%, 100% { transform: translateY(0); filter: none; }
    50%       { transform: translateY(-0.3rem); filter: drop-shadow(0 0 0.8rem var(--win-color)); }
}

@keyframes handLose {
    0%, 100% { filter: none; }
    50%       { filter: brightness(0.7); }
}

@keyframes handPush {
    0%, 100% { filter: none; }
    50%       { filter: drop-shadow(0 0 0.6rem var(--push-color)); }
}

@keyframes handBust {
    0%, 100% { transform: translateX(0); }
    25%       { transform: translateX(-0.4rem); }
    75%       { transform: translateX(0.4rem); }
}

/* ============ FELT DIVIDER ============ */
.felt-divider {
    height: 0.05rem;
    background: linear-gradient(90deg, transparent, rgba(212, 175, 55, 0.5) 30%, rgba(212, 175, 55, 0.5) 70%, transparent);
    margin: 0 1rem;
}

/* ============ CARDS ============ */
.card {
    width: var(--card-w);
    height: var(--card-h);
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.5s ease;
    flex-shrink: 0;
}

.card.flipped {
    transform: rotateY(180deg);
}

/* Entry animation: card flies in from deck (top-right) */
.card.dealing {
    transform: translate(8rem, -4rem) rotate(180deg) scale(0.6);
    opacity: 0.2;
}

.card-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: var(--card-radius);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 0.3rem 0.4rem;
}

.card-front {
    background: var(--card-white);
    box-shadow: 0 0.2rem 0.6rem rgba(0, 0, 0, 0.4);
    border: 0.06rem solid rgba(0, 0, 0, 0.1);
}

.card-back {
    background:
        repeating-linear-gradient(45deg,
            var(--card-back) 0, var(--card-back) 0.25rem,
            var(--card-back-2) 0.25rem, var(--card-back-2) 0.5rem);
    transform: rotateY(180deg);
    box-shadow: 0 0.2rem 0.6rem rgba(0, 0, 0, 0.4);
    border: 0.12rem solid var(--gold-dark);
}

.card-back::after {
    content: '';
    position: absolute;
    inset: 0.3rem;
    border: 0.06rem solid rgba(212, 175, 55, 0.55);
    border-radius: calc(var(--card-radius) - 0.15rem);
}

.card-rank-top {
    font-size: 1.05rem;
    font-weight: 800;
    line-height: 1;
}

.card-suit-center {
    font-size: 2rem;
    text-align: center;
    line-height: 1;
    align-self: center;
}

.card-rank-bottom {
    font-size: 1.05rem;
    font-weight: 800;
    text-align: right;
    line-height: 1;
    transform: rotate(180deg);
    align-self: flex-end;
}

.card.red .card-rank-top,
.card.red .card-rank-bottom,
.card.red .card-suit-center {
    color: var(--card-red);
}

.card.black .card-rank-top,
.card.black .card-rank-bottom,
.card.black .card-suit-center {
    color: var(--card-black);
}

/* ============ RESULT DISPLAY ============ */
#result-display {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(160deg, rgba(15, 81, 50, 0.97) 0%, rgba(10, 58, 36, 0.97) 100%);
    padding: 1rem 2rem;
    border-radius: 0.9rem;
    border: 0.12rem solid var(--gold);
    box-shadow:
        0 0 0 0.05rem rgba(212, 175, 55, 0.3),
        0 0 2.5rem rgba(212, 175, 55, 0.45),
        inset 0 0.05rem 0 rgba(255, 255, 255, 0.08);
    z-index: 100;
    text-align: center;
    animation: resultPopup 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#result-display.hidden { display: none; }

@keyframes resultPopup {
    0%   { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    100% { transform: translate(-50%, -50%) scale(1);   opacity: 1; }
}

.result-text {
    display: block;
    font-size: 1.7rem;
    font-weight: 800;
    letter-spacing: 0.15rem;
    text-shadow: 0 0.15rem 0.4rem rgba(0, 0, 0, 0.6);
}

.result-text.win  { color: var(--win-color); }
.result-text.lose { color: var(--lose-color); }
.result-text.push { color: var(--push-color); }

.result-amount {
    display: block;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--gold);
    margin-top: 0.3rem;
    text-shadow: 0 0 0.8rem rgba(212, 175, 55, 0.5);
}

/* ============ MESSAGE DISPLAY ============ */
#message-display {
    position: absolute;
    bottom: 12rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    padding: 0.5rem 1.3rem;
    border-radius: 0.5rem;
    border: 0.09rem solid var(--gold);
    z-index: 100;
    white-space: nowrap;
}

#message-display.hidden { display: none; }

#message-text {
    color: var(--text-white);
    font-size: 0.85rem;
}

/* ============ ACTION BUTTONS (HIT / STAND) ============ */
#action-buttons {
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 0.8rem;
    padding: 0.4rem 0.2rem 0.2rem;
}

#action-buttons.hidden { display: none; }

.action-btn {
    flex: 1;
    max-width: 9rem;
    height: 3rem;
    border: 0.12rem solid var(--gold);
    border-radius: 0.6rem;
    color: #fff;
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: 0.15rem;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.15s ease;
    text-shadow: 0 0.1rem 0.2rem rgba(0, 0, 0, 0.5);
}

.action-btn.hit {
    background: linear-gradient(180deg, #1f9d55 0%, #11623a 100%);
    box-shadow: 0 0.25rem 0.9rem rgba(34, 197, 94, 0.35);
}

.action-btn.stand {
    background: linear-gradient(180deg, #c8102e 0%, #7e1322 100%);
    box-shadow: 0 0.25rem 0.9rem rgba(200, 16, 46, 0.35);
}

.action-btn:hover:not(:disabled) {
    transform: translateY(-0.1rem);
}

.action-btn:active:not(:disabled) {
    transform: translateY(0);
}

.action-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* ============ BETTING CONTROLS ============ */
#betting-controls {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.55rem;
    padding: 0.4rem 0.2rem 0.2rem;
}

#betting-controls.hidden { display: none; }

.bet-selector {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.bet-label {
    color: var(--gold);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.1rem;
    text-transform: uppercase;
}

.bet-buttons {
    display: flex;
    gap: 0.35rem;
}

.bet-btn {
    width: 2.8rem;
    height: 2rem;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.04) 0%, rgba(0, 0, 0, 0.2) 100%);
    border: 0.09rem solid var(--gold-dark);
    border-radius: 0.4rem;
    color: var(--text-white);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
}

.bet-btn:hover:not(:disabled) {
    border-color: var(--gold);
    background: rgba(212, 175, 55, 0.12);
}

.bet-btn.active {
    background: linear-gradient(180deg, var(--gold) 0%, var(--gold-dark) 100%);
    color: var(--felt-deep);
    border-color: var(--gold-light);
    box-shadow: 0 0.15rem 0.5rem rgba(212, 175, 55, 0.4);
}

.bet-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.current-bet {
    background: rgba(0, 0, 0, 0.4);
    padding: 0.2rem 0.7rem;
    border-radius: 0.4rem;
    border: 0.09rem solid var(--gold-dark);
}

#current-bet-value {
    color: var(--gold);
    font-size: 1rem;
    font-weight: 800;
}

/* ============ DEAL BUTTON ============ */
#deal-btn {
    width: 100%;
    max-width: 18rem;
    height: 3rem;
    background: linear-gradient(180deg, var(--gold) 0%, var(--gold-dark) 100%);
    border: 0.15rem solid #fff8dc;
    border-radius: 1.6rem;
    color: var(--felt-deep);
    cursor: pointer;
    box-shadow:
        0 0.25rem 1rem rgba(212, 175, 55, 0.45),
        inset 0 0.05rem 0 rgba(255, 255, 255, 0.4);
    transition: all 0.18s ease;
}

#deal-btn:hover:not(:disabled) {
    transform: translateY(-0.1rem);
    box-shadow: 0 0.4rem 1.4rem rgba(212, 175, 55, 0.6);
}

#deal-btn:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 0.15rem 0.6rem rgba(212, 175, 55, 0.4);
}

#deal-btn:disabled {
    background: linear-gradient(180deg, #555 0%, #333 100%);
    border-color: rgba(255, 255, 255, 0.1);
    color: #999;
    box-shadow: none;
    cursor: not-allowed;
}

#deal-btn.pulse {
    animation: dealPulse 1.6s ease-in-out infinite;
}

@keyframes dealPulse {
    0%, 100% { box-shadow: 0 0.25rem 1rem rgba(212, 175, 55, 0.45); }
    50%       { box-shadow: 0 0.25rem 2rem rgba(240, 215, 122, 0.85); }
}

.deal-text {
    color: var(--felt-deep);
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: 0.25rem;
}

#deal-btn:disabled .deal-text { color: #777; }

/* ============ GAME TITLE ============ */
.game-title {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0 0.2rem;
}

.title-suit {
    font-size: 1rem;
    line-height: 1;
}

.title-suit.red   { color: var(--card-red); }
.title-suit.black { color: #2a2a2a; text-shadow: 0 0 0.3rem rgba(255, 255, 255, 0.2); }

.title-text {
    color: var(--gold);
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.2rem;
    text-transform: uppercase;
    text-shadow: 0 0 0.6rem rgba(212, 175, 55, 0.5);
}

/* ============ PARTICLES ============ */
#particles-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1500;
}

.particle {
    position: absolute;
    font-size: 1.3rem;
    animation: particleFall 2s ease-out forwards;
}

@keyframes particleFall {
    0%   { opacity: 1; transform: translateY(0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translateY(80vh) rotate(540deg) scale(0.3); }
}

/* ============ RESPONSIVE ============ */
@media (max-width: 25rem) {
    :root {
        --card-w: 3.6rem;
        --card-h: 5.05rem;
    }
    .card-suit-center { font-size: 1.6rem; }
    .card-rank-top, .card-rank-bottom { font-size: 0.9rem; }
    .hand .card + .card { margin-left: -1.4rem; }
    .bet-btn { width: 2.4rem; height: 1.8rem; font-size: 0.75rem; }
    .action-btn { height: 2.6rem; font-size: 0.9rem; }
    #deal-btn { height: 2.7rem; }
    .deal-text { font-size: 0.95rem; }
}

@media (max-height: 44rem) {
    .felt-frame { min-height: 18rem; }
    :root {
        --card-w: 3.8rem;
        --card-h: 5.35rem;
    }
}
