:root {
    --bg-color: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --primary: #3b82f6;
    --accent: #8b5cf6;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: rgba(148, 163, 184, 0.2);
    --glass: rgba(255, 255, 255, 0.05);
    --safe: #22c55e;
    --danger: #ef4444;
    --gold: #eab308;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- Layout --- */
#app {
    display: flex;
    flex: 1;
    height: calc(100vh - 60px);
    /* Minus Header */
    overflow: hidden;
}

#sidebar {
    width: 300px;
    background: var(--card-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1rem;
    backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    /* resize: horizontal; - Removed in favor of JS handle */
    /* overflow: auto; */
    min-width: 250px;
    max-width: 50vw;
    /* direction: rtl; */
}

#resize-gutter {
    width: 5px;
    cursor: col-resize;
    background: transparent;
    transition: background 0.2s;
    z-index: 20;
}

#resize-gutter:hover,
#resize-gutter.active {
    background: var(--primary);
}

/* Fix direction for children if using rtl on parent for left-side resize handle (if it worked that way) */
/* But here we just want standard right-side resize for now as sidebar is on the right? */
/* Wait, sidebar is defined AFTER main-content in HTML, so it IS on the right? */
/* public/index.html: flex-direction: row (default). #main-content then #sidebar. */
/* So #sidebar is on the RIGHT. resize: horizontal puts handle on bottom-right. */
/* Dragging it right increases width, pushing it off screen? */
/* Actually, let's keep it simple. User asked for resize. */
/* If I want it to resize "inwards", I need more complex CSS or JS. */
/* For now let's just enable resize. */

#main-content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    position: relative;
}

/* --- Header --- */
header {
    height: 60px;
    background: rgba(15, 23, 42, 0.9);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    z-index: 10;
}

.logo {
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(to right, var(--primary), var(--accent));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    cursor: pointer;
}

.user-info {
    display: flex;
    gap: 1.5rem;
    font-size: 0.95rem;
    align-items: center;
}

.chip {
    background: var(--glass);
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* --- Chat --- */
#chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding-right: 0.5rem;
    font-size: 0.85rem;
}

.chat-msg {
    animation: fadeIn 0.2s;
    word-break: break-all;
    line-height: 1.4;
}

.chat-msg.system {
    color: var(--gold);
    font-style: italic;
    text-align: center;
    font-size: 0.75rem;
    margin: 0.5rem 0;
}

.chat-input-area {
    margin-top: 1rem;
    display: flex;
    gap: 0.5rem;
}

input[type="text"],
input[type="password"] {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    color: white;
    padding: 0.75rem;
    border-radius: 0.5rem;
    flex: 1;
    outline: none;
    transition: 0.2s;
}

input:focus {
    border-color: var(--primary);
}

button {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.75rem 1.25rem;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
}

button:hover {
    filter: brightness(1.1);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* --- Lobby --- */
.game-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 2rem;
    margin-bottom: 3rem;
}

.game-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 1rem;
    overflow: hidden;
    transition: 0.3s;
    cursor: pointer;
    position: relative;
}

.game-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary);
    box-shadow: 0 10px 30px rgba(59, 130, 246, 0.15);
}

.card-img {
    height: 160px;
    background: #1e293b;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    position: relative;
    overflow: hidden;
}

.card-img::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, rgba(59, 130, 246, 0.1), rgba(139, 92, 246, 0.1));
}

.card-content {
    padding: 1.5rem;
}

.card-title {
    font-size: 1.25rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
}

.card-desc {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* --- Ranking Table --- */
.ranking-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: 1rem;
    overflow: hidden;
    border: 1px solid var(--border);
}

.ranking-table th,
.ranking-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.ranking-table th {
    background: rgba(0, 0, 0, 0.2);
    font-weight: 600;
    color: var(--text-muted);
}

.ranking-table tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

/* --- Modal --- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(5px);
}

.modal.active {
    display: flex;
}

.modal-box {
    background: #1e293b;
    padding: 2.5rem;
    border-radius: 1.5rem;
    width: 320px;
    border: 1px solid var(--border);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    text-align: center;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

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

/* Utils */
.hidden {
    display: none !important;
}

.text-gold {
    color: var(--gold);
}

.text-accent {
    color: var(--accent);
}

.clickable {
    cursor: pointer;
    text-decoration: underline;
    text-decoration-color: rgba(255, 255, 255, 0.3);
}

.clickable:hover {
    color: var(--primary);
    text-decoration-color: var(--primary);
}

/* --- Mobile Responsive --- */
@media (max-width: 900px) {
    #app {
        flex-direction: column;
        height: auto;
        /* Allow scrolling if needed, but usually fixed height is better for app-feel */
        position: relative;
    }

    #main-content {
        width: 100%;
        padding: 1rem;
        padding-bottom: 80px;
        /* Space for FAB */
    }

    #resize-gutter {
        display: none;
    }

    #sidebar {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 85% !important;
        max-width: 320px;
        z-index: 1000;
        transform: translateX(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: -5px 0 20px rgba(0, 0, 0, 0.5);
    }

    #sidebar.mobile-active {
        transform: translateX(0);
    }

    #mobile-chat-btn {
        display: flex !important;
    }

    .mobile-backdrop {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 900;
        backdrop-filter: blur(2px);
    }

    .mobile-backdrop.active {
        display: block;
        animation: fadeIn 0.3s;
    }
}

