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

:root {
  --bg: #1c2230;
  --card: #262e40;
  --accent: #4f9dde;
  --text: #e8edf5;
  --muted: #8b97ac;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.screen {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.hidden { display: none !important; }

/* ---- Lobby ---- */
.card {
  background: var(--card);
  padding: 28px 32px;
  border-radius: 16px;
  width: 360px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  text-align: center;
}
.card h1 { font-size: 28px; }
.card .sub { color: var(--muted); margin-bottom: 20px; }
.card label {
  display: block;
  text-align: left;
  font-size: 13px;
  color: var(--muted);
  margin: 16px 0 6px;
}
.card input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #3a445c;
  background: #1c2230;
  color: var(--text);
  font-size: 15px;
}
.swatches { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-start; }
.swatch {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  border: 3px solid transparent;
}
.swatch.sel { border-color: #fff; }
.swatch.hat {
  background: #1c2230;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  width: auto;
  min-width: 34px;
  padding: 0 10px;
  white-space: nowrap;
}
/* lobby two-column layout: controls + live 3D preview */
.lobby-card { width: min(760px, 94vw); }
.lobby-grid { display: flex; gap: 24px; text-align: left; margin-top: 8px; }
.lobby-form { flex: 1; min-width: 0; }
.lobby-preview { width: 280px; flex: none; display: flex; flex-direction: column; align-items: center; gap: 8px; position: sticky; top: 0; align-self: flex-start; }
#avatar3d {
  width: 280px; height: 380px; display: block;
  background: radial-gradient(circle at 50% 32%, #2f3a52, #171c28);
  border-radius: 16px; cursor: grab; touch-action: none;
}
#avatar3d:active { cursor: grabbing; }
.lobby-preview .hint { margin: 0; }
@media (max-width: 700px) {
  .lobby-grid { flex-direction: column-reverse; }
  .lobby-preview { width: 100%; position: static; }
  #avatar3d { width: 100%; height: 320px; }
}
button {
  margin-top: 16px;
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
button:hover { filter: brightness(1.08); }
.hint { color: var(--muted); font-size: 12px; margin-top: 12px; }

/* ---- Room ---- */
#stage { display: block; background: #20283a; }
#hud {
  position: fixed;
  top: 14px;
  left: 14px;
  display: flex;
  gap: 10px;
  align-items: center;
  background: rgba(38, 46, 64, 0.9);
  padding: 8px 12px;
  border-radius: 12px;
}
#nearby-count { font-size: 13px; color: var(--muted); margin-right: 4px; font-weight: 600; }
#nearby-count[data-zone="stations"] { color: #f08a4b; }
#nearby-count[data-zone="lunch"] { color: #e6a93b; }

/* invite buttons (lunch) */
#invites {
  position: fixed;
  top: 64px;
  left: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 240px;
}
.hud-btn.invite { background: #e6a93b; color: #1c2230; }
.hud-btn.invite:disabled { opacity: 0.6; cursor: default; }

/* flash toast */
#flash {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(38, 46, 64, 0.95);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
}

#palette3d {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  align-items: center;
  max-width: min(94vw, 980px);
  background: rgba(20, 26, 38, 0.92);
  padding: 8px 12px;
  border-radius: 12px;
  z-index: 15;
}
#palette3d span { font-size: 12px; color: var(--muted); margin-right: 2px; }
#palette3d .pal-label { width: 100%; font-weight: 700; color: #cdd6e6; margin: 2px 0 0; }
#palette3d .hud-btn { background: #2f6f4f; }

#eprompt {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(16, 20, 28, 0.9);
  border: 1px solid #4f9dde;
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
}
#eprompt b { color: #ffd76a; background: #2a3346; padding: 1px 7px; border-radius: 5px; }

/* incoming invite modal */
#invite-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.modal-card {
  background: var(--card);
  padding: 26px 30px;
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.modal-card p { font-size: 17px; margin-bottom: 18px; }
.modal-btns { display: flex; gap: 12px; }
.modal-btns button { margin: 0; padding: 12px 20px; width: auto; }
.modal-btns .secondary { background: #5a4250; }
.hud-btn {
  width: auto;
  margin: 0;
  padding: 8px 12px;
  font-size: 13px;
  background: #3a445c;
}
.hud-btn.off { background: #7a3a3a; }

/* Google-Meet-style video overlay */
#meet { position: fixed; inset: 0; pointer-events: none; z-index: 12; }
/* main area: camera gallery (top band by default), or the screen stage when sharing */
#meet-main {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  width: 74vw; height: 30vh;
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center;
}
/* side strip: camera thumbnails when someone shares their screen */
#meet-strip {
  position: absolute; top: 12px; right: 12px;
  display: none; flex-direction: column; gap: 8px; max-height: 92vh; overflow: auto;
}
#meet.sharing #meet-strip { display: flex; }
#meet.sharing #meet-main { width: 64vw; height: 56vh; }   /* big readable screen stage */
#meet-strip .video-tile { width: 168px; }
/* my own camera, bottom-right */
#meet-self { position: absolute; right: 14px; bottom: 14px; }

.video-tile {
  border-radius: 12px; overflow: hidden; background: #11151c; position: relative;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.5); border: 3px solid transparent;
  pointer-events: auto; aspect-ratio: 16 / 9;
}
.video-tile.cam video { width: 100%; height: 100%; object-fit: cover; background: #000; display: block; }
/* shared screen: never crop, fill the stage */
.video-tile.screen { aspect-ratio: auto; width: 100%; height: 100%; background: #000; border-color: #e6a93b; }
.video-tile.screen video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }

/* states */
.video-tile.speaking { border-color: #5fc26b; }
.video-tile.active { border-color: #6ea8ff; box-shadow: 0 0 0 3px rgba(110,168,255,0.45), 0 6px 22px rgba(0,0,0,0.5); }

/* expanded "fullscreen meet" gallery (toggle with V) */
#meet.expanded { background: rgba(8, 10, 16, 0.94); pointer-events: auto; }
#meet.expanded #meet-main { top: 0; left: 0; transform: none; width: 100vw; height: 100vh; box-sizing: border-box; padding: 14px; }
#meet.expanded.sharing #meet-main { width: calc(100vw - 200px); height: 100vh; }
#meet.expanded #meet-strip { top: 0; right: 0; height: 100vh; max-height: 100vh; padding: 12px; }
#meet.expanded #meet-self { right: 18px; bottom: 18px; }

/* persistent controls hint */
#controls-hint {
  position: fixed; bottom: 12px; left: 12px; z-index: 11;
  font-size: 12px; color: #aeb6c6; background: rgba(20, 26, 38, 0.7);
  padding: 6px 10px; border-radius: 8px;
}
#controls-hint b { color: #fff; }
#dbg {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%); z-index: 20; display: none;
  background: rgba(0,0,0,0.85); color: #6fe0c0; font: bold 20px/1.5 monospace;
  padding: 14px 18px; border-radius: 10px; white-space: pre; pointer-events: none;
}
.video-tile .tag {
  position: absolute; bottom: 5px; left: 7px; font-size: 12px; font-weight: 600; color: #fff;
  background: rgba(0, 0, 0, 0.6); padding: 2px 7px; border-radius: 6px; max-width: 90%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.video-tile.muted .tag::before { content: "🔇 "; }
#meet-self .video-tile { width: 200px; border-color: #4f9dde; aspect-ratio: 16 / 9; }
#meet-self video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; }   /* mirror own cam */
