/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0e1419;
    --text-primary: #ebdbb2;
    --text-secondary: #646669;
    --border-base: #3c3836;
    --text-error: #ca4754;
    --text-success: #72f1b8;
    --accent-primary: #e2b714;
    --ui-element-bg: #1d242b;
    --ui-element-hover: #2c343c;
}

body {
    font-family: 'Victor Mono', 'Fira Code', 'Consolas', monospace;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    overflow: hidden;
}

/* Hide scrollbars */
html {
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

html::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

.container {
    width: 100%;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}



/* Stats */
.stats {
    display: flex;
    justify-content: center;
    gap: 4rem;
    margin: 0 2rem 3rem 2rem;
    opacity: 0.7;
    transition: opacity 0.3s;
}

.stats.active {
    opacity: 1;
}

.stat {
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    display: block;
    font-size: 2.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Typing area */
.typing-area {
    width: 100%;
    margin: 0 0 2rem 0;
}

.text-display {
    background: var(--bg-primary);
    padding: 2rem;
    font-size: 3.5rem;
    line-height: 2;
    margin: 0 2rem 1rem 2rem;
    position: relative;
    height: calc((3.5rem * 2) * 3 + 4rem); /* 3 lines + total vertical padding (2rem top + 2rem bottom) */
    min-height: calc((3.5rem * 2) * 3 + 4rem); /* 3 lines + total vertical padding */
    max-height: calc((3.5rem * 2) * 3 + 4rem); /* 3 lines + total vertical padding */
    border: 1px solid var(--border-base);
    transition: border-color 0.2s;
    text-align: justify;
    width: calc(100% - 4rem);
    overflow: hidden; /* Keep as hidden to prevent manual scrolling */
    display: block;
    box-sizing: border-box;
    max-width: 100%;
    word-break: break-word;
}


.text-display.active {
    border-color: transparent;
}

.char {
    display: inline;
    color: var(--text-secondary);
    transition: color 0.2s ease, background 0.2s ease, opacity 0.2s ease;
    will-change: color, background, opacity;
}


.char.correct {
    color: var(--text-primary);
    transition: color 0.2s ease, background 0.2s ease, opacity 0.2s ease;
}

.char.incorrect {
    color: var(--text-error);
    background: rgba(202, 71, 84, 0.3);
    transition: color 0.2s ease, background 0.2s ease, opacity 0.2s ease;
}

.char.incorrect-space {
    color: var(--text-error);
    background: rgba(202, 71, 84, 0.3);
    transition: color 0.2s ease, background 0.2s ease, opacity 0.2s ease;
    border: 1px dashed var(--text-error); /* Visual indicator for an incorrect space */
}

.char.current {
    background-color: var(--text-primary); /* New foreground color as background for cursor */
    color: var(--bg-primary); /* New background color as text for contrast */
    transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
    animation: cursorBlink 1s infinite step-end;
}

.char.correct-word {
    color: var(--text-success);
    text-shadow: 0 0 5px rgba(114, 241, 184, 0.5);
    transition: color 0.2s ease, background 0.2s ease, text-shadow 0.2s ease, opacity 0.2s ease;
}

.char.pace-caret {
    background-color: var(--accent-primary); /* Yellow accent color as background for pace cursor */
    color: var(--bg-primary); /* Dark background as text color for contrast */
    transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
}

@keyframes cursorBlink {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.8;
    }
}

#typing-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

#typing-input[readonly] {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Controls */
.controls {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin: 0 2rem 3rem 2rem;
    flex-wrap: wrap;
}

.setting-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    background: var(--ui-element-bg);
    padding: 1.5rem;
    border-radius: 8px;
    border: 1px solid var(--border-base);
    min-width: 200px;
    transition: all 0.3s ease;
}

.setting-group:hover {
    border-color: var(--accent-primary);
    box-shadow: 0 0 10px rgba(226, 183, 20, 0.2);
}

.setting-group label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
    display: block;
}

.shortcut-info {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.3rem;
    padding: 0.2rem 0.4rem;
    background: var(--bg-primary);
    border-radius: 3px;
    display: inline-block;
}

.setting-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.controls select,
.controls input[type="number"] {
    background: var(--bg-primary);
    border: 1px solid var(--text-secondary);
    color: var(--text-primary);
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
}

.pace-options {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
}

.pace-options input[type="number"],
.pace-options span {
    margin: 0;
    flex: 1;
}

.pace-options span {
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding: 0.5rem;
    background: var(--bg-primary);
    border-radius: 4px;
    text-align: center;
}

/* Style the number input spin buttons (arrows) */
.controls input[type="number"]::-webkit-outer-spin-button,
.controls input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.settings-content input[type="number"]::-webkit-outer-spin-button,
.settings-content input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.controls input[type="number"] {
    -moz-appearance: textfield; /* For Firefox */
}

.settings-content input[type="number"] {
    -moz-appearance: textfield; /* For Firefox */
}

.controls select:hover,
.controls input[type="number"]:hover {
    background: var(--bg-primary);
    border-color: var(--accent-primary);
}

