:root {
    --bg-color: #050505;
    --card-table: #1a4a3a;
    --neon-red: #ff3131;
    --gold: #ffd700;
    --text-white: #ffffff;
    --glass: rgba(255, 255, 255, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Noto Sans KR', sans-serif;
}

html,
body {
    height: 100vh;
    width: 100vw;
    background-color: var(--bg-color);
    color: var(--text-white);
    overflow: hidden;
}

body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

#app {
    display: contents;
}

.game-header {
    height: 70px;
    padding: 0 30px;
    background: rgba(0, 0, 0, 0.8);
    border-bottom: 2px solid var(--gold);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    z-index: 10;
}

.logo-group {
    display: flex;
    align-items: center;
    gap: 20px;
}

.logo {
    font-family: 'Outfit', sans-serif;
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--gold);
    white-space: nowrap;
    /* Prevent logo breaking */
    flex-shrink: 0;
}

.rule-info {
    margin-left: 20px;
    padding: 10px 15px;
    background: rgba(255, 215, 0, 0.05);
    border: 1px dashed rgba(255, 215, 0, 0.3);
    border-radius: 8px;
    font-size: 0.75rem;
    color: #ccc;
    line-height: 1.4;
    max-width: 400px;
}

.rule-info strong {
    color: var(--gold);
    display: block;
    margin-bottom: 2px;
}

.game-nav {
    display: flex;
    gap: 15px;
    margin-left: 30px;
    min-width: 0;
}

.nav-link {
    color: #999;
    /* Brighter than #666 */
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 700;
    transition: all 0.2s;
    padding: 6px 12px;
    border-radius: 6px;
    white-space: nowrap;
    /* Prevent vertical squashing */
}

.nav-link:hover {
    color: var(--gold);
    background: rgba(255, 215, 0, 0.1);
}

.nav-link.active {
    color: #000;
    background: var(--gold);
}

.back-btn {
    color: var(--gold);
    text-decoration: none;
    font-size: 1.5rem;
    transition: transform 0.2s;
}

.back-btn:hover {
    transform: translateX(-5px);
}

.status-panel {
    display: flex;
    gap: 20px;
    margin-left: auto;
}

.stat-box {
    background: var(--glass);
    padding: 8px 20px;
    border-radius: 10px;
    text-align: right;
    min-width: 150px;
}

.stat-label {
    font-size: 0.7rem;
    color: #aaa;
    display: block;
    margin-bottom: 2px;
}

.stat-value {
    font-family: 'Outfit', sans-serif;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--gold);
}

.unit {
    font-size: 0.8rem;
    margin-left: 3px;
    color: var(--gold);
}

.main-container {
    display: grid;
    grid-template-columns: 1fr 320px;
    flex: 1;
    /* Take up remaining space between header and footer */
    min-height: 0;
    overflow-y: auto;
}

.game-area {
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* Center content on PC */
    background: radial-gradient(circle at center, var(--card-table) 0%, var(--bg-color) 100%);
    position: relative;
    overflow-y: auto;
    flex: 1;
}

.game-message {
    font-size: 1.1rem;
    font-weight: 800;
    background: rgba(0, 0, 0, 0.8);
    padding: 0 30px;
    border-radius: 20px;
    border: 1px solid var(--gold);
    color: var(--gold);
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.8);
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.9), rgba(20, 20, 0, 0.8));
    margin-top: 10px;
    /* Reduced from auto */
    margin-bottom: 20px;
    height: 35px;
    /* Slimmer */
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.hands-container {
    display: flex;
    gap: 60px;
    justify-content: center;
    width: 100%;
    margin-bottom: 10px;
    height: 160px;
    /* Slimmer */
    flex-shrink: 0;
}

.hand-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.side-label {
    font-size: 1.2rem;
    /* Reduced to match Blackjack */
    font-weight: 900;
    letter-spacing: 2px;
    text-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

.player-side .side-label {
    color: #2196f3;
}

.banker-side .side-label {
    color: var(--neon-red);
}

.score-badge {
    width: 40px;
    height: 40px;
    background: #fff;
    color: #000;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    margin-left: 10px;
    border: 2px solid #333;
}

.cards-area {
    display: flex;
    gap: 10px;
    height: 120px;
    /* Reduced to match Blackjack */
    min-width: 300px;
    justify-content: center;
}

.card {
    width: 80px;
    height: 120px;
    background: #fff;
    color: #000;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 10px;
    font-weight: 800;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4);
    animation: dealIn 0.4s ease-out;
}

