:root {
  --bg: #111318;
  --surface: #1a1e26;
  --surface-2: #232834;
  --surface-glass: rgba(24, 28, 36, 0.88);
  --border: rgba(255, 255, 255, 0.1);
  --text: #eef1f7;
  --text-muted: #98a2b3;
  --primary: #5b8cff;
  --primary-hover: #709bff;
  --donate: #e25578;
  --donate-hover: #f06588;
  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #f59e0b;
  --radius: 12px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Inter, sans-serif;
  font-size: 14px;
  line-height: 1.4;
}

.hidden {
  display: none !important;
}

button, input, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ================= BUTTONS & INPUTS ================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover { background: #2c3342; }
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--primary);
  border-color: transparent;
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
  background: var(--surface-2);
  border-color: var(--border);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
}
.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.08);
}

.btn-donate {
  background: rgba(226, 85, 120, 0.16);
  border-color: rgba(226, 85, 120, 0.45);
  color: #ff8aa6;
}
.btn-donate:hover {
  background: var(--donate);
  border-color: transparent;
  color: #fff;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.16);
  border-color: rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}
.btn-danger:hover {
  background: var(--danger);
  color: #fff;
}

.btn-lg { padding: 11px 18px; font-size: 15px; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-xs { padding: 4px 8px; font-size: 12px; border-radius: 7px; }
.full-width { width: 100%; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 32px;
  padding: 0 9px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.1); }
.icon-btn.active {
  background: rgba(91, 140, 255, 0.25);
  border-color: rgba(91, 140, 255, 0.55);
  color: #a9c3ff;
}

.icon-btn-xs {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn-xs:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

input[type="text"], select {
  width: 100%;
  padding: 9px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: #12151c;
  color: var(--text);
  outline: none;
}
input[type="text"]:focus, select:focus {
  border-color: var(--primary);
}

input[type="color"] {
  width: 36px;
  height: 36px;
  padding: 2px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: #12151c;
  cursor: pointer;
}

/* ================= MAIN MENU ================= */
.menu-view {
  min-height: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px 18px 40px;
}

.menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(135deg, #4b73ff, #e25578);
  display: grid;
  place-items: center;
  font-size: 24px;
  box-shadow: 0 8px 22px rgba(91, 140, 255, 0.25);
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.menu-grid {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: 18px;
  align-items: start;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 12px;
  font-size: 16px;
}

.card-header-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.card-header-inline h2 { margin: 0; }

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}
.field > span {
  font-size: 12px;
  color: var(--text-muted);
}

.form-row.two-col {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
}

.color-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}
.color-inline span {
  font-family: monospace;
  font-size: 12px;
  color: var(--text-muted);
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}

.mode-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.mode-card {
  cursor: pointer;
}
.mode-card input {
  display: none;
}
.mode-card-body {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: #141720;
  display: flex;
  flex-direction: column;
  gap: 4px;
  height: 100%;
  transition: border-color 0.15s, background 0.15s;
}
.mode-card-body small {
  color: var(--text-muted);
  font-size: 12px;
}
.mode-card input:checked + .mode-card-body {
  border-color: var(--primary);
  background: rgba(91, 140, 255, 0.12);
}

.actions-row {
  display: flex;
  gap: 10px;
}
.actions-row .btn { width: 100%; }

.join-row {
  display: flex;
  gap: 8px;
}

.file-open-row {
  margin-top: 10px;
}
.file-btn {
  width: 100%;
  border: 1px dashed var(--border);
}

.muted-hint {
  color: var(--text-muted);
  font-size: 12px;
  margin: 0 0 12px;
}

.rooms-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 490px;
  overflow-y: auto;
}

.room-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #141720;
  border: 1px solid var(--border);
}

.room-item-info {
  min-width: 0;
}
.room-item-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.room-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
}

.room-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.empty-state {
  text-align: center;
  padding: 28px 12px;
  color: var(--text-muted);
}

/* ================= STUDIO VIEW ================= */
.studio-view {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #13151b;
  user-select: none;
  -webkit-user-select: none;
}

.topbar {
  position: fixed;
  top: 10px;
  left: 10px;
  right: 10px;
  height: 46px;
  padding: 0 10px;
  border-radius: 13px;
  background: var(--surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  z-index: 30;
  overflow-x: auto;
  scrollbar-width: none;
}
.topbar::-webkit-scrollbar { display: none; }

.topbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.room-badge-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 6px;
}

.room-title {
  font-weight: 600;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}

.ws-pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
}
.ws-pill.online { color: #6ee7b7; }
.ws-pill.offline { color: #fca5a5; }
.ws-pill.connecting { color: #fcd34d; }

/* Dropdown */
.dropdown-wrap {
  position: relative;
}

.dropdown-menu {
  position: fixed;
  top: 62px;
  right: 18px;
  min-width: 245px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 6px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 60;
}

.dropdown-menu button,
.dropdown-file-item {
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: block;
  font-size: 13px;
}
.dropdown-menu button:hover,
.dropdown-file-item:hover {
  background: rgba(255, 255, 255, 0.09);
}
.dropdown-menu hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

/* Canvas Stage */
.canvas-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
}

#draw-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.cursors-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 10;
}

.remote-cursor {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate3d(-100px, -100px, 0);
  pointer-events: none;
  will-change: transform;
}

.remote-cursor-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -50%);
}

