* {
    box-sizing: border-box;
}

body {
    background-color: #121212;
    color: #e0e0e0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    padding: 20px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    height: 100%;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 1px solid #333;
    margin-bottom: 20px;
}

h1 { margin: 0; color: #9146ff; }

#connection-panel {
    display: flex;
    gap: 10px;
}

input {
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #444;
    background: #222;
    color: white;
}

button {
    padding: 8px 16px;
    background: #9146ff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

button:hover { background: #772ce8; }

#disconnect-btn {
    background: #ff4444;
}

#disconnect-btn:hover {
    background: #cc0000;
}

main {
    display: flex;
    flex: 1;
    gap: 20px;
    min-height: 0; /* for nested flex scrolling */
    flex-wrap: wrap; /* Allow wrapping on smaller screens */
}

.game-area {
    flex: 2 1 600px; /* Grow 2, Shrink 1, Basis 600px */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 300px;
}

/* History Bar */
.history-container {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 50px;
    min-height: 50px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap; /* Wrap history bubbles if needed */
    max-width: 100%;
}

.history-bubble {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    color: white;
    font-size: 14px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
}

.bubble-green { background-color: #008000; }
.bubble-red { background-color: #c90000; }
.bubble-black { background-color: #1a1a1a; }

.wheel-container {
    position: relative;
    width: 400px;
    height: 400px;
    margin-bottom: 20px;
    border-radius: 50%;
    /* Create a border/bezel with purple neon glow */
    box-shadow: 0 0 0 10px #9146ff, 0 0 20px #9146ff, 0 0 40px rgba(145, 70, 255, 0.5);
    flex-shrink: 0; /* Prevent flexbox from squishing it */
}

.wheel-frame {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    overflow: hidden;
    position: relative;
    border: 5px solid #222;
}

.wheel {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    position: relative;
    /* Transition controlled by JS */
}

.wheel::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60%;
    height: 60%;
    background: #121212;
    border-radius: 50%;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
    z-index: 1;
}

/* Center Winning Number */
.center-winner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100px;
    height: 100px;
    background: rgba(18, 18, 18, 0.5); /* Semi-transparent to see channel name */
    border: 4px solid #ffd700;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 48px;
    font-weight: bold;
    color: white;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
    z-index: 20; /* Topmost */
    opacity: 1;
    transition: opacity 0.5s, transform 0.5s;
}

.center-winner.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -50%) scale(0.5);
}

/* Center Channel Name */
.center-channel-name {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 200px; /* Constrain width to fit inside wheel center */
    max-height: 140px;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    font-size: 20px;
    line-height: 1.2;
    white-space: nowrap; /* Keep on one line */
    text-overflow: ellipsis; /* Add ... if too long */
    overflow: hidden;
    font-weight: bold;
    color: #9146ff;
    text-shadow: 0 0 10px rgba(145, 70, 255, 0.5);
    z-index: 15; /* Above wheel, below winner */
    text-transform: uppercase;
    opacity: 1;
    transition: opacity 0.5s;
    pointer-events: none;
}

.center-channel-name.hidden {
    opacity: 0;
}

.wheel-number {
    position: absolute;
    top: 50%;
    left: 50%;
    transform-origin: center;
    font-size: 14px;
    font-weight: bold;
    color: white;
    text-shadow: 1px 1px 2px black;
    z-index: 5; /* Higher than wheel::after */
    width: 30px;
    height: 20px;
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
}

.ball-track {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    pointer-events: none;
    z-index: 10;
    /* Transition controlled by JS */
}

.ball {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 14px;
    height: 14px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 0 5px black;
    /* Move ball to 185px to be clearly on the rim but inside the border */
    transform: translate(-50%, -50%) translateY(-185px);
}

/* Animation Classes Removed - handled by JS/RAF */


/* Spin animations are handled by JS transitions on the container */

.info-panel {
    flex: 1 1 300px; /* Basis 300px, can shrink/grow */
    background: #1e1e1e;
    padding: 20px;
    border-radius: 8px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 300px;
}

/* ... existing styles ... */

.betting-table-container {
    perspective: 1000px;
    margin-top: 20px;
    margin-bottom: 20px;
    width: 100%;
    max-width: 1000px; /* Ensure it can grow */
    flex-shrink: 1; /* Allow shrinking */
    overflow-x: hidden; /* No scrolling */
    padding-bottom: 10px;
}

/* ... existing styles ... */

/* Responsive Media Queries */
@media (max-width: 1024px) {
    .game-area {
        flex-basis: 100%; /* Take full width */
    }
    
    .info-panel {
        flex-basis: 100%; /* Take full width */
        max-height: 400px; /* Limit height when stacked */
    }
}

@media (max-width: 600px) {
    .wheel-container {
        transform: scale(0.8);
        margin: -40px 0; /* Compensate for whitespace */
    }
    
    .center-winner {
        transform: translate(-50%, -50%) scale(0.8);
    }

    .container {
        padding: 10px;
    }
    
    header {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }
    
    #connection-panel {
        width: 100%;
        flex-wrap: wrap;
    }

    .betting-table {
        gap: 2px;
        padding: 5px;
    }

    .bet-cell {
        font-size: 0.8em;
    }

    .chip {
        width: 20px;
        height: 20px;
        font-size: 8px;
    }
}

@media (max-width: 400px) {
    .wheel-container {
        transform: scale(0.65);
        margin: -70px 0;
    }
    
    .betting-table {
        transform: none; /* Remove 3D effect on mobile for clarity */
        grid-template-columns: minmax(20px, 30px) repeat(12, 1fr);
        grid-template-rows: repeat(6, minmax(12px, 18px)) minmax(25px, 35px);
    }

    .chip {
        width: 15px;
        height: 15px;
        font-size: 6px;
        border-width: 1px;
    }
}

ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

