:root {
  --bg: #2b2b2b;
  --ui-bg: #333333;
  --bg-panel: #333333;
  --bg-button: #333333;
  --bg-input: #333333;
  --ui-border: rgba(255, 255, 255, 0.08);
  --ui-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --text: #f4f4f5;
  --text-muted: #a1a1aa;
  --accent: #60a5fa;
  --accent-glow: rgba(96, 165, 250, 0.3);
  --radius: 14px;
  --canvas-bg: #2b2b2b;
  --grid-line-base: 255, 255, 255;
  --scrollbar-thumb: rgba(255, 255, 255, 0.2);
  --scrollbar-track: transparent;
  --cooldown-bg: rgba(255, 255, 255, 0.1);
}

[data-theme="light"] {
  --bg: #ffffff;
  --ui-bg: rgba(255, 255, 255, 0.92);
  --ui-border: rgba(0, 0, 0, 0.08);
  --bg-panel: #e0e0e0;
  --bg-button: #e0e0e0;
  --bg-input: #e0e0e0;
  --ui-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
  --text: #2b2b2b;
  --text-muted: #71717a;
  --accent: #60a5fa;
  --accent-glow: rgba(59, 130, 246, 0.3);
  --canvas-bg: #ffffff;
  --grid-line-base: 0, 0, 0;
  --scrollbar-thumb: rgba(0, 0, 0, 0.2);
  --scrollbar-track: transparent;
  --cooldown-bg: rgba(0, 0, 0, 0.1);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--text);
  transform: none !important;
  touch-action: none;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

body.js-loading .user-overlays-toggle {
  opacity: 0 !important;
  pointer-events: none !important;
  transition: opacity 0.2s ease !important;
}

#canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  cursor: crosshair;
}

.ui-panel, #palette, #toolbar, #coords, #share-btn, #theme-toggle, button, .color-swatch, input, #overlay-controls, #counters-container {
    touch-action: manipulation;
}

canvas, #controls-drag-handle {
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.ui-panel {
  background: var(--bg-panel) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  border: 1px solid var(--ui-border);
  border-radius: var(--radius);
  box-shadow: var(--ui-shadow);
  z-index: 1;
}

#users-online {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  background: var(--bg-panel) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  border: 1px solid var(--ui-border) !important;
  border-radius: var(--radius);
}

.online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
  animation: pulse 2s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }
}

.share-btn,
#coords {
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
  background: var(--bg-panel) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  border: 1px solid var(--ui-border) !important;
  border-radius: var(--radius);
}

.share-btn:hover,
#coords:hover {
  border-color: var(--accent) !important;
  box-shadow: var(--ui-shadow), 0 0 0 1px var(--accent) !important;
}

#share-btn.copied,
#share-btn.copied:hover,
#coords.copied,
#coords.copied:hover,
#account-btn.copied,
#account-btn.copied:hover {
  border-color: #22c55e !important;
  box-shadow: 0 0 0 1px #22c55e, 0 0 12px rgba(34, 197, 94, 0.5) !important;
}

.share-btn svg {
  opacity: 0.7;
}

#palette {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) !important;
  contain: layout style !important;
  isolation: isolate;

  height: 190px;
  padding: 14px 20px 18px 20px;

  display: flex;
  flex-direction: column;
  align-items: flex-start;

  max-width: calc(100vw - 140px);
  min-width: 200px;

  overflow-x: auto;
  overflow-y: hidden;

  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;

  background: var(--bg-panel) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  border: 1px solid var(--ui-border) !important;
  border-radius: var(--radius);
  z-index: 1;
}

#palette::-webkit-scrollbar {
  height: 6px;
}

#palette::-webkit-scrollbar-track {
  background: transparent;
}

#palette::-webkit-scrollbar-thumb {
  background-color: var(--scrollbar-thumb);
  border-radius: 3px;
}

#palette::-webkit-scrollbar-thumb:hover {
  background-color: var(--scrollbar-thumb);
  opacity: 0.8;
}

