:root {
  --bg-primary: #f8f7f4;
  --bg-secondary: #ffffff;
  --bg-panel: #ffffff;
  --border: #e5e2dc;
  --text-primary: #1a1a1a;
  --text-secondary: #6b7c93;
  --accent: #f59e0b;
  --accent-hover: #d97706;
  --accent-light: rgba(245, 158, 11, 0.08);
  --input-bg: #f3f1ed;
  --success: #16a34a;
  --success-hover: #15803d;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 25px rgba(107, 124, 147, 0.15);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

.app {
  display: flex;
  width: 100%;
  height: 100%;
}

/* ── 3D Viewer ── */
.viewer-container {
  flex: 1;
  position: relative;
  background: #1a1a2e;
  border-radius: 0;
}

.viewer-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #8888aa;
}

.viewer-placeholder p { font-size: 1.2rem; }
.viewer-placeholder .hint { font-size: 0.85rem; margin-top: 8px; opacity: 0.6; }

/* ── Sidebar ── */
.sidebar {
  width: 380px;
  min-width: 380px;
  height: 100%;
  overflow-y: auto;
  background: var(--bg-primary);
  border-left: 1px solid var(--border);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.app-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--accent);
}

/* ── Panels ── */
.panel {
  background: var(--bg-panel);
  border-radius: 14px;
  padding: 20px;
  border: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.03);
}

#settingsPanels {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.panel-sub {
  margin-top: -14px;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  padding-top: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.panel-header .panel-title {
  margin-bottom: 0;
}

.step-badge {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.panel-tag {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-primary);
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.panel-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-primary);
  margin-bottom: 12px;
}

/* ── Model Selection ── */
.model-grid {
  display: flex;
  gap: 10px;
}

.model-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 18px 12px;
  border: 2px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  background: var(--bg-primary);
  transition: all 0.25s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.model-card:hover {
  border-color: var(--accent);
  background: var(--accent-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.model-card.selected {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15), var(--shadow-md);
}

.model-icon {
  font-size: 2rem;
  margin-bottom: 6px;
}

.model-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* ── Size Selection ── */
.size-grid {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.size-card {
  flex: 1 1 calc(33.333% - 4px);
  min-width: 0;
  padding: 10px 4px;
  border: 2px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  background: var(--bg-primary);
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.size-card:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.size-card.selected {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15);
  color: var(--accent-hover);
}

/* ── Advanced Settings ── */
.advanced-settings {
  margin-top: 14px;
  margin-bottom: 4px;
}

.advanced-settings summary {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px 0;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: color 0.2s;
}

.advanced-settings summary::-webkit-details-marker {
  display: none;
}

.advanced-settings summary::before {
  content: '\25B8';
  font-size: 0.7rem;
  transition: transform 0.2s;
}

.advanced-settings[open] summary::before {
  transform: rotate(90deg);
}

.advanced-settings summary:hover {
  color: var(--accent);
}

.advanced-settings-content {
  padding-top: 10px;
}

/* ── Drop Zones ── */
.drop-zone {
  border: 2px dashed rgba(0, 0, 0, 0.12);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s ease;
  background: var(--bg-primary);
}

.drop-zone:hover, .drop-zone.active {
  border-color: var(--accent);
  background: var(--accent-light);
}

.drop-zone-text { font-size: 0.85rem; color: var(--text-secondary); }
.file-info { font-size: 0.8rem; color: var(--accent-hover); margin-top: 8px; font-weight: 500; }

/* ── Image Previews ── */
.image-preview-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.image-preview-col { flex: 1; min-width: 0; }

.preview-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 4px;
}

.image-preview {
  width: 100%;
  max-height: 120px;
  object-fit: contain;
  border-radius: 6px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
}

/* ── Slider Groups ── */
.slider-group {
  padding: 12px;
  background: var(--bg-primary);
  border-radius: 10px;
  margin-bottom: 10px;
}

.slider-group-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-hover);
  margin-bottom: 10px;
}

/* ── Controls ── */
.control-group { margin-bottom: 14px; }
.control-group:last-child { margin-bottom: 0; }

.control-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.control-value { color: var(--text-primary); font-weight: 600; }

.control-hint {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 4px;
  opacity: 0.7;
}

input[type="range"] {
  width: 100%;
  height: 5px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 3px;
  outline: none;
  transition: background 0.2s;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(245, 158, 11, 0.4);
  transition: transform 0.15s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

/* ── Buttons ── */
.btn {
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  margin-top: 10px;
}

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35);
}

.btn-secondary {
  background: var(--success);
  color: white;
  box-shadow: 0 2px 8px rgba(22, 163, 74, 0.25);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--success-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(22, 163, 74, 0.3);
}

.btn-auto {
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--accent);
  margin-bottom: 14px;
}
.btn-auto:hover:not(:disabled) {
  background: var(--accent-light);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.2);
}

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

.btn.loading {
  position: relative;
  pointer-events: none;
  opacity: 0.7;
}

/* ── Export Info ── */
.export-info {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 8px;
  line-height: 1.5;
}

/* ── Light Toggle ── */
.light-toggle {
  position: absolute;
  bottom: 20px;
  left: 20px;
  padding: 10px 22px;
  background: rgba(245, 158, 11, 0.9);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  z-index: 10;
  backdrop-filter: blur(8px);
  transition: all 0.25s ease;
  box-shadow: 0 2px 10px rgba(245, 158, 11, 0.3);
}

.light-toggle:hover {
  background: rgba(217, 119, 6, 0.95);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(245, 158, 11, 0.4);
}

/* ── Status Bar ── */
.status-bar {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 20px;
  background: rgba(0, 0, 0, 0.7);
  color: #f0f0f0;
  border-radius: 8px;
  font-size: 0.85rem;
  z-index: 10;
  backdrop-filter: blur(8px);
  transition: opacity 0.4s ease;
}

.status-bar.success {
  background: rgba(22, 163, 74, 0.85);
}

.status-bar.error {
  background: rgba(239, 68, 68, 0.85);
}

.status-bar.fade-out {
  opacity: 0;
}

/* ── Text Input ── */
.text-input-group {
  position: relative;
}

.text-field {
  width: 100%;
  padding: 10px 12px;
  padding-right: 50px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--bg-primary);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s;
  resize: vertical;
  min-height: 42px;
  max-height: 120px;
}

.text-field:focus {
  border-color: var(--accent);
}

.char-count {
  position: absolute;
  right: 10px;
  top: 10px;
  font-size: 0.7rem;
  color: var(--text-secondary);
}

/* ── Font Selector ── */
.font-selector {
  position: relative;
}

.font-search {
  width: 100%;
  padding: 8px 12px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s;
  cursor: pointer;
}

.font-search:focus {
  border-color: var(--accent);
}

.font-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 280px;
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 4px;
  z-index: 100;
  box-shadow: var(--shadow-lg);
}

.font-dropdown.open {
  display: block;
}

.font-option {
  padding: 10px 12px;
  font-size: 1.05rem;
  line-height: 1.3;
  cursor: pointer;
  transition: background 0.15s;
}

.font-option:hover {
  background: var(--accent-light);
}

.font-option.selected {
  background: var(--accent-light);
  color: var(--accent-hover);
  font-weight: 600;
}

/* ── Text Canvas Preview ── */
.text-canvas-preview {
  margin-top: 10px;
  text-align: center;
}

.text-canvas-preview canvas {
  max-width: 100%;
  max-height: 100px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
}

/* ── Alignment Buttons ── */
.align-buttons {
  display: flex;
  gap: 0;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid var(--border);
}

.align-btn {
  flex: 1;
  padding: 7px 0;
  border: none;
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.align-btn:not(:last-child) {
  border-right: 1px solid var(--border);
}

.align-btn:hover {
  background: var(--accent-light);
}

.align-btn.selected {
  background: var(--accent);
  color: white;
  font-weight: 600;
}

/* ── Panel Subtitle & Divider ── */
.panel-divider {
  height: 1px;
  background: var(--border);
  margin: 14px 0;
}

.panel-subtitle {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

/* ── Loading Overlay ── */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.loading-overlay.active {
  display: flex;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: var(--bg-secondary);
  padding: 32px 48px;
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-primary);
}

/* ── Scrollbar ── */
.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

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

.sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* ── Image Delete Button ── */
.image-preview-row {
  position: relative;
}

.image-delete-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: #ef4444;
  color: white;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  transition: background 0.2s, transform 0.15s;
}

.image-delete-btn:hover {
  background: #dc2626;
  transform: scale(1.1);
}

/* ── Background Remove Button ── */
.btn-bg-remove {
  background: transparent;
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
  font-size: 0.78rem;
  padding: 7px 12px;
  margin-top: 8px;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.btn-bg-remove:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-light);
}

.btn-bg-remove:disabled {
  opacity: 0.5;
  cursor: wait;
}

/* ── Responsive Mobile Layout ── */
@media (max-width: 768px) {
  body {
    height: auto;
    overflow: auto;
  }

  .app {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
  }

  .viewer-container {
    flex: none;
    height: 45vh;
    width: 100%;
  }

  .sidebar {
    width: 100%;
    min-width: unset;
    height: auto;
    overflow-y: visible;
    border-left: none;
    border-top: 1px solid var(--border);
    padding: 20px 16px;
    gap: 16px;
  }

  .panel {
    padding: 16px;
    border-radius: 12px;
  }

  .model-card {
    padding: 16px 12px;
  }

  .slider-group {
    padding: 10px;
  }

  .control-group {
    margin-bottom: 18px;
  }

  .loading-content {
    padding: 24px 28px;
    max-width: 85vw;
  }

  /* Touch-friendly controls */
  input[type="range"]::-webkit-slider-thumb {
    width: 20px;
    height: 20px;
  }

  .btn {
    min-height: 44px;
  }

  .light-toggle {
    bottom: 12px;
    left: 12px;
    padding: 8px 16px;
  }

  .status-bar {
    top: 12px;
    font-size: 0.8rem;
    padding: 6px 14px;
  }
}
