/* ─── Design Tokens ──────────────────────────────────────── */
:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-surface: rgba(255, 255, 255, 0.04);
  --bg-surface-hover: rgba(255, 255, 255, 0.08);
  --bg-glass: rgba(18, 18, 26, 0.75);
  --bg-glass-strong: rgba(18, 18, 26, 0.92);

  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-medium: rgba(255, 255, 255, 0.1);
  --border-accent: rgba(168, 85, 247, 0.4);

  --text-primary: #f0f0f5;
  --text-secondary: #8b8b9e;
  --text-muted: #5a5a6e;

  --accent-purple: #a855f7;
  --accent-pink: #ec4899;
  --accent-blue: #3b82f6;
  --accent-gradient: linear-gradient(135deg, #a855f7 0%, #ec4899 50%, #f97316 100%);
  --accent-gradient-subtle: linear-gradient(135deg, rgba(168,85,247,0.15) 0%, rgba(236,72,153,0.15) 100%);

  --danger: #ef4444;
  --success: #22c55e;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 20px rgba(168,85,247,0.2);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);

  --toolbar-height: 56px;
}

/* ─── Reset ──────────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  font-size: inherit;
}

input {
  font-family: inherit;
  color: inherit;
  border: none;
  background: none;
  outline: none;
}

/* ─── Screen Transitions ─────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
  transform: scale(0.97);
}

.screen.active {
  opacity: 1;
  pointer-events: all;
  transform: scale(1);
}

/* ─── Lobby ──────────────────────────────────────────────── */
.lobby-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  max-width: 440px;
  width: 100%;
  padding: 24px;
}

.lobby-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 72px;
  height: 72px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-8px) rotate(3deg); }
}

.lobby-header h1 {
  font-size: 2.4rem;
  font-weight: 800;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
  max-width: 320px;
}

.lobby-card {
  width: 100%;
  background: var(--bg-glass-strong);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-xl);
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  box-shadow: var(--shadow-lg), var(--shadow-glow);
}

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

.input-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.input-group input,
.join-group input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  color: var(--text-primary);
  transition: var(--transition);
}

.input-group input:focus,
.join-group input:focus {
  border-color: var(--accent-purple);
  box-shadow: 0 0 0 3px rgba(168,85,247,0.15);
  background: var(--bg-surface-hover);
}

.input-group input::placeholder,
.join-group input::placeholder {
  color: var(--text-muted);
}

.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  transition: var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 4px 16px rgba(168,85,247,0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(168,85,247,0.45);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  color: var(--text-primary);
  padding: 12px 20px;
}

.btn-secondary:hover {
  background: var(--bg-surface-hover);
  border-color: var(--accent-purple);
}

.btn-ghost {
  color: var(--text-secondary);
  padding: 8px 16px;
  font-size: 0.85rem;
}

.btn-ghost:hover {
  color: var(--text-primary);
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 0.8rem;
}

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

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

.join-group input {
  flex: 1;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-weight: 600;
}

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  text-align: center;
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* ─── Toolbar ────────────────────────────────────────────── */
.toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--toolbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-glass-strong);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 100;
  gap: 12px;
}

.toolbar-section {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-left {
  min-width: 180px;
}

.toolbar-right {
  min-width: 180px;
  justify-content: flex-end;
}

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

.room-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.room-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.room-code {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent-purple);
  letter-spacing: 0.1em;
  background: rgba(168,85,247,0.1);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
}

.user-count {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: var(--transition);
}

.icon-btn:hover {
  color: var(--text-primary);
  background: var(--bg-surface-hover);
}

.icon-btn-danger:hover {
  color: var(--danger);
  background: rgba(239,68,68,0.1);
}

/* ─── Tool Buttons ───────────────────────────────────────── */
.tool-group {
  display: flex;
  gap: 2px;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  padding: 3px;
}

.tool-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: var(--transition);
  position: relative;
}

.tool-btn:hover {
  color: var(--text-primary);
  background: var(--bg-surface-hover);
}

