:root {
  --bg: #1a1b26;
  --panel: #24283b;
  --panel-2: #2a2e44;
  --text: #c0caf5;
  --dim: #565f89;
  --correct: #9ece6a;
  --wrong: #f7768e;
  --cursor: #e0af68;
  --accent: #7aa2f7;
  --lp: #f7768e; --lr: #ff9e64; --lm: #e0af68; --li: #9ece6a;
  --ri: #73daca; --rm: #7aa2f7; --rr: #bb9af7; --rp: #ff9e9e;
  --tt: #c0caf5;
  --text-shadow: rgba(0,0,0,0.3);
  --panel-shadow: rgba(0,0,0,0.5);
  --overlay: rgba(0,0,0,0.6);
  --key-border: transparent;
  --key-text: var(--dim);
  --sidebar-w: 260px;
}

/* ============ LIGHT THEME ============ */
.light-theme {
  --bg: #f0f2f5;
  --panel: #ffffff;
  --panel-2: #e4e6eb;
  --text: #1c1e21;
  --dim: #65676b;
  --correct: #2e7d32;
  --wrong: #c62828;
  --cursor: #e65100;
  --accent: #1565c0;
  --lp: #c62828; --lr: #e65100; --lm: #f57f17; --li: #2e7d32;
  --ri: #00695c; --rm: #1565c0; --rr: #4a148c; --rp: #880e4f;
  --tt: #37474f;
  --text-shadow: rgba(255,255,255,0.5);
  --panel-shadow: rgba(0,0,0,0.12);
  --overlay: rgba(0,0,0,0.35);
  --key-border: #d0d0d0;
  --key-text: var(--text);
}

* { box-sizing: border-box; }
/* Always reserve scrollbar space so frames never shift sideways when a scrollbar appears */
html { scrollbar-gutter: stable; overflow-x: hidden; }
body {
  margin: 0; min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg); color: var(--text);
  display: flex; align-items: flex-start; justify-content: flex-start;
  padding: 8px; overflow-x: hidden;
  transition: background 0.3s, color 0.3s;
}
.app { width: 100%; max-width: 1100px; margin: 0 auto; position: relative; }

/* ========================================================================
   START-MODE / FOCUS-MODE LAYOUT SWITCHING
   ======================================================================== */

.app.start-mode .text-display,
.app.start-mode .hands-wrap,
.app.start-mode .back-btn,
.app.start-mode .focus-stats {
  display: none !important;
}
.app.start-mode .top-frame,
.app.start-mode .auth-bar,
.app.start-mode .top-bar,
.app.start-mode .ach-panel,
.app.start-mode .side-col,
.app.start-mode .train-panel,
.app.start-mode .controls-row,
.app.start-mode .footnote {
  display: flex;
}

.app.focus-mode .top-frame,
.app.focus-mode .auth-bar,
.app.focus-mode .top-bar,
.app.focus-mode .train-panel,
.app.focus-mode .controls-row,
.app.focus-mode .ach-panel,
.app.focus-mode .side-col,
.app.focus-mode .footnote {
  display: none !important;
}
.app.focus-mode .text-display,
.app.focus-mode .hands-wrap,
.app.focus-mode .back-btn,
.app.focus-mode .focus-stats {
  display: flex;
}
.app.focus-mode .text-display {
  display: block;
}
.app.focus-mode .layout-row:not(.hidden) {
  display: flex;
}
.app.focus-mode {
  display: flex;
  flex-direction: column;
  max-width: 1100px;
  /* Fixed to the viewport: the text frame takes what's left and never pushes the keyboard */
  height: calc(100vh - 16px);
  height: calc(100dvh - 16px);
}
.app.focus-mode .text-display {
  /* Fixed-size frame; main.js shrinks the font until the text fits */
  flex: 1 1 0;
  min-height: 80px;
  font-size: min(3vw, 34px);
  padding: 20px 24px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 4px;
}
.app.focus-mode .text-display .char {
  font-size: 1em;
  line-height: 1.6;
}

.app.focus-mode .key {
  --k: 64px;
  height: 64px;
  font-size: 20px;
}
.app.focus-mode .key.shift {
  width: 108px;
  font-size: 22px;
}
.app.focus-mode .key.space {
  width: 300px;
  font-size: 26px;
}
.app.focus-mode .finger {
  width: 64px;
}
.app.focus-mode .finger .shaft {
  font-size: 18px;
}
.app.focus-mode .finger .home {
  font-size: 14px;
  min-width: 32px;
}
.app.focus-mode .finger .name {
  font-size: 12px;
  max-width: 64px;
}
.app.focus-mode .thumb-bar {
  width: 120px;
  height: 18px;
  border-radius: 9px;
}
.app.focus-mode .hint-line {
  font-size: 15px;
  margin-bottom: 8px;
}
.app.focus-mode .kb-row {
  gap: 5px; --g: 5px;
}
.app.focus-mode .keyboard {
  gap: 5px; --rg: 5px;
  margin-top: 6px;
}
.app.focus-mode .hands-wrap {
  flex: 0 0 auto;
  padding: 8px 10px 10px;
  margin-bottom: 0;
}
.app.focus-mode .hands {
  gap: 14px;
}
.app.focus-mode .hand {
  gap: 6px;
}

/* ============ TOP FRAME: START BUTTON + AUTH BAR ============ */
.top-frame {
  align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap;
  padding: 6px 10px; background: var(--panel); border-radius: 8px;
  transition: background 0.3s;
}
.top-frame > .auth-bar { margin: 0 0 0 auto; padding: 0; background: none; }

/* ============ AUTH BAR ============ */
.auth-bar {
  display: flex; justify-content: flex-end; align-items: center;
  gap: 8px; margin-bottom: 8px; font-size: 13px; flex-wrap: wrap;
  padding: 6px 10px; background: var(--panel); border-radius: 8px;
  transition: background 0.3s;
}
.auth-bar .username { color: var(--accent); font-weight: 600; font-size: 14px; }
.auth-bar button {
  background: transparent; color: var(--dim);
  border: 1px solid var(--dim); border-radius: 6px;
  padding: 6px 14px; font-size: 12px; cursor: pointer;
  font-family: inherit; transition: all 0.15s; font-weight: 500;
}
.auth-bar button:hover { border-color: var(--accent); color: var(--accent); background: rgba(21,101,192,0.05); }
/* ============ SETTINGS MODAL (auth.js + displayPrefs.js) ============ */
.modal.settings-modal { max-width: 480px; max-height: 90vh; overflow-y: auto; }
.modal .settings-section {
  margin: 12px 0 12px; padding-top: 14px;
  border-top: 1px solid var(--key-border);
  font-size: 13px; font-weight: 700; color: var(--accent);
  text-transform: uppercase; letter-spacing: 1.2px;
}
.modal h2 + .modal-error + .settings-section { margin-top: 4px; padding-top: 0; border-top: none; }
/* Theme: two-button segmented control */
.pref-seg {
  display: flex; gap: 4px; padding: 4px; margin-bottom: 14px;
  background: var(--panel-2); border: 1px solid var(--key-border); border-radius: 8px;
}
.pref-seg-btn {
  flex: 1; padding: 8px 12px; border: none; border-radius: 6px;
  background: transparent; color: var(--dim);
  font-size: 14px; font-family: inherit; cursor: pointer; transition: all 0.15s;
}
.pref-seg-btn:hover { color: var(--text); }
.pref-seg-btn.active { background: var(--accent); color: var(--bg); font-weight: 600; }
/* Typing buddy: a grid of pictures, the picked one outlined */
.pref-animals { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 6px; margin-bottom: 14px; }
.pref-animal {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  padding: 4px; border-radius: 10px; cursor: pointer;
  background: var(--panel-2); border: 2px solid transparent; transition: all 0.15s;
}
.pref-animal:hover { border-color: var(--key-border); }
.pref-animal:hover .buddy-svg { transform: scale(1.1); }
.pref-animal.active { border-color: var(--accent); background: rgba(122,162,247,0.14); }
.pref-animal .buddy-svg { width: 30px; height: 30px; transition: transform 0.15s; }
.pref-animal .animal-off { font-size: 22px; opacity: 0.45; }
.pref-animal .an-sclera { fill: #fff; stroke: #1b1a20; stroke-width: 0.6; }
.pref-animal .an-pupil { fill: #1b1a20; }
.pref-animal .an-glint { fill: #fff; }
.pref-animal .an-brow { fill: none; opacity: 0; }
.pref-animal .an-mouth-calm { fill: none; stroke: #1b1a20; stroke-width: 0.8; stroke-linecap: round; }
.pref-animal .an-mouth-scared, .pref-animal .an-sweat, .pref-animal .an-zzz { opacity: 0; }
.pref-animal .an-lid { transform-box: fill-box; transform-origin: 50% 0; transform: scaleY(0); }
/* On/off switches */
.pref-switches { display: flex; flex-direction: column; margin-bottom: 14px; }
.modal label.pref-switch {
  display: flex; align-items: center; gap: 12px; margin: 0; padding: 10px 2px;
  font-size: 14px; color: var(--text); text-transform: none; letter-spacing: 0;
  cursor: pointer; border-bottom: 1px solid var(--key-border);
}
.modal label.pref-switch:last-child { border-bottom: none; }
.pref-switch-text { flex: 1; min-width: 0; }
.pref-switch-text small { display: block; margin-top: 2px; font-size: 12px; color: var(--dim); line-height: 1.35; }
.modal .pref-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; padding: 0; }
.pref-switch-track {
  position: relative; flex: none; width: 40px; height: 22px; border-radius: 11px;
  background: color-mix(in srgb, var(--dim) 45%, transparent); transition: background 0.2s;
}
.pref-switch-track::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3); transition: transform 0.2s;
}
.pref-switch input:checked + .pref-switch-track { background: var(--accent); }
.pref-switch input:checked + .pref-switch-track::after { transform: translateX(18px); }
.pref-switch input:focus-visible + .pref-switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  .pref-switch-track, .pref-switch-track::after { transition: none; }
}

/* ============ MODAL ============ */
.modal-overlay {
  position: fixed; inset: 0; background: var(--overlay);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; animation: fadeIn 0.2s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--panel); border-radius: 14px;
  padding: 28px; width: 90%; max-width: 420px;
  box-shadow: 0 24px 80px var(--panel-shadow);
  transition: background 0.3s;
}
.modal h2 { margin: 0 0 16px; font-size: 22px; color: var(--text); }
.modal label {
  display: block; font-size: 12px; color: var(--dim);
  margin-bottom: 4px; text-transform: uppercase; letter-spacing: 1px;
}
.modal input {
  width: 100%; padding: 12px 16px; margin-bottom: 14px;
  background: var(--panel-2); border: 1px solid var(--key-border);
  border-radius: 8px; color: var(--text); font-size: 15px;
  font-family: inherit; outline: none; transition: border-color 0.15s;
}
.modal input:focus { border-color: var(--accent); }
.modal select {
  width: 100%; padding: 12px 16px; margin-bottom: 14px;
  background: var(--panel-2); border: 1px solid var(--key-border);
  border-radius: 8px; color: var(--text); font-size: 15px;
  font-family: inherit; outline: none; transition: border-color 0.15s;
}
.modal select:focus { border-color: var(--accent); }
.modal .modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.modal .modal-actions button {
  padding: 10px 24px; border-radius: 8px; font-size: 15px;
  cursor: pointer; font-family: inherit; border: none; transition: all 0.15s;
  font-weight: 500;
}
.modal .modal-actions .primary-btn { background: var(--accent); color: var(--bg); }
.modal .modal-actions .primary-btn:hover { filter: brightness(1.15); }
.modal .modal-actions .ghost-btn { background: transparent; color: var(--dim); }
.modal .modal-actions .ghost-btn:hover { color: var(--text); }
.modal .modal-error { color: var(--wrong); font-size: 13px; margin-top: -8px; margin-bottom: 10px; }
.modal .modal-switch { font-size: 13px; color: var(--dim); text-align: center; margin-top: 14px; cursor: pointer; }
.modal .modal-switch:hover { color: var(--accent); }

/* ============ HISTORY & LEADERBOARD WINDOWS (auth.js) ============ */
.modal.table-modal { max-width: 640px; width: 94%; max-height: 88vh; display: flex; flex-direction: column; }
.table-modal-body { overflow: auto; min-height: 0; margin: 0 -6px 8px; padding: 0 6px; }
.table-modal-body table th { position: sticky; top: 0; background: var(--panel); }
.history-loading, .history-empty { color: var(--dim); font-size: 14px; text-align: center; padding: 40px 0; }
.history-table, .leaderboard-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.history-table th, .leaderboard-table th {
  text-align: left; font-size: 12px;
  text-transform: uppercase; letter-spacing: 1px;
  color: var(--dim); padding: 8px 6px 4px;
  border-bottom: 1px solid var(--panel-2);
}
.history-table td, .leaderboard-table td { padding: 7px 6px; border-bottom: 1px solid rgba(128,128,128,0.06); }
.history-table tr:hover, .leaderboard-table tr:hover { background: rgba(128,128,128,0.04); }
.wpm-cell { color: var(--accent); font-weight: 600; }
.xp-cell { color: var(--cursor); font-weight: 600; }
.draft-badge { color: var(--dim); font-size: 10px; }
.leaderboard-table .rank-1 td { color: var(--cursor); font-weight: 600; }
.leaderboard-table .rank-2 td { color: var(--dim); }
.leaderboard-table .rank-3 td { color: var(--lr); }
.retry-btn {
  margin-top: 12px; padding: 9px 22px;
  background: var(--accent); color: var(--bg);
  border: none; border-radius: 8px; cursor: pointer;
  font-size: 14px; font-family: inherit; font-weight: 500;
  transition: filter 0.15s;
}
.retry-btn:hover { filter: brightness(1.15); }

/* ============ TOP BAR ============ */
.top-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; margin-bottom: 0;
  background: var(--panel); border-radius: 10px;
  transition: background 0.3s; flex-wrap: wrap;
}
.level-compact { display: flex; align-items: center; gap: 8px; }
.lvl-badge {
  background: linear-gradient(135deg, var(--accent), var(--lr));
  color: var(--bg); font-weight: 700;
  border-radius: 50%; width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  box-shadow: 0 0 16px rgba(122,162,247,0.3);
  flex-shrink: 0;
}
.lvl-title { font-size: 14px; font-weight: 600; }
.xp-compact { font-size: 11px; color: var(--dim); font-variant-numeric: tabular-nums; }
.xp-mini { width: 100%; height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.xp-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--li), var(--accent));
  transition: width 0.5s ease;
}
.score-compact { text-align: right; margin-left: auto; }
.sc-label { font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: 1px; display: block; }
.sc-value { font-size: 20px; font-weight: 700; color: var(--cursor); font-variant-numeric: tabular-nums; text-shadow: 0 0 10px rgba(224,175,104,0.3); line-height: 1.1; }

/* ============ RIGHT COLUMN: ACHIEVEMENTS + LEVEL MAP ============ */
.side-col { flex-direction: column; gap: 6px; min-width: 0; min-height: 0; }
/* The map sits on top; the achievements below take only the room they need.
   Without the map (guests) the achievements fill the column as before. */
.side-col > .ach-panel { flex: 0 1 auto; min-height: 96px; }
.side-col:has(> .level-map.hidden) > .ach-panel { flex: 1 1 0; }

/* ============ LEVEL MAP (levelMap.js) ============ */
.level-map {
  background: var(--panel); border-radius: 10px; padding: 10px 12px;
  /* Never shrinks: when the column is short the achievements scroll instead
     (Safari otherwise squeezed the map to zero height after leaving a lesson) */
  display: flex; flex-direction: column; flex: 0 0 auto;
  transition: background 0.3s;
}
.level-map h2 {
  font-size: 11px; font-weight: 500; color: var(--dim);
  text-transform: uppercase; letter-spacing: 1px;
  margin: 0 0 6px; display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.lm-head-right { display: flex; align-items: center; gap: 8px; }
#lm-count { color: var(--cursor); font-variant-numeric: tabular-nums; white-space: nowrap; }
.lm-langs { display: inline-flex; background: var(--panel-2); border-radius: 6px; padding: 2px; }
.lm-lang {
  border: 0; background: transparent; color: var(--dim); cursor: pointer;
  font: inherit; font-size: 10px; letter-spacing: 0.5px; padding: 2px 7px; border-radius: 4px;
}
.lm-lang.active { background: var(--accent); color: var(--bg); }
.lm-lang:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.lm-scroll {
  overflow-y: auto; overflow-x: hidden; max-height: 46vh;
  border-radius: 8px;
  background:
    radial-gradient(circle at 15% 20%, rgba(158,206,106,0.10), transparent 45%),
    radial-gradient(circle at 85% 80%, rgba(122,162,247,0.10), transparent 50%),
    var(--panel-2);
}
.lm-svg { display: block; }
.lm-road { fill: none; stroke: var(--bg); stroke-width: 14; stroke-linecap: round; stroke-linejoin: round; opacity: 0.7; }
.lm-road-dash { fill: none; stroke: var(--dim); stroke-width: 1.5; stroke-dasharray: 4 7; opacity: 0.6; }
.lm-road-done {
  fill: none; stroke: var(--correct); stroke-width: 5; stroke-linecap: round; opacity: 0.85;
  filter: drop-shadow(0 0 4px rgba(158,206,106,0.45));
}
.lm-tree { fill: var(--li); opacity: 0.35; }
.lm-trunk { fill: var(--lr); opacity: 0.35; }
.lm-bush { fill: var(--ri); opacity: 0.22; }
.lm-flag line { stroke: var(--dim); stroke-width: 2; stroke-linecap: round; }
.lm-flag path { fill: var(--dim); }
.lm-flag.done path { fill: var(--cursor); }

.lm-node { cursor: pointer; outline: none; }
.lm-node .lm-disc { stroke-width: 2.5; transition: transform 0.15s; transform-box: fill-box; transform-origin: center; }
.lm-node .lm-glyph { font-weight: 700; pointer-events: none; }
.lm-node .lm-num { font-size: 9px; fill: var(--dim); pointer-events: none; }
.lm-node.passed .lm-disc { fill: var(--correct); stroke: var(--bg); }
.lm-node.passed .lm-glyph { fill: var(--bg); }
.lm-node.current .lm-disc { fill: var(--accent); stroke: var(--cursor); }
.lm-node.current .lm-glyph { fill: var(--bg); }
.lm-node.current .lm-num { fill: var(--cursor); font-weight: 700; }
.lm-node.locked { cursor: default; }
.lm-node.locked .lm-disc { fill: var(--panel); stroke: var(--dim); stroke-dasharray: 3 3; }
.lm-node.locked .lm-glyph { fill: var(--dim); }
.lm-node.unlocked:hover .lm-disc,
.lm-node.unlocked:focus-visible .lm-disc { transform: scale(1.15); }
.lm-node:focus-visible .lm-disc { stroke: var(--cursor); stroke-width: 3.5; }
.lm-badge { fill: var(--cursor); stroke: var(--bg); stroke-width: 1.5; }
.lm-check { fill: none; stroke: var(--bg); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.lm-lock { fill: var(--dim); }
.lm-lock-arc { fill: none; stroke: var(--dim); stroke-width: 1.5; }
.lm-pulse {
  fill: none; stroke: var(--cursor); stroke-width: 2; opacity: 0.6;
  transform-box: fill-box; transform-origin: center;
  animation: lm-pulse 1.6s ease-out infinite;
}
@keyframes lm-pulse {
  from { transform: scale(0.85); opacity: 0.7; }
  to { transform: scale(1.35); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .lm-pulse { animation: none; } }

/* ============ ACHIEVEMENTS (RECTANGULAR PANEL) ============ */
.ach-panel {
  margin-top: 0; background: var(--panel);
  border-radius: 10px; padding: 10px 12px;
  transition: background 0.3s;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.ach-panel h2 {
  font-size: 11px; font-weight: 500; color: var(--dim);
  text-transform: uppercase; letter-spacing: 1px;
  margin: 0 0 8px; display: flex; justify-content: space-between;
  flex-shrink: 0;
}
.ach-panel h2 span { color: var(--cursor); }
/* Overall progress strip under the title */
.ach-total {
  height: 3px; border-radius: 2px; background: var(--panel-2);
  margin: -2px 0 8px; overflow: hidden; flex-shrink: 0;
}
.ach-total i {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--cursor), var(--correct));
  transition: width 0.8s cubic-bezier(.2,.8,.2,1);
}
.ach-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
  overflow-y: auto; overflow-x: hidden;
  flex: 1;
  align-content: start;
  padding: 4px 2px 6px;
}

/* ---- Achievement cards. Tier sets --tc (its colour): bronze, silver, gold, legendary ---- */
.ach-card {
  --tc: #cd7f32;
  position: relative; isolation: isolate;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  min-width: 0; padding: 10px 6px 8px;
  border-radius: 12px; cursor: help; text-align: center;
  background: var(--panel-2);
  border: 1px solid rgba(255,255,255,0.04);
  overflow: hidden;
  transition: transform 0.25s cubic-bezier(.2,.8,.2,1), box-shadow 0.25s, border-color 0.25s;
}
.ach-card.tier-2 { --tc: #b8c4dc; }
.ach-card.tier-3 { --tc: #f2c14e; }
.ach-card.tier-4 { --tc: #bb9af7; }
.ach-card.secret { --tc: #73daca; }
/* Light theme: deeper tier colours so dates and bars stay readable on white */
html.light-theme .ach-card { --tc: #a0612a; border-color: rgba(0,0,0,0.06); }
html.light-theme .ach-card.tier-2 { --tc: #5f6b85; }
html.light-theme .ach-card.tier-3 { --tc: #b07d00; }
html.light-theme .ach-card.tier-4 { --tc: #7b4fd0; }
html.light-theme .ach-card.secret { --tc: #00897b; }

.ach-badge {
  position: relative; width: 62px; height: 62px; flex-shrink: 0;
  display: grid; place-items: center; border-radius: 50%;
  transition: transform 0.3s cubic-bezier(.3,1.6,.5,1);
}
/* Painted medallion (public/ach/*.svg) — it carries its own frame */
.ach-icon {
  display: block; width: 100%; height: 100%;
  -webkit-user-drag: none; user-select: none;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.45));
  transition: filter 0.3s, opacity 0.3s;
}
.ach-name {
  font-size: 11px; font-weight: 600; line-height: 1.25; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; min-height: 2.5em; overflow-wrap: anywhere;
}
.ach-foot {
  width: 100%; font-size: 9.5px; color: var(--dim);
  font-variant-numeric: tabular-nums; letter-spacing: 0.2px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  min-height: 12px;
}
.ach-bar { width: 100%; height: 4px; border-radius: 2px; background: var(--bg); overflow: hidden; }
.ach-bar i {
  display: block; height: 100%; width: calc(var(--p, 0) * 100%);
  border-radius: 2px; background: var(--tc); opacity: 0.75;
  transition: width 0.8s cubic-bezier(.2,.8,.2,1);
}

/* Unlocked: tinted card, glowing medal, slow shine passing over it */
.ach-card.unlocked {
  background:
    radial-gradient(120% 80% at 50% 0%, color-mix(in srgb, var(--tc) 26%, transparent), transparent 70%),
    var(--panel-2);
  border-color: color-mix(in srgb, var(--tc) 45%, transparent);
  box-shadow: 0 2px 10px color-mix(in srgb, var(--tc) 18%, transparent);
}
.ach-card.unlocked .ach-icon {
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.45)) drop-shadow(0 0 7px color-mix(in srgb, var(--tc) 55%, transparent));
}
.ach-card.unlocked .ach-foot { color: var(--tc); font-weight: 600; }
.ach-card.unlocked::after {
  content: ''; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: linear-gradient(105deg, transparent 35%, rgba(255,255,255,0.16) 50%, transparent 65%);
  transform: translateX(-120%);
  animation: ach-shine 7s ease-in-out infinite;
  animation-delay: calc(var(--i, 0) * 0.45s);
}
@keyframes ach-shine {
  0%, 82% { transform: translateX(-120%); }
  100% { transform: translateX(120%); }
}
/* Legendary: a colour ring slowly running around the edge */
.ach-card.unlocked.tier-4::before {
  content: ''; position: absolute; inset: -60%; z-index: -2; pointer-events: none;
  background: conic-gradient(from 0deg, transparent 0 70%, var(--tc) 85%, #f7768e 92%, transparent 100%);
  animation: ach-spin 5s linear infinite;
  opacity: 0.55;
}
.ach-card.unlocked.tier-4 { background-clip: padding-box; }
.ach-card.unlocked.tier-4 .ach-badge { animation: ach-float 3.2s ease-in-out infinite; }
@keyframes ach-spin { to { transform: rotate(360deg); } }
@keyframes ach-float { 50% { transform: translateY(-3px); } }

/* Locked: faded medal behind a small lock, dashed rim in the tier colour */
/* Locked: the painting is there but faded to a dim sepia sketch */
.ach-card.locked .ach-icon { filter: grayscale(0.9) sepia(0.25) brightness(0.75); opacity: 0.55; }
.ach-card.locked .ach-name { color: color-mix(in srgb, var(--text) 55%, var(--dim)); font-weight: 500; }
.ach-lock {
  position: absolute; right: -2px; bottom: -1px;
  font-size: 11px; line-height: 1;
  background: var(--panel-2); border-radius: 50%; padding: 2px;
}
.ach-card.secret .ach-icon { filter: none; opacity: 0.7; animation: ach-wobble 4s ease-in-out infinite; }
.ach-card.secret { border-style: dashed; border-color: color-mix(in srgb, var(--tc) 35%, transparent); }
@keyframes ach-wobble { 0%, 85%, 100% { transform: rotate(0); } 90% { transform: rotate(-12deg); } 95% { transform: rotate(10deg); } }

/* Hover / focus: card lifts, medal bounces */
.ach-card:hover, .ach-card:focus-visible {
  transform: translateY(-3px);
  box-shadow: 0 8px 18px var(--panel-shadow), 0 0 0 1px color-mix(in srgb, var(--tc) 50%, transparent);
  z-index: 2;
}
.ach-card:hover .ach-badge, .ach-card:focus-visible .ach-badge { transform: scale(1.12) rotate(-6deg); }
.ach-card.locked:hover .ach-icon { opacity: 0.8; filter: grayscale(0.5) brightness(0.9); }
.ach-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* First render: cards rise in one after another */
.ach-grid.intro .ach-card {
  animation: ach-in 0.45s cubic-bezier(.2,.8,.2,1) both;
  animation-delay: calc(min(var(--i, 0), 24) * 28ms);
}
@keyframes ach-in { from { opacity: 0; transform: translateY(10px) scale(0.94); } }

/* Just earned: the card pops and a burst of light rings the medal */
.ach-card.fresh { animation: ach-pop 0.7s cubic-bezier(.3,1.6,.5,1) both; }
.ach-card.fresh .ach-badge::after {
  content: ''; position: absolute; inset: -4px; border-radius: 50%;
  border: 2px solid var(--tc);
  animation: ach-ring 1.2s ease-out 0.15s 2 both;
}
@keyframes ach-pop {
  0% { transform: scale(0.6); opacity: 0; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}
@keyframes ach-ring { from { transform: scale(0.9); opacity: 0.9; } to { transform: scale(1.9); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .ach-card, .ach-card *, .ach-card::before, .ach-card::after { animation: none !important; transition: none !important; }
  .ach-card.unlocked::after { display: none; }
}

/* Floating description (achTooltip.js) — attached to <body>, so the panel can't clip it */
.ach-tooltip {
  position: fixed; left: 0; top: 0; z-index: 250;
  max-width: 260px; padding: 8px 10px; border-radius: 8px;
  background: var(--bg); border: 1px solid var(--accent);
  box-shadow: 0 6px 18px var(--panel-shadow);
  font-size: 12px; line-height: 1.4; color: var(--text);
  display: flex; flex-direction: column; gap: 2px;
  pointer-events: none; opacity: 0; visibility: hidden; transition: opacity 0.15s;
}
.ach-tooltip.visible { opacity: 1; visibility: visible; }
.ach-tooltip b { color: var(--cursor); font-size: 13px; }
.ach-tooltip em { font-style: normal; font-size: 11px; color: var(--dim); }
.ach-tooltip em.ok { color: var(--correct); }

/* ============ OWN TRAINING PANEL: text settings + Start ============ */
.train-panel {
  flex-direction: column; gap: 6px;
  padding: 10px 12px;
  background: var(--panel); border-radius: 10px;
  transition: background 0.3s;
}
.train-panel h2 {
  margin: 0 0 2px; font-size: 10px; font-weight: 600;
  color: var(--cursor); text-transform: uppercase; letter-spacing: 1px;
}
.train-panel select {
  width: 100%; padding: 6px 8px; font-size: 12px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--key-border); border-radius: 6px;
  cursor: pointer; font-family: inherit; font-weight: 500;
  transition: border-color 0.15s;
}
.train-panel select:hover { border-color: var(--accent); }
.train-panel .start-btn { width: 100%; margin-top: 2px; align-items: center; text-align: center; }
.train-panel .start-btn:hover { transform: scale(1.02); }

/* ============ CONTROLS ROW ============ */
.controls-row {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding: 10px 14px; margin-bottom: 0;
  background: var(--panel); border-radius: 10px;
  transition: background 0.3s;
  align-items: center;
}
.controls-row button, .controls-row select {
  padding: 7px 14px; font-size: 12px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--key-border); border-radius: 6px;
  cursor: pointer; font-family: inherit;
  transition: all 0.15s; font-weight: 500;
}
.controls-row button:hover, .controls-row select:hover { border-color: var(--accent); }
.controls-row button.primary { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 600; }
.controls-row button.primary:hover { filter: brightness(1.12); }
.controls-row button.ghost { background: transparent; color: var(--dim); border-color: transparent; }
.controls-row button.ghost:hover { color: var(--wrong); border-color: var(--wrong); }

#sidebar-btn-group {
  display: flex !important; flex-wrap: wrap !important;
  gap: 4px !important; margin-top: 6px !important;
  width: 100%;
}
#sidebar-btn-group button.small { font-size: 11px !important; padding: 5px 10px !important; flex: 0 1 auto; }

/* ============ START BUTTON ============ */
.start-btn {
  display: flex; flex-direction: column; align-items: flex-start;
  max-width: 100%; min-width: 0;
  padding: 6px 22px; border-radius: 10px; border: none;
  background: linear-gradient(135deg, var(--accent), var(--cursor));
  color: var(--bg); cursor: pointer; font-family: inherit; text-align: left;
  box-shadow: 0 4px 16px rgba(122,162,247,0.35), 0 0 24px rgba(224,175,104,0.15);
  transition: transform 0.15s, box-shadow 0.15s;
}
.start-btn:hover { transform: scale(1.04); box-shadow: 0 8px 28px rgba(122,162,247,0.5), 0 0 40px rgba(224,175,104,0.3); }
.start-btn:active { transform: scale(0.97); }
.start-main { font-size: 17px; font-weight: 700; letter-spacing: 1px; line-height: 1.2; }
.start-what {
  font-size: 11px; font-weight: 600; opacity: 0.8; line-height: 1.2; max-width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.start-what:empty { display: none; }

/* ============ BACK BUTTON ============ */
.back-btn {
  position: fixed; top: 16px; left: 16px; z-index: 50;
  font-size: 14px; font-weight: 600; padding: 10px 20px; border-radius: 10px;
  border: 1px solid var(--dim); background: var(--panel); color: var(--dim);
  cursor: pointer; font-family: inherit; transition: all 0.15s; backdrop-filter: blur(8px);
}
.back-btn:hover { border-color: var(--accent); color: var(--accent); background: rgba(122,162,247,0.1); }

/* ============ FOCUS-MODE COMPACT STATS ============ */
.focus-stats {
  display: flex; gap: 16px; justify-content: center; align-items: center;
  padding: 6px 14px; background: var(--panel); border-radius: 10px;
  margin-bottom: 4px; flex-wrap: wrap; transition: background 0.3s;
}
.focus-stats .fs-item { font-size: 12px; color: var(--dim); white-space: nowrap; }
.focus-stats .fs-item b { color: var(--accent); font-weight: 600; font-size: 14px; margin-left: 3px; font-variant-numeric: tabular-nums; }
/* Level progress bar (in place of the accuracy percent) */
.focus-stats .fs-progress { display: inline-flex; align-items: center; gap: 6px; }
.fs-progress-track {
  display: inline-block; width: 120px; height: 8px; border-radius: 4px;
  background: rgba(122,162,247,0.15); overflow: hidden;
}
.fs-progress-fill {
  display: block; height: 100%; width: 0; border-radius: 4px;
  background: var(--accent); transition: width 0.15s ease-out;
}

.focus-stats .fs-toggle {
  font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 8px;
  border: 1px solid var(--dim); background: transparent; color: var(--dim);
  cursor: pointer; font-family: inherit; transition: all 0.15s;
}
.focus-stats .fs-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* ============ HIDDEN TEXT PANEL (focus-stats toggle) ============
   Collapsed, not display:none — the panel keeps keyboard focus for typing. */
.app.focus-mode.hide-text .text-display {
  flex: 0 0 0; height: 0; min-height: 0; padding: 0; margin: 0;
  border: 0; box-shadow: none; opacity: 0; overflow: hidden;
}
.app.focus-mode.hide-text { justify-content: center; }
.app.focus-mode.hide-text .hands-wrap { cursor: text; }

/* ============ HIDDEN KEYBOARD (sidebar toggle) ============ */
.app.focus-mode.hide-keyboard .keyboard,
.app.focus-mode.hide-keyboard .layout-row { display: none !important; }

/* ============ SKINS (skins.js sets <html data-skin>) ============
   A skin brings its own dark and light palettes and draws its art on a fixed layer
   behind the page. High contrast (higher specificity, below) still wins. */
html[data-skin] body::before {
  content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: var(--skin-art);
}
.skin-note { color: var(--dim); font-size: 12px; margin: -8px 0 14px; }

html[data-skin="general"] {
  --bg: #0d0f24; --panel: rgba(28,30,62,0.86); --panel-2: rgba(40,43,84,0.9);
  --text: #dfe3ff; --dim: #7c82b8; --accent: #8c9eff; --cursor: #ffcb6b;
  --correct: #7ee0b5; --wrong: #ff7a9a; --key-border: rgba(140,158,255,0.18);
  --text-shadow: rgba(0,0,0,0.3); --panel-shadow: rgba(0,0,0,0.5); --key-text: var(--dim);
  --skin-art:
    url("../skins/general.svg") 0 0 / 480px 420px,
    radial-gradient(60% 45% at 15% 20%, rgba(94,234,212,0.18), transparent 70%),
    radial-gradient(55% 40% at 85% 30%, rgba(168,85,247,0.2), transparent 70%),
    radial-gradient(70% 50% at 50% 100%, rgba(59,130,246,0.18), transparent 70%),
    #0d0f24;
}
html[data-skin="general"] body::before { background-size: 480px 420px, 140% 140%, 140% 140%, 140% 140%, auto; animation: skinAurora 40s ease-in-out infinite alternate; }
@keyframes skinAurora {
  from { background-position: 0 0, 0% 0%, 100% 0%, 50% 100%, 0 0; }
  to   { background-position: 0 0, 30% 20%, 70% 30%, 40% 80%, 0 0; }
}

/* Programmer: green-on-black terminal with falling code and CRT scanlines */
html[data-skin="programmer"] {
  --bg: #020602; --panel: rgba(4,18,6,0.88); --panel-2: rgba(8,34,12,0.92);
  --text: #b6ffb0; --dim: #3f9a47; --accent: #39ff14; --cursor: #c6ff00;
  --correct: #39ff14; --wrong: #ff3b3b; --tt: #b6ffb0;
  --lp: #39ff14; --lr: #5cff3a; --lm: #7dff5e; --li: #a0ff82; --ri: #a0ff82; --rm: #7dff5e; --rr: #5cff3a; --rp: #39ff14;
  --key-border: rgba(57,255,20,0.25); --key-text: #6fdc68;
  --text-shadow: rgba(57,255,20,0.25); --panel-shadow: rgba(0,0,0,0.7);
  --skin-art:
    repeating-linear-gradient(0deg, rgba(0,0,0,0.35) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 45%, rgba(0,0,0,0.75) 100%),
    url("../skins/programmer.svg") 0 0 / 640px 560px,
    url("../skins/matrix.svg") 0 0 / 240px 480px,
    radial-gradient(80% 60% at 50% 40%, rgba(57,255,20,0.08), transparent 70%),
    #020602;
}
html[data-skin="programmer"] body { font-family: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace; }
html[data-skin="programmer"] body::before { animation: skinMatrix 30s linear infinite; }
html[data-skin="programmer"] :is(.top-frame, .level-map, .ach-panel, .text-display) {
  border: 1px solid rgba(57,255,20,0.22); box-shadow: 0 0 18px rgba(57,255,20,0.08) inset;
}
html[data-skin="programmer"] .char.correct { text-shadow: 0 0 6px rgba(57,255,20,0.6); }
@keyframes skinMatrix {
  from { background-position: 0 0, 0 0, 0 0, 0 0, 0 0, 0 0; }
  to   { background-position: 0 0, 0 0, 0 0, 0 480px, 0 0, 0 0; }
}

/* Writer: warm desk by lamplight, quill and ink */
html[data-skin="writer"] {
  --bg: #1a140f; --panel: rgba(42,33,25,0.88); --panel-2: rgba(58,46,35,0.92);
  --text: #f1e6d2; --dim: #a08c72; --accent: #d9a35b; --cursor: #e8c07a;
  --correct: #a9c47a; --wrong: #e0735f; --key-border: rgba(217,163,91,0.2);
  --text-shadow: rgba(0,0,0,0.35); --panel-shadow: rgba(0,0,0,0.55); --key-text: var(--dim);
  --skin-art:
    url("../skins/writer.svg") 0 0 / 620px 560px,
    repeating-linear-gradient(0deg, rgba(232,192,122,0.035) 0 1px, transparent 1px 32px),
    radial-gradient(60% 50% at 20% 10%, rgba(232,170,90,0.16), transparent 70%),
    #1a140f;
}
html[data-skin="writer"] .text-display { font-family: Georgia, "Times New Roman", serif; }

/* Accountant: ledger grid, figures and a calculator */
html[data-skin="accountant"] {
  --bg: #0b1915; --panel: rgba(16,36,30,0.88); --panel-2: rgba(24,52,43,0.92);
  --text: #dff5ec; --dim: #6fa391; --accent: #4fd1a5; --cursor: #f2c14e;
  --correct: #4fd1a5; --wrong: #ff6b6b; --key-border: rgba(79,209,165,0.2);
  --text-shadow: rgba(0,0,0,0.3); --panel-shadow: rgba(0,0,0,0.5); --key-text: var(--dim);
  --skin-art:
    url("../skins/accountant.svg") 0 0 / 600px 520px,
    linear-gradient(rgba(79,209,165,0.06) 1px, transparent 1px) 0 0 / 100% 24px,
    linear-gradient(90deg, rgba(79,209,165,0.06) 1px, transparent 1px) 0 0 / 96px 100%,
    linear-gradient(90deg, transparent 0 58px, rgba(242,193,78,0.12) 58px 60px, transparent 60px) 0 0 / 100% 100%,
    #0b1915;
}

/* Journalist: newsprint front page with a red BREAKING stamp */
html[data-skin="journalist"] {
  --bg: #141414; --panel: rgba(30,30,30,0.9); --panel-2: rgba(44,44,44,0.92);
  --text: #f0f0f0; --dim: #8f8f8f; --accent: #e63946; --cursor: #ffd166;
  --correct: #8bd17c; --wrong: #ff5c6c; --key-border: rgba(255,255,255,0.12);
  --text-shadow: rgba(0,0,0,0.35); --panel-shadow: rgba(0,0,0,0.6); --key-text: var(--dim);
  --skin-art:
    url("../skins/journalist.svg") 0 0 / 640px 560px,
    radial-gradient(rgba(255,255,255,0.035) 1px, transparent 1.2px) 0 0 / 5px 5px,
    #141414;
}
html[data-skin="journalist"] .top-frame { border-bottom: 3px double rgba(240,240,240,0.25); }

/* Student: chalkboard in a wooden frame */
html[data-skin="student"] {
  --bg: #1d3328; --panel: rgba(22,40,32,0.88); --panel-2: rgba(34,58,46,0.92);
  --text: #f4f4ea; --dim: #93ab9c; --accent: #ffe680; --cursor: #ffb86b;
  --correct: #b6f0a0; --wrong: #ff8f8f; --key-border: rgba(244,244,234,0.18);
  --text-shadow: rgba(0,0,0,0.3); --panel-shadow: rgba(0,0,0,0.5); --key-text: var(--dim);
  --skin-art:
    url("../skins/student.svg") 0 0 / 640px 560px,
    radial-gradient(70% 60% at 50% 50%, rgba(255,255,255,0.05), transparent 75%),
    #1d3328;
}
html[data-skin="student"] body::before { box-shadow: inset 0 0 0 10px #5b3a22, inset 0 0 0 12px #3b2414, inset 0 0 60px rgba(0,0,0,0.5); }

/* Doctor: calm clinic teal with a running heartbeat line */
html[data-skin="doctor"] {
  --bg: #071c26; --panel: rgba(12,38,50,0.88); --panel-2: rgba(18,54,70,0.92);
  --text: #e6f6f4; --dim: #7aa7ad; --accent: #4fd8c4; --cursor: #ffd27a;
  --correct: #6ee7b7; --wrong: #ff5a6e; --key-border: rgba(79,216,196,0.2);
  --text-shadow: rgba(0,0,0,0.3); --panel-shadow: rgba(0,0,0,0.5); --key-text: var(--dim);
  --skin-art:
    url("../skins/ecg.svg") 0 calc(100% - 40px) / 400px 200px repeat-x,
    url("../skins/doctor.svg") 0 0 / 600px 520px,
    linear-gradient(rgba(79,216,196,0.045) 1px, transparent 1px) 0 0 / 20px 20px,
    linear-gradient(90deg, rgba(79,216,196,0.045) 1px, transparent 1px) 0 0 / 20px 20px,
    #071c26;
}
html[data-skin="doctor"] body::before { animation: skinPulse 6s linear infinite; }
@keyframes skinPulse {
  from { background-position: 0 calc(100% - 40px), 0 0, 0 0, 0 0, 0 0; }
  to   { background-position: -400px calc(100% - 40px), 0 0, 0 0, 0 0, 0 0; }
}

/* Lawyer: mahogany library with gold scales and Latin maxims */
html[data-skin="lawyer"] {
  --bg: #1c1012; --panel: rgba(40,22,25,0.88); --panel-2: rgba(56,32,35,0.92);
  --text: #f3e9d8; --dim: #a8907e; --accent: #c9a227; --cursor: #e8c766;
  --correct: #9fcf86; --wrong: #ff6f6f; --key-border: rgba(201,162,39,0.22);
  --text-shadow: rgba(0,0,0,0.35); --panel-shadow: rgba(0,0,0,0.6); --key-text: var(--dim);
  --skin-art:
    url("../skins/lawyer.svg") 0 0 / 620px 560px,
    repeating-linear-gradient(90deg, rgba(0,0,0,0.12) 0 2px, transparent 2px 7px, rgba(255,255,255,0.015) 7px 9px, transparent 9px 16px),
    radial-gradient(70% 60% at 50% 0%, rgba(201,162,39,0.12), transparent 70%),
    #1c1012;
}
html[data-skin="lawyer"] :is(.top-frame, .level-map, .ach-panel, .text-display) { border: 1px solid rgba(201,162,39,0.25); }

/* Light theme: the art layer is inverted with its hues kept (dark green → light page,
   bright green → deep green), and each skin swaps to a light palette of its own. */
html.light-theme[data-skin] body::before { filter: invert(1) hue-rotate(180deg); }
html.light-theme[data-skin] {
  --text-shadow: rgba(255,255,255,0.5); --panel-shadow: rgba(0,0,0,0.12); --key-text: var(--text);
}
html.light-theme[data-skin="general"] {
  --bg: #f1f2ff; --panel: rgba(255,255,255,0.88); --panel-2: rgba(228,231,252,0.92);
  --text: #1e2150; --dim: #5d628f; --accent: #4f5bd5; --cursor: #c77700;
  --correct: #138a5e; --wrong: #c8284f; --key-border: rgba(79,91,213,0.25);
}
html.light-theme[data-skin="programmer"] {
  --bg: #f3fbf2; --panel: rgba(250,255,249,0.9); --panel-2: rgba(222,243,219,0.92);
  --text: #0b3d0b; --dim: #3e7a3e; --accent: #0a8f0a; --cursor: #6b8f00;
  --correct: #0a8f0a; --wrong: #c62828; --tt: #0b3d0b;
  --lp: #0a8f0a; --lr: #1f9a1f; --lm: #2f7d1f; --li: #3d6b14; --ri: #3d6b14; --rm: #2f7d1f; --rr: #1f9a1f; --rp: #0a8f0a;
  --key-border: rgba(10,143,10,0.3); --key-text: #145214;
}
html.light-theme[data-skin="programmer"] .char.correct { text-shadow: none; }
html.light-theme[data-skin="programmer"] :is(.top-frame, .level-map, .ach-panel, .text-display) {
  border-color: rgba(10,143,10,0.3); box-shadow: none;
}
html.light-theme[data-skin="writer"] {
  --bg: #f7f0e3; --panel: rgba(255,251,243,0.9); --panel-2: rgba(238,226,205,0.92);
  --text: #3a2a1a; --dim: #7d6649; --accent: #a8641c; --cursor: #b7791f;
  --correct: #4f7a28; --wrong: #b23a2a; --key-border: rgba(168,100,28,0.25);
}
html.light-theme[data-skin="accountant"] {
  --bg: #eef8f4; --panel: rgba(255,255,255,0.9); --panel-2: rgba(220,240,232,0.92);
  --text: #12352b; --dim: #4f7d6d; --accent: #11845f; --cursor: #a87a00;
  --correct: #11845f; --wrong: #c62828; --key-border: rgba(17,132,95,0.25);
}
html.light-theme[data-skin="journalist"] {
  --bg: #f4f2ec; --panel: rgba(255,255,253,0.92); --panel-2: rgba(232,229,220,0.94);
  --text: #1a1a1a; --dim: #66625a; --accent: #c1121f; --cursor: #b7791f;
  --correct: #2e7d32; --wrong: #c1121f; --key-border: rgba(0,0,0,0.15);
}
html.light-theme[data-skin="journalist"] .top-frame { border-bottom-color: rgba(0,0,0,0.25); }
html.light-theme[data-skin="student"] {
  --bg: #eef6f0; --panel: rgba(255,255,255,0.9); --panel-2: rgba(222,238,227,0.92);
  --text: #18352a; --dim: #557565; --accent: #a06a00; --cursor: #c4581a;
  --correct: #2e7d32; --wrong: #c62828; --key-border: rgba(24,53,42,0.2);
}
html.light-theme[data-skin="doctor"] {
  --bg: #eef8fa; --panel: rgba(255,255,255,0.9); --panel-2: rgba(219,239,243,0.92);
  --text: #0e3442; --dim: #4d7884; --accent: #0f8f80; --cursor: #b7791f;
  --correct: #138a5e; --wrong: #d03a50; --key-border: rgba(15,143,128,0.25);
}
html.light-theme[data-skin="lawyer"] {
  --bg: #f8f1ea; --panel: rgba(255,251,246,0.9); --panel-2: rgba(240,226,214,0.92);
  --text: #3a1d20; --dim: #7e5f55; --accent: #8a6a00; --cursor: #a8550f;
  --correct: #4f7a28; --wrong: #b3261e; --key-border: rgba(138,106,0,0.28);
}
html.light-theme[data-skin="lawyer"] :is(.top-frame, .level-map, .ach-panel, .text-display) { border-color: rgba(138,106,0,0.3); }

@media (prefers-reduced-motion: reduce) {
  html[data-skin] body::before { animation: none !important; }
}

/* ============ HIGH CONTRAST ============ */
:root.high-contrast {
  --text: #ffffff;
  --dim: #b4bce0;
  --panel: #10121a;
  --panel-2: #1c1f2c;
  --key-border: #6b74a0;
  --key-text: #ffffff;
  --bg: #000000;
}
:root.high-contrast.light-theme {
  --text: #000000;
  --dim: #2e3440;
  --panel: #ffffff;
  --panel-2: #eef0f4;
  --key-border: #5b6274;
  --key-text: #000000;
  --bg: #ffffff;
}
:root.high-contrast .char.current { outline: 2px solid var(--text); }
:root.high-contrast .char.wrong { text-decoration: underline wavy; }

/* ============ ONBOARDING ============ */
.onboarding-card { max-width: 440px !important; text-align: center; }
.onb-icon { font-size: 44px; margin-bottom: 6px; }
.onb-text { color: var(--dim); line-height: 1.55; font-size: 15px; margin: 0 0 16px; }
.onb-text b { color: var(--text); }
.onb-dots { display: flex; gap: 6px; justify-content: center; margin-bottom: 14px; }
.onb-dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--panel-2); }
.onb-dots span.on { background: var(--accent); }
.onboarding-card .modal-actions { justify-content: center; }

/* Visible to screen readers and search engines, not on screen */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.noscript-about { max-width: 640px; margin: 40px auto; line-height: 1.6; }

/* ============ GROUPS & RACES ============ */
.social-modal { max-width: 620px !important; width: 94%; }
.social-note { color: var(--dim); font-size: 14px; line-height: 1.5; margin: 0 0 12px; }
.social-note.small { font-size: 12px; }
.social-note b { color: var(--text); }
.grp-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.grp-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--key-border); color: var(--text); cursor: pointer; text-align: left; font-family: inherit; font-size: 14px; }
.grp-item:hover { border-color: var(--accent); }
.grp-item span { color: var(--dim); font-size: 12px; }
.grp-forms { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.grp-form { display: flex; gap: 8px; }
.grp-form input { flex: 1; margin: 0 !important; }
.grp-form button { white-space: nowrap; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--key-border); background: var(--panel-2); color: var(--text); cursor: pointer; font-family: inherit; }
.grp-form .primary-btn { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.grp-code, .race-code { font-family: "SF Mono", Menlo, monospace; letter-spacing: 3px; color: var(--cursor) !important; }
.race-code { font-size: 40px; font-weight: 700; text-align: center; margin: 4px 0 12px; }
.grp-table-wrap { overflow-x: auto; margin-bottom: 8px; }
.grp-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.grp-table th { text-align: left; color: var(--dim); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; padding: 6px; border-bottom: 1px solid var(--key-border); }
.grp-table td { padding: 6px; border-bottom: 1px solid var(--panel-2); color: var(--text); white-space: nowrap; }
.modal .modal-actions .danger-btn { color: var(--wrong); }
.race-players { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 12px; font-size: 14px; }
.race-players span { padding: 4px 10px; border-radius: 12px; background: var(--panel-2); }
.race-bar { background: var(--panel); border-radius: 10px; padding: 8px 12px; margin-bottom: 4px; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.app.start-mode .race-bar { display: none !important; }
.race-status { color: var(--dim); }
.race-status b { color: var(--cursor); font-family: "SF Mono", Menlo, monospace; letter-spacing: 2px; }
.race-row { display: grid; grid-template-columns: minmax(80px, 160px) 1fr 70px; align-items: center; gap: 8px; }
.race-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.race-track { height: 8px; border-radius: 4px; background: var(--panel-2); overflow: hidden; }
.race-fill { display: block; height: 100%; background: var(--accent); transition: width 0.4s; }
.race-wpm { text-align: right; color: var(--dim); font-variant-numeric: tabular-nums; }

/* ============ PLAYER CHAT ============ */
.chat-modal { display: flex; flex-direction: column; max-height: 90vh; }
.chat-tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 8px; padding-bottom: 2px; }
.chat-tab { flex: none; padding: 6px 12px; border-radius: 14px; border: 1px solid var(--key-border); background: var(--panel-2); color: var(--dim); cursor: pointer; font-family: inherit; font-size: 13px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-tab:hover { color: var(--text); }
.chat-tab.active { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.chat-log { height: 340px; max-height: 50vh; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 10px; margin-bottom: 10px; border-radius: 8px; background: var(--panel-2); }
.chat-empty { margin: auto; text-align: center; }
.chat-older { align-self: center; padding: 4px 12px; border-radius: 12px; border: 1px solid var(--key-border); background: transparent; color: var(--dim); cursor: pointer; font-family: inherit; font-size: 12px; }
.chat-older:hover { color: var(--text); }
.chat-msg { max-width: 85%; align-self: flex-start; padding: 6px 10px; border-radius: 10px; background: var(--panel); }
.chat-msg.mine { align-self: flex-end; background: color-mix(in srgb, var(--accent) 18%, var(--panel)); }
.chat-meta { display: flex; align-items: baseline; gap: 8px; font-size: 12px; }
.chat-name { padding: 0; border: 0; background: none; color: var(--accent); font-weight: 600; font-family: inherit; font-size: 12px; cursor: pointer; }
.chat-name:hover { text-decoration: underline; }
.chat-time { color: var(--dim); font-size: 11px; }
.chat-del { margin-left: auto; padding: 0 2px; border: 0; background: none; color: var(--dim); cursor: pointer; font-size: 11px; opacity: 0; }
.chat-msg:hover .chat-del, .chat-del:focus { opacity: 1; }
.chat-del:hover { color: var(--wrong); }
.chat-body { color: var(--text); font-size: 14px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-form { display: flex; gap: 8px; margin-bottom: 8px; }
.chat-form input { flex: 1; margin: 0 !important; }
.chat-form button { white-space: nowrap; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--accent); background: var(--accent); color: var(--bg); cursor: pointer; font-family: inherit; }
@media (hover: none) { .chat-del { opacity: 1; } }

/* ============ DAILY GOAL ============ */
.daily { width: 100%; margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }
.daily-row { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--dim); }
.daily-streak { font-weight: 700; color: var(--cursor); font-size: 14px; }
.daily-goal-select { margin-left: auto; font-size: 11px; padding: 2px 4px; border-radius: 5px; background: var(--panel-2); color: var(--text); border: 1px solid var(--key-border); }
.daily-bar { height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; }
.daily-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.4s; }
.daily.done .daily-fill { background: var(--correct); }
.daily-text { font-size: 11px; color: var(--dim); }
.daily.done .daily-text { color: var(--correct); }

/* ============ LESSON INFO ============ */
.lesson-info {
  text-align: center; font-size: 13px; color: var(--dim);
  padding: 4px 10px; margin-bottom: 4px;
}
.lesson-info b { color: var(--cursor); font-family: "SF Mono", Menlo, monospace; font-size: 15px; letter-spacing: 2px; }
.app.start-mode .lesson-info { display: none !important; }

/* ============ TEXT DISPLAY ============ */
.text-display {
  background: var(--panel); border-radius: 10px; padding: 24px;
  font-family: "SF Mono", Menlo, Monaco, monospace;
  font-size: 22px; line-height: 1.8; letter-spacing: 0.5px;
  user-select: none; cursor: text; min-height: 100px;
  position: relative; outline: none; margin-bottom: 0;
  transition: background 0.3s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  text-align: center;
}
.text-display.blurred::after {
  content: attr(data-hint-text);
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel); color: var(--dim);
  border-radius: 10px; font-size: 16px; font-family: inherit;
  pointer-events: none; font-weight: 600;
  text-shadow: 0 1px 3px rgba(0,0,0,0.15);
  box-shadow: inset 0 0 18px rgba(0,0,0,0.04);
  letter-spacing: 0.3px;
}
.char { color: var(--dim); transition: color 0.05s; }
.char.correct { color: var(--text); }
.char.wrong { color: var(--wrong); background: rgba(247,118,142,0.18); border-radius: 2px; }
.char.current { background: var(--cursor); color: var(--bg); border-radius: 3px; }
/* Space characters must preserve their whitespace so they render with visible width */
.char.space { white-space: pre; display: inline-block; min-width: 0.6em; }
/* A word's letters never split across lines; lines wrap only at spaces / newlines */
.text-display .word { display: inline-block; white-space: nowrap; }
.app.focus-mode .text-display.code-text { justify-content: flex-start; text-align: left; }
/* Forces a new line after ↵ (works both as a flex item and in block layout) */
.text-display .line-break { display: block; flex-basis: 100%; width: 100%; height: 0; }

/* ============ TYPE LINE (single-line copy above the keyboard) ============ */
.type-line {
  display: flex; width: 100%; max-width: 900px; margin-bottom: 8px;
  font-family: "SF Mono", Menlo, Monaco, monospace;
  font-size: 26px; line-height: 1.5; white-space: pre;
  background: var(--panel-2); border: 1px solid var(--key-border);
  border-radius: 8px; padding: 6px 0; user-select: none;
}
.type-line .tl-before { flex: 1 1 0; display: flex; justify-content: flex-end; overflow: hidden; }
.type-line .tl-after { flex: 1 1 0; display: flex; justify-content: flex-start; overflow: hidden; }
.type-line .tl-before { -webkit-mask-image: linear-gradient(to right, transparent, #000 40%); mask-image: linear-gradient(to right, transparent, #000 40%); }
.type-line .tl-after { -webkit-mask-image: linear-gradient(to left, transparent, #000 40%); mask-image: linear-gradient(to left, transparent, #000 40%); }
.type-line .char { flex-shrink: 0; }

/* ============ TYPING BUDDY (animal on the current letter, animal.js) ============ */
.type-line { position: relative; }
.type-line.has-buddy { padding-top: 2.45em; isolation: isolate; }
/* Scenery behind the buddy (.scenery in index.html): a soft sky and three layers that scroll
   at different speeds as it walks, like a platformer. animal.js counts the steps in --walk.
   It stays in the strip above the letters, faint and low-contrast, so nothing competes with the text */
.type-line .scenery { display: none; }
.type-line.has-buddy .scenery {
  display: block; position: absolute; z-index: -1; pointer-events: none; overflow: hidden;
  left: 0; right: 0; top: 0; bottom: calc(6px + 1.45em);
  border-radius: 8px 8px 0 0;
  border-bottom: 1px solid color-mix(in srgb, var(--dim) 35%, transparent);
  background: linear-gradient(to bottom, color-mix(in srgb, var(--accent) 9%, var(--panel-2)), var(--panel-2));
  --walk: 0; --step-ms: 200ms;
}
.scenery > i {
  position: absolute; left: 0; right: 0; bottom: 0;
  -webkit-mask-repeat: repeat-x; mask-repeat: repeat-x;
  transition: -webkit-mask-position var(--step-ms) ease-out, mask-position var(--step-ms) ease-out;
}
/* Far hills and clouds: barely move */
.scenery .sc-far {
  top: 0.4em; background-color: color-mix(in srgb, var(--dim) 14%, transparent);
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 40' preserveAspectRatio='none'%3E%3Cellipse cx='70' cy='7' rx='22' ry='3.5'/%3E%3Cellipse cx='86' cy='5' rx='10' ry='3'/%3E%3Cellipse cx='275' cy='10' rx='18' ry='3'/%3E%3Cellipse cx='288' cy='8' rx='8' ry='2.5'/%3E%3Cpath d='M0 40V24C40 16 70 10 110 18S170 30 210 22 280 6 320 14 380 26 400 24V40Z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 40' preserveAspectRatio='none'%3E%3Cellipse cx='70' cy='7' rx='22' ry='3.5'/%3E%3Cellipse cx='86' cy='5' rx='10' ry='3'/%3E%3Cellipse cx='275' cy='10' rx='18' ry='3'/%3E%3Cellipse cx='288' cy='8' rx='8' ry='2.5'/%3E%3Cpath d='M0 40V24C40 16 70 10 110 18S170 30 210 22 280 6 320 14 380 26 400 24V40Z'/%3E%3C/svg%3E");
  -webkit-mask-size: 400px 100%; mask-size: 400px 100%;
  -webkit-mask-position: calc(var(--walk) * -0.12ch) 0; mask-position: calc(var(--walk) * -0.12ch) 0;
}
/* Near hills with a few pines: a bit faster */
.scenery .sc-near {
  top: 0.9em; background-color: color-mix(in srgb, var(--dim) 22%, transparent);
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 40' preserveAspectRatio='none'%3E%3Cpath d='M0 40V32C40 28 70 26 110 30S180 36 220 31 270 28 300 32V40Z'/%3E%3Cpath d='M60 29l5-11 5 11Z M68 29l3.5-8 3.5 8Z M200 32l4-9 4 9Z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 40' preserveAspectRatio='none'%3E%3Cpath d='M0 40V32C40 28 70 26 110 30S180 36 220 31 270 28 300 32V40Z'/%3E%3Cpath d='M60 29l5-11 5 11Z M68 29l3.5-8 3.5 8Z M200 32l4-9 4 9Z'/%3E%3C/svg%3E");
  -webkit-mask-size: 300px 100%; mask-size: 300px 100%;
  -webkit-mask-position: calc(var(--walk) * -0.35ch) 0; mask-position: calc(var(--walk) * -0.35ch) 0;
}
/* Grass and pebbles under the feet: move with the letters, one letter per step */
.scenery .sc-ground {
  height: 0.3em; background-color: color-mix(in srgb, var(--dim) 40%, transparent);
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 90 10' preserveAspectRatio='none'%3E%3Cpath d='M6 10l1.5-6 1.5 6Z M9 10l1-4 1 4Z M37 10l1.2-4 1.2 4Z M64 10l1.5-7 1.5 7Z M67.5 10l1-4.5 1 4.5Z'/%3E%3Cellipse cx='24' cy='9.4' rx='2.5' ry='1'/%3E%3Cellipse cx='80' cy='9.6' rx='1.6' ry='0.7'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 90 10' preserveAspectRatio='none'%3E%3Cpath d='M6 10l1.5-6 1.5 6Z M9 10l1-4 1 4Z M37 10l1.2-4 1.2 4Z M64 10l1.5-7 1.5 7Z M67.5 10l1-4.5 1 4.5Z'/%3E%3Cellipse cx='24' cy='9.4' rx='2.5' ry='1'/%3E%3Cellipse cx='80' cy='9.6' rx='1.6' ry='0.7'/%3E%3C/svg%3E");
  -webkit-mask-size: 9ch 100%; mask-size: 9ch 100%;
  -webkit-mask-position: calc(var(--walk) * -1ch) 0; mask-position: calc(var(--walk) * -1ch) 0;
}
@media (prefers-reduced-motion: reduce) { .scenery > i { transition: none; } }
/* The animal replaces the highlight: the current letter is just bold and accented */
.type-line.has-buddy .char.current { background: none; color: var(--cursor); font-weight: 700; border-radius: 0; box-shadow: inset 0 -2px 0 var(--cursor); }
.buddy {
  /* Feet ~0.2em above the tallest letters (Й, Б, Д start ~0.17em below the line box top):
     strip padding-bottom (6px) + line box (1.5em) + 0.03em, minus the 0.08em below the feet in the SVG */
  position: absolute; bottom: calc(6px + 1.45em); left: calc(50% + 0.5ch);
  width: 2.4em; height: 2.4em; transform: translateX(-56%);
  pointer-events: none; z-index: 2;
}
.buddy-svg { width: 100%; height: 100%; overflow: visible; display: block; transform-origin: 50% 95%; }
.buddy .an-sclera { fill: #fff; stroke: #1b1a20; stroke-width: 0.6; }
.buddy .an-pupil { fill: #1b1a20; }
.buddy .an-glint { fill: #fff; }
.buddy .an-sclera, .buddy .an-pupil, .buddy .an-glint, .buddy .an-brow, .buddy .an-mouth, .buddy .an-sweat {
  transform-box: fill-box; transform-origin: center; transition: transform 0.18s, opacity 0.18s;
}
.buddy .an-brow { fill: none; stroke: #1b1a20; stroke-width: 1.1; stroke-linecap: round; opacity: 0; }
.buddy .an-mouth-calm { fill: none; stroke: #1b1a20; stroke-width: 0.8; stroke-linecap: round; }
.buddy .an-mouth-scared { fill: #4a1d24; opacity: 0; }
.buddy .an-sweat { fill: #7dcfff; opacity: 0; }
/* 1 · alert: eyes wider */
.buddy[data-fear="1"] .an-sclera { transform: scale(1.2); }
.buddy[data-fear="1"] .an-pupil { transform: scale(0.85); }
/* 2 · scared: big eyes, small pupils, raised brows, a sweat drop */
.buddy[data-fear="2"] .an-sclera { transform: scale(1.45); }
.buddy[data-fear="2"] .an-pupil, .buddy[data-fear="2"] .an-glint { transform: scale(0.6); }
.buddy[data-fear="2"] .an-brow { opacity: 1; transform: translateY(-2.2px) rotate(-8deg); }
.buddy[data-fear="2"] .an-sweat-1 { opacity: 1; }
/* 3 · terrified: pinpoint pupils, open mouth, two drops, trembling */
.buddy[data-fear="3"] .an-sclera { transform: scale(1.7); }
.buddy[data-fear="3"] .an-pupil { transform: scale(0.38); }
.buddy[data-fear="3"] .an-glint { opacity: 0; }
.buddy[data-fear="3"] .an-brow { opacity: 1; transform: translateY(-3.4px) rotate(-16deg); }
.buddy[data-fear="3"] .an-mouth-calm { opacity: 0; }
.buddy[data-fear="3"] .an-mouth-scared { opacity: 1; }
.buddy[data-fear="3"] .an-sweat { opacity: 1; }
.buddy[data-fear="3"] .an-body, .buddy[data-fear="3"] .an-face { animation: buddyTremble 0.12s linear infinite; }
@keyframes buddyTremble { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(0.5px); } }
/* Standing still it breathes, wags its tail and looks about; the head and tail
   turn around their own pivots (set inline in animal.js) */
.buddy .an-body { transform-box: fill-box; transform-origin: 50% 100%; animation: buddyBreath 2.8s ease-in-out infinite; }
.buddy .an-head { animation: buddyHeadIdle 4.2s ease-in-out infinite; transition: transform 0.3s; }
.buddy .an-tail { animation: buddyWag 1.6s ease-in-out infinite; }
@keyframes buddyBreath { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.015, 1.035); } }
@keyframes buddyHeadIdle {
  0%, 30%, 100% { transform: rotate(0deg); }
  38%, 52% { transform: rotate(-7deg); }
  60%, 70% { transform: rotate(4deg); }
  76% { transform: rotate(-2deg); }
}
@keyframes buddyWag { 0%, 100% { transform: rotate(-12deg); } 50% { transform: rotate(14deg); } }
/* Legs swing from the hip and bend at the knee while it moves; faster gaits are quicker */
.buddy .an-leg, .buddy .an-shin { transform-box: fill-box; transform-origin: 50% 0; }
.buddy.moving .an-leg.a { animation: buddyLegA 0.24s ease-in-out infinite; }
.buddy.moving .an-leg.b { animation: buddyLegB 0.24s ease-in-out infinite; }
.buddy.moving .an-leg.a .an-shin { animation: buddyKneeA 0.24s ease-in-out infinite; }
.buddy.moving .an-leg.b .an-shin { animation: buddyKneeB 0.24s ease-in-out infinite; }
.buddy.moving[data-gait="run"] .an-leg, .buddy.moving[data-gait="run"] .an-shin { animation-duration: 0.17s; }
.buddy.moving[data-gait="jump"] .an-leg.a { animation: buddyTuck 0.15s ease-out infinite; }
.buddy.moving[data-gait="jump"] .an-leg.b { animation: buddyTuck 0.15s ease-out infinite reverse; }
.buddy.moving[data-gait="jump"] .an-shin { animation: buddyKneeTuck 0.15s ease-out infinite; }
@keyframes buddyLegA { 0%, 100% { transform: rotate(18deg); } 50% { transform: rotate(-18deg); } }
@keyframes buddyLegB { 0%, 100% { transform: rotate(-18deg); } 50% { transform: rotate(18deg); } }
/* The shin folds back while the leg is carried forward, then straightens to land */
@keyframes buddyKneeA { 0%, 50%, 100% { transform: rotate(0deg); } 75% { transform: rotate(40deg); } }
@keyframes buddyKneeB { 0%, 50%, 100% { transform: rotate(0deg); } 25% { transform: rotate(40deg); } }
@keyframes buddyTuck { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(28deg) scaleY(0.8); } }
@keyframes buddyKneeTuck { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(55deg); } }
/* Moving: the head nods with every stride and the tail flicks faster */
.buddy.moving .an-head { animation: buddyNod 0.24s ease-in-out infinite; }
.buddy.moving[data-gait="run"] .an-head { animation-duration: 0.17s; }
.buddy.moving[data-gait="jump"] .an-head { animation: buddyHeadUp 0.15s ease-out infinite; }
.buddy.moving .an-tail { animation-duration: 0.3s; }
@keyframes buddyNod { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(7deg); } }
@keyframes buddyHeadUp { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(-14deg); } }
/* Wrong key: front legs fly up like hands, the head jerks back */
.buddy.oops .an-leg.front { animation: buddyHandsUp 0.5s ease-out; }
.buddy.oops .an-leg.front .an-shin { animation: buddyElbow 0.5s ease-out; }
.buddy.oops .an-leg.front.b { animation-delay: 0.04s; }
.buddy.oops .an-head { animation: buddyRecoil 0.5s ease-out; }
@keyframes buddyHandsUp { 0%, 100% { transform: rotate(0deg); } 30%, 60% { transform: rotate(-70deg); } }
@keyframes buddyElbow { 0%, 100% { transform: rotate(0deg); } 30%, 60% { transform: rotate(60deg); } }
@keyframes buddyRecoil { 0%, 100% { transform: rotate(0deg); } 25% { transform: rotate(-20deg); } 55% { transform: rotate(-12deg); } }
/* Eyelid: open (collapsed to the top edge) unless blinking or sleepy */
.buddy .an-lid { transform-box: fill-box; transform-origin: 50% 0; transform: scaleY(0); }
.buddy .an-zzz { opacity: 0; }
.buddy .an-zzz text { font: 700 5px sans-serif; fill: #a9b1d6; }
/* Bored (no typing for a few seconds): looks behind and back, eyes dart, blinks */
.buddy[data-idle="bored"] .buddy-svg { animation: buddyLook 6s ease-in-out infinite; }
.buddy[data-idle="bored"] .an-pupil { animation: buddyDart 3s ease-in-out infinite; }
.buddy[data-idle="bored"] .an-lid { animation: buddyBlink 3.5s infinite; }
@keyframes buddyLook {
  0%, 28% { transform: scaleX(1) rotate(0deg); }
  34%, 54% { transform: scaleX(-1) rotate(0deg); }
  60%, 72% { transform: scaleX(1) rotate(0deg); }
  78%, 88% { transform: scaleX(1) rotate(-6deg); }
  94%, 100% { transform: scaleX(1) rotate(0deg); }
}
@keyframes buddyDart { 0%, 20%, 100% { transform: translateX(0); } 35%, 50% { transform: translateX(-1px); } 65%, 80% { transform: translateX(0.9px); } }
@keyframes buddyBlink { 0%, 44%, 52%, 100% { transform: scaleY(0); } 48% { transform: scaleY(1); } }
/* …taps a front hoof impatiently and tilts its head up and down */
.buddy[data-idle="bored"] .an-leg.front.b { animation: buddyTap 1.4s ease-in-out infinite; }
.buddy[data-idle="bored"] .an-leg.front.b .an-shin { animation: buddyTapKnee 1.4s ease-in-out infinite; }
.buddy[data-idle="bored"] .an-head { animation: buddyHeadBored 6s ease-in-out infinite; }
@keyframes buddyTap { 0%, 40%, 60%, 100% { transform: rotate(0deg); } 50%, 90% { transform: rotate(-24deg); } }
@keyframes buddyTapKnee { 0%, 40%, 60%, 100% { transform: rotate(0deg); } 50%, 90% { transform: rotate(30deg); } }
@keyframes buddyHeadBored {
  0%, 20%, 100% { transform: rotate(0deg); }
  28%, 40% { transform: rotate(-12deg); }
  48%, 62% { transform: rotate(8deg); }
  70% { transform: rotate(-3deg); }
}
/* Sleepy (a long pause): heavy eyelids, slow breathing, floating z z z */
.buddy[data-idle="sleepy"] .an-lid { transform: scaleY(0.62); }
.buddy[data-idle="sleepy"] .an-mouth-calm { transform: scaleX(0.6); }
.buddy[data-idle="sleepy"] .an-body { animation: buddyBreath 4s ease-in-out infinite; }
/* The head droops and slowly bobs; the tail rests */
.buddy[data-idle="sleepy"] .an-head { animation: buddyDoze 4s ease-in-out infinite; }
.buddy[data-idle="sleepy"] .an-tail { animation: none; transform: rotate(18deg); }
@keyframes buddyDoze { 0%, 100% { transform: rotate(16deg); } 50% { transform: rotate(21deg); } }
.buddy[data-idle="sleepy"] .an-zzz { opacity: 1; }
.buddy[data-idle="sleepy"] .an-zzz text { animation: buddyZ 3s ease-in infinite; opacity: 0; }
.buddy[data-idle="sleepy"] .an-zzz .z2 { animation-delay: 1s; }
.buddy[data-idle="sleepy"] .an-zzz .z3 { animation-delay: 2s; }
@keyframes buddyZ { 0% { opacity: 0; transform: translate(0, 2px); } 30% { opacity: 1; } 100% { opacity: 0; transform: translate(3px, -4px); } }
/* ---- Per-animal ways of moving (data-kind / data-move set in animal.js) ---- */
/* Owl: yellow eyes; takes off when you type, flaps faster the faster you go, lands after a pause */
.buddy-svg.kind-owl .an-sclera { fill: #ffd23f; }
.buddy .an-fly { transition: transform 0.35s ease-out; }
.buddy .an-wing { transition: transform 0.25s; }
.buddy.airborne .an-fly { transform: translateY(-8px); }
.buddy.airborne .an-wing { animation: buddyFlap 0.24s ease-in-out infinite; }
.buddy.airborne[data-fear="2"] .an-wing { animation-duration: 0.16s; }
.buddy.airborne[data-fear="3"] .an-wing { animation-duration: 0.11s; }
.buddy.airborne .an-leg.a, .buddy.airborne .an-leg.b { animation: none; transform: rotate(45deg); }
.buddy.airborne .an-leg .an-shin { animation: none; }
.buddy.airborne .an-head { animation: buddyHeadUp 0.48s ease-in-out infinite; }
@keyframes buddyFlap { 0%, 100% { transform: rotate(25deg); } 50% { transform: rotate(125deg); } }
/* A mistake: wings flare up */
.buddy.oops .an-wing { animation: buddyWingFlare 0.5s ease-out; }
@keyframes buddyWingFlare { 0%, 100% { transform: rotate(0deg); } 30%, 60% { transform: rotate(115deg); } }
/* Pigeon: struts with its head jerking forward and back on every step */
.buddy[data-kind="pigeon"].moving .an-head { animation: buddyPigeonBob 0.24s ease-in-out infinite; }
.buddy[data-kind="pigeon"].moving[data-gait="run"] .an-head { animation-duration: 0.17s; }
@keyframes buddyPigeonBob { 0%, 100% { transform: translateX(-1.6px); } 45% { transform: translateX(2.2px); } }
/* Mantis: its six thin legs scurry fast; the abdomen only sways a little */
.buddy[data-kind="mantis"].moving .an-leg.a, .buddy[data-kind="mantis"].moving .an-leg.b,
.buddy[data-kind="mantis"].moving .an-leg .an-shin { animation-duration: 0.12s; }
.buddy[data-kind="mantis"] .an-tail { animation-name: buddyMantisSway; }
.buddy[data-kind="mantis"][data-idle="sleepy"] .an-tail { transform: rotate(3deg); }
@keyframes buddyMantisSway { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(3deg); } }
/* Dog: wags happily even standing still */
.buddy[data-kind="dog"]:not(.moving):not([data-idle="sleepy"]) .an-tail { animation-duration: 0.55s; }
@media (prefers-reduced-motion: reduce) {
  .buddy .an-leg, .buddy .an-shin, .buddy .an-head, .buddy .an-tail, .buddy .an-body, .buddy .an-face, .buddy .buddy-svg, .buddy .an-pupil, .buddy .an-lid, .buddy .an-zzz text { animation: none !important; }
  .buddy[data-idle="sleepy"] .an-zzz text { opacity: 1; }
}

/* ============ HANDS ============ */
.hands-wrap {
  background: var(--panel); border-radius: 10px;
  padding: 14px 10px 12px; margin-bottom: 0;
  transition: background 0.3s;
  display: flex; flex-direction: column; align-items: center;
}
.hint-line {
  text-align: center; color: var(--dim);
  font-size: 13px; margin-bottom: 8px;
  font-family: "SF Mono", monospace; min-height: 20px;
  display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap;
}
.hint-line b { color: var(--cursor); font-weight: 600; }
.hint-line .hint-arrow {
  display: inline-block; color: var(--accent); font-size: 16px;
  animation: hintArrowBounce 0.6s ease-in-out infinite alternate;
}
@keyframes hintArrowBounce { from { transform: translateY(0); opacity: 0.6; } to { transform: translateY(3px); opacity: 1; } }
.hands { display: flex; justify-content: center; align-items: flex-end; gap: 12px; font-family: "SF Mono", Menlo, monospace; }
.hand { display: flex; gap: 5px; align-items: flex-end; }
.finger {
  display: flex; flex-direction: column; align-items: center;
  color: var(--dim); transition: all 0.1s; width: 56px;
}
.finger .shaft { font-size: 16px; line-height: 0.9; white-space: pre; text-align: center; color: inherit; }
.finger.f-lp { --c: var(--lp); } .finger.f-lr { --c: var(--lr); } .finger.f-lm { --c: var(--lm); } .finger.f-li { --c: var(--li); }
.finger.f-ri { --c: var(--ri); } .finger.f-rm { --c: var(--rm); } .finger.f-rr { --c: var(--rr); } .finger.f-rp { --c: var(--rp); }
.finger .tip { font-size: 14px; line-height: 1; color: inherit; }
.finger .home { margin-top: 3px; font-size: 12px; padding: 2px 8px; border-radius: 4px; background: rgba(255,255,255,0.04); color: var(--dim); min-width: 28px; text-align: center; font-weight: 500; }
.finger .name { margin-top: 3px; font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 56px; text-align: center; }
.finger.active { color: var(--c); }
.finger.active .shaft { text-shadow: 0 0 8px var(--c); }
.finger.active .home { color: var(--bg); background: var(--c); font-weight: 700; }
.finger.active .name { color: var(--c); }
.thumb-area { display: flex; flex-direction: column; align-items: center; margin: 0 6px; }
.thumb-bar { width: 100px; height: 14px; border-radius: 7px; background: rgba(128,128,128,0.06); border: 1px solid var(--key-border); transition: all 0.1s; }
.thumb-bar.active { background: var(--tt); box-shadow: 0 0 14px var(--tt); border-color: var(--tt); }
.thumb-label { font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 3px; white-space: nowrap; }

/* ============ KEYBOARD ============ */
.keyboard { display: flex; flex-direction: column; gap: 4px; --rg: 4px; margin-top: 10px; align-items: center; width: 100%; max-width: 100%; overflow: visible; }
.kb-row { display: flex; gap: 3px; --g: 3px; justify-content: center; flex-wrap: nowrap; }
.key {
  --k: 42px; height: 42px; display: flex; align-items: center; justify-content: center;
  border-radius: 6px; font-family: "SF Mono", monospace; font-size: 14px;
  background: var(--panel-2); color: var(--key-text);
  border: 1px solid var(--key-border);
  transition: background 0.1s, color 0.1s, border-color 0.1s, transform 0.08s;
  position: relative; user-select: none; font-weight: 500; flex-shrink: 0;
}
.key.shift { width: 72px; font-size: 16px; }
.key.space { width: 200px; font-size: 18px; }
/* Physical geometry (keyGeometry.js): --k is the 1u key size of the current
   screen mode, --u a key's width in key units, --cols the board width in
   units (15 PC, 14.5 MacBook). Keys shrink to fit the container so the
   whole board keeps its real proportions instead of wrapping. */
#keyboard { container-type: inline-size; }
#keyboard .key {
  --kw: min(var(--k, 42px), calc((100cqw - (var(--cols, 15) - 1) * var(--g, 3px)) / var(--cols, 15)));
  width: calc(var(--kw) * var(--u, 1) + var(--g, 3px) * (var(--u, 1) - 1));
}
.key.mod { flex-direction: column; gap: 1px; line-height: 1.05; opacity: 0.55; font-family: -apple-system, system-ui, sans-serif; overflow: hidden; }
.key.mod:not(.lp):not(.rp) { color: var(--dim); }
.key.mod.next { opacity: 1; }
.key.mod .mod-word { font-size: 0.62em; white-space: nowrap; }
.key.deco { opacity: 0.55; }
/* ISO Enter spans two rows: the narrower lower part joins the upper one. */
.key.enter-top { border-bottom-left-radius: 0; }
.key.enter-bottom { border-top-color: transparent; border-top-left-radius: 0; border-top-right-radius: 0; }
.key.enter-bottom::before {
  content: ''; position: absolute; left: -1px; right: -1px; bottom: 100%;
  height: calc(var(--rg, 4px) + 2px); background: inherit;
  border: 1px solid var(--key-border); border-top: 0; border-bottom: 0;
}
/* MacBook arrow cluster: full-height ◀ ▶, half-height ▲ ▼ stacked between. */
.kb-arrows { --u: 3; display: flex; gap: var(--g, 3px); flex-shrink: 0; }
.kb-arrows .key, .kb-arrows-v { --u: 1; }
.kb-arrows-v { display: flex; flex-direction: column; gap: 2px; }
#keyboard .kb-arrows-v .key { height: auto; flex: 1 1 0; min-height: 0; font-size: 0.6em; }
.kb-arrows > .key { font-size: 0.6em; }
@media (max-width: 800px) { .key.mod .mod-word { display: none; } }
.key.shift.next { background: var(--accent) !important; color: var(--bg) !important; border-color: var(--accent) !important; box-shadow: 0 0 20px var(--accent); transform: scale(1.1); z-index: 2; }
.key.lp { background: rgba(247,118,142,0.12); color: var(--lp); }
.key.lr { background: rgba(255,158,100,0.12); color: var(--lr); }
.key.lm { background: rgba(224,175,104,0.12); color: var(--lm); }
.key.li { background: rgba(158,206,106,0.12); color: var(--li); }
.key.ri { background: rgba(115,218,202,0.12); color: var(--ri); }
.key.rm { background: rgba(122,162,247,0.12); color: var(--rm); }
.key.rr { background: rgba(187,154,247,0.12); color: var(--rr); }
.key.rp { background: rgba(255,158,158,0.12); color: var(--rp); }
.key.tt { background: rgba(128,128,128,0.06); color: var(--text); }
.key.next { transform: scale(1.18); color: var(--bg) !important; font-weight: 700; box-shadow: 0 0 16px currentColor; z-index: 2; }
.key.next.lp { background: var(--lp); } .key.next.lr { background: var(--lr); } .key.next.lm { background: var(--lm); } .key.next.li { background: var(--li); }
.key.next.ri { background: var(--ri); } .key.next.rm { background: var(--rm); } .key.next.rr { background: var(--rr); } .key.next.rp { background: var(--rp); } .key.next.tt { background: var(--tt); }

/* ============ HOME-ROW KEY FINGER PADS ============ */
/* Each home-row key (A S D F / J K L ; and RU: Ф Ы В А / О Л Д Ж) and the
   space key gets a rounded fingertip pad drawn "on the button", colored by
   its finger zone. The pads form a natural semicircular arc across the home
   row (pinky lowest & smallest → middle highest & largest, index just below
   middle; the right hand mirrors the left), while the thumb — the biggest
   pad of all — rests on the lowest key (the space bar). */
.key .key-cap {
  position: absolute;
  left: 50%;
  bottom: 4px;
  transform: translateX(-50%);
  line-height: 1;
  z-index: 1;
}
.key .finger-mark {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  color: inherit;
  opacity: 0.95;
  pointer-events: none;
  z-index: 1;
  transition: opacity 0.15s, transform 0.15s;
}
.key .finger-mark svg {
  width: 100%;
  height: auto;
  display: block;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4));
}
/* Semicircular arc: pinky low & small → middle high & large */
.key .finger-mark.lp { top: 30%; width: 30%; }
.key .finger-mark.lr { top: 21%; width: 36%; }
.key .finger-mark.lm { top: 11%; width: 42%; }
.key .finger-mark.li { top: 17%; width: 40%; }
.key .finger-mark.ri { top: 17%; width: 40%; }
.key .finger-mark.rm { top: 11%; width: 42%; }
.key .finger-mark.rr { top: 21%; width: 36%; }
.key .finger-mark.rp { top: 30%; width: 30%; }
/* Thumb — biggest and lowest pad of all, on the (bottom-row) space key */
.key.space .finger-mark.tt {
  top: 24%;
  height: 60%;
}
.key.space .finger-mark.tt svg {
  width: auto;
  height: 100%;
}
.key:hover .finger-mark { opacity: 1; }
.key.next .finger-mark {
  color: rgba(255,255,255,0.92);
  opacity: 1;
  transform: translateX(-50%) scale(1.08);
}
/* Keep the finger visible during hit / wrong-press animations too */
.key.correct-hit .finger-mark,
.key.wrong-hit .finger-mark,
.key.combo-hit .finger-mark,
.key.actual-pressed .finger-mark {
  color: rgba(255,255,255,0.9);
}
/* Physical keyboard nubs on the left/right index home keys (F/J, А/О) */
.key.finger-bump::after {
  content: '';
  position: absolute;
  bottom: 1px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 1.5px;
  border-radius: 2px;
  background: rgba(128,128,128,0.45);
  pointer-events: none;
  z-index: 1;
}

/* ============ SVG ARROW OVERLAY ============ */
/* The arrow line dashes animate to show direction flow */
.arrow-overlay .arrow-line {
  animation: arrowDashFlow 0.5s linear infinite;
  filter: drop-shadow(0 0 3px currentColor);
}

@keyframes arrowDashFlow {
  to {
    stroke-dashoffset: -12;
  }
}

/* Arrow head triangle — no animation needed, just a subtle glow */
.arrow-overlay .arrow-head {
  filter: drop-shadow(0 0 4px currentColor);
}

/* ============ KEY HIT EFFECTS ============ */
.key.correct-hit { animation: correctHit 0.45s ease-out; }
@keyframes correctHit { 0% { transform: scale(1); } 30% { transform: scale(1.7); background: var(--correct) !important; color: var(--bg) !important; box-shadow: 0 0 40px var(--correct), 0 0 80px var(--correct); } 100% { transform: scale(1.18); } }
.key.wrong-hit { animation: wrongHit 0.45s ease-out; }
@keyframes wrongHit { 0%, 100% { transform: translateX(0); } 15% { transform: translateX(-8px); background: var(--wrong) !important; color: var(--bg) !important; } 30% { transform: translateX(8px); } 45% { transform: translateX(-6px); } 60% { transform: translateX(6px); } 75% { transform: translateX(-4px); } }
.key.combo-hit { animation: comboHit 0.6s ease-out; z-index: 3; }
@keyframes comboHit { 0% { transform: scale(1); } 25% { transform: scale(1.9) rotate(-8deg); background: var(--cursor) !important; color: var(--bg) !important; box-shadow: 0 0 50px var(--cursor), 0 0 100px var(--lr); } 50% { transform: scale(1.5) rotate(6deg); } 100% { transform: scale(1.18) rotate(0); } }
.key.actual-pressed { animation: pressedWrong 0.5s ease-out; }
@keyframes pressedWrong { 0% { transform: scale(1); } 20% { transform: scale(1.5); background: var(--wrong) !important; color: var(--bg) !important; box-shadow: 0 0 30px rgba(247,118,142,0.6); border-color: var(--wrong); } 50% { transform: scale(1.3); background: var(--wrong) !important; color: var(--bg) !important; } 100% { transform: scale(1); } }

/* ============ PARTICLES ============ */
/* Clipped layer for all effects (see effects.js): contain:paint makes it the containing block
   for the fixed-position effects and clips them, so off-screen animations can't affect layout */
/* Above the completion overlay (300) so held level-ups and achievements show over the results */
.fx-layer { position: fixed; inset: 0; overflow: hidden; contain: paint; pointer-events: none; z-index: 310; }
.particle { position: fixed; pointer-events: none; font-size: 16px; font-weight: 700; animation: floatUp 0.9s ease-out forwards; z-index: 90; transform: translate(-50%, 0); }
@keyframes floatUp { 0% { transform: translate(-50%, 0) scale(0.4); opacity: 0; } 20% { transform: translate(-50%, -10px) scale(1.3); opacity: 1; } 100% { transform: translate(-50%, -80px) scale(1); opacity: 0; } }
.spark { position: fixed; pointer-events: none; width: 6px; height: 6px; border-radius: 50%; z-index: 90; }

/* ============ GIFT FLY ============ */
.gift { position: fixed; font-size: 60px; pointer-events: none; z-index: 100; bottom: -80px; animation: giftFly 2.4s cubic-bezier(.4,0,.6,1) forwards; filter: drop-shadow(0 0 16px rgba(224,175,104,0.6)); }
@keyframes giftFly { 0% { transform: translateY(0) scale(0.4) rotate(0deg); opacity: 0; } 15% { opacity: 1; } 50% { transform: translateY(-60vh) scale(1.2) rotate(360deg); opacity: 1; } 100% { transform: translateY(-120vh) scale(0.8) rotate(720deg); opacity: 0; } }

/* ============ LEVEL UP ============ */
.flash { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(circle, rgba(255,255,255,0.5), transparent 60%); animation: flashAnim 0.8s ease-out forwards; z-index: 140; }
@keyframes flashAnim { from { opacity: 1; } to { opacity: 0; } }
.level-up-banner { position: fixed; top: 30%; left: 50%; transform: translate(-50%, -50%); background: linear-gradient(135deg, var(--accent), var(--cursor)); color: var(--bg); padding: 32px 60px; border-radius: 18px; font-size: 30px; font-weight: 700; box-shadow: 0 24px 80px var(--panel-shadow), 0 0 80px rgba(224,175,104,0.5); animation: levelUpBanner 2.4s ease-out forwards; z-index: 150; text-align: center; }
@keyframes levelUpBanner { 0% { transform: translate(-50%, -50%) scale(0) rotate(-10deg); opacity: 0; } 15% { transform: translate(-50%, -50%) scale(1.2) rotate(2deg); opacity: 1; } 25% { transform: translate(-50%, -50%) scale(1) rotate(0); } 85% { transform: translate(-50%, -50%) scale(1); opacity: 1; } 100% { transform: translate(-50%, -50%) scale(0.7); opacity: 0; } }

/* ============ TOAST ============ */
.toast-stack { position: fixed; top: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; max-height: calc(100vh - 40px); overflow: hidden; }
.toast { position: relative; background: var(--panel); border-left: 4px solid var(--cursor); padding: 16px 20px; border-radius: 8px; box-shadow: 0 12px 32px var(--panel-shadow); animation: toastIn 0.4s ease-out, toastOut 0.4s ease-in 3.6s forwards; z-index: 200; min-width: 300px; transition: background 0.3s; }
@keyframes toastIn { from { transform: translateX(110%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toastOut { to { transform: translateX(110%); opacity: 0; } }
.toast-title { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 6px; }
.toast-content { display: flex; align-items: center; gap: 12px; }
.toast-icon { width: 72px; height: 72px; flex-shrink: 0; filter: drop-shadow(0 0 10px color-mix(in srgb, var(--cursor) 45%, transparent)) drop-shadow(0 3px 4px rgba(0,0,0,0.4)); animation: toastIconIn 0.7s cubic-bezier(.3,1.6,.5,1) 0.15s both; }
@keyframes toastIconIn { from { transform: scale(0.4) rotate(-20deg); opacity: 0; } }
.toast-name { font-weight: 600; font-size: 15px; }
.toast-desc { font-size: 13px; color: var(--dim); }

/* ============ FOOTER ============ */
.footnote { color: var(--dim); font-size: 12px; margin-top: 0; text-align: center; line-height: 1.4; }
.footnote kbd { background: var(--panel); padding: 1px 5px; border-radius: 3px; font-family: "SF Mono", monospace; font-size: 11px; border: 1px solid var(--key-border); }
kbd { background: var(--panel); padding: 2px 6px; border-radius: 3px; font-family: "SF Mono", monospace; font-size: 11px; border: 1px solid var(--key-border); }

/* ============ COMPLETION OVERLAY ============ */
.completion-overlay { position: fixed; inset: 0; background: var(--overlay); display: flex; align-items: center; justify-content: center; z-index: 300; animation: fadeIn 0.3s ease-out; }
.completion-insight { margin: -8px 0 16px; font-size: 13px; color: var(--dim); }
.completion-insight b { color: var(--wrong); font-family: "SF Mono", Menlo, monospace; font-size: 15px; }

/* ============ STATISTICS WINDOW ============ */
.stats-modal { max-width: 640px !important; width: 94%; }
.stats-modal h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--dim); margin: 14px 0 8px; display: flex; align-items: center; gap: 10px; }
.stats-modal .stats-lang { width: auto !important; padding: 2px 6px !important; margin: 0 !important; font-size: 12px; }
.stats-chart-wrap { color: var(--dim); font-size: 13px; min-height: 40px; }
.stats-chart { width: 100%; height: auto; display: block; }
.stats-chart .axis { stroke: var(--key-border); stroke-width: 1; }
.stats-chart .tick { fill: var(--dim); font-size: 10px; }
.stats-chart .tick.acc { fill: var(--correct); }
.stats-chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.stats-chart .line.wpm { stroke: var(--accent); }
.stats-chart .line.acc { stroke: var(--correct); opacity: 0.7; }
.stats-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--dim); margin-top: 4px; }
.stats-legend .lg.wpm { color: var(--accent); }
.stats-legend .lg.acc { color: var(--correct); }
.heatmap { display: flex; flex-direction: column; gap: 3px; align-items: center; }
.hm-row { display: flex; gap: 3px; }
.hm-key { width: 32px; height: 32px; border-radius: 5px; display: flex; align-items: center; justify-content: center; font-family: "SF Mono", Menlo, monospace; font-size: 13px; color: #fff; font-weight: 600; text-shadow: 0 1px 2px rgba(0,0,0,0.4); }
.hm-key.empty { background: var(--panel-2); color: var(--dim); text-shadow: none; font-weight: 400; }
.stats-weak { text-align: center; font-size: 13px; color: var(--dim); margin: 10px 0 4px; }
.stats-weak b { color: var(--wrong); font-family: "SF Mono", Menlo, monospace; letter-spacing: 2px; font-size: 15px; }
@media (max-width: 480px) { .hm-key { width: 22px; height: 24px; font-size: 10px; } .hm-row { gap: 2px; } }
.completion-course { margin: 0 0 18px; padding: 10px 14px; border-radius: 10px; font-weight: 600; background: rgba(158,206,106,0.14); color: var(--correct); }
.completion-course.fail { background: rgba(224,175,104,0.14); color: var(--cursor); }
.completion-card { background: var(--panel); border-radius: 18px; padding: 36px 40px; width: 90%; max-width: 460px; box-shadow: 0 24px 80px var(--panel-shadow), 0 0 60px rgba(122,162,247,0.2); text-align: center; animation: cardSlideUp 0.4s ease-out; }
@keyframes cardSlideUp { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.completion-title { font-size: 26px; font-weight: 700; color: var(--correct); margin-bottom: 24px; }
.completion-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 28px; }
.cstat { background: var(--panel-2); border-radius: 10px; padding: 12px 10px; }
.cstat-xp { grid-column: 1 / -1; background: linear-gradient(135deg, rgba(224,175,104,0.15), rgba(122,162,247,0.15)); }
.cstat-label { display: block; font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 4px; }
.cstat-value { font-size: 28px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.cstat-xp .cstat-value { color: var(--cursor); }
.cstat-unit { font-size: 12px; color: var(--dim); margin-left: 2px; }
.completion-title.fail { color: var(--cursor); }
/* Lesson goal missed on this tile */
.cstat.miss { box-shadow: inset 0 0 0 2px var(--wrong); }
.cstat.miss .cstat-value { color: var(--wrong); }
.completion-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.completion-actions button { padding: 12px 28px; border-radius: 10px; font-size: 15px; font-weight: 600; cursor: pointer; font-family: inherit; border: none; transition: all 0.15s; }
.completion-actions .primary-btn { background: var(--accent); color: var(--bg); }
.completion-actions .primary-btn:hover { filter: brightness(1.15); transform: scale(1.04); }
.completion-actions .ghost-btn { background: transparent; color: var(--dim); border: 1px solid var(--dim); }
.completion-actions .ghost-btn:hover { color: var(--text); border-color: var(--text); }

/* ============ LAYOUT INDICATOR ============ */
.layout-row { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 6px; padding: 6px 12px; background: rgba(122,162,247,0.08); border-radius: 8px; border: 1px solid rgba(122,162,247,0.15); }
.layout-indicator { font-size: 13px; font-weight: 600; color: var(--accent); padding: 3px 10px; border-radius: 5px; background: rgba(122,162,247,0.12); animation: layoutPulse 1s ease-in-out infinite alternate; white-space: nowrap; }
.layout-indicator.ru { color: var(--lr); background: rgba(255,158,100,0.15); }
.layout-indicator.en { color: var(--accent); background: rgba(122,162,247,0.15); }
@keyframes layoutPulse { from { transform: scale(1); opacity: 0.7; } to { transform: scale(1.12); opacity: 1; } }
.layout-toggle { font-size: 13px; font-weight: 600; padding: 5px 18px; border-radius: 6px; border: 2px solid var(--accent); background: transparent; color: var(--accent); cursor: pointer; font-family: inherit; transition: all 0.15s; letter-spacing: 0.5px; }
.layout-toggle:hover { background: var(--accent); color: var(--bg); transform: scale(1.06); }
.layout-toggle:active { transform: scale(0.96); }
.layout-hint { font-size: 11px; color: var(--dim); opacity: 0.6; white-space: nowrap; }

.hidden { display: none !important; }

/* ========================================================================
   TWO-COLUMN LAYOUT — ALL SCREEN SIZES!
   Panels arranged side-by-side — no vertical stacking.
   Achievement panel is rectangular, fills available height.
   ======================================================================== */

/* ---- MOBILE (<= 480px) ---- */
@media (max-width: 480px) {
  .app.start-mode {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto 1fr auto;
    gap: 4px;
    min-height: calc(100vh - 12px);
    overflow: hidden;
  }

  .app.start-mode > .top-frame   { grid-column: 1 / -1; grid-row: 1; }

  /* Left column */
  .app.start-mode > .top-bar     { grid-column: 1; grid-row: 2; }
  .app.start-mode > .train-panel { grid-column: 1; grid-row: 3; }
  .app.start-mode > .controls-row { grid-column: 1; grid-row: 4; }

  /* Right column */
  .app.start-mode > .side-col {
    grid-column: 2;
    grid-row: 2 / 5;
    align-self: stretch;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .app.start-mode .ach-panel, .app.start-mode .level-map { padding: 8px; }

  .app.start-mode > .footnote    { grid-column: 1 / -1; grid-row: 5; }

  .app.start-mode .top-bar {
    flex-direction: column; align-items: flex-start; gap: 2px;
    padding: 5px 8px;
  }
  .lvl-badge { width: 28px; height: 28px; font-size: 12px; }
  .lvl-title { font-size: 10px; }
  .xp-compact { font-size: 9px; }
  .xp-mini { height: 4px; }
  .score-compact { text-align: left; margin-left: 0; width: 100%; }
  .sc-value { font-size: 14px; }


  .app.start-mode .controls-row {
    flex-direction: column; gap: 2px; padding: 4px 8px;
  }
  .controls-row button, .controls-row select {
    width: 100%; padding: 3px 6px; font-size: 9px;
  }
  #sidebar-btn-group button.small { font-size: 9px !important; padding: 3px 5px !important; }

  .app.start-mode .ach-panel h2, .app.start-mode .level-map h2 { font-size: 9px; margin-bottom: 4px; }
  /* Phones: compact medals, the name lives in the tooltip */
  .app.start-mode .ach-panel .ach-grid { grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 4px; }
  .app.start-mode .ach-card { padding: 5px 3px; gap: 3px; border-radius: 8px; }
  .app.start-mode .ach-badge { width: 40px; height: 40px; }
  .app.start-mode .ach-name, .app.start-mode .ach-foot span { display: none; }
  .app.start-mode .ach-card.unlocked .ach-foot { display: none; }
  .app.start-mode .ach-lock { font-size: 8px; }

  .top-frame { padding: 3px 6px; gap: 4px; margin-bottom: 3px; }
  .app.start-mode .train-panel { gap: 3px; padding: 5px 8px; }
  .train-panel select { padding: 3px 6px; font-size: 10px; }
  .train-panel h2 { font-size: 9px; }
  .start-btn { padding: 4px 12px; }
  .start-main { font-size: 13px; }
  .start-what { font-size: 9px; }

  .app.start-mode .footnote { font-size: 9px; line-height: 1.2; }

  .key { --k: 26px; height: 26px; font-size: 9px; }
  .key.shift { width: 42px; font-size: 11px; }
  .key.space { width: 90px; font-size: 11px; }
  .finger { width: 36px; }
  .finger .shaft { font-size: 12px; }
  .finger .home { font-size: 9px; min-width: 20px; }
  .finger .name { max-width: 36px; font-size: 7px; }
  .thumb-bar { width: 55px; height: 10px; }
  body { padding: 4px; }

  .app.focus-mode .key { --k: 30px; height: 30px; font-size: 10px; }
  .type-line { font-size: 18px; padding: 4px 0; }
  .app.focus-mode .key.shift { width: 44px; font-size: 11px; }
  .app.focus-mode .key.space { width: 70px; font-size: 10px; }
  .app.focus-mode .finger { width: 32px; }
  .app.focus-mode .finger .shaft { font-size: 11px; }
  .app.focus-mode .finger .home { font-size: 8px; min-width: 18px; }
  .app.focus-mode .finger .name { font-size: 7px; max-width: 32px; }
  .app.focus-mode .thumb-bar { width: 50px; height: 10px; }
  .app.focus-mode .text-display { font-size: min(4vw, 18px); padding: 8px 10px; }
  .focus-stats { gap: 6px; padding: 4px 10px; }
  .focus-stats .fs-item { font-size: 9px; }
  .focus-stats .fs-item b { font-size: 11px; }
  .fs-progress-track { width: 70px; height: 6px; }
  .completion-card { padding: 20px 16px; }
  .completion-title { font-size: 20px; }
  .cstat-value { font-size: 20px; }

  .auth-bar { font-size: 11px; padding: 3px 6px; gap: 4px; margin-bottom: 3px; }
  .auth-bar button { padding: 4px 8px; font-size: 10px; }

  /* Home-row finger pads — a touch larger on tiny screens for readability */
  .key .finger-mark.lp { top: 31%; width: 32%; }
  .key .finger-mark.lr { top: 22%; width: 38%; }
  .key .finger-mark.lm { top: 12%; width: 44%; }
  .key .finger-mark.li { top: 18%; width: 42%; }
  .key .finger-mark.ri { top: 18%; width: 42%; }
  .key .finger-mark.rm { top: 12%; width: 44%; }
  .key .finger-mark.rr { top: 22%; width: 38%; }
  .key .finger-mark.rp { top: 31%; width: 32%; }
  .key.space .finger-mark.tt { top: 22%; height: 56%; }
  .key .key-cap { bottom: 3px; }
  .key.finger-bump::after { width: 3px; height: 1px; }
}

/* ---- TABLET (481px – 800px) ---- */
@media (min-width: 481px) and (max-width: 800px) {
  .app.start-mode {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto 1fr auto;
    gap: 5px;
    min-height: calc(100vh - 16px);
  }

  .app.start-mode > .top-frame   { grid-column: 1 / -1; grid-row: 1; }
  .app.start-mode > .footnote    { grid-column: 1 / -1; grid-row: 5; }

  .app.start-mode > .top-bar     { grid-column: 1; grid-row: 2; }
  .app.start-mode > .train-panel { grid-column: 1; grid-row: 3; }
  .app.start-mode > .controls-row { grid-column: 1; grid-row: 4; }

  .app.start-mode > .side-col {
    grid-column: 2;
    grid-row: 2 / 5;
    align-self: stretch;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .app.start-mode .top-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    padding: 7px 10px;
  }
  .lvl-badge { width: 30px; height: 30px; font-size: 13px; }
  .lvl-title { font-size: 11px; }
  .xp-compact { font-size: 9px; }
  .xp-mini { height: 4px; }
  .score-compact { text-align: left; margin-left: 0; width: 100%; }
  .sc-value { font-size: 15px; }


  .app.start-mode .controls-row {
    flex-direction: column;
    gap: 3px;
    padding: 5px 10px;
  }
  .controls-row button, .controls-row select {
    width: 100%;
    padding: 4px 7px;
    font-size: 10px;
  }

  .app.start-mode .ach-panel { padding: 10px; }
  .app.start-mode .ach-panel h2, .app.start-mode .level-map h2 { font-size: 10px; margin-bottom: 5px; }
  .app.start-mode .ach-panel .ach-grid { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
  .app.start-mode .ach-badge { width: 50px; height: 50px; }

  .start-btn { padding: 5px 18px; }
  .app.start-mode .train-panel { gap: 4px; padding: 6px 10px; }
  .train-panel select { padding: 4px 7px; font-size: 11px; }
  .start-main { font-size: 15px; }
  .start-what { font-size: 10px; }

  .app.start-mode .footnote { font-size: 10px; line-height: 1.3; }

  .key { --k: 34px; height: 34px; font-size: 12px; }
  .key.shift { width: 56px; font-size: 14px; }
  .key.space { width: 140px; font-size: 15px; }
  .finger { width: 48px; }
  .finger .name { max-width: 48px; font-size: 9px; }
  .thumb-bar { width: 80px; }
  .keyboard { margin-top: 8px; }
  .kb-row { gap: 2px; --g: 2px; }

  .app.focus-mode .key { --k: 44px; height: 44px; font-size: 15px; }
  .app.focus-mode .key.shift { width: 72px; font-size: 16px; }
  .app.focus-mode .key.space { width: 180px; font-size: 18px; }
  .app.focus-mode .finger { width: 52px; }
  .app.focus-mode .finger .shaft { font-size: 16px; }
  .app.focus-mode .finger .home { font-size: 12px; min-width: 28px; }
  .app.focus-mode .finger .name { font-size: 10px; max-width: 52px; }
  .app.focus-mode .thumb-bar { width: 90px; }
  .app.focus-mode .text-display { font-size: min(3.5vw, 26px); padding: 14px 16px; }
  .type-line { font-size: 22px; }
}

/* ---- DESKTOP (>= 801px) ---- */
@media (min-width: 801px) {
  .app.start-mode {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: auto auto auto auto 1fr auto;
    gap: 6px;
    min-height: calc(100vh - 16px);
    overflow: hidden;
  }

  .app.start-mode > .top-frame        { grid-column: 1 / -1; grid-row: 1; }

  .app.start-mode > .top-bar           { grid-column: 1; grid-row: 2; }
  .app.start-mode > .train-panel       { grid-column: 1; grid-row: 3; }
  .app.start-mode > .controls-row      { grid-column: 1; grid-row: 4; }

  .app.start-mode > .side-col {
    grid-column: 2;
    grid-row: 2 / 6;
    align-self: stretch;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .app.start-mode > .footnote          { grid-column: 1 / -1; grid-row: 6; }

  .app.start-mode .top-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    padding: 7px 10px;
  }
  .lvl-badge { width: 32px; height: 32px; font-size: 14px; }
  .lvl-title { font-size: 12px; }
  .xp-compact { font-size: 10px; }
  .xp-mini { width: 100%; height: 4px; }
  .score-compact { text-align: left; margin-left: 0; width: 100%; }
  .sc-value { font-size: 16px; }


  .app.start-mode .controls-row {
    flex-direction: column;
    gap: 3px;
    padding: 5px 10px;
  }
  .controls-row button, .controls-row select {
    width: 100%;
    padding: 5px 8px;
    font-size: 11px;
  }
  #sidebar-btn-group button.small { font-size: 10px !important; padding: 4px 6px !important; }

  .app.start-mode .ach-panel {
    padding: 12px 14px;
  }
  .app.start-mode .ach-panel h2 {
    font-size: 10px;
    margin-bottom: 6px;
  }


  .app.start-mode .footnote { font-size: 11px; line-height: 1.4; }

  .app.focus-mode .key { --k: 64px; height: 64px; font-size: 20px; }
  .app.focus-mode .key.shift { width: 108px; font-size: 22px; }
  .app.focus-mode .key.space { width: 300px; font-size: 26px; }
  .app.focus-mode .finger { width: 64px; }
  .app.focus-mode .finger .shaft { font-size: 18px; }
  .app.focus-mode .finger .home { font-size: 14px; min-width: 32px; }
  .app.focus-mode .finger .name { font-size: 12px; max-width: 64px; }
  .app.focus-mode .thumb-bar { width: 120px; height: 18px; }
  .app.focus-mode .text-display { font-size: min(3vw, 34px); }

  body { padding: 8px; }
}

/* ---- SHORT DESKTOP SCREENS: smaller keys so the text frame keeps enough room ---- */
@media (min-width: 801px) and (max-height: 760px) {
  .app.focus-mode .key { --k: 52px; height: 52px; font-size: 16px; }
  .app.focus-mode .key.shift { width: 88px; font-size: 18px; }
  .app.focus-mode .key.space { width: 240px; font-size: 22px; }
  .type-line { font-size: 22px; padding: 4px 0; }
}

/* ============ ACCOUNT & SECURITY ============ */
.modal.acc-wide { max-width: 560px; max-height: 88vh; overflow-y: auto; }
.modal .acc-text { color: var(--dim); font-size: 13px; margin: 0 0 12px; line-height: 1.45; }
.modal .acc-hint { color: var(--dim); font-size: 12px; margin: -6px 0 12px; line-height: 1.4; }
.modal .acc-dev { font-size: 12px; margin: 0 0 12px; padding: 6px 10px; border-radius: 6px; background: var(--panel-2); color: var(--accent); }
.modal input.acc-code-input { font-size: 24px; letter-spacing: 8px; text-align: center; font-variant-numeric: tabular-nums; }
.modal .acc-check {
  display: flex; align-items: center; gap: 8px; text-transform: none; letter-spacing: 0;
  font-size: 13px; color: var(--dim); margin: 0 0 12px; cursor: pointer;
}
.modal .acc-check input { width: auto; margin: 0; }
.modal .acc-link {
  display: block; margin: 10px auto 0; background: none; border: none; color: var(--dim);
  font-size: 13px; cursor: pointer; font-family: inherit;
}
.modal .acc-link:hover { color: var(--accent); }
.acc-divider { display: flex; align-items: center; gap: 10px; color: var(--dim); font-size: 12px; margin: 14px 0 10px; }
.acc-divider::before, .acc-divider::after { content: ''; flex: 1; height: 1px; background: var(--panel-2); }
.acc-provider {
  display: block; width: 100%; padding: 10px 14px; margin-bottom: 8px; border-radius: 8px;
  border: 1px solid var(--key-border); background: var(--panel-2); color: var(--text);
  font-size: 14px; font-family: inherit; cursor: pointer;
}
.acc-provider:hover { border-color: var(--accent); }
.acc-btn {
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--key-border); background: var(--panel-2);
  color: var(--text); font-size: 13px; font-family: inherit; cursor: pointer; white-space: nowrap;
}
.acc-btn:hover:not(:disabled) { border-color: var(--accent); }
.acc-btn:disabled { opacity: 0.6; cursor: default; }
.acc-btn.primary { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.acc-btn.danger { color: var(--wrong); border-color: var(--wrong); }
.modal .acc-open-security { display: block; width: 100%; margin: 4px 0 6px; padding: 10px 14px; }
.acc-section { border-top: 1px solid var(--panel-2); padding: 14px 0 6px; }
.acc-section:first-child { border-top: none; padding-top: 0; }
.acc-section h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--dim); }
.acc-section .acc-value { margin: 0 0 10px; color: var(--text); font-size: 15px; word-break: break-all; }
.acc-section > button { margin-bottom: 8px; }
.acc-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; font-size: 14px; color: var(--text); }
.acc-row small { color: var(--dim); font-size: 12px; }
.acc-current { color: var(--accent); font-style: normal; font-size: 12px; }
.acc-events { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; }
.acc-events li { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; font-size: 13px; color: var(--text); border-bottom: 1px solid rgba(128,128,128,0.06); }
.acc-events li small { color: var(--dim); font-size: 12px; text-align: right; }
.acc-events li.warn span { color: var(--wrong); }
.acc-toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); z-index: 2000;
  max-width: min(520px, 90vw); padding: 12px 18px; border-radius: 10px; background: var(--panel);
  color: var(--text); box-shadow: 0 12px 40px var(--panel-shadow); font-size: 14px; line-height: 1.4;
  opacity: 0; transition: opacity 0.3s, transform 0.3s; pointer-events: none;
}
.acc-toast.show { opacity: 1; transform: translate(-50%, 0); }
