:root {
  color-scheme: light;
  --bg: #f6f6f6;
  --panel: #ffffff;
  --shell: #cfcfcf;
  --ink: #111111;
  --muted: #6b6b6b;
  --accent: #7939e4;
  --radius: 28px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.28);
}

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

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Space Grotesk", "Trebuchet MS", sans-serif;
  overflow: hidden;
}

.app {
  position: relative;
  width: 100%;
  height: 100%;
}

.canvas-shell {
  position: absolute;
  inset: 0;
  background: var(--shell);
  overflow: hidden;
}

#view {
  width: 100%;
  height: 100%;
  display: block;
  background: var(--shell);
  cursor: crosshair;
  touch-action: none;
}

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

.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  background: rgba(246, 246, 246, 0.82);
  backdrop-filter: blur(2px);
  z-index: 2;
  pointer-events: auto;
  user-select: none;
  transition: opacity 0.2s ease;
}

.loading-overlay.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.connection-status {
  position: absolute;
  top: 20px;
  left: 20px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 16px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
  z-index: 3;
  font-size: 0.9rem;
}

.connection-text {
  font-weight: 600;
  color: var(--ink);
}

.connection-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #f1c40f;
  box-shadow: 0 0 0 3px rgba(241, 196, 15, 0.25);
}

.connection-status[data-state="failed"] .connection-dot {
  background: #e74c3c;
  box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.25);
}

.connection-status[data-state="connecting"] .connection-dot,
.connection-status[data-state="reconnecting"] .connection-dot {
  animation: pulse 1.2s ease-in-out infinite;
}

.connection-action {
  border: none;
  background: var(--ink);
  color: #ffffff;
  padding: 6px 12px;
  border-radius: 10px;
  font: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.connection-action:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.18);
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.25);
  }
  100% {
    transform: scale(1);
  }
}

.remote-cursor {
  position: absolute;
  left: 0;
  top: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--cursor-color, var(--accent));
  transform: translate(-6px, -6px);
  will-change: transform;
}

.remote-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9);
}

.remote-label {
  background: #ffffff;
  color: currentColor;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  border: 1px solid currentColor;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.18);
}

.cursor-layer.hide-labels .remote-label {
  display: none;
}

.cursor-layer.hide-labels .remote-cursor {
  gap: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  flex-wrap: wrap;
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: calc(100% - 40px);
  justify-content: center;
  z-index: 2;
}

.mobile-toolbar {
  display: none;
}

.desktop-toolbar {
  width: max-content;
}

.desktop-toolbar > * {
  flex-shrink: 0;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: #f3f3f3;
  border-radius: 999px;
}

.tool-label {
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.tool-value {
  font-weight: 600;
}

#brushValue {
  display: inline-block;
  width: 5ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#brushSize {
  accent-color: var(--accent);
}

.brush-size-input {
  width: 74px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 12px;
  padding: 6px 8px;
  font: inherit;
  font-weight: 600;
  text-align: center;
  background: #ffffff;
}

#brushColor {
  width: 38px;
  height: 38px;
  border: none;
  padding: 0;
  background: none;
}

.color-trigger {
  border: none;
  font: inherit;
  cursor: pointer;
}

.color-trigger:hover {
  transform: translateY(-1px);
}

.color-preview {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  border: 2px solid rgba(0, 0, 0, 0.15);
  background: var(--color-preview, #111111);
}

.swatches {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  border: 2px solid rgba(0, 0, 0, 0.12);
  background: var(--swatch-color);
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.swatch:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.12);
}

.swatch.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(121, 57, 228, 0.25);
}

.swatch.is-empty {
  border-style: dashed;
  border-color: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  background: transparent;
  cursor: default;
  box-shadow: none;
}

.swatch.is-empty:hover {
  transform: none;
  box-shadow: none;
}

.icon-button {
  width: 48px;
  height: 48px;
  border-radius: 18px;
  border: none;
  background: #f3f3f3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.icon-button svg {
  width: 26px;
  height: 26px;
  fill: currentColor;
}

.icon-button[aria-pressed="true"] {
  color: var(--accent);
}

.icon-button:hover {
  transform: translateY(-1px);
}

.settings-dialog {
  border: none;
  padding: 0;
  background: transparent;
  max-width: 90vw;
  overflow-x: hidden;
}

.settings-dialog::backdrop {
  background: rgba(17, 17, 17, 0.4);
}

.settings-panel {
  /* min-width: 360px; */
  max-width: 520px;
  background: var(--panel);
  border-radius: 28px;
  padding: 20px;
}

.color-dialog .settings-panel {
  min-width: 320px;
  max-width: 460px;
}

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

.settings-title {
  font-size: 1.2rem;
  font-weight: 700;
}

.settings-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.settings-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  padding: 14px 16px;
  background: #f3f3f3;
  border-radius: 18px;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

.settings-label {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
  background: #f3f3f3;
  border-radius: 18px;
}

.settings-input {
  width: 100%;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  background: #ffffff;
  color: var(--ink);
}

.settings-input:focus {
  outline: 2px solid rgba(121, 57, 228, 0.5);
  outline-offset: 1px;
}

.color-picker-field {
  gap: 10px;
}

#mobileBrushColor {
  width: 100%;
  height: 44px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 12px;
  padding: 0;
  background: #ffffff;
}

.settings-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: inherit;
}

.settings-icon svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.settings-action[aria-pressed="true"] {
  color: var(--accent);
}

.settings-action:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.12);
}

.settings-action:focus-visible {
  outline: 2px solid rgba(121, 57, 228, 0.5);
  outline-offset: 2px;
}

.tool-hint {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.85rem;
}

@media (max-width: 720px) {
  .tool-hint {
    width: 100%;
    margin-left: 0;
  }

  .connection-status {
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 32px);
    justify-content: center;
    text-align: center;
  }

  .desktop-toolbar {
    display: none;
  }

  .mobile-toolbar {
    display: flex;
  }

  .mobile-toolbar {
    width: calc(100% - 20px);
    max-width: none;
    bottom: 10px;
    padding: 10px;
    gap: 10px;
    border-radius: 18px;
  }

  .mobile-toolbar .tool-group {
    flex: 1 1 auto;
    justify-content: center;
  }

  .color-trigger {
    min-width: 130px;
  }

}
