:root {
  --bg: #e8f4ff;
  --ink: #23324a;
  --muted: #5d6b82;
  --card: #ffffff;
  --accent: #2b6cb0;
  --accent-ink: #ffffff;
  --orange: #f08a24;
  --green: #2e9d4c;
  --red: #c0392b;
  --line: #c9d8ea;
  --f-lp: #f7b2bd; --f-lr: #f9d29b; --f-lm: #fff09a; --f-li: #b9e8a8;
  --f-ri: #a8dff0; --f-rm: #c4c3f7; --f-rr: #e7b7ef; --f-rp: #f2c0d6;
  font-family: "Trebuchet MS", system-ui, -apple-system, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); min-height: 100%; }
#app { min-height: 100vh; }
[hidden] { display: none !important; }

button {
  font: inherit; font-weight: 700; color: var(--ink); background: var(--card);
  border: 2px solid var(--line); border-radius: 12px; padding: 10px 16px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }
button.big { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-size: 1.15rem; padding: 12px 22px; }
button.link { background: none; border: none; color: var(--accent); padding: 6px 8px; text-decoration: underline; }
button.danger { color: var(--red); }
input[type=text] { font: inherit; font-size: 1.1rem; padding: 10px 12px; border: 2px solid var(--line); border-radius: 12px; min-width: 0; }

