:root {
  --bg: #e8f4ff;
  --card: #ffffff;
  --ink: #1b3a5c;
  --muted: #6b7f95;
  --accent: #ff7043;
  --accent2: #ffd54f;
  --ok: #2e7d32;
  --bad: #e53935;
  --border: #1b3a5c;
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Nunito', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(circle at 10% 20%, rgba(255,255,255,0.7) 0 12px, transparent 13px),
    radial-gradient(circle at 80% 70%, rgba(255,255,255,0.6) 0 18px, transparent 19px);
  color: var(--ink);
  min-height: 100vh;
}
button { font-family: inherit; }

/* ---------------- Top bar ---------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 12px 20px;
  background: linear-gradient(180deg, #e53935, #c62828);
  color: #fff;
  border-bottom: 5px solid #7f1d1d;
  box-shadow: 0 4px 0 rgba(0,0,0,0.12);
}
.logo { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.logo-icon { font-size: 26px; }
.logo-text { font-family: 'Press Start 2P', monospace; font-size: 18px; letter-spacing: 1px; text-shadow: 3px 3px 0 #7f1d1d; }
.logo-sub { font-size: 13px; opacity: 0.9; }
.stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat {
  display: flex; flex-direction: column; align-items: center; min-width: 80px;
  background: rgba(0,0,0,0.25); border-radius: 10px; padding: 4px 10px;
}
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; opacity: 0.85; }
.stat-value { font-family: 'Press Start 2P', monospace; font-size: 14px; margin-top: 4px; color: var(--accent2); }

/* ---------------- Layout ---------------- */
.layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; padding: 16px; max-width: 1500px; margin: 0 auto; }
.sidebar {
  background: var(--card); border: 3px solid var(--border); border-radius: var(--radius);
  padding: 12px; box-shadow: 6px 6px 0 rgba(27,58,92,0.18); align-self: start;
  position: sticky; top: 16px; max-height: calc(100vh - 32px); display: flex; flex-direction: column;
}
.sidebar h2 { margin: 4px 8px 8px; font-size: 18px; }
#lesson-list { overflow: auto; flex: 1; }
.group-title { font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); margin: 12px 8px 6px; font-weight: 800; }
.lesson {
  display: flex; flex-direction: column; gap: 3px; width: 100%; text-align: left;
  background: #f4f8fc; border: 2px solid transparent; border-radius: 12px; padding: 8px 10px; margin-bottom: 6px;
  cursor: pointer; color: var(--ink); transition: transform .08s, background .15s;
}
.lesson:hover { background: #e3eefa; transform: translateX(3px); }
.lesson.selected { background: #fff3e0; border-color: var(--accent); }
.lesson-title { font-weight: 800; font-size: 14px; }
.lesson-desc { font-size: 12px; color: var(--muted); }
.lesson-badges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }
.badge { font-size: 10px; font-weight: 800; background: #dfe8f3; color: var(--ink); border-radius: 999px; padding: 2px 7px; }
.badge.a4 { background: #c8e6c9; color: var(--ok); }
.badge.best { background: #fff59d; color: #8d6e00; }
.sidebar-foot { border-top: 2px dashed #dfe8f3; margin-top: 8px; padding-top: 8px; display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; }
.toggle { display: flex; align-items: center; gap: 4px; cursor: pointer; }

.main { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.card {
  background: var(--card); border: 3px solid var(--border); border-radius: var(--radius);
  box-shadow: 6px 6px 0 rgba(27,58,92,0.18); padding: 14px;
}
.muted { color: var(--muted); }
.center { text-align: center; }

/* ---------------- Game ---------------- */
.game-card { padding: 0; overflow: hidden; }
#scene { display: block; width: 100%; height: auto; image-rendering: pixelated; }
.progress { height: 12px; background: #dfe8f3; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, #66bb6a, #ffd54f); transition: width .2s; }

/* ---------------- Text ---------------- */
.lesson-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 8px; }
.lesson-head h3 { margin: 0; font-size: 20px; }
.lesson-head p { margin: 2px 0 0; font-size: 13px; }
.btn {
  background: #fff; border: 2px solid var(--border); border-radius: 10px; padding: 8px 14px; font-weight: 800;
  cursor: pointer; color: var(--ink); box-shadow: 3px 3px 0 rgba(27,58,92,0.25); white-space: nowrap;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 rgba(27,58,92,0.25); }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 rgba(27,58,92,0.25); }
.btn.primary { background: var(--accent); color: #fff; border-color: #bf360c; }

.text-box {
  position: relative; height: 176px; overflow-y: auto; scroll-behavior: smooth;
  font-size: 22px; line-height: 1.8; padding: 10px 14px;
  background: #fbfdff; border: 2px solid #dfe8f3; border-radius: 12px; outline: none;
  word-break: normal; overflow-wrap: anywhere;
}
.text-box:focus { border-color: #90caf9; }
.word { white-space: nowrap; }
.ch { border-radius: 4px; color: #4b5d70; }
.ch.ok { color: var(--ok); }
.ch.cur { background: var(--accent2); color: var(--ink); box-shadow: 0 3px 0 var(--accent); animation: blink 1s infinite; }
.ch.bad { background: var(--bad); color: #fff; animation: none; }
.ch.nl { color: #b0bec5; font-size: 0.8em; }
.ch.nl.ok { color: #a5d6a7; }
.ch.sp.cur { padding: 0 3px; }
@keyframes blink { 50% { box-shadow: 0 3px 0 transparent; } }

.hint { margin-top: 10px; font-size: 16px; font-weight: 700; min-height: 26px; }
.hint kbd {
  display: inline-block; background: var(--ink); color: #fff; border-radius: 6px; padding: 1px 8px; font-family: inherit;
  font-weight: 900; box-shadow: 0 3px 0 #0d2036;
}
.fname { font-weight: 900; padding: 0 6px; border-radius: 6px; background: color-mix(in srgb, var(--fc) 35%, white); border-bottom: 3px solid var(--fc); }

/* ---------------- Keyboard + hands ---------------- */
.kb-and-hands { display: grid; grid-template-columns: 190px 1fr 190px; gap: 14px; align-items: end; }
.hand-wrap { width: 100%; }
body.no-hands .hand-wrap { visibility: hidden; }
.hand { width: 100%; height: auto; display: block; overflow: visible; }
.hand .skin { fill: #f8c89a; stroke: #b5794a; stroke-width: 2.5; }
.hand .palm-cover { stroke: none; }
.hand .tip { opacity: 0.9; stroke: rgba(0,0,0,0.15); stroke-width: 1; }
.hand .finger { transition: transform .12s; transform-box: fill-box; transform-origin: 50% 100%; }
.hand .finger .fbody { transition: fill .12s; }
.hand .finger.active { transform: translateY(-10px); }
.hand .finger.active .fbody { fill: var(--fc); stroke: #333; filter: drop-shadow(0 0 6px var(--fc)); }
.hand .finger.active .tip { fill: #fff !important; }
.hand .finger.shift .fbody { stroke-dasharray: 6 4; }
.hand .badge { display: none; }
.hand .finger.active .badge { display: block; }
.hand .badge circle { fill: #1b3a5c; stroke: #fff; stroke-width: 2.5; }
.hand .badge text { fill: #fff; font-weight: 900; font-family: 'Nunito', sans-serif; text-anchor: middle; }
.hand-label { font-size: 13px; font-weight: 900; fill: var(--muted); text-anchor: middle; letter-spacing: 2px; }

.keyboard { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.kb-row { display: flex; gap: 6px; }
.key {
  --fc: #cfd8dc;
  flex: 1; min-width: 0; height: 46px; border-radius: 8px; position: relative;
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  background: color-mix(in srgb, var(--fc) 32%, white);
  border: 2px solid rgba(27,58,92,0.35); border-bottom-width: 5px;
  font-weight: 800; font-size: 15px; color: var(--ink); user-select: none;
  transition: transform .08s, background .12s;
}
.key-top { font-size: 10px; line-height: 1; color: var(--muted); }
.key-bot { font-size: 14px; line-height: 1.1; }
.key-lab { font-size: 13px; }
.key.home-bump::after { content: ''; position: absolute; bottom: 6px; width: 12px; height: 3px; border-radius: 2px; background: rgba(27,58,92,0.5); }
.key.next {
  background: var(--fc); color: #fff; border-color: #1b3a5c;
  transform: scale(1.1); z-index: 2; box-shadow: 0 0 0 4px rgba(255,213,79,0.9), 0 0 16px var(--fc);
  animation: pulse .7s infinite alternate;
}
.key.next .key-top { color: rgba(255,255,255,0.8); }
.key.next-shift { background: var(--fc); color: #fff; border-style: dashed; border-color: #1b3a5c; box-shadow: 0 0 0 3px rgba(255,213,79,0.9); }
.key.pressed { transform: translateY(3px); border-bottom-width: 2px; filter: brightness(0.9); }
@keyframes pulse { to { transform: scale(1.18); } }

.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 12px; font-size: 12px; font-weight: 700; color: var(--muted); justify-content: center; }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-item i { width: 14px; height: 14px; border-radius: 4px; border: 1px solid rgba(0,0,0,0.2); }

/* ---------------- Results ---------------- */
.modal { position: fixed; inset: 0; background: rgba(13,32,54,0.6); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal.hidden { display: none; }
.modal-box {
  background: #fff; border: 4px solid var(--border); border-radius: 20px; padding: 24px 32px; width: min(520px, 92vw);
  text-align: center; box-shadow: 10px 10px 0 rgba(0,0,0,0.25); animation: pop .35s cubic-bezier(.2,1.6,.4,1);
}
@keyframes pop { from { transform: scale(0.6); opacity: 0; } }
.modal-box h2 { margin: 0 0 6px; font-size: 28px; }
.stars { font-size: 44px; color: #ffb300; letter-spacing: 6px; text-shadow: 2px 2px 0 #8d6e00; }
.stars .dim { color: #dfe8f3; text-shadow: none; }
.res-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 10px; margin: 16px 0 8px; }
.res-grid > div { background: #f4f8fc; border-radius: 12px; padding: 10px 6px; display: flex; flex-direction: column; }
.res-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 800; }
.res-value { font-family: 'Press Start 2P', monospace; font-size: 16px; margin-top: 8px; color: var(--ink); }
.res-unit { font-size: 10px; color: var(--muted); margin-top: 4px; }
.modal-actions { display: flex; gap: 12px; justify-content: center; margin-top: 12px; }

/* ---------------- Narrow screens ---------------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; }
  #lesson-list { max-height: 260px; }
  .kb-and-hands { grid-template-columns: 1fr; }
  .hand-wrap { width: 180px; margin: 0 auto; }
  .hand-wrap#hand-left { order: 2; }
  .hand-wrap#hand-right { order: 3; }
  .keyboard { order: 1; }
}
@media (max-width: 700px) {
  .key { height: 34px; font-size: 11px; }
  .key-bot { font-size: 11px; }
  .text-box { font-size: 18px; }
}

/* ---------------- Ads ---------------- */
.page { display: grid; grid-template-columns: minmax(0, 1fr); }
.ad-rail { display: none; padding: 16px 8px; }
.ad-rail .ad-box { position: sticky; top: 16px; width: 160px; min-height: 600px; margin: 0 auto; }
.ad-bottom { max-width: 1500px; margin: 0 auto; padding: 0 16px 16px; }
.ad-bottom .ad-box { min-height: 90px; width: 100%; }
.ad-box.placeholder {
  display: flex; align-items: center; justify-content: center;
  border: 2px dashed rgba(27,58,92,0.35); border-radius: 12px; color: var(--muted);
  font-size: 12px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase;
  background: repeating-linear-gradient(45deg, rgba(255,255,255,0.5) 0 10px, rgba(223,232,243,0.6) 10px 20px);
}
@media (min-width: 1560px) {
  .page { grid-template-columns: 180px minmax(0, 1fr) 180px; }
  .ad-rail { display: block; }
  .ad-bottom { display: none; }
}
.footer { text-align: center; font-size: 12px; color: var(--muted); padding: 8px 16px 20px; }
.footer a { color: var(--ink); font-weight: 700; }

/* ---------------- Content pages (About, Contact, Guides, Privacy) ---------------- */
.topbar .logo a, .topbar .logo a:visited, .topbar .logo a:hover { color: #fff; text-decoration: none; display: inline-flex; align-items: baseline; gap: 10px; }
.site-nav { display: flex; gap: 16px; flex-wrap: wrap; font-weight: 800; font-size: 14px; }
.site-nav a { color: #fff; text-decoration: none; opacity: 0.9; }
.site-nav a:hover { opacity: 1; text-decoration: underline; }
.doc { max-width: 780px; margin: 24px auto; padding: 28px 32px; }
.doc h1 { margin-top: 0; font-size: 30px; }
.doc h2 { font-size: 20px; margin-top: 28px; }
.doc p, .doc li { line-height: 1.7; font-size: 17px; }
.doc .lead { font-size: 19px; color: var(--muted); }
.doc a { color: #c62828; font-weight: 700; }
.doc .cta { display: inline-block; margin-top: 12px; text-decoration: none; color: #fff; }
.doc img.mog { float: right; width: 128px; height: auto; image-rendering: pixelated; margin: 0 0 12px 20px; }
.doc .tip { background: #fff8e1; border-left: 5px solid var(--accent2); padding: 10px 14px; border-radius: 8px; }
.guide-list { display: grid; gap: 12px; padding: 0; list-style: none; }
.guide-list a { display: block; background: #f4f8fc; border-radius: 12px; padding: 14px 16px; text-decoration: none; color: var(--ink); font-weight: 400; }
.guide-list a:hover { background: #e3eefa; }
.guide-list b { display: block; font-size: 17px; margin-bottom: 2px; }
.footer nav { margin-top: 6px; display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
@media (max-width: 600px) { .doc { margin: 12px; padding: 20px; } .doc img.mog { width: 96px; } }
