/* ─── Reset & Variables ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:        #fafaf8;
    --bg2:       #f3f2ef;
    --bg3:       #eae9e4;
    --surface:   #ffffff;
    --border:    #e2e1db;
    --text:      #1a1916;
    --text2:     #6b6a65;
    --text3:     #a09f99;
    --accent:    #2563eb;
    --accent-h:  #1d4ed8;
    --accent-l:  #eff6ff;
    --green:     #16a34a;
    --red:       #dc2626;
    --yellow:    #ca8a04;
    --radius:    10px;
    --radius-lg: 16px;
    --shadow:    0 1px 3px rgba(0,0,0,.07), 0 4px 16px rgba(0,0,0,.04);
    --shadow-lg: 0 4px 24px rgba(0,0,0,.09), 0 1px 4px rgba(0,0,0,.06);
    --font-mono: 'DM Mono', 'Fira Mono', monospace;
    --font-sans: 'DM Sans', system-ui, sans-serif;
    --transition: 160ms cubic-bezier(.4,0,.2,1);
}

html { scroll-behavior: smooth; }

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ─── Navbar ────────────────────────────────────────────── */
.navbar {
    position: sticky; top: 0; z-index: 100;
    background: rgba(250,250,248,.9);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 2rem;
    padding: 0 2rem; height: 60px;
}

.navbar-brand {
    display: flex; align-items: center; gap: .5rem;
    text-decoration: none; color: var(--text);
    font-weight: 600; font-size: 1.1rem; white-space: nowrap;
}
.brand-icon { font-size: 1.3rem; }

.navbar-links {
    display: flex; align-items: center; gap: .25rem;
    flex: 1;
}

.nav-link {
    text-decoration: none; color: var(--text2);
    padding: .4rem .75rem; border-radius: 8px;
    font-size: .9rem; font-weight: 400;
    transition: all var(--transition);
}
.nav-link:hover, .nav-link.active {
    color: var(--text); background: var(--bg2);
}
.nav-link.active { font-weight: 500; }

.navbar-actions {
    display: flex; align-items: center; gap: .75rem; margin-left: auto;
}

.lang-toggle {
    background: none; border: 1px solid var(--border);
    border-radius: 8px; padding: .35rem .6rem;
    font-size: .8rem; cursor: pointer; color: var(--text2);
    transition: all var(--transition);
}
.lang-toggle:hover { border-color: var(--accent); color: var(--accent); }

.user-menu { position: relative; }
.user-btn {
    display: flex; align-items: center; gap: .5rem;
    background: none; border: 1px solid var(--border);
    border-radius: 8px; padding: .35rem .75rem;
    cursor: pointer; font-family: var(--font-sans);
    font-size: .9rem; color: var(--text);
    transition: all var(--transition);
}
.user-btn:hover { border-color: var(--accent); }
.user-avatar {
    width: 26px; height: 26px; background: var(--accent);
    border-radius: 50%; color: white;
    display: flex; align-items: center; justify-content: center;
    font-size: .75rem; font-weight: 600;
}
.chevron { font-size: .7rem; color: var(--text3); }
.user-dropdown {
    display: none; position: absolute; top: calc(100% + 8px); right: 0;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-lg);
    min-width: 140px; overflow: hidden;
}
.user-dropdown.open { display: block; }
.user-dropdown a {
    display: block; padding: .65rem 1rem;
    text-decoration: none; color: var(--text2);
    font-size: .9rem; transition: all var(--transition);
}
.user-dropdown a:hover { background: var(--bg2); color: var(--text); }

.mobile-menu-btn {
    display: none; background: none; border: none;
    font-size: 1.3rem; cursor: pointer; color: var(--text);
    margin-left: auto;
}

.mobile-menu {
    display: none; flex-direction: column;
    background: var(--surface); border-bottom: 1px solid var(--border);
    padding: 1rem 2rem;
}
.mobile-menu.open { display: flex; }
.mobile-menu a {
    padding: .65rem 0; text-decoration: none;
    color: var(--text2); border-bottom: 1px solid var(--border);
    font-size: .95rem;
}
.mobile-menu a:last-child { border-bottom: none; }

