﻿@font-face {
    font-family: 'Sora';
    src: local('Sora');
}

:root {
    --primary: #1E73BE;
    --secondary: #0A2540;
    --accent: #00C2FF;
    --bg: #F4F7FB;
    --success: #1FAA59;
    --warning: #F5A623;
    --error: #E5484D;
    --surface: #FFFFFF;
    --surface-2: #EDF1F7;
    --border: rgba(10,37,64,0.10);
    --text: #0A2540;
    --text-dim: #5C7089;
    --text-faint: #9AACC0;
    --caret: #00C2FF;
    --shadow: 0 10px 30px -12px rgba(10,37,64,0.18);
    --shadow-sm: 0 4px 14px -6px rgba(10,37,64,0.15);
    --radius: 18px;
    --radius-sm: 12px;
    --font-display: 'Sora',system-ui,sans-serif;
    --font-body: 'Inter',system-ui,sans-serif;
    --font-mono: 'JetBrains Mono','Fira Code',monospace;
    --dur: 220ms;
}

[data-theme="dark"] {
    --bg: #0A0F1A;
    --surface: #101827;
    --surface-2: #161F30;
    --border: rgba(255,255,255,0.08);
    --text: #E8EEF7;
    --text-dim: #8DA0BC;
    --text-faint: #556479;
    --shadow: 0 10px 34px -12px rgba(0,0,0,0.55);
    --shadow-sm: 0 4px 16px -6px rgba(0,0,0,0.45);
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.001ms !important;
        transition-duration: 0.001ms !important;
    }
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    background: radial-gradient(1200px 600px at 15% -10%, rgba(0,194,255,0.08), transparent 60%), radial-gradient(1000px 500px at 100% 0%, rgba(30,115,190,0.10), transparent 55%), var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
    transition: background var(--dur) ease, color var(--dur) ease;
    min-height: 100vh;
}

a {
    color: inherit;
}

button {
    font-family: inherit;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 6px;
}

/* Skip link */
.skip-link {
    position: absolute;
    left: -999px;
    top: 0;
    background: var(--accent);
    color: #012;
    padding: 10px 16px;
    border-radius: 8px;
    z-index: 999;
}

    .skip-link:focus {
        left: 12px;
        top: 12px;
    }

/* ---------- Layout shell ---------- */
.app {
    max-width: 1180px;
    margin: 0 auto;
    padding: 20px 20px 60px;
}

/* ---------- Header ---------- */
header.top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px 18px;
    margin-bottom: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-display);
    font-weight: 700;
}

.brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    flex: none;
    background: conic-gradient(from 200deg, var(--accent), var(--primary), var(--secondary), var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 16px;
    box-shadow: 0 4px 14px -3px rgba(0,194,255,0.5);
}

.brand-name {
    font-size: 18px;
    letter-spacing: 0.2px;
}

.brand-tag {
    display: block;
    font-family: var(--font-body);
    font-weight: 500;
    font-size: 11px;
    color: var(--text-dim);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.top-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--dur) ease, background var(--dur) ease, box-shadow var(--dur) ease;
    font-size: 16px;
}

    .icon-btn:hover {
        transform: translateY(-2px);
        box-shadow: var(--shadow-sm);
    }

    .icon-btn:active {
        transform: translateY(0);
    }

select.pill, .pill-btn {
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--dur) ease;
    appearance: none;
}

    select.pill:hover, .pill-btn:hover {
        border-color: var(--primary);
        color: var(--primary);
    }

.timer-chip {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 15px;
    padding: 8px 14px;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff;
    min-width: 52px;
    text-align: center;
}

/* ---------- Mode bar ---------- */
.mode-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 6px 0 24px;
}

.seg {
    display: flex;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px;
    box-shadow: var(--shadow-sm);
}

    .seg button {
        border: none;
        background: transparent;
        color: var(--text-dim);
        font-weight: 600;
        font-size: 13px;
        padding: 8px 16px;
        border-radius: 999px;
        cursor: pointer;
        transition: all var(--dur) ease;
    }

        .seg button.active {
            background: var(--primary);
            color: #fff;
            box-shadow: 0 4px 12px -3px rgba(30,115,190,0.55);
        }

