/* ----- Reset / base ----- */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(180deg, #87ceeb 0%, #b9e3f4 60%, #d8f1c7 100%);
  color: #1f2933;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  display: flex;
  align-items: flex-start;     /* anchor at top so tall content scrolls naturally */
  justify-content: center;
  padding: 16px;
}

/* ----- Shell layout ----- */
.game-shell {
  width: 100%;
  max-width: 940px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  border-radius: 20px;
  padding: 16px;
  box-shadow: 0 20px 60px -20px rgba(15, 23, 42, 0.4);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ----- HUD ----- */
.hud {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.hud-item {
  background: white;
  border-radius: 12px;
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  font-weight: 700;
  font-size: 18px;
  min-width: 80px;
  border: 2px solid rgba(31, 41, 51, 0.08);
}
.hud-grow { margin-left: auto; }
.hud-back {
  text-decoration: none;
  color: #1f2933;
  background: white;
  padding: 8px 14px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 13px;
  border: 2px solid rgba(31, 41, 51, 0.08);
  transition: background 0.15s;
}
.hud-back:hover { background: #f1f5f9; }
.hud-link {
  margin-left: auto;
  text-decoration: none;
  color: white;
  background: #f59e0b;
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 14px;
  transition: background 0.15s, transform 0.08s;
}
.hud-link:hover { background: #d97706; transform: translateY(-1px); }
.hud-lang {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  background: white;
  border: 2px solid rgba(31, 41, 51, 0.08);
  border-radius: 10px;
  padding: 7px 8px;
  cursor: pointer;
  margin-left: auto;
}
.hud-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #64748b;
}

/* ----- Stage / canvas ----- */
.stage {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  background: linear-gradient(180deg, #87ceeb 0%, #aedef0 70%, #fff7c2 100%);
  border: 3px solid rgba(31, 41, 51, 0.12);
}
canvas#game {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 900 / 420;
}

/* ----- Overlay (start / game over) ----- */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease;
}
.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}
.overlay-card {
  background: white;
  padding: 24px 32px;
  border-radius: 16px;
  text-align: center;
  max-width: 420px;
  box-shadow: 0 20px 50px -10px rgba(0, 0, 0, 0.4);
}
.overlay-card h1 {
  font-size: 32px;
  margin-bottom: 8px;
  color: #f59e0b;
}
.overlay-card p { margin-bottom: 14px; color: #475569; }
.overlay-card .hint { font-size: 13px; color: #64748b; }
.overlay-card kbd {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 2px 6px;
  font-family: inherit;
  font-size: 12px;
  margin: 0 1px;
}
button#start-btn {
  background: #10b981;
  color: white;
  border: none;
  font-size: 18px;
  font-weight: 700;
  padding: 12px 28px;
  border-radius: 12px;
  cursor: pointer;
  margin-bottom: 10px;
  transition: transform 0.1s, background 0.2s;
}
button#start-btn:hover { background: #059669; transform: translateY(-1px); }
button#start-btn:active { transform: translateY(0); }

/* ----- Teaching panel ----- */
.teaching {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 14px;
}
@media (max-width: 720px) {
  .teaching { grid-template-columns: 1fr; }
}

.hands-wrap, .keyboard-wrap {
  background: white;
  border-radius: 14px;
  padding: 12px;
  border: 2px solid rgba(31, 41, 51, 0.08);
}
.panel-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
  margin-bottom: 8px;
}

.hands {
  display: flex;
  align-items: center;
  justify-content: center;
}
.hands svg { width: 100%; height: auto; max-height: 180px; }

/* ----- Keyboard ----- */
.keyboard {
  display: flex;
  flex-direction: column;
  gap: 4px;
  user-select: none;
}
.kb-row {
  display: flex;
  gap: 4px;
  justify-content: center;
}
.kb-key {
  flex: 1 1 auto;
  min-width: 24px;
  height: 32px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  border: 2px solid rgba(0, 0, 0, 0.08);
  border-bottom-width: 3px;
  transition: transform 0.08s, box-shadow 0.08s, filter 0.12s;
}
.kb-key.kb-wide { flex: 2.2; font-size: 11px; }
.kb-key.kb-space { flex: 8; font-size: 11px; }
.kb-key.is-target {
  filter: brightness(1.15) saturate(1.1);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.9), 0 0 0 5px currentColor;
  transform: translateY(-2px);
  animation: pulse 0.8s infinite alternate;
}
.kb-key.is-pressed {
  transform: translateY(2px);
  filter: brightness(0.85);
  border-bottom-width: 1px;
}
@keyframes pulse {
  from { box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.9), 0 0 0 5px currentColor; }
  to   { box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.6), 0 0 0 8px currentColor; }
}

