/* ==========================================================================
   CANVAS STUDIO — MINIMAL CREATIVE & PLAYFUL THEME
   Design System & Component Tokens
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@600;700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  /* Color Tokens — Minimal Creative Palette */
  --bg: #f9f8f5;
  --surface: #ffffff;
  --surface-2: #f3f1ea;
  --border: #e4e1d8;
  --text: #18181b;
  --text-dim: #71717a;

  /* Hero Color: Deep Black / Charcoal */
  --accent: #18181b;
  --accent-hover: #27272a;
  --accent-active: #09090b;
  --accent-text: #ffffff;

  --danger: #e5484d;
  --success: #2ea043;
  --warning: #f5a524;
  --canvas: #ffffff;
  --focus-ring: #18181b;
  --disabled-bg: #eeece8;
  --disabled-text: #b0ada8;

  /* Typography Scale */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-calligraphy: 'Caveat', cursive, -apple-system, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs-xs: 11px;
  --fs-sm: 13px;
  --fs-md: 14px;
  --fs-lg: 18px;
  --fs-xl: 28px;

  /* Elevation — Soft, Diffuse Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-pop: 0 4px 20px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-modal: 0 12px 48px rgba(0, 0, 0, 0.10), 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-hover: 0 8px 32px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04);

  /* Z-Index Scale */
  --z-canvas: 1;
  --z-hud: 5;
  --z-toolbar: 10;
  --z-users: 10;
  --z-reconnect: 30;
  --z-toast: 40;
  --z-modal: 50;

  /* Radii — Generous, Friendly */
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius-pill: 999px;
  --radius-round: 50%;
}

[data-theme="dark"] {
  --bg: #0f1013;
  --surface: #181a1f;
  --surface-2: #22252c;
  --border: #2c303a;
  --text: #f4f4f5;
  --text-dim: #9ca3af;

  /* Crisp chalk white contrast in dark mode */
  --accent: #f4f4f5;
  --accent-hover: #e4e4e7;
  --accent-active: #ffffff;
  --accent-text: #18181b;

  --danger: #ff5a5f;
  --success: #34d399;
  --warning: #fbbf24;
  --canvas: #141519;
  --focus-ring: #f4f4f5;
  --disabled-bg: #262932;
  --disabled-text: #595e6f;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-pop: 0 8px 24px rgba(0, 0, 0, 0.5);
  --shadow-modal: 0 16px 56px rgba(0, 0, 0, 0.6);
  --shadow-hover: 0 8px 32px rgba(0, 0, 0, 0.6);
}

/* Fast, noticeable animation for theme switch across the entire webpage */
.theme-transitioning,
.theme-transitioning *,
.theme-transitioning *::before,
.theme-transitioning *::after {
  transition: background-color 280ms cubic-bezier(0.4, 0, 0.2, 1),
              border-color 280ms cubic-bezier(0.4, 0, 0.2, 1),
              color 280ms cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 280ms cubic-bezier(0.4, 0, 0.2, 1),
              filter 280ms cubic-bezier(0.4, 0, 0.2, 1),
              opacity 280ms cubic-bezier(0.4, 0, 0.2, 1) !important;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: 1.5;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  position: relative;
}

/* Seamless dynamic doodle background pattern */
body::before {
  content: "";
  position: fixed;
  top: -400px;
  left: -400px;
  width: calc(100vw + 800px);
  height: calc(100vh + 800px);
  background-image: url('/doodle-pattern.svg');
  background-repeat: repeat;
  background-size: 400px 400px;
  opacity: 0.08;
  pointer-events: none;
  z-index: 0;
  animation: doodleDrift 110s linear infinite;
  will-change: transform;
}

[data-theme="dark"] body::before {
  opacity: 0.065;
  filter: invert(1);
}

@keyframes doodleDrift {
  0% {
    transform: translate3d(0, 0, 0);
  }
  100% {
    transform: translate3d(-400px, -400px, 0);
  }
}

/* Accessible Focus States */
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

button:focus:not(:focus-visible),
input:focus:not(:focus-visible) {
  outline: none;
}

/* ==========================================================================
   SVG ICON HELPERS
   ========================================================================== */
