/* PixelForge — Design System */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ─── CSS Custom Properties (Dark Theme Default) ─── */
:root, [data-theme="dark"] {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-tertiary: #252540;
  --bg-glass: rgba(26, 26, 46, 0.85);
  --bg-glass-hover: rgba(37, 37, 64, 0.9);
  --text-primary: #e8e8f0;
  --text-secondary: #a0a0b8;
  --text-muted: #6b6b80;
  --accent: #7c5cfc;
  --accent-hover: #9b7fff;
  --accent-glow: rgba(124, 92, 252, 0.3);
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --border: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.15);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --transition: 0.2s ease;
}

[data-theme="light"] {
  --bg-primary: #f0f0f5;
  --bg-secondary: #ffffff;
  --bg-tertiary: #e8e8f0;
  --bg-glass: rgba(255, 255, 255, 0.9);
  --bg-glass-hover: rgba(240, 240, 245, 0.95);
  --text-primary: #1a1a2e;
  --text-secondary: #555570;
  --text-muted: #8888a0;
  --accent: #6c4ce6;
  --accent-hover: #5a38d4;
  --accent-glow: rgba(108, 76, 230, 0.2);
  --border: rgba(0, 0, 0, 0.08);
  --border-hover: rgba(0, 0, 0, 0.15);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.15);
}

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

html { font-size: 14px; }

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background var(--transition), color var(--transition);
}

/* ─── Top Bar ─── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 52px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--accent);
}

.topbar-logo svg { width: 24px; height: 24px; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition);
}

.topbar-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); border-color: var(--border-hover); }
.topbar-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.topbar-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ─── Landing View ─── */
.landing-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 80px 20px 40px;
}

.landing-view.hidden { display: none; }

.landing-title {
  font-size: 3rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #e879f9, #fb923c);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 12px;
}

.landing-subtitle {
  color: var(--text-secondary);
  font-size: 1.1rem;
  margin-bottom: 40px;
}

.drop-zone {
  width: 100%;
  max-width: 560px;
  border: 2px dashed var(--border-hover);
  border-radius: var(--radius);
  padding: 60px 40px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  background: var(--bg-secondary);
}

.drop-zone:hover, .drop-zone.drag-active {
  border-color: var(--accent);
  background: var(--bg-tertiary);
  box-shadow: 0 0 30px var(--accent-glow);
  transform: scale(1.01);
}

.drop-zone-icon { font-size: 3rem; margin-bottom: 16px; display: block; }
.drop-zone-text { color: var(--text-secondary); font-size: 1rem; margin-bottom: 8px; }
.drop-zone-hint { color: var(--text-muted); font-size: 0.85rem; }

.drop-zone .upload-btn {
  margin-top: 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 28px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all var(--transition);
}

.drop-zone .upload-btn:hover { background: var(--accent-hover); transform: translateY(-1px); }

/* ─── Editor View ─── */
.editor-view {
  display: none;
  padding-top: 52px;
  height: 100vh;
}

.editor-view.visible { display: flex; }

/* ─── Sidebar ─── */
.sidebar {
  width: 300px;
  min-width: 300px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 52px);
  overflow: hidden;
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0;
  overflow-x: auto;
  flex-shrink: 0;
}

.sidebar-tab {
  flex: 1;
  padding: 10px 4px;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: inherit;
}

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

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.sidebar-content::-webkit-scrollbar { width: 4px; }
.sidebar-content::-webkit-scrollbar-track { background: transparent; }
.sidebar-content::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 2px; }

.sidebar-panel { display: none; }
.sidebar-panel.active { display: block; }

/* ─── Sliders ─── */
.slider-group { margin-bottom: 16px; }

.slider-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.slider-icon { font-size: 0.9rem; width: 20px; text-align: center; }
.slider-label { font-size: 0.85rem; color: var(--text-secondary); flex: 1; }
.slider-value {
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 600;
  min-width: 32px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.pf-slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.pf-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 8px var(--accent-glow);
  transition: transform var(--transition);
}

.pf-slider::-webkit-slider-thumb:hover { transform: scale(1.2); }

.pf-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
  box-shadow: 0 0 8px var(--accent-glow);
}

.pf-slider-small { height: 3px; }
.pf-slider-small::-webkit-slider-thumb { width: 12px; height: 12px; }

/* ─── Preset Grid ─── */
.preset-card {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  width: calc(50% - 6px);
  margin-bottom: 12px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  transition: all var(--transition);
  background: var(--bg-tertiary);
}

.preset-card:nth-child(odd) { margin-right: 12px; }

.preset-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.preset-thumb {
  width: 100%;
  height: 60px;
  background-size: cover;
  background-position: center;
  background-color: var(--bg-primary);
  position: relative;
}

.preset-name {
  padding: 6px 8px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-align: center;
  width: 100%;
}

.fav-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,0.5);
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.fav-btn:hover, .fav-btn.active { color: #fbbf24; background: rgba(0,0,0,0.7); }

.ai-section-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
}

.ai-param {
  padding: 4px 8px 8px;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
}

.empty-favorites {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-favorites span { font-size: 2rem; display: block; margin-bottom: 12px; }
.empty-favorites p { font-size: 0.85rem; line-height: 1.6; }

/* ─── Main Canvas Area ─── */
.canvas-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  position: relative;
  overflow: hidden;
  min-width: 0;
}

.canvas-wrapper {
  position: relative;
  max-width: 90%;
  max-height: calc(100vh - 100px);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.canvas-wrapper canvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 120px);
  object-fit: contain;
}

