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

:root {
  --ui-bg: rgba(18, 18, 24, 0.92);
  --ui-border: rgba(255, 255, 255, 0.08);
  --ui-text: #e8e8f0;
  --ui-text-dim: rgba(255, 255, 255, 0.5);
  --ui-accent: #6c7bff;
  --ui-accent-glow: rgba(108, 123, 255, 0.4);
  --ui-radius: 14px;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #0a0a0f;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  color: var(--ui-text);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

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

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

/* Toolbar */
#toolbar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  border-radius: 20px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 100;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

#toolbar button {
  width: 42px; height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 12px;
  color: var(--ui-text-dim);
  cursor: pointer;
  transition: all 0.2s;
}

#toolbar button svg { width: 22px; height: 22px; }

#toolbar button:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--ui-text);
}

#toolbar button:active {
  transform: scale(0.92);
}

#toolbar button.active {
  background: var(--ui-accent);
  color: white;
  box-shadow: 0 0 16px var(--ui-accent-glow);
}

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

/* Panels */
.panel {
  position: fixed;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 200;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  animation: panelIn 0.25s ease-out;
}

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

.panel.hidden { display: none; }

.panel-header {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--ui-border);
}

.panel-header h3 {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
}

.close-btn {
  width: 28px; height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.06);
  border: none;
  border-radius: 8px;
  color: var(--ui-text-dim);
  font-size: 18px;
  cursor: pointer;
  transition: all 0.15s;
}

.close-btn:hover { background: rgba(255,255,255,0.12); color: var(--ui-text); }

.panel-body {
  padding: 16px;
  max-height: 400px;
  overflow-y: auto;
}

.panel-body::-webkit-scrollbar { width: 6px; }
.panel-body::-webkit-scrollbar-track { background: transparent; }
.panel-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }

/* Color Picker */
#color-picker {
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 320px;
}

.picker-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#hue-sat-canvas {
  border-radius: 12px;
  cursor: crosshair;
  touch-action: none;
  width: 280px;
  height: 280px;
}

#lightness-slider {
  -webkit-appearance: none;
  width: 280px;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(to right, #000, #888, #fff);
  outline: none;
}

#lightness-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: white;
  border: 3px solid rgba(0,0,0,0.3);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

#color-preview {
  width: 280px;
  height: 48px;
  border-radius: 10px;
  border: 2px solid var(--ui-border);
  transition: background 0.1s;
}

#hex-input {
  width: 280px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--ui-border);
  border-radius: 10px;
  color: var(--ui-text);
  font-size: 16px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  text-align: center;
  outline: none;
}

#hex-input:focus { border-color: var(--ui-accent); }

.primary-btn {
  width: 280px;
  padding: 12px;
  background: var(--ui-accent);
  border: none;
  border-radius: 10px;
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.primary-btn:hover { filter: brightness(1.15); }
.primary-btn:active { transform: scale(0.97); }

/* Palettes Panel */
#palettes-panel, #gallery-panel {
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 380px;
  max-width: 95vw;
}

.palette-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.palette-card:hover { background: rgba(255,255,255,0.08); }

.palette-colors {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}

.palette-swatch {
  width: 24px; height: 24px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.1);
}

.palette-info { flex: 1; min-width: 0; }
.palette-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.palette-date { font-size: 12px; color: var(--ui-text-dim); margin-top: 2px; }

.palette-actions {
  display: flex;
  gap: 4px;
}

.palette-actions button {
  width: 30px; height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.06);
  border: none;
  border-radius: 8px;
  color: var(--ui-text-dim);
  cursor: pointer;
  font-size: 14px;
}

.palette-actions button:hover { background: rgba(255,255,255,0.12); color: var(--ui-text); }

/* Gallery */
.gallery-tabs {
  display: flex;
  gap: 4px;
  margin-left: auto;
  margin-right: 8px;
}

.tab {
  padding: 4px 12px;
  background: rgba(255,255,255,0.06);
  border: none;
  border-radius: 8px;
  color: var(--ui-text-dim);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.tab.active { background: var(--ui-accent); color: white; }

.gallery-card {
  padding: 12px;
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.gallery-card:hover { background: rgba(255,255,255,0.08); }

.gallery-preview {
  height: 80px;
  border-radius: 8px;
  margin-bottom: 8px;
  overflow: hidden;
  display: flex;
  gap: 2px;
}

.gallery-preview-stripe {
  flex: 1;
  min-width: 0;
}

.gallery-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.gallery-title { font-size: 14px; font-weight: 500; }

.gallery-likes {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--ui-text-dim);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.15s;
}

.gallery-likes:hover { background: rgba(255,255,255,0.08); color: #ff6b8a; }

/* Save Dialog */
#save-dialog {
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 340px;
}

#save-name {
  width: 100%;
  padding: 10px 14px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--ui-border);
  border-radius: 10px;
  color: var(--ui-text);
  font-size: 15px;
  outline: none;
  margin-bottom: 12px;
}

#save-name:focus { border-color: var(--ui-accent); }

#save-confirm { width: 100%; }

.share-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 13px;
  color: var(--ui-text-dim);
  cursor: pointer;
}

.share-check input { accent-color: var(--ui-accent); }

/* Orb Edit Popup */
#orb-edit {
  position: fixed;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  border-radius: 12px;
  backdrop-filter: blur(20px);
  z-index: 150;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

#orb-edit.hidden { display: none; }

#orb-color-input {
  width: 32px; height: 32px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: none;
  padding: 0;
}

#orb-color-input::-webkit-color-swatch-wrapper { padding: 0; }
#orb-color-input::-webkit-color-swatch { border: 2px solid rgba(255,255,255,0.2); border-radius: 8px; }

#orb-edit button {
  width: 32px; height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.06);
  border: none;
  border-radius: 8px;
  color: var(--ui-text-dim);
  cursor: pointer;
}

#orb-edit button:hover { background: rgba(255,255,255,0.12); color: var(--ui-text); }

/* Hint */
#hint {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  border-radius: 10px;
  font-size: 14px;
  color: var(--ui-text-dim);
  backdrop-filter: blur(20px);
  z-index: 50;
  animation: hintFade 4s ease-in-out forwards;
  pointer-events: none;
}

@keyframes hintFade {
  0%, 70% { opacity: 1; }
  100% { opacity: 0; }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--ui-text-dim);
  font-size: 14px;
}

/* Mobile adjustments */
@media (max-width: 480px) {
  #toolbar {
    bottom: 12px;
    padding: 6px 8px;
    gap: 2px;
  }

  #toolbar button { width: 36px; height: 36px; }
  #toolbar button svg { width: 18px; height: 18px; }

  .panel {
    width: 95vw !important;
    max-width: 95vw;
  }

  #hue-sat-canvas { width: 240px; height: 240px; }
  #lightness-slider, #color-preview, .primary-btn, #hex-input { width: 240px; }
}
