/* Keypath — precision instrument aesthetic */
:root {
  --bg: #0a0d12;
  --bg-elev: #11161f;
  --bg-elev-2: #171d28;
  --line: #243041;
  --line-soft: #1a2230;
  --text: #e8edf5;
  --muted: #8b97a8;
  --faint: #5c6778;
  --amber: #f0b429;
  --amber-dim: rgba(240, 180, 41, 0.14);
  --coral: #ff6b6b;
  --coral-dim: rgba(255, 107, 107, 0.16);
  --mint: #3dd68c;
  --mint-dim: rgba(61, 214, 140, 0.14);
  --sky: #5b9fd4;
  --sky-dim: rgba(91, 159, 212, 0.14);
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  --font-ui: "Outfit", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-ui);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(240, 180, 41, 0.08), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(91, 159, 212, 0.07), transparent 50%),
    radial-gradient(700px 400px at 50% 100%, rgba(61, 214, 140, 0.04), transparent 45%),
    var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.noise {
  pointer-events: none;
  position: fixed;
  inset: 0;
  opacity: 0.035;
  z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.app {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2.5rem;
}

/* —— Top bar —— */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.brand {
  display: flex;
  gap: 0.9rem;
  align-items: center;
}

.brand-mark {
  width: 2.6rem;
  height: 2.6rem;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(145deg, #1c2433, #121820);
  border: 1px solid var(--line);
  color: var(--amber);
  font-weight: 700;
  font-size: 1.2rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.brand h1 {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.tagline {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.topbar-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  justify-content: flex-end;
}

.layout-picker {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.3rem 0.35rem 0.3rem 0.75rem;
  background: var(--bg-elev);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  font-size: 0.82rem;
  color: var(--muted);
}

.layout-picker-label {
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.68rem;
  color: var(--faint);
}

.layout-picker select {
  appearance: auto; /* keep native dropdown so it always opens */
  -webkit-appearance: menulist;
  border: 0;
  background: var(--bg);
  color: var(--text);
  font: 500 0.88rem/1.2 var(--font-ui);
  padding: 0.45rem 0.55rem;
  min-width: 11.5rem;
  max-width: 16rem;
  border-radius: 999px;
  cursor: pointer;
  position: relative;
  z-index: 5;
}

.layout-picker select:focus,
.layout-picker select:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.mode-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.3rem;
  background: var(--bg-elev);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
}

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 500 0.88rem/1 var(--font-ui);
  padding: 0.65rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.2s var(--ease), background 0.2s var(--ease), transform 0.15s var(--ease);
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  background: var(--amber-dim);
  color: var(--amber);
  box-shadow: inset 0 0 0 1px rgba(240, 180, 41, 0.25);
}

.tab:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

/* —— Layout —— */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(280px, 0.9fr);
  gap: 1.15rem;
  align-items: start;
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

.stage,
.panel {
  background: linear-gradient(180deg, rgba(23, 29, 40, 0.92), rgba(17, 22, 31, 0.96));
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stage {
  padding: 1.15rem 1.2rem 1.25rem;
  min-height: 520px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* —— Stats —— */
.stats-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.6rem;
}

@media (max-width: 720px) {
  .stats-row {
    grid-template-columns: repeat(2, 1fr);
  }
  .stat.highlight {
    grid-column: 1 / -1;
  }
}

.stat {
  background: var(--bg);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.8rem;
}

.stat.highlight {
  border-color: rgba(240, 180, 41, 0.28);
  background: linear-gradient(160deg, var(--amber-dim), transparent 70%), var(--bg);
}

.stat-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--faint);
  margin-bottom: 0.25rem;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--text);
}

.stat-value.small {
  font-size: 1rem;
  letter-spacing: 0;
  text-transform: none;
  color: var(--amber);
}

.unit {
  font-size: 0.75em;
  color: var(--muted);
  margin-left: 0.1em;
}

/* —— Prompt —— */
.prompt-card {
  position: relative;
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) - 2px);
  padding: 1.1rem 1.15rem 1.3rem;
  min-height: 140px;
  cursor: text;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.prompt-card.focused {
  border-color: rgba(240, 180, 41, 0.45);
  box-shadow: 0 0 0 3px rgba(240, 180, 41, 0.08);
}

.prompt-card.finished {
  opacity: 0.45;
  pointer-events: none;
}

.prompt-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--sky);
  background: var(--sky-dim);
  border: 1px solid rgba(91, 159, 212, 0.25);
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
}

.prompt-hint {
  color: var(--faint);
  font-size: 0.85rem;
}

.prompt {
  font-family: var(--font-mono);
  font-size: clamp(1.15rem, 2.2vw, 1.45rem);
  line-height: 1.85;
  letter-spacing: 0.01em;
  word-break: break-word;
  outline: none;
  user-select: none;
}

.ch {
  border-radius: 3px;
  transition: background 0.1s ease, color 0.1s ease;
}

.ch.pending {
  color: var(--muted);
}

.ch.correct {
  color: var(--text);
}