.sub-options {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

    .sub-options button {
        border: 1px solid var(--border);
        background: var(--surface);
        color: var(--text-dim);
        padding: 7px 13px;
        border-radius: 10px;
        font-size: 12.5px;
        font-weight: 600;
        cursor: pointer;
        transition: all var(--dur) ease;
    }

        .sub-options button.active {
            border-color: var(--accent);
            color: var(--primary);
            background: rgba(0,194,255,0.08);
        }

.custom-input {
    width: 64px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    padding: 6px 8px;
    font-size: 12.5px;
    text-align: center;
}

/* ---------- Stats strip (live) ---------- */
.live-stats {
    display: flex;
    justify-content: center;
    gap: 28px;
    flex-wrap: wrap;
    margin-bottom: 18px;
    font-family: var(--font-mono);
}

    .live-stats .stat {
        text-align: center;
    }

        .live-stats .stat .val {
            font-size: 22px;
            font-weight: 700;
            color: var(--primary);
        }

        .live-stats .stat .lab {
            font-size: 10.5px;
            text-transform: uppercase;
            letter-spacing: 1px;
            color: var(--text-faint);
        }

.progress-track {
    height: 6px;
    border-radius: 6px;
    background: var(--surface-2);
    overflow: hidden;
    margin-bottom: 22px;
    border: 1px solid var(--border);
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--primary));
    transition: width 120ms linear;
}

/* ---------- Typing card ---------- */
.type-card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 34px clamp(18px,4vw,46px);
    margin-bottom: 22px;
    overflow: hidden;
}

    .type-card::before {
        content: "";
        position: absolute;
        inset: 0;
        pointer-events: none;
        opacity: 0.5;
        background: radial-gradient(600px 220px at 50% 0%, rgba(0,194,255,0.06), transparent 70%);
    }

.zen-hint {
    position: absolute;
    top: 14px;
    right: 18px;
    font-size: 11px;
    color: var(--text-faint);
    font-family: var(--font-mono);
}

#text-display {
    font-family: var(--font-mono);
    font-size: var(--type-size,26px);
    line-height: 1.75;
    letter-spacing: 0.2px;
    color: var(--text-faint);
    user-select: none;
    position: relative;
    z-index: 1;
    word-wrap: break-word;
    filter: blur(0px);
    transition: filter var(--dur) ease;
}

body.blurred #text-display {
    filter: blur(5px);
}

#text-display .word {
    display: inline-block;
    margin: 2px 6px 2px 0;
    position: relative;
}

    #text-display .word.current-word {
    }

#text-display .char {
    position: relative;
    transition: color 80ms ease;
}

    #text-display .char.correct {
        color: var(--success);
    }

    #text-display .char.incorrect {
        color: var(--error);
        text-decoration: underline;
        text-decoration-color: var(--error);
    }

    #text-display .char.current {
        color: var(--text);
    }

        #text-display .char.current::before {
            content: "";
            position: absolute;
            left: -1px;
            top: -2px;
            bottom: -2px;
            width: 2px;
            background: var(--caret);
            animation: blink 1s steps(1) infinite;
            box-shadow: 0 0 8px var(--accent);
        }

@keyframes blink {
    0%,55% {
        opacity: 1;
    }

    56%,100% {
        opacity: 0;
    }
}

#type-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.type-card.locked #text-display {
    opacity: 0.4;
}

.start-hint {
    text-align: center;
    color: var(--text-dim);
    font-size: 14px;
    margin-top: 14px;
    position: relative;
    z-index: 1;
}

kbd {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1px 7px;
    font-family: var(--font-mono);
    font-size: 12px;
}

/* ---------- Action row ---------- */
.action-row {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 26px;
    flex-wrap: wrap;
}

.btn {
    border: none;
    cursor: pointer;
    padding: 11px 22px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 14px;
    transition: transform var(--dur) ease, box-shadow var(--dur) ease, opacity var(--dur) ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

    .btn:hover {
        transform: translateY(-2px);
    }

.btn-primary {
    background: linear-gradient(135deg,var(--primary),var(--secondary));
    color: #fff;
    box-shadow: 0 8px 20px -8px rgba(30,115,190,0.6);
}

.btn-ghost {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-accent {
    background: var(--accent);
    color: #012437;
    box-shadow: 0 8px 20px -8px rgba(0,194,255,0.6);
}

/* ---------- Virtual keyboard ---------- */
.vkb {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
    margin-bottom: 26px;
}

.vkb-row {
    display: flex;
    gap: 6px;
}

.vkey {
    min-width: 34px;
    height: 38px;
    border-radius: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    transition: all 90ms ease;
}

    .vkey.wide {
        min-width: 64px;
    }

    .vkey.space {
        min-width: 220px;
    }

    .vkey.active {
        background: var(--primary);
        color: #fff;
        transform: translateY(1px);
        box-shadow: 0 0 0 2px rgba(0,194,255,0.4);
    }

    .vkey.wrong {
        background: var(--error);
        color: #fff;
    }

/* ---------- Cards grid (results / leaderboard / achievements) ---------- */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit,minmax(230px,1fr));
    gap: 16px;
    margin-bottom: 22px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 18px;
    box-shadow: var(--shadow-sm);
}

    .card h3 {
        margin: 0 0 10px;
        font-family: var(--font-display);
        font-size: 15px;
    }