.main-colors-row,
.custom-colors-row {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;

  gap: 8px !important;

  margin: 0 0 8px 0 !important;
  padding: 0 !important;
}

#recent-colors-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 !important;
  padding: 0 !important;
}

#recent-colors-row .color-swatch {
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

#recent-colors-row .color-swatch.active,
#recent-colors-row .eraser-swatch.active,
#recent-colors-row .eyedropper-swatch.active,
#recent-colors-row .image-tool-swatch.active,
#recent-colors-row .user-overlays-toggle.active {
  position: relative !important;
  z-index: 10 !important;
  border: 1px solid var(--text) !important;
  box-shadow: 0 0 0 1px var(--text), 0 0 14px rgba(var(--grid-line-base), 0.85) !important;
  transform: scale(1.2) translateY(-3px) !important;
  transition: box-shadow 0.2s ease, border-color 0.2s ease, transform 0.2s ease !important;
}

[data-theme="light"] #recent-colors-row .color-swatch {
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

#recent-colors-row .color-swatch:not([data-color]) {
  background: rgba(255, 255, 255, 0.03);
  border: 2px dashed rgba(255, 255, 255, 0.1);
  cursor: default;
}

[data-theme="light"] #recent-colors-row .color-swatch:not([data-color]) {
  background: rgba(238, 28, 28, 0.04);
  border: 2px dashed rgba(0, 0, 0, 0.12);
}

#recent-colors-row .color-swatch:not([data-color]).active {
  border: 2px dashed rgba(255, 255, 255, 0.1) !important;
  box-shadow: none !important;
  transform: none !important;
}

.recent-edit-btn {
  position: absolute;
  top: -8px;
  left: -8px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--ui-bg);
  color: var(--text);
  border: 1.5px solid var(--ui-border);
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding-bottom: 3px;
  cursor: pointer;
  opacity: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  transition: opacity 0.2s ease, background 0.2s ease, color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
  z-index: 3;
  pointer-events: auto;
}

.color-swatch[data-color]:hover .recent-edit-btn {
  opacity: 1;
}

.color-swatch[data-color] .recent-edit-btn:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transform: scale(1.5);
}

[data-theme="dark"] .color-swatch[data-color] .recent-edit-btn {
  background: rgba(30, 30, 35, 1);
  border-color: rgba(255, 255, 255, 0.15);
}

.color-swatch:not([data-color]) .recent-edit-btn {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 10px;
  background: transparent;
  border: none;
  box-shadow: none;
  opacity: 0.4;
  font-size: 24px;
  font-weight: 400;
  color: var(--text-muted);
  padding-bottom: 5px;
  transition: opacity 0.2s ease, color 0.2s ease;
}

.color-swatch:not([data-color]):hover .recent-edit-btn {
  opacity: 1;
  color: var(--accent);
}

@property --progress {
  syntax: '<number>';
  initial-value: 1;
  inherits: true;
}

@property --ring-color {
  syntax: '<color>';
  initial-value: hsl(0, 90%, 55%);
  inherits: true;
}

#cooldown-container {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 60px;
  --ring-color: hsl(calc((1 - var(--progress, 1)) * 120), 90%, 55%);
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), bottom 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  z-index: 99;
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.5),
    0 0 12px var(--ring-color),
    0 0 24px var(--ring-color),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

#cooldown-ring {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: conic-gradient(var(--ring-color) 0deg,
      var(--ring-color) calc(var(--progress, 1) * 360deg),
      rgba(255, 255, 255, 0.08) calc(var(--progress, 1) * 360deg),
      rgba(255, 255, 255, 0.08) 360deg);
  mask: radial-gradient(circle at center, transparent 58%, black 60%);
  -webkit-mask: radial-gradient(circle at center, transparent 58%, black 60%);
}

#cooldown-content {
  position: relative;
  z-index: 2;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}

#cooldown-number {
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
  text-shadow: 0 0 8px var(--ring-color);
  transition: transform 0.1s ease-out, opacity 0.1s ease-out;
  will-change: transform, opacity;
  line-height: 1;
}

