/* =========================================================
   lesson-typing.css – WordHammer Typing Lesson
   MonkeyType-inspired, desktop-primary design
   ========================================================= */
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;700;800&display=swap');

/* Hide only the sidebar elements (let topbar menu render normally) */
.sidebar, .sidebar__overlay {
    display: none !important;
}

/* True Dark Theme Override */
[data-theme="dark"] .typing-page-body {
    --bg: #000000;
    --surface: #0a0a0a;
    --card: #121212;
    --border: #222222;
    --text: #f5f5f5;
    --text-dim: #555555;
}

/* True Light Theme Override */
[data-theme="light"] .typing-page-body {
    --bg: #ffffff;
    --surface: #f9f9f9;
    --card: #ffffff;
    --border: #e0e0e0;
    --text: #1a1a1a;
    --text-dim: #b0b0b0;
}

.typing-page {
    width: 100vw;
    min-height: calc(100vh - var(--topbar-h));
    padding: 12px 40px 40px;
    margin-top: var(--topbar-h);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    gap: 12px;
    box-sizing: border-box;
    overflow-x: hidden;
    max-width: 100%;
}

/* ── Header Row ─────────────────────────────────────────── */
.typing-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    background: none;
    padding: 0 0 8px 0;
    border: none;
    box-shadow: none;
    width: 100%;
    max-width: 95vw;
    margin: 0 auto;
}

.typing-header__left {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.typing-header__right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.typing-back-link {
    font-size: 0.75rem;
    color: var(--accent);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: opacity 0.2s;
    margin-bottom: 1px;
    opacity: 0.7;
}
.typing-back-link:hover { opacity: 1; }

.typing-title {
    font-size: 1rem;
    font-weight: 400;
    color: var(--text-dim);
    margin: 0;
    line-height: 1.2;
}

.typing-subtitle {
    font-size: 0.75rem;
    font-weight: 300;
    color: var(--text-dim);
    opacity: 0.6;
    margin-top: 1px;
}

/* ── Live Stats Pills ────────────────────────────────────── */
.typing-stats {
    display: flex;
    align-items: center;
    gap: 10px;
}

.typing-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 8px 18px;
    min-width: 72px;
    transition: border-color 0.3s;
}

.typing-stat__val {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--accent);
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    line-height: 1;
}

.typing-stat__label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-dim);
    font-weight: 600;
    margin-top: 3px;
}

.typing-btn-restart {
    background: none;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-dim);
    padding: 8px 18px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}
.typing-btn-restart:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(0, 210, 200, 0.06);
}

/* ── Typing Arena ───────────────────────────────────────── */
.typing-arena {
    position: relative;
    background: none;
    border: none;
    border-radius: 0;
    padding: 24px 0;
    cursor: text;
    user-select: none;
    box-shadow: none;
    min-height: 180px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: 100%;
    max-width: 95vw;
    margin: 0 auto;
}

.typing-arena.is-focused {
    border-color: transparent;
    box-shadow: none;
}

/* ── Forge Panel (Configuration Controls) ────────────────── */
.typing-config-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    background: none;
    border: none;
    padding: 8px 0;
    margin-bottom: 0;
    width: 100%;
    max-width: 95vw;
    user-select: none;
    box-shadow: none;
}

.config-group {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.config-label {
    font-size: 0.7rem;
    color: var(--text-dim);
    opacity: 0.5;
    text-transform: lowercase;
    margin-right: 2px;
    user-select: none;
}

.config-divider {
    width: 1px;
    height: 14px;
    background: var(--border);
    opacity: 0.5;
    flex-shrink: 0;
}

.config-checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-dim);
    font-weight: 400;
    transition: color 0.2s;
}

.config-checkbox:hover { color: var(--text); }

.config-checkbox input {
    accent-color: var(--accent);
    cursor: pointer;
    width: 13px;
    height: 13px;
}

/* Per-option count select */
.config-count-sel {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 0.72rem;
    border-radius: var(--radius-sm);
    padding: 1px 4px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
    -webkit-appearance: none;
    appearance: none;
    text-align: center;
    width: 28px;
}
.config-count-sel:focus { border-color: var(--accent); }
.config-count-sel:disabled { opacity: 0.35; pointer-events: none; }

.config-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 0.8rem;
    font-weight: 400;
    cursor: pointer;
    padding: 3px 10px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.config-btn:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.03);
}

.config-btn.active {
    color: var(--accent);
    background: rgba(0, 210, 200, 0.08);
}
[data-theme="light"] .config-btn.active {
    color: var(--accent);
    background: rgba(0, 151, 167, 0.08);
}

/* ── Theme Toggle Icon Selectors ────────────────────────── */
.theme-icon-light, .theme-icon-dark {
    display: none;
}
[data-theme="dark"] .theme-icon-light {
    display: inline;
}
[data-theme="light"] .theme-icon-dark {
    display: inline;
}

/* ── Unfocused Overlay ───────────────────────────────────── */
.typing-focus-overlay {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: rgba(13, 27, 42, 0.86);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 10;
    transition: opacity 0.25s ease;
    cursor: pointer;
}

