:root {
    --bg-color: #1e1e1e;
    --container-bg: #252526;
    --track-bg: #2d2d2d;
    --text-color: #d4d4d4;
    --border-color: #3c3c3c;
    --title-color: #569cd6;
    --accent-color: #ce9178;
    --force-bar-bg: #3e3e42;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 2rem;
    min-height: 100vh;
    margin: 0;
}

.hidden {
    display: none !important;
}

#game-container {
    background-color: var(--container-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem 2rem;
    width: 90%;
    max-width: 1100px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

h1, h2, h3, h4 {
    text-align: center;
    color: var(--title-color);
    margin-top: 0;
}
h1, h2, h3 {
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}
h4 {
    margin-bottom: 0.5rem;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}
.top-bar h1 {
    flex-grow: 1;
    text-align: left;
    border: none;
    padding: 0;
}

#player-management {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
#player-select, #add-player-button, #start-mode-select, #false-start-penalty-select {
    padding: 0.5rem;
    font-size: 0.9rem;
    background-color: #3a3d41;
    border: 1px solid #4a4a4a;
    color: var(--text-color);
    border-radius: 5px;
}
#add-player-button {
    cursor: pointer;
    transition: background-color 0.2s;
}
#add-player-button:hover:not(:disabled) { background-color: #4a4d51; }

.top-buttons {
    display: flex;
    gap: 0.5rem;
}

#new-game-button, #customize-toggle-button {
    border: 1px solid #4a4a4a;
    color: var(--text-color);
    padding: 0.5rem 1rem;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s, opacity 0.2s;
}
#new-game-button:disabled, #add-player-button:disabled {
    background-color: #555;
    border-color: #444;
    cursor: not-allowed;
    opacity: 0.6;
}

#new-game-button { background-color: #4CAF50; border-color: #388E3C; }
#new-game-button:hover:not(:disabled) { background-color: #5cb85c; }
#customize-toggle-button { background-color: #3a3d41; }
#customize-toggle-button:hover { background-color: #4a4d51; }

#modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

#customize-modal, #help-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--container-bg);
    padding: 2rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    z-index: 1001;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-content {
    position: relative;
}
.modal-content h2 {
    margin-bottom: 1.5rem;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}
.close-button {
    position: absolute;
    top: -1.5rem;
    right: -1rem;
    background: none;
    border: none;
    font-size: 2.5rem;
    color: var(--text-color);
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}
.close-button:hover {
    color: var(--accent-color);
}
.customize-player-section {
    text-align: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px dashed var(--border-color);
}
#customize-player-list .customize-player-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}
.customize-player-section h4 {
    border: none;
    font-size: 1.2em;
    margin-bottom: 0.75rem;
}
.customize-player-section h4 span {
    font-size: 1.5em;
    vertical-align: middle;
}
.vehicle-selector {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}
.vehicle-btn {
    font-size: 2rem;
    width: 55px;
    height: 55px;
    border: 1px solid #4a4a4a;
    border-radius: 5px;
    background-color: #3a3d41;
    color: #ccc;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: scaleX(-1);
}
.vehicle-btn:hover { background-color: #4a4d51; }
.current-vehicle {
    transform: scaleX(-1);
    display: inline-block;
}

.key-config-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-top: 15px;
}
.key-config-area {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    width: 100%;
}
.key-label {
    font-weight: bold;
    color: #9cdcfe;
    min-width: 50px;
}
.current-key-display {
    font-weight: bold;
    color: var(--title-color);
    background-color: var(--track-bg);
    padding: 4px 10px;
    border-radius: 5px;
    border: 1px solid var(--border-color);
    font-family: 'Consolas', 'Courier New', monospace;
    min-width: 100px;
    text-align: center;
}
.change-key-btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
    background-color: #3a3d41;
    border: 1px solid #4a4a4a;
    color: var(--text-color);
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.2s;
}
.change-key-btn:hover {
    background-color: #4f5257;
}
.change-key-btn.is-listening {
    background-color: var(--accent-color);
    color: var(--bg-color);
    border-color: #a56d54;
}

.difficulty-settings {
    margin-bottom: 1rem; padding: 1rem; border: 1px solid var(--border-color);
    border-radius: 8px; background-color: var(--bg-color);
}
.difficulty-settings h3 { margin-bottom: 10px; font-size: 1.1em; border: none; text-align: left; }
.difficulty-options { display: flex; justify-content: center; gap: 15px; flex-wrap: wrap; }
.difficulty-options label { cursor: pointer; padding: 5px 8px; border-radius: 4px; transition: background-color 0.2s; }
.difficulty-options label:hover { background-color: var(--force-bar-bg); }
.difficulty-options input[type="radio"] { margin-right: 5px; }

.manual-controls-area {
    margin-top: 2rem;
    padding: 1rem 1rem 0 1rem;
    border-top: 2px solid var(--border-color);
}
.manual-controls-area h4 {
    margin-bottom: 1rem;
    font-size: 1.1em;
    border: none;
    text-align: left;
}
.settings-group { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 10px; }
.settings-group label { font-size: 0.9em; flex-shrink: 0; }
.settings-group input[type="range"] { flex-grow: 1; max-width: 300px; }
.settings-group select { flex-grow: 1; max-width: 300px; }
.settings-group span { font-weight: bold; min-width: 30px; text-align: left; color: var(--accent-color); }
input[type=range] { -webkit-appearance: none; appearance: none; background: transparent; cursor: pointer; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; border: 1px solid var(--border-color); height: 18px; width: 18px; border-radius: 50%; background: var(--title-color); margin-top: -7px; }
input[type=range]::-moz-range-thumb { border: 1px solid var(--border-color); height: 18px; width: 18px; border-radius: 50%; background: var(--title-color); }
input[type=range]::-webkit-slider-runnable-track { width: 100%; height: 5px; cursor: pointer; background: var(--track-bg); border-radius: 3px; border: 1px solid var(--border-color); }
input[type=range]::-moz-range-track { width: 100%; height: 5px; cursor: pointer; background: var(--track-bg); border-radius: 3px; border: 1px solid var(--border-color); }

