:root {
  --bg: #07090d;
  --ink: #e8f4f1;
  --teal: #3ee6c4;
  --amber: #ffb454;
  --coral: #ff6f61;
  --muted: #8fa3ad;
  --glass: rgba(10, 14, 20, 0.55);
  --line: rgba(62, 230, 196, 0.16);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Space Grotesk", system-ui, -apple-system, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

.mono { font-family: "IBM Plex Mono", ui-monospace, monospace; }
.hidden { display: none !important; }

#scene { position: fixed; inset: 0; display: block; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }

#topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px;
}
#topbar > * { pointer-events: auto; }

.chip {
  display: flex; align-items: center; gap: 9px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 16px;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.78rem; font-weight: 700; letter-spacing: 0.1em;
  color: var(--ink);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
}
button.chip:hover { border-color: var(--teal); }

#timer {
  font-size: 2rem; font-weight: 700;
  text-shadow: 0 0 24px rgba(62, 230, 196, 0.35);
  pointer-events: none;
}
#timer.low { color: var(--coral); animation: timerPulse 0.9s infinite; }
@keyframes timerPulse { 50% { transform: scale(1.12); text-shadow: 0 0 30px rgba(255, 111, 97, 0.8); } }

#mass-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--coral); box-shadow: 0 0 10px var(--coral); }
#mass-val { font-size: 1.05rem; font-weight: 700; min-width: 3ch; text-align: right; }
.unit { color: var(--muted); font-size: 0.75rem; }

#dash-meter { width: 60px; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
#dash-fill { height: 100%; width: 100%; border-radius: 3px; background: var(--teal); box-shadow: 0 0 8px var(--teal); }

#mass-bar {
  position: absolute; top: 66px; left: 50%; transform: translateX(-50%);
  width: min(340px, 50vw); height: 3px; border-radius: 2px;
  background: rgba(255, 255, 255, 0.08);
}
#mass-bar-fill { height: 100%; width: 100%; background: linear-gradient(90deg, var(--coral), var(--amber)); border-radius: 2px; transition: width 0.2s; }

#leaderboard { position: absolute; top: 88px; left: 20px; width: 196px; }
.lb-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 11px; margin-bottom: 6px;
  background: var(--glass);
  border: 1px solid rgba(62, 230, 196, 0.1);
  border-radius: 10px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-size: 0.8rem; font-weight: 500;
  transition: opacity 0.2s;
}
.lb-row.me { border-color: rgba(62, 230, 196, 0.55); background: rgba(62, 230, 196, 0.08); }
.lb-row.down { opacity: 0.4; }
.lb-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 8px currentColor; }
.lb-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-mass { font-size: 0.76rem; color: var(--teal); }

#toast {
  position: absolute; top: 19%; left: 50%; transform: translate(-50%, -6px);
  font-size: 1.15rem; font-weight: 700; letter-spacing: 0.06em;
  opacity: 0; transition: opacity 0.25s, transform 0.25s;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.6);
  pointer-events: none; white-space: nowrap;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.good { color: var(--teal); }
#toast.bad { color: var(--coral); }

#hint {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  font-size: 0.7rem; letter-spacing: 0.09em; color: rgba(232, 244, 241, 0.42);
  white-space: nowrap;
}

/* ---------- vignettes ---------- */
#vignette, #flash {
  position: fixed; inset: 0; pointer-events: none; opacity: 0; z-index: 8;
}
#vignette { background: radial-gradient(ellipse at center, transparent 50%, rgba(255, 150, 60, 0.5) 100%); }
#flash { background: radial-gradient(ellipse at center, transparent 40%, rgba(255, 60, 50, 0.55) 100%); }

