/* ============================================================
   Blackjack - Styles
   ============================================================ */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    display: flex;
    justify-content: center;
}

/* ── Container ── */
.game-container {
    width: 100%;
    max-width: 560px;
    min-height: 480px;
    background: linear-gradient(180deg, #1a2332 0%, #0f1923 100%);
    display: flex;
    flex-direction: column;
    position: relative;
}

/* ── Background Texture ── */
.game-container::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse at 20% 20%, rgba(34, 197, 94, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(59, 130, 246, 0.06) 0%, transparent 50%);
    pointer-events: none;
}

/* ── Header ── */
.game-header {
    padding: 12px 16px 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    z-index: 1;
}

.title-section {
    flex-shrink: 0;
}

.title-section h1 {
    font-size: 18px;
    font-weight: 800;
    color: #f1f5f9;
    line-height: 1.2;
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 10px;
    color: #64748b;
    font-weight: 500;
}

/* ── Money Section ── */
.money-section {
    display: flex;
    gap: 10px;
    margin-left: auto;
}

.money-item {
    text-align: center;
    min-width: 56px;
    background: rgba(255,255,255,0.05);
    border-radius: 8px;
    padding: 2px 8px;
}

.money-label {
    display: block;
    font-size: 8px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.money-value {
    display: block;
    font-size: 15px;
    font-weight: 800;
    color: #e2e8f0;
    line-height: 1.3;
}

.player-money .money-value {
    color: #22c55e;
}

.reset-stats-btn {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    color: #64748b;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.reset-stats-btn:hover {
    background: rgba(34, 197, 94, 0.15);
    border-color: rgba(34, 197, 94, 0.3);
    color: #22c55e;
}

/* ── Bet Bar ── */
.bet-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 16px 10px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    position: relative;
    z-index: 1;
}

