:root {
    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --bg-header: #1e293b;
    --bg-input: #334155;
    --accent-blue: #38bdf8;
    --accent-indigo: #818cf8;
    --accent-green: #10b981;
    --accent-red: #ef4444;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    --neon-blue: 0 0 15px rgba(56, 189, 248, 0.4);
}

[data-theme="light"] {
    --bg-dark: #f1f5f9;
    --bg-card: #ffffff;
    --bg-header: #ffffff;
    --bg-input: #f8fafc;
    --accent-blue: #0284c7;
    --accent-indigo: #4f46e5;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

* {
    box-sizing: border-box;
    transition: background-color 0.3s, color 0.3s, border-color 0.3s;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Fredoka', 'Pretendard', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    height: 60px;
    background: var(--bg-header);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 2px solid var(--border-color);
    z-index: 1000;
}

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

.logo-icon {
    font-size: 1.5rem;
    filter: drop-shadow(var(--neon-blue));
}

.logo-text h1 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 1px;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-indigo));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-text p {
    margin: 0;
    font-size: 0.6rem;
    color: var(--text-secondary);
    letter-spacing: 2px;
}

.jackpot-banner {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 5px 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.1);
}

.jackpot-icon {
    font-size: 1rem;
    animation: fire 1s infinite alternate;
}

@keyframes fire {
    from { transform: scale(1); opacity: 0.8; }
    to { transform: scale(1.1); opacity: 1; }
}

.jackpot-label {
    font-size: 0.6rem;
    color: var(--accent-red);
    font-weight: 700;
}

.jackpot-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: #fbbf24;
}

.jackpot-unit {
    font-size: 0.6rem;
    color: #fbbf24;
    margin-left: 2px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.icon-btn {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 6px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
}

.login-btn {
    background: linear-gradient(90deg, var(--accent-indigo), var(--accent-blue));
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    border: none;
    cursor: pointer;
    font-size: 0.8rem;
    box-shadow: 0 4px 10px rgba(129, 140, 248, 0.3);
}

/* App Container */
.app-container {
    display: grid;
    grid-template-columns: 280px 1fr 280px;
    gap: 12px;
    padding: 12px;
    flex: 1;
    overflow: hidden;
    height: calc(100vh - 120px); /* header(60px) + footer(60px) */
}

.side-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
}

.side-panel::-webkit-scrollbar {
    width: 4px;
}
.side-panel::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

/* Cards */
.user-card, .stats-grid, .preview-section, .chat-container, .ads-card, .game-board-frame {
    background: var(--bg-card);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
}

.card-header {
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border-color);
}

.user-avatar-wrapper {
    position: relative;
}

.user-avatar {
    width: 36px;
    height: 36px;
    background: var(--bg-input);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.status-indicator {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--bg-card);
}

.status-indicator.online { background: var(--accent-green); }

.user-name {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
}

.user-rank {
    font-size: 0.65rem;
    color: var(--accent-blue);
}

/* Wallet */
.wallet-card {
    padding: 12px;
}

.wallet-balance {
    background: rgba(0, 0, 0, 0.2);
    padding: 10px;
    border-radius: 12px;
    margin-bottom: 10px;
    text-align: center;
}

.label {
    font-size: 0.6rem;
    color: var(--text-secondary);
    font-weight: 600;
    display: block;
    margin-bottom: 2px;
}

.balance-amount {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--accent-green);
}

.balance-amount .unit { font-size: 0.7rem; color: var(--text-secondary); margin-left: 3px; }

.wallet-actions {
    display: flex;
    gap: 8px;
}

.action-btn {
    flex: 1;
    padding: 8px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    color: white;
    font-size: 0.75rem;
}

.action-btn.deposit { background: var(--accent-blue); }
.action-btn.withdraw { background: var(--bg-input); border: 1px solid var(--border-color); }

/* Bet Card */
.bet-card {
    padding: 0 12px 12px;
}

.bet-input-wrapper {
    display: flex;
    gap: 6px;
    margin-top: 5px;
}

.bet-input-wrapper input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: white;
    padding: 8px;
    border-radius: 8px;
    outline: none;
    font-weight: 600;
    font-size: 0.8rem;
}

.bet-input-wrapper button {
    background: var(--accent-indigo);
    color: white;
    border: none;
    padding: 0 10px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.75rem;
}

.quick-bets {
    display: flex;
    gap: 5px;
    margin-top: 8px;
}