#cooldown-label {
  color: var(--text-muted);
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  opacity: 0.8;
  line-height: 1;
}

[data-theme="light"] #cooldown-container {
  background: rgba(255, 255, 255, 0.95);
  border: 1.5px solid rgba(0, 0, 0, 0.08);
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.15),
    0 0 12px var(--ring-color),
    0 0 24px var(--ring-color),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

[data-theme="light"] #cooldown-ring {
  background: conic-gradient(var(--ring-color) 0deg,
      var(--ring-color) calc(var(--progress, 1) * 360deg),
      rgba(0, 0, 0, 0.06) calc(var(--progress, 1) * 360deg),
      rgba(0, 0, 0, 0.06) 360deg);
}

#theme-toggle {
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  cursor: pointer;
  background: var(--bg-panel) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  border: 1px solid var(--ui-border) !important;
  border-radius: var(--radius);
  transition: all 0.3s ease;
}

#theme-toggle svg {
  transition: transform 0.3s ease;
}

#theme-toggle:hover svg {
  transform: rotate(15deg);
}

.add-custom-btn {
  background: var(--ui-bg);
  color: var(--text);
  border: 1px solid var(--ui-border) !important;
  cursor: pointer;
}

.add-custom-btn:hover {
  background: var(--accent);
  color: white;
  transform: translateY(-3px) scale(1.08);
}

[data-theme="light"] .add-custom-btn:hover {
  color: var(--text);
}

.clr-picker {
  overflow: visible !important;
  clip: auto !important;
  clip-path: none !important;
}

.clr-picker .clr-arrow,
.clr-picker::before,
.clr-picker::after {
  display: none !important;
}

.clr-field input,
.clr-color-value,
.clr-color {
  background: var(--bg) !important;
  color: var(--text) !important;
  border: 1px solid var(--ui-border) !important;
  border-radius: 6px !important;
  font-family: 'Inter', system-ui, sans-serif !important;
}

[data-theme="dark"] .clr-picker {
  background: #222222 !important;
  border-color: rgba(255, 255, 255, 0.12) !important;
}

[data-theme="dark"] .clr-arrow {
  border-top-color: #222222 !important;
}

[data-theme="dark"] .clr-field input,
[data-theme="dark"] .clr-color-value,
[data-theme="dark"] .clr-color {
  background: #18181b !important;
  border-color: rgba(255, 255, 255, 0.12) !important;
  color: #f4f4f5 !important;
}

[data-theme="dark"] .clr-swatches button {
  background: #18181b !important;
  border-color: rgba(255, 255, 255, 0.12) !important;
}

[data-theme="light"] .clr-picker {
  background: #ffffff !important;
  border-color: rgba(0, 0, 0, 0.08) !important;
}

[data-theme="light"] .clr-arrow {
  border-top-color: #ffffff !important;
}

[data-theme="light"] .clr-field input,
[data-theme="light"] .clr-color-value,
[data-theme="light"] .clr-color {
  background: #ffffff !important;
  border-color: rgba(0, 0, 0, 0.08) !important;
  color: #18181b !important;
}

input[type="color"][style*="opacity: 0"] {
  position: fixed !important;
}

#top-bar {
  position: absolute;
  top: 20px;
  left: 20px;
  right: 20px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  pointer-events: none;
  z-index: 100;
}

#top-bar>* {
  pointer-events: auto;
}

#coords,
#users-online,
#share-btn,
#theme-toggle,
#account-btn {
  font-family: 'Inter', system-ui, -apple-system, sans-serif !important;
  font-size: 13px !important;
  font-weight: 500 !important;
  color: var(--text-muted) !important;
  line-height: 1.4 !important;
  padding: 8px 14px !important;
  min-height: 36px !important;
  display: flex !important;
  align-items: center !important;
  box-sizing: border-box !important;
  border-radius: var(--radius) !important;
  margin: 0 !important;
  background: var(--bg-panel) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  border: 1px solid var(--ui-border) !important;
}

#top-center-controls {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
}

