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

:root {
  --bg-primary: #ffffff;
  --bg-canvas: #f5f5f5;
  --bg-sidebar: #ffffff;
  --bg-hover: rgba(0, 0, 0, 0.05);
  --bg-active: #e3e3e3;
  --text-primary: #1b1b1f;
  --text-secondary: #8b8b8b;
  --border-color: #e0e0e0;
  --border-strong: #ccc;
  --accent: #6965db;
  --accent-hover: #5a57c9;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
  --sidebar-width: 56px;
  --topbar-height: 44px;
  --bottombar-height: 44px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --transition: 120ms ease;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-canvas);
  -webkit-font-smoothing: antialiased;
}

#app {
  width: 100%;
  height: 100%;
  display: flex;
  position: relative;
}

.welcome-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.welcome-modal-overlay.hidden {
  display: none;
}

.welcome-modal {
  background: white;
  border-radius: 12px;
  padding: 40px 48px;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}

.welcome-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.welcome-subtitle {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 28px;
}

.welcome-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.welcome-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 120ms ease;
}

.welcome-btn.primary {
  background: var(--accent);
  color: white;
}

.welcome-btn.primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(105, 101, 219, 0.3);
}

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

.welcome-btn.secondary:hover {
  background: var(--bg-active);
}

.welcome-storage-note {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100%;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 4px;
  z-index: 10;
  user-select: none;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
}

.sidebar-divider {
  width: 32px;
  height: 1px;
  background: var(--border-color);
  margin: 6px 0;
}

.sidebar-section.bottom-actions {
  margin-top: auto;
}

.tool-btn {
  width: 42px;
  height: 42px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  position: relative;
  color: var(--text-primary);
}

.tool-btn svg {
  width: 22px;
  height: 22px;
}

.tool-btn:hover {
  background: var(--bg-hover);
}

.tool-btn.active {
  background: var(--bg-active);
}

.tool-btn.active:hover {
  background: #ddd;
}

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

.tool-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.tool-btn-small {
  width: 34px;
  height: 34px;
  border: none;
  background: rgba(255, 255, 255, 0.9);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  color: var(--text-primary);
  backdrop-filter: blur(8px);
}

.tool-btn-small:hover {
  background: white;
}

.color-section {
  position: relative;
  padding: 8px 0;
}

.color-swatch {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: 2px solid var(--border-color);
  cursor: pointer;
  padding: 0;
  background: none;
  transition: border-color 150ms ease, transform 100ms ease;
}

.color-swatch:hover {
  border-color: var(--border-strong);
  transform: scale(1.05);
}

.color-swatch-inner {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 4px;
}

.color-popover {
  position: absolute;
  left: 50px;
  top: 0;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  z-index: 200;
  display: none;
  min-width: 168px;
}

.color-popover.open {
  display: block;
}

.color-presets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  margin-bottom: 8px;
}

.color-opt {
  width: 34px;
  height: 34px;
  border-radius: 4px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 100ms ease, border-color 100ms ease;
  padding: 0;
}

.color-opt:hover {
  transform: scale(1.15);
  border-color: var(--border-strong);
}

.color-opt.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px white, 0 0 0 3px var(--accent);
  transform: scale(1.1);
}

.color-custom {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-color);
}

.color-custom input[type="color"] {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  padding: 0;
  background: none;
}

.color-custom input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-custom input[type="color"]::-webkit-color-swatch {
  border: 1px solid var(--border-color);
  border-radius: 6px;
}

.color-hex {
  font-size: 12px;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  color: var(--text-secondary);
}

.stroke-width-wrap {
  padding: 6px 4px;
}

.stroke-width-wrap input[type="range"] {
  writing-mode: vertical-lr;
  direction: rtl;
  width: 28px;
  height: 80px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}

.stroke-width-wrap input[type="range"]::-webkit-slider-runnable-track {
  width: 4px;
  height: 100%;
  background: var(--border-color);
  border-radius: 2px;
}

.stroke-width-wrap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-primary);
  border: 2px solid var(--bg-sidebar);
  box-shadow: var(--shadow-sm);
  margin-left: -5px;
}

.canvas-area {
  flex: 1;
  height: 100%;
  position: relative;
  overflow: hidden;
  background-color: var(--bg-canvas);
  background-image: radial-gradient(circle, #d0d0d0 0.8px, transparent 0.8px);
  background-size: 20px 20px;
}

#whiteboard {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: transparent;
  pointer-events: none;
  z-index: 20;
}

.topbar > * {
  pointer-events: auto;
}

.logo {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: -0.3px;
  background: rgba(255,255,255,0.9);
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.participants {
  position: relative;
}

.participants-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
  transition: background 150ms ease;
}

.participants-toggle:hover {
  background: white;
}

.participants-list {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 8px;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 8px;
  min-width: 160px;
  box-shadow: var(--shadow-md);
  display: none;
}

.participants-list.open {
  display: block;
}

.participant-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 13px;
}

.participant-item:hover {
  background: var(--bg-hover);
}

.participant-color {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.online-count {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--text-secondary);
  background: rgba(255,255,255,0.9);
  padding: 5px 10px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  backdrop-filter: blur(8px);
}

.online-count.hidden {
  display: none;
}