.controls select:focus,
.controls input[type="number"]:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* Custom checkbox styling */
.setting-label input[type="checkbox"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 1.2rem;
    height: 1.2rem;
    background: var(--bg-primary);
    border: 1px solid var(--text-secondary);
    border-radius: 3px;
    position: relative;
    cursor: pointer;
    margin: 0;
}

.setting-label input[type="checkbox"]:checked {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.setting-label input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 1px;
    width: 5px;
    height: 10px;
    border: solid var(--bg-primary);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* Shortcuts */
.shortcuts {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.shortcut-group h4 {
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.shortcut {
    display: inline-block;
    margin: 0.25rem 0.5rem;
}

kbd {
    background: var(--ui-element-bg);
    border: 1px solid var(--text-secondary);
    border-radius: 3px;
    padding: 0.1rem 0.3rem;
    font-family: inherit;
    font-size: 0.8rem;
    color: var(--text-primary);
}

.controls button {
    background: var(--ui-element-bg);
    border: 1px solid var(--text-secondary);
    color: var(--text-primary);
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.2s;
}

.controls button:hover {
    background: var(--ui-element-hover);
}

.controls button:active {
    background: var(--accent-primary);
    color: var(--bg-primary);
    border-color: var(--accent-primary);
}

/* Responsive */
@media (max-width: 1200px) {
    .container {
        padding: 1rem;
    }

    .stats {
        gap: 2rem;
        margin-bottom: 2rem;
    }

    .stat-value {
        font-size: 2rem;
    }

    .text-display {
        padding: 1.5rem;
        font-size: 3rem;
        height: calc((3rem * 2) * 3 + 3rem); /* 3 lines + total vertical padding (1.5rem top + 1.5rem bottom) */
        min-height: calc((3rem * 2) * 3 + 3rem); /* 3 lines + total vertical padding */
        max-height: calc((3rem * 2) * 3 + 3rem); /* 3 lines + total vertical padding */
        margin: 0 2rem 1rem 2rem;
        width: calc(100% - 4rem);
        max-width: calc(100% - 4rem);
    }
}

/* Medium screens */
@media (max-width: 992px) {
    .text-display {
        padding: 1.25rem;
        font-size: 2.5rem;
        height: calc((2.5rem * 2) * 3 + 2.5rem); /* 3 lines + total vertical padding */
        min-height: calc((2.5rem * 2) * 3 + 2.5rem);
        max-height: calc((2.5rem * 2) * 3 + 2.5rem);
        margin: 0 1.5rem 1rem 1.5rem;
        width: calc(100% - 3rem);
        max-width: calc(100% - 3rem);
    }
}

/* Small screens */
@media (max-width: 768px) {
    .text-display {
        padding: 1rem;
        font-size: 2rem;
        height: calc((2rem * 2) * 3 + 2rem); /* 3 lines + total vertical padding */
        min-height: calc((2rem * 2) * 3 + 2rem);
        max-height: calc((2rem * 2) * 3 + 2rem);
        margin: 0 1.5rem 1rem 1.5rem;
        width: calc(100% - 3rem);
        max-width: calc(100% - 3rem);
    }

    .stats {
        gap: 1.5rem;
    }
}

/* Extra small screens */
@media (max-width: 576px) {
    .text-display {
        padding: 0.75rem;
        font-size: 1.5rem;
        height: calc((1.5rem * 2) * 3 + 1.5rem); /* 3 lines + total vertical padding */
        min-height: calc((1.5rem * 2) * 3 + 1.5rem);
        max-height: calc((1.5rem * 2) * 3 + 1.5rem);
        margin: 0 1rem 1rem 1rem;
        width: calc(100% - 2rem);
        max-width: calc(100% - 2rem);
    }

    .stats {
        flex-direction: column;
        gap: 1rem;
    }
}

/* Results overlay */
.results-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(14, 20, 25, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.results-content {
    text-align: center;
    padding: 2rem;
    background: var(--ui-element-bg);
    max-width: 90%;
    width: 500px;
}

.results-title {
    font-size: 2rem;
    color: var(--accent-primary);
    margin-bottom: 1.5rem;
    font-weight: bold;
}

.final-stats {
    display: flex;
    justify-content: space-around;
    margin-bottom: 2rem;
}

.final-stat {
    text-align: center;
}

.final-stat-value {
    font-size: 3rem;
    font-weight: bold;
    color: var(--text-success);
    margin-bottom: 0.5rem;
}

.final-stat-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.restart-instruction {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-top: 1rem;
}

/* Settings overlay */
.settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(14, 20, 25, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1001;
    animation: fadeIn 0.3s ease;
    font-weight: 500;
}

select, input {
    background-color: var(--ui-element-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-base);
    padding: 0.5rem;
}

.settings-menu {
    background: var(--ui-element-bg);
    border-radius: 8px;
    border: 1px solid var(--border-base);
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-base);
}

.settings-header h2 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.5rem;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.close-btn:hover {
    background: var(--ui-element-hover);
}

.settings-content {
    padding: 1.5rem;
}

.settings-content .setting-group {
    margin-bottom: 1.5rem;
    background: var(--bg-primary);
    padding: 1rem;
    border-radius: 6px;
    border: 1px solid var(--border-base);
}

.settings-content .setting-group:last-child {
    margin-bottom: 0;
}

.hidden {
    display: none !important;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