.icon {
  width: 20px;
  height: 20px;
  display: inline-block;
  vertical-align: middle;
  pointer-events: none;
  flex-shrink: 0;
}

.icon-sm {
  width: 16px;
  height: 16px;
}

/* ==========================================================================
   BUTTON SYSTEM
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  padding: 0 20px;
  border-radius: var(--radius-md);
  font-size: var(--fs-md);
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  transition: all 200ms ease;
  user-select: none;
  touch-action: manipulation;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-primary {
  background-color: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.16);
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--accent-hover);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.24);
  transform: translateY(-1px);
}

.btn-primary:active:not(:disabled) {
  background-color: var(--accent-active);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  transform: translateY(1px);
}

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

.btn-secondary:hover:not(:disabled) {
  background-color: var(--border);
  transform: translateY(-1px);
}

.btn-ghost {
  background-color: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover:not(:disabled) {
  background-color: var(--surface-2);
  border-color: #d9d7d2;
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn-danger {
  background-color: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background-color: rgba(229, 72, 77, 0.08);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ==========================================================================
   LANDING VIEW — Playful Minimal Creative
   ========================================================================== */
.landing-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  position: relative;
  z-index: 1;
}

.landing-top-bar {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10;
}

.landing-theme-btn {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-round);
  background-color: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 180ms cubic-bezier(0.34, 1.56, 0.64, 1), background-color 180ms ease, border-color 180ms ease;
}

.landing-theme-btn:hover {
  transform: scale(1.1) rotate(6deg);
  background-color: var(--surface-2);
  box-shadow: var(--shadow-pop);
}

.landing-theme-btn:active {
  transform: scale(0.95);
}

.landing-header {
  text-align: center;
  margin-bottom: 28px;
}

.landing-title {
  font-family: var(--font-calligraphy);
  font-size: 54px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 4px 0;
  color: var(--text);
  line-height: 1.1;
  text-align: center;
  display: block;
}

.landing-subtitle {
  font-size: 16px;
  color: var(--text-dim);
  margin: 0;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.landing-card {
  width: 100%;
  max-width: 420px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 34px 32px;
  box-shadow: var(--shadow-modal);
  display: flex;
  flex-direction: column;
  gap: 18px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: box-shadow 300ms ease, transform 300ms ease;
}

.landing-card:hover {
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.12), 0 4px 16px rgba(0, 0, 0, 0.04);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.01em;
}

.input-field {
  height: 44px;
  background-color: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 14px;
  color: var(--text);
  font-size: var(--fs-md);
  font-family: inherit;
  transition: border-color 200ms ease, box-shadow 200ms ease, background-color 200ms ease;
}

.input-field::placeholder {
  color: var(--text-dim);
  opacity: 0.7;
}

.input-field:hover {
  border-color: #c9c6bd;
}

[data-theme="dark"] .input-field:hover {
  border-color: #434855;
}

.input-field:focus {
  border-color: var(--accent);
  background-color: var(--surface);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.12);
}

[data-theme="dark"] .input-field:focus {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.16);
}

.landing-divider {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--text-dim);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
}

.landing-divider::before,
.landing-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background-color: var(--border);
}

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

.join-form-row .input-field {
  flex: 1;
}

.form-error {
  font-size: var(--fs-sm);
  color: var(--danger);
  min-height: 18px;
  margin: 0;
}

.landing-footer-hint {
  text-align: center;
  font-size: var(--fs-xs);
  color: var(--text-dim);
  margin-top: 22px;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1px dashed var(--border);
  letter-spacing: 0.04em;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}

/* ==========================================================================
   ROOM VIEW & CANVAS STACK — Fixed Relative Containment
   ========================================================================== */
.room-container {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background-color: var(--bg);
}

#canvas-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-canvas);
  cursor: crosshair;
  touch-action: none;
  overflow: hidden;
}

/* Stacked canvases within letterboxed contain area */
.canvas-wrapper {
  position: relative;
  box-shadow: var(--shadow-modal);
  background-color: var(--canvas);
  border-radius: 4px;
}

.canvas-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.canvas-base {
  z-index: 1;
  background-color: var(--canvas);
  box-shadow: var(--shadow-modal);
  border-radius: 4px;
}

.canvas-active {
  z-index: 2;
  pointer-events: none;
}

