:root {
    --primary-color: #6366f1;
    /* Indigo-500 */
    --primary-hover: #4f46e5;
    --bg-color: #f3f4f6;
    /* Gray-100 */
    --text-main: #1f2937;
    /* Gray-800 */
    --text-sub: #6b7280;
    /* Gray-500 */
    --correct-color: #10b981;
    /* Soft Green */
    --incorrect-text: #ffffff;
    /* White text on error */
    --incorrect-bg: #ef4444;
    /* Dark Red */
    --card-bg: rgba(255, 255, 255, 0.8);
    --glass-border: 1px solid rgba(255, 255, 255, 0.5);
    --shadow-soft: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-hover: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background-color: var(--bg-color);
    color: var(--text-main);
    overflow-x: hidden;
}

/* Abstract Background Gradient */
.bg-gradient {
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at center, rgba(99, 102, 241, 0.1) 0%, rgba(243, 244, 246, 0) 60%);
    z-index: -10;
    pointer-events: none;
    animation: pulse 15s ease-in-out infinite alternate;
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }

    100% {
        transform: scale(1.1);
    }
}

.container {
    width: 100%;
    max-width: 1200px;
    padding: 2.5rem;
    position: relative;
    z-index: 1;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 3rem;
}

.logo-section {
    display: flex;
    flex-direction: column;
}

.logo {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -1.5px;
    line-height: 1;
}

.logo .highlight {
    color: var(--primary-color);
}

.tagline {
    font-size: 0.9rem;
    color: var(--text-sub);
    font-weight: 500;
    margin-top: 4px;
    letter-spacing: 0.5px;
}

.header-controls {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 1rem;
}

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

.sound-toggle-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-sub);
    transition: color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sound-toggle-btn:hover {
    color: var(--primary-color);
}

.sound-toggle-btn svg {
    width: 24px;
    height: 24px;
    stroke-width: 2px;
}

.timer-options {
    background: #e5e7eb;
    padding: 4px;
    border-radius: 9999px;
    display: flex;
    gap: 2px;
}

.timer-btn {
    border: none;
    background: transparent;
    padding: 6px 14px;
    border-radius: 9999px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-sub);
    transition: all 0.2s ease;
}

.timer-btn:hover {
    color: var(--text-main);
}

.timer-btn.active {
    background: #fff;
    color: var(--primary-color);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* Stats Cards */
.stats-container {
    display: flex;
    justify-content: space-between;
    gap: 1.5rem;
    margin-bottom: 4rem;
}

.stat-card {
    flex: 1;
    background: var(--card-bg);
    border: var(--glass-border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 1.25rem;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    box-shadow: var(--shadow-soft);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
}

.stat-card .label {
    font-size: 0.8rem;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: var(--text-sub);
    margin-bottom: 0.5rem;
}

.stat-card .value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-main);
    font-variant-numeric: tabular-nums;
}

/* Typing Area */
.typing-area-wrapper {
    position: relative;
    max-height: 300px;
    /* Approx 6 lines (3rem * 6 = 288px + padding) */
    height: 300px;
    margin-bottom: 3rem;
    outline: none;
    cursor: text;
    overflow: hidden;
    /* Hide extra text */
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.4);
    /* Subtle backing for focus area */
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    /* Center vertically if needed, but usually top alignment is better for text */
    align-items: flex-start;
}

.input-field {
    opacity: 0;
    position: absolute;
    z-index: -999;
}

.typing-text {
    font-family: 'JetBrains Mono', monospace;
    font-size: 2rem;
    line-height: 3rem;
    color: #9ca3af;
    user-select: none;
    transition: filter 0.2s;
    letter-spacing: 0.05em;
    width: 100%;
    height: 100%;
    overflow-y: hidden;
    /* Programmatic scrolling only */
    scroll-behavior: smooth;
    padding: 0 1rem;
    white-space: pre-wrap;
    /* Ensure wrapping */
    word-break: break-word;
}

/* Blur typing area slightly when not focused */
.typing-area-wrapper:not(:focus-within) .typing-text {
    filter: blur(4px);
    opacity: 0.5;
}

.typing-text span {
    position: relative;
    transition: color 0.15s ease, background-color 0.15s ease;
}

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

.typing-text span.incorrect {
    color: var(--incorrect-text);
    background-color: var(--incorrect-bg);
    border-radius: 4px;
}

/* Blinking Caret (Custom implementation) */
/* Requires JS helper or CSS targeting active span */
.typing-text span.active {
    color: var(--text-main);
}

.typing-text span.active::before {
    content: "";
    position: absolute;
    left: -2px;
    top: 10%;
    height: 80%;
    width: 3px;
    background: var(--primary-color);
    border-radius: 2px;
    animation: blinkCaret 1s infinite;
}

@keyframes blinkCaret {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

.footer-instructions {
    text-align: center;
    color: var(--text-sub);
    font-size: 0.9rem;
    margin-top: 2rem;
}

.motivation-text {
    font-size: 1.1rem;
    font-style: italic;
    color: var(--primary-color);
    margin-bottom: 1.5rem;
    font-weight: 500;
    line-height: 1.6;
}

.footer-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    opacity: 0.8;
}

.website-name {
    font-weight: 700;
    color: var(--text-main);
    font-size: 1rem;
}

.separator {
    color: var(--text-sub);
}

.support-email {
    font-size: 0.9rem;
}

.support-email a {
    color: var(--primary-color);
    text-decoration: none;
    transition: all 0.2s ease;
    font-weight: 600;
}

.support-email a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

.footer-instructions kbd {
    background: #e5e7eb;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    border-bottom: 2px solid #d1d5db;
}

/* Fullscreen Result Modal */
.result-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 1;
    visibility: visible;
    transition: all 0.4s ease;
}

.result-modal.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.result-content {
    background: white;
    padding: 4rem;
    border-radius: 32px;
    text-align: center;
    box-shadow: 0 35px 60px -15px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 600px;
    transform: scale(1);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.result-modal.hidden .result-content {
    transform: scale(0.8) translateY(50px);
}

.result-content h2 {
    font-size: 3rem;
    margin-bottom: 0.5rem;
    color: var(--text-main);
    font-weight: 800;
}

.tier-label {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 3rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.final-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3rem;
    margin-bottom: 4rem;
    text-align: left;
}

.final-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.final-stat p {
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-sub);
    margin-bottom: 0.5rem;
    font-weight: 700;
}

.final-stat span {
    font-size: 3.5rem;
    font-weight: 900;
    color: var(--text-main);
    line-height: 1;
}

.actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.retry-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    border: none;
    padding: 1.25rem 4rem;
    font-size: 1.25rem;
    font-weight: 700;
    border-radius: 16px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 10px 15px -3px rgba(99, 102, 241, 0.4);
}

.retry-btn:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 20px 25px -5px rgba(99, 102, 241, 0.5);
}

.retry-btn:active {
    transform: translateY(-1px);
}

@media (max-width: 768px) {
    .container {
        padding: 1.5rem;
    }

    .stats-container {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .stat-card {
        min-width: 45%;
    }

    .typing-text {
        font-size: 1.25rem;
        line-height: 2rem;
    }
}