:root {
  --bg: #f7f9fc;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1f2937;
  --muted: #94a3b8;
  --done: #16a34a;
  --done-soft: #dcfce7;
  --next: #f59e0b;
  --next-soft: #fef3c7;
  --wrong: #dc2626;
  --wrong-soft: #fee2e2;
  --accent: #2563eb;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 12px rgba(0,0,0,.06);
  --radius: 10px;
  --key-bg: #fff;
  --key-edge: #cbd5e1;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.header h1 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 700;
}
.header .subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- Stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.stat-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.stat-value {
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---------- Lesson text ---------- */
.lesson {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px 28px;
  font-family: "SF Mono", Menlo, Monaco, "Courier New", monospace;
  font-size: 28px;
  line-height: 1.7;
  letter-spacing: .04em;
  word-spacing: .15em;
  white-space: pre-wrap;
  text-transform: uppercase;
  text-align: center;
  box-shadow: var(--shadow);
  user-select: none;
}
.word-caption { text-transform: uppercase; }
.char {
  display: inline-block;
  padding: 0 1px;
  border-radius: 4px;
  color: #475569;
  transition: background .08s, color .08s;
}
.char.done { color: var(--done); }
.char.wrong { color: var(--wrong); background: var(--wrong-soft); }
.char.current {
  background: var(--next-soft);
  color: #92400e;
  outline: 2px solid var(--next);
  outline-offset: 1px;
}
.char.space.current { background: var(--next-soft); }
.char.space::before { content: "\00a0"; }

/* ---------- Keyboard ---------- */
.keyboard {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 6px;
  --u: 44px; /* one key unit */
}
.kb-row {
  display: flex;
  gap: 6px;
  justify-content: center;
}
.key {
  height: var(--u);
  min-width: var(--u);
  padding: 0 8px;
  background: var(--key-bg);
  border: 1px solid var(--key-edge);
  border-bottom-width: 2px;
  border-radius: 6px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", sans-serif;
  font-size: 13px;
  font-weight: 500;
  color: #334155;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  user-select: none;
  transition: background .08s, color .08s, border-color .08s, transform .08s;
}
.key.wide-1\.25 { min-width: calc(var(--u) * 1.25); }
.key.wide-1\.5  { min-width: calc(var(--u) * 1.5); }
.key.wide-1\.75 { min-width: calc(var(--u) * 1.75); }
.key.wide-2     { min-width: calc(var(--u) * 2); }
.key.wide-2\.25 { min-width: calc(var(--u) * 2.25); }
.key.wide-5     { min-width: calc(var(--u) * 5); }
.key.small {
  height: calc(var(--u) * .55);
  font-size: 11px;
}
.key.modifier {
  font-size: 11px;
  color: #64748b;
  justify-content: flex-end;
  padding: 4px 6px;
  align-items: flex-end;
}
.key[data-key="f"]::after,
.key[data-key="j"]::after {
  content: "";
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 12px;
  height: 2px;
  background: #94a3b8;
  border-radius: 2px;
}
.key.next {
  background: var(--next-soft);
  border-color: var(--next);
  color: #92400e;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, .25);
}
.key.flash-good {
  background: var(--done-soft);
  border-color: var(--done);
  color: var(--done);
  transform: translateY(1px);
}
.key.flash-bad {
  background: var(--wrong-soft);
  border-color: var(--wrong);
  color: var(--wrong);
  transform: translateY(1px);
}

/* Half-height function row */
.kb-row.fn-row .key { height: calc(var(--u) * .55); font-size: 10px; }

/* ---------- Hands ---------- */
.hands {
  display: flex;
  justify-content: center;
  gap: 60px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.hand {
  position: relative;
  display: inline-block;
  line-height: 0;
}
.hand img {
  display: block;
  width: 280px;
  height: auto;
}
.hand img.flip-x {
  transform: scaleX(-1);
}
.finger-dot {
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: transparent;
  border: 3px solid transparent;
  transform: translate(-50%, -50%);
  pointer-events: none;
  transition: background .12s, border-color .12s, box-shadow .12s, transform .12s;
}
.finger-dot.active {
  background: var(--next);
  border-color: #fff;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, .35);
  transform: translate(-50%, -50%) scale(1.15);
}

/* Tọa độ ngón tay theo SVG Hand2011.svg (viewBox 678x501) — tính bằng % */
/* Tay trái: ngón cái ở bên phải, ngón út ở bên trái */
.hand-left .finger-dot[data-finger="left-pinky"]  { left: 19%; top: 36%; }
.hand-left .finger-dot[data-finger="left-ring"]   { left: 28%; top: 14%; }
.hand-left .finger-dot[data-finger="left-middle"] { left: 37%; top: 7%; }
.hand-left .finger-dot[data-finger="left-index"]  { left: 49.5%; top: 9%; }
.hand-left .finger-dot[data-finger="left-thumb"]  { left: 76%; top: 38%; }
/* Tay phải = tay trái lật ngang (scaleX(-1)), nên hoán đổi left = 100% - left */
.hand-right .finger-dot[data-finger="right-pinky"]  { left: 81%; top: 36%; }
.hand-right .finger-dot[data-finger="right-ring"]   { left: 72%; top: 14%; }
.hand-right .finger-dot[data-finger="right-middle"] { left: 63%; top: 7%; }
.hand-right .finger-dot[data-finger="right-index"]  { left: 50.5%; top: 9%; }
.hand-right .finger-dot[data-finger="right-thumb"]  { left: 24%; top: 38%; }

/* ---------- Overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.overlay[hidden] { display: none; }
.overlay-card {
  background: #fff;
  border-radius: 14px;
  padding: 28px 32px;
  width: min(420px, 92vw);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.overlay-card h2 { margin: 0 0 8px; font-size: 24px; }
.overlay-card p { margin: 0 0 16px; color: var(--muted); }
.overlay-stats {
  list-style: none;
  padding: 0;
  margin: 0 0 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 15px;
}
.overlay-stats li b { font-variant-numeric: tabular-nums; }
.overlay-card button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.overlay-card button:hover { background: #1d4ed8; }

/* ---------- Lesson list (index.php) ---------- */
.lesson-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}
.lesson-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow);
  transition: transform .08s, border-color .08s;
}
.lesson-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}
.lesson-card-id {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.lesson-card-title { font-weight: 600; font-size: 16px; }

.back-link { margin: 0 0 8px; font-size: 13px; }
.back-link a { color: var(--accent); text-decoration: none; }
.back-link a:hover { text-decoration: underline; }

/* ---------- Word card (bài 2 — words) ---------- */
.word-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow);
}
.word-card img {
  max-width: 220px;
  max-height: 180px;
  object-fit: contain;
  display: block;
}
.word-caption {
  font-size: 16px;
  color: var(--muted);
  font-style: italic;
}
