:root {
  --bg-primary: #0b0f19;
  --bg-panel: #131b2e;
  --bg-panel-subtle: #1e293b;
  --bg-hover: #334155;
  --bg-active: #4f46e5;
  --border-color: #334155;
  --border-focus: #6366f1;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #10b981;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --toolbar-h: 56px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-primary);
  font-family: var(--font-sans);
  color: var(--text-main);
}

.app-container {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
}

/* Header & Top Bar */
.top-header {
  height: var(--toolbar-h);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 20;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.logo-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #a5b4fc, #818cf8, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-badge {
  font-size: 0.72rem;
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.4);
  padding: 2px 7px;
  border-radius: 12px;
  font-weight: 600;
}

/* Tool controls in header */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border-color);
  background: var(--bg-panel-subtle);
  color: var(--text-main);
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-hover);
  border-color: #475569;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

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

/* Main workspace */
.workspace-wrapper {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
}

/* Left Floating Toolbar */
.floating-toolbar {
  position: absolute;
  top: 16px;
  left: 16px;
  background: rgba(19, 27, 46, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 15;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.4);
}

.tool-btn {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}

.tool-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.tool-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
}

.tool-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: #818cf8;
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.5);
}

.tool-separator {
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
  margin: 4px 2px;
}

/* Tooltip */
.tool-btn[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background: #020617;
  color: #f8fafc;
  padding: 4px 8px;
  font-size: 0.75rem;
  border-radius: 6px;
  white-space: nowrap;
  border: 1px solid #334155;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  pointer-events: none;
  z-index: 100;
}

/* Top properties sub-toolbar */
.properties-toolbar {
  position: absolute;
  top: 16px;
  left: 80px;
  max-width: calc(100vw - 100px);
  overflow-x: auto;
  scrollbar-width: none;
  background: rgba(19, 27, 46, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 14;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
}

.properties-toolbar::-webkit-scrollbar {
  display: none;
}

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

.color-picker-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.color-swatch-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid #ffffff33;
  cursor: pointer;
  transition: transform 0.15s;
}

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

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

.palette-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.2);
  transition: transform 0.15s;
}

.palette-dot:hover {
  transform: scale(1.2);
}

.hex-color-input {
  width: 68px;
  background: var(--bg-panel-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 0.74rem;
  font-family: monospace;
  text-transform: uppercase;
  outline: none;
  text-align: center;
}

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

.eyedropper-btn {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-panel-subtle);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.eyedropper-btn:hover {
  background: var(--bg-hover);
  color: #38bdf8;
  border-color: #38bdf8;
}

.eyedropper-btn.active {
  background: #38bdf8;
  color: #0f172a;
  border-color: #38bdf8;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.5);
}

.color-input-native {
  opacity: 0;
  position: absolute;
  width: 0;
  height: 0;
  pointer-events: none;
}

.stroke-range {
  width: 76px;
  cursor: pointer;
  accent-color: var(--accent);
}

.font-size-select, .stroke-style-select {
  background: var(--bg-panel-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.78rem;
  outline: none;
  max-width: 140px;
}

.toggle-mode-label {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  font-size: 0.78rem;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.25);
  padding: 3px 8px;
  border-radius: 6px;
  transition: all 0.15s ease;
}

.toggle-mode-label:hover {
  background: rgba(56, 189, 248, 0.16);
  border-color: #38bdf8;
}

.toggle-mode-text {
  font-weight: 600;
  color: #7dd3fc;
  white-space: nowrap;
}

.prop-separator {
  width: 1px;
  height: 20px;
  background: rgba(255, 255, 255, 0.15);
}

.layer-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.layer-group .btn-sm {
  font-size: 0.72rem;
  padding: 2px 7px;
  background: rgba(255, 255, 255, 0.05);
}

.layer-group .btn-sm:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: #64748b;
}

.zoom-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.zoom-btn {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-panel-subtle);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.zoom-btn:hover {
  background: var(--bg-hover);
  border-color: #475569;
}

.zoom-percent-badge {
  font-size: 0.75rem;
  font-weight: 600;
  font-family: monospace;
  color: #38bdf8;
  padding: 2px 6px;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 6px;
  min-width: 44px;
  text-align: center;
}

.btn-sm {
  padding: 3px 8px;
  font-size: 0.74rem;
  height: 24px;
}

/* Canvas viewport */
.canvas-viewport {
  flex: 1;
  width: 100%;
  height: 100%;
  overflow: auto;
  position: relative;
  background: radial-gradient(#1e293b 1px, transparent 1px) 0 0 / 24px 24px, #0b0f19;
  display: grid;
  place-items: center;
  padding: 40px;
  cursor: crosshair;
}

.canvas-viewport.mode-select {
  cursor: default;
}

.canvas-viewport.mode-hand {
  cursor: grab;
}

.canvas-viewport.mode-hand:active {
  cursor: grabbing;
}

.canvas-container {
  position: relative;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.1);
  background: #ffffff;
  border-radius: 2px;
  transition: width 0.1s ease, height 0.1s ease;
  margin: auto;
}

#paintCanvas {
  display: block;
}