#coords {
  justify-self: start !important;
  width: fit-content !important;
  font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace !important;
  font-size: 12px !important;
  font-weight: 500 !important;
}

#coords #coord-x,
#coords #coord-y {
  font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace !important;
  font-size: 12px !important;
  font-weight: 500 !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
  min-width: 0 !important;
  flex: 1 1 auto !important;
}

#coords #zoom-level {
  margin-left: 8px !important;
  padding-left: 8px !important;
  border-left: 1px solid var(--ui-border) !important;
  color: var(--accent) !important;
}

#users-online {
  justify-self: end !important;
  gap: 6px !important;
  width: fit-content !important;
}

.online-dot {
  width: 10px !important;
  height: 10px !important;
  flex-shrink: 0 !important;
  margin: 0 !important;
}

#share-btn svg,
#theme-toggle svg,
#account-btn svg {
  width: 18px !important;
  height: 18px !important;
  flex-shrink: 0 !important;
  opacity: 0.7 !important;
}

#share-btn:hover,
#theme-toggle:hover,
#account-btn:hover {
  border-color: var(--accent) !important;
  box-shadow: var(--ui-shadow), 0 0 0 1px var(--accent) !important;
}

#counters-container {
  font-family: 'Inter', system-ui, -apple-system, sans-serif !important;
  font-size: 13px !important;
  font-weight: 500 !important;
  color: var(--text-muted) !important;
  line-height: 1.4 !important;
  padding: 8px 16px !important;
  min-height: 36px !important;
  display: flex !important;
  align-items: center !important;
  box-sizing: border-box !important;
  border-radius: var(--radius) !important;
  margin: 0 auto !important;
  background: var(--bg-panel) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  border: 1px solid var(--ui-border) !important;
  box-shadow: var(--ui-shadow) !important;
  flex-wrap: wrap !important;
  justify-content: center !important;
  gap: 4px !important;
}

#counters-container span {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 1;
  min-width: 0;
}

.counter-change {
  position: absolute;
  font-weight: 600;
  font-size: 14px;
  color: #22c55e;
  pointer-events: none;
  animation: floatUpFade 1.2s ease-out forwards;
  z-index: 1000;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
}

@keyframes floatUpFade {
  0% {
    opacity: 1;
    transform: translateY(0) scale(var(--popup-scale, 1));
  }

  70% {
    opacity: 1;
    transform: translateY(-20px) scale(calc(var(--popup-scale, 1) * 1.1));
  }

  100% {
    opacity: 0;
    transform: translateY(-40px) scale(calc(var(--popup-scale, 1) * 0.9));
  }
}

.counter-change.erased {
  color: #ef4444;
}

.counter-change.overwritten {
  color: #f59e0b;
}

.counter-change.copied {
  color: #3b82f6;
}

@media (max-width: 500px) {
  #top-bar {
    position: absolute;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    gap: 10px !important;
  }

  #share-btn,
  #theme-toggle {
    flex-shrink: 0 !important;
    white-space: nowrap !important;
  }

  #coords,
  #top-center-controls,
  #users-online {
    max-width: 100% !important;
  }

  #coords {
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    width: fit-content !important;
    max-width: 100% !important;
  }

  #top-center-controls {
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    gap: 10px !important;
    min-width: 188px;
  }

  #counters-container {
    top: calc(16px + 36px + 10px + 36px + 10px + 36px + 12px) !important;
  }
}

#image-modal-overlay {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

#image-modal-overlay input[type="range"] {
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
}

#image-modal-overlay input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

#overlay-controls {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  user-select: none;
}

#overlay-controls input[type="range"] {
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
}

#overlay-controls input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* ==========================================
   OVERLAY CONTROLS BUTTON ENHANCEMENTS
   ========================================== */
#overlay-controls button {
  transition: all 0.15s ease;
}

#move-up-btn,
#move-down-btn,
#move-left-btn,
#move-right-btn {
  transition: all 0.15s ease !important;
  -webkit-tap-highlight-color: transparent;
}