/* ---------- Results overlay ---------- */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(5,12,24,0.6);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur) ease;
}

    .overlay.show {
        opacity: 1;
        pointer-events: auto;
    }

.result-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow);
    max-width: 640px;
    width: 100%;
    padding: 30px;
    max-height: 90vh;
    overflow: auto;
    transform: translateY(14px) scale(0.98);
    transition: transform var(--dur) ease;
}

.overlay.show .result-panel {
    transform: translateY(0) scale(1);
}

.result-head {
    text-align: center;
    margin-bottom: 18px;
}

    .result-head .grade {
        font-family: var(--font-display);
        font-size: 48px;
        font-weight: 800;
        background: linear-gradient(135deg,var(--accent),var(--primary));
        -webkit-background-clip: text;
        background-clip: text;
        color: transparent;
    }

.stars {
    font-size: 22px;
    color: var(--warning);
    letter-spacing: 3px;
}

.gauge-wrap {
    display: flex;
    justify-content: center;
    margin: 6px 0 18px;
}

.result-grid {
    display: grid;
    grid-template-columns: repeat(3,1fr);
    gap: 10px;
    margin-bottom: 18px;
}

    .result-grid .box {
        background: var(--surface-2);
        border-radius: 12px;
        padding: 12px;
        text-align: center;
    }

        .result-grid .box .v {
            font-family: var(--font-mono);
            font-size: 20px;
            font-weight: 700;
            color: var(--primary);
        }

        .result-grid .box .l {
            font-size: 10.5px;
            text-transform: uppercase;
            color: var(--text-faint);
            letter-spacing: 0.6px;
        }

/* ---------- Settings panel ---------- */
.drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: 340px;
    max-width: 92vw;
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: -16px 0 40px -18px rgba(0,0,0,0.35);
    z-index: 210;
    transform: translateX(100%);
    transition: transform var(--dur) ease;
    padding: 22px;
    overflow-y: auto;
}

    .drawer.show {
        transform: translateX(0);
    }

    .drawer h2 {
        font-family: var(--font-display);
        font-size: 18px;
        margin-top: 0;
    }

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    gap: 10px;
}

.switch {
    position: relative;
    width: 42px;
    height: 24px;
    flex: none;
}

    .switch input {
        opacity: 0;
        width: 0;
        height: 0;
    }

.slider-tog {
    position: absolute;
    inset: 0;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    transition: all var(--dur) ease;
}

    .slider-tog::before {
        content: "";
        position: absolute;
        height: 18px;
        width: 18px;
        left: 2px;
        top: 2px;
        background: #fff;
        border-radius: 50%;
        transition: all var(--dur) ease;
        box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    }

.switch input:checked + .slider-tog {
    background: var(--primary);
}

    .switch input:checked + .slider-tog::before {
        transform: translateX(18px);
    }

.range {
    width: 100%;
}

.scrim {
    position: fixed;
    inset: 0;
    background: rgba(5,12,24,0.5);
    z-index: 205;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur) ease;
}

    .scrim.show {
        opacity: 1;
        pointer-events: auto;
    }

/* footer / sections */
section.panel {
    margin-bottom: 26px;
}

    section.panel h2 {
        font-family: var(--font-display);
        font-size: 17px;
        margin: 0 0 12px;
        display: flex;
        align-items: center;
        gap: 8px;
    }

table.lb {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

    table.lb th {
        text-align: left;
        color: var(--text-faint);
        font-weight: 600;
        text-transform: uppercase;
        font-size: 10.5px;
        padding: 6px 8px;
        border-bottom: 1px solid var(--border);
    }

    table.lb td {
        padding: 8px;
        border-bottom: 1px solid var(--border);
        font-family: var(--font-mono);
    }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    background: var(--surface-2);
    color: var(--primary);
}

.xp-bar-track {
    height: 10px;
    border-radius: 6px;
    background: var(--surface-2);
    overflow: hidden;
    border: 1px solid var(--border);
}

.xp-bar-fill {
    height: 100%;
    background: linear-gradient(90deg,var(--success),var(--accent));
    transition: width 300ms ease;
}

footer {
    text-align: center;
    color: var(--text-faint);
    font-size: 12px;
    padding: 20px 0 6px;
}

canvas#confetti-canvas {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 300;
}

@media (max-width:640px) {
    #text-display {
        font-size: 20px;
        line-height: 1.9;
    }

    .result-grid {
        grid-template-columns: repeat(2,1fr);
    }

    .vkey {
        min-width: 24px;
        height: 32px;
        font-size: 10px;
    }

        .vkey.space {
            min-width: 120px;
        }
}