.bet-label {
    font-size: 10px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.bet-value {
    font-size: 14px;
    font-weight: 800;
    color: #fbbf24;
}

/* ── Game Content (horizontal layout) ── */
.game-content {
    flex: 1;
    display: flex;
    flex-direction: row;
    min-height: 0;
    position: relative;
    z-index: 1;
}

/* ── Game Board (cards area, left) ── */
.game-board {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 12px 16px;
    gap: 6px;
    min-width: 0;
}

/* ── Side Panel (message + controls, right) ── */
.side-panel {
    width: 140px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 16px;
    padding: 12px;
    border-left: 1px solid rgba(255,255,255,0.06);
}


.player-section {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.player-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.label-icon {
    font-size: 16px;
}

.label-text {
    font-size: 13px;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.score-badge {
    margin-left: auto;
    background: rgba(255,255,255,0.08);
    padding: 3px 12px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 800;
    color: #e2e8f0;
    min-width: 30px;
    text-align: center;
    transition: all 0.3s;
}

.score-badge.bust {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.score-badge.blackjack {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

/* ── Cards ── */
.cards {
    display: flex;
    gap: -20px;
    padding: 4px 0;
    min-height: 120px;
    flex-wrap: wrap;
    align-items: flex-start;
}

.card {
    width: 80px;
    height: 112px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    position: relative;
    box-shadow:
        0 2px 8px rgba(0,0,0,0.3),
        inset 0 1px 0 rgba(255,255,255,0.2);
    transition: transform 0.3s ease;
    margin-right: -16px;
    animation: dealCard 0.6s ease-out;
}

@keyframes dealCard {
    from {
        opacity: 0;
        transform: translateY(-30px) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

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

.card.red {
    background: linear-gradient(135deg, #fff0f0, #fff);
    color: #dc2626;
    border: 1px solid #fecaca;
}

.card.black {
    background: linear-gradient(135deg, #f0f0f0, #fff);
    color: #1e293b;
    border: 1px solid #e2e8f0;
}

.card-back {
    background: linear-gradient(135deg, #1e40af, #3b82f6);
    border: 2px solid #1d4ed8;
    box-shadow:
        0 2px 8px rgba(0,0,0,0.3),
        inset 0 0 20px rgba(59, 130, 246, 0.3);
}

.card-back::after {
    content: '🎴';
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    opacity: 0.8;
}

/* ── Card Flip Animation ── */
.card-flip-container {
    width: 80px;
    height: 112px;
    perspective: 400px;
    margin-right: -16px;
    flex-shrink: 0;
    animation: dealCard 0.6s ease-out;
}

.card-flip-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.8s ease;
    transform-style: preserve-3d;
}

.card-flip-inner.flipping {
    transform: rotateY(180deg);
}

.card-flip-front,
.card-flip-back {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    border-radius: 8px;
}

.card-flip-front {
    z-index: 1;
    transform: rotateY(180deg);
}

.card-flip-back {
    z-index: 2;
    background: linear-gradient(135deg, #1e40af, #3b82f6);
    border: 2px solid #1d4ed8;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow:
        0 2px 8px rgba(0,0,0,0.3),
        inset 0 0 20px rgba(59, 130, 246, 0.3);
}

.card-flip-back::after {
    content: '🎴';
    font-size: 28px;
    opacity: 0.8;
}

@media (max-width: 480px) {
    .card-flip-container {
        width: 68px;
        height: 96px;
        margin-right: -14px;
    }
}

.card-rank {
    font-size: 18px;
    font-weight: 800;
    line-height: 1;
}

.card-suit {
    font-size: 22px;
    line-height: 1;
    margin-top: 4px;
}

.card-corner {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1;
}

.card-corner-top {
    top: 5px;
    left: 6px;
}

.card-corner-bottom {
    bottom: 5px;
    right: 6px;
    transform: rotate(180deg);
}

.card-corner .cr {
    font-size: 12px;
    font-weight: 800;
}

.card-corner .cs {
    font-size: 10px;
}

.card-center-suit {
    font-size: 28px;
    margin-top: 4px;
    opacity: 0.3;
}

/* ── Divider ── */
.divider {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 0;
}

.divider-line {
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
}

.vs-badge {
    font-size: 11px;
    font-weight: 700;
    color: #475569;
    background: rgba(255,255,255,0.05);
    padding: 4px 10px;
    border-radius: 12px;
    letter-spacing: 1px;
    border: 1px solid rgba(255,255,255,0.06);
}

/* ── Message Area ── */
.message-area {
    text-align: center;
}

.message-text {
    display: inline-block;
    font-size: 13px;
    font-weight: 700;
    color: #94a3b8;
    background: rgba(255,255,255,0.04);
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.06);
    transition: all 0.3s;
    writing-mode: horizontal-tb;
    max-width: 100%;
}

.message-text.win {
    color: #22c55e;
    background: rgba(34, 197, 94, 0.1);
    border-color: rgba(34, 197, 94, 0.2);
}

.message-text.lose {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.2);
}

.message-text.tie {
    color: #eab308;
    background: rgba(234, 179, 8, 0.1);
    border-color: rgba(234, 179, 8, 0.2);
}

.message-text.blackjack-message {
    color: #22c55e;
    background: rgba(34, 197, 94, 0.15);
    border-color: rgba(34, 197, 94, 0.3);
    font-size: 16px;
    animation: pulseGlow 0.6s ease-in-out infinite alternate;
}

@keyframes pulseGlow {
    from { box-shadow: 0 0 10px rgba(34, 197, 94, 0.2); }
    to { box-shadow: 0 0 20px rgba(34, 197, 94, 0.4); }
}

/* ── Bet Controls ── */
.bet-controls {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.bet-options {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    align-items: center;
}

.btn-bet {
    padding: 8px 20px;
    border: 2px solid rgba(255,255,255,0.12);
    border-radius: 10px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.5px;
    width: 100%;
    max-width: 110px;
    text-align: center;
    background: rgba(255,255,255,0.04);
    color: #94a3b8;
}

.btn-bet:hover {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.4);
    color: #60a5fa;
    transform: translateY(-1px);
}

.btn-bet:active {
    transform: scale(0.96);
}

.btn-bet-allin {
    border-color: rgba(239, 68, 68, 0.3);
    color: #f87171;
}

.btn-bet-allin:hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.5);
    color: #ef4444;
}

/* ── Controls (vertical in side panel) ── */
.controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    align-items: center;
}

.btn {
    padding: 10px 24px;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.5px;
    width: 100%;
    max-width: 110px;
    text-align: center;
}

.btn:active {
    transform: scale(0.96);
}

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

.btn-hit {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-hit:hover:not(:disabled) {
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
    transform: translateY(-1px);
}

.btn-stand {
    background: linear-gradient(135deg, #64748b, #475569);
    color: white;
    box-shadow: 0 4px 12px rgba(100, 116, 139, 0.3);
}

.btn-stand:hover:not(:disabled) {
    box-shadow: 0 6px 20px rgba(100, 116, 139, 0.4);
    transform: translateY(-1px);
}

.btn-new-game {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: white;
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
    width: auto;
    min-width: 110px;
}

.btn-new-game:hover {
    box-shadow: 0 6px 20px rgba(34, 197, 94, 0.4);
    transform: translateY(-1px);
}

.btn-play-again {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: white;
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
    min-width: 160px;
    font-size: 15px;
    max-width: none;
    width: auto;
}

.btn-play-again:hover {
    box-shadow: 0 6px 20px rgba(34, 197, 94, 0.4);
    transform: translateY(-1px);
}

/* ── Results Overlay ── */
.results-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.results-panel {
    background: linear-gradient(180deg, #1e293b, #0f172a);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 20px;
    padding: 32px 40px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    animation: slideUp 0.4s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.result-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.result-title {
    font-size: 28px;
    font-weight: 800;
    color: #f1f5f9;
    margin-bottom: 6px;
}

.result-detail {
    font-size: 13px;
    color: #64748b;
    margin-bottom: 12px;
    line-height: 1.5;
}

.result-money-line {
    font-size: 20px;
    font-weight: 800;
    margin-bottom: 20px;
}

.result-money-line.win { color: #22c55e; }
.result-money-line.lose { color: #ef4444; }
.result-money-line.tie { color: #eab308; }

/* ── Level Up Panel ── */
.level-up-panel {
    border: 2px solid rgba(251, 191, 36, 0.4);
    background: linear-gradient(180deg, #1c1917, #0f172a);
}

.level-up-panel .result-icon {
    animation: bounce 0.6s ease infinite alternate;
}

@keyframes bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-8px); }
}

/* ── Bankrupt Panel ── */
.bankrupt-panel {
    border: 2px solid rgba(239, 68, 68, 0.3);
    background: linear-gradient(180deg, #1f1315, #0f172a);
}

/* ── Chip anim ── */
.chip-fly {
    position: fixed;
    font-size: 24px;
    pointer-events: none;
    z-index: 200;
    animation: chipFly 1s ease-out forwards;
}

@keyframes chipFly {
    0% {
        opacity: 1;
        transform: translateY(0) rotate(0deg) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(-120px) rotate(360deg) scale(0.5);
    }
}

/* ── 竖屏手机适配 ── */
@media (max-width: 480px) and (orientation: portrait) {
    .game-container {
        max-width: 100%;
        min-height: auto;
    }

    .game-content {
        flex-direction: column;
    }

    .side-panel {
        width: 100%;
        flex-direction: row;
        border-left: none;
        border-top: 1px solid rgba(255,255,255,0.06);
        padding: 8px 10px;
        gap: 8px;
        justify-content: center;
    }

    .bet-options {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 4px;
    }

    .btn-bet {
        max-width: 72px;
        padding: 5px 8px;
        font-size: 10px;
    }

    .controls {
        flex-direction: row;
        width: auto;
    }

    .btn {
        max-width: 90px;
        padding: 7px 14px;
        font-size: 12px;
    }

    .message-text {
        font-size: 11px;
        padding: 4px 10px;
        white-space: nowrap;
    }

    .message-area {
        flex-shrink: 0;
    }

    .game-board {
        padding: 8px 10px;
    }

    .card {
        width: 60px;
        height: 84px;
        margin-right: -12px;
    }

    .card-rank {
        font-size: 13px;
    }

    .card-suit {
        font-size: 16px;
    }

    .card-corner .cr {
        font-size: 9px;
    }

    .card-corner .cs {
        font-size: 8px;
    }

    .card-center-suit {
        font-size: 18px;
    }

    .card-back::after {
        font-size: 18px;
    }

    .card-flip-container {
        width: 60px;
        height: 84px;
        margin-right: -12px;
    }

    .game-header {
        padding: 8px 10px;
    }

    .title-section h1 {
        font-size: 15px;
    }

    .money-item {
        min-width: 42px;
        padding: 2px 5px;
    }

    .money-value {
        font-size: 12px;
    }

    .bet-bar {
        padding: 2px 10px 6px;
    }

    .bet-value {
        font-size: 12px;
    }

    .results-panel {
        padding: 20px 24px;
        margin: 0 16px;
    }

    .result-icon {
        font-size: 36px;
    }

    .result-title {
        font-size: 22px;
    }

    .result-money-line {
        font-size: 17px;
    }

    .btn-play-again {
        min-width: 130px;
        font-size: 13px;
    }
}

/* ── 更小屏竖屏适配 ── */
@media (max-width: 360px) and (orientation: portrait) {
    .card {
        width: 52px;
        height: 74px;
        margin-right: -10px;
    }
    .card-flip-container {
        width: 52px;
        height: 74px;
        margin-right: -10px;
    }
    .card-rank { font-size: 11px; }
    .card-suit { font-size: 14px; }
    .btn { max-width: 76px; padding: 6px 10px; font-size: 11px; }
    .btn-bet { max-width: 62px; font-size: 9px; }
    .money-value { font-size: 11px; }
}

/* ── 横屏手机适配 ── */
@media (max-width: 900px) and (orientation: landscape) {
    .game-container {
        max-width: 100%;
        min-height: auto;
        max-height: 100vh;
    }

    .game-content {
        flex-direction: row;
        min-height: 0;
        flex: 1;
    }

    .game-board {
        padding: 6px 10px;
        gap: 3px;
    }

    .side-panel {
        width: 120px;
        padding: 8px 6px;
        gap: 8px;
        justify-content: center;
    }

    .bet-options {
        gap: 3px;
    }

    .btn-bet {
        max-width: 90px;
        padding: 4px 8px;
        font-size: 10px;
    }

    .controls {
        gap: 5px;
    }

    .btn {
        max-width: 90px;
        padding: 6px 12px;
        font-size: 11px;
    }

    .card {
        width: 52px;
        height: 74px;
        margin-right: -10px;
    }

    .card-flip-container {
        width: 52px;
        height: 74px;
        margin-right: -10px;
    }

    .card-rank { font-size: 11px; }
    .card-suit { font-size: 14px; }
    .card-corner .cr { font-size: 8px; }
    .card-corner .cs { font-size: 7px; }
    .card-center-suit { font-size: 16px; }
    .card-back::after { font-size: 16px; }

    .game-header {
        padding: 6px 10px;
    }

    .title-section h1 {
        font-size: 14px;
    }

    .money-item {
        min-width: 40px;
        padding: 1px 5px;
    }

    .money-value {
        font-size: 11px;
    }

    .bet-bar {
        padding: 2px 10px 4px;
    }

    .bet-value {
        font-size: 11px;
    }

    .player-section {
        flex: none;
    }

    .player-label {
        margin-bottom: 4px;
    }

    .label-text {
        font-size: 11px;
    }

    .score-badge {
        font-size: 11px;
        padding: 2px 8px;
        min-width: 24px;
    }

    .cards {
        min-height: 80px;
    }

    .message-text {
        font-size: 10px;
        padding: 3px 8px;
    }

    .results-panel {
        padding: 16px 20px;
        margin: 0 12px;
    }

    .result-icon {
        font-size: 30px;
        margin-bottom: 8px;
    }

    .result-title {
        font-size: 20px;
    }

    .result-detail {
        font-size: 11px;
    }

    .result-money-line {
        font-size: 15px;
    }

    .btn-play-again {
        min-width: 110px;
        font-size: 12px;
        padding: 8px 20px;
    }
}
