:root {
  --bg: #000;
  --fg: #fff;
  --accent: #E5484D;
  --dim: #888;
  --font: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  overflow: hidden;
}

#cam {
  position: fixed;
  bottom: 12px;
  right: 12px;
  width: 72px;
  height: 54px;
  object-fit: cover;
  border: 1px solid var(--dim);
  opacity: 0.2;
  transform: scaleX(-1); /* mirror */
  z-index: 5;
}

#app { height: 100%; }

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  text-align: center;
}
.hidden { display: none !important; }

h1 { font-size: 48px; letter-spacing: 8px; }
h2 { font-size: 32px; letter-spacing: 4px; }
.subtitle { color: var(--dim); letter-spacing: 1px; }
.note { color: var(--dim); font-size: 13px; min-height: 16px; }

.players { display: flex; gap: 24px; flex-wrap: wrap; justify-content: center; }
.player-btn {
  background: transparent;
  border: 1px solid var(--fg);
  color: var(--fg);
  padding: 24px 32px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-family: var(--font);
}
.player-btn:hover { border-color: var(--accent); color: var(--accent); }
.pname { font-size: 24px; letter-spacing: 4px; }
.pbest { font-size: 12px; color: var(--dim); }

.countdown { font-size: 72px; color: var(--accent); }

#game { display: block; width: 100vw; height: 100vh; background: var(--bg); }

#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  gap: 24px;
  padding: 12px 20px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
  z-index: 4;
}
#hud-round {
  color: #5cb8c6; font-weight: bold;
  border: 1px solid rgba(92, 184, 198, 0.5);
  border-radius: 6px; padding: 0 8px; align-self: center; font-size: 13px;
}
#hud-score { color: var(--accent); font-weight: bold; }
#hud-combo { color: #e6b45c; font-size: 13px; align-self: center; }
#hud-wpm { color: #8ed081; font-size: 13px; align-self: center; }
#hud-acc { color: var(--dim); font-size: 13px; align-self: center; }

/* --- round banner (intro / clear beats) --- */
#round-banner {
  position: fixed;
  top: 40%; left: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  text-align: center;
  opacity: 0; pointer-events: none; z-index: 6;
  transition: opacity 180ms ease;
}
#round-banner.show { opacity: 1; animation: rb-pop 420ms cubic-bezier(0.2, 1.4, 0.4, 1) forwards; }
#round-banner .rb-main {
  font-size: 56px; font-weight: 800; letter-spacing: 3px;
  color: #fff; text-shadow: 0 0 24px rgba(92, 184, 198, 0.8);
}
#round-banner.clear .rb-main { text-shadow: 0 0 24px rgba(230, 180, 92, 0.9); color: #e6b45c; }
#round-banner .rb-sub {
  font-size: 16px; letter-spacing: 4px; color: var(--dim); font-weight: 600;
}
@keyframes rb-pop {
  0%   { transform: translate(-50%, -50%) scale(0.6); }
  60%  { transform: translate(-50%, -50%) scale(1.08); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

/* --- on-screen keyboard guide --- */
#kb-guide {
  position: fixed;
  bottom: 10px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 4;
  opacity: 0.9;
  user-select: none;
  pointer-events: none;
}
.kb-row { display: flex; gap: 4px; justify-content: center; }
.kb-row:nth-child(2) { padding-left: 14px; }
.kb-row:nth-child(3) { padding-left: 42px; }
.kb-key {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600;
  border-radius: 5px;
  border: 1px solid color-mix(in srgb, var(--fc) 60%, #000);
  background: color-mix(in srgb, var(--fc) 22%, #000);
  color: color-mix(in srgb, var(--fc) 85%, #fff);
  transition: background 80ms, transform 80ms, box-shadow 80ms;
}
.kb-key.locked { opacity: 0.18; filter: grayscale(1); }
.kb-key.next {
  background: color-mix(in srgb, var(--fc) 55%, #000);
  color: #fff;
}
.kb-key.next-primary {
  background: var(--fc);
  color: #000;
  transform: translateY(-3px) scale(1.08);
  box-shadow: 0 0 14px var(--fc);
}
.kb-key.just-unlocked { animation: key-unlock 1200ms cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes key-unlock {
  0%   { transform: scale(0.2) rotate(-15deg); filter: brightness(3); }
  40%  { transform: scale(1.6) rotate(6deg); filter: brightness(2.2); }
  70%  { transform: scale(0.9); }
  100% { transform: scale(1); filter: brightness(1); }
}

/* --- unlock progress bar --- */
#unlock-bar {
  position: fixed;
  top: 44px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  z-index: 4;
  pointer-events: none;
}
#unlock-row { display: flex; align-items: center; gap: 10px; }
#unlock-needs {
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--dim);
  min-height: 13px;
  font-variant-numeric: tabular-nums;
}
#unlock-needs b { color: #e6b45c; font-weight: 600; }
#unlock-label {
  font-size: 12px;
  letter-spacing: 2px;
  color: var(--dim);
  white-space: nowrap;
}
#unlock-label b { color: #e6b45c; font-size: 14px; }
#unlock-track {
  width: 180px; height: 6px;
  background: #1c1c1c;
  border-radius: 3px;
  overflow: hidden;
}
#unlock-fill {
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: linear-gradient(90deg, #e6b45c, #E5484D);
  transition: width 350ms ease-out;
}
#unlock-bar.almost #unlock-fill { animation: fill-pulse 900ms ease-in-out infinite; }
@keyframes fill-pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.7); }
}

