:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --bg-gradient: linear-gradient(135deg, #f6f8fc 0%, #edf2ff 100%);
  --surface: rgba(255, 255, 255, 0.85);
  --surface-border: rgba(255, 255, 255, 0.4);
  --shadow-sm: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-md: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.08);
  --text-main: #0f172a;
  --text-muted: #475569;
  --border: rgba(15, 23, 42, 0.08);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --radius-md: 12px;
  --radius-lg: 16px;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; }
body { 
  margin: 0; 
  font-family: 'Inter', system-ui, -apple-system, sans-serif; 
  background: var(--bg-gradient); 
  overflow: hidden; 
  color: var(--text-main);
}

/* Launch Page */
#launchPage { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
#launchPage[hidden] { display: none; }
.launchCard { width: min(640px, 100%); background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(12px); border: 1px solid var(--border); border-radius: 24px; padding: 40px; box-shadow: 0 30px 80px rgba(15, 23, 42, 0.12); }
.launchEyebrow { margin: 0 0 12px; color: var(--primary); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; font-size: 13px; }
.launchCard h1 { margin: 0; font-size: clamp(2rem, 4vw, 3.5rem); line-height: 1.1; color: var(--text-main); font-weight: 800; letter-spacing: -0.02em; }
.launchCopy { margin: 16px 0 0; color: var(--text-muted); font-size: 1.1rem; line-height: 1.6; max-width: 52ch; }
.launchActions { margin-top: 32px; display: grid; gap: 16px; }
.launchPrimary { width: 100%; padding: 16px 24px; border: none; border-radius: 16px; background: var(--text-main); color: #fff; font-weight: 600; font-size: 16px; cursor: pointer; box-shadow: 0 14px 30px rgba(15, 23, 42, 0.18); transition: all 0.2s; }
.launchPrimary:hover { background: #000; transform: translateY(-2px); box-shadow: 0 20px 40px rgba(15, 23, 42, 0.25); }
.joinRow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; }
.joinRow input { width: 100%; padding: 16px 20px; border: 1px solid var(--border); border-radius: 16px; background: #fff; font-size: 16px; outline: none; font-family: inherit; transition: border-color 0.2s, box-shadow 0.2s; }
.joinRow input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12); }
.joinRow button { padding: 16px 24px; border: none; border-radius: 16px; background: var(--primary); color: #fff; font-weight: 600; font-size: 16px; cursor: pointer; transition: all 0.2s; }
.joinRow button:hover { background: var(--primary-hover); transform: translateY(-2px); }

/* App Shell & Canvas */
#appShell { position: relative; width: 100%; height: 100%; }
#board, #elements { position: fixed; left: 0; top: 0; width: 100%; height: 100%; touch-action: none; }
#board { pointer-events: none; z-index: 1; }
#elements { pointer-events: auto; z-index: 2; }

/* Floating Islands */
.floating-island {
  position: fixed;
  z-index: 20;
  background: var(--surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  padding: 8px;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-center { top: 20px; left: 50%; transform: translateX(-50%); }
.top-left { top: 20px; left: 20px; }
.top-right { top: 20px; right: 20px; }

/* Popout Menus */
.popout-container { position: relative; display: flex; align-items: center; }
.popout-menu {
  position: absolute;
  top: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  padding: 8px;
  box-shadow: var(--shadow-md);
  display: flex;
  gap: 8px;
  z-index: 30;
  transition: opacity 0.2s, transform 0.2s;
  transform-origin: top center;
}
.popout-menu[hidden] {
  display: none !important;
}
.options-menu {
  flex-direction: column;
  min-width: 200px;
  padding: 16px;
}

/* Tool Groups & Dividers */
.tool-group { display: flex; align-items: center; gap: 4px; }
.island-row { display: flex; align-items: center; gap: 8px; }
.prop-group { display: flex; flex-direction: column; gap: 12px; width: 100%; }
.divider { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }
.divider-horizontal { width: 100%; height: 1px; background: var(--border); margin: 8px 0; }

/* Buttons & Icons */
.tool-btn, .icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  border: none; border-radius: var(--radius-md);
  background: transparent; color: var(--text-muted);
  cursor: pointer; transition: all 0.2s;
}
.tool-btn:hover, .icon-btn:hover { background: rgba(15, 23, 42, 0.05); color: var(--text-main); }
.tool-btn.active { background: var(--primary); color: white; box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3); }
.icon-btn.danger:hover { background: #fee2e2; color: var(--danger); }
.icon-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Form Elements */
.input-with-icon {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: rgba(255,255,255,0.5);
  border: 1px solid var(--border); border-radius: var(--radius-md);
}
.input-with-icon i { width: 16px; height: 16px; color: var(--text-muted); }
.input-with-icon input { border: none; background: transparent; width: 110px; font-size: 13px; font-weight: 500; color: var(--text-main); outline: none; }

label { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; font-weight: 500; color: var(--text-muted); cursor: pointer; }
.checkbox-label { justify-content: flex-start; }

input[type="color"] {
  -webkit-appearance: none;
  width: 28px; height: 28px; border: none; border-radius: 6px; cursor: pointer; padding: 0; background: transparent; overflow: hidden;
  box-shadow: 0 0 0 1px var(--border);
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 6px; }

input[type="range"] {
  -webkit-appearance: none; width: 100px; height: 6px; background: var(--border); border-radius: 3px; outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--primary); cursor: pointer; box-shadow: 0 2px 4px rgba(0,0,0,0.2); transition: transform 0.1s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }

.modern-select {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px;
  background: rgba(255,255,255,0.5); color: var(--text-main); font-family: inherit; outline: none; cursor: pointer;
}

input[type="checkbox"] { width: 16px; height: 16px; border-radius: 4px; cursor: pointer; accent-color: var(--primary); }

/* Mobile Responsiveness */
@media (max-width: 768px) {
  /* Hide connection status to save space */
  #connectionStatus { display: none !important; }

  /* Room Controls - Top Left */
  .top-left { top: 8px; left: 8px; padding: 4px; gap: 4px; }
  .top-left .input-with-icon input { width: 60px; font-size: 11px; }
  .top-left .input-with-icon { padding: 4px; gap: 4px; }
  .top-left .icon-btn { width: 28px; height: 28px; }
  
  /* Actions - Top Right */
  .top-right { top: 8px; right: 8px; padding: 4px; gap: 2px; }
  .top-right .icon-btn { width: 28px; height: 28px; }
  .top-right .icon-btn i { width: 16px; height: 16px; }

  /* Toolbar - Move to Bottom Dock */
  .top-center { 
    top: auto; 
    bottom: 8px; 
    left: 50%; 
    transform: translateX(-50%); 
    width: calc(100% - 16px); 
    justify-content: space-between;
    padding: 6px;
    gap: 2px;
  }
  .tool-btn { width: 34px; height: 34px; }
  .tool-btn i { width: 18px; height: 18px; }

  /* Properties - Now inside popout menu, we can adjust popout positioning for mobile if needed */
  .popout-menu {
    top: auto;
    bottom: calc(100% + 12px);
    transform-origin: bottom center;
  }
  .options-menu {
    min-width: 240px;
  }
  .options-menu label { gap: 8px; font-size: 13px; white-space: normal; }
  input[type="range"] { width: 100px; }
  .modern-select { padding: 6px 10px; font-size: 13px; }
  input[type="color"] { width: 28px; height: 28px; }
}