/* Empty state banner when no image */
.empty-state-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(11, 15, 25, 0.85);
  backdrop-filter: blur(8px);
  z-index: 10;
  pointer-events: auto;
  text-align: center;
  padding: 24px;
}

.empty-state-card {
  max-width: 520px;
  background: rgba(30, 41, 59, 0.7);
  border: 2px dashed rgba(99, 102, 241, 0.5);
  border-radius: 20px;
  padding: 36px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
  transition: all 0.25s ease;
}

.empty-state-card.drag-over {
  border-color: #38bdf8;
  background: rgba(56, 189, 248, 0.1);
  transform: scale(1.02);
}

.paste-hero-icon {
  width: 72px;
  height: 72px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(99,102,241,0.2), rgba(147,51,234,0.2));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #818cf8;
}

.paste-hero-icon svg {
  width: 38px;
  height: 38px;
}

.empty-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: #f8fafc;
}

.empty-desc {
  font-size: 0.92rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.kbd-badge {
  background: #334155;
  color: #f8fafc;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-family: monospace;
  border: 1px solid #475569;
  box-shadow: 0 2px 0 #1e293b;
}

.empty-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

/* In-line text editor input */
.text-inline-editor {
  position: absolute;
  background: transparent;
  border: 1px dashed #6366f1;
  outline: none;
  color: inherit;
  font-family: var(--font-sans);
  font-weight: 600;
  line-height: 1.2;
  padding: 2px 4px;
  resize: none;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
  z-index: 25;
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.4);
}

/* Status Bar at bottom */
.bottom-status-bar {
  height: 28px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-size: 0.74rem;
  color: var(--text-muted);
  z-index: 20;
}

.status-left, .status-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Toast message */
.toast-container {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(99, 102, 241, 0.4);
  color: #f8fafc;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 500;
  box-shadow: 0 15px 30px rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
}

.toast-container.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-8px);
}

/* Color Wheel Popup (Mac / HSL style) */
.color-wheel-popup {
  position: fixed;
  background: rgba(19, 27, 46, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.05);
  padding: 14px;
  z-index: 1000;
  width: 236px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.95) translateY(-6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.color-wheel-popup.show {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1) translateY(0);
}

.cwheel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 8px;
}

.cwheel-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: #cbd5e1;
}

.cwheel-close-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  border-radius: 4px;
}

.cwheel-close-btn:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.cwheel-canvas-wrap {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 0 auto;
  cursor: crosshair;
  border-radius: 50%;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
}

.cwheel-canvas {
  display: block;
  border-radius: 50%;
}

.cwheel-reticle {
  position: absolute;
  width: 22px;
  height: 22px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.7));
}

.cwheel-slider-wrap {
  width: 100%;
  padding: 4px 2px;
}

.cwheel-slider-track {
  height: 14px;
  border-radius: 7px;
  position: relative;
  cursor: pointer;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.5), 0 0 0 1px rgba(255, 255, 255, 0.15);
}

.cwheel-slider-thumb {
  position: absolute;
  top: 50%;
  width: 18px;
  height: 18px;
  background: #ffffff;
  border: 2px solid #0f172a;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
  pointer-events: none;
  transition: transform 0.1s ease;
}

.cwheel-slider-track:active .cwheel-slider-thumb {
  transform: translate(-50%, -50%) scale(1.15);
}

.cwheel-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.cwheel-preview-color {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.cwheel-hex-input {
  flex: 1;
  background: var(--bg-panel-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 0.78rem;
  font-family: monospace;
  text-transform: uppercase;
  outline: none;
  text-align: center;
}

.cwheel-hex-input:focus {
  border-color: var(--accent);
}

.cwheel-apply-btn {
  padding: 4px 10px;
}

/* --- Sticker / Icon Library Drawer --- */
.sticker-library-panel {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 280px;
  max-height: calc(100vh - 100px);
  background: rgba(19, 27, 46, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.05);
  padding: 14px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 10px;
  opacity: 0;
  pointer-events: none;
  transform: translateX(20px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.sticker-library-panel.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}

.sticker-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sticker-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 700;
  color: #f8fafc;
}

.sticker-panel-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  line-height: 1;
}

.sticker-panel-close-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.sticker-panel-actions {
  display: flex;
  gap: 8px;
}

.sticker-tip-text {
  font-size: 0.72rem;
  color: #94a3b8;
  line-height: 1.4;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: 6px;
  padding: 6px 8px;
}

.sticker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  overflow-y: auto;
  max-height: 320px;
  padding: 4px 2px;
  scrollbar-width: thin;
}

.sticker-grid::-webkit-scrollbar {
  width: 5px;
}
.sticker-grid::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 4px;
}

.sticker-item {
  aspect-ratio: 1;
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  cursor: pointer;
  position: relative;
  transition: all 0.15s ease;
}

.sticker-item:hover {
  background: rgba(99, 102, 241, 0.2);
  border-color: #818cf8;
  transform: scale(1.06);
}

.sticker-item img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.sticker-del-btn {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 16px;
  height: 16px;
  background: #ef4444;
  color: #fff;
  border-radius: 50%;
  border: none;
  font-size: 10px;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.5);
  line-height: 1;
}

.sticker-item:hover .sticker-del-btn {
  display: flex;
}

.sticker-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
  padding: 24px 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

