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

:root {
  --bg: #0a0a0f;
  --bg-card: #12121a;
  --bg-hover: #1a1a28;
  --border: #2a2a3d;
  --border-glow: #6c5ce7;
  --text: #e8e8f0;
  --text-dim: #8888a8;
  --accent: #6c5ce7;
  --accent-light: #a29bfe;
  --accent-glow: rgba(108, 92, 231, 0.3);
  --success: #00d2a0;
  --warning: #ffa502;
  --danger: #ff6b81;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

html { scroll-behavior: smooth; }

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

/* ===== ANIMATED BACKGROUND ===== */
.bg-grid {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image:
    radial-gradient(circle at 20% 50%, rgba(108, 92, 231, 0.08) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(0, 210, 160, 0.06) 0%, transparent 50%),
    radial-gradient(circle at 50% 80%, rgba(162, 155, 254, 0.05) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ===== HEADER ===== */
.header {
  position: relative;
  text-align: center;
  padding: 40px 20px 30px;
  z-index: 1;
}

.header-logo {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}

.header-logo svg {
  width: 48px;
  height: 48px;
  filter: drop-shadow(0 0 20px var(--accent-glow));
}

.header h1 {
  font-size: 2.4rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent-light), var(--accent), var(--success));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.header p {
  color: var(--text-dim);
  font-size: 1.05rem;
  max-width: 500px;
  margin: 0 auto;
}

/* ===== MAIN LAYOUT ===== */
.app-container {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px 60px;
}

/* ===== DROP ZONE ===== */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 60px 40px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  background: var(--bg-card);
  position: relative;
  overflow: hidden;
}

.drop-zone::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(135deg, var(--accent-glow), transparent);
  opacity: 0;
  transition: opacity 0.3s;
}

.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--bg-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 32px var(--accent-glow);
}

.drop-zone:hover::before, .drop-zone.drag-over::before {
  opacity: 1;
}

.drop-zone-content {
  position: relative;
  z-index: 1;
}

.drop-zone svg {
  width: 64px;
  height: 64px;
  color: var(--accent);
  margin-bottom: 16px;
  opacity: 0.7;
}

.drop-zone h3 {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.drop-zone p {
  color: var(--text-dim);
  font-size: 0.9rem;
}

.drop-zone .btn-browse {
  display: inline-block;
  margin-top: 16px;
  padding: 10px 28px;
  background: var(--accent);
  color: #fff;
  border-radius: 50px;
  font-weight: 600;
  font-size: 0.95rem;
  transition: var(--transition);
  border: none;
  cursor: pointer;
}

.drop-zone .btn-browse:hover {
  background: var(--accent-light);
  transform: scale(1.05);
}

/* ===== WORKSPACE (after upload) ===== */
.workspace {
  display: none;
  gap: 24px;
  margin-top: 24px;
}

.workspace.active {
  display: grid;
  grid-template-columns: 1fr 340px;
}

/* ===== PREVIEW PANEL ===== */
.preview-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.preview-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
}

.btn-new {
  padding: 6px 16px;
  border-radius: 50px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 0.8rem;
  cursor: pointer;
  transition: var(--transition);
}

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

.preview-canvas-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