.canvas-cursor {
  z-index: 3;
  pointer-events: auto;
}

/* Empty State Canvas Indicator */
.canvas-empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-dim);
  font-size: var(--fs-md);
  font-weight: 500;
  pointer-events: none;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  transition: opacity 200ms ease;
  opacity: 0.5;
}

/* ==========================================================================
   TOP FLOATING TOOLBAR — Pill Shape
   ========================================================================== */
.toolbar {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  height: 52px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 5px;
  max-width: calc(100vw - 28px);
  overflow-x: auto;
  scrollbar-width: none;
  box-shadow: var(--shadow-pop);
  z-index: var(--z-toolbar);
  user-select: none;
  transition: box-shadow 300ms ease, transform 300ms ease;
}

.toolbar::-webkit-scrollbar {
  display: none;
}

.toolbar:hover {
  box-shadow: var(--shadow-hover);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background-color: var(--border);
  margin: 0 4px;
}

/* Tool Buttons */
.tool-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 200ms ease;
  touch-action: manipulation;
  position: relative;
}

.tool-btn:hover:not(:disabled) {
  background-color: var(--surface-2);
  color: var(--text);
  transform: translateY(-1px);
}

.tool-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.tool-btn.active {
  background-color: var(--surface-2);
  color: var(--accent);
  border-color: var(--border);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] .tool-btn.active {
  border-color: rgba(255, 255, 255, 0.16);
}

.tool-btn.active:hover {
  background-color: var(--border);
}

.tool-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

/* Swatches */
.swatches-cluster {
  display: flex;
  align-items: center;
  gap: 4px;
}

.swatch-btn {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-round);
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  transition: all 200ms cubic-bezier(0.34, 1.56, 0.64, 1);
  touch-action: manipulation;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.swatch-btn:hover {
  transform: scale(1.25);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15), inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.swatch-btn.active {
  border-color: var(--text);
  transform: scale(1.15);
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text);
}

/* Custom color input container */
.color-picker-wrapper {
  position: relative;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-round);
  border: 1px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  background: conic-gradient(from 0deg, #ff6b6b, #ffd93d, #6bcb77, #4d96ff, #9b59b6, #ff6b6b);
  transition: transform 200ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.color-picker-wrapper:hover {
  transform: scale(1.25);
}

.color-picker-input {
  position: absolute;
  top: -10px;
  left: -10px;
  width: 50px;
  height: 50px;
  opacity: 0;
  cursor: pointer;
}

/* Size Slider */
.slider-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.size-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 90px;
  height: 4px;
  background: var(--border);
  border-radius: var(--radius-pill);
  outline: none;
  transition: background 200ms ease;
}

.size-slider:hover {
  background: #d0cec9;
}

.size-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  transition: all 200ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.size-slider::-webkit-slider-thumb:hover {
  transform: scale(1.3);
  box-shadow: 0 2px 8px rgba(255, 107, 107, 0.3);
}

.size-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

.size-chip {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text-dim);
  min-width: 28px;
  text-align: right;
}

/* ==========================================================================
   ONLINE USERS PANEL — Docked to Bottom Right
   ========================================================================== */
.users-panel {
  position: fixed;
  bottom: 16px;
  right: 16px;
  top: auto;
  width: 204px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  z-index: var(--z-users);
  transition: all 250ms ease;
  display: flex;
  flex-direction: column;
}

.users-panel:hover {
  box-shadow: var(--shadow-hover);
}

.users-panel-header {
  height: 40px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text);
}

.users-count-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.users-count-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--success);
  box-shadow: 0 0 0 2px rgba(46, 160, 67, 0.2);
}

.users-list {
  list-style: none;
  margin: 0;
  padding: 4px 0;
  max-height: 240px;
  overflow-y: auto;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: var(--fs-sm);
  transition: background-color 150ms ease;
  border-radius: 4px;
  margin: 0 4px;
}

.user-row:hover {
  background-color: var(--surface-2);
}

.user-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.user-name-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.user-you-tag {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  font-weight: 400;
}

/* ==========================================================================
   PERFORMANCE HUD — Frosted Glass Pill (Left of Users Panel)
   ========================================================================== */
