:root {
    --bg-color: #1a1a1a;
    --panel-bg: #2d2d2d;
    --text-main: #e0e0e0;
    --accent-green: #4caf50;
    --accent-red: #e74c3c;
    --accent-blue: #3498db;
    --highlight: #f1c40f;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: 'Courier New', Courier, monospace; /* Monospace for text-game feel */
    display: flex;
    justify-content: center;
    height: 100vh;
    overflow: hidden;
}

.game-wrapper {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    height: 100%;
    border-left: 1px solid #444;
    border-right: 1px solid #444;
    overflow: hidden; /* Prevent body scroll */
}

/* Setup Overlay */
#setup-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.95);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    overflow-y: auto;
    padding: 40px 20px 80px 20px;
    color: white;
}

/* Team Creator Overlay */
#team-creator-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: #1a1a1a;
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 20px 80px 20px;
    overflow-y: auto;
}

#players-editor-container {
    width: 100%;
    max-width: 600px;
    margin-bottom: 20px;
}

.editor-header, .editor-row {
    display: grid;
    grid-template-columns: 2.5fr 2fr 0.8fr 0.8fr 0.8fr 1.5fr;
    gap: 10px;
    margin-bottom: 5px;
    align-items: center;
}

.editor-header {
    font-weight: bold;
    color: var(--accent-green);
    text-transform: uppercase;
    font-size: 0.8rem;
    width: 100%;
    max-width: 600px;
}

.editor-row input, .editor-row select {
    background: #333;
    border: 1px solid #555;
    color: white;
    padding: 5px;
    width: 100%;
}

.editor-controls {
    display: flex;
    gap: 20px;
}

.hidden { display: none !important; }

.setup-group { margin-bottom: 20px; text-align: center; }
.setup-group label { display: block; margin-bottom: 5px; color: #aaa; }
.setup-group select, .setup-group input { 
    padding: 10px; font-size: 1.2rem; background: #333; color: white; border: 1px solid #555; 
}

/* Tabs */
#tab-nav {
    display: flex;
    background: #222;
    border-bottom: 1px solid #444;
}
.tab-btn {
    flex: 1;
    padding: 12px;
    background: #222;
    color: #888;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-weight: bold;
    border-bottom: 3px solid transparent;
}
.tab-btn.active {
    color: white;
    border-bottom-color: var(--accent-green);
    background: #2a2a2a;
}

.tab-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}
.tab-content.hidden { display: none; }

/* Mini Scoreboard */
#mini-scoreboard {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    background: #252525;
    border-bottom: 1px solid #333;
}
.mini-stat-box {
    font-size: 0.9rem;
}
#mini-batting { text-align: left; }
#mini-bowling { text-align: right; display: flex; align-items: center; }
.active-batter { color: var(--accent-green); font-weight: bold; }
#mini-non-striker { color: #aaa; }
#mini-bowler { color: var(--accent-blue); }

/* Full Scorecards */
#scorecard-view {
    overflow-y: auto;
    padding: 10px;
}
.card-panel {
    background: #222;
    margin-bottom: 15px;
    border-radius: 4px;
    padding: 10px;
    border: 1px solid #333;
}
.card-panel h3 {
    color: var(--accent-green);
    border-bottom: 1px solid #444;
    padding-bottom: 5px;
    margin-bottom: 5px;
    font-size: 1rem;
}
.card-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: #666;
    padding: 5px 0;
    border-bottom: 1px solid #333;
    text-transform: uppercase;
}

/* Batting Card */
#player-list { list-style: none; font-size: 0.9rem; }
#player-list li { display: flex; justify-content: space-between; padding: 6px 0; color: #888; border-bottom: 1px solid #2a2a2a; }
#player-list li.active { color: var(--highlight); font-weight: bold; border-left: 3px solid var(--highlight); padding-left: 5px; }
#player-list li.non-striker { color: #fff; border-left: 3px solid #fff; padding-left: 5px; }
#player-list li.out { color: var(--accent-red); text-decoration: line-through; }
#player-list li span.score { color: white; }
#player-list li span.dismissal { font-size: 0.7rem; color: #aaa; margin-left: 8px; text-decoration: none; display: inline-block; }

/* Bowling Card */
#bowling-list { list-style: none; font-size: 0.9rem; }
#bowling-list li { display: flex; justify-content: space-between; padding: 6px 0; color: #888; border-bottom: 1px solid #2a2a2a; }
#bowling-list li span.stats { color: white; font-family: monospace; }

