:root {
  --bg: #ececef;
  --bg-2: #e2e2e6;
  --panel: #f5f5f7;
  --panel-2: #eaeaee;
  --ink: #1f2024;
  --muted: #7a7c85;
  --line: #d3d4da;
  --accent: #2b2d33;
  --danger: #b04a4a;
  --ok: #3e6b55;

  --key-bg: #ffffff;
  --key-edge: #c9cad0;
  --key-ink: #2b2d33;

  /* muted greys for finger assignment on keys (very subtle) */
  --finger-L-pinky:  #c8c9cf;
  --finger-L-ring:   #d3d4da;
  --finger-L-middle: #dddee3;
  --finger-L-index:  #c1c3ca;
  --finger-thumb:    #cccdd2;
  --finger-R-index:  #c1c3ca;
  --finger-R-middle: #dddee3;
  --finger-R-ring:   #d3d4da;
  --finger-R-pinky:  #c8c9cf;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, -apple-system, system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.app {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

/* --- TOP --- */
.top {
  display: flex;
  flex-direction: column;
  padding: 22px 32px 10px 32px;
  gap: 14px;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.4px;
  color: var(--muted);
  text-transform: uppercase;
}

.stats {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.stat {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 12px;
  min-width: 80px;
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.stat .label { font-size: 9px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.2px; }
.stat .value { font-size: 16px; font-weight: 600; color: var(--ink); }
.stat .sub   { font-size: 10px; color: var(--muted); margin-top: 2px; }

.actions { display: flex; gap: 4px; margin-left: 4px; }
.btn {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 7px 12px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--panel-2); border-color: #b8b9c0; }
.btn.ghost { border-color: transparent; }
.btn.ghost:hover { background: var(--panel-2); border-color: var(--line); }

/* Prompt */
.prompt-wrap {
  background: transparent;
  border: none;
  padding: 18px 0 6px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.prompt {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: clamp(26px, 3.6vw, 44px);
  line-height: 1.4;
  letter-spacing: 3px;
  white-space: pre-wrap;
  word-break: break-word;
  outline: none;
  user-select: none;
  color: var(--muted);
  font-weight: 400;
}

.prompt .ch {
  color: #b4b6bd;
  position: relative;
  padding: 0 2px;
  transition: color .1s, background .1s;
}
.prompt .ch.done { color: #4a4c52; }
.prompt .ch.wrong {
  color: var(--danger);
  text-decoration: underline wavy var(--danger);
  text-underline-offset: 6px;
}
.prompt .ch.current {
  color: var(--ink);
  background: #1f2024;
  color: #fafafb;
  border-radius: 4px;
}

.hint {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}
.status.ok { color: var(--ok); }
.status.bad { color: var(--danger); }

/* --- BOTTOM (keyboard with overlaid transparent hands) --- */
.bottom {
  padding: 0 28px 28px 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.stage {
  position: relative;
  width: 100%;
  max-width: 1200px;
  aspect-ratio: 16 / 6;
  max-height: 60vh;
}

.keyboard {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 22px;
  background: linear-gradient(180deg, #f3f3f6 0%, #e3e4e9 100%);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow:
    0 1px 0 rgba(255,255,255,0.6) inset,
    0 18px 40px rgba(30,30,40,0.08);
}
.kb-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex: 1;
}
.key {
  position: relative;
  min-width: 0;
  flex: 1 1 0;
  max-width: 90px;
  padding: 0 10px;
  border-radius: 10px;
  background: var(--key-bg);
  border: 1px solid var(--key-edge);
  box-shadow: 0 2px 0 #c0c1c8, inset 0 1px 0 rgba(255,255,255,0.9);
  color: var(--key-ink);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 15px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: lowercase;
  letter-spacing: 0.5px;
  user-select: none;
}
.key.wide { flex: 1.4 1 0; }
.key.wider { flex: 1.8 1 0; }
/* Bottom row: Ctrl / Alt stay fixed-width; space bar stretches to fill. */
.kb-row:last-child .key { flex: 0 0 auto; min-width: 70px; max-width: none; }
.kb-row:last-child .key.space {
  flex: 1 1 auto;
  min-width: 0;
  max-width: none;
}

.key[data-finger="L-pinky"]  { background: color-mix(in oklab, var(--key-bg) 80%, var(--finger-L-pinky)); }
.key[data-finger="L-ring"]   { background: color-mix(in oklab, var(--key-bg) 80%, var(--finger-L-ring)); }
.key[data-finger="L-middle"] { background: color-mix(in oklab, var(--key-bg) 80%, var(--finger-L-middle)); }
.key[data-finger="L-index"]  { background: color-mix(in oklab, var(--key-bg) 80%, var(--finger-L-index)); }
.key[data-finger="L-thumb"], .key[data-finger="R-thumb"] { background: color-mix(in oklab, var(--key-bg) 85%, var(--finger-thumb)); }
.key[data-finger="R-index"]  { background: color-mix(in oklab, var(--key-bg) 80%, var(--finger-R-index)); }
.key[data-finger="R-middle"] { background: color-mix(in oklab, var(--key-bg) 80%, var(--finger-R-middle)); }
.key[data-finger="R-ring"]   { background: color-mix(in oklab, var(--key-bg) 80%, var(--finger-R-ring)); }
.key[data-finger="R-pinky"]  { background: color-mix(in oklab, var(--key-bg) 80%, var(--finger-R-pinky)); }

.key.home::after {
  content: "";
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 14px;
  height: 2px;
  border-radius: 2px;
  background: #8e8f96;
}

.key.target {
  background: #1f2024;
  color: #fafafb;
  border-color: #1f2024;
  box-shadow:
    0 2px 0 #0f0f12,
    0 0 0 4px rgba(31,32,36,0.12),
    inset 0 1px 0 rgba(255,255,255,0.08);
  transform: translateY(-1px);
}
.key.pressed {
  transform: translateY(1px);
  box-shadow: 0 0 0 2px rgba(0,0,0,0.08) inset;
}

/* Hands overlay — transparent, sits on top of the keyboard.
   Hands are pinned at a fixed home position (JS computes once and on resize).
   The active finger extends or retracts so its tip reaches the target key. */
.hands-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  overflow: visible;
}
.hand {
  position: absolute;
  width: 30%;
  height: auto;
  opacity: 0.55;
  filter: drop-shadow(0 8px 14px rgba(30,30,40,0.18));
  overflow: visible;
}
svg.hand { overflow: visible; }
.hand.left  { left: 6%; top: 0; }
.hand.right { right: 6%; top: 0; }

.hand .palm {
  fill: #ffffff;
  stroke: #5a5c63;
  stroke-width: 2;
}
.finger .bone {
  stroke: #ffffff;
  fill: none;
  paint-order: stroke;
  /* subtle edge via filter below */
  filter: drop-shadow(0 0 0.6px #5a5c63) drop-shadow(0 0 0.6px #5a5c63);
}
.finger .tip {
  fill: rgba(255,255,255,0);
  stroke: rgba(90,92,99,0);
}

/* Highlighted finger */
.finger.active .bone {
  stroke: #1f2024;
  filter: drop-shadow(0 0 0.6px #0f0f12) drop-shadow(0 0 0.6px #0f0f12);
}
.finger.active .tip {
  fill: #fafafb;
  stroke: #1f2024;
  stroke-width: 2;
}

@media (max-width: 900px) {
  .stage { aspect-ratio: 16 / 7; }
  .key { font-size: 12px; padding: 0 6px; }
  .prompt { letter-spacing: 2px; }
}