.perf-hud {
  position: fixed;
  bottom: 16px;
  right: 232px;
  left: auto;
  top: auto;
  background-color: rgba(255, 255, 255, 0.75);
  border: 1px solid rgba(232, 230, 225, 0.7);
  border-radius: var(--radius-pill);
  padding: 5px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.03em;
  color: var(--text-dim);
  box-shadow: var(--shadow-sm);
  z-index: var(--z-hud);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  user-select: none;
  transition: all 200ms ease;
}

[data-theme="dark"] .perf-hud {
  background-color: rgba(24, 26, 31, 0.75);
  border-color: rgba(44, 48, 58, 0.6);
}

.perf-hud:hover {
  background-color: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow-pop);
}

[data-theme="dark"] .perf-hud:hover {
  background-color: rgba(30, 33, 40, 0.9);
}

.perf-hud-item span {
  color: var(--text);
  font-weight: 600;
}

/* ==========================================================================
   RECONNECTING BANNER
   ========================================================================== */
.reconnect-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 38px;
  background: linear-gradient(135deg, var(--accent) 0%, #ff8e8e 100%);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: var(--fs-sm);
  font-weight: 600;
  z-index: var(--z-reconnect);
  box-shadow: 0 2px 12px rgba(255, 107, 107, 0.25);
  animation: slideDown 200ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideDown {
  from {
    transform: translateY(-100%);
  }
  to {
    transform: translateY(0);
  }
}

/* ==========================================================================
   TOAST SYSTEM
   ========================================================================== */
.toast-container {
  position: fixed;
  bottom: 14px;
  left: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 340px;
  width: calc(100vw - 28px);
  z-index: var(--z-toast);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: var(--fs-sm);
  color: var(--text);
  box-shadow: var(--shadow-pop);
  animation: toastIn 250ms cubic-bezier(0.34, 1.56, 0.64, 1);
  transition: opacity 180ms ease-in, transform 180ms ease-in;
}

.toast.toast-success {
  border-left-color: var(--success);
}

.toast.toast-warning {
  border-left-color: var(--warning);
}

.toast.toast-danger {
  border-left-color: var(--danger);
}

.toast.toast-exit {
  opacity: 0;
  transform: translateY(8px) scale(0.97);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ==========================================================================
   MODAL DIALOGS
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(250, 250, 248, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: var(--z-modal);
  animation: fadeIn 200ms ease-out;
}

.modal-dialog {
  width: 100%;
  max-width: 400px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 28px;
  box-shadow: var(--shadow-modal);
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: modalScale 250ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-title {
  font-size: var(--fs-lg);
  font-weight: 600;
  margin: 0;
  color: var(--text);
}

.modal-message {
  font-size: var(--fs-md);
  color: var(--text-dim);
  margin: 0;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalScale {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* ==========================================================================
   LOADING OVERLAY
   ========================================================================== */
.loading-overlay {
  position: absolute;
  inset: 0;
  background-color: rgba(250, 250, 248, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 25;
  color: var(--text);
  font-size: var(--fs-md);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.loading-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ==========================================================================
   RESPONSIVE DESIGN — MOBILE-OPTIMIZED (PHONE & TABLET)
   ========================================================================== */
@media (max-width: 768px) {
  /* Prevent bounce scrolling and pull-to-refresh on mobile browsers */
  html, body {
    width: 100vw;
    height: 100dvh;
    height: 100vh;
    overflow: hidden;
    overscroll-behavior: none;
    position: fixed;
    inset: 0;
  }

  .room-container {
    width: 100vw;
    height: 100dvh;
    height: 100vh;
    overflow: hidden;
    position: fixed;
    inset: 0;
  }

  /* ------------------------------------------------------------------------
     1. PERFORMANCE HUD — Top Left Floating Badge
     ------------------------------------------------------------------------ */
  .perf-hud {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 8px);
    left: 8px;
    right: auto;
    bottom: auto;
    height: 28px;
    padding: 0 10px;
    font-size: 11px;
    gap: 6px;
    border-radius: var(--radius-pill);
    background-color: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    z-index: var(--z-hud);
    display: flex;
    align-items: center;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
  }

  .perf-hud-item {
    font-size: 10.5px;
    display: flex;
    align-items: center;
    gap: 2px;
  }

  /* ------------------------------------------------------------------------
     2. ONLINE MEMBERS PANEL — Top Right Pill with Overlay Dropdown
     ------------------------------------------------------------------------ */
  .users-panel {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 8px);
    right: 8px;
    left: auto;
    bottom: auto;
    width: auto;
    border: none;
    background: transparent;
    box-shadow: none;
    z-index: var(--z-users);
  }

  .users-panel-header {
    height: 28px;
    padding: 0 10px;
    border-radius: var(--radius-pill);
    background-color: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    font-size: 11px;
    font-weight: 600;
    gap: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
  }

  .users-panel-header:active {
    background-color: var(--surface-2);
    transform: scale(0.97);
  }

  .users-toggle-btn {
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    padding: 0;
    color: var(--text-dim);
  }

  .users-list {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    width: 200px;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-modal);
    max-height: 220px;
    overflow-y: auto;
    z-index: 100;
    padding: 6px 0;
    animation: fadeIn 150ms ease-out;
  }

  /* ------------------------------------------------------------------------
     3. TOOLBAR — Compact Touch-Friendly Strip at Top (Below Status Row)
     ------------------------------------------------------------------------ */
  .toolbar {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 42px);
    bottom: auto;
    left: 8px;
    right: 8px;
    transform: none;
    width: calc(100% - 16px);
    max-width: calc(100vw - 16px);
    height: 48px;
    padding: 0 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    border-radius: var(--radius-pill);
    background-color: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-pop);
    z-index: var(--z-toolbar);
    flex-wrap: nowrap;
    touch-action: pan-x;
  }

  .toolbar::-webkit-scrollbar {
    display: none;
  }

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

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

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

  .size-slider {
    width: 60px;
    height: 5px;
  }

  .size-chip {
    font-size: 10px;
    min-width: 22px;
  }

  .tool-btn {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
  }

  .swatch-btn {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
  }

  .custom-color-btn {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
  }

  .toolbar-divider {
    height: 20px;
    margin: 0 3px;
    flex-shrink: 0;
  }

  /* ------------------------------------------------------------------------
     4. DRAWING CANVAS — Anchored at the Bottom of Phone
     ------------------------------------------------------------------------ */
  #canvas-container {
    position: absolute;
    top: calc(env(safe-area-inset-top, 0px) + 96px);
    bottom: env(safe-area-inset-bottom, 0px);
    left: 0;
    right: 0;
    width: 100%;
    height: calc(100dvh - env(safe-area-inset-top, 0px) - 96px - env(safe-area-inset-bottom, 0px));
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    touch-action: none;
    z-index: var(--z-canvas);
  }

  .canvas-base,
  .canvas-active,
  .canvas-cursor {
    touch-action: none !important;
  }

  /* ------------------------------------------------------------------------
     5. LANDING VIEW & MODALS — Phone Screen Responsiveness
     ------------------------------------------------------------------------ */
  .landing-container {
    min-height: 100dvh;
    padding: calc(env(safe-area-inset-top, 0px) + 16px) 16px calc(env(safe-area-inset-bottom, 0px) + 16px) 16px;
    justify-content: center;
  }

  .landing-top-bar {
    top: calc(env(safe-area-inset-top, 0px) + 14px);
    right: 14px;
  }

  .landing-header {
    margin-bottom: 20px;
  }

  .landing-title {
    font-size: 38px;
  }

  .landing-subtitle {
    font-size: 14px;
  }

  .landing-card {
    padding: 24px 18px;
    width: 100%;
    max-width: 380px;
    border-radius: 20px;
  }

  .input-field {
    font-size: 16px; /* Prevents auto-zoom behavior on iOS Safari */
  }

  .color-picker-modal {
    width: min(320px, calc(100vw - 28px));
    max-height: 86dvh;
    overflow-y: auto;
    padding: 14px;
    gap: 12px;
    border-radius: 18px;
  }

  .cp-satval-container {
    height: 135px;
  }

  .modal-dialog {
    width: min(360px, calc(100vw - 28px));
    padding: 22px 18px;
    border-radius: 18px;
  }

  .toast-container {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
    left: 12px;
    right: 12px;
    width: calc(100vw - 24px);
    max-width: 100vw;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ==========================================================================
   ADVANCED COLOR PICKER MODAL (Reference Redesign)
   ========================================================================== */

.color-picker-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: cpFadeIn 0.15s ease-out;
}

@keyframes cpFadeIn {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}

.color-picker-modal {
  position: relative;
  background: var(--surface);
  width: 310px;
  border-radius: 20px;
  box-shadow: var(--shadow-modal);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border: 1px solid var(--border);
  user-select: none;
}

.cp-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.cp-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}

.cp-close-btn {
  background: none;
  border: none;
  font-size: 16px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}

.cp-close-btn:hover {
  color: var(--text);
  background: var(--surface-2);
}

.cp-satval-container {
  position: relative;
  width: 100%;
  height: 155px;
  border-radius: 12px;
  overflow: hidden;
}

.cp-satval-box {
  width: 100%;
  height: 100%;
  border-radius: 12px;
  position: relative;
  cursor: crosshair;
  background-color: #ff0000;
}

.cp-satval-white {
  position: absolute;
  inset: 0;
  background: linear-gradient(to right, #ffffff, rgba(255, 255, 255, 0));
}

.cp-satval-black {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, #000000, rgba(0, 0, 0, 0));
}

.cp-satval-handle {
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 3px solid #ffffff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
  transform: translate(-50%, -50%);
  pointer-events: none;
  left: 100%;
  top: 0%;
}

.cp-sliders-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cp-eyedropper-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}

.cp-eyedropper-btn:hover {
  background: var(--border);
}

.cp-sliders-bars {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cp-slider-track {
  width: 100%;
  height: 12px;
  border-radius: 6px;
  position: relative;
  cursor: pointer;
}

.cp-hue-track {
  background: linear-gradient(
    to right,
    #ff0000 0%,
    #ffff00 17%,
    #00ff00 33%,
    #00ffff 50%,
    #0000ff 67%,
    #ff00ff 83%,
    #ff0000 100%
  );
}

.cp-alpha-track {
  background-image:
    linear-gradient(45deg, #ccc 25%, transparent 25%),
    linear-gradient(-45deg, #ccc 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ccc 75%),
    linear-gradient(-45deg, transparent 75%, #ccc 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
  position: relative;
  overflow: hidden;
}

.cp-alpha-gradient {
  position: absolute;
  inset: 0;
  border-radius: 6px;
}

.cp-slider-handle {
  position: absolute;
  top: 50%;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
  transform: translate(-50%, -50%);
  pointer-events: none;
  left: 0%;
}

.cp-inputs-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cp-mode-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s;
}

.cp-mode-btn:hover {
  background: var(--border);
}

.cp-values-boxes {
  flex: 1;
}

.cp-input-group {
  display: flex;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
}

.cp-input {
  flex: 1;
  min-width: 0;
  border: none;
  border-right: 1px solid var(--border);
  background: transparent;
  text-align: center;
  font-size: 12px;
  padding: 6px 2px;
  color: var(--text);
  font-family: var(--font-mono);
  -moz-appearance: textfield;
}

.cp-input::-webkit-outer-spin-button,
.cp-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.cp-input:last-child {
  border-right: none;
}

.cp-alpha-box {
  display: flex;
  align-items: center;
  flex: 1.2;
  padding-right: 4px;
}

.cp-unit {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

.cp-saved-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cp-saved-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.cp-saved-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.cp-add-saved-btn {
  background: none;
  border: none;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-dim);
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}

.cp-add-saved-btn:hover {
  color: var(--text);
  background: var(--surface-2);
}

.cp-saved-list {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  align-items: center;
}

.cp-saved-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.1);
  cursor: pointer;
  position: relative;
  transition: transform 0.1s;
}

.cp-saved-swatch:hover {
  transform: scale(1.15);
}

.cp-swatch-active {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent) !important;
  transform: scale(1.1);
}

/* Custom color trigger button in toolbar */
.custom-color-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 0;
  transition: transform 0.15s, border-color 0.15s;
}

.custom-color-btn:hover {
  transform: scale(1.15);
  border-color: var(--accent);
}

.custom-color-icon {
  width: 14px;
  height: 14px;
  color: #ffffff;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.7));
}