.share-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.share-btn:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 12px rgba(105, 101, 219, 0.25);
}

.bottombar {
  position: fixed;
  bottom: 0;
  left: var(--sidebar-width);
  right: 0;
  height: var(--bottombar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  pointer-events: none;
  z-index: 20;
}

.bottombar > * {
  pointer-events: auto;
}

.bottom-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bottom-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 2px;
  background: rgba(255,255,255,0.95);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 3px;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-sm);
}

.zoom-controls button {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  transition: background var(--transition);
}

.zoom-controls button:hover {
  background: var(--bg-hover);
}

.zoom-controls button:active {
  background: var(--bg-active);
}

.zoom-controls span {
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 42px;
  text-align: center;
  user-select: none;
  font-weight: 500;
}

.action-btn-group {
  display: flex;
  align-items: center;
  gap: 2px;
  background: rgba(255,255,255,0.95);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 3px;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-sm);
}

.action-btn-group button {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  transition: background var(--transition);
}

.action-btn-group button:hover {
  background: var(--bg-hover);
}

.action-btn-group button:active {
  background: var(--bg-active);
}

.action-btn-group button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.fill-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.95);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 3px;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-sm);
}

.fill-toggle button {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  transition: background var(--transition);
}

.fill-toggle button:hover {
  background: var(--bg-hover);
}

.fill-toggle button.active {
  background: var(--accent);
  color: white;
}

.shortcut-hint {
  font-size: 11px;
  color: var(--text-secondary);
  background: rgba(255,255,255,0.95);
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.remote-cursor {
  position: fixed;
  pointer-events: none;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: transform 60ms linear;
}

.remote-cursor svg {
  width: 20px;
  height: 24px;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.35));
}

.remote-cursor .cursor-label {
  font-size: 13px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 5px;
  white-space: nowrap;
  color: white;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  text-shadow: 0 1px 2px rgba(0,0,0,0.35);
  letter-spacing: 0.01em;
}

.cursor-tip-ring {
  position: fixed;
  pointer-events: none;
  z-index: 99;
  border-radius: 50%;
  opacity: 0.5;
  display: none;
}

.tooltip {
  position: fixed;
  z-index: 1000;
  background: #1b1b1f;
  color: white;
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 4px;
  pointer-events: none;
  opacity: 0;
  transform: translateX(8px);
  transition: opacity 120ms ease, transform 120ms ease;
  white-space: nowrap;
  font-weight: 450;
}

.tooltip.visible {
  opacity: 1;
  transform: translateX(0);
}

.tooltip::before {
  content: '';
  position: absolute;
  left: -4px;
  top: 50%;
  transform: translateY(-50%);
  border: 4px solid transparent;
  border-right-color: #1b1b1f;
}

.text-input {
  position: fixed;
  z-index: 150;
  min-width: 10px;
  min-height: 20px;
  outline: none;
  background: transparent;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.2;
  word-break: break-word;
  white-space: pre-wrap;
  border-bottom: 2px solid var(--accent);
  padding: 2px 4px;
}

.eraser-circle {
  position: fixed;
  pointer-events: none;
  z-index: 100;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.08);
  border: 2.5px solid rgba(0, 0, 0, 0.35);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.4) inset;
  display: none;
}

/* Name dialog */
.name-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.name-modal-overlay.hidden {
  display: none;
}

.name-modal {
  background: white;
  border-radius: 12px;
  padding: 36px 40px;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}

.name-modal h2 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.name-modal p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.name-input-group {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.name-input-group input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 150ms ease;
  color: var(--text-primary);
}

.name-input-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(105, 101, 219, 0.15);
}

.name-input-group button {
  padding: 10px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 150ms ease;
}

.name-input-group button:hover {
  background: var(--accent-hover);
}

.name-hint {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 0 !important;
}

/* Pen preview circle */
.pen-preview {
  position: fixed;
  pointer-events: none;
  z-index: 100;
  border-radius: 50%;
  display: none;
}

/* Self cursor */
.self-cursor {
  position: fixed;
  pointer-events: none;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0;
  transition: opacity 150ms ease;
}

.self-cursor.visible {
  opacity: 1;
}

.self-cursor-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2.5px solid white;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.self-cursor-name {
  font-size: 13px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 5px;
  white-space: nowrap;
  color: white;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  text-shadow: 0 1px 2px rgba(0,0,0,0.35);
}

/* Bottom stroke slider */
.stroke-slider-wrap {
  display: none;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.95);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 3px 8px;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-sm);
}

.stroke-slider-wrap.visible {
  display: flex;
}

.stroke-slider-wrap input[type="range"] {
  width: 64px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border-color);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.stroke-slider-wrap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-primary);
  border: 2px solid white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}

.stroke-slider-val {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  min-width: 14px;
  text-align: center;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
}

/* Loading overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 999;
  gap: 16px;
}

.loading-overlay.hidden {
  display: none;
}

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

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

.loading-text {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 450;
}

/* Disconnect toast */
.disconnect-toast {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: #e03131;
  color: white;
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  z-index: 9999;
  box-shadow: 0 4px 16px rgba(224, 49, 49, 0.35);
  animation: toastIn 0.3s ease;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