#overlay-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: col-resize;
  pointer-events: none;
}

#overlay-canvas.comparison-active { pointer-events: auto; }

.canvas-placeholder {
  color: var(--text-muted);
  text-align: center;
  font-size: 1rem;
}

.editor-drop-zone {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  opacity: 0;
  pointer-events: none;
  background: rgba(15, 15, 26, 0.8);
  backdrop-filter: blur(8px);
  transition: opacity 0.3s ease;
}

.editor-drop-zone.drag-active {
  opacity: 1;
  pointer-events: auto;
}

/* ─── Right Panel ─── */
.right-panel {
  width: 260px;
  min-width: 260px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 52px);
  overflow: hidden;
}

.panel-section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.panel-section-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.panel-scrollable {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.panel-scrollable::-webkit-scrollbar { width: 4px; }
.panel-scrollable::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 2px; }

/* ─── Filter Stack ─── */
.stack-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-xs);
  background: var(--bg-tertiary);
  margin-bottom: 6px;
  transition: all var(--transition);
}

.stack-item:hover { background: var(--bg-glass-hover); }

.stack-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stack-name { flex: 1; font-size: 0.8rem; color: var(--text-secondary); }
.stack-value { font-size: 0.75rem; color: var(--accent); font-weight: 600; }

.stack-remove {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 2px 6px;
  border-radius: 4px;
  transition: all var(--transition);
}

.stack-remove:hover { color: var(--danger); background: rgba(248, 113, 113, 0.1); }

.empty-stack {
  text-align: center;
  padding: 24px 16px;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ─── History Controls ─── */
.history-controls {
  display: flex;
  gap: 6px;
  align-items: center;
}

.history-controls button {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
  transition: all var(--transition);
}

.history-controls button:hover:not(:disabled) { background: var(--bg-glass-hover); color: var(--text-primary); }
.history-controls button:disabled { opacity: 0.3; cursor: not-allowed; }

#history-counter {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: auto;
}

/* ─── Download Section ─── */
.download-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.download-row label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  min-width: 50px;
}

.pf-select, .download-row select {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: var(--radius-xs);
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.pf-select option { background: var(--bg-secondary); }

.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), #9b7fff);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 16px var(--accent-glow); }

.btn-danger {
  width: 100%;
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-weight: 500;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition);
  margin-top: 8px;
}

.btn-danger:hover { background: rgba(248, 113, 113, 0.1); }

.btn-sm {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  transition: all var(--transition);
}

.btn-sm:hover { background: var(--bg-glass-hover); color: var(--text-primary); }

/* ─── Batch Panel ─── */
.batch-panel {
  display: none;
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  max-height: 200px;
  overflow-y: auto;
}

.batch-panel.active { display: block; }

.batch-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.batch-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-xs);
  margin-bottom: 4px;
  font-size: 0.8rem;
  background: var(--bg-tertiary);
}

.batch-status { width: 16px; text-align: center; }
.batch-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); }
.status-done .batch-status { color: var(--success); }
.status-error .batch-status { color: var(--danger); }
.status-processing .batch-status { animation: spin 1s linear infinite; }

.batch-progress {
  width: 100%;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  margin: 8px 0;
  overflow: hidden;
}

#batch-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--success));
  border-radius: 2px;
  transition: width 0.3s ease;
  width: 0%;
}

.batch-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.batch-actions .btn-sm { flex: 1; text-align: center; }

/* ─── Toast Notifications ─── */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 0.85rem;
  color: var(--text-primary);
  transform: translateX(120%);
  transition: transform 0.3s ease;
  max-width: 320px;
}

.toast.show { transform: translateX(0); }
.toast-info { border-left: 3px solid var(--accent); }
.toast-success { border-left: 3px solid var(--success); }
.toast-warning { border-left: 3px solid var(--warning); }
.toast-error { border-left: 3px solid var(--danger); }

/* ─── Shortcuts Modal ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

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

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 420px;
  width: 90%;
  box-shadow: var(--shadow-lg);
}

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

.modal-header h3 { font-size: 1.1rem; font-weight: 600; }

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px;
}

.shortcut-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.shortcut-row:last-child { border-bottom: none; }

.shortcut-row kbd {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 8px;
  font-family: inherit;
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 600;
}

.shortcut-row span {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ─── Animations ─── */
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

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

.landing-view { animation: fadeInUp 0.6s ease; }

/* ─── Hidden Inputs ─── */
.hidden-input { display: none; }

/* ─── Responsive ─── */
@media (max-width: 1024px) {
  .sidebar { width: 240px; min-width: 240px; }
  .right-panel { width: 220px; min-width: 220px; }
}

@media (max-width: 768px) {
  .editor-view.visible { flex-direction: column; }
  .sidebar { width: 100%; min-width: unset; height: auto; max-height: 40vh; }
  .right-panel { width: 100%; min-width: unset; height: auto; max-height: 30vh; }
  .canvas-area { min-height: 300px; }
  .landing-title { font-size: 2rem; }
  .preset-card { width: calc(33.33% - 8px); }
  .preset-card:nth-child(odd) { margin-right: 0; }
  .preset-card:nth-child(3n+1), .preset-card:nth-child(3n+2) { margin-right: 8px; }
}

@media (max-width: 480px) {
  .topbar-actions .topbar-btn span { display: none; }
  .landing-title { font-size: 1.6rem; }
  .sidebar { max-height: 35vh; }
}