:root {
  --bg: #0f172a;
  --bg-panel: #1e293b;
  --bg-panel-2: #334155;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --accent: #fbbf24;
  --success: #22c55e;
  --error: #ef4444;
  --highlight: #fde047;

  /* Vinger-kleuren */
  --f-L5: #f87171; /* links pink - rood */
  --f-L4: #fb923c; /* links ring - oranje */
  --f-L3: #facc15; /* links midden - geel */
  --f-L2: #4ade80; /* links wijs - groen */
  --f-LT: #38bdf8; /* links duim - lichtblauw */
  --f-RT: #38bdf8; /* rechts duim - lichtblauw */
  --f-R2: #818cf8; /* rechts wijs - indigo */
  --f-R3: #c084fc; /* rechts midden - paars */
  --f-R4: #f472b6; /* rechts ring - roze */
  --f-R5: #f43f5e; /* rechts pink - framboos */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  min-height: 100vh;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

h1 {
  margin: 0;
  font-size: 1.8rem;
  letter-spacing: -0.5px;
}

.level-info {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-panel);
  padding: 8px 16px;
  border-radius: 12px;
}
.level-label { color: var(--text-dim); font-size: 0.85rem; }
#levelNumber {
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--accent);
}
.level-title {
  font-size: 0.95rem;
  color: var(--text);
  margin-left: 6px;
}

.stars {
  display: flex;
  gap: 3px;
  font-size: 1.4rem;
}

/* Lesson picker */
.lesson-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
}
.lesson-picker button {
  background: var(--bg-panel);
  color: var(--text);
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  flex-shrink: 0;
}
.lesson-picker button:hover { background: var(--bg-panel-2); }
.lesson-list {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  flex: 1;
  padding: 4px 2px;
  scrollbar-width: thin;
}
.lesson-chip {
  background: var(--bg-panel);
  color: var(--text-dim);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  border: 2px solid transparent;
  transition: all 0.15s;
  flex-shrink: 0;
}
.lesson-chip:hover { background: var(--bg-panel-2); }
.lesson-chip.active {
  background: var(--accent);
  color: #1e293b;
  font-weight: 600;
}
.lesson-chip.completed::before { content: "✓ "; color: var(--success); }
.lesson-chip.active.completed::before { color: #1e293b; }

/* Typing area */
.typing-area {
  background: var(--bg-panel);
  border-radius: 16px;
  padding: 28px;
  margin-bottom: 20px;
}
.instruction {
  color: var(--text-dim);
  font-size: 1rem;
  margin-bottom: 14px;
  min-height: 24px;
}
.text-display {
  font-family: 'Courier New', monospace;
  font-size: 1.8rem;
  line-height: 1.8;
  letter-spacing: 2px;
  min-height: 100px;
  user-select: none;
}
.text-display .char {
  position: relative;
  transition: color 0.1s;
}
.text-display .char.correct { color: var(--success); }
.text-display .char.incorrect {
  color: var(--error);
  background: rgba(239, 68, 68, 0.15);
  border-radius: 3px;
}
.text-display .char.current {
  background: var(--highlight);
  color: #1e293b;
  border-radius: 3px;
  animation: pulse 1s infinite;
}
.text-display .char.space { display: inline-block; min-width: 0.6em; }
.text-display .char.space.correct { background: rgba(34, 197, 94, 0.15); }
.text-display .char.space.incorrect { background: rgba(239, 68, 68, 0.25); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(253, 224, 71, 0.6); }
  50% { box-shadow: 0 0 0 6px rgba(253, 224, 71, 0); }
}