.card.red {
    color: var(--neon-red);
}

@keyframes dealIn {
    from {
        transform: translateY(30px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.chart-container {
    width: 100%;
    max-width: 800px;
    height: 140px;
    /* Hard fixed height */
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--glass);
    border-radius: 15px;
    padding: 10px;
    margin-top: 20px;
    /* Reduced from auto */
    flex-shrink: 0;
    /* Never shrink or grow */
    overflow: hidden;
}

.stats-panel {
    background: rgba(0, 0, 0, 0.7);
    border-left: 1px solid var(--glass);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    backdrop-filter: blur(15px);
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    color: #fff;
}

.stats-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sub-title {
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--gold);
    border-bottom: 1px solid var(--glass);
    padding-bottom: 5px;
}

.stat-value.red {
    color: var(--neon-red);
}

.stat-value.gold {
    color: var(--gold);
}

.flex-log {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.log-area {
    flex: 1;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    padding: 10px;
    font-size: 0.8rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    /* Better stability than column-reverse */
    gap: 5px;
    min-height: 0;
}

.analysis-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 5px;
    overflow-y: auto;
    min-height: 0;
}

.analysis-card {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.analysis-label {
    display: block;
    font-size: 0.75rem;
    color: #bbb;
    margin-bottom: 8px;
    font-weight: 700;
}

.win-rate-bar {
    height: 8px;
    background: #333;
    border-radius: 4px;
    display: flex;
    overflow: hidden;
    margin-bottom: 5px;
}

.rate-p {
    background: #2196f3;
    height: 100%;
    transition: width 0.3s;
}

.rate-b {
    background: var(--neon-red);
    height: 100%;
    transition: width 0.3s;
}

.rate-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
}

.streak-box {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.streak-item {
    text-align: center;
    background: rgba(0, 0, 0, 0.3);
    padding: 5px;
    border-radius: 8px;
}

.s-label {
    display: block;
    font-size: 0.6rem;
    color: #666;
}

.s-value {
    font-family: 'Outfit', sans-serif;
    font-size: 1.1rem;
    font-weight: 800;
}

.s-value.green {
    color: #4caf50;
}

.s-value.red {
    color: var(--neon-red);
}

.roi-value {
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--gold);
    text-align: center;
}

.roi-sub {
    display: block;
    text-align: center;
    font-size: 0.6rem;
    color: #555;
}

.commission-value {
    font-family: 'Outfit', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    color: #ff9800;
    text-align: center;
}

.game-controls {
    height: 100px;
    padding: 0 40px;
    background: #000;
    border-top: 2px solid var(--gold);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.control-group {
    display: flex;
    gap: 30px;
    align-items: center;
}

.speed-slider-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.amount-btns {
    display: flex;
    gap: 5px;
}

.amount-btns button {
    padding: 5px 10px;
    border-radius: 5px;
    border: 1px solid #444;
    background: transparent;
    color: #fff;
    cursor: pointer;
}

.bet-side-select {
    display: flex;
    gap: 10px;
}

.bet-btn {
    padding: 10px 20px;
    border-radius: 20px;
    border: 2px solid #444;
    background: transparent;
    color: #888;
    font-weight: 800;
    cursor: pointer;
}

.bet-btn.active.player {
    border-color: #2196f3;
    color: #2196f3;
    background: rgba(33, 150, 243, 0.1);
}

.bet-btn.active.banker {
    border-color: var(--neon-red);
    color: var(--neon-red);
    background: rgba(255, 49, 49, 0.1);
}

.start-btn {
    padding: 15px 40px;
    border-radius: 30px;
    border: none;
    background: linear-gradient(135deg, var(--gold), #b8860b);
    color: #000;
    font-weight: 900;
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.3);
}

.start-btn.active {
    background: var(--neon-red);
    color: #fff;
}

.secondary-btn {
    padding: 15px 30px;
    border-radius: 30px;
    border: 2px solid var(--gold);
    background: transparent;
    color: var(--gold);
    font-weight: 800;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    margin-right: 15px;
}

.secondary-btn:hover:not(:disabled) {
    background: rgba(255, 215, 0, 0.1);
}

.secondary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    border-color: #444;
    color: #444;
}

.house-rule-info {
    font-size: 0.75rem;
    color: #666;
    max-width: 200px;
    text-align: right;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: #111;
    padding: 50px;
    border-radius: 30px;
    text-align: center;
    border: 2px solid var(--gold);
    max-width: 500px;
}

.modal-content h2 {
    color: var(--gold);
    font-size: 2.22rem;
    margin-bottom: 20px;
}

.modal-content button {
    margin-top: 30px;
    padding: 12px 40px;
    border-radius: 10px;
    border: none;
    background: var(--gold);
    color: #000;
    font-weight: 800;
    cursor: pointer;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 1100px) {
    .rule-info {
        display: none;
    }
}

@media (max-width: 850px) {

    html,
    body {
        height: auto;
        overflow: visible;
    }

    body {
        display: block;
        position: relative;
    }

    .game-header {
        height: auto;
        padding: 8px 15px;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: flex-start;
        gap: 12px;
        align-items: center;
    }

    .logo-group {
        width: auto !important;
        display: flex;
        align-items: center;
        gap: 10px;
        justify-content: flex-start;
    }

    .game-nav {
        display: flex !important;
        flex: 1;
        /* Take remaining space on the same line */
        flex-wrap: nowrap;
        overflow-x: auto;
        margin-left: 5px;
        padding: 10px 0;
        justify-content: flex-start;
        gap: 12px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .nav-link {
        flex-shrink: 0;
        white-space: nowrap;
        padding: 6px 12px;
        font-size: 0.8rem;
    }

    .status-panel {
        width: 100%;
        /* Drop to second row */
        margin-top: 5px;
        display: flex;
        justify-content: space-between;
        gap: 10px;
        padding-bottom: 10px;
    }

    .stat-box {
        flex: 1;
        min-width: 0;
        padding: 8px 10px;
    }

    .main-container {
        display: flex;
        flex-direction: column;
        height: auto;
        overflow: visible;
        align-items: center;
        /* Ensure centering */
    }

    .game-area {
        height: auto;
        min-height: 250px;
        /* Reduced */
        overflow: visible;
        padding: 10px;
    }

    .hands-container {
        flex-direction: row;
        height: auto;
        gap: 15px;
        margin-top: 10px;
    }

    .cards-area {
        min-width: 0;
        height: 100px;
        width: 140px;
        /* Fixed width to allow overlap */
    }

    .cards-area .card {
        margin-left: -40px;
    }

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

    .card {
        width: 65px;
        height: 100px;
        font-size: 0.9rem;
    }

    .stats-panel {
        border-left: none;
        border-top: 1px solid var(--glass);
        height: auto;
        overflow: visible;
        padding: 20px;
    }

    .game-controls {
        height: auto;
        padding: 5px 12px 20px;
        display: flex;
        flex-direction: column;
        gap: 8px;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        z-index: 1000;
        background: rgba(5, 5, 5, 0.95);
        border-top: 1px solid rgba(255, 215, 0, 0.4);
        backdrop-filter: blur(20px);
    }

    .main-container {
        display: flex;
        flex-direction: column;
        height: auto;
        overflow: visible;
        padding-bottom: 150px;
    }

    .btn-group {
        display: flex;
        gap: 10px;
        width: 100%;
    }

    #play-once-btn,
    #auto-btn,
    .secondary-btn,
    .start-btn {
        flex: 1;
        width: auto;
        height: 44px;
        padding: 0 5px;
        font-size: 0.9rem;
        margin: 0 !important;
        border-radius: 12px;
    }

    .house-rule-info {
        display: none;
    }

    .control-group {
        width: 100%;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        gap: 15px;
        align-items: center;
    }

    .bet-side-select {
        width: 100%;
        justify-content: center;
    }

    .bet-btn {
        flex: 1;
        padding: 10px 10px;
        text-align: center;
    }

    .secondary-btn,
    .start-btn {
        width: 100%;
        margin-right: 0;
    }

    .house-rule-info {
        text-align: center;
        max-width: none;
    }

    .chart-container {
        height: 180px;
        margin-top: 30px;
    }
}

@media (max-width: 480px) {
    .logo {
        font-size: 1.4rem;
    }

    .stat-value {
        font-size: 1rem;
    }

    .side-label {
        font-size: 0.9rem;
    }

    .modal-content {
        padding: 30px 20px;
        margin: 0 15px;
    }

    .modal-content h2 {
        font-size: 1.6rem;
    }
}