/* ----- Name row (always visible on overlay) ----- */
.name-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 14px;
  padding: 8px 14px;
  background: #f8fafc;
  border-radius: 12px;
  border: 1.5px solid #cbd5e1;
}
.name-row label {
  font-size: 13px;
  font-weight: 700;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.name-row input {
  font: inherit;
  font-weight: 700;
  font-size: 18px;
  text-align: center;
  width: 140px;
  padding: 6px 8px;
  border: 1.5px solid transparent;
  border-radius: 8px;
  outline: none;
  background: white;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.name-row input:focus {
  border-color: #f59e0b;
}
.name-row input.shake {
  animation: shake 0.35s;
  border-color: #ef4444;
}

/* ----- Score entry & leaderboard ----- */
.score-entry {
  margin: 16px 0 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}
.score-entry .se-prompt {
  font-size: 14px;
  color: #475569;
  font-weight: 600;
}
.score-entry .se-hint {
  font-size: 12px;
  color: #94a3b8;
}
.score-entry .se-saved-mode {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: #475569;
  font-weight: 600;
}
.score-entry .se-saved-name {
  color: #f59e0b;
  font-weight: 800;
  letter-spacing: 0.04em;
}
.score-entry .se-change-link {
  background: none;
  border: none;
  padding: 2px 6px;
  font: inherit;
  font-size: 12px;
  color: #64748b;
  cursor: pointer;
  text-decoration: underline;
}
.score-entry .se-change-link:hover { color: #1f2933; }
.score-entry input {
  font: inherit;
  font-weight: 700;
  font-size: 18px;
  text-align: center;
  width: 200px;
  padding: 10px 12px;
  border: 2px solid #cbd5e1;
  border-radius: 10px;
  outline: none;
  letter-spacing: 0.04em;
  background: #f8fafc;
  text-transform: uppercase;
}
.score-entry input:focus {
  border-color: #f59e0b;
  background: white;
}
.score-entry input.shake {
  animation: shake 0.35s;
  border-color: #ef4444;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-3px); }
}
.score-entry-buttons {
  display: flex;
  gap: 8px;
}
.score-entry button {
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
  border: none;
}
.score-entry button.primary { background: #10b981; color: white; }
.score-entry button.primary:hover { background: #059669; }
.score-entry button.secondary { background: #e2e8f0; color: #1f2933; }
.score-entry button.secondary:hover { background: #cbd5e1; }
.score-entry button:disabled { opacity: 0.55; cursor: wait; }

.leaderboard {
  margin: 12px 0;
  text-align: left;
}
.leaderboard h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
  margin-bottom: 8px;
  text-align: center;
}
.leaderboard ol {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 280px;
  overflow-y: auto;
}
.lb-item {
  display: grid;
  grid-template-columns: 28px 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  background: #f8fafc;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
}
.lb-item.lb-empty {
  display: block;
  text-align: center;
  color: #64748b;
  font-style: italic;
}
.lb-rank { color: #94a3b8; font-variant-numeric: tabular-nums; }
.lb-name { font-weight: 700; color: #0f172a; }
.lb-score {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  color: #f59e0b;
}
.lb-level {
  font-size: 11px;
  color: #64748b;
  background: #e2e8f0;
  padding: 2px 7px;
  border-radius: 999px;
}
.lb-mine {
  background: linear-gradient(90deg, #fef3c7, #fde68a);
  border: 1px solid #f59e0b;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.25);
}

/* ----- Hand SVG finger pads ----- */
.finger-pad {
  fill: #e2e8f0;
  stroke: #94a3b8;
  stroke-width: 1.5;
  transition: fill 0.15s;
}
.finger-pad.is-active {
  fill: var(--finger-color, #ffd43b);
  stroke: rgba(0, 0, 0, 0.25);
  stroke-width: 2;
}
.hand-outline {
  fill: rgba(255, 220, 200, 0.35);
  stroke: #94a3b8;
  stroke-width: 1.2;
}
