:root {
    --primary-color: crimson;
    --winner-color: #4CAF50;
    --p1-color: #3363DE;
    --p2-color: #CA33DE;
    --text-color: white;
    --bg-color: #111;
    --gray-color: #aaa;
    --gray-dark: #555;
    --shadow-light: rgba(255, 255, 255, 0.1);
    --shadow-med: rgba(255, 255, 255, 0.3);
    --shadow-dark: rgba(255, 255, 255, 0.5);
    --bg-light: rgba(255, 255, 255, 0.05);
    --bg-light-hover: rgba(255, 255, 255, 0.08);
}

/* --- Base --- */
body {
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    position: relative;
    padding: 0 0 40px 0;
    box-sizing: border-box;
}

h1 {
    margin-bottom: 30px;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

h1 input {
    width: 30px;
    padding: 4px 8px;
    font-size: 1.5rem;
    text-align: center;
    background: var(--shadow-light);
    border: 2px solid var(--shadow-med);
    border-radius: 6px;
    color: var(--text-color);
    font-weight: bold;
    transition: width 0.2s;
}

h1 input:focus {
    outline: none;
    border-color: var(--primary-color);
    background: rgba(220, 20, 60, 0.2);
}

h1 input::-webkit-outer-spin-button,
h1 input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

h1 input[type=number] {
    -moz-appearance: textfield;
}

/* --- Score Display --- */
.scores {
    display: flex;
    gap: 80px;
    margin-bottom: 40px;
}

.player {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.player-name {
    font-size: 1.3rem;
    color: var(--gray-color);
    transition: all 0.5s;
    padding: 5px 10px;
    border-radius: 6px;
}

.player-name[contenteditable="true"] {
    cursor: text;
    transition: background 0.2s, box-shadow 0.2s;
}
.player-name[contenteditable="true"]:hover,
.player-name[contenteditable="true"]:focus {
    background: var(--shadow-light);
    box-shadow: 0 0 0 2px var(--primary-color);
    outline: none;
}


.player.winner .player-name {
    color: var(--winner-color);
    font-size: 1.6rem;
    font-weight: bold;
}

.score {
    font-size: 6rem;
    font-weight: bold;
    color: var(--primary-color);
    transition: all 0.5s;
}

.player.winner .score {
    color: var(--winner-color);
    text-shadow: 0 0 20px var(--winner-color);
}

/* --- Player Controls --- */
.player-controls {
    position: fixed;
    display: flex;
    flex-direction: column;
    top: 50%;
    transform: translateY(-50%);
    background: var(--primary-color);
    border-radius: 10px;
    overflow: hidden;
    z-index: 10;
}

.player-controls.left { left: 40px; }
.player-controls.right { right: 40px; }

button {
    background: transparent;
    border: none;
    color: var(--text-color);
    font-size: 2rem;
    cursor: pointer;
    transition: 0.2s;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

button:focus {
    outline: none;
}

.player-controls button {
    padding: 40px 30px;
    min-width: 70px;
    position: relative;
}

.player-controls button:first-child::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 10%;
    right: 10%;
    height: 2px;
    background: var(--text-color);
}

button:hover {
    background: rgba(0, 0, 0, 0.2);
}

button:active {
    background: rgba(0, 0, 0, 0.4);
}

button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.player-controls:has(button:disabled) {
    background: var(--gray-dark);
}

/* --- Game Controls (Reset/Undo) --- */
.game-controls {
    display: flex;
    gap: 15px;
    margin-top: 20px;
}

.game-controls button {
    padding: 12px 30px;
    font-size: 1.1rem;
    background: var(--shadow-light);
    border: 2px solid var(--shadow-med);
    border-radius: 8px;
}
.game-controls button:hover:not(:disabled) {
    background: var(--shadow-dark);
}
.game-controls button#resetBtn {
    background: rgba(220, 20, 60, 0.3);
    border-color: rgba(220, 20, 60, 0.5);
}
.game-controls button#resetBtn:hover {
    background: rgba(220, 20, 60, 0.5);
}

/* --- UI Controls --- */
#fullscreenBtn, #settingsBtn {
    position: fixed;
    top: 20px;
    padding: 12px 16px;
    font-size: 1.4rem;
    background: var(--shadow-light);
    border: 2px solid var(--shadow-med);
    border-radius: 8px;
    line-height: 1;
}
#fullscreenBtn { right: 20px; }
#settingsBtn { 
    right: 80px; 
    font-size: 1rem; /* Adjusted for text */
    font-weight: 600;
    line-height: 1.2; /* Adjusted for text */
    padding: 12px 20px; /* Adjusted for text */
}


#fullscreenBtn:hover, #settingsBtn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: var(--shadow-dark);
}

#fullscreenBtn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

/* --- Settings Panel --- */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}
.overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.settings-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 320px;
    max-width: 90%;
    height: 100%;
    background: #222;
    border-left: 2px solid var(--shadow-med);
    z-index: 100;
    transform: translateX(100%);
    pointer-events: none;
    transition: transform 0.3s ease-in-out;
    display: flex;
    flex-direction: column;
}
.settings-panel.show {
    transform: translateX(0);
    pointer-events: auto;
}
.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    border-bottom: 2px solid var(--shadow-med);
    flex-shrink: 0;
}
.settings-header h2 {
    margin: 0;
    font-size: 1.5rem;
}
.settings-content {
    padding: 25px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    flex-grow: 1;
}
.settings-content h3 {
    margin: 0;
    text-align: left;
    color: var(--gray-color);
    border-bottom: 1px solid var(--gray-dark);
    padding-bottom: 8px;
    font-size: 1.2rem;
}
.color-picker {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    font-size: 1.1rem;
}
.color-picker input[type="color"] {
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    padding: 0;
    border-radius: 6px;
    cursor: pointer;
}
.setting-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.1rem;
}
.setting-toggle input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

