:root {
    --bg-deep: #0a0e17;
    --bg-mid: #111827;
    --glass-bg: rgba(255, 255, 255, 0.06);
    --glass-border: rgba(255, 255, 255, 0.12);
    --glass-highlight: rgba(255, 255, 255, 0.18);
    --text-primary: #f1f5f9;
    --text-muted: #94a3b8;
    --accent: #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.45);
    --success: #34d399;
    --error: #f87171;
    --warning: #fbbf24;
    --radius: 16px;
    --radius-sm: 10px;
    --font-sans: 'DM Sans', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'Consolas', monospace;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font-sans);
    color: var(--text-primary);
    background: var(--bg-deep);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Background */
.app-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    background: linear-gradient(145deg, var(--bg-deep) 0%, #0f172a 40%, #1e1b4b 100%);
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.5;
    animation: float 12s ease-in-out infinite;
}

.orb-1 {
    width: 420px;
    height: 420px;
    background: #4f46e5;
    top: -10%;
    left: -5%;
}

.orb-2 {
    width: 350px;
    height: 350px;
    background: #7c3aed;
    bottom: 10%;
    right: -5%;
    animation-delay: -4s;
}

.orb-3 {
    width: 280px;
    height: 280px;
    background: #2563eb;
    top: 50%;
    left: 40%;
    animation-delay: -8s;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(30px, -20px) scale(1.05); }
    66% { transform: translate(-20px, 15px) scale(0.95); }
}

/* Layout */
.typing-app {
    position: relative;
    z-index: 1;
    max-width: 900px;
    margin: 0 auto;
    padding: 1.5rem 1rem 2.5rem;
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
}

/* Header */
.typing-tool-header {
    text-align: center;
    padding: 1.75rem 1.5rem 1.25rem;
    margin-bottom: 1rem;
    animation: fadeUp 0.6s ease both;
}

.tool-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
}

.brand-icon {
    font-size: 1.75rem;
    line-height: 1;
}

.brand-title {
    margin: 0;
    font-size: clamp(1.35rem, 4vw, 1.75rem);
    font-weight: 700;
    letter-spacing: -0.02em;
}

.tool-subtitle {
    margin: 0.5rem 0 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Setup */
.setup-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem;
    justify-content: center;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
    animation: fadeUp 0.6s ease 0.1s both;
}

.config-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.config-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.config-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    justify-content: center;
}

.btn-config {
    padding: 0.45rem 0.9rem;
    font-size: 0.85rem;
    font-weight: 500;
    font-family: var(--font-sans);
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.btn-config .unit {
    font-size: 0.75em;
    opacity: 0.8;
}

.btn-config:hover:not(:disabled) {
    color: var(--text-primary);
    border-color: var(--glass-highlight);
    background: rgba(255, 255, 255, 0.08);
}

.btn-config.active {
    color: #fff;
    background: linear-gradient(135deg, var(--accent), #818cf8);
    border-color: transparent;
    box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-config:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.config-group-wide {
    width: 100%;
    max-width: 100%;
}

.config-hint {
    margin: 0;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.custom-input-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.35rem;
}

.custom-number-input {
    width: 5.5rem;
    padding: 0.45rem 0.65rem;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    outline: none;
    transition: var(--transition);
}

.custom-number-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.input-suffix {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.setup-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.25rem;
}

.btn-start {
    min-width: 180px;
    justify-content: center;
    font-size: 1rem;
    padding: 0.75rem 1.5rem;
}

.setup-error {
    margin: 0;
    font-size: 0.85rem;
    color: var(--error);
}

.paragraph-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    text-align: center;
}

/* Stats */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.5rem;
    padding: 1rem;
    margin-bottom: 0.75rem;
    animation: fadeUp 0.6s ease 0.15s both;
}

.stat-item {
    text-align: center;
}

.stat-value {
    display: block;
    font-family: var(--font-mono);
    font-size: clamp(1.1rem, 3vw, 1.5rem);
    font-weight: 600;
    line-height: 1.2;
}

.stat-value.stat-errors {
    color: var(--error);
}

.stat-timer .stat-value {
    color: var(--accent);
}

.stat-label {
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

/* Progress */
.progress-wrapper {
    height: 6px;
    padding: 0;
    overflow: hidden;
    margin-bottom: 1rem;
    border-radius: 99px;
    animation: fadeUp 0.6s ease 0.2s both;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), #a78bfa);
    border-radius: 99px;
    transition: width 0.3s linear;
    box-shadow: 0 0 12px var(--accent-glow);
}

/* Typing panel */
.typing-panel {
    padding: 1.5rem;
    margin-bottom: 1rem;
    animation: fadeUp 0.6s ease 0.25s both;
    position: relative;
}

.paragraph-display {
    font-family: var(--font-mono);
    font-size: clamp(1rem, 2.5vw, 1.15rem);
    line-height: 1.85;
    letter-spacing: 0.02em;
    margin-bottom: 1rem;
    min-height: 5.5em;
    word-break: break-word;
    user-select: none;
}

.paragraph-display .char {
    position: relative;
    transition: color 0.1s ease;
}

.paragraph-display .char.correct {
    color: var(--success);
}

.paragraph-display .char.incorrect {
    color: var(--error);
    background: rgba(248, 113, 113, 0.15);
    border-radius: 2px;
}

.paragraph-display .char.current {
    background: rgba(99, 102, 241, 0.25);
    border-radius: 2px;
    animation: blink 1s step-end infinite;
}

.paragraph-display .char.pending {
    color: var(--text-muted);
}

@keyframes blink {
    50% { background: rgba(99, 102, 241, 0.45); }
}

.typing-input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
    opacity: 0;
}

