:root {
    --bg-color: #1a3c21;
    --card-bg: #224d2b;
    --text-color: #ffffff;
    --active-border: #ffd700;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.container {
    width: 100%;
    max-width: 600px;
    background: rgba(0, 0, 0, 0.4);
    padding: 25px;
    border-radius: 15px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    text-align: center;
}

.hidden {
    display: none !important;
}

h1 {
    margin-top: 0;
    letter-spacing: 1px;
}

/* Menu Layout styling */
.menu-screen {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 10px 0;
}

.input-group {
    display: flex;
    flex-direction: column;
    text-align: left;
    gap: 8px;
}

.input-group label {
    font-weight: bold;
    font-size: 0.95rem;
    color: #cbd5e1;
}

.input-group input[type="text"] {
    padding: 12px;
    border: none;
    border-radius: 6px;
    background: #224d2b;
    color: white;
    font-size: 1rem;
}

/* Custom Segmented Radio Buttons for Red selection */
.radio-tile-group {
    display: flex;
    gap: 10px;
}

.radio-tile {
    flex: 1;
    position: relative;
    background: var(--card-bg);
    padding: 12px;
    border-radius: 6px;
    text-align: center;
    cursor: pointer;
    border: 2px solid transparent;
    font-weight: bold;
    transition: all 0.2s ease;
}

.radio-tile input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
}

.radio-tile:has(input:checked) {
    border-color: var(--active-border);
    background: #2d6639;
}

.start-btn {
    background: #2ed573;
    color: white;
    border: none;
    padding: 15px;
    font-size: 1.2rem;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    margin-top: 10px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    transition: background 0.2s;
}

.start-btn:hover {
    background: #26af5f;
}

/* Scoreboard */
.scoreboard {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 5px;
}

.player-card {
    flex: 1;
    background: var(--card-bg);
    padding: 15px;
    border-radius: 10px;
    border: 3px solid transparent;
    cursor: pointer;
    transition: all 0.3s ease;
}

.player-card h2 {
    margin: 0;
    font-size: 1.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-card.active {
    border-color: var(--active-border);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.4);
}

.score {
    font-size: 3rem;
    font-weight: bold;
    margin-top: 10px;
}

/* Margin text layout */
.margin-display {
    font-size: 0.95rem;
    font-weight: 600;
    color: #ffd700;
    margin-bottom: 20px;
    background: rgba(255, 255, 255, 0.1);
    padding: 6px;
    border-radius: 20px;
}

/* Stats Bar */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    background: rgba(0, 0, 0, 0.2);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 25px;
    font-size: 0.95rem;
    text-align: left;
}

#target-ball {
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    display: inline-block;
}

.target-red { background-color: #d63031; color: white; }
.target-color { background-color: #e1b12c; color: black; }

/* Ball Buttons */
.ball-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 25px;
    height: 150px;
}

.ball {
    padding: 15px 5px;
    border: none;
    border-radius: 50px;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.3s;
    box-shadow: inset -5px -5px 15px rgba(0,0,0,0.4), 2px 4px 6px rgba(0,0,0,0.3);
}

.ball:active:not(:disabled) {
    transform: scale(0.95);
}

.ball:disabled {
    opacity: 0.2;
    cursor: not-allowed;
    box-shadow: none;
}

/* Ball Colors styling */
.white { background: #ffffff; color: #000; }
.red { background: #d63031; color: #fff; }
.yellow { background: #f1c40f; color: #000; }
.green { background: #2ed573; color: #fff; }
.brown { background: #8b5a2b; color: #fff; }
.blue { background: #1e90ff; color: #fff; }
.pink { background: #ff7675; color: #fff; }
.black { background: #2d3436; color: #fff; }

/* Control Buttons */
.controls {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 15px;
}

.control-btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 5px;
    font-weight: bold;
    cursor: pointer;
    color: white;
}

.foul-btn { background-color: #e67e22; }
.miss-btn { background-color: #7f8c8d; }
.reset-btn { background-color: #c0392b; }

.rules-anchor-btn {
    background: transparent;
    color: #94a3b8;
    border: 1px dashed #475569;
    padding: 10px;
    border-radius: 6px;
    cursor: pointer;
    width: 100%;
    font-weight: bold;
    transition: all 0.2s;
}

.rules-anchor-btn:hover {
    color: white;
    border-color: var(--active-border);
}

/* Modal Styling */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal-content {
    background: #1e293b;
    padding: 25px;
    border-radius: 12px;
    max-width: 450px;
    width: 90%;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
}

/* Specific size adjustments for the Rules Modal */
.rules-content {
    max-width: 550px;
    max-height: 80vh; /* Keeps the entire popup from running off-screen */
}

.modal-content h2 {
    margin-top: 0;
    font-size: 1.4rem;
    margin-bottom: 10px;
}

/* Rules Modal Navigation Tabs (Static) */
.rules-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 15px;
    border-bottom: 1px solid #334155;
    padding-bottom: 12px;
    flex-shrink: 0; /* Prevents tabs from squishing */
}

.tab-btn {
    background: #334155;
    color: #94a3b8;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: bold;
    transition: background 0.2s;
}

.tab-btn.active {
    background: var(--active-border);
    color: black;
}

/* Completely Scrollable Rules Body */
.rules-body {
    background: rgba(0, 0, 0, 0.2);
    padding: 15px;
    border-radius: 8px;
    text-align: left;
    overflow-y: auto; /* Activates vertical scrolling when text overflows */
    flex-grow: 1;     /* Automatically expands to use maximum allowed space */
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Custom Scrollbar Styling for a premium feel */
.rules-body::-webkit-scrollbar {
    width: 6px;
}
.rules-body::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
}
.rules-body::-webkit-scrollbar-thumb {
    background: #475569;
    border-radius: 4px;
}
.rules-body::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

.rules-body h3 {
    margin-top: 0;
    color: var(--active-border);
    font-size: 1.15rem;
}

.rules-body ul {
    margin: 0;
    padding-left: 20px;
}

.rules-body li {
    margin-bottom: 12px;
    font-size: 0.95rem;
    line-height: 1.45;
    color: #e2e8f0;
}

.foul-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.foul-choice {
    padding: 12px;
    border: none;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 1px 2px 4px rgba(0,0,0,0.2);
}

.close-modal-btn {
    background: #475569;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    width: 100%;
    flex-shrink: 0; /* Ensures button size remains static at the bottom */
}

/* Victory Elements styling */
.trophy-icon {
    font-size: 4rem;
    margin-bottom: 10px;
    animation: bounce 2s infinite alternate;
}

#winner-announcement {
    color: var(--active-border);
    margin: 5px 0 15px 0;
    font-size: 2rem;
}

.victory-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 15px;
}

.celebrate-btn {
    background: linear-gradient(45deg, #ff007f, #ffd700);
    color: black;
    border: none;
    padding: 14px;
    border-radius: 5px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.3);
    transition: transform 0.1s;
}

.celebrate-btn:active {
    transform: scale(0.98);
}

@keyframes bounce {
    0% { transform: translateY(0); }
    100% { transform: translateY(-10px); }
}

@media (max-width: 480px) {
    .ball-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}