/* General settings button */
.setting-btn {
    padding: 10px 15px;
    font-size: 0.9rem;
    background: var(--shadow-light);
    border: 2px solid var(--shadow-med);
    border-radius: 6px;
    color: var(--text-color);
    cursor: pointer;
    width: 100%;
    transition: 0.3s;
    font-weight: 600;
    margin-top: 10px;
}
.setting-btn:hover {
    background: var(--shadow-dark);
    border-color: var(--shadow-med);
}

/* Keybinding styles */
.settings-content h3:has(+ .keybinding-editor) {
    margin-bottom: 15px; /* Add space before keybinding editor */
}

.keybinding-editor {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.keybinding-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-size: 1.1rem;
}
.keybinding-row label {
    flex-shrink: 0;
    white-space: nowrap;
}
.keybinding-input {
    width: 100%;
    background: var(--bg-light);
    border: 2px solid var(--shadow-med);
    border-radius: 6px;
    color: var(--text-color);
    padding: 8px 12px;
    font-size: 1rem;
    font-family: 'Courier New', Courier, monospace;
}
.keybinding-input:focus {
    outline: none;
    border-color: var(--primary-color);
    background: var(--shadow-light);
}


.danger-zone-header {
    margin-top: auto; /* Pushes to bottom */
    padding-top: 20px;
    color: var(--primary-color);
    border-top: 1px solid var(--gray-dark);
    border-bottom: none;
    font-size: 1.2rem;
}

.clear-history-btn {
    padding: 12px 20px;
    font-size: 1rem;
    background: rgba(220, 20, 60, 0.3);
    border: 2px solid rgba(220, 20, 60, 0.5);
    border-radius: 6px;
    color: var(--text-color);
    cursor: pointer;
    width: 100%;
    transition: 0.3s;
    font-weight: 600;
}
.clear-history-btn:hover {
    background: rgba(220, 20, 60, 0.5);
    border-color: rgba(220, 20, 60, 0.7);
}

#closeSettingsBtn {
    font-size: 1.8rem;
    font-weight: 300;
    padding: 0 10px;
    background: transparent;
    border: none;
    color: var(--gray-color);
    line-height: 1;
    border-radius: 6px;
}
#closeSettingsBtn:hover {
    color: var(--text-color);
    background: var(--shadow-light);
}

/* --- Winner Message --- */
.winner-message {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--winner-color);
    padding: 15px 30px;
    border-radius: 10px;
    font-size: 1.5rem;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.5s;
    pointer-events: none;
    z-index: 80;
}

.winner-message.show {
    opacity: 1;
}

/* --- History --- */
.win-history-section {
    margin-top: 40px;
    width: 90%;
    max-width: 600px;
}

.win-counter {
    text-align: center;
    font-size: 1.3rem;
    margin-bottom: 20px;
    color: var(--gray-color);
    display: none;
}

.win-counter.show {
    display: block;
}

.win-history {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 200px;
    overflow-y: auto;
    padding-right: 5px;
}

.win-history::-webkit-scrollbar { width: 8px; }
.win-history::-webkit-scrollbar-track {
    background: var(--shadow-light);
    border-radius: 4px;
}
.win-history::-webkit-scrollbar-thumb {
    background: rgba(220, 20, 60, 0.5);
    border-radius: 4px;
}

.win-record {
    background: var(--bg-light);
    border: 2px solid var(--shadow-med);
    border-radius: 8px;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s;
}

.win-record:hover {
    background: var(--bg-light-hover);
    border-color: var(--shadow-dark);
}

.win-record.p1-win { border-left: 4px solid var(--p1-color); }
.win-record.p2-win { border-left: 4px solid var(--p2-color); }

.win-record-winner {
    font-weight: bold;
    font-size: 1.2rem;
    min-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.win-record.p1-win .win-record-winner { color: var(--p1-color); }
.win-record.p2-win .win-record-winner { color: var(--p2-color); }

.win-record-score {
    font-size: 1.3rem;
    font-weight: bold;
    flex: 1;
    text-align: center;
}

.win-record-settings {
    color: #888;
    font-size: 0.9rem;
}

/* Clear History Button is now styled above in Settings Panel */


/* --- Mobile Layout --- */
@media (max-width: 768px) {
    .player-controls {
        position: static;
        transform: none;
        flex-direction: row;
        width: 90%;
        max-width: 300px;
        justify-content: center;
        background: transparent;
    }
    
    .player-controls button {
        flex: 1;
        padding: 20px 15px;
        font-size: 1.5rem;
        background: var(--primary-color);
    }

    .player-controls.left {
        order: 3; /* P1 controls below score */
        margin: 20px 0 -30px 0;
    }
    .player-controls.right {
        order: 4; /* P2 controls below score */
        margin: 20px 0 -30px 0;
    }
    .scores { order: 2; } /* Scores */
    h1 { order: 1; } /* Settings */
    .game-controls { order: 5; } /* Reset/Undo */
    .win-history-section { order: 6; } /* History */

    .player-controls.left button:first-child { border-radius: 10px 0 0 10px; }
    .player-controls.left button:last-child { border-radius: 0 10px 10px 0; }
    .player-controls.right button:first-child { border-radius: 10px 0 0 10px; }
    .player-controls.right button:last-child { border-radius: 0 10px 10px 0; }
    
    .player-controls button:first-child::after {
        content: none; /* Remove horizontal line */
    }

    .scores { gap: 40px; }
    .score { font-size: 5rem; }
}