.typing-panel:focus-within {
    border-color: rgba(99, 102, 241, 0.4);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15), 0 8px 32px rgba(0, 0, 0, 0.25);
}

.typing-panel {
    cursor: text;
}

.typing-hint {
    margin: 0;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
}

/* Results */
.results-panel {
    padding: 2rem 1.5rem;
    text-align: center;
    animation: fadeUp 0.5s ease both;
}

.results-panel.hidden {
    display: none;
}

.results-title {
    margin: 0 0 0.25rem;
    font-size: 1.75rem;
    font-weight: 700;
}

.results-subtitle {
    margin: 0 0 1.5rem;
    color: var(--text-muted);
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.result-card {
    padding: 1rem 0.75rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
}

.result-card.highlight {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(129, 140, 248, 0.1));
    border-color: rgba(99, 102, 241, 0.35);
}

.result-value {
    display: block;
    font-family: var(--font-mono);
    font-size: 1.5rem;
    font-weight: 600;
}

.result-card.highlight .result-value {
    font-size: 2rem;
    color: #a5b4fc;
}

.result-label {
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.results-meta {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.results-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    justify-content: center;
}

.btn-action {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.65rem 1.25rem;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.btn-action:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--glass-highlight);
    transform: translateY(-1px);
}

.btn-primary-action {
    background: linear-gradient(135deg, var(--accent), #818cf8);
    border-color: transparent;
    color: #fff;
}

.btn-primary-action:hover {
    box-shadow: 0 6px 20px var(--accent-glow);
    background: linear-gradient(135deg, #5558e3, #9098fa);
}

.copy-toast {
    margin: 1rem 0 0;
    font-size: 0.85rem;
    color: var(--success);
    animation: fadeUp 0.3s ease;
}

.copy-toast.hidden {
    display: none;
}

/* States */
.typing-app.test-active .setup-panel .btn-config {
    pointer-events: none;
}

.typing-app.test-finished .typing-panel,
.typing-app.test-finished .stats-bar,
.typing-app.test-finished .progress-wrapper {
    display: none;
}

.hidden {
    display: none !important;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Error page */
.error-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: var(--bg-deep);
}

.error-panel {
    padding: 2rem;
    text-align: center;
    max-width: 400px;
}

.error-panel h1 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.error-panel p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive */
@media (max-width: 768px) {
    .stats-bar {
        grid-template-columns: repeat(3, 1fr);
    }

    .stat-timer {
        grid-column: span 3;
    }

    .results-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .result-card.highlight {
        grid-column: span 2;
    }
}

@media (max-width: 480px) {
    .typing-app {
        padding: 1rem 0.75rem 2rem;
    }

    .setup-panel {
        flex-direction: column;
    }

    .stats-bar {
        grid-template-columns: repeat(2, 1fr);
    }

    .stat-timer {
        grid-column: span 2;
    }

    .results-grid {
        grid-template-columns: 1fr;
    }

    .result-card.highlight {
        grid-column: span 1;
    }

    .results-actions {
        flex-direction: column;
    }

    .btn-action {
        width: 100%;
        justify-content: center;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* Toolistify visual integration */
:root {
    --bg-deep: #f7fbff;
    --bg-mid: #eef8ff;
    --glass-bg: rgba(255, 255, 255, 0.94);
    --glass-border: rgba(0, 164, 255, 0.16);
    --glass-highlight: rgba(0, 164, 255, 0.35);
    --text-primary: #172033;
    --text-muted: #667085;
    --accent: #00a4ff;
    --accent-glow: rgba(0, 164, 255, 0.22);
    --success: #16a66a;
    --radius: 24px;
}

body {
    background: #f7fbff;
}

.app-bg {
    position: fixed;
    top: 69px;
    background: linear-gradient(145deg, #f7fbff 0%, #edf8ff 48%, #fbffe9 100%);
}

.orb {
    opacity: 0.18;
}

.orb-1,
.orb-3 {
    background: #00a4ff;
}

.orb-2 {
    background: #c7f408;
}

.glass-panel {
    border-radius: 24px;
    box-shadow: 0 8px 28px rgba(0, 164, 255, 0.1);
}

.typing-tool-header {
    background: linear-gradient(135deg, #ffffff 0%, #f1faff 100%);
}

.brand-icon {
    color: #00a4ff;
}

.btn-config,
.btn-action,
.result-card {
    color: #526075;
    background: #f8fbfd;
}

.btn-config:hover:not(:disabled),
.btn-action:hover {
    color: #172033;
    background: #eef8ff;
}

.btn-config.active,
.btn-primary-action,
.progress-fill {
    background: linear-gradient(135deg, #00a4ff, #28b5ff);
    color: #fff;
}

.custom-number-input {
    color: #172033;
    background: #fff;
}

.result-card.highlight {
    background: linear-gradient(135deg, rgba(0, 164, 255, 0.14), rgba(199, 244, 8, 0.1));
    border-color: rgba(0, 164, 255, 0.3);
}

.result-card.highlight .result-value {
    color: #008bd8;
}

body.toolistfy-embed .tool-header {
    display: none;
}

body.toolistfy-embed .typing-app {
    padding-top: 1rem;
}

body.toolistfy-embed .app-bg {
    top: 0;
}