/* Preview backgrounds */
.bg-checkerboard {
  background-image:
    linear-gradient(45deg, #1e1e2e 25%, transparent 25%),
    linear-gradient(-45deg, #1e1e2e 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1e1e2e 75%),
    linear-gradient(-45deg, transparent 75%, #1e1e2e 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-color: #14141e;
}

.bg-light {
  background: #ffffff !important;
}

.bg-dark {
  background: #0a0a0f !important;
}

.bg-toggle-bar {
  display: flex;
  gap: 6px;
  align-items: center;
}

.bg-toggle-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: var(--transition);
  padding: 0;
  position: relative;
}

.bg-toggle-btn:hover, .bg-toggle-btn.active {
  border-color: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

.bg-toggle-btn.btn-bg-light {
  background: #ffffff;
}

.bg-toggle-btn.btn-bg-dark {
  background: #0a0a0f;
}

.bg-toggle-btn.btn-bg-checker {
  background-image:
    linear-gradient(45deg, #ccc 25%, transparent 25%),
    linear-gradient(-45deg, #ccc 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ccc 75%),
    linear-gradient(-45deg, transparent 75%, #ccc 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0;
  background-color: #fff;
}

.preview-canvas-wrap img {
  max-width: 100%;
  max-height: 500px;
  object-fit: contain;
  image-rendering: auto;
}

/* Size previews */
.size-previews {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}

.size-preview {
  text-align: center;
}

.size-preview-img {
  border-radius: 4px;
  image-rendering: auto;
  background-image:
    linear-gradient(45deg, #1e1e2e 25%, transparent 25%),
    linear-gradient(-45deg, #1e1e2e 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1e1e2e 75%),
    linear-gradient(-45deg, transparent 75%, #1e1e2e 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0;
  background-color: #14141e;
}

.size-preview span {
  display: block;
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ===== CONTROLS PANEL ===== */
.controls-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  max-height: calc(100vh - 180px);
  position: sticky;
  top: 20px;
}

.controls-panel h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 8px;
}

/* Collapsible sections */
.ctrl-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
}

.ctrl-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  cursor: pointer;
  background: var(--bg);
  transition: var(--transition);
  user-select: none;
}

.ctrl-section-header:hover { background: var(--bg-hover); }

.ctrl-section-header h3 {
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ctrl-section-header h3 svg { display: none; }

.ctrl-section-header .chevron {
  width: 16px;
  height: 16px;
  transition: transform 0.2s;
  color: var(--text-dim);
}

.ctrl-section.open .chevron { transform: rotate(180deg); }

.ctrl-section-body {
  display: none;
  padding: 0 14px;
}

.ctrl-section.open .ctrl-section-body {
  display: block;
  padding: 12px 14px;
}

/* Form controls */
.ctrl-group {
  margin-bottom: 14px;
}

.ctrl-group:last-child { margin-bottom: 0; }

.ctrl-group label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ctrl-group input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  outline: none;
}

.ctrl-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 10px var(--accent-glow);
}

.ctrl-group input[type="number"],
.ctrl-group select {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: var(--transition);
}

.ctrl-group input[type="number"]:focus,
.ctrl-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.range-value {
  font-size: 0.85rem;
  color: var(--accent-light);
  font-weight: 600;
}

/* Toggle switch */
.toggle-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.toggle-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border);
  border-radius: 12px;
  transition: var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: var(--transition);
}

.toggle input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* Color picker button */
.color-picker-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
  width: 100%;
  color: var(--text);
  font-size: 0.85rem;
}

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

.color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 2px solid var(--border);
  flex-shrink: 0;
}

/* ===== ACTION BUTTONS ===== */
.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: auto;
  padding-top: 16px;
}

.btn-primary, .btn-secondary {
  padding: 12px 20px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.95rem;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #7c6cf0);
  color: #fff;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px var(--accent-glow);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

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

.btn-row {
  display: flex;
  gap: 10px;
}

.btn-row .btn-secondary { flex: 1; }

/* ===== LOADING ===== */
.spinner {
  display: none;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

.loading .spinner { display: inline-block; }
.loading .btn-text { display: none; }

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 30px;
  right: 30px;
  padding: 14px 24px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  z-index: 1000;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s ease;
}

.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--success); color: #000; }
.toast.error { background: var(--danger); color: #fff; }

/* ===== COLOR PICKER OVERLAY ===== */
.color-picker-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  z-index: 500;
  align-items: center;
  justify-content: center;
}

.color-picker-overlay.active {
  display: flex;
}

.color-picker-modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  max-width: 400px;
}

.color-picker-modal p {
  color: var(--text-dim);
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.color-picker-modal canvas {
  cursor: crosshair;
  border-radius: var(--radius-sm);
  max-width: 100%;
}

.color-picker-modal .btn-row {
  margin-top: 16px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .workspace.active {
    grid-template-columns: 1fr;
  }
  .controls-panel {
    position: static;
    max-height: none;
  }
}

@media (max-width: 600px) {
  .header h1 { font-size: 1.8rem; }
  .drop-zone { padding: 40px 20px; }
  .preview-canvas-wrap { min-height: 250px; }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* File info bar */
.file-info {
  display: flex;
  gap: 20px;
  padding: 10px 16px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: var(--text-dim);
}

.file-info span { display: flex; align-items: center; gap: 4px; }
.file-info strong { color: var(--text); font-weight: 600; }

/* Quick presets */
.presets-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.preset-chip {
  padding: 6px 14px;
  border-radius: 50px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.preset-chip:hover, .preset-chip.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

/* Crop overlay */
.crop-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  cursor: crosshair;
  display: none;
  z-index: 10;
}

.crop-overlay.active { display: block; }

.crop-rect {
  position: absolute;
  border: 2px solid var(--accent);
  background: rgba(108, 92, 231, 0.15);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
}
