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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242736;
  --accent: #6c63ff;
  --accent2: #a29bfe;
  --text: #e8e8f0;
  --muted: #8888aa;
  --danger: #e74c3c;
  --radius: 12px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  overflow: hidden;
}

/* ── Join screen ────────────────────────────────── */
#join-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 40%, #1e1b4b 0%, var(--bg) 70%);
  z-index: 100;
}

.join-card {
  background: var(--surface);
  border: 1px solid #2d2f45;
  border-radius: 20px;
  padding: 48px 40px;
  width: 360px;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
}

.join-card h1 {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: -1px;
  margin-bottom: 12px;
}

.join-card h1 span { color: var(--accent); }

.join-card p { color: var(--muted); margin-bottom: 28px; font-size: 0.95rem; line-height: 1.5; }

.join-card input {
  width: 100%;
  padding: 12px 16px;
  background: var(--surface2);
  border: 1px solid #3a3c55;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  margin-bottom: 16px;
  transition: border-color 0.2s;
}

.join-card input:focus { border-color: var(--accent); }

.join-card button {
  width: 100%;
  padding: 13px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.join-card button:hover { background: var(--accent2); }
.join-card button:active { transform: scale(0.98); }
.join-card .hint { font-size: 0.78rem; margin-top: 14px; color: var(--muted); }

/* ── Room layout ───────────────────────────────── */
#room {
  display: flex;
  height: 100vh;
  width: 100vw;
}

#canvas-wrap {
  flex: 1;
  overflow: hidden;
  cursor: crosshair;
  position: relative;
  background: #0d0f1a;
}

#world-canvas {
  display: block;
  image-rendering: pixelated;
}

/* ── Sidebar ───────────────────────────────────── */
#sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--surface);
  border-left: 1px solid #2d2f45;
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
}

/* Self video */
#self-video-wrap {
  position: relative;
  background: #000;
  aspect-ratio: 16/9;
}

#self-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform: scaleX(-1);
}

#self-label {
  position: absolute;
  bottom: 6px; left: 8px;
  font-size: 0.72rem;
  background: rgba(0,0,0,0.6);
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: none;
}

/* Controls */
#controls {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface2);
  border-bottom: 1px solid #2d2f45;
}

.ctrl-btn {
  flex: 1;
  padding: 8px;
  background: #3a3c55;
  border: none;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s;
  display: flex; align-items: center; justify-content: center;
}

.ctrl-btn svg { width: 18px; height: 18px; }

.ctrl-btn:hover { background: #4a4c6a; }
.ctrl-btn.off { background: var(--danger); color: #fff; }

/* Peer videos */
#peer-videos {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.peer-tile {
  position: relative;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 16/9;
  border: 1px solid #2d2f45;
  transition: border-color 0.3s;
}

.peer-tile.active { border-color: var(--accent); }

.peer-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.peer-tile .peer-name {
  position: absolute;
  bottom: 5px; left: 7px;
  font-size: 0.7rem;
  background: rgba(0,0,0,0.6);
  padding: 2px 6px;
  border-radius: 4px;
}

/* Proximity hint */
#proximity-hint {
  padding: 12px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
  border-top: 1px solid #2d2f45;
}

/* Utilities */
.hidden { display: none !important; }