#move-up-btn:hover,
#move-down-btn:hover,
#move-left-btn:hover,
#move-right-btn:hover {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 1px var(--accent), 0 3px 10px rgba(96, 165, 250, 0.25) !important;
  transform: translateY(-1px);
}

#move-up-btn:active,
#move-down-btn:active,
#move-left-btn:active,
#move-right-btn:active {
  background: var(--accent) !important;
  color: white !important;
  border-color: var(--accent) !important;
  transform: scale(0.95) translateY(1px) !important;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2) !important;
  transition: all 0.05s ease !important;
}

#overlay-delete-btn {
  transition: all 0.15s ease !important;
}

#overlay-delete-btn:hover {
  background: #ef4444 !important;
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.35) !important;
  transform: translateY(-1px);
}

#overlay-delete-btn:active {
  background: #dc2626 !important;
  transform: scale(0.96) translateY(1px) !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2) !important;
  transition: all 0.05s ease !important;
}


.color-swatch,
.eraser-swatch,
.eyedropper-swatch,
.image-tool-swatch {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

[data-theme="light"] .color-swatch,
[data-theme="light"] .eraser-swatch,
[data-theme="light"] .eyedropper-swatch,
[data-theme="light"] .image-tool-swatch {
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.color-swatch:not(.active):hover,
.eraser-swatch:not(.active):hover,
.eyedropper-swatch:not(.active):hover,
.image-tool-swatch:not(.active):hover {
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
  border-color: var(--accent) !important;
  transform: scale(1.2) translateY(-3px);
  z-index: 5;
}

.eraser-swatch,
.eyedropper-swatch,
.image-tool-swatch {
  font-size: 18px !important;
}

.eraser-swatch::before,
.eyedropper-swatch::before,
.image-tool-swatch::before {
  display: block;
  width: 100%;
  height: 100%;
  text-align: center;
  line-height: 34px;
}

.color-swatch.custom-picker {
  background: conic-gradient(from 0deg, red, yellow, lime, aqua, blue, magenta, red);
  background-size: cover;
}

.color-swatch.custom-picker:not(.active):hover {
  box-shadow: 0 4px 12px var(--accent-glow);
}

.color-swatch.custom-picker input[type="color"] {
  cursor: pointer;
}

[data-theme="light"] .color-swatch.custom-picker {
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.color-swatch[data-color="ffffff"] {
  border-color: rgba(0, 0, 0, 0.15);
}

.color-swatch[data-color="ffffff"].active {
  border-color: var(--text);
}

#palette .color-swatch.active {
  position: relative !important;
  border: 1px solid var(--text) !important;
  box-shadow: 0 0 0 1px var(--text), 0 0 14px rgba(var(--grid-line-base), 0.85) !important;
  transform: none !important;
  transition: box-shadow 0.2s ease, border-color 0.2s ease !important;
}

#palette .color-swatch.active,
#palette .eraser-swatch.active,
#palette .eyedropper-swatch.active,
#palette .image-tool-swatch.active,
#palette .user-overlays-toggle.active {
  position: relative !important;
  border: 1px solid var(--accent) !important;
  box-shadow: 0 0 0 1px var(--accent), 0 0 14px var(--accent) !important;
  transform: scale(1.2) translateY(-3px) !important;
  transition: box-shadow 0.2s ease, border-color 0.2s ease, transform 0.2s ease !important;
}

.color-swatch[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 8px;
  background: var(--bg-panel);
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  font-size: 11px;
  color: var(--text);
  white-space: nowrap;
  z-index: 100;
  pointer-events: none;
  margin-bottom: 4px;
}

.color-swatch.active {
  box-shadow: 0 0 0 2px var(--accent) !important;
}

.user-overlays-toggle.active {
  background: #00ff00 !important;
  border-color: #16a34a !important;
}

.user-overlays-toggle:not(.active) {
  background: #ff0000 !important;
  border-color: #dc2626 !important;
}

.user-overlays-toggle {
  color: white !important;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, box-shadow 0.2s ease;
  font-size: 18px !important;
  line-height: 1;
  padding-bottom: 7px;
}

.user-overlays-toggle::before,
.user-overlays-toggle>* {
  color: white !important;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

#auth-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: transparent;
  z-index: 99999;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

.auth-panel {
  padding: 30px;
  border-radius: 12px;
  width: 300px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.auth-panel h2 {
  margin-top: 0;
  color: var(--text);
  margin-bottom: 10px;
}

.auth-subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 20px;
}

.auth-input {
  width: 100%;
  padding: 10px;
  margin-bottom: 10px;
  border-radius: 6px;
  border: 1px solid var(--ui-border);
  background: var(--bg-input);
  color: var(--text);
  box-sizing: border-box;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.auth-input:focus {
  border-color: var(--accent);
}

.auth-error {
  color: #f59e0b;
  font-size: 13px;
  margin-top: 0;
  margin-bottom: 15px;
  min-height: 18px;
  display: none;
}

.auth-error.error {
  color: #ff4444;
}

.auth-error.warning {
  color: #f59e0b;
}

.auth-error.success {
  color: #22c55e;
}


.auth-btn {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
  font-size: 14px;
  margin-bottom: 15px;
  transition: opacity 0.2s;
}

.auth-btn:hover {
  opacity: 0.9;
}

.auth-footer {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0;
}

.auth-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: bold;
}

.auth-link:hover {
  text-decoration: underline;
}

#auth-login-username.auth-input,
#auth-login-password.auth-input,
#auth-register-confirm.auth-input,
#acc-new-username.auth-input,
#acc-current-password.auth-input,
#acc-new-password.auth-input,
#acc-confirm-password.auth-input {
  opacity: 1;
  color: #60A5FA;
}

.remote-cursor {
  position: absolute;
  width: 20px;
  height: 20px;
  border: 2px solid #60a5fa;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 100;
}

.remote-cursor-emote {
  position: absolute;
  top: 50%;
  left: 50%;
  font-size: 13px;
  padding-bottom: 2px;
  pointer-events: none;
  z-index: 101;
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));

  opacity: 0;
  transform: translate(-50%, -50%) scale(0.85);
}