/* ---------- touch controls ---------- */
#joystick {
  position: fixed; left: 26px; bottom: 26px; z-index: 12;
  width: 116px; height: 116px; border-radius: 50%;
  border: 2px solid rgba(62, 230, 196, 0.3);
  background: rgba(10, 14, 20, 0.35);
  touch-action: none;
}
#stick {
  position: absolute; left: 50%; top: 50%;
  width: 48px; height: 48px; margin: -24px 0 0 -24px;
  border-radius: 50%;
  background: rgba(62, 230, 196, 0.5);
  border: 2px solid rgba(255, 255, 255, 0.25);
}
#dash-btn {
  position: fixed; right: 26px; bottom: 36px; z-index: 12;
  width: 88px; height: 88px; border-radius: 50%;
  background: rgba(255, 180, 84, 0.14);
  border: 2px solid rgba(255, 180, 84, 0.5);
  color: var(--amber);
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.78rem; font-weight: 700; letter-spacing: 0.12em;
  touch-action: none;
}

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: rgba(7, 9, 13, 0.66);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  text-align: center;
  padding: 24px;
}
.menu-inner { max-width: 760px; animation: rise 0.5s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } }

h1 {
  margin: 0 0 10px;
  font-size: clamp(3.2rem, 11vw, 7.5rem);
  font-weight: 700; letter-spacing: 0.02em; line-height: 0.95;
  text-shadow: 0 0 60px rgba(62, 230, 196, 0.25);
}
h1 span { color: var(--teal); }

h2 {
  margin: 0 0 8px;
  font-size: clamp(2.2rem, 7vw, 4.2rem);
  font-weight: 700; letter-spacing: 0.04em;
}

.tag { color: var(--muted); font-size: clamp(0.95rem, 2vw, 1.15rem); margin: 0 0 30px; }

.rules { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin-bottom: 34px; }
.rule {
  text-align: left; max-width: 220px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 15px 17px;
  background: rgba(10, 14, 20, 0.4);
  font-size: 0.85rem; line-height: 1.45; color: rgba(232, 244, 241, 0.85);
}
.rule b {
  display: block; font-family: "IBM Plex Mono", monospace;
  color: var(--teal); font-size: 0.8rem; margin-bottom: 6px; letter-spacing: 0.15em;
}

#start-btn, #again-btn {
  font-family: "Space Grotesk", sans-serif;
  font-size: 1rem; font-weight: 700; letter-spacing: 0.14em;
  padding: 16px 44px;
  border: none; border-radius: 999px;
  background: var(--teal); color: #04211b;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
#start-btn:hover, #again-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 44px rgba(62, 230, 196, 0.35);
}

.note { margin-top: 22px; font-size: 0.72rem; letter-spacing: 0.08em; color: rgba(232, 244, 241, 0.4); }

.rank-row {
  display: flex; align-items: center; gap: 12px;
  width: min(380px, 86vw);
  margin: 0 auto 8px;
  padding: 11px 16px;
  background: var(--glass);
  border: 1px solid rgba(62, 230, 196, 0.1);
  border-radius: 12px;
  font-size: 0.95rem; font-weight: 500;
  text-align: left;
}
.rank-row.me { border-color: rgba(62, 230, 196, 0.55); background: rgba(62, 230, 196, 0.08); }
.rank-medal { width: 44px; text-align: center; font-family: "IBM Plex Mono", monospace; font-weight: 700; }
.rank-row .lb-mass { margin-left: auto; font-size: 0.9rem; }

/* ---------- loading ---------- */
#loading {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px;
  background: var(--bg);
  color: var(--muted);
  font-size: 0.72rem; letter-spacing: 0.35em;
  transition: opacity 0.5s;
}
.pulse-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--teal);
  animation: pulse 0.9s infinite alternate ease-in-out;
}
@keyframes pulse {
  from { transform: scale(0.7); box-shadow: 0 0 0 rgba(62, 230, 196, 0.4); }
  to { transform: scale(1.25); box-shadow: 0 0 26px rgba(62, 230, 196, 0.9); }
}

@media (max-width: 720px) {
  #leaderboard { width: 150px; top: 80px; left: 12px; }
  .lb-row { font-size: 0.7rem; padding: 6px 8px; }
  #hint { display: none; }
  #timer { font-size: 1.4rem; }
  #topbar { padding: 10px 12px; }
  .chip { padding: 6px 12px; font-size: 0.68rem; }
}
