:root {
    /* Color Palette */
    --bg-color: #f4f7f6;
    --card-bg: #ffffff;
    --text-primary: #2d3748;
    --text-secondary: #718096;
    --accent: #4a90e2; /* Vibrant Blue */
    --success: #48bb78; /* Green */
    --error: #e53e3e;   /* Red */
    --untyped: #a0aec0; /* Dark Gray */
    --cursor: #333;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 32px;
    --space-xl: 64px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
}

.app-container {
    max-width: 800px;
    margin: 0 auto;
    padding: var(--space-lg) var(--space-md);
    min-height: 100%;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: var(--space-lg);
    border-bottom: 1px solid #e2e8f0;
    margin-bottom: var(--space-lg);
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.icon {
    width: 32px;
    height: 32px;
    color: var(--accent);
}

/* Loading State */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: var(--space-md);
}

@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Test Area */
.test-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-lg);
    flex: 1;
}

.quote-display {
    font-size: clamp(1.2rem, 2.5vw, 1.8rem);
    line-height: 1.5;
    letter-spacing: 0.5px;
    text-align: center;
    max-width: 700px;
    width: 100%;
    min-height: 80px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 2px;
    position: relative;
}

.char-span {
    display: inline-block;
    padding: 2px 4px;
    border-radius: 4px;
    transition: all 0.15s ease;
    position: relative;
}

.char-span.correct {
    color: var(--success);
    background-color: rgba(72, 187, 120, 0.1);
}

.char-span.incorrect {
    color: var(--error);
    background-color: rgba(229, 62, 62, 0.1);
    text-decoration: line-through;
}

.char-span.untyped {
    color: var(--untyped);
}

.char-span.active {
    background-color: rgba(74, 144, 226, 0.2);
    outline: 2px solid var(--accent);
}

.cursor-line {
    width: 2px;
    height: 1.2em;
    background-color: var(--cursor);
    animation: blink 1s infinite;
    position: absolute;
    pointer-events: none;
    opacity: 0; /* Hidden until typing starts */
}

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

/* HUD */
.hud {
    display: flex;
    justify-content: space-around;
    width: 100%;
    max-width: 500px;
    padding: var(--space-md);
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border: 1px solid #e2e8f0;
}

.hud-item {
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.value {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--text-primary);
}

/* Results */
.results-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-lg);
    padding: var(--space-lg);
    text-align: center;
}

.charts-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-lg);
    width: 100%;
    max-width: 700px;
}

.chart-wrapper {
    background: var(--card-bg);
    border-radius: 8px;
    padding: var(--space-sm);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    border: 1px solid #e2e8f0;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Buttons */
.btn-primary {
    padding: var(--space-sm) var(--space-md);
    background-color: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.btn-primary:hover {
    background-color: #357abd;
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

/* Utilities */
.hidden {
    display: none !important;
}

/* Responsive Design */
@media (max-width: 600px) {
    .app-header h1 {
        font-size: 1.2rem;
    }

    .hud {
        flex-direction: column;
        gap: var(--space-md);
    }

    .charts-container {
        grid-template-columns: 1fr;
    }
}
