/* ===== Reset & Base ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #f8f7f5;
  --surface: #ffffff;
  --surface-alt: #f2f0ed;
  --border: #e8e5e0;
  --text: #3a3633;
  --text-light: #8a8580;
  --text-lighter: #b5b0aa;
  --accent: #7ba5c4;
  --accent-soft: #d4e5f0;
  --danger: #d4746a;
  --danger-soft: #f5e0dd;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
  --font: 'Helvetica Neue', -apple-system, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* ===== Header ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  flex-shrink: 0;
}

.app-title {
  font-size: 15px;
  font-weight: 300;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-light);
}

.btn-settings {
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  transition: background 0.2s;
}

.btn-settings:hover {
  background: var(--surface-alt);
}

/* ===== Tab Navigation ===== */
.tab-nav {
  display: flex;
  gap: 0;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  padding: 10px 0;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.8px;
  color: var(--text-lighter);
  cursor: pointer;
  transition: all 0.2s;
  text-transform: lowercase;
}

.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tab-panel {
  display: none;
  flex: 1;
  overflow: hidden;
  flex-direction: column;
}

.tab-panel.active {
  display: flex;
}

/* ===== Ref Toolbar ===== */
.ref-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 20px;
  flex-shrink: 0;
}

.btn-ref-settings {
  background: none;
  border: none;
  color: var(--text-lighter);
  cursor: pointer;
  padding: 5px;
  border-radius: 6px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  transition: color 0.2s, background 0.2s;
}

.btn-ref-settings:hover {
  color: var(--text-light);
  background: var(--surface-alt);
}

.ref-folder-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  flex: 1;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 2px 0;
}

.ref-folder-tabs::-webkit-scrollbar {
  display: none;
}

.ref-folder-tab {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-lighter);
  font-size: 11px;
  cursor: pointer;
  flex-shrink: 0;
  scroll-snap-align: start;
  transition: all 0.15s;
  white-space: nowrap;
}

