:root {
    /* Light Theme (Default) */
    --bg-color: #f4f6f8;
    --surface-color: #ffffff;
    --text-color: #2c3e50;
    --text-secondary: #636e72;
    --primary-color: #2980b9;
    --primary-hover: #3498db;
    --accent-color: #e67e22;
    --success-color: #27ae60;
    --border-color: #dfe6e9;
    --shadow: 0 4px 6px rgba(0,0,0,0.1);
    --radius: 12px;
    --die-size: 48px;
    --die-dot-color: #2d3436;
    --die-bg: #ffffff;
    --highlight-bg: #e3f2fd;
    --active-turn-bg: #fff3e0;
}

[data-theme="dark"] {
    --bg-color: #121212;
    --surface-color: #1e1e1e;
    --text-color: #ecf0f1;
    --text-secondary: #b2bec3;
    --primary-color: #3498db;
    --primary-hover: #2980b9;
    --accent-color: #f39c12;
    --success-color: #2ecc71;
    --border-color: #333;
    --shadow: 0 4px 6px rgba(0,0,0,0.3);
    --die-dot-color: #121212;
    --die-bg: #ecf0f1;
    --highlight-bg: #2c3e50;
    --active-turn-bg: #3d342b;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
}

.container {
    background: var(--surface-color);
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    padding: 15px;
}

/* On larger screens, don't just center a small box, FILL the screen with a max constraint but centered if huge */
@media (min-width: 1024px) {
    body {
        align-items: center;
        justify-content: center;
        background-color: var(--bg-color); /* Ensure background is visible outside container */
        padding: 20px;
    }
    .container {
        height: auto;
        min-height: 80vh; /* Takes up most of screen height */
        max-width: 1200px;
        border-radius: var(--radius);
        box-shadow: var(--shadow);
    }
}

/* Header & Theme Toggle */
.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -1px;
    color: var(--text-color);
}

.theme-toggle {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    padding: 0;
}

/* SETUP SCREEN (Flex Fill) */
.screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s ease-in-out;
    width: 100%;
    overflow-y: auto; /* Allow scroll if needed */
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.hidden { display: none !important; }

.setup-card {
    width: 100%;
    max-width: 500px; /* Keep content readable width */
    margin: auto; /* Center in the flex container */
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 20px 0;
}

.input-group {
    display: flex;
    gap: 10px;
    width: 100%;
    height: 50px; /* Fixed height for touch targets */
}

input {
    flex: 1;
    padding: 0 16px;
    border: 2px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-color);
    border-radius: var(--radius);
    font-size: 16px;
    outline: none;
    min-width: 0;
    height: 100%;
    box-sizing: border-box;
}
input:focus { border-color: var(--primary-color); }

.player-list {
    list-style: none;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    min-height: 20px;
}

.player-tag {
    background: var(--surface-color);
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.player-tag .remove-player {
    cursor: pointer;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    background: rgba(0,0,0,0.1);
    border-radius: 50%;
    font-size: 12px;
}
.player-tag .remove-player:hover { background: rgba(0,0,0,0.2); }

.divider {
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    margin: 10px 0;
}
.divider::before, .divider::after {
    content: "";
    position: absolute;
    top: 50%;
    width: 40%;
    height: 1px;
    background: var(--border-color);
}
.divider::before { left: 0; }
.divider::after { right: 0; }

/* Buttons */
.btn {
    background: var(--primary-color);
    color: white;
    border: none;
    height: 50px; /* Consistent height */
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    width: 100%;
    transition: background 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn:hover { background: var(--primary-hover); }
.btn:active { transform: scale(0.98); }
.btn:disabled { background: var(--border-color); color: var(--text-secondary); cursor: not-allowed; opacity: 1; }

.btn-secondary { 
    background: transparent; 
    border: 2px solid var(--border-color); 
    color: var(--text-secondary); 
}
.btn-secondary:hover { 
    border-color: var(--text-color); 
    color: var(--text-color); 
    background: var(--bg-color);
}

/* GAME SCREEN (Flex Layout) */
#gameScreen {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow: hidden; /* Prevent body scroll, handle internally */
    padding-top: 20px;
}

/* Desktop/Tablet Grid */
@media (min-width: 700px) {
    #gameScreen {
        display: flex; /* Stack vertically instead of grid columns */
        flex-direction: column;
        flex: 1; /* Fill remaining space, don't force 100% height */
        overflow: hidden;
    }

    .game-controls-area {
        order: -1; /* Ensure controls are at the top */
        display: flex;
        flex-direction: row; /* Horizontal controls bar */
        align-items: center;
        justify-content: space-between;
        padding: 15px 20px;
        gap: 20px;
        flex-shrink: 0; /* Don't shrink */
        border-bottom: 2px solid var(--border-color); /* Separation */
        text-align: left; /* Reset alignment */
    }

    /* Layout inside the top control bar */
    .dice-container {
        margin: 0;
        order: 2; /* Dice in middle */
    }
    
    .turn-status-group {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        order: 1; /* Left side */
        min-width: 150px;
    }

    .action-group {
        order: 3; /* Right side */
        min-width: 150px;
        text-align: right;
    }

    /* Element Styling adjustments for the bar */
    .turn-indicator { margin: 0 0 5px 0; font-size: 1rem; }
    .message { margin: 0; font-size: 1rem; text-align: left; }
    
    .btn { 
        width: auto; 
        padding: 12px 30px; 
        margin: 0; 
        font-size: 18px;
    }

    .die { width: 60px; height: 60px; }
    .die-arrow { font-size: 18px; padding: 5px; }

    /* Score Table fills the rest */
    .table-container {
        flex: 1;
        border-radius: 0 0 var(--radius) var(--radius);
        box-shadow: none;
        border-top: none;
    }
    
    /* Table font sizing */
    th, td { padding: 12px; font-size: 16px; }
}

/* Adjust Setup Screen centering too */
.setup-card {
    justify-content: center; /* Pack to center, don't spread */
    gap: 25px;
}


/* Mobile Portrait / Small Screens */
@media (max-width: 767px) {
    .container {
        padding: 10px;
        border-radius: 0; /* Full screen on mobile */
        box-shadow: none;
    }
    
    body { padding: 0; }
    
    #gameScreen {
        flex-direction: column;
        overflow: hidden;
    }
    
    .game-controls-area {
        padding: 10px;
    }
    
    .table-container {
        border-radius: 8px;
    }

    .die { width: 42px; height: 42px; }
    .die-arrow { padding: 4px 12px; }
}