.tool-btn.active {
  color: var(--accent-purple);
  background: rgba(168,85,247,0.12);
  box-shadow: inset 0 0 0 1px rgba(168,85,247,0.3);
}

/* ─── Color Picker ───────────────────────────────────────── */
.color-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-presets {
  display: flex;
  gap: 4px;
}

.color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: var(--transition);
  cursor: pointer;
  position: relative;
}

.color-swatch:hover {
  transform: scale(1.2);
}

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

#color-picker {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  background: none;
  padding: 0;
  overflow: hidden;
}

#color-picker::-webkit-color-swatch-wrapper {
  padding: 0;
}

#color-picker::-webkit-color-swatch {
  border: 2px solid var(--border-medium);
  border-radius: 50%;
}

/* ─── Brush Size ─────────────────────────────────────────── */
.size-group {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
}

#brush-size {
  width: 90px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border-medium);
  border-radius: 2px;
  outline: none;
}

#brush-size::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: var(--accent-purple);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 8px rgba(168,85,247,0.4);
  transition: var(--transition);
}

#brush-size::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 14px rgba(168,85,247,0.6);
}

.size-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 32px;
}

/* ─── Canvas ─────────────────────────────────────────────── */
.canvas-wrapper {
  position: fixed;
  top: var(--toolbar-height);
  left: 0;
  right: 0;
  bottom: 0;
  background: #1a1a2e;
  overflow: hidden;
}

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

#canvas-bg {
  z-index: 1;
}

#canvas-active {
  z-index: 2;
}

.cursors-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

/* ─── Remote Cursor ──────────────────────────────────────── */
.remote-cursor {
  position: absolute;
  pointer-events: none;
  transition: left 0.08s linear, top 0.08s linear;
  z-index: 50;
}

.remote-cursor-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,0.3);
  box-shadow: 0 0 6px rgba(0,0,0,0.3);
  transform: translate(-50%, -50%);
}

.remote-cursor-label {
  position: absolute;
  top: 10px;
  left: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
  padding: 2px 6px;
  border-radius: 4px;
  color: #fff;
  opacity: 0.85;
}

/* ─── Users Panel ────────────────────────────────────────── */
.users-panel {
  position: fixed;
  top: calc(var(--toolbar-height) + 12px);
  right: 12px;
  width: 180px;
  background: var(--bg-glass-strong);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  z-index: 90;
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.users-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-subtle);
}

.badge {
  background: var(--accent-gradient-subtle);
  color: var(--accent-purple);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
}

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

.users-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  animation: fadeIn 0.3s ease;
}

.users-list li:hover {
  background: var(--bg-surface);
}

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

.user-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-you {
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 400;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateX(8px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ─── Toast ──────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--bg-glass-strong);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 18px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
  pointer-events: all;
  animation: toastIn 0.3s ease forwards;
  white-space: nowrap;
}

.toast.leaving {
  animation: toastOut 0.3s ease forwards;
}

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

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

/* ─── Confirm Dialog / Overlay ───────────────────────────── */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeInOverlay 0.2s ease;
}

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

.confirm-dialog {
  background: var(--bg-glass-strong);
  backdrop-filter: blur(24px);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 320px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: dialogIn 0.25s ease;
}

@keyframes dialogIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.confirm-dialog h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.confirm-dialog p {
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin-bottom: 22px;
}

.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.confirm-actions .btn {
  min-width: 100px;
  padding: 10px 20px;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: #dc2626;
}

/* ─── Scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: 3px;
}

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 900px) {
  .toolbar {
    gap: 6px;
    padding: 0 8px;
  }

  .toolbar-left {
    min-width: auto;
  }

  .toolbar-right {
    min-width: auto;
  }

  .color-presets {
    display: none;
  }

  #color-picker {
    width: 32px;
    height: 32px;
  }

  .size-group {
    display: none;
  }

  .users-panel {
    display: none;
  }
}

@media (max-width: 600px) {
  .toolbar-divider {
    display: none;
  }

  .room-info .room-label {
    display: none;
  }

  #leave-btn {
    display: none;
  }
}