.ch.incorrect {
  color: var(--coral);
  background: var(--coral-dim);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.ch.current {
  color: var(--bg);
  background: var(--amber);
  box-shadow: 0 0 0 1px rgba(240, 180, 41, 0.5), 0 0 18px rgba(240, 180, 41, 0.25);
  animation: caret-pulse 1.1s ease-in-out infinite;
}

.ch.current.incorrect-live {
  background: var(--coral);
  box-shadow: 0 0 0 1px rgba(255, 107, 107, 0.45);
}

.ch.space.incorrect {
  background: var(--coral-dim);
}

@keyframes caret-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 1px rgba(240, 180, 41, 0.5), 0 0 12px rgba(240, 180, 41, 0.2);
  }
  50% {
    box-shadow: 0 0 0 1px rgba(240, 180, 41, 0.7), 0 0 22px rgba(240, 180, 41, 0.35);
  }
}

.hidden-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
  left: 0;
  top: 0;
}

/* —— Actions / buttons —— */
.stage-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: flex-end;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  color: var(--text);
  font: 600 0.9rem/1 var(--font-ui);
  padding: 0.72rem 1.1rem;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s var(--ease), background 0.15s var(--ease), border-color 0.15s var(--ease);
}

.btn:hover {
  transform: translateY(-1px);
  border-color: #364457;
}

.btn:active {
  transform: translateY(0);
}

.btn:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.btn.primary {
  background: linear-gradient(180deg, #f6c44a, #e0a51a);
  color: #1a1406;
  border-color: transparent;
  box-shadow: 0 8px 20px rgba(240, 180, 41, 0.2);
}

.btn.primary:hover {
  border-color: transparent;
  filter: brightness(1.04);
}

.btn.ghost {
  background: transparent;
}

.linkish {
  appearance: none;
  border: 0;
  background: none;
  color: var(--muted);
  font: 500 0.82rem var(--font-ui);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 0;
}

.linkish:hover {
  color: var(--coral);
}

/* —— Result —— */
.result-panel {
  border: 1px solid rgba(61, 214, 140, 0.25);
  background: linear-gradient(160deg, var(--mint-dim), transparent 55%), var(--bg);
  border-radius: var(--radius-sm);
  padding: 1rem 1.1rem;
  animation: rise 0.35s var(--ease);
}

.result-panel.hidden {
  display: none;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.result-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.result-grid h2 {
  margin: 0 0 0.25rem;
  font-size: 1.15rem;
}

.muted {
  color: var(--muted);
}

.muted.small,
.small {
  font-size: 0.85rem;
}

.result-metrics {
  display: flex;
  gap: 1.1rem;
  font-family: var(--font-mono);
}

.result-metrics .label {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--faint);
  margin-bottom: 0.15rem;
}

.result-metrics strong {
  font-size: 1.25rem;
}

.result-insights {
  margin: 0 0 0.9rem;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.45rem;
}

.result-insights li {
  font-size: 0.92rem;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
  border-left: 3px solid var(--amber);
}

/* —— Sidebar —— */
.sidebar {
  display: grid;
  gap: 1rem;
}

.panel {
  padding: 1rem 1.05rem 1.1rem;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.panel-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* Weak list */
.weak-list {
  display: grid;
  gap: 0.45rem;
}

.weak-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.65rem;
  align-items: center;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--line-soft);
}

.weak-key {
  font-family: var(--font-mono);
  font-weight: 600;
  min-width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--coral-dim);
  color: var(--coral);
  border: 1px solid rgba(255, 107, 107, 0.25);
}

.weak-meta {
  min-width: 0;
}

.weak-meta strong {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
}

.weak-meta span {
  font-size: 0.78rem;
  color: var(--muted);
}

.weak-bar {
  width: 52px;
  height: 6px;
  border-radius: 999px;
  background: var(--line-soft);
  overflow: hidden;
}

.weak-bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--amber), var(--coral));
  border-radius: inherit;
}

.empty-state {
  color: var(--faint);
  font-size: 0.88rem;
  padding: 0.4rem 0;
}

/* Keyboard heatmap */
.keyboard {
  display: grid;
  gap: 0.3rem;
  font-family: var(--font-mono);
}

.kb-row {
  display: flex;
  justify-content: center;
  gap: 0.28rem;
}

.kb-key {
  min-width: 1.7rem;
  height: 1.7rem;
  padding: 0 0.15rem;
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 500;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--line-soft);
  color: var(--muted);
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.kb-key.wide {
  min-width: 3.2rem;
  font-size: 0.62rem;
}

.kb-key.hot-1 {
  background: rgba(240, 180, 41, 0.12);
  border-color: rgba(240, 180, 41, 0.28);
  color: #e6c36a;
}
.kb-key.hot-2 {
  background: rgba(240, 140, 60, 0.2);
  border-color: rgba(240, 140, 60, 0.35);
  color: #f0a060;
}
.kb-key.hot-3 {
  background: rgba(255, 107, 107, 0.28);
  border-color: rgba(255, 107, 107, 0.45);
  color: #ff9a9a;
  font-weight: 700;
}
.kb-key.solid {
  background: rgba(61, 214, 140, 0.1);
  border-color: rgba(61, 214, 140, 0.22);
  color: #7fd9a8;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
  margin: 0.7rem 0 0;
}