#mobile-chat-btn {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: auto;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.5);
    z-index: 1100;
    font-size: 1.5rem;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
    transition: transform 0.2s;
}

#mobile-chat-btn:active {
    transform: scale(0.95);
}

/* --- Responsive Table --- */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
    border-radius: 1rem;
    border: 1px solid var(--border);
}

.table-responsive table {
    border: none;
    /* Border is on wrapper */
    min-width: 500px;
    /* Force scroll on small screens */
}

@media (max-width: 600px) {

    .ranking-table th,
    .ranking-table td {
        padding: 0.5rem;
        font-size: 0.8rem;
    }
}

/* --- Toast Notification --- */
#toast-notification {
    visibility: hidden;
    min-width: 250px;
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: 8px;
    padding: 16px;
    position: fixed;
    z-index: 2000;
    left: 50%;
    bottom: 30px;
    transform: translateX(-50%);
    font-size: 1rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border);
}

#toast-notification.show {
    visibility: visible;
    animation: fadein 0.5s, fadeout 0.5s 2.5s;
}

@keyframes fadein {
    from {
        bottom: 0;
        opacity: 0;
    }

    to {
        bottom: 30px;
        opacity: 1;
    }
}

@keyframes fadeout {
    from {
        bottom: 30px;
        opacity: 1;
    }

    to {
        bottom: 0;
        opacity: 0;
    }
}

/* --- Mobile Header Tweaks --- */
@media (max-width: 480px) {
    header {
        padding: 0 1rem;
        height: auto;
        min-height: 60px;
        flex-wrap: wrap;
        gap: 10px;
        justify-content: center;
    }

    .logo {
        font-size: 1.2rem;
    }

    .user-actions {
        display: flex;
        align-items: center;
        width: 100%;
        justify-content: center;
    }

    #user-header {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
        font-size: 0.9rem;
    }

    #user-header span {
        white-space: nowrap;
    }

    /* Move Chat Button to Left */
    #mobile-chat-btn {
        right: auto;
        left: 20px;
    }
}

/* Roulette Game Styles */

.r-info-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.3);
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.r-timer-box {
    font-size: 1.2rem;
    font-weight: bold;
}

.r-history {
    display: flex;
    gap: 5px;
}

.r-hist-item {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: bold;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.r-hist-item.red {
    background: #ef4444;
}

.r-hist-item.black {
    background: #1e293b;
}

/* Slate 800 */
.r-hist-item.green {
    background: #22c55e;
}

.roulette-board {
    display: flex;
    flex-direction: column;
    /* Mobile first stack? Or just stack 0 top, grid mid, opts bot */
    gap: 10px;
    max-width: 600px;
    margin: 0 auto;
    user-select: none;
}

.roulette-board.disabled {
    opacity: 0.6;
    pointer-events: none;
    filter: grayscale(0.5);
}

.r-cell {
    background: #334155;
    color: white;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: transform 0.1s;
    position: relative;
    /* For chips */
}

.r-cell:active {
    transform: scale(0.95);
}

.r-cell:hover {
    brightness: 1.1;
}

.r-zero {
    height: 50px;
    border-radius: 8px 8px 0 0;
    background: #22c55e;
    font-size: 1.5rem;
}

.r-numbers-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    /* 3 cols standard */
    gap: 5px;
}

.r-num {
    height: 50px;
    font-size: 1.2rem;
}

.r-num.red {
    background: #ef4444;
}

.r-num.black {
    background: #1e293b;
}

.r-side-bets {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 5px;
}

.r-opt {
    height: 40px;
    font-size: 0.9rem;
    background: #475569;
}

.r-opt.r-red {
    background: #ef4444;
}

.r-opt.r-black {
    background: #1e293b;
}

/* Chip Visual */
.chip-visual {
    position: absolute;
    width: 24px;
    height: 24px;
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="50" cy="50" r="45" fill="%23eab308" stroke="white" stroke-width="5"/></svg>') no-repeat center;
    background-size: contain;
    color: black;
    font-size: 0.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    z-index: 10;
    pointer-events: none;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-shadow: none;
}

.chip-btn {
    border: none;
    color: white;
    padding: 5px 10px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
    margin: 0 5px;
    transition: transform 0.1s;
}

.chip-btn:active {
    transform: scale(0.95);
}

/* Animation */
@keyframes winnerPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(234, 179, 8, 0.7);
    }

    70% {
        box-shadow: 0 0 0 20px rgba(234, 179, 8, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(234, 179, 8, 0);
    }
}

.winner-anim {
    z-index: 20;
    box-shadow: 0 0 20px #eab308;
    animation: winnerPulse 1s infinite;
    transform: scale(1.1);
}