:root {
  --bg: #0b0d10;
  --bg-2: #11141a;
  --bg-3: #161a22;
  --panel: #12161e;
  --line: #1f2530;
  --line-2: #2a3140;
  --ink: #e6ebf2;
  --ink-2: #aab3c0;
  --ink-3: #6c7588;
  --accent: #58a6ff;
  --accent-2: #3b82d4;
  --good: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 0 rgba(255,255,255,0.04), 0 8px 24px rgba(0,0,0,0.5);
  --font: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* -------- Join overlay -------- */
.overlay {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background:
    radial-gradient(900px 600px at 30% 20%, rgba(88,166,255,0.12), transparent 60%),
    radial-gradient(900px 600px at 80% 90%, rgba(168,85,247,0.10), transparent 60%),
    var(--bg);
  z-index: 50;
  padding: 24px;
}
.overlay-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.brand { display: flex; gap: 14px; align-items: center; margin-bottom: 20px; }
.brand h1 { font-size: 18px; margin: 0; font-weight: 600; letter-spacing: -0.01em; }
.brand p { margin: 2px 0 0; color: var(--ink-2); font-size: 13px; }

.field { display: block; margin-top: 14px; }
.field > span { display: block; color: var(--ink-2); font-size: 12px; margin-bottom: 6px; font-weight: 500; }
.field input[type=text] {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  color: var(--ink);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-family: var(--mono);
  font-size: 13px;
  outline: none;
}
.field input[type=text]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(88,166,255,0.18); }
.field .row { display: flex; gap: 8px; }
.field .row input { flex: 1; }
.hint { display: block; margin-top: 6px; color: var(--ink-3); font-size: 11px; }

.footnote { margin-top: 16px; color: var(--ink-3); font-size: 11px; text-align: center; }

/* -------- Buttons -------- */
.btn {
  appearance: none; border: 1px solid var(--line-2);
  background: var(--bg-3); color: var(--ink);
  padding: 9px 14px; border-radius: var(--radius-sm);
  font: inherit; font-weight: 500; cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 80ms ease;
}
.btn:hover { background: #1c2230; border-color: #364056; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #061224; font-weight: 600; width: 100%; margin-top: 18px; padding: 12px; }
.btn.primary:hover { background: #74b7ff; border-color: #74b7ff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn.full { width: 100%; }

/* -------- App shell -------- */
.app { position: fixed; inset: 0; display: grid; grid-template-rows: 48px 1fr; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  user-select: none;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.brand-text strong { font-size: 13px; font-weight: 600; letter-spacing: -0.01em; }
.brand-text { display: flex; align-items: baseline; gap: 10px; }
.room-tag { color: var(--ink-2); font-size: 12px; }
.room-tag code { font-family: var(--mono); background: var(--bg-3); padding: 1px 6px; border-radius: 4px; color: var(--ink); }

.topbar-right { display: flex; align-items: center; gap: 10px; }

.presence-list { display: flex; align-items: center; gap: -6px; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: inline-grid; place-items: center;
  font-size: 11px; font-weight: 600;
  color: #061224;
  margin-left: -6px;
  border: 2px solid var(--bg-2);
  position: relative;
  transition: transform 120ms ease;
}
.avatar:first-child { margin-left: 0; }
.avatar:hover { transform: translateY(-1px) scale(1.05); z-index: 2; }
.avatar.you::after {
  content: ''; position: absolute; right: -1px; bottom: -1px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--good); border: 2px solid var(--bg-2);
}
.avatar[data-tooltip]:hover::before {
  content: attr(data-tooltip);
  position: absolute; top: calc(100% + 6px); right: 0;
  background: var(--bg-3); border: 1px solid var(--line-2);
  color: var(--ink); padding: 4px 8px; border-radius: 4px;
  font-size: 11px; white-space: nowrap; font-weight: 500;
  z-index: 10;
}

/* -------- Layout -------- */
.layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  min-height: 0;
}
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .panel { max-height: 45vh; }
}

/* -------- Viewport -------- */
.viewport { position: relative; background: #0a0c10; overflow: hidden; }
#scene { display: block; width: 100%; height: 100%; }

.hud-overlay { position: absolute; inset: 0; pointer-events: none; }

.remote-cursor {
  position: absolute;
  pointer-events: none;
  transform: translate(-2px, -2px);
  transition: left 80ms linear, top 80ms linear;
  display: flex; align-items: flex-start; gap: 4px;
  z-index: 5;
}
.remote-cursor svg { width: 18px; height: 18px; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5)); }
.remote-cursor .label {
  padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600; color: #061224;
  white-space: nowrap; margin-top: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.viewport-hud {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 12px 14px;
  display: flex; justify-content: space-between; align-items: flex-end;
  pointer-events: none;
}
.dimension-readout {
  background: rgba(11,13,16,0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  padding: 6px 10px; border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 12px; color: var(--ink-2);
}
.view-controls { display: flex; gap: 6px; pointer-events: auto; }
.hud-btn {
  background: rgba(11,13,16,0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  color: var(--ink); padding: 6px 12px;
  border-radius: var(--radius-sm); font: inherit; font-size: 12px;
  cursor: pointer;
}
.hud-btn:hover { background: var(--bg-3); }
.hud-btn.active { background: var(--accent); color: #061224; border-color: var(--accent); font-weight: 600; }

.status-pill {
  position: absolute; top: 12px; left: 12px;
  padding: 5px 10px; border-radius: 999px;
  background: rgba(11,13,16,0.7);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  font-size: 11px; font-weight: 500; color: var(--ink-2);
  display: flex; align-items: center; gap: 6px;
}
.status-pill::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%;
  background: var(--warn); box-shadow: 0 0 6px currentColor;
}
.status-pill.connected { color: var(--good); }
.status-pill.connected::before { background: var(--good); }
.status-pill.error { color: var(--bad); }
.status-pill.error::before { background: var(--bad); }

/* -------- Panel -------- */
.panel {
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: 4px 0 24px;
}
.panel-section { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel-section:last-child { border-bottom: 0; }
.panel-section h2 {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink-3); margin: 0 0 10px;
}

.control { margin-bottom: 12px; }
.control:last-child { margin-bottom: 0; }
.control label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12px; color: var(--ink-2); margin-bottom: 5px;
}
.control label output {
  font-family: var(--mono); color: var(--ink); font-size: 11px;
  background: var(--bg-3); padding: 1px 6px; border-radius: 4px;
}

input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; border-radius: 999px;
  background: var(--bg-3); outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); cursor: pointer;
  border: 2px solid var(--bg-2);
  transition: transform 100ms ease;
}
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type=range]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 2px solid var(--bg-2);
}

select, input[type=color] {
  width: 100%; background: var(--bg-3);
  border: 1px solid var(--line-2); color: var(--ink);
  padding: 7px 10px; border-radius: var(--radius-sm);
  font: inherit; font-size: 12px; outline: none;
  cursor: pointer;
}
select:focus { border-color: var(--accent); }
input[type=color] { padding: 3px; height: 32px; }

.checkbox { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.checkbox input { width: 14px; height: 14px; accent-color: var(--accent); }

.swatches { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.swatch {
  appearance: none;
  background: linear-gradient(135deg, var(--c1), var(--c2));
  border: 2px solid transparent;
  color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.6);
  padding: 10px; border-radius: var(--radius-sm);
  font: inherit; font-size: 11px; font-weight: 600;
  cursor: pointer; text-align: left;
}
.swatch.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(88,166,255,0.25); }

.session-meta {
  display: grid; gap: 6px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
  margin-bottom: 10px;
}
.session-meta > div { display: flex; justify-content: space-between; font-size: 12px; }
.session-meta span { color: var(--ink-3); }
.session-meta code { font-family: var(--mono); font-size: 12px; }

/* -------- Toast -------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bg-3); border: 1px solid var(--line-2);
  color: var(--ink); padding: 9px 14px;
  border-radius: var(--radius-sm); font-size: 13px;
  opacity: 0; pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 100;
  max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Edit pulse — flashes the control briefly when a remote edit comes in */
@keyframes editPulse {
  0% { box-shadow: 0 0 0 0 currentColor; }
  100% { box-shadow: 0 0 0 8px transparent; }
}
.control.remote-edit {
  position: relative;
}
.control.remote-edit::after {
  content: attr(data-editor); position: absolute; right: 0; top: 0;
  font-size: 10px; padding: 1px 6px; border-radius: 10px;
  background: var(--accent); color: #061224; font-weight: 600;
  animation: fadeOut 1.2s ease forwards;
  pointer-events: none;
}
@keyframes fadeOut {
  0%   { opacity: 1; transform: translateY(-2px); }
  100% { opacity: 0; transform: translateY(-8px); }
}