.swatch {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 3px;
  display: inline-block;
  margin-right: 0.2rem;
  vertical-align: -1px;
}
.swatch.cold {
  background: rgba(61, 214, 140, 0.45);
}
.swatch.warm {
  background: rgba(240, 180, 41, 0.55);
}
.swatch.hot {
  background: rgba(255, 107, 107, 0.7);
}

/* Coach */
.coach-tip {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text);
  line-height: 1.55;
}

.coach-tip + .coach-tip {
  margin-top: 0.65rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 0.88rem;
}

.coach-tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--amber);
  margin-bottom: 0.3rem;
}

/* Session */
.session-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.mini {
  background: var(--bg);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
}

.mini span {
  display: block;
  font-size: 0.72rem;
  color: var(--faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.mini strong {
  font-family: var(--font-mono);
  font-size: 1.05rem;
}

.history {
  display: grid;
  gap: 0.35rem;
  max-height: 160px;
  overflow: auto;
}

.history-item {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--muted);
  padding: 0.35rem 0.2rem;
  border-bottom: 1px solid var(--line-soft);
}

.history-item strong {
  color: var(--text);
  font-family: var(--font-mono);
  font-weight: 500;
}

.footer {
  margin-top: 1.25rem;
  text-align: center;
  color: var(--faint);
  font-size: 0.8rem;
}

/* —— Hands guide (TypingClub-style finger teaching) —— */
.hands-panel {
  background: var(--bg);
  border: 1px solid var(--line-soft);
  border-radius: calc(var(--radius) - 2px);
  padding: 0.75rem 0.85rem 0.65rem;
  overflow: hidden;
}

.hands-guide {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.finger-cue {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  background: linear-gradient(120deg, rgba(240, 180, 41, 0.06), transparent 55%), #0c1018;
  border: 1px solid var(--line-soft);
}

.finger-cue-dot {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 12px currentColor;
  background: var(--faint);
  transition: background 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.finger-cue-text {
  flex: 1;
  min-width: 0;
}

.finger-cue-text strong {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.finger-cue-text span {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.35;
  margin-top: 0.1rem;
}

.finger-cue-key {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 600;
  min-width: 2.4rem;
  height: 2.4rem;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  background: var(--bg-elev);
  color: var(--muted);
  padding: 0 0.45rem;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.hands-svg {
  width: 100%;
  height: auto;
  display: block;
  max-height: 300px;
  border-radius: 12px;
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(91, 159, 212, 0.06), transparent 60%),
    #0b0f16;
}

.hands-scene {
  transform-origin: center center;
}

.guide-key .key-face {
  transition: fill 0.18s var(--ease), stroke 0.18s var(--ease), stroke-width 0.18s var(--ease), fill-opacity 0.18s;
}

.guide-key.is-target .key-label {
  fill: #0a0d12 !important;
  opacity: 1 !important;
  font-weight: 700;
}

.finger-body,
.finger-accent,
.palm-fill {
  transition: opacity 0.22s var(--ease), d 0.22s var(--ease), stroke-opacity 0.22s var(--ease);
}

.finger-accent {
  transition: x2 0.22s var(--ease), y2 0.22s var(--ease), opacity 0.22s var(--ease), stroke-width 0.22s var(--ease);
}

.fingertip-group .fingertip,
.fingertip-group .fingertip-ring,
.fingertip-group .fingertip-glow {
  transition:
    cx 0.22s var(--ease),
    cy 0.22s var(--ease),
    r 0.18s var(--ease),
    opacity 0.18s,
    fill-opacity 0.18s;
}

.fingertip-group.is-active .fingertip {
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.25));
}

.fingertip-group.pulse-ok {
  animation: tip-ok 0.35s var(--ease);
}

.guide-key.pulse-err {
  animation: key-err 0.4s ease;
}

@keyframes tip-ok {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.25);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes key-err {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-3px);
  }
  75% {
    transform: translateX(3px);
  }
}

.finger-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.65rem;
  justify-content: center;
  padding-top: 0.15rem;
}

.finger-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
}

.finger-legend-item i {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 2px;
  display: inline-block;
}

.hands-panel.hidden {
  display: none;
}

/* Curriculum step buttons hidden unless fingers mode — toggled via body class */
body:not(.mode-fingers) #btn-prev-step,
body:not(.mode-fingers) #btn-next-step {
  display: none;
}

@media (max-width: 720px) {
  .hands-svg {
    max-height: 220px;
  }
  .finger-cue {
    flex-wrap: wrap;
  }
  .finger-cue-key {
    margin-left: auto;
  }
}

/* Scrollbar subtle */
.history::-webkit-scrollbar {
  width: 6px;
}
.history::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 999px;
}