.ref-folder-tab .folder-name {
  display: none;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ref-folder-tab.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.ref-folder-tab.active .folder-name {
  display: inline;
}

.ref-folder-tab:hover {
  border-color: var(--text-lighter);
  color: var(--text-light);
}

.ref-folder-tab .folder-icon {
  flex-shrink: 0;
}

/* ===== Ref Settings Dropdown ===== */
.ref-settings-dropdown {
  position: fixed;
  top: auto;
  bottom: auto;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  border: 1px solid var(--border);
  z-index: 500;
  min-width: 160px;
  overflow: hidden;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  font-size: 12px;
  color: var(--text-light);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}

.dropdown-item:hover {
  background: var(--surface-alt);
}

.dropdown-item.danger {
  color: var(--danger);
}

.dropdown-item:disabled,
.dropdown-item.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.dropdown-item svg {
  flex-shrink: 0;
  opacity: 0.7;
}

.dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* ===== Library Tab ===== */
.ref-images-area {
  flex: 0 0 33.33%;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 6px 0 4px;
  overflow: hidden;
}

.ref-images-scroll {
  flex: 1;
  display: flex;
  gap: 12px;
  padding: 0 20px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  align-items: center;
}

.ref-images-scroll::-webkit-scrollbar {
  display: none;
}

.ref-img-card {
  flex: 0 0 auto;
  width: 120px;
  height: 120px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  scroll-snap-align: center;
  transition: border-color 0.2s, transform 0.2s;
  position: relative;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.ref-img-card.selected {
  border-color: var(--accent);
  transform: scale(1.04);
}

.ref-img-card canvas,
.ref-img-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.hint-text {
  font-size: 10px;
  color: var(--text-lighter);
  text-align: center;
  padding: 6px 0 0;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

/* ===== Color Cards Area ===== */
.color-cards-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 20px;
  -webkit-overflow-scrolling: touch;
}

.color-cards-area::-webkit-scrollbar {
  width: 3px;
}

.color-cards-area::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.color-cards-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.color-card-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.color-card-name {
  font-size: 11px;
  font-weight: 300;
  color: var(--text-light);
  letter-spacing: 0.5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.color-card-strip {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 6px 10px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: 0 1px 6px rgba(0,0,0,0.04);
  cursor: pointer;
  transition: box-shadow 0.2s;
  overflow-x: auto;
}

.color-card-strip::-webkit-scrollbar {
  display: none;
}

.color-card-strip:hover {
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}

.color-card-strip.selected {
  box-shadow: 0 0 0 2px var(--accent), 0 2px 10px rgba(0,0,0,0.08);
}

.color-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1.5px solid rgba(0,0,0,0.06);
  transition: transform 0.15s;
}

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

/* ===== Create Card Tab ===== */
.create-card-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.preview-ref-area {
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.ref-images-scroll.mini {
  padding: 0;
  justify-content: center;
}

.ref-images-scroll.mini .ref-img-card {
  width: 80px;
  height: 80px;
}

.section-title {
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 1px;
  color: var(--text-light);
  text-transform: lowercase;
  margin-bottom: 10px;
}

.palette-editor {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.palette-strip {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 10px;
  background: var(--surface);
  border-radius: var(--radius);
  min-height: 50px;
  align-items: center;
}

.palette-strip .color-dot {
  cursor: pointer;
}

.palette-strip .color-dot.active {
  box-shadow: 0 0 0 2px var(--accent);
  transform: scale(1.15);
}

.palette-controls {
  display: flex;
  gap: 8px;
}

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

.picker-label {
  font-size: 11px;
  color: var(--text-light);
}

.color-picker-input {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  background: none;
}

.color-picker-input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-picker-input::-webkit-color-swatch {
  border: 1.5px solid var(--border);
  border-radius: 50%;
}

.hex-input {
  width: 80px;
  padding: 6px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: monospace;
  color: var(--text);
  background: var(--surface);
}

.card-name-input {
  width: 100%;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 300;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  letter-spacing: 0.3px;
}

.card-name-input::placeholder {
  color: var(--text-lighter);
}

/* ===== Buttons ===== */
.btn-primary {
  padding: 10px 20px;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.8px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  align-self: flex-start;
}

.btn-primary:active {
  transform: scale(0.97);
}

.btn-small {
  padding: 6px 14px;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.5px;
  background: var(--surface-alt);
  color: var(--text-light);
  border: 1px solid var(--border);
  border-radius: 16px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-small:hover {
  background: var(--border);
}

.btn-danger {
  padding: 8px 16px;
  font-size: 11px;
  background: var(--danger-soft);
  color: var(--danger);
  border: none;
  border-radius: 16px;
  cursor: pointer;
}

.btn-secondary {
  padding: 8px 16px;
  font-size: 11px;
  background: var(--surface-alt);
  color: var(--text-light);
  border: 1px solid var(--border);
  border-radius: 16px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-secondary:hover {
  background: var(--border);
}

/* ===== Image Upload ===== */
.image-upload-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-lighter);
  transition: border-color 0.2s;
}

.upload-zone:hover {
  border-color: var(--accent);
}

.upload-zone p {
  font-size: 11px;
  letter-spacing: 0.5px;
}

/* ===== Create Image Tab ===== */
.create-image-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

.canvas-wrapper {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px;
  touch-action: none;
}

.canvas-wrapper canvas {
  display: block;
  border-radius: var(--radius-sm);
  image-rendering: pixelated;
  max-width: 100%;
  height: auto;
}

/* ===== Image Import Area ===== */
.image-import-area {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
}

.upload-zone-new {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
  height: 60px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-light);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.upload-zone-new:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.upload-zone-new.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.upload-zone-new svg {
  opacity: 0.7;
}

.upload-zone-label {
  font-size: 11px;
  letter-spacing: 0.3px;
  opacity: 0.8;
}

.image-info-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 4px 4px 0;
}

.image-file-name {
  font-size: 11px;
  color: var(--text-light);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

.btn-remove-image {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-light);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
  padding: 0;
}

.btn-remove-image:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.draw-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
  justify-content: center;
  align-items: center;
}

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

.tool-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.15s;
}

.tool-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

.mode-label {
  font-size: 10px;
  color: var(--text-light);
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.brush-select {
  padding: 4px 8px;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}

.draw-palette {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  padding: 8px;
  background: var(--surface);
  border-radius: 20px;
  width: 100%;
  position: relative;
}

.palette-dots-wrapper {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  flex: 1;
}

.draw-palette .color-dot {
  cursor: pointer;
}

.draw-palette .color-dot.active {
  box-shadow: 0 0 0 2px var(--accent);
  transform: scale(1.2);
}

/* Left: library picker button */
.palette-library-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1.5px solid rgba(0,0,0,0.08);
  background: var(--surface);
  color: var(--text-light);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.palette-library-btn:hover {
  background: var(--accent);
  color: #fff;
}

/* Right: circular color picker */
.draw-color-picker {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1.5px solid rgba(0,0,0,0.08);
  background: none;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
  overflow: hidden;
}
.draw-color-picker::-webkit-color-swatch-wrapper { padding: 0; }
.draw-color-picker::-webkit-color-swatch { border: none; border-radius: 50%; }

/* Dropdown panel */
.palette-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  min-width: 200px;
  max-height: 300px;
  overflow-y: auto;
}
.palette-dropdown.open { display: block; }

.palette-dropdown-title {
  font-size: 11px;
  color: var(--text-light);
  padding: 0 4px 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}

.palette-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.1s;
}
.palette-dropdown-item:hover { background: var(--hover-bg); }