.quick-bet-btn {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 5px;
    border-radius: 6px;
    font-size: 0.65rem;
    cursor: pointer;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    padding: 10px;
    gap: 8px;
}

.stat-box {
    text-align: center;
    background: rgba(0, 0, 0, 0.2);
    padding: 8px;
    border-radius: 10px;
}

.stat-box .value {
    display: block;
    font-size: 1rem;
    font-weight: 700;
    color: var(--accent-blue);
}

/* Preview Section */
.preview-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 10px;
    gap: 10px;
}

.preview-card {
    text-align: center;
}

.canvas-wrapper {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    padding: 8px;
    margin-top: 5px;
}

/* Game Main */
.game-main {
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.game-board-frame {
    width: 100%;
    max-width: 400px;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 12px;
}

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

.board-title { font-weight: 700; color: var(--text-secondary); letter-spacing: 1px; font-size: 0.8rem; }
.board-status { color: var(--accent-red); font-weight: 700; font-size: 0.8rem; animation: blink 1s infinite; }

.canvas-container {
    flex: 1;
    position: relative;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 0 50px rgba(56, 189, 248, 0.1);
    border-bottom: 4px solid #1e293b; /* Clearly mark the bottom */
}

#tetris-canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.mobile-controls {
    display: none;
    justify-content: center;
    gap: 20px;
    margin-top: 15px;
    padding: 0 10px;
}

.ctrl-btn {
    flex: 1;
    height: 50px;
    border-radius: 12px;
    border: none;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    color: white;
}

.ctrl-btn.rotate { background: var(--accent-indigo); }
.ctrl-btn.drop { background: var(--accent-blue); }

.controls-hint {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 8px;
}

.hint {
    font-size: 0.6rem;
    color: var(--text-secondary);
    background: var(--bg-input);
    padding: 3px 8px;
    border-radius: 5px;
}

/* Chat */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0; /* Important for flex container scrolling */
}

.chat-messages {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
}

.chat-footer {
    padding: 10px;
    display: flex;
    gap: 8px;
    border-top: 1px solid var(--border-color);
}

.chat-footer input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: white;
    padding: 8px 12px;
    border-radius: 16px;
    outline: none;
    font-size: 0.8rem;
}

.chat-footer button {
    background: var(--accent-blue);
    color: white;
    border: none;
    padding: 0 12px;
    border-radius: 16px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.8rem;
}

/* Footer */
.app-footer {
    height: 60px;
    background: var(--bg-header);
    border-top: 1px solid var(--border-color);
    padding: 0 20px;
    display: flex;
    align-items: center;
}

/* Responsive */
@media (max-width: 1024px) {
    body { overflow-y: hidden; height: 100vh; }
    
    .app-container { 
        grid-template-columns: 1fr; 
        padding: 8px; 
        gap: 8px;
        display: flex;
        flex-direction: column;
        height: calc(100vh - 120px);
    }
    
    .side-panel.left-panel {
        order: 2;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .game-main { order: 1; flex: 2; min-height: 0; }
    .right-panel { order: 3; flex: 1; min-height: 0; }

    .game-board-frame { 
        max-width: 100%; 
        height: 100%;
        padding: 5px;
    }
    
    .canvas-container {
        flex: 1;
        aspect-ratio: auto;
    }

    .mobile-controls {
        display: flex;
    }

    .controls-hint { display: none; }
    
    .chat-container { height: 100%; }
    .ads-card { display: none; }
    
    .stats-grid { grid-column: span 1; padding: 0; }
    .preview-section { grid-column: span 1; padding: 0; }
    .user-card { grid-column: span 2; }
}

@media (max-width: 600px) {
    .app-header { height: 50px; padding: 0 10px; }
    .app-footer { height: 40px; }
    .app-container { height: calc(100vh - 90px); }
    
    .logo-text h1 { font-size: 1rem; }
    .jackpot-banner { padding: 3px 10px; }
    .jackpot-value { font-size: 1rem; }
    
    .side-panel.left-panel {
        grid-template-columns: 1fr;
    }
    
    .user-card { grid-column: span 1; }
    .stats-grid { grid-template-columns: 1fr 1fr 1fr; }
    
    .board-header { position: absolute; top: 10px; left: 10px; right: 10px; z-index: 10; pointer-events: none; }
    .board-title { background: rgba(0,0,0,0.5); padding: 2px 8px; border-radius: 4px; }
    .board-status { background: rgba(0,0,0,0.5); padding: 2px 8px; border-radius: 4px; }
}