.remote-cursor-tag {
  margin-top: 2px;
  margin-left: 6px;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

/* Left Tool Dock */
.tool-dock {
  position: fixed;
  left: 10px;
  top: 68px;
  bottom: 12px;
  width: 72px;
  padding: 8px 6px;
  border-radius: 14px;
  background: var(--surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  overflow-y: auto;
  scrollbar-width: none;
  z-index: 25;
}
.tool-dock::-webkit-scrollbar { display: none; }

.brush-presets-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: 100%;
}

.dock-btn {
  width: 56px;
  min-height: 40px;
  padding: 4px 2px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 16px;
}
.dock-btn span.lbl {
  font-size: 10px;
  color: var(--text-muted);
  max-width: 52px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dock-btn:hover { background: rgba(255, 255, 255, 0.1); }
.dock-btn.active {
  background: rgba(91, 140, 255, 0.25);
  border-color: var(--primary);
}
.dock-btn.active span.lbl { color: #cfe0ff; }

.dock-sep {
  width: 75%;
  height: 1px;
  background: var(--border);
  margin: 2px 0;
  flex-shrink: 0;
}

.color-picker-wrap input[type="color"] {
  width: 42px;
  height: 36px;
  border-radius: 10px;
}

.quick-palette {
  display: grid;
  grid-template-columns: repeat(2, 18px);
  gap: 4px;
}

.swatch {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  cursor: pointer;
  padding: 0;
}
.swatch.active {
  outline: 2px solid #fff;
  outline-offset: 1px;
}

.dock-slider-group {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 2px;
}
.dock-slider-group label {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-muted);
}
.dock-slider-group input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  margin: 0;
}

/* Right Side Panels */
.side-panel {
  position: fixed;
  top: 68px;
  right: 10px;
  width: 286px;
  max-height: calc(100vh - 82px);
  border-radius: 14px;
  background: var(--surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  z-index: 26;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.panel-header h3 {
  margin: 0;
  font-size: 14px;
}
.panel-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.panel-list {
  padding: 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.layer-row {
  padding: 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid transparent;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
}
.layer-row.active {
  background: rgba(91, 140, 255, 0.16);
  border-color: rgba(91, 140, 255, 0.5);
}

.layer-row-top {
  display: flex;
  align-items: center;
  gap: 6px;
}
.layer-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}
.layer-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}
.layer-controls input[type="range"] {
  flex: 1;
  accent-color: var(--primary);
}

.role-banner {
  padding: 7px 12px;
  font-size: 12px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--border);
}

.user-row {
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.user-row.is-hidden-author {
  opacity: 0.6;
}

.user-main {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  cursor: pointer;
}

.user-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.user-text {
  min-width: 0;
}
.user-name-line {
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 500;
}
.user-name-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 115px;
}
.user-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.user-actions {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}

.mod-btn {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.mod-btn:hover { background: rgba(255, 255, 255, 0.14); }
.mod-btn.active-warn {
  background: rgba(239, 68, 68, 0.25);
  border-color: rgba(239, 68, 68, 0.5);
}
.mod-btn.active-role {
  background: rgba(91, 140, 255, 0.28);
  border-color: rgba(91, 140, 255, 0.6);
}

/* ================= MODALS ================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 80;
}

.modal {
  width: 100%;
  max-height: 92vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-sm { max-width: 440px; }
.modal-lg { max-width: 720px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 16px; }

.modal-body {
  padding: 16px;
  overflow-y: auto;
}

.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.copy-box {
  display: flex;
  gap: 8px;
  margin: 10px 0;
}

/* Brush Editor */
.brush-editor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.brush-preview-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}
.brush-preview-box span {
  font-size: 12px;
  color: var(--text-muted);
}
#be-preview-canvas {
  width: 100%;
  height: 170px;
  background: #ffffff;
  border-radius: 10px;
  border: 1px solid var(--border);
  touch-action: none;
  cursor: crosshair;
}

.brush-io-row {
  display: flex;
  gap: 8px;
}
.brush-io-row > * { flex: 1; }

.param-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 9px;
}
.param-row label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
}
.param-row input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}
.two-col-inline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

/* Toasts */
.toast-container {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 90;
  pointer-events: none;
}

.toast {
  padding: 9px 14px;
  border-radius: 10px;
  background: rgba(24, 28, 36, 0.94);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: fadeInUp 0.18s ease-out;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ================= RESPONSIVE ================= */
@media (max-width: 860px) {
  .menu-grid {
    grid-template-columns: 1fr;
  }
  .brush-editor-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .mode-cards {
    grid-template-columns: 1fr;
  }
  .room-title {
    max-width: 90px;
  }
  .tool-dock {
    width: 62px;
    left: 6px;
    top: 62px;
  }
  .dock-btn {
    width: 48px;
    min-height: 36px;
  }
  .side-panel {
    width: calc(100vw - 80px);
    right: 6px;
    top: 62px;
  }
}