.palette-dropdown-item .mini-strip {
  display: flex;
  gap: 3px;
}
.palette-dropdown-item .mini-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}
.palette-dropdown-item .mini-name {
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
}

.draw-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
}

.draw-actions .mode-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.draw-actions #btnSaveImage {
  align-self: center;
}

.draw-actions .btn-icon {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 16px;
  color: var(--text-light);
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}

.draw-actions .btn-icon:hover {
  background: var(--border);
}

.mode-toggle {
  display: inline-flex;
  gap: 4px;
}

.mode-btn {
  background: var(--surface-alt);
  color: var(--text-light);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 12px;
  font-size: 10px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.mode-btn:hover {
  border-color: var(--text);
  color: var(--text);
}

.mode-btn.active {
  background: var(--text);
  color: var(--surface);
  border-color: var(--text);
}

/* ===== Modals ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 1000;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(2px);
}

.modal-overlay.open {
  display: flex;
}

.modal-content {
  background: var(--surface);
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  border-radius: 20px 20px 0 0;
  padding: 20px;
  overflow-y: auto;
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

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

.modal-title {
  font-size: 14px;
  font-weight: 300;
  letter-spacing: 1px;
}

.btn-close {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text-light);
  cursor: pointer;
  padding: 4px 8px;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ===== Settings Lists (see below) ===== */
.empty-hint {
  font-size: 11px;
  color: var(--text-lighter);
  text-align: center;
  padding: 12px;
}

/* ===== Settings Floating Modal ===== */
#settingsModal.modal-overlay {
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
}

.modal-content.settings-floating {
  background: var(--surface);
  width: 100%;
  max-width: 420px;
  border-radius: var(--radius);
  max-height: 85vh;
  padding: 20px;
  overflow-y: auto;
  box-sizing: border-box;
}

/* ===== Settings Accordion ===== */
.settings-accordion {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.accordion-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: var(--surface-alt);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
}

.accordion-header:hover {
  background: var(--border);
}

.accordion-icon {
  font-size: 10px;
  transition: transform 0.2s;
  color: var(--text-lighter);
}

.accordion-header.open .accordion-icon {
  transform: rotate(180deg);
}

.accordion-body {
  padding: 12px;
  background: var(--surface);
}

.accordion-body.hidden {
  display: none;
}

/* ===== Settings Badge ===== */
.badge {
  margin-left: auto;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  flex-shrink: 0;
}

/* ===== Settings Tabs ===== */
.recycle-tabs,
.example-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.recycle-tab,
.example-tab {
  flex: 1;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text-light);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}

.recycle-tab.active,
.example-tab.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== Settings Lists ===== */
.recycle-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
}

.recycle-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  font-size: 11px;
  color: var(--text-light);
}

.recycle-item-strip {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.recycle-item-strip::-webkit-scrollbar {
  display: none;
}

.recycle-item-strip .dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
}

.recycle-item-row2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.recycle-item-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}