.keycap {
  display: inline-block; min-width: 1.6em; padding: 0 0.4em; margin: 0 2px; text-align: center;
  font-family: ui-monospace, Menlo, monospace; font-weight: 700; color: var(--ink); background: var(--card);
  border: 2px solid var(--line); border-bottom-width: 4px; border-radius: 6px; line-height: 1.5;
}
.stars { color: #f5b301; letter-spacing: 2px; }
.stars .dim { color: #cfd8e3; }
.error { color: var(--red); min-height: 1.2em; }
.row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

.card { background: var(--card); max-width: 640px; margin: 40px auto; padding: 32px 24px; border-radius: 20px; box-shadow: 0 6px 24px rgba(35, 50, 74, 0.12); }
.center { text-align: center; }
.logo { font-size: 2.6rem; color: var(--accent); margin: 0 0 8px; letter-spacing: 1px; }
.logo.small { font-size: 1.6rem; margin: 0; }

.players { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin: 20px 0; }
.add-player { display: flex; gap: 8px; justify-content: center; margin-top: 16px; }

/* Lessons */
.lessons-screen { max-width: 1100px; margin: 0 auto; padding: 16px; }
.top { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.who { display: flex; align-items: center; gap: 4px; font-weight: 700; }
.hint, .trouble { color: var(--muted); }
.lessons { list-style: none; padding: 0; margin: 12px 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.lesson { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; text-align: left; padding: 12px 14px; border-radius: 16px; }
.lesson .num { font-size: 0.85rem; color: var(--muted); }
.lesson .title { font-size: 1.1rem; }
.lesson .keys { min-height: 1.6em; }
.lesson .best { font-size: 0.8rem; color: var(--muted); font-weight: 400; }
.lesson.suggested { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(240, 138, 36, 0.25); }
.lesson.locked { opacity: 0.5; cursor: not-allowed; }
.settings { margin-top: 20px; background: var(--card); border-radius: 14px; padding: 12px 16px; }
.settings summary { cursor: pointer; font-weight: 700; }
.settings .toggle { display: block; margin: 10px 0; }
.settings .row { justify-content: flex-start; }

/* Play */
.play { max-width: 1200px; margin: 0 auto; padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 10px; min-height: 100vh; }
.hud { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-weight: 700; }
.hud .lesson-name { white-space: nowrap; }
.progress { flex: 1; min-width: 120px; height: 12px; background: var(--card); border: 2px solid var(--line); border-radius: 8px; overflow: hidden; }
.progress .bar { height: 100%; width: 0; background: var(--green); transition: width 0.2s; }
.speed { color: var(--accent); white-space: nowrap; }
.stage { position: relative; border-radius: 18px; overflow: hidden; box-shadow: 0 4px 16px rgba(35, 50, 74, 0.15); }
.stage-canvas { display: block; width: 100%; height: clamp(260px, 42vh, 420px); }
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(35, 50, 74, 0.25); }
.overlay .panel { background: var(--card); border-radius: 18px; padding: 20px 28px; max-width: 520px; margin: 16px; text-align: center; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2); }
.overlay .panel h2 { margin-top: 0; }
.overlay .go { font-weight: 700; font-size: 1.15rem; }
.new-keys { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; font-size: 1.1rem; }
.new-keys .keycap { font-size: 1.4rem; }
.count { font-size: 7rem; font-weight: 700; color: #fff; text-shadow: 0 4px 12px rgba(0, 0, 0, 0.35); }

.under { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.word { font-family: ui-monospace, Menlo, monospace; font-size: clamp(2rem, 5vw, 3.2rem); font-weight: 700; letter-spacing: 0.08em; min-height: 1.3em; }
.word .done { color: var(--green); }
.word .waiting { color: #b3bfd0; }
.word .now { color: var(--orange); text-decoration: underline; text-underline-offset: 6px; }
.finger { color: var(--muted); min-height: 1.3em; }

.keyboard { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.kb-row { display: flex; gap: 6px; }
.kb-row:nth-child(2) { margin-left: 0; }
.key {
  width: clamp(30px, 5.2vw, 52px); height: clamp(30px, 5.2vw, 52px); display: flex; align-items: center; justify-content: center;
  font-family: ui-monospace, Menlo, monospace; font-weight: 700; font-size: clamp(0.9rem, 2vw, 1.2rem);
  border-radius: 8px; border: 2px solid rgba(35, 50, 74, 0.15); border-bottom-width: 4px; transition: transform 0.08s;
}
.key.wide { width: clamp(46px, 8vw, 80px); font-size: 0.8rem; background: #eef2f7; }
.key.spacer { visibility: hidden; width: clamp(10px, 2vw, 20px); }
.key.spacer.wide { width: clamp(20px, 3.5vw, 34px); }
.key.bump { text-decoration: underline; text-underline-offset: 4px; }
.key.next { border-color: var(--orange); box-shadow: 0 0 0 3px var(--orange); transform: translateY(-2px); }
.f-lp { background: var(--f-lp); } .f-lr { background: var(--f-lr); } .f-lm { background: var(--f-lm); } .f-li { background: var(--f-li); }
.f-ri { background: var(--f-ri); } .f-rm { background: var(--f-rm); } .f-rr { background: var(--f-rr); } .f-rp { background: var(--f-rp); }
.key.wide.next { background: #ffe2c2; }

/* Results */
.results .big-stars { font-size: 3.4rem; }
.numbers { display: flex; justify-content: center; gap: 28px; flex-wrap: wrap; margin: 16px 0; }
.numbers dt { color: var(--muted); }
.numbers dd { margin: 0; font-size: 1.8rem; font-weight: 700; }

@media (max-width: 600px) {
  .card { margin: 16px; padding: 24px 16px; }
  .add-player { flex-direction: column; }
  .hud .lesson-name { display: none; }
}

/* Worlds on the lesson list */
.world { margin: 18px 0 6px; padding: 10px 14px 4px; border-radius: 18px; }
.world h2 { margin: 0 0 4px; font-size: 1.1rem; }
.w-meadow { background: #dff3d8; } .w-desert { background: #fbe9cc; } .w-jungle { background: #d3efe3; }
.w-snow { background: #eef4fc; } .w-cave { background: #ecd9df; } .w-sky { background: #dde2f7; }
.world-name { margin: 0; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 1px; font-size: 0.8rem; }
.new-thing { background: #fff4e5; border-radius: 10px; padding: 8px 12px; }

/* Lesson intro: full-screen card with the hands */
.overlay.intro { position: fixed; inset: 0; z-index: 10; background: rgba(35, 50, 74, 0.45); overflow-y: auto; }
.overlay.intro .panel { max-width: 560px; }
.speed-settings { margin-top: 12px; }
.speed-settings select { font: inherit; padding: 6px 8px; border-radius: 8px; border: 2px solid var(--line); margin-left: 6px; }
.saved-note { color: var(--green); font-size: 0.9rem; }
.finger.go-now { color: var(--orange); font-weight: 700; font-size: 1.1rem; animation: blink 0.8s ease-in-out infinite; }
@keyframes blink { 50% { opacity: 0.45; } }
.word.nudge { animation: nudge 0.3s; }
@keyframes nudge { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.player-switch { text-decoration: none; font-weight: 700; }
.overlay .small { font-size: 0.9rem; color: var(--muted); margin-bottom: 0; }
.overlay .how { font-weight: 700; color: var(--accent); }

/* Players and turns */
.count-button { min-width: 72px; font-size: 1.8rem; }
.turn-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 4px 10px; border-radius: 999px; background: var(--card); border: 2px solid var(--line); font-weight: 700; }
.chip.current { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.turn-banner { font-size: 1.6rem; font-weight: 700; color: var(--accent); margin: 8px 0; }
.numbers dd.sub { font-size: 0.85rem; font-weight: 400; color: var(--muted); }

/* Results: the top thing to work on */
.results { max-width: 720px; }
.focus { border-top: 2px solid var(--line); margin-top: 18px; padding-top: 6px; }
.focus h2 { font-size: 1.2rem; color: var(--muted); }
.focus-card { background: #fff4e5; border-radius: 16px; padding: 14px 18px; }
.focus-card h3 { margin: 0 0 6px; font-size: 1.35rem; color: var(--ink); }
.focus-card p { margin: 0 0 6px; }
.focus-perfect .focus-card { background: #e6f6ea; }
.stat-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.stat-chip { background: var(--bg); border-radius: 999px; padding: 4px 12px; font-weight: 700; color: var(--muted); }
