:root {
  --orange: #ffb347;
  --orange-deep: #ff9800;
  --green: #4caf50;
  --black: #1c1c1c;
  --bg: #f4f6fb;
  --panel: #ffffff;
  --text: #23272f;
  --muted: #6b7280;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 20px;
}

h1 { margin: 0; font-size: 1.4rem; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--panel);
  padding: 14px 20px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

.controls { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; }
.control-group { display: flex; flex-direction: column; gap: 4px; }
.control-group label { font-size: 0.7rem; text-transform: uppercase; color: var(--muted); font-weight: 600; }

select, .restart-btn {
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid #d0d5dd;
  font-size: 0.9rem;
  background: white;
  cursor: pointer;
}

.restart-btn { background: var(--orange); border: none; font-weight: 600; }
.restart-btn:hover { background: var(--orange-deep); }

.toggle { display: flex; border: 1px solid #d0d5dd; border-radius: 8px; overflow: hidden; }
.toggle button {
  padding: 7px 14px;
  border: none;
  background: white;
  cursor: pointer;
  font-size: 0.85rem;
}
.toggle button.active { background: var(--orange); color: #402400; font-weight: 700; }

.stats-bar {
  display: flex;
  justify-content: center;
  gap: 28px;
  padding: 14px;
  flex-wrap: wrap;
}
.stat { display: flex; flex-direction: column; align-items: center; min-width: 70px; }
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--orange-deep); }
.stat-label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; }

.ticker-wrap {
  position: relative;
  margin: 10px auto;
  max-width: 900px;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  padding: 18px 0;
}
.ticker-mask {
  overflow: hidden;
  height: 48px;
  display: flex;
  align-items: center;
}
.ticker-track {
  display: flex;
  white-space: pre;
  font-size: 1.9rem;
  font-family: "Consolas", "Menlo", monospace;
  transition: transform 0.12s ease-out;
  will-change: transform;
  backface-visibility: hidden;
  text-rendering: optimizeLegibility;
}
.ticker-track .char { color: #4b5563; position: relative; }
.ticker-track .char.correct { color: var(--green); }
.ticker-track .char.incorrect { color: #e53935; text-decoration: underline wavy #e53935; }
.ticker-track .char.current {
  color: var(--black);
  background: var(--orange);
  border-radius: 4px;
}
.ticker-marker {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--orange-deep);
  opacity: 0.5;
}

.guide-panel {
  max-width: 900px;
  margin: 10px auto;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}
.guide-message { font-size: 1rem; flex: 1; min-width: 220px; }
.guide-message strong { color: var(--orange-deep); }
.guide-message.error { color: #e53935; font-weight: 600; }

.hands { display: flex; gap: 30px; }
.hand { display: flex; gap: 4px; }
.right-hand { flex-direction: row-reverse; }
.finger {
  width: 16px;
  height: 34px;
  border-radius: 8px;
  background: #d9dce3;
  transition: background 0.15s;
}
.finger.active { background: var(--orange); box-shadow: 0 0 0 2px var(--orange-deep); }

.keyboard-wrap {
  display: flex;
  justify-content: center;
  padding: 10px;
}
.keyboard {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #2b2f38;
  padding: 17px;
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}
.kb-row { display: flex; gap: 8px; }
.kb-row-center { justify-content: center; }
.key {
  height: 56px;
  min-width: 48px;
  background: #454b57;
  color: #e4e6eb;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.97rem;
  font-family: "Consolas", monospace;
  user-select: none;
  transition: background 0.1s, transform 0.05s;
  position: relative;
  border: 1px solid #363b45;
}
.key .shift-label { font-size: 0.73rem; color: #9aa0ab; position: absolute; top: 3px; left: 5px; }
.key.w-125 { min-width: 70px; }
.key.w-15 { min-width: 83px; }
.key.w-2 { min-width: 109px; }
.key.w-625 { min-width: 363px; }
.key.f-home::after {
  content: "";
  position: absolute;
  bottom: 6px;
  width: 14px;
  height: 3px;
  background: #9aa0ab;
  border-radius: 2px;
}

.key.next-key { background: var(--orange); color: #402400; transform: translateY(-2px); box-shadow: 0 3px 8px rgba(255,152,0,0.5); }
.key.next-shift { background: #ffd699; color: #402400; }
.key.correct-flash { background: var(--green); color: white; }
.key.wrong-key { background: var(--black); color: #ff6b6b; }

/* Passive mistake tip toast — never blocks input, just a gentle hint. */
.tip-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  max-width: 300px;
  background: #fff4e5;
  border-left: 4px solid var(--orange-deep);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 0.9rem;
  color: #7a4a00;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  z-index: 60;
}
.tip-toast.hidden { display: none; }
.tip-toast.show { opacity: 1; transform: translateY(0); }

/* Celebration text for word streaks */
.celebration-text {
  position: fixed;
  /* top is set dynamically in JS to align with the header height */
  top: 30px;
  left: 50%;
  transform: translate(-50%, -60%);
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--orange-deep);
  text-shadow: 0 2px 6px rgba(0,0,0,0.15);
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  z-index: 70;
}
.celebration-text.hidden { display: none; }
.celebration-text.show { opacity: 1; transform: translate(-50%, -50%); }

.fireworks-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 65;
}
.fireworks-canvas.show { opacity: 1; }

/* Unicorn that gallops across the bottom of the screen every 2nd streak */
.unicorn {
  position: fixed;
  bottom: 10px;
  left: 0;
  font-size: 3rem;
  transform: translateX(100vw) scaleX(-1);
  pointer-events: none;
  z-index: 80;
}
.unicorn.hidden { display: none; }
.unicorn.running {
  animation: unicorn-run 4s linear;
}
@keyframes unicorn-run {
  from { transform: translateX(100vw) scaleX(-1); }
  to { transform: translateX(-15vw) scaleX(-1); }
}

/* Rocket easter egg that launches from the bottom-right to the top-right
   corner every 3rd streak */
.rocket {
  position: fixed;
  right: 4%;
  bottom: -10%;
  font-size: 3rem;
  transform: rotate(0deg);
  pointer-events: none;
  z-index: 85;
}
.rocket.hidden { display: none; }
.rocket.running {
  animation: rocket-launch 2.4s ease-in;
}
@keyframes rocket-launch {
  0% { bottom: -10%; right: 4%; opacity: 1; }
  100% { bottom: 110%; right: 12%; opacity: 1; }
}

.tips {
  max-width: 900px;
  margin: 16px auto;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 14px 22px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
}
.tips h3 { margin: 6px 0; }
.tips ul { margin: 6px 0; padding-left: 20px; color: var(--muted); font-size: 0.9rem; }