li {
    padding: 5px 0;
    border-bottom: 1px solid #333;
}

.instructions {
    margin-top: 20px;
    padding: 10px;
    background: #222;
    border-radius: 4px;
    font-size: 0.9em;
}

.hidden { display: none; }

#result-display h2 {
    font-size: 2em;
    color: #ffd700;
}

.bets-section h3 {
    margin-top: 0;
    margin-bottom: 0; /* Let header handle spacing */
    border-bottom: none; /* Remove old border if any */
}

.bets-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #333;
    padding-bottom: 10px;
    margin-bottom: 15px;
}

.timer-badge {
    background-color: #2c2c2c;
    color: #00ff00;
    padding: 5px 12px;
    border-radius: 15px;
    font-family: 'Courier New', Courier, monospace;
    font-weight: bold;
    font-size: 1.1em;
    display: flex;
    align-items: center;
    gap: 5px;
    border: 1px solid #444;
    box-shadow: 0 0 5px rgba(0, 255, 0, 0.2);
    transition: all 0.3s ease;
}

.timer-badge.warning {
    color: #ffff00;
    border-color: #aaaa00;
    box-shadow: 0 0 5px rgba(255, 255, 0, 0.2);
}

.timer-badge.critical {
    background-color: #3d0000;
    color: #ff0000;
    border-color: #ff0000;
    box-shadow: 0 0 8px rgba(255, 0, 0, 0.5);
    animation: pulse-red 1s infinite;
}

@keyframes pulse-red {
    0% { box-shadow: 0 0 5px rgba(255, 0, 0, 0.5); }
    50% { box-shadow: 0 0 15px rgba(255, 0, 0, 0.8); }
    100% { box-shadow: 0 0 5px rgba(255, 0, 0, 0.5); }
}

/* Developer Footer */
.developer-footer {
    margin-top: 20px;
    text-align: center;
    font-size: 0.9em;
    color: #888;
    padding: 10px;
}

.twitch-name {
    color: #9146ff;
    font-weight: bold;
    text-shadow: 0 0 5px rgba(145, 70, 255, 0.3);
}

/* Bet Status Indicator */
.bet-status-text {
    font-size: 1.2em;
    font-weight: bold;
    text-align: center;
    margin-bottom: 10px;
    padding: 5px;
    border-radius: 4px;
    background: rgba(0,0,0,0.3);
    text-transform: uppercase;
}

.bets-open {
    color: #00ff00;
    animation: flash-green 2s infinite ease-in-out;
}

.bets-closed {
    color: #ff4444;
    animation: flash-red 2s infinite ease-in-out;
}

@keyframes flash-green {
    0% { opacity: 1; text-shadow: 0 0 5px #00ff00; }
    50% { opacity: 0.3; text-shadow: none; }
    100% { opacity: 1; text-shadow: 0 0 5px #00ff00; }
}

@keyframes flash-red {
    0% { opacity: 1; text-shadow: 0 0 5px #ff4444; }
    50% { opacity: 0.3; text-shadow: none; }
    100% { opacity: 1; text-shadow: 0 0 5px #ff4444; }
}


.betting-table {
    display: grid;
    grid-template-columns: minmax(30px, 50px) repeat(12, 1fr);
    grid-template-rows: repeat(6, minmax(15px, 25px)) minmax(30px, 50px);
    gap: 4px;
    background: #0b3d0b; /* Felt Green */
    padding: 10px;
    border-radius: 10px;
    border: 5px solid #9146ff; /* Purple Neon Border */
    box-shadow: 0 0 15px #9146ff, 0 10px 30px rgba(0,0,0,0.5); /* Neon Glow + Drop Shadow */
    transform: rotateX(20deg); /* Slight 3D effect */
    width: 100%;
    max-width: 100%;
}

.bet-cell {
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    color: white;
    border: 1px solid rgba(255,255,255,0.2);
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
    position: relative; /* For chip positioning */
}

.bet-cell:hover {
    background-color: rgba(255,255,255,0.1);
    transform: scale(1.05);
    z-index: 2;
}

.cell-red { background-color: #c90000; }
.cell-black { background-color: #1a1a1a; }
.cell-0, .cell-00 { background-color: green; }

.cell-number {
    grid-row: span 2;
}

/* 0 spans top 3 rows (half of 6) */
.cell-0 {
    grid-column: 1;
    grid-row: 1 / span 3;
    font-size: 1.5em;
}

/* 00 spans bottom 3 rows */
.cell-00 {
    display: flex;
    grid-column: 1;
    grid-row: 4 / span 3;
    font-size: 1.5em;
}

.outside-bets-row {
    grid-column: 2 / span 12;
    grid-row: 7;
    display: flex;
    gap: 4px;
}

.bet-option {
    flex: 1;
    height: 100%;
}

.chip {
    width: 30px;
    height: 30px;
    background: radial-gradient(circle at 30% 30%, #ffd700, #b8860b);
    border: 2px dashed white;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 2px 2px 5px rgba(0,0,0,0.5);
    pointer-events: none;
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 10px;
    color: black;
    font-weight: bold;
}

.bet-instructions {
    text-align: center;
    margin-bottom: 10px;
    font-size: 1.1em;
    color: #e0e0e0;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px;
    border-radius: 5px;
    width: 100%;
    max-width: 800px;
}

code {
    background: #333;
    padding: 2px 4px;
    border-radius: 3px;
    color: #ffd700;
}