.remote-cursor.tool-active .remote-cursor-emote {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.remote-cursor.tool-active {
  background-color: transparent !important;
}

.remote-cursor.tool-active::after {
  display: none;
}

.cursor-label {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 8px;
  border: 1px solid #60a5fa;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  background-color: rgba(0, 0, 0, 0.85);
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

html[data-theme="light"] .cursor-label {
  background-color: #e0e0e0 !important;
  color: #000000;
  text-shadow: none;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
}

html[data-theme="dark"] .cursor-label {
  background-color: #333333 !important;
  color: #e0e0e0;
  text-shadow: none;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
}

.cursor-label.admin {
  color: #950000 !important;
  font-weight: 800 !important;
  text-shadow: 0 0 8px rgba(149, 0, 0, 0.6) !important;
  border-color: #950000 !important;
}

.share-btn:active,
#theme-toggle:active,
#coords:active {
  transform: scale(0.92) translateY(2px) !important;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15) !important;
  transition: transform 0.05s ease-out, box-shadow 0.05s ease-out !important;
}

#palette .color-swatch:active,
#palette .eraser-swatch:active,
#palette .eyedropper-swatch:active,
#palette .image-tool-swatch:active,
#palette .user-overlays-toggle:active,
#recent-colors-row .color-swatch:active,
#recent-colors-row .eraser-swatch:active,
#recent-colors-row .eyedropper-swatch:active,
#recent-colors-row .image-tool-swatch:active,
#recent-colors-row .user-overlays-toggle:active {
  transform: scale(0.95) translateY(2px) !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2) !important;
  transition: transform 0.05s ease-out, box-shadow 0.05s ease-out !important;
}

.recent-edit-btn:active {
  transform: scale(0.95) !important;
  transition: transform 0.05s ease-out !important;
}

.add-custom-btn:active {
  transform: translateY(-1px) scale(0.95) !important;
  transition: transform 0.05s ease-out !important;
}