#countdown-display {
    font-size: 4em; font-weight: bold; color: var(--accent-color); text-align: center;
    height: 1.2em; display: flex; align-items: center; justify-content: center;
    margin-bottom: 0.5rem; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

#winner-announcement { font-size: 2.5em; font-weight: bold; text-align: center; padding: 1rem; margin-bottom: 1rem; min-height: 2.5em; }

#controls {
    display: grid;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

#race-track {
    background-color: #1a1a1a;
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1.5rem;
    border: 1px solid #333;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.lane-container {
    position: relative;
}
.lane-label {
    text-align: center;
    font-weight: bold;
    margin-bottom: 8px;
    font-size: 1.1em;
}

.lane {
    position: relative; height: 50px; background-color: var(--track-bg);
    border-radius: 3px; border: 1px solid #444; display: flex; align-items: center;
}
.lane .finish-line { position: absolute; right: 10px; top: 0; height: 100%; font-size: 2rem; display: flex; align-items: center; justify-content: center; }
.horse { 
    position: absolute; top: 25%; transform: translateY(-50%) scaleX(-1); font-size: 1.8rem; z-index: 10;
    transition: opacity 0.3s, text-shadow 0.3s ease-in-out;
}
/* NEW CLASS FOR THE HIGHLIGHT */
.horse.perfect-start-highlight {
    text-shadow: 0 0 12px #ffd700;
}

.remove-player-btn {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #c13434;
    color: white;
    border: 1px solid #a02a2a;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 14px;
    line-height: 20px;
    text-align: center;
    cursor: pointer;
    z-index: 20;
    font-weight: bold;
}
.remove-player-btn:hover { background: #e04343; }

.control-group {
    text-align: center; border: 2px solid var(--border-color); padding: 1rem;
    border-radius: 5px; background-color: var(--container-bg);
    display: flex; flex-direction: column; align-items: center;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: background-color 0.2s, border-color 0.2s;
}
.control-group:hover {
    background-color: #3a3d41;
    border-color: #555;
}

.control-group h3 { border: none; height: auto; margin-bottom: 10px; font-size: 1.1em; }
.score { color: var(--accent-color); font-weight: bold; font-size: 1.1rem; margin-top: 0; margin-bottom: 0.5rem; }

.force-container { 
    width: 40px; height: 150px; background-color: var(--force-bar-bg); 
    border: 1px solid var(--border-color); border-radius: 8px; position: relative; 
    overflow: hidden; display: flex; flex-direction: column-reverse; margin: 10px auto;
    transition: border-color 0.2s;
}
.control-group:hover .force-container {
    border-color: #555;
}

.force-bar { width: 100%; height: 0%; transition: height 0.05s ease-out; border-radius: 6px 6px 0 0; }

#log-container { background-color: var(--bg-color); border: 1px solid var(--border-color); border-radius: 5px; padding: 1rem; height: 150px; overflow-y: auto; }
#log-list { list-style: none; padding: 0; margin: 0; }
#log-list li { padding: 0.3rem 0.5rem; border-bottom: 1px dashed #333; font-family: 'Consolas', 'Courier New', monospace; word-break: break-word; }
#log-list li:last-child { border-bottom: none; }

#help-prompt {
    position: fixed;
    bottom: 10px;
    left: 10px;
    background-color: rgba(0, 0, 0, 0.6);
    color: #ccc;
    padding: 6px 12px;
    border-radius: 5px;
    font-size: 0.9em;
    font-style: italic;
    z-index: 500;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color 0.2s;
}
#help-prompt:hover {
    background-color: rgba(37, 37, 38, 0.8);
    color: white;
}

#help-modal .modal-content h2, #help-modal .modal-content h3 {
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
}
#help-modal .modal-content h3 { font-size: 1.2rem; color: var(--accent-color); border: none; }
#help-modal p { line-height: 1.6; margin-bottom: 1.5rem; }
#help-modal ul { padding-left: 20px; }
#help-modal ul li { margin-bottom: 0.5rem; }

#help-controls-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}
.help-control-item {
    background-color: var(--bg-color);
    padding: 1rem;
    border-radius: 5px;
    border: 1px solid var(--border-color);
}
.help-control-item p { margin: 0; }
.help-control-item .key {
    font-weight: bold;
    color: var(--title-color);
    background-color: var(--track-bg);
    padding: 2px 6px;
    border-radius: 3px;
    border: 1px solid var(--border-color);
    font-family: 'Consolas', 'Courier New', monospace;
    display: inline-block;
    margin-left: 8px;
}

#audio-controls, #about-section {
    margin-top: 2rem;
    border-top: 1px solid var(--border-color);
    padding-top: 1.5rem;
}
.audio-setting-item {
    display: flex;
    align-items: center;
    gap: 10px;
}
.audio-setting-item label {
    font-weight: bold;
}
#volume-slider {
    flex-grow: 1;
}
#mute-button {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    color: var(--text-color);
    font-size: 1.2rem;
    cursor: pointer;
    width: 40px;
    height: 35px;
    transition: background-color 0.2s;
}
#mute-button:hover {
    background-color: #3a3d41;
}