.hidden-input-wrap {
  position: absolute;
  left: -9999px;
  opacity: 0;
}

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.stat {
  background: var(--bg-panel);
  padding: 14px;
  border-radius: 12px;
  text-align: center;
}
.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
}
.stat-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* Keyboard */
.keyboard-wrap {
  background: var(--bg-panel);
  border-radius: 16px;
  padding: 20px;
}
.hands {
  display: flex;
  justify-content: space-between;
  margin-bottom: 14px;
  padding: 0 10px;
}
.hand {
  display: flex;
  gap: 4px;
  align-items: flex-end;
}
.hand-right { flex-direction: row; }
.finger {
  width: 30px;
  height: 44px;
  border-radius: 12px 12px 6px 6px;
  background: var(--bg-panel-2);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 4px;
  font-size: 0.65rem;
  color: rgba(255,255,255,0.7);
  transition: transform 0.1s, background 0.1s;
  position: relative;
}
.finger.thumb {
  height: 30px;
  width: 46px;
  align-self: center;
}
.finger.active {
  transform: translateY(-8px) scale(1.08);
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}
.finger[data-finger="L5"].active { background: var(--f-L5); color: #000; }
.finger[data-finger="L4"].active { background: var(--f-L4); color: #000; }
.finger[data-finger="L3"].active { background: var(--f-L3); color: #000; }
.finger[data-finger="L2"].active { background: var(--f-L2); color: #000; }
.finger[data-finger="LT"].active { background: var(--f-LT); color: #000; }
.finger[data-finger="RT"].active { background: var(--f-RT); color: #000; }
.finger[data-finger="R2"].active { background: var(--f-R2); color: #000; }
.finger[data-finger="R3"].active { background: var(--f-R3); color: #000; }
.finger[data-finger="R4"].active { background: var(--f-R4); color: #000; }
.finger[data-finger="R5"].active { background: var(--f-R5); color: #000; }

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}
.key-row {
  display: flex;
  gap: 6px;
}
.key {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: var(--bg-panel-2);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 500;
  border: 2px solid transparent;
  position: relative;
  transition: transform 0.08s, background 0.08s, border-color 0.08s;
}
.key.wide { width: 72px; }
.key.extra-wide { width: 96px; }
.key.space { width: 280px; }
.key.tab { width: 72px; font-size: 0.7rem; }
.key.shift { width: 96px; font-size: 0.7rem; }
.key.caps { width: 84px; font-size: 0.7rem; }
.key.enter { width: 96px; font-size: 0.7rem; }

/* Finger-kleuring op toetsen (subtiel randje) */
.key[data-finger="L5"] { border-top: 3px solid var(--f-L5); }
.key[data-finger="L4"] { border-top: 3px solid var(--f-L4); }
.key[data-finger="L3"] { border-top: 3px solid var(--f-L3); }
.key[data-finger="L2"] { border-top: 3px solid var(--f-L2); }
.key[data-finger="LT"] { border-top: 3px solid var(--f-LT); }
.key[data-finger="RT"] { border-top: 3px solid var(--f-RT); }
.key[data-finger="R2"] { border-top: 3px solid var(--f-R2); }
.key[data-finger="R3"] { border-top: 3px solid var(--f-R3); }
.key[data-finger="R4"] { border-top: 3px solid var(--f-R4); }
.key[data-finger="R5"] { border-top: 3px solid var(--f-R5); }

/* Home row bumpjes op F en J */
.key[data-key="f"]::after,
.key[data-key="j"]::after {
  content: "";
  position: absolute;
  bottom: 6px;
  width: 12px;
  height: 2px;
  background: rgba(255,255,255,0.6);
  border-radius: 2px;
}

.key.next {
  background: var(--highlight);
  color: #1e293b;
  transform: translateY(-4px);
  box-shadow: 0 4px 14px rgba(253, 224, 71, 0.5);
  font-weight: 700;
}
.key.pressed {
  transform: translateY(2px);
  background: var(--success);
  color: #fff;
}
.key.wrong {
  background: var(--error);
  color: #fff;
  animation: shake 0.3s;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.tip {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.9rem;
  margin: 14px 0 0;
}

/* Celebration modal */
.celebration {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.9);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.celebration.show { display: flex; }
.celebration-content {
  background: var(--bg-panel);
  padding: 40px;
  border-radius: 20px;
  text-align: center;
  max-width: 420px;
  position: relative;
  animation: popIn 0.4s ease-out;
}
@keyframes popIn {
  from { transform: scale(0.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.celebration h2 {
  font-size: 2rem;
  margin: 0 0 10px;
  color: var(--accent);
}
.celebration p {
  color: var(--text-dim);
  margin: 0 0 20px;
}
.celebration-stars {
  font-size: 3rem;
  margin: 20px 0;
}
.celebration button {
  background: var(--accent);
  color: #1e293b;
  border: none;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin: 4px;
}
.celebration button:hover { filter: brightness(1.1); }
#retryBtn {
  background: var(--bg-panel-2);
  color: var(--text);
}

@media (max-width: 720px) {
  .text-display { font-size: 1.3rem; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .key { width: 32px; height: 40px; font-size: 0.8rem; }
  .key.wide { width: 48px; }
  .key.space { width: 180px; }
  .key.shift, .key.caps, .key.enter, .key.tab { width: 56px; }
  h1 { font-size: 1.4rem; }
  .finger { width: 22px; height: 36px; font-size: 0.55rem; }
  .finger.thumb { width: 34px; height: 24px; }
}