/* ==========================================
   TUTORIAL OVERLAY & BACKDROP BLUR
   ========================================== */
.tutorial-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 99998;
  opacity: 0;
  animation: overlayFadeIn 0.3s ease forwards;
}

.tutorial-overlay.fade-out {
  animation: fadeOut 0.3s ease-in forwards !important;
}

@keyframes overlayFadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }

  to {
    opacity: 0;
  }
}

.tutorial-overlay,
.tutorial-popup {
  pointer-events: auto !important;
}

/* ==========================================
   TUTORIAL POPUP STYLES
   ========================================== */
.tutorial-popup {
  position: fixed;
  background: var(--bg-panel);
  color: var(--text);
  border: 2px solid #60a5fa;
  border-radius: var(--radius);
  padding: 20px 24px;
  max-width: 300px;
  min-width: 240px;
  z-index: 99999;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 16px;
  animation: popupFadeIn 0.3s ease-out forwards, floatUpDown 3s ease-in-out infinite 0.3s;
}

.tutorial-popup .tutorial-btn+.tutorial-btn.secondary {
  margin-top: -8px;
}

.tutorial-popup .tutorial-title {
  font-size: 26px;
  font-weight: 600;
  margin: 0;
  color: var(--text);
  text-align: center;
  margin-bottom: -8px;
}

.tutorial-popup .tutorial-text,
.tutorial-popup p {
  margin: 0;
  line-height: 1.5;
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
}

.tutorial-highlight-text {
  color: #60a5fa !important;
  font-weight: 600 !important;
}

.tutorial-popup.fade-out {
  animation: popupFadeOut 0.3s ease-in forwards !important;
}

@keyframes popupFadeIn {
  from {
    opacity: 0;
    transform: translateY(15px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes popupFadeOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }

  to {
    opacity: 0;
    transform: translateY(15px);
  }
}

@keyframes floatUpDown {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-8px);
  }
}

.tutorial-popup p {
  margin: 0 0 12px 0;
}

.tutorial-popup.center-screen {
  top: 50%;
  left: 50%;
  animation: popupFadeInCenter 0.3s ease-out forwards !important;
  text-align: center;
  max-width: 320px;
}

.tutorial-popup.center-screen.fade-out {
  animation: popupFadeOutCenter 0.3s ease-in forwards !important;
}

@keyframes popupFadeInCenter {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.9);
  }

  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

@keyframes popupFadeOutCenter {
  from {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }

  to {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.9);
  }
}

.tutorial-popup.center-screen::before,
.tutorial-popup.center-screen::after {
  display: none !important;
}

/* ==========================================
   BUTTONS (Hover and Press Animations)
   ========================================== */
.tutorial-popup .tutorial-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: all 0.2s ease;
  transform: translateY(0);
}

.tutorial-popup .tutorial-btn:hover {
  opacity: 0.9;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.tutorial-popup .tutorial-btn:active {
  transform: translateY(1px) scale(0.98);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  opacity: 0.8;
}

.tutorial-popup .tutorial-btn.secondary {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--ui-border);
  margin: 0;
}