.recycle-item-name {
  font-size: 11px;
  color: var(--text-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recycle-item-meta {
  font-size: 9px;
  color: var(--text-lighter);
}

.recycle-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* Icon buttons for recycle bin */
.recycle-icon-btn {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s, transform 0.1s;
  padding: 0;
  flex-shrink: 0;
}

.recycle-icon-btn:active {
  transform: scale(0.9);
}

.recycle-icon-btn.restore {
  background: var(--accent-soft);
  color: var(--accent);
}

.recycle-icon-btn.delete {
  background: var(--danger-soft);
  color: var(--danger);
}

.recycle-icon-btn svg {
  width: 12px;
  height: 12px;
  pointer-events: none;
}

.restore-item button {
  font-size: 10px;
  padding: 4px 10px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
}

.restore-item .btn-restore {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ===== Settings Recycle Folder Card ===== */
.recycle-folder-card {
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 6px;
}

.recycle-folder-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.recycle-folder-header:hover {
  background: var(--border);
}

.recycle-folder-header .folder-expand-icon {
  font-size: 10px;
  color: var(--text-lighter);
  width: 12px;
  flex-shrink: 0;
  transition: transform 0.15s;
}

.recycle-folder-name {
  font-weight: 600;
  font-size: 12px;
  color: var(--text-light);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recycle-folder-count {
  font-size: 10px;
  color: var(--text-lighter);
  flex-shrink: 0;
  margin-right: 4px;
}

.recycle-folder-children {
  display: none;
  padding: 0 12px 10px 32px;
}

.recycle-folder-children.open {
  display: block;
}

.recycle-folder-children .recycle-image-item {
  background: var(--surface);
  border: 1px solid var(--border);
}

/* ===== Settings Recycle Image Item ===== */
.recycle-image-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-light);
}

.recycle-image-thumb {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--border);
}

.recycle-image-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.recycle-image-name {
  font-weight: 600;
  font-size: 12px;
  color: var(--text-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recycle-image-meta {
  font-size: 10px;
  color: var(--text-lighter);
}

/* ===== System Example Palette Items (mirrors .recycle-item) ===== */
.restore-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  font-size: 11px;
  color: var(--text-light);
}

.restore-item-strip {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.restore-item-strip::-webkit-scrollbar {
  display: none;
}

.restore-item-strip .dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
}

.restore-item-row2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.restore-item-info {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
}

.restore-item-name {
  font-size: 11px;
  color: var(--text-light);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.restore-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.restore-item.added {
  opacity: 0.5;
  pointer-events: none;
}

.restore-item .btn-added {
  font-size: 10px;
  padding: 4px 10px;
  border-radius: 12px;
  border: none;
  background: var(--border);
  color: var(--text-lighter);
  cursor: default;
}

/* ===== System Example Folders ===== */
.example-folder-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 8px;
}

.example-folder-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface-alt);
  cursor: pointer;
  font-size: 12px;
  transition: background 0.15s;
}

.example-folder-header:hover {
  background: var(--border);
}

.example-folder-header .folder-expand-icon {
  font-size: 10px;
  color: var(--text-lighter);
  transition: transform 0.2s;
}

.example-folder-header.open .folder-expand-icon {
  transform: rotate(90deg);
}

.example-folder-name {
  font-weight: 600;
  color: var(--text-light);
  flex: 1;
}

.example-folder-add-all {
  font-size: 10px;
  padding: 3px 10px;
  border-radius: 12px;
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
  transition: background 0.15s;
}

.example-folder-add-all:hover {
  background: var(--accent);
  color: #fff;
}

.example-folder-body {
  display: none;
  padding: 8px;
  background: var(--surface);
}

.example-folder-body.open {
  display: block;
}

.example-image-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.1s;
}

.example-image-item:hover {
  background: var(--surface-alt);
}

.example-image-thumb {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
}

.example-image-name {
  flex: 1;
  font-size: 11px;
  color: var(--text-light);
}

.example-image-add {
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 12px;
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}

.example-image-add:hover {
  background: var(--accent);
  color: #fff;
}

.example-image-add.added {
  background: var(--border);
  color: var(--text-lighter);
  cursor: default;
}

.restore-item-name {
  font-size: 12px;
  color: var(--text-light);
  flex: 1;
  padding: 0 8px;
}