@media (max-width: 768px) {
    .navbar-links, .navbar-actions { display: none; }
    .mobile-menu-btn { display: block; }
}

/* ─── Buttons ───────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    padding: .55rem 1.25rem; border-radius: 8px;
    font-family: var(--font-sans); font-size: .9rem; font-weight: 500;
    text-decoration: none; cursor: pointer; border: none;
    transition: all var(--transition); white-space: nowrap;
}
.btn-primary {
    background: var(--accent); color: white;
}
.btn-primary:hover { background: var(--accent-h); transform: translateY(-1px); }
.btn-ghost {
    background: transparent; color: var(--text2);
    border: 1px solid var(--border);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-lg { padding: .75rem 1.75rem; font-size: 1rem; border-radius: var(--radius); }
.btn-xl { padding: .9rem 2.25rem; font-size: 1.05rem; border-radius: var(--radius); }
.btn-full { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ─── Hero ──────────────────────────────────────────────── */
.hero {
    padding: 7rem 2rem 5rem;
    text-align: center;
    max-width: 780px; margin: 0 auto;
}
.hero-badge {
    display: inline-flex; align-items: center; gap: .4rem;
    background: var(--accent-l); color: var(--accent);
    padding: .3rem .85rem; border-radius: 999px;
    font-size: .8rem; font-weight: 500; margin-bottom: 1.75rem;
    border: 1px solid #bfdbfe;
}
.hero h1 {
    font-size: clamp(2.4rem, 6vw, 4rem);
    font-weight: 600; line-height: 1.15; letter-spacing: -.03em;
    margin-bottom: 1.25rem; color: var(--text);
}
.hero h1 em {
    font-style: normal; color: var(--accent);
}
.hero p {
    font-size: 1.15rem; color: var(--text2);
    max-width: 520px; margin: 0 auto 2.5rem;
    line-height: 1.7;
}
.hero-actions {
    display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap;
}

/* ─── Stats Bar ─────────────────────────────────────────── */
.stats-bar {
    background: var(--surface); border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 1.75rem 2rem;
}
.stats-bar-inner {
    max-width: 900px; margin: 0 auto;
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem; text-align: center;
}
.stat-item-label {
    font-size: .82rem; color: var(--text3);
    text-transform: uppercase; letter-spacing: .07em; margin-bottom: .3rem;
}
.stat-item-value {
    font-size: 2rem; font-weight: 600; color: var(--text);
    font-family: var(--font-mono); letter-spacing: -.02em;
}

/* ─── Section ───────────────────────────────────────────── */
.section { padding: 5rem 2rem; }
.section-inner { max-width: 900px; margin: 0 auto; }
.section-title {
    font-size: 1.6rem; font-weight: 600;
    letter-spacing: -.025em; margin-bottom: .5rem;
}
.section-sub {
    color: var(--text2); margin-bottom: 2.5rem; font-size: .95rem;
}

/* ─── Cards ─────────────────────────────────────────────── */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 1.75rem;
    box-shadow: var(--shadow);
}
.card-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.25rem;
}
.feature-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 1.75rem;
    transition: all var(--transition);
}
.feature-card:hover {
    border-color: var(--accent); box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}
.feature-icon {
    font-size: 1.75rem; margin-bottom: 1rem;
}
.feature-title { font-weight: 600; margin-bottom: .4rem; }
.feature-desc { color: var(--text2); font-size: .9rem; line-height: 1.6; }

