:root {
    --bg-color: #f0f2f5;
    --text-color: #333;
    --card-bg-color: #ffffff;
    --primary-color: #007bff;
    --secondary-color: #6c757d;
    --correct-color: #28a745;
    --incorrect-color: #dc3545;
    --font-body: 'Poppins', sans-serif;
    --font-mono: 'Inconsolata', monospace;
    --shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    --border-radius: 12px;
}

[data-theme="dark"] {
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --card-bg-color: #1e1e1e;
    --primary-color: #0d6efd;
    --secondary-color: #adb5bd;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

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

body {
    font-family: var(--font-body);
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 1rem;
    transition: background-color 0.3s, color 0.3s;
}

.container {
    background-color: var(--card-bg-color);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 800px;
    text-align: center;
    transition: background-color 0.3s;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.title-container {
    text-align: left;
}

h1 {
    font-size: 2rem;
    color: var(--primary-color);
    margin: 0;
}

.powered-by {
    font-size: 0.9rem;
    color: var(--secondary-color);
    margin-top: 4px;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.home-btn {
    font-size: 0.9rem;
    color: var(--secondary-color);
    text-decoration: none;
    border: 1px solid var(--secondary-color);
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    transition: all 0.3s ease;
}

.home-btn:hover {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

/* Dark Mode Toggle */
.theme-switcher {
    position: relative;
}
#dark-mode-toggle {
    display: none;
}
.toggle-label {
    display: block;
    width: 50px;
    height: 26px;
    background-color: #ccc;
    border-radius: 13px;
    cursor: pointer;
    position: relative;
    transition: background-color 0.3s;
}
.toggle-label::after {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background-color: white;
    top: 2px;
    left: 2px;
    transition: transform 0.3s;
}
#dark-mode-toggle:checked + .toggle-label {
    background-color: var(--primary-color);
}
#dark-mode-toggle:checked + .toggle-label::after {
    transform: translateX(24px);
}

.test-settings {
    margin-bottom: 1.5rem;
}

.time-options .time-btn {
    font-family: var(--font-body);
    font-size: 1rem;
    background-color: transparent;
    color: var(--secondary-color);
    border: 1px solid var(--secondary-color);
    padding: 0.5rem 1rem;
    margin: 0 0.5rem;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.time-options .time-btn.active,
.time-options .time-btn:hover {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.test-area {
    position: relative;
    margin-bottom: 1.5rem;
}

.text-display-area {
    font-family: var(--font-mono);
    font-size: 1.5rem;
    line-height: 1.8;
    background-color: var(--bg-color);
    padding: 1rem;
    border-radius: var(--border-radius);
    text-align: left;
    height: 150px; /* Fixed height is crucial for scrolling */
    overflow-y: auto; /* Enables vertical scrolling when content exceeds height */
    user-select: none;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.text-display-area span {
    transition: color 0.1s;
}

.text-display-area span.correct {
    color: var(--correct-color);
}

.text-display-area span.incorrect {
    color: var(--incorrect-color);
    text-decoration: underline;
}

.text-display-area span.current {
    background-color: var(--primary-color);
    color: white;
    border-radius: 2px;
}

.text-input-area {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    z-index: 10;
    cursor: text;
    padding: 0;
    border: none;
}

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

.info-item {
    font-size: 1rem;
}

.info-item span {
    font-size: 2rem;
    font-weight: 600;
    color: var(--primary-color);
}

.retry-btn {
    font-family: var(--font-body);
    font-size: 1.1rem;
    font-weight: 600;
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0.8rem 2rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: background-color 0.3s, transform 0.2s;
}

.retry-btn:hover {
    background-color: #0056b3;
    transform: translateY(-2px);
}

/* Results Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal-content {
    background-color: var(--card-bg-color);
    padding: 2.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    text-align: left;
    width: 90%;
    max-width: 500px;
}

.modal-content h2 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--primary-color);
}

.modal-content p {
    font-size: 1.2rem;
    margin-bottom: 1rem;
}

.modal-content p span {
    font-weight: 600;
}

.high-score {
    margin-top: 1.5rem;
    text-align: center;
    font-size: 1.2rem;
    color: var(--correct-color);
}

.modal-content .retry-btn {
    display: block;
    width: 100%;
    margin-top: 2rem;
    text-align: center;
}

/* Responsive Design */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        align-items: center;
    }
    .title-container {
        text-align: center;
    }
    h1 {
        font-size: 1.5rem;
    }
    .container {
        padding: 1.5rem;
    }
    .text-display-area {
        font-size: 1.2rem;
        height: 180px;
    }
    .info-item span {
        font-size: 1.5rem;
    }
    .info-item p {
        font-size: 0.8rem;
    }
    .modal-content {
        padding: 2rem;
    }
    .modal-content p {
        font-size: 1rem;
    }
}