.restore-item .btn-restore {
  font-size: 10px;
  padding: 3px 10px;
  border-radius: 12px;
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.restore-item .btn-restore:hover {
  background: var(--accent);
  color: #fff;
}

/* ===== Edit Modal Colors ===== */
.edit-colors-strip {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 10px;
  background: var(--surface-alt);
  border-radius: var(--radius);
  min-height: 50px;
  align-items: center;
}

.edit-colors-strip .color-dot {
  cursor: pointer;
}

.edit-colors-strip .color-dot.active {
  box-shadow: 0 0 0 2px var(--accent);
  transform: scale(1.15);
}

.edit-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* ===== Form Fields (shared) ===== */
.meta-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.meta-field label {
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 1px;
  color: var(--text-lighter);
  text-transform: uppercase;
}

.meta-field input,
.meta-field textarea {
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 300;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  resize: none;
  width: 100%;
}

.meta-field input::placeholder,
.meta-field textarea::placeholder {
  color: var(--text-lighter);
}

.meta-field textarea {
  min-height: 48px;
}

/* ===== Ref Card Overlay (centered) ===== */
.ref-card-overlay {
  align-items: center;
  justify-content: center;
  padding: 16px;
}

/* ===== Ref Card ===== */
.ref-card {
  background: var(--surface);
  width: 100%;
  max-width: 300px;
  border-radius: 20px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.10), 0 1px 4px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: calc(90vh - 32px);
  animation: cardIn 0.25s cubic-bezier(0.34, 1.2, 0.64, 1);
}

@keyframes cardIn {
  from { opacity: 0; transform: scale(0.92); }
  to   { opacity: 1; transform: scale(1); }
}

.ref-card-header {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 10px 12px 0;
  flex-shrink: 0;
}

.btn-ref-detail-settings {
  background: none;
  border: none;
  color: var(--text-lighter);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  transition: color 0.2s, background 0.2s;
  flex-shrink: 0;
}

.btn-ref-detail-settings:hover {
  color: var(--text-light);
  background: var(--surface-alt);
}

.ref-card-preview {
  width: calc(100% - 24px);
  aspect-ratio: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 6px 12px 0;
  border-radius: 14px;
  background: var(--surface-alt);
  flex-shrink: 0;
}

.ref-card-preview canvas,
.ref-card-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 14px;
}

.ref-card-meta {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ref-card-meta::-webkit-scrollbar { width: 3px; }
.ref-card-meta::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.meta-field-row {
  display: flex;
  gap: 8px;
}

.meta-field-row .meta-field {
  flex: 1;
}

.ref-card-actions {
  display: flex;
  gap: 8px;
  padding: 10px 12px 14px;
  flex-shrink: 0;
}

.ref-card-actions .btn-primary,
.ref-card-actions .btn-danger-outline {
  flex: 1;
  padding: 10px 12px;
  font-size: 11px;
  letter-spacing: 0.5px;
  text-align: center;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

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

.ref-card-actions .btn-primary:active {
  transform: scale(0.97);
}

.ref-card-actions .btn-danger-outline {
  background: transparent;
  color: var(--danger);
  border: 1.5px solid var(--danger);
}

.ref-card-actions .btn-danger-outline:active {
  background: var(--danger-soft);
  transform: scale(0.97);
}

/* ===== Ref Detail Settings Menu ===== */
.ref-detail-settings-menu {
  position: fixed;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  border: 1px solid var(--border);
  z-index: 1100;
  min-width: 160px;
  max-width: calc(100vw - 16px);
  max-height: calc(100vh - 16px);
  overflow-y: auto;
  animation: fadeIn 0.15s ease;
}

/* ===== Folder Picker Modal ===== */
.folder-picker-content {
  max-height: 60vh;
}

.folder-picker-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.folder-picker-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  cursor: pointer;
  transition: background 0.15s;
  font-size: 12px;
  color: var(--text-light);
}

.folder-picker-item:hover {
  background: var(--accent-soft);
}

.folder-picker-item.selected {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ===== Library Import Modal (Create Image) ===== */
.upload-zone-library {
  border-style: dashed;
}

.library-import-content {
  max-width: 560px;
}

.library-import-folder-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.library-import-folder-tab {
  padding: 6px 12px;
  font-size: 11px;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--text-light);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.library-import-folder-tab:hover {
  background: var(--accent-soft);
}

.library-import-folder-tab.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.library-import-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  max-height: 50vh;
  overflow-y: auto;
  padding: 4px;
}

.library-import-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px;
  border-radius: var(--radius);
  background: var(--surface-alt);
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}

.library-import-card:hover {
  border-color: var(--accent-soft);
}

