:root {
  --pink: #ff2ec4;
  --cyan: #00e5ff;
  --gold: #ffd23f;
  --purple: #6a0dad;
  --bg0: #0a0014;
  --bg1: #170028;
  --text: #f3ecff;
  --muted: #b79fd6;
  --danger: #ff3860;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  font-family: 'Rajdhani', sans-serif;
  background: #05000c;
  color: var(--text);
}

/* ============ Three.js canvas host, fills the viewport behind the UI ============ */
#sceneRoot {
  position: fixed;
  inset: 0;
  z-index: 0;
}
#sceneRoot canvas { display: block; width: 100%; height: 100%; }

/* CSS2D nameplate labels rendered by Three.js's CSS2DRenderer, positioned
   in screen-space above each 3D figure. This layer sits above the WebGL
   canvas but must NOT block clicks on the scene, hence pointer-events:none
   on the layer itself (individual plates re-enable where needed). */
#labelLayer {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
}

/* ============ top chrome ============ */
#topBar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center;
  padding: 10px 10px 0;
  pointer-events: none;
}
h1.marquee {
  font-family: 'Bungee', cursive;
  font-size: clamp(18px, 3.6vw, 28px);
  margin: 4px 0 2px;
  letter-spacing: 2px;
  background: linear-gradient(90deg, var(--pink), var(--gold), var(--cyan));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 30px rgba(255,46,196,0.35);
  text-align: center;
}
.subtitle { color: var(--muted); font-size: 11px; margin-bottom: 4px; letter-spacing: 1px; text-transform: uppercase; }

#musicToggle {
  position: fixed; top: 10px; right: 10px; z-index: 30;
  background: rgba(20,0,35,0.75); border: 1px solid var(--pink); color: var(--text);
  border-radius: 999px; padding: 7px 12px; font-size: 12px;
  backdrop-filter: blur(4px); box-shadow: 0 0 14px rgba(255,46,196,0.35);
  pointer-events: auto;
}

button {
  cursor: pointer; border: none; border-radius: 8px; padding: 9px 16px;
  font-size: 13px; font-weight: 700; font-family: 'Rajdhani', sans-serif; letter-spacing: .5px;
  transition: transform .05s ease, opacity .15s ease;
}
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-gold { background: linear-gradient(90deg, var(--gold), #ffb020); color: #1a1004; box-shadow: 0 0 14px rgba(255,210,63,0.45); }
.btn-outline { background: rgba(0,0,0,0.3); color: var(--text); border: 1px solid var(--cyan); box-shadow: 0 0 8px rgba(0,229,255,0.2); }

/* ============ join overlay ============ */
#joinOverlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(5,0,10,0.72);
  display: flex; align-items: center; justify-content: center;
  pointer-events: auto;
}
#joinPanel {
  background: linear-gradient(160deg, rgba(40,4,60,0.95), rgba(15,0,25,0.95));
  border: 1px solid var(--pink);
  box-shadow: 0 0 24px rgba(255,46,196,0.3);
  border-radius: 14px; padding: 22px; width: 280px; text-align: center;
}
#joinPanel h1 { margin-top: 0; }
#joinPanel input {
  width: 100%; padding: 10px; border-radius: 8px; border: 1px solid var(--purple);
  background: #0f0018; color: var(--text); margin-bottom: 12px; font-size: 14px;
  font-family: 'Rajdhani', sans-serif;
}

/* ============ HUD, bottom-right, floats over the canvas ============ */
#hud {
  position: fixed; right: 10px; bottom: 10px; z-index: 20;
  background: rgba(0,0,0,0.6);
  border: 1px solid var(--purple);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 190px;
  pointer-events: auto;
}
#hud .hint { font-size: 10px; color: var(--muted); text-align: center; margin-bottom: 2px; }
#hud input[type=number] {
  width: 100%; padding: 7px; border-radius: 6px; border: 1px solid var(--purple);
  background: #0f0018; color: var(--text); font-size: 13px; font-family: 'Rajdhani', sans-serif;
}
#hud button { width: 100%; }

/* ============ table plaque (phase / pot / timer), centered top ============ */
#tablePlaque {
  position: fixed; left: 50%; top: 66px; transform: translateX(-50%);
  z-index: 15; text-align: center; pointer-events: none;
}
#tablePlaque .phase { font-size: 11px; letter-spacing: 2px; color: var(--muted); text-transform: uppercase; }
#tablePlaque .pot { font-family: 'Bungee', cursive; font-size: clamp(18px, 3vw, 26px); color: var(--gold); text-shadow: 0 0 14px rgba(255,210,63,0.6); }
#tablePlaque .timer { font-size: 12px; margin-top: 2px; }
#tablePlaque .timer b { color: var(--cyan); text-shadow: 0 0 8px rgba(0,229,255,0.6); }

/* ============ result banner ============ */
#resultBanner {
  position: fixed; left: 50%; top: 130px; transform: translateX(-50%);
  z-index: 25; display: none;
  background: rgba(10,0,20,0.85); border: 1px solid var(--gold);
  box-shadow: 0 0 20px rgba(255,210,63,0.4);
  border-radius: 10px; padding: 8px 16px; text-align: center; font-size: 12px;
  max-width: 92%;
  pointer-events: none;
}
#resultBanner b { color: var(--gold); }

/* ============ event log, top-left ============ */
#eventLog {
  position: fixed; top: 10px; left: 10px; z-index: 15;
  width: 230px; max-height: 130px; overflow: hidden;
  background: rgba(0,0,0,0.55);
  border-left: 2px solid var(--cyan);
  border-radius: 4px;
  padding: 6px 8px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 10px;
  line-height: 1.5;
  color: #d8f8ff;
  pointer-events: none;
}
#eventLog .ts { color: var(--gold); margin-right: 4px; }

/* ============ CSS2D nameplates anchored above each figure ============ */
.nameplate {
  background: rgba(5,0,15,0.72);
  border: 1px solid rgba(255,210,63,0.3);
  border-radius: 8px;
  padding: 4px 8px;
  text-align: center;
  min-width: 84px;
  backdrop-filter: blur(2px);
  transform: translate(-50%, -100%);
}
.nameplate .nm { font-size: 11px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
.nameplate .bal { font-size: 9px; color: var(--muted); }
.nameplate .bet { font-size: 10px; color: var(--cyan); }
.nameplate .dice {
  font-family: 'Bungee', cursive; font-size: 13px; color: var(--gold);
  background: #0f0018; border: 1px solid var(--purple); border-radius: 5px;
  width: 22px; height: 22px; line-height: 22px; margin: 3px auto 0;
}
.nameplate .dice.pending { font-family: 'Rajdhani', sans-serif; font-size: 8px; color: var(--muted); }
.nameplate .empty { font-size: 10px; color: var(--muted); font-style: italic; }

#toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: var(--danger); color: white; padding: 9px 16px; border-radius: 8px;
  font-size: 12px; display: none; max-width: 90%; text-align: center; z-index: 40;
}

#loadingHint {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: #05000c; color: var(--muted); font-size: 13px; letter-spacing: 1px;
}

@media (max-width: 520px) {
  #eventLog { width: 150px; font-size: 9px; max-height: 90px; }
  #hud { width: 150px; }
  #tablePlaque { top: 60px; }
}