.typing-focus-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.typing-focus-overlay__icon {
    font-size: 2.2rem;
    animation: focusPulse 1.8s ease-in-out infinite;
}

.typing-focus-overlay__text {
    font-size: 0.92rem;
    color: var(--text-dim);
    font-weight: 500;
}

@keyframes focusPulse {
    0%, 100% { transform: scale(1); opacity: 0.8; }
    50%       { transform: scale(1.1); opacity: 1; }
}

/* ── Hidden input for capturing keystrokes ───────────────── */
#typing-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    border: none;
    outline: none;
    background: transparent;
    font-size: 16px; /* prevent iOS zoom */
}

/* ── Progress Bar ────────────────────────────────────────── */
.typing-progress-bar {
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    overflow: hidden;
    margin-bottom: 28px;
}

.typing-progress-fill {
    height: 100%;
    border-radius: 2px;
    background: linear-gradient(90deg, var(--accent2), var(--accent));
    transition: width 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    width: 0%;
}

/* ── Words Container ──────────────────────────────────── */
.typing-words-wrap {
    position: relative;
    overflow-y: auto;
    max-height: 48vh;
    scroll-behavior: smooth;
    /* custom scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

/* Only bottom fade — no top fade (it was hiding text) */
.typing-words-wrap::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 48px;
    pointer-events: none;
    z-index: 5;
    background: linear-gradient(to top, var(--bg) 0%, transparent 100%);
    display: none; /* Removed to fix contrast/defocus blending issues when scrolling */
}

/* Webkit scrollbar */
.typing-words-wrap::-webkit-scrollbar { width: 4px; }
.typing-words-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

#words-container {
    position: relative;
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 2.2rem;
    line-height: 1.6;
    letter-spacing: 0.02em;
    display: block;   /* block so .wt-word-group gets its own line */
    transition: none;
    padding-bottom: 12px; /* reduced from 48px since fade is removed */
}

/* Per-vocabulary-word block group */
.wt-word-group {
    display: block;
    margin-bottom: 0.25em;
}

/* Token row inside a group wraps inline */
.wt-word-group > .wt-word {
    display: inline-flex;
}

/* ── Word Token ──────────────────────────────────────────── */
.wt-word {
    display: inline-flex;
    position: relative;
}

/* ── Character Spans ─────────────────────────────────────── */
.wt-char {
    color: var(--text-dim);
    transition: color 0.06s;
    position: relative;
    white-space: pre;
}

.wt-char.correct {
    color: var(--text);
}

.wt-char.incorrect {
    color: var(--danger);
    text-decoration: underline;
    text-decoration-color: rgba(255, 77, 109, 0.6);
    text-underline-offset: 3px;
}

/* Extra chars typed past word length */
.wt-char.extra {
    color: var(--danger);
    opacity: 0.75;
}

/* ── Caret ───────────────────────────────────────────────── */
#typing-caret {
    position: absolute;
    width: 2.5px;
    background: var(--accent);
    border-radius: 2px;
    transition: left 0.05s ease-out, top 0s;
    pointer-events: none;
    z-index: 20;
    /* Height set dynamically from line-height */
}

@keyframes caretBlink {
    0%, 49%  { opacity: 1; }
    50%, 100% { opacity: 0; }
}

#typing-caret.blinking {
    animation: caretBlink 0.9s ease-in-out infinite;
}

/* ── Word label tag (e.g. "Word:", "Synonyms:") ────────────── */
.wt-word--label .wt-char {
    color: var(--accent);
    opacity: 0.6;
}
.wt-word--label .wt-char.correct {
    color: var(--text) !important;
    opacity: 1;
}
.wt-word--label .wt-char.incorrect {
    color: var(--danger) !important;
    opacity: 1;
}

.wt-word--sep .wt-char {
    color: var(--text-dim);
    opacity: 0.4;
}

