:root {
  --bg: #0a120c;
  --panel: #101c12cc;
  --line: #ffffff16;
  --text: #eef5ee;
  --muted: #9db3a0;
  --accent: #7ddf64;
  --amber: #ffcf40;
}

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

html, body { height: 100%; }

body {
  font-family: "Outfit", system-ui, -apple-system, "Segoe UI", sans-serif;
  background:
    radial-gradient(1100px 650px at 70% -10%, #16281a 0%, var(--bg) 55%) fixed,
    var(--bg);
  color: var(--text);
  overflow: hidden;
}

.hidden { display: none !important; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 22px;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; gap: 12px; align-items: center; }
.logo { font-size: 30px; }
.brand h1 { font-size: 20px; font-weight: 800; letter-spacing: .3px; }
.brand p { font-size: 12.5px; color: var(--muted); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 18px;
  padding: 18px 22px;
  height: calc(100vh - 71px);
}

.stage {
  position: relative;
  border-radius: 22px;
  overflow: hidden;
  background: #000;
  border: 1px solid var(--line);
  box-shadow: 0 0 90px -20px #7ddf6433;
}

#cam-video {
  position: absolute;
  width: 4px;
  height: 4px;
  opacity: 0;
  pointer-events: none;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hud {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  gap: 12px;
  align-items: center;
}

.meter {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #00000088;
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
}
.meter-label { font-size: 12px; font-weight: 700; letter-spacing: .5px; }
.bar { width: 130px; height: 10px; background: #ffffff14; border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 100%; border-radius: 99px; transition: width .25s ease; }
/* Initial meter colors (moved out of inline style attributes for CSP);
   updateHUD() overrides them at runtime via CSSOM. */
#bar-bee { background: #37d67a; }
#bar-eco { background: #7ddf64; }
.meter-val { font-size: 12.5px; font-weight: 600; min-width: 38px; text-align: right; }

.counter {
  margin-left: auto;
  font-size: 18px;
  font-weight: 800;
  background: #00000088;
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 18px;
}

.mute-btn {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: #00000088;
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  font-size: 16px;
  cursor: pointer;
  color: var(--text);
}
.mute-btn:hover { background: #ffffff14; }

.timer-pill { color: var(--amber); }
.timer-pill.low {
  color: #ff5f5f;
  animation: timerPulse 1s infinite;
}
@keyframes timerPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.09); }
}

.combo {
  position: absolute;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--amber);
  text-shadow: 0 2px 10px #000a, 0 0 24px #ffcf4055;
  pointer-events: none;
}
.combo.pop { animation: comboPop .3s cubic-bezier(.34,1.56,.64,1); }
@keyframes comboPop {
  0% { transform: translateX(-50%) scale(1.35); }
  100% { transform: translateX(-50%) scale(1); }
}

#cam-preview {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 190px;
  height: 142px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #111;
  opacity: .92;
}

.toast {
  position: absolute;
  left: 50%;
  top: 70px;
  transform: translate(-50%, -8px);
  background: #0a120cee;
  border: 1px solid var(--line);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  transition: .25s;
  pointer-events: none;
  z-index: 6;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.overlay {
  position: absolute;
  inset: 0;
  background: #06100ae0;
  backdrop-filter: blur(9px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 15px;
  padding: 30px;
  z-index: 5;
}
.overlay h2 { font-size: clamp(30px, 4.5vw, 46px); font-weight: 800; letter-spacing: 1px; }
.tagline { color: var(--muted); line-height: 1.55; max-width: 560px; }

/* Attract mode: keep the start screen translucent so the live demo shows behind it. */
#start-overlay {
  background: #08130caa;
  backdrop-filter: blur(6px);
}
#start-overlay h2,
#start-overlay .tagline { text-shadow: 0 2px 16px #000c, 0 0 34px #0009; }
#start-btn { animation: ctaPulse 2.2s ease-in-out infinite; }
#start-btn:disabled { animation: none; }
@keyframes ctaPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 10px 30px -8px #7ddf6488; }
  50% { transform: scale(1.045); box-shadow: 0 16px 42px -6px #7ddf64cc; }
}
@media (prefers-reduced-motion: reduce) {
  #start-btn { animation: none; }
}

.howto {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 640px;
}
.howto span {
  background: #ffffff0d;
  border: 1px solid var(--line);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13.5px;
}

.status-line { font-size: 15px; color: var(--amber); min-height: 20px; }

.primary-btn {
  background: linear-gradient(135deg, #3fae54, #7ddf64);
  color: #08120a;
  border: none;
  padding: 14px 30px;
  font-size: 16px;
  font-weight: 800;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 10px 30px -8px #7ddf6488;
}
.primary-btn:hover:not(:disabled) { filter: brightness(1.07); }
.primary-btn:disabled { opacity: .6; cursor: wait; }

.ghost-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  padding: 11px 18px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 13.5px;
  cursor: pointer;
}
.ghost-btn:hover:not(:disabled) { background: #ffffff0d; }
.ghost-btn.small { padding: 7px 12px; font-size: 12px; margin-top: 10px; }

.error-msg { color: #ff9a9a; font-size: 14px; min-height: 18px; }
.fineprint { font-size: 12px; color: var(--muted); max-width: 480px; }

.tier-badge {
  font-size: 22px;
  font-weight: 800;
  background: linear-gradient(135deg, #3fae54, #7ddf64);
  color: #08120a;
  padding: 8px 22px;
  border-radius: 999px;
}

.impact-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(140px, 1fr));
  gap: 12px;
}
.impact-grid div {
  background: #ffffff0a;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 10px;
}
.impact-grid b { display: block; font-size: 26px; color: var(--accent); }
.impact-grid span { font-size: 12px; color: var(--muted); }

.final-score { font-size: 17px; color: var(--muted); }
.final-score b { font-size: 26px; color: var(--amber); }
/* Step 4: results-screen player name + personal-best line */
.over-player { font-size: 1.05rem; font-weight: 600; opacity: .92; margin-top: -10px; }
.best-note { min-height: 1.5em; font-weight: 800; letter-spacing: .3px; color: var(--muted); }
.best-note.new-best { color: #ffd166; text-shadow: 0 0 16px #ffd16640; font-size: 1.1rem; }

.fact-card {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  max-width: 540px;
  background: #ffffff08;
  border-left: 3px solid var(--accent);
  border-radius: 12px;
  padding: 12px 16px;
}
.fact-card p { font-size: 13.5px; line-height: 1.5; color: #d7e6d8; text-align: left; }

#player-name-start {
  background: #ffffff0d;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 12px 20px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  text-align: center;
  outline: none;
  width: min(340px, 90%);
}
#player-name-start:focus { border-color: var(--accent); }

.board-status {
  margin-top: 12px;
  min-height: 16px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--amber);
}

.row { display: flex; gap: 12px; align-items: center; }

.panel {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 20px;
  overflow-y: auto;
}
.panel h2 { font-size: 17px; font-weight: 800; }

.leaderboard { list-style: none; margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.leaderboard li {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #ffffff0a;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14.5px;
}
.leaderboard li b { margin-left: auto; color: var(--amber); }
.leaderboard .rank { font-size: 18px; }
.leaderboard .empty {
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
  border-style: dashed;
}

.aggregate {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 13.5px;
  color: #cfe3d1;
}
.aggregate b { color: var(--accent); }

.disclaimer {
  margin-top: auto;
  padding-top: 16px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

@media (max-width: 1020px) {
  body { overflow: auto; }
  .layout { grid-template-columns: 1fr; height: auto; }
  .stage { aspect-ratio: 16 / 9; }
}
