/* ============================================================
   style.css — TypeDrill Typing Tutor
   Aesthetic: Retro terminal / phosphor green on dark
   ============================================================ */

/* ── Custom Properties ─────────────────────────────────────── */
:root {
    /* Light theme is now the default */
    --bg:          #f5f5f0;
    --bg-panel:    #ffffff;
    --bg-arena:    #fafaf7;
    --border:      #d8d8ce;
    --phosphor:    #1a6b3a;
    --phosphor-dim:#2d8a52;
    --amber:       #c0550a;
    --red:         #d63030;
    --white:       #1a1a16;
    --muted:       #7a7a6a;
    --font-mono:   'JetBrains Mono', 'Courier New', monospace;
    --font-display:'Orbitron', monospace;
    --glow:        0 0 6px rgba(26,107,58,0.25);
    --glow-lg:     0 0 16px rgba(26,107,58,0.15);
    --radius:      4px;
    --transition:  0.15s ease;
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
    background: var(--bg);
    color: var(--white);
    font-family: var(--font-mono);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    /* subtle scanline texture */
    background-image: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0,0,0,0.03) 2px,
        rgba(0,0,0,0.03) 4px
    );
}

/* ── Header ────────────────────────────────────────────────── */
.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 32px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-panel);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    color: var(--phosphor);
    font-size: 1.1rem;
    animation: blink-cursor 1.2s step-end infinite;
}

.brand-name {
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--phosphor);
    letter-spacing: 0.08em;
    text-shadow: var(--glow);
}

.header-meta {
    font-size: 0.75rem;
    color: var(--muted);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* ── Main Container ────────────────────────────────────────── */
.app-container {
    flex: 1;
    max-width: 860px;
    width: 100%;
    margin: 0 auto;
    padding: 32px 24px 16px;
    position: relative;
}

/* ── Lesson Info ────────────────────────────────────────────── */
.lesson-info {
    margin-bottom: 20px;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

.lesson-info h2 {
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--phosphor);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.lesson-keys {
    font-size: 0.75rem;
    color: var(--muted);
    letter-spacing: 0.05em;
}

kbd {
    display: inline-block;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1px 6px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--phosphor-dim);
    letter-spacing: 0.12em;
}

/* ── Stats Bar ──────────────────────────────────────────────── */
.stats-bar {
    display: flex;
    gap: 2px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-panel);
}

.stat-block {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 8px;
    border-right: 1px solid var(--border);
    transition: background var(--transition);
}

.stat-block:last-child { border-right: none; }

.stat-value {
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--phosphor);
    line-height: 1;
    text-shadow: var(--glow);
    transition: all 0.2s;
}

.stat-label {
    font-size: 0.6rem;
    color: var(--muted);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-top: 4px;
}

/* Flash animation when stats update */
@keyframes stat-flash {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.4; }
}
.stat-value.flash { animation: stat-flash 0.25s ease; }

/* ── Typing Arena ───────────────────────────────────────────── */
.typing-arena {
    position: relative;
    background: var(--bg-arena);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 32px;
    min-height: 110px;
    font-family: var(--font-mono);
    font-size: 1.35rem;
    line-height: 1.8;
    letter-spacing: 0.04em;
    cursor: text;
    user-select: none;
    /* inner shadow for depth */
    box-shadow: inset 0 2px 12px rgba(0,0,0,0.5);
    overflow-wrap: break-word;
    word-break: break-all;
}

/* ── Character Spans ────────────────────────────────────────── */
.char {
    position: relative;
    transition: color 0.06s;
}

/* Pending (not yet typed) */
.char.pending { color: var(--muted); }

/* Correct */
.char.correct { color: var(--phosphor); }

/* Incorrect */
.char.incorrect {
    color: var(--red);
    text-decoration: underline;
    text-decoration-color: rgba(255,68,68,0.5);
}

/* Current cursor position */
.char.cursor::before {
    content: '';
    position: absolute;
    left: 0;
    top: 6%;
    width: 2px;
    height: 88%;
    background: var(--phosphor);
    box-shadow: var(--glow);
    animation: blink-cursor 0.9s step-end infinite;
}

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

/* Space chars — show a faint dot */
.char.space-char.pending::after  { content: '·'; color: var(--border); }
.char.space-char.correct::after  { content: '·'; color: var(--phosphor-dim); }
.char.space-char.incorrect::after{ content: '·'; color: var(--red); }
.char.space-char { color: transparent !important; }