/* ── Result Card ─────────────────────────────────────────── */
#typing-result {
    display: none;
    flex-direction: column;
    align-items: stretch;
    text-align: left;
    gap: 28px;
    padding: 40px;
    background: none;
    border: none;
    width: 100%;
    max-width: 95vw;
    animation: resultIn 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes resultIn {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Top row: big stats left + mini stats right */
.result-top-row {
    display: flex;
    align-items: flex-end;
    gap: 40px;
    flex-wrap: wrap;
}

.result-left {
    display: flex;
    align-items: flex-end;
    gap: 28px;
}

.result-stat-col {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.result-big-val {
    font-size: clamp(4rem, 10vw, 6.5rem);
    font-weight: 700;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    color: var(--accent);
    line-height: 1;
    letter-spacing: -2px;
}

.result-big-val--acc {
    color: var(--gold);
}

.result-big-label {
    font-size: 0.95rem;
    text-transform: lowercase;
    letter-spacing: 0.8px;
    color: var(--text-dim);
    font-weight: 500;
    margin-top: 4px;
}

.result-right {
    margin-bottom: 12px;
}

.result-mini-stats {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.result-mini-row {
    display: flex;
    gap: 16px;
    align-items: baseline;
}

.result-mini-label {
    font-size: 0.88rem;
    color: var(--text-dim);
    font-weight: 500;
    min-width: 52px;
    opacity: 0.75;
}

.result-mini-val {
    font-size: 1.15rem;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text);
    font-weight: 600;
}

/* ── Result Chart ────────────────────────────────────────── */
.result-chart-wrap {
    width: 100%;
    position: relative;
    margin-top: 10px;
}

.result-chart {
    width: 100% !important;
    height: 220px !important;
    display: block;
}

.result-chart-legend {
    display: flex;
    gap: 16px;
    margin-bottom: 8px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    user-select: none;
    padding-left: 52px; /* aligns with chart PAD_L */
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-dim);
    cursor: pointer;
    opacity: 0.4;
    transition: opacity 0.18s, color 0.18s;
}

.legend-item.active {
    opacity: 1;
}

.legend-item.wpm.active { color: var(--accent); }
.legend-item.raw.active { color: var(--text); }
.legend-item.errors.active { color: var(--danger, #ca4754); }

.legend-color-line {
    width: 12px;
    height: 3px;
    border-radius: 1.5px;
    display: inline-block;
}

.legend-color-line.wpm {
    background: var(--accent);
}

.legend-color-line.raw {
    background: var(--text-dim);
    border-bottom: 1.5px dashed var(--text-dim);
    height: 0px;
    vertical-align: middle;
}

.legend-color-line.errors {
    background: var(--danger, #ca4754);
}

.result-actions {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    justify-content: flex-start;
    margin-top: 8px;
}

/* ── Instruction line ────────────────────────────────────── */
.typing-hint {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-dim);
    opacity: 0.7;
    letter-spacing: 0.5px;
    margin-top: -4px;
}

.typing-hint kbd {
    display: inline-block;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 1px 7px;
    font-size: 0.78rem;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-dim);
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 720px) {
    .typing-page { padding: 16px; gap: 16px; }
    .typing-arena { padding: 24px 16px; }
    #words-container { font-size: 1.5rem; line-height: 1.5; gap: 0 10px; }
    .typing-header { padding: 14px 16px; }
    .typing-title { font-size: 1.2rem; }
    .typing-config-bar { padding: 10px 16px; gap: 12px; flex-wrap: wrap; }
    .result-top-row { gap: 20px; }
    .result-big-val { font-size: clamp(2.4rem, 10vw, 3.5rem); }
    #typing-result { padding: 24px 20px; }
    .result-chart { height: 140px !important; }
}

@media (max-width: 480px) {
    .typing-stats { gap: 6px; }
    .typing-stat { padding: 6px 12px; min-width: 56px; }
    .typing-stat__val { font-size: 1.2rem; }
    .typing-config-bar { gap: 8px; }
    .result-top-row { flex-direction: column; align-items: flex-start; gap: 12px; }
}

/* Hide WPM, ACC, and overall progress pills on the top stats bar during typing */
#stat-wpm-pill,
#stat-acc-pill,
#stat-progress-pill,
.typing-progress-bar {
    display: none !important;
}

/* Punctuation base — visible in dim state */
.wt-char.punctuation { color: var(--text-dim); }

/* When correctly typed: white/dark */
[data-theme="dark"]  .wt-char.punctuation.correct   { color: #e0e0e0; }
[data-theme="light"] .wt-char.punctuation.correct   { color: #222222; }

/* When incorrectly typed: red (same as normal incorrect) */
.wt-char.punctuation.incorrect { color: var(--danger) !important; }

/* ── ADHD Mode Pill Toggle (Bionic Reading) ────────── */
.adhd-mode-pill {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(var(--accent-rgb), 0.1);
    border: 1px solid rgba(var(--accent-rgb), 0.2);
    padding: 4px 12px;
    border-radius: 100px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.adhd-mode-pill:hover {
    background: rgba(var(--accent-rgb), 0.15);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.adhd-mode-pill.active {
    background: rgba(var(--accent-rgb), 0.2);
    border-color: rgba(var(--accent-rgb), 0.4);
}

.adhd-mode-label {
    font-size: 0.78rem;
    font-weight: 800;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: color 0.3s;
}

.adhd-mode-pill.active .adhd-mode-label {
    color: var(--accent);
}

.adhd-mode-pill .toggle-switch {
    position: relative;
    width: 32px;
    height: 18px;
    background: var(--border);
    border-radius: 20px;
    transition: background 0.3s;
}

.adhd-mode-pill.active .toggle-switch {
    background: var(--accent);
}

.adhd-mode-pill .toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.adhd-mode-pill.active .toggle-switch::after {
    transform: translateX(14px);
}

/* Bionic Reading Fixations */
.wt-char.wt-char--bionic {
    font-weight: 800 !important;
    /* Bionic untyped: noticeably brighter than dim untyped, but not as bright as typed */
    color: rgba(255, 255, 255, 0.48);
}

[data-theme="light"] .wt-char.wt-char--bionic {
    color: rgba(0, 0, 0, 0.48);
}

.wt-char.wt-char--bionic.correct {
    color: var(--text) !important;
    font-weight: 800 !important;
}

.wt-char.wt-char--bionic.incorrect {
    color: var(--danger) !important;
    font-weight: 800 !important;
}