.library-import-card.selected {
  border-color: var(--accent);
  transform: scale(1.02);
}

.library-import-thumb {
  width: 96px;
  height: 96px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
}

.library-import-thumb canvas,
.library-import-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.library-import-card .library-import-name {
  font-size: 11px;
  color: var(--text-light);
  text-align: center;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.library-import-empty {
  padding: 30px 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-lighter);
}

.library-import-empty.hidden {
  display: none;
}

.palette-export-hint {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--text-light);
  line-height: 1.5;
}

/* ===== Utility ===== */
.hidden {
  display: none !important;
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .upload-zone-label {
    font-size: 10px;
  }
}

@media (max-width: 320px) {
  .ref-img-card {
    width: 100px;
    height: 100px;
  }
  .color-dot {
    width: 20px;
    height: 20px;
  }
  .canvas-wrapper canvas {
    width: 260px;
    height: 260px;
  }
  .upload-zone-label {
    font-size: 10px;
  }
}

@media (min-width: 400px) {
  .canvas-wrapper canvas {
    width: 300px;
    height: 300px;
  }
}

/* ===== Save Image Modal Form Elements ===== */
.modal-form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-form-row {
  display: flex;
  gap: 12px;
}

.modal-form-row .modal-form-group {
  flex: 1;
}

.modal-label {
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.8px;
  color: var(--text-light);
  text-transform: uppercase;
}

.modal-input,
.modal-textarea,
.modal-select {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  padding: 8px 12px;
  width: 100%;
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.15s;
}

.modal-input:focus,
.modal-textarea:focus,
.modal-select:focus {
  border-color: var(--accent);
}

.modal-textarea {
  resize: none;
  line-height: 1.4;
}

.modal-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23888' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.modal-actions .btn-primary {
  padding: 8px 20px;
}

/* ===== Global Color Picker Modal ===== */
.color-picker-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  align-items: center;
  justify-content: center;
}
.color-picker-modal.open { display: flex; }

.cpm-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.3);
}

.cpm-panel {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  width: 280px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}

.cpm-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.cpm-title { font-size: 13px; font-weight: 500; color: var(--text); }
.cpm-close {
  background: none; border: none; font-size: 18px; cursor: pointer;
  color: var(--text-light); line-height: 1;
}
.cpm-close:hover { color: var(--text); }

.cpm-gradient-area {
  position: relative;
  width: 220px;
  height: 140px;
  margin: 0 auto 10px;
}
#colorPickerCanvas {
  border-radius: 8px;
  cursor: crosshair;
  display: block;
  width: 220px;
  height: 140px;
}

.cpm-cursor {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.4), 0 2px 6px rgba(0,0,0,0.3);
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 2;
}

.cpm-preview-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.cpm-preview {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  flex-shrink: 0;
}
.cpm-hex {
  font-size: 12px;
  font-family: monospace;
  color: var(--text);
}

.cpm-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}
.cpm-tab {
  flex: 1;
  padding: 4px 0;
  font-size: 11px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-light);
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.cpm-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.cpm-modes { min-height: 80px; }
.cpm-mode { display: none; }
.cpm-mode.active { display: block; }

.cpm-slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.cpm-slider-row label {
  width: 14px;
  font-size: 11px;
  color: var(--text-light);
  flex-shrink: 0;
}
.cpm-slider-row input[type="range"] {
  flex: 1;
  height: 4px;
  accent-color: var(--accent);
}
.cpm-slider-row span {
  width: 28px;
  font-size: 11px;
  font-family: monospace;
  color: var(--text);
  text-align: right;
}

.cpm-hex-row { padding: 4px 0; }
.cpm-hex-row .hex-input { width: 100%; }

.cpm-confirm-row { margin-top: 10px; }
.cpm-confirm-row .btn-primary { width: 100%; }

.color-picker-trigger {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface);
  padding: 0;
  cursor: pointer;
  overflow: hidden;
  flex-shrink: 0;
  transition: border-color 0.15s;
}
.color-picker-trigger:hover { border-color: var(--accent); }

.picker-swatch {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

/* ===== Export Crop Preview Modal ===== */
#crop-preview-overlay button:first-child:hover {
  background: var(--border) !important;
}
#crop-preview-overlay button:last-child:hover {
  background: #6a93b2 !important;
}
