/* --- Custom Theme & Variables --- */
:root {
    --bg-dark: #212F3D;
    --text-light: #ABB2B9;
    --accent-color: #1ABC9C;
    --surface-color: #2C3A47;
    --error-color: #E74C3C;
    --correct-color: #2ECC71;
    --font-mono: 'Roboto Mono', 'Source Code Pro', 'Courier New', Courier, monospace;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-light);
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow-x: hidden;
}

.container {
    width: 90%;
    max-width: 850px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

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

h1 {
    color: var(--accent-color);
    font-size: 2.2rem;
    margin: 0;
}

.stats {
    display: flex;
    gap: 25px;
    font-size: 1.1rem;
}

.main-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.time-selection {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.time-btn {
    padding: 8px 16px;
    background-color: var(--surface-color);
    border: 2px solid var(--surface-color);
    border-radius: 5px;
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.3s ease;
}

.time-btn.active {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
    color: var(--bg-dark);
}

.time-btn:hover:not(.active) {
    background-color: #3f5267;
    border-color: #3f5267;
}

#loading {
    font-size: 1.2rem;
    color: var(--accent-color);
    margin-bottom: 20px;
}

#words-display {
    font-family: var(--font-mono);
    font-size: 1.6rem;
    line-height: 1.8;
    background-color: var(--surface-color);
    padding: 25px;
    border-radius: 8px;
    height: 210px; 
    overflow: auto;
    text-align: left;
    position: relative;
    color: var(--text-light);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--accent-color) var(--surface-color);
}

#words-display::-webkit-scrollbar {
    width: 8px;
}

#words-display::-webkit-scrollbar-track {
    background: var(--surface-color);
    border-radius: 4px;
}

#words-display::-webkit-scrollbar-thumb {
    background-color: var(--accent-color);
    border-radius: 4px;
}

.time-btn:focus, #start-btn:focus, #restart-btn:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

#caret {
    position: absolute;
    width: 2px;
    height: 1.2em;
    background-color: var(--accent-color);
    border-radius: 1px;
    transition: left 0.08s ease-out, top 0.08s ease-out;
    animation: blink 1s step-end infinite;
    pointer-events: none;
}

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

#typing-input {
    opacity: 0;
    position: absolute;
    top: -9999px;
    left: -9999px;
}

#results {
    margin-top: 20px;
    padding: 20px;
    background-color: var(--surface-color);
    border-radius: 8px;
    width: 100%;
    box-sizing: border-box;
    color: var(--text-light);
}

h2 {
    color: var(--accent-color);
    margin-top: 0;
    font-size: 1.8rem;
}

.result-stats {
    display: flex;
    justify-content: space-around;
    font-size: 1.2rem;
    margin-top: 15px;
}

.hidden {
    display: none;
}

.footer {
    display: flex;
    gap: 15px;
    justify-content: center;
}

#start-btn, #restart-btn {
    padding: 10px 25px;
    font-size: 1.1rem;
    cursor: pointer;
    background-color: var(--accent-color);
    color: var(--bg-dark);
    border: none;
    border-radius: 5px;
    transition: background-color 0.3s ease;
}

#start-btn:hover, #restart-btn:hover {
    background-color: #16a085;
}

#start-btn:disabled, #restart-btn:disabled {
    background-color: #7f8c8d;
    cursor: not-allowed;
    color: #bdc3c7;
}

.letter {
    transition: color 0.2s;
}

.letter.correct {
    color: var(--correct-color);
}

.letter.incorrect {
    color: var(--error-color);
}

.shake {
    animation: shake 0.3s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px); }
    50% { transform: translateX(3px); }
    75% { transform: translateX(-3px); }
}

@media (max-width: 768px) {
    .container {
        gap: 1rem;
    }
    .header {
        flex-direction: column;
        gap: 15px;
        padding-bottom: 0.5rem;
    }
    h1 {
        font-size: 1.8rem;
    }
    .stats {
        flex-wrap: wrap;
        justify-content: center;
        font-size: 1rem;
        gap: 15px;
    }
    #words-display {
        font-size: 1.1rem;
        line-height: 1.6;
        height: 120px;
        padding: 15px;
    }
    #caret {
        height: 1.1em;
    }
    .result-stats {
        flex-direction: column;
        gap: 10px;
    }
    .footer {
        flex-direction: column;
        gap: 10px;
    }
    #start-btn, #restart-btn, .time-btn {
        width: 100%;
        max-width: 200px;
    }
}