/* ─── Typing Test ───────────────────────────────────────── */
.test-container {
    max-width: 820px; margin: 0 auto; padding: 2rem;
}
.test-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1.5rem; flex-wrap: wrap; gap: 1rem;
}
.test-options {
    display: flex; gap: .5rem; flex-wrap: wrap;
}
.opt-btn {
    padding: .35rem .85rem; border-radius: 8px;
    border: 1px solid var(--border); background: none;
    font-family: var(--font-sans); font-size: .85rem;
    cursor: pointer; color: var(--text2); transition: all var(--transition);
}
.opt-btn:hover, .opt-btn.active {
    border-color: var(--accent); color: var(--accent);
    background: var(--accent-l);
}
.test-stats {
    display: flex; gap: 2rem;
}
.test-stat {
    text-align: center;
}
.test-stat-val {
    font-size: 1.5rem; font-weight: 600;
    font-family: var(--font-mono); color: var(--text);
    line-height: 1;
}
.test-stat-lbl {
    font-size: .72rem; color: var(--text3);
    text-transform: uppercase; letter-spacing: .06em;
}

.test-progress {
    height: 3px; background: var(--bg3);
    border-radius: 999px; margin-bottom: 1.5rem; overflow: hidden;
}
.test-progress-bar {
    height: 100%; background: var(--accent);
    border-radius: 999px; transition: width .3s ease;
    width: 0%;
}

.words-display {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 2rem;
    font-family: var(--font-mono); font-size: 1.15rem;
    line-height: 2; position: relative; min-height: 120px;
    overflow: hidden; cursor: text;
}
.words-display:focus-within { border-color: var(--accent); }

.word { display: inline-block; margin-right: .4em; position: relative; }
.word .char { display: inline-block; transition: color .05s; }
.char.correct { color: var(--green); }
.char.incorrect { color: var(--red); text-decoration: underline wavy var(--red); }
.char.current {
    background: var(--accent); color: white;
    border-radius: 2px;
}
.word.current-word { }

#typingInput {
    position: absolute; opacity: 0; width: 1px; height: 1px;
    pointer-events: none;
}

.test-footer {
    display: flex; justify-content: space-between; align-items: center;
    margin-top: 1.25rem; flex-wrap: wrap; gap: 1rem;
}

/* ─── Result Card ───────────────────────────────────────── */
.result-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 2.5rem;
    text-align: center; max-width: 520px; margin: 0 auto;
}
.result-wpm {
    font-size: 5rem; font-weight: 700;
    font-family: var(--font-mono); color: var(--accent);
    line-height: 1; letter-spacing: -.04em;
}
.result-wpm-lbl { color: var(--text3); font-size: .85rem; letter-spacing: .1em; text-transform: uppercase; margin-bottom: 2rem; }
.result-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem;
    margin: 2rem 0;
}
.result-stat { }
.result-stat-val { font-size: 1.4rem; font-weight: 600; font-family: var(--font-mono); }
.result-stat-lbl { font-size: .75rem; color: var(--text3); text-transform: uppercase; letter-spacing: .06em; }