/* ── Ghost Input (invisible, captures keystrokes) ───────────── */
.ghost-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 1px;
    height: 1px;
    top: 0;
    left: 0;
}

/* ── Overlay ────────────────────────────────────────────────── */
.overlay {
    position: absolute;
    inset: 0;
    background: rgba(13,15,14,0.88);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    backdrop-filter: blur(2px);
    z-index: 10;
}

.overlay-box {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

#overlay-msg {
    font-size: 0.85rem;
    color: var(--muted);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn-start,
.btn-primary,
.btn-secondary {
    font-family: var(--font-display);
    font-size: 0.8rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: 10px 28px;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-start,
.btn-primary {
    background: var(--phosphor);
    color: var(--bg);
    font-weight: 700;
    box-shadow: var(--glow-lg);
}

.btn-start:hover,
.btn-primary:hover {
    background: #fff;
    box-shadow: 0 0 24px rgba(57,255,132,0.7);
    transform: translateY(-1px);
}

.btn-secondary {
    background: transparent;
    color: var(--phosphor-dim);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    border-color: var(--phosphor-dim);
    color: var(--phosphor);
}

/* ── Result Card ────────────────────────────────────────────── */
.result-card {
    position: absolute;
    inset: 0;
    background: rgba(10,12,11,0.97);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    border-radius: var(--radius);
    border: 1px solid var(--phosphor-dim);
    box-shadow: var(--glow-lg);
    z-index: 20;
}

.result-card.hidden { display: none; }

.result-card h3 {
    font-family: var(--font-display);
    color: var(--phosphor);
    font-size: 1rem;
    letter-spacing: 0.1em;
    text-shadow: var(--glow);
}

.result-stats {
    display: flex;
    gap: 32px;
    text-align: center;
}

.result-stats span {
    font-family: var(--font-display);
    font-size: 2.2rem;
    font-weight: 600;
    color: var(--phosphor);
    text-shadow: var(--glow);
    display: block;
}

.result-stats small {
    font-size: 0.65rem;
    color: var(--muted);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.result-actions {
    display: flex;
    gap: 12px;
}

/* ── Lesson Nav ─────────────────────────────────────────────── */
.lesson-nav {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

.nav-dot {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-panel);
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all var(--transition);
    line-height: 1;
}

.nav-dot:hover {
    border-color: var(--phosphor-dim);
    color: var(--phosphor);
}

.nav-dot.active {
    border-color: var(--phosphor);
    background: rgba(57,255,132,0.1);
    color: var(--phosphor);
    box-shadow: var(--glow);
}

.nav-dot.done {
    border-color: var(--phosphor-dim);
    color: var(--phosphor-dim);
}

/* ── Visual Keyboard ────────────────────────────────────────── */
.keyboard-wrap {
    padding: 12px 24px 20px;
    display: flex;
    justify-content: center;
}

.keyboard {
    display: flex;
    flex-direction: column;
    gap: 5px;
    align-items: center;
}

.kb-row {
    display: flex;
    gap: 4px;
}

.kb-key {
    width: 36px;
    height: 34px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--muted);
    text-transform: uppercase;
    transition: all 0.1s;
    position: relative;
    /* bottom edge for 3D feel */
    box-shadow: 0 2px 0 rgba(0,0,0,0.6);
}

/* Space bar */
.kb-key.space { width: 220px; }

/* Home row keys get a tactile marker dot */
.kb-key.home-row::after {
    content: '';
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--phosphor-dim);
}

/* Active/highlighted key in the current lesson */
.kb-key.active {
    background: rgba(57,255,132,0.15);
    border-color: var(--phosphor-dim);
    color: var(--phosphor);
    box-shadow: 0 2px 0 rgba(0,0,0,0.6), 0 0 6px rgba(57,255,132,0.3);
}

/* Pressed (animate on keydown) */
.kb-key.pressed {
    background: rgba(57,255,132,0.35);
    border-color: var(--phosphor);
    color: var(--phosphor);
    box-shadow: 0 1px 0 rgba(0,0,0,0.6), var(--glow);
    transform: translateY(1px);
}

/* Wrong key flash */
.kb-key.error-flash {
    background: rgba(255,68,68,0.3);
    border-color: var(--red);
    animation: error-flash 0.3s ease forwards;
}

@keyframes error-flash {
    0%   { background: rgba(255,68,68,0.45); }
    100% { background: var(--bg-panel); }
}

/* ── Footer ─────────────────────────────────────────────────── */
.site-footer {
    text-align: center;
    padding: 12px;
    font-size: 0.65rem;
    color: var(--border);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    border-top: 1px solid var(--border);
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 640px) {
    .typing-arena { font-size: 1.1rem; padding: 20px 18px; }
    .stat-value   { font-size: 1.1rem; }
    .keyboard-wrap{ overflow-x: auto; padding: 8px 12px 16px; }
    .lesson-nav   { gap: 6px; }
    .nav-dot      { width: 30px; height: 30px; font-size: 0.7rem; }
}


/* ════════════════════════════════════════════════════════════
   DARK THEME
   Applied when <html data-theme="dark">
   ════════════════════════════════════════════════════════════ */

[data-theme="dark"] {
    --bg:          #0d0f0e;
    --bg-panel:    #111410;
    --bg-arena:    #0a0c0b;
    --border:      #1e2820;
    --phosphor:    #39ff84;
    --phosphor-dim:#1a7a3c;
    --amber:       #ffb347;
    --red:         #ff4444;
    --white:       #d4e8d4;
    --muted:       #4a6650;
    --glow:        0 0 8px rgba(57,255,132,0.55);
    --glow-lg:     0 0 20px rgba(57,255,132,0.3);
}

/* Light theme: remove scanline texture from body */
[data-theme="dark"] body {
    background-image: none;
}

/* Light theme: arena gets a subtle ruled-line texture */
[data-theme="dark"] .typing-arena {
    box-shadow: inset 0 1px 4px rgba(0,0,0,0.06);
    background-image: repeating-linear-gradient(
        transparent,
        transparent 35px,
        rgba(0,0,0,0.04) 35px,
        rgba(0,0,0,0.04) 36px
    );
}

/* Light theme: brand glow softened */
[data-theme="dark"] .brand-name {
    text-shadow: none;
}

/* Light theme: keyboard keys look like real keys */
[data-theme="dark"] .kb-key {
    background: #ffffff;
    border-color: #c8c8bc;
    box-shadow: 0 2px 0 #b0b0a0;
    color: #4a4a3a;
}

[data-theme="dark"] .kb-key.home-row::after {
    background: var(--phosphor-dim);
}

[data-theme="dark"] .kb-key.active {
    background: #edfaf2;
    border-color: var(--phosphor-dim);
    color: var(--phosphor);
    box-shadow: 0 2px 0 #b0b0a0;
}

[data-theme="dark"] .kb-key.pressed {
    background: #c8f0d8;
    box-shadow: 0 1px 0 #a0c0b0;
}

/* Light theme: stat bar */
[data-theme="dark"] .stats-bar {
    background: #ffffff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

/* Light theme: result card */
[data-theme="dark"] .result-card {
    background: rgba(245,245,240,0.98);
    box-shadow: 0 4px 24px rgba(0,0,0,0.12);
}

/* Light theme: overlay */
[data-theme="dark"] .overlay {
    background: rgba(245,245,240,0.92);
}

/* Light theme: nav */
[data-theme="dark"] .app-nav {
    box-shadow: 0 1px 0 var(--border);
}

/* ── Theme toggle button ──────────────────────────────────────
   Sits in the nav bar. JS adds/removes data-theme="light"
   on <html> and persists to localStorage.
   ──────────────────────────────────────────────────────────── */
.theme-toggle {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 4px 11px;
    font-family: var(--font-mono);
    font-size: 0.68rem;
    color: var(--muted);
    cursor: pointer;
    letter-spacing: 0.05em;
    transition: all 0.15s;
    white-space: nowrap;
}
.theme-toggle:hover {
    border-color: var(--phosphor-dim);
    color: var(--phosphor);
}

/* ── Nav dot locking ──────────────────────────────────────────── */
.nav-dot.nav-locked {
    opacity: .35;
    cursor: not-allowed;
    color: var(--muted);
    border-color: var(--border);
}
/* Brief red flash when user tries to click a locked dot */
@keyframes locked-flash {
    0%, 100% { border-color: var(--border); }
    40%       { border-color: var(--red); box-shadow: 0 0 6px rgba(255,68,68,0.5); color: var(--red); }
}
.nav-dot.locked-flash {
    animation: locked-flash 0.6s ease forwards;
}