/* Records */
.record-group h4 { color: #aaa; font-size: 0.8rem; margin-bottom: 5px; text-transform: uppercase; }
.record-group p { font-size: 0.9rem; color: #666; margin-bottom: 3px; display: flex; justify-content: space-between; }
.text-white { color: white; }

/* Scoreboard */
#scoreboard {
    background-color: var(--panel-bg);
    padding: 15px;
    display: flex;
    justify-content: space-between;
    border-bottom: 2px solid var(--accent-green);
}

.score-box {
    text-align: center;
}

.score-box .label {
    font-size: 0.8rem;
    color: #888;
}

.score-box .value {
    font-size: 1.5rem;
    font-weight: bold;
    color: #fff;
}

/* Main Console */
#game-console {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start; 
    min-height: 0; /* Important for flex scrolling */
    background: #222;
}

#commentary-log {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 20px;
    border-top: 1px solid #333;
    padding-top: 10px;
    color: #888;
    font-size: 0.9rem;
}

.history {
    margin-bottom: 5px;
}

#current-action {
    background: var(--panel-bg);
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    border: 1px solid #444;
    position: relative;
}

#bowler-action {
    font-size: 1.2rem;
    color: var(--accent-blue);
    margin-bottom: 10px;
}

#auto-bowl-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 0.7rem;
    padding: 5px 10px;
    background: transparent;
    border: 1px solid #fff;
    color: #fff;
    cursor: pointer;
    border-radius: 4px;
    font-family: inherit;
}
#auto-bowl-btn.active { border-color: var(--accent-green); color: var(--accent-green); }

.action-btn {
    padding: 12px 24px;
    font-size: 1rem;
    background: var(--accent-blue);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin: 10px 0;
}

.action-btn:disabled {
    background: #444;
    color: #999;
    cursor: not-allowed;
}

#drs-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    width: 100%;
}

#delivery-description {
    font-size: 1.4rem;
    font-weight: bold;
    color: var(--highlight);
    margin-bottom: 15px;
    min-height: 1.6em;
}

#result-message {
    font-size: 1.1rem;
    font-weight: bold;
    min-height: 1.2em;
}

/* Footer & Keypad */
#controls-area {
    padding: 10px;
    background: var(--panel-bg);
    border-top: 1px solid #444;
    flex-shrink: 0; /* Prevent shrinking */
}

.instruction {
    text-align: center;
    margin-bottom: 15px;
    font-size: 0.9rem;
    color: #aaa;
}

.keypad-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    max-width: 300px;
    margin: 0 auto;
}

.key {
    background: #333;
    padding: 10px;
    text-align: center;
    border-radius: 5px;
    font-weight: bold;
    cursor: pointer;
    border: 1px solid #555;
    transition: background 0.1s;
    user-select: none;
    touch-action: manipulation;
}

.key span {
    font-size: 0.7rem;
    font-weight: normal;
    color: #888;
    text-transform: uppercase;
}

.key.active {
    background: var(--accent-green);
    color: #000;
    border-color: var(--accent-green);
}

.key.active span {
    color: #222;
}

.key:active {
    background: var(--accent-green);
    color: #000;
    border-color: var(--accent-green);
}

@media (max-width: 600px) {
    body {
        height: 100dvh;
        overflow: auto;
    }

    .game-wrapper {
        max-width: 100%;
        border-left: none;
        border-right: none;
    }

    #scoreboard {
        padding: 10px;
    }

    .score-box .value {
        font-size: 1.2rem;
    }

    #game-console {
        padding: 12px;
    }

    #delivery-description {
        font-size: 1.1rem;
    }

    .instruction {
        font-size: 0.8rem;
    }

    .keypad-grid,
    #controls-area .action-btn {
        max-width: 100%;
    }

    .key {
        padding: 12px;
    }
}

/* Utility for text colors */
.text-green { color: var(--accent-green); }
.text-red { color: var(--accent-red); }

/* DRS Specific Buttons */
.btn-review {
    background-color: #e67e22;
    flex: 2; /* Emphasize Review as the primary action */
    font-weight: bold;
}

.btn-walk {
    background-color: #c0392b;
    flex: 1;
}

/* Bowler Controls (Multiplayer) */
.ball-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 15px;
}

.ball-btn {
    padding: 10px;
    background: #333;
    border: 1px solid #555;
    color: white;
    cursor: pointer;
    font-size: 0.8rem;
    border-radius: 4px;
}
.ball-btn:hover { background: #444; }