/* ─── Leaderboard ───────────────────────────────────────── */
.lb-table {
    width: 100%; border-collapse: collapse;
}
.lb-table th {
    text-align: left; padding: .75rem 1rem;
    font-size: .78rem; text-transform: uppercase;
    letter-spacing: .07em; color: var(--text3);
    border-bottom: 1px solid var(--border);
    font-weight: 500;
}
.lb-table td {
    padding: .9rem 1rem; border-bottom: 1px solid var(--bg2);
    font-size: .92rem;
}
.lb-table tr:last-child td { border-bottom: none; }
.lb-table tr:hover td { background: var(--bg); }
.lb-rank {
    font-family: var(--font-mono); font-weight: 600;
    color: var(--text3); width: 40px;
}
.lb-rank.gold { color: #ca8a04; }
.lb-rank.silver { color: #9ca3af; }
.lb-rank.bronze { color: #b45309; }
.lb-wpm { font-family: var(--font-mono); font-weight: 600; color: var(--accent); }
.lb-username { font-weight: 500; }
.lb-acc { color: var(--green); font-family: var(--font-mono); }

/* ─── Auth Forms ────────────────────────────────────────── */
.auth-page {
    min-height: calc(100vh - 60px);
    display: flex; align-items: center; justify-content: center;
    padding: 2rem;
}
.auth-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 2.5rem;
    width: 100%; max-width: 420px;
    box-shadow: var(--shadow-lg);
}
.auth-title {
    font-size: 1.5rem; font-weight: 600;
    letter-spacing: -.025em; margin-bottom: .35rem;
}
.auth-sub {
    color: var(--text2); font-size: .9rem; margin-bottom: 2rem;
}

.form-group { margin-bottom: 1.1rem; }
.form-label {
    display: block; font-size: .85rem; font-weight: 500;
    margin-bottom: .4rem; color: var(--text2);
}
.form-input {
    width: 100%; padding: .65rem .9rem;
    border: 1px solid var(--border); border-radius: 8px;
    font-family: var(--font-sans); font-size: .95rem;
    color: var(--text); background: var(--surface);
    transition: border-color var(--transition);
    outline: none;
}
.form-input:focus { border-color: var(--accent); }
.form-input.error { border-color: var(--red); }

.form-error {
    color: var(--red); font-size: .82rem; margin-top: .35rem;
    display: none;
}
.form-error.show { display: block; }

.alert {
    padding: .8rem 1rem; border-radius: 8px;
    font-size: .88rem; margin-bottom: 1.25rem;
}
.alert-error { background: #fef2f2; color: var(--red); border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: var(--green); border: 1px solid #bbf7d0; }

.auth-footer {
    text-align: center; margin-top: 1.5rem;
    font-size: .88rem; color: var(--text2);
}
.auth-footer a { color: var(--accent); text-decoration: none; font-weight: 500; }

/* ─── Blog ──────────────────────────────────────────────── */
.blog-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}
.blog-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); overflow: hidden;
    transition: all var(--transition); text-decoration: none; color: inherit;
    display: block;
}
.blog-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.blog-card-body { padding: 1.5rem; }
.blog-tag {
    display: inline-block; background: var(--accent-l); color: var(--accent);
    padding: .2rem .6rem; border-radius: 999px; font-size: .75rem;
    font-weight: 500; margin-bottom: .75rem;
}
.blog-card-title { font-size: 1rem; font-weight: 600; margin-bottom: .5rem; line-height: 1.4; }
.blog-card-excerpt { color: var(--text2); font-size: .87rem; line-height: 1.6; }
.blog-card-meta {
    padding: 1rem 1.5rem; border-top: 1px solid var(--bg2);
    font-size: .78rem; color: var(--text3);
    display: flex; gap: 1rem;
}

/* ─── Loading ───────────────────────────────────────────── */
.spinner {
    width: 24px; height: 24px; border: 2px solid var(--bg3);
    border-top-color: var(--accent); border-radius: 50%;
    animation: spin .6s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
    background: linear-gradient(90deg, var(--bg2) 25%, var(--bg3) 50%, var(--bg2) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: 6px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ─── Footer ────────────────────────────────────────────── */
.footer {
    border-top: 1px solid var(--border);
    padding: 2rem;
    margin-top: auto;
}
.footer-inner {
    max-width: 900px; margin: 0 auto;
    display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap; gap: 1.5rem;
}
.footer-brand { display: flex; align-items: center; gap: .5rem; }
.footer-tagline { color: var(--text3); font-size: .82rem; margin-left: .25rem; }
.footer-links { display: flex; gap: 1.5rem; }
.footer-links a { color: var(--text2); text-decoration: none; font-size: .88rem; transition: color var(--transition); }
.footer-links a:hover { color: var(--accent); }
.footer-bottom {
    max-width: 900px; margin: 1.25rem auto 0;
    padding-top: 1.25rem; border-top: 1px solid var(--border);
    font-size: .8rem; color: var(--text3);
}

/* ─── Utility ───────────────────────────────────────────── */
.container { max-width: 900px; margin: 0 auto; padding: 0 2rem; }
.text-center { text-align: center; }
.text-muted { color: var(--text2); }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.gap-1 { gap: .5rem; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }
