:root {
  --bg: #eef4ff;
  --card: #ffffff;
  --ink: #1e293b;
  --muted: #64748b;
  --line: #dbe3f0;
  --primary: #4f6df5;
  --primary-dark: #3b55d6;
  --accent: #ff8a3d;
  --good: #16a34a;
  --warn: #ca8a04;
  --bad: #dc2626;
  --radius: 20px;
  --shadow: 0 10px 30px rgba(30, 41, 59, 0.08);
  --font: "Nunito", "Quicksand", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  --mono: "JetBrains Mono", "Fira Mono", "DejaVu Sans Mono", "Consolas", "Menlo", monospace;
}
.finger-lp, .finger-rp { --fc: #ec4899; --fc-bg: #fce7f3; }
.finger-lr, .finger-rr { --fc: #f59e0b; --fc-bg: #fef3c7; }
.finger-lm, .finger-rm { --fc: #22c55e; --fc-bg: #dcfce7; }
.finger-li, .finger-ri { --fc: #3b82f6; --fc-bg: #dbeafe; }
.finger-th { --fc: #a855f7; --fc-bg: #f3e8ff; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg) radial-gradient(circle at 10% 10%, #ffffff 0, transparent 40%) fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
h1, h2 { margin: 0 0 12px; line-height: 1.15; }
h1 { font-size: 2rem; }
h2 { font-size: 1.3rem; }
p { margin: 0 0 12px; line-height: 1.5; }
.muted { color: var(--muted); }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; font-weight: 800; color: var(--primary); }

#app { max-width: 1080px; margin: 0 auto; padding: 0 20px 40px; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 16px 0; }
.brand { border: 0; background: none; font-size: 1.4rem; font-weight: 900; color: var(--ink); cursor: pointer; }
.brand span { color: var(--primary); }
.topbar-right { display: flex; gap: 10px; align-items: center; }
.icon-btn { border: 0; background: var(--card); box-shadow: var(--shadow); width: 42px; height: 42px; border-radius: 50%; cursor: pointer; font-size: 1.1rem; }
.profile-chip { border: 0; background: var(--card); box-shadow: var(--shadow); border-radius: 999px; padding: 6px 14px 6px 8px; display: flex; gap: 8px; align-items: center; font-weight: 800; cursor: pointer; }
.profile-chip #chip-avatar { font-size: 1.4rem; }
.profile-chip.hidden { display: none; }
.footer { text-align: center; color: var(--muted); font-size: .85rem; margin-top: 40px; }

.screen { display: none; animation: fade .25s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.big-title { text-align: center; font-size: 2.4rem; margin: 20px 0 24px; }
.screen-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; margin-bottom: 20px; }
.row { display: flex; gap: 12px; align-items: center; }
.row.center { justify-content: center; }
.row.wrap { flex-wrap: wrap; }

.btn {
  border: 0; border-radius: 999px; padding: 12px 22px; font-weight: 800; cursor: pointer;
  background: #e2e8f0; color: var(--ink); transition: transform .08s, box-shadow .08s, background .15s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: #fff; box-shadow: 0 6px 0 var(--primary-dark); }
.btn.primary:active { box-shadow: 0 2px 0 var(--primary-dark); transform: translateY(4px); }
.btn.big { font-size: 1.15rem; padding: 14px 30px; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { background: #e2e8f0; color: var(--ink); }
.btn.danger { background: #fee2e2; color: var(--bad); }

/* Profiles */
.profile-list { display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; margin-bottom: 24px; }
.profile-card {
  border: 0; background: var(--card); box-shadow: var(--shadow); border-radius: var(--radius); padding: 20px 28px;
  display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; min-width: 140px; transition: transform .1s;
}
.profile-card:hover { transform: translateY(-3px) scale(1.02); }
.profile-card .avatar { font-size: 3rem; }
.profile-card .name { font-weight: 900; font-size: 1.1rem; }
.profile-card .sub { color: var(--muted); font-size: .8rem; }
.new-profile { max-width: 560px; margin: 0 auto; }
.avatar-picker { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.avatar-picker button { border: 3px solid transparent; background: #f1f5f9; border-radius: 14px; font-size: 1.8rem; width: 56px; height: 56px; cursor: pointer; }
.avatar-picker button.selected { border-color: var(--primary); background: #dbeafe; }
input[type="text"] { flex: 1; border: 2px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 1.05rem; outline: none; }
input[type="text"]:focus { border-color: var(--primary); }

/* Home */
.continue-card { display: flex; justify-content: space-between; align-items: center; gap: 20px; flex-wrap: wrap;
  background: linear-gradient(135deg, #fff 0%, #eef2ff 100%); }
.continue-title { font-size: 1.5rem; font-weight: 900; }
.nav-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; }
.nav-card {
  border: 0; background: var(--card); box-shadow: var(--shadow); border-radius: var(--radius); padding: 24px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 8px; font-weight: 900; font-size: 1.05rem; cursor: pointer; transition: transform .1s;
}
.nav-card:hover { transform: translateY(-3px); }
.nav-icon { font-size: 2.4rem; }

/* Lessons grid */
.lesson-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.lesson-card {
  border: 0; text-align: left; background: var(--card); box-shadow: var(--shadow); border-radius: 16px; padding: 16px;
  display: flex; flex-direction: column; gap: 6px; cursor: pointer; position: relative; transition: transform .1s;
}
.lesson-card:hover { transform: translateY(-2px); }
.lesson-card.locked { opacity: .5; cursor: not-allowed; }
.lesson-card.current { outline: 3px solid var(--primary); }
.lesson-card .lesson-num { font-size: .75rem; color: var(--muted); font-weight: 800; }
.lesson-card .lesson-title { font-weight: 900; font-size: 1.05rem; }
.lesson-card .lesson-keys { display: flex; gap: 4px; }
.lesson-card .lesson-stars { color: #f59e0b; letter-spacing: 2px; }
.lesson-card .lock { position: absolute; top: 12px; right: 12px; }
.key-chip {
  display: inline-flex; align-items: center; justify-content: center; min-width: 34px; height: 34px; padding: 0 8px;
  border-radius: 8px; background: var(--fc-bg, #f1f5f9); color: var(--ink); border-bottom: 3px solid var(--fc, #cbd5e1); font-weight: 900; font-family: var(--mono);
}
.key-chip.big { min-width: 64px; height: 64px; font-size: 1.8rem; border-radius: 12px; }

/* Intro */
.intro-card { max-width: 720px; margin: 0 auto; text-align: center; }
.intro-keys { display: flex; gap: 14px; justify-content: center; margin: 16px 0; }
.intro-tip { font-size: 1.1rem; }
.intro-fingers { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 10px; }
.finger-tag { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--fc-bg); font-weight: 800; font-size: .9rem; }
.finger-tag::before { content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--fc); }
.intro-hands { max-width: 380px; margin: 0 auto 16px; }

/* Practice */
.practice-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
.stats { display: flex; gap: 20px; }
.stat { display: flex; flex-direction: column; align-items: center; min-width: 70px; }
.stat-val { font-size: 1.6rem; font-weight: 900; line-height: 1; }
.stat-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 800; margin-top: 4px; }
.progress-bar { height: 10px; background: #e2e8f0; border-radius: 999px; overflow: hidden; margin-bottom: 14px; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), #22d3ee); transition: width .15s; }

.text-display {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px 30px;
  font-family: var(--mono); font-size: 1.9rem; line-height: 1.7; outline: none; min-height: 100px; user-select: none;
  letter-spacing: .02em;
}
.text-display .w { display: inline-block; white-space: pre; }
.text-display .c { color: #94a3b8; border-radius: 4px; transition: background .08s; }
.text-display .c.correct { color: var(--good); }
.text-display .c.fixed { color: var(--warn); }
.text-display .c.wrong { color: #fff; background: var(--bad); }
.text-display .c.cur { background: #dbeafe; color: var(--ink); box-shadow: inset 0 -4px 0 var(--primary); animation: blink 1s steps(2) infinite; }
.text-display .c.cur.wrong { background: var(--bad); color: #fff; animation: none; }
.text-display .c.sp { background-image: radial-gradient(circle, #cbd5e1 2.5px, transparent 3px); }
.text-display .c.sp.correct { background-image: radial-gradient(circle, #86efac 2.5px, transparent 3px); }
.text-display.shake { animation: shake .2s; }
@keyframes blink { 50% { box-shadow: inset 0 -4px 0 transparent; } }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

.hint-line { text-align: center; margin: 12px 0; font-weight: 800; color: var(--muted); min-height: 1.5em; }
.hint-line .key-chip { margin: 0 4px; }

.kb-area { display: flex; gap: 20px; align-items: center; justify-content: center; flex-wrap: wrap; }
#kb-practice { flex: 1 1 560px; max-width: 760px; }
.hands-wrap { flex: 0 1 300px; }
.hands-wrap.hidden, #kb-practice.hidden { display: none; }
.practice-actions { margin-top: 16px; }

/* Keyboard */
.kb { display: flex; flex-direction: column; gap: 6px; padding: 10px; background: #e2e8f0; border-radius: 14px; }
.kb-row { display: flex; gap: 6px; }
.kb-key {
  height: 44px; min-width: 0; border-radius: 8px; background: var(--fc-bg, #fff); color: var(--ink);
  border-bottom: 3px solid rgba(0, 0, 0, .12); display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: .95rem; position: relative; transition: transform .06s, background .1s;
  user-select: none;
}
.kb-key.kb-special { font-size: .7rem; color: var(--muted); }
.kb-key .kb-upper { position: absolute; top: 3px; left: 6px; font-size: .6rem; color: var(--muted); }
.kb-key .kb-lower { position: absolute; bottom: 3px; left: 6px; font-size: .8rem; }
.kb-key.kb-bump::after { content: ""; position: absolute; bottom: 5px; left: 50%; transform: translateX(-50%); width: 12px; height: 3px; border-radius: 2px; background: rgba(0, 0, 0, .25); }
.kb-key.next { background: var(--fc); color: #fff; box-shadow: 0 0 0 4px rgba(79, 109, 245, .25); animation: pulse .9s ease-in-out infinite; z-index: 1; }
.kb-key.next .kb-upper, .kb-key.next .kb-lower, .kb-key.next.kb-special { color: #fff; }
.kb-key.pressed { transform: translateY(3px); border-bottom-width: 0; }
.kb-key.wrong { background: var(--bad) !important; color: #fff; }
@keyframes pulse { 50% { transform: scale(1.06); } }
.kb-key.heat-none { background: #f8fafc; color: #cbd5e1; }
.kb-key.heat-good { background: #bbf7d0; }
.kb-key.heat-ok { background: #fde68a; }
.kb-key.heat-bad { background: #fecaca; }
.heat-legend { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; font-size: .8rem; font-weight: 800; }
.heat-legend span { padding: 4px 10px; border-radius: 999px; }
.heat-legend .heat-good { background: #bbf7d0; } .heat-legend .heat-ok { background: #fde68a; }
.heat-legend .heat-bad { background: #fecaca; } .heat-legend .heat-none { background: #f1f5f9; color: var(--muted); }

/* Hands */
.hands { width: 100%; height: auto; display: block; }
.hand-palm { fill: #fde7cf; stroke: #e5b58c; stroke-width: 2; }
.hand-finger { fill: #fde7cf; stroke: #e5b58c; stroke-width: 2; transition: fill .1s; }
.hand-finger.active { fill: var(--fc); stroke: var(--fc); }

/* Results */
.results-card { max-width: 620px; margin: 0 auto; text-align: center; }
.stars { font-size: 3rem; margin: 8px 0 16px; letter-spacing: 6px; }
.stars .star { display: inline-block; color: #e2e8f0; }
.stars .star.on { color: #f59e0b; animation: star-pop .5s cubic-bezier(.3, 1.6, .5, 1) both; }
.stars .star:nth-child(2) { animation-delay: .15s; } .stars .star:nth-child(3) { animation-delay: .3s; }
@keyframes star-pop { from { transform: scale(0) rotate(-30deg); } to { transform: scale(1) rotate(0); } }
.results-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 16px; margin: 10px 0 18px; }
.results-message { font-size: 1.1rem; font-weight: 800; }

/* Games */
.game-card { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.game-icon { font-size: 4rem; }
.game-info { flex: 1; }
.rain-hud { display: flex; gap: 24px; align-items: center; justify-content: center; margin-bottom: 12px; flex-wrap: wrap; }
.rain-area {
  position: relative; height: 480px; border-radius: var(--radius); overflow: hidden;
  background: linear-gradient(180deg, #bae6fd 0%, #e0f2fe 70%, #bbf7d0 100%); box-shadow: var(--shadow);
}
.rain-ground { position: absolute; left: 0; right: 0; bottom: 0; height: 18px; background: #4ade80; }
.rain-word {
  position: absolute; top: 0; left: 0; padding: 4px 12px; border-radius: 10px; background: #fff; box-shadow: 0 4px 12px rgba(0,0,0,.12);
  font-family: var(--mono); font-size: 1.5rem; font-weight: 800; white-space: pre; will-change: transform;
}
.rain-word.active { outline: 3px solid var(--primary); }
.rain-word .done { color: var(--good); }
.rain-word.pop { animation: pop .3s ease-out forwards; }
.rain-word.splat { animation: splat .3s ease-out forwards; }
@keyframes pop { to { transform: scale(1.6); opacity: 0; } }
@keyframes splat { to { transform: scaleY(.2); opacity: 0; } }
.rain-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .85); text-align: center; z-index: 5; padding: 20px;
}
.rain-overlay.hidden { display: none; }
.rain-area.shake { animation: shake .2s; }

/* Progress tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; }
td.stars-cell { color: #f59e0b; letter-spacing: 2px; }

/* Settings */
.toggle { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; font-weight: 700; }
.toggle:last-child { border-bottom: 0; }
.toggle input { width: 22px; height: 22px; accent-color: var(--primary); }
.toggle small { display: block; color: var(--muted); font-weight: 600; }
.danger-zone { border: 2px dashed #fecaca; }

@media (max-width: 640px) {
  .text-display { font-size: 1.3rem; padding: 18px; }
  .kb-key { height: 34px; font-size: .75rem; }
  .big-title { font-size: 1.8rem; }
  .stats { gap: 12px; }
}

/* Rocket Race */
.race-track { position: relative; padding: 20px 24px; }
.race-lane { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.race-label { width: 48px; font-weight: 900; color: var(--muted); }
.race-bar { position: relative; flex: 1; height: 44px; border-radius: 999px; background: repeating-linear-gradient(90deg, #e2e8f0 0 20px, #f1f5f9 20px 40px); }
.race-rocket { position: absolute; top: 0; left: 0; font-size: 2rem; line-height: 44px; transition: left .12s linear; }
.race-flag { font-size: 1.6rem; }
.race-countdown { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 4rem; font-weight: 900; color: var(--primary); pointer-events: none; text-shadow: 0 4px 12px rgba(255,255,255,.9); }
.race-text-wrap { position: relative; }
.text-display.small { font-size: 1.4rem; line-height: 1.6; max-height: 190px; overflow: hidden; }
.race-text-wrap .rain-overlay { border-radius: var(--radius); }

/* Bubble Pop */
.bubbles-area { background: linear-gradient(180deg, #a5f3fc 0%, #22d3ee 60%, #0891b2 100%); }
.bubble {
  position: absolute; top: 0; left: 0; width: 64px; height: 64px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-size: 1.8rem; font-weight: 900; color: var(--ink);
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,.95), rgba(255,255,255,.45) 60%, rgba(255,255,255,.2));
  border: 2px solid rgba(255,255,255,.8); box-shadow: 0 6px 16px rgba(8, 145, 178, .25); will-change: transform;
}
.bubble.pop { animation: pop .25s ease-out forwards; }
.bubble.escape { animation: escape .3s ease-out forwards; }
@keyframes escape { to { opacity: 0; transform: translateY(-40px) scale(.6); } }

/* Skill level picker */
.level-picker { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 16px; }
.level-picker button { border: 3px solid transparent; background: #f1f5f9; border-radius: 14px; padding: 10px 16px; cursor: pointer; font-weight: 800; text-align: left; }
.level-picker button small { display: block; color: var(--muted); font-weight: 600; }
.level-picker button.selected { border-color: var(--primary); background: #dbeafe; }
select { font: inherit; font-weight: 700; padding: 8px 12px; border-radius: 10px; border: 2px solid var(--line); background: #fff; margin-left: auto; }

/* Lesson units */
.unit { margin-bottom: 26px; }
.unit-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.unit-head h2 { margin: 0; }
.unit-head .unit-progress { color: var(--muted); font-weight: 700; font-size: .9rem; }
.lesson-card.test { background: linear-gradient(135deg, #fff 0%, #fef3c7 100%); }
.lesson-card.mastered { border-left: 5px solid var(--good); }

/* Intro checklist */
.intro-checklist { list-style: none; padding: 0; margin: 0 auto 16px; max-width: 520px; text-align: left; }
.intro-checklist li { display: flex; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-weight: 700; }
.intro-checklist li span:first-child { font-size: 1.5rem; }

/* Weak keys card */
.weak-card { display: flex; justify-content: space-between; align-items: center; gap: 20px; flex-wrap: wrap; background: linear-gradient(135deg, #fff 0%, #fff7ed 100%); }
.weak-card .key-chip { margin: 0 3px; }

/* Caps Lock warning */
.capslock {
  position: sticky; top: 8px; z-index: 20; margin: 0 auto 12px; width: fit-content; max-width: 100%;
  background: #fef3c7; color: #92400e; border: 2px solid #f59e0b; border-radius: 999px; padding: 10px 18px;
  font-weight: 900; box-shadow: var(--shadow); animation: wobble .5s ease-in-out;
}
@keyframes wobble { 25% { transform: rotate(-2deg); } 75% { transform: rotate(2deg); } }