.tutorial-popup .tutorial-btn.secondary:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--accent);
  color: var(--text);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.tutorial-popup .tutorial-btn.secondary:active {
  transform: translateY(1px) scale(0.98);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* ==========================================
   ARROW SYSTEM
   ========================================== */
.tutorial-popup::before,
.tutorial-popup::after {
  content: '';
  position: absolute;
  width: 0;
  height: 0;
}

.tutorial-popup.arrow-top::before,
.tutorial-popup.arrow-top-left::before,
.tutorial-popup.arrow-top-right::before {
  top: -10px;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-bottom: 10px solid #60a5fa;
}

.tutorial-popup.arrow-top::after,
.tutorial-popup.arrow-top-left::after,
.tutorial-popup.arrow-top-right::after {
  top: -7px;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 8px solid var(--bg-panel);
}

.tutorial-popup.arrow-bottom::before,
.tutorial-popup.arrow-bottom-left::before,
.tutorial-popup.arrow-bottom-right::before {
  bottom: -10px;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 10px solid #60a5fa;
}

.tutorial-popup.arrow-bottom::after,
.tutorial-popup.arrow-bottom-left::after,
.tutorial-popup.arrow-bottom-right::after {
  bottom: -7px;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid var(--bg-panel);
}

.tutorial-popup.arrow-left::before {
  left: -10px;
  top: 50%;
  transform: translateY(-50%);
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-right: 10px solid #60a5fa;
}

.tutorial-popup.arrow-left::after {
  left: -7px;
  top: 50%;
  transform: translateY(-50%);
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-right: 8px solid var(--bg-panel);
}

.tutorial-popup.arrow-right::before {
  right: -10px;
  top: 50%;
  transform: translateY(-50%);
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-left: 10px solid #60a5fa;
}

.tutorial-popup.arrow-right::after {
  right: -7px;
  top: 50%;
  transform: translateY(-50%);
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-left: 8px solid var(--bg-panel);
}

.tutorial-popup.arrow-top-left::before,
.tutorial-popup.arrow-top-left::after,
.tutorial-popup.arrow-bottom-left::before,
.tutorial-popup.arrow-bottom-left::after {
  left: 18px;
  right: auto;
  transform: none;
}

.tutorial-popup.arrow-top-right::before,
.tutorial-popup.arrow-top-right::after,
.tutorial-popup.arrow-bottom-right::before,
.tutorial-popup.arrow-bottom-right::after {
  right: 18px;
  left: auto;
  transform: none;
}

.tutorial-popup.arrow-top::before,
.tutorial-popup.arrow-top::after,
.tutorial-popup.arrow-bottom::before,
.tutorial-popup.arrow-bottom::after {
  left: 50%;
  transform: translateX(-50%);
}

/* ==========================================
   TUTORIAL BLUR EFFECT
   ========================================== */
body.tutorial-active>*:not(.tutorial-overlay):not(.tutorial-popup) {
  pointer-events: none;
}

.tutorial-overlay,
.tutorial-popup {
  pointer-events: auto !important;
}

/* ==========================================
   TUTORIAL HIGHLIGHT
   ========================================== */
.tutorial-highlight {
  position: relative;
  z-index: 99999 !important;
  isolation: isolate;
  box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.6), 0 0 24px rgba(96, 165, 250, 0.4);
  border-radius: 8px;
  transition: box-shadow 0.3s ease, filter 0.3s ease;
  scroll-margin: 24px;
}

/* ==========================================
   TUTORIAL OVERRIDES
   ========================================== */
body.tutorial-active .recent-edit-btn {
  pointer-events: none !important;
}

#account-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2147483646;
}

#auth-modal {
  background: transparent !important;
  backdrop-filter: blur(12px) !important;
  -webkit-backdrop-filter: blur(12px) !important;
}

#account-modal .ui-panel,
#auth-modal .ui-panel {
  background: var(--bg-panel) !important;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4) !important;
}

/* ==========================================
   ACCOUNT MODAL ENHANCEMENTS
   ========================================== */
.auth-input {
  caret-color: #60a5fa;
}

.auth-btn:active {
  transform: translateY(1px) scale(0.98) !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2) !important;
  opacity: 0.9 !important;
}

.auth-btn.success {
  background: #22c55e !important;
  border: 1px solid #22c55e !important;
  box-shadow: 0 0 0 1px #22c55e, 0 0 12px rgba(34, 197, 94, 0.5) !important;
  color: white !important;
  transform: translateY(0) scale(1) !important;
  opacity: 1 !important;
}

#acc-close-btn:hover {
  background: var(--accent) !important;
  color: white !important;
  box-shadow: 0 4px 12px rgba(96, 165, 250, 0.3) !important;
  transform: translateY(-1px);
}

#acc-close-btn:active {
  transform: translateY(1px) scale(0.98) !important;
  box-shadow: 0 2px 4px rgba(96, 165, 250, 0.2) !important;
}

#account-btn.hidden {
  display: none !important;
}