:root {
  --bg: #11131a;
  --panel: #1b1f2b;
  --accent: #5b8cff;
  --accent-2: #7a5bff;
  --text: #e8ebf2;
  --muted: #9aa3b8;
  --error: #ff6b6b;
  /* Checkerboard so transparency is visible while editing the stage. */
  --checker: #1a1d27;
  --checker-2: #20242f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", Meiryo, sans-serif;
}

/* ---------- Join panel ---------- */
.panel {
  max-width: 420px;
  margin: 8vh auto;
  padding: 28px 32px 32px;
  background: var(--panel);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}
.panel h1 {
  margin: 0 0 4px;
  font-size: 28px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.panel .sub { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.panel label {
  display: block;
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--muted);
}
.panel input, .panel select {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  background: #11141d;
  border: 1px solid #2b3142;
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}
.panel button {
  width: 100%;
  margin-top: 22px;
  padding: 12px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.panel button:hover { filter: brightness(1.08); }
.role-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; }
.role-opt {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 !important;
  padding: 10px;
  border: 1px solid #2b3142;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1.35;
}
.role-opt:has(input:checked) {
  border-color: var(--accent);
  background: rgba(91, 140, 255, 0.12);
}
.role-opt input { width: auto !important; margin: 2px 0 0 !important; }
.role-opt strong { color: var(--text); font-size: 13px; }

.hint { margin-top: 16px; color: var(--muted); font-size: 12px; }
.error { color: var(--error); font-size: 13px; margin-top: 12px; }

/* ---------- Stage ---------- */
#stage-wrap { position: fixed; inset: 0; }
#stage-host {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  /* checkerboard backdrop to reveal transparency during editing */
  background-image:
    linear-gradient(45deg, var(--checker) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker) 75%);
  background-size: 32px 32px;
  background-position: 0 0, 0 16px, 16px -16px, -16px 0;
  background-color: var(--checker-2);
}
#stage-host .compositor {
  position: relative;
  aspect-ratio: 16 / 9;
  width: min(100%, calc(100vh * 16 / 9));
  max-height: 100%;
  touch-action: none;
  cursor: grab;
}
#stage-host .compositor.dragging { cursor: grabbing; }
#stage-host .compositor canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#stage-host .compositor .labels { pointer-events: none; }
#stage-host .preview-canvas {
  max-height: 70vh;
  max-width: 40vw;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: linear-gradient(180deg, rgba(0,0,0,0.55), transparent);
  z-index: 10;
}
.hud-left { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.hud-right { display: flex; gap: 8px; }
.hud button {
  padding: 8px 12px;
  border: 1px solid #2b3142;
  border-radius: 8px;
  background: rgba(27, 31, 43, 0.85);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.hud button:hover { border-color: var(--accent); }
.hud button.off { opacity: 0.5; }
.stats {
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  padding-left: 8px;
}
.badge {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 12px;
  background: var(--accent);
  color: white;
  font-size: 12px;
}
.badge.role { background: var(--accent-2); }
.banner {
  position: absolute;
  top: 56px; left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  background: rgba(122, 91, 255, 0.18);
  border: 1px solid var(--accent-2);
  border-radius: 10px;
  color: var(--text);
  font-size: 13px;
  z-index: 10;
}
.help {
  position: absolute;
  bottom: 12px; left: 50%;
  transform: translateX(-50%);
  padding: 8px 14px;
  background: rgba(0,0,0,0.5);
  border-radius: 20px;
  color: var(--muted);
  font-size: 12px;
  z-index: 10;
  white-space: nowrap;
}

/* ---------- OBS stage mode: hide all chrome, transparent backdrop ---------- */
body.stage-mode #stage-host {
  background: transparent;
}
body.stage-mode .hud,
body.stage-mode .help { display: none; }
body.stage-mode #stage-host canvas { cursor: none; }