/* --- unlock toast --- */
#toast {
  position: fixed;
  top: 22%; left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  padding: 16px 30px;
  border-radius: 10px;
  font-size: 22px; letter-spacing: 3px; font-weight: 700;
  z-index: 8;
  box-shadow: 0 6px 30px rgba(229,72,77,0.5);
  animation: toast-bounce 600ms cubic-bezier(0.34, 1.56, 0.64, 1),
             toast-glow 1600ms ease-in-out infinite;
}
@keyframes toast-bounce {
  0%   { transform: translateX(-50%) scale(0.3) rotate(-6deg); opacity: 0; }
  60%  { transform: translateX(-50%) scale(1.15) rotate(2deg); opacity: 1; }
  100% { transform: translateX(-50%) scale(1) rotate(0deg); }
}
@keyframes toast-glow {
  0%, 100% { box-shadow: 0 6px 30px rgba(229,72,77,0.5); }
  50% { box-shadow: 0 6px 55px rgba(230,180,92,0.9); }
}

/* --- level-up screen flash --- */
#flash {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 35%, rgba(230,180,92,0.55), rgba(229,72,77,0.15) 55%, transparent 75%);
  opacity: 0;
  pointer-events: none;
  z-index: 7;
}
#flash.zap { animation: flash-fade 700ms ease-out; }
@keyframes flash-fade {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

/* --- results heatmap --- */
.heatmap {
  display: flex; flex-direction: column; gap: 4px;
  align-items: center; margin-top: 4px;
}
.heatmap .kb-row { display: flex; gap: 4px; }
.heatmap .kb-key {
  width: 26px; height: 26px; font-size: 12px;
}
.heatmap .kb-key.untested {
  background: #1d1d1d; border-color: #333; color: var(--dim);
}
.heatmap .kb-key.locked { opacity: 0.15; }
.tracker-ok::before { content: "● tracking"; color: var(--dim); font-size: 12px; }
.tracker-noface::before { content: "○ can't see you"; color: var(--dim); font-size: 12px; }
.tracker-off::before { content: "○ camera off"; color: var(--dim); font-size: 12px; }

.results { display: grid; grid-template-columns: auto auto; gap: 8px 24px; }
.results dt { color: var(--dim); text-align: right; }
.results dd { color: var(--fg); text-align: left; font-variant-numeric: tabular-nums; }

.over-actions { display: flex; gap: 16px; }
.over-actions button {
  background: transparent; border: 1px solid var(--fg); color: var(--fg);
  padding: 12px 20px; cursor: pointer; font-family: var(--font); letter-spacing: 2px;
}
.over-actions button:hover { border-color: var(--accent); color: var(--accent); }

#version {
  position: fixed;
  bottom: 8px; left: 12px;
  color: var(--dim);
  font-size: 11px;
  z-index: 5;
}
