:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #1f2937;
  --bg-input: #111827;
  --border: #374151;
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --accent: #10b981;
  --accent-hover: #059669;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --warning: #f59e0b;
}

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

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

/* Stepper */
.stepper { display: flex; align-items: center; justify-content: center; gap: 0; padding: 1.5rem 0; }
.step-item { display: flex; align-items: center; gap: 0.5rem; }
.step-circle {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.875rem; font-weight: 600;
  background: var(--bg-card); color: var(--text-secondary); border: 2px solid var(--border);
  transition: all 0.3s;
}
.step-circle.active { background: var(--accent); color: white; border-color: var(--accent); }
.step-circle.completed { background: var(--accent); color: white; border-color: var(--accent); }
.step-label { font-size: 0.875rem; color: var(--text-secondary); }
.step-label.active { color: var(--text-primary); font-weight: 600; }
.step-line { width: 80px; height: 2px; background: var(--border); margin: 0 0.5rem; }
.step-line.active { background: var(--accent); }

/* Cards */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 0.75rem; padding: 1.5rem; margin-bottom: 1rem;
  position: relative;
}

/* Inputs */
input[type="text"], textarea, select {
  width: 100%; padding: 0.75rem 1rem;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 0.5rem; color: var(--text-primary);
  font-family: 'Inter', sans-serif; font-size: 0.9rem;
  transition: border-color 0.2s;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent);
}
textarea { resize: vertical; min-height: 80px; }

label { display: block; font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 0.375rem; }

/* Buttons */
.btn {
  padding: 0.75rem 1.5rem; border-radius: 0.5rem; font-weight: 600;
  cursor: pointer; border: none; font-size: 0.95rem;
  transition: all 0.2s; display: inline-flex; align-items: center; gap: 0.5rem;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-secondary { background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-full { width: 100%; justify-content: center; }

/* Badge */
.badge {
  display: inline-block; padding: 0.25rem 0.75rem;
  border-radius: 9999px; font-size: 0.75rem; font-weight: 600;
}
.badge-accent { background: var(--accent); color: white; }
.badge-danger { background: var(--danger); color: white; }
.badge-warning { background: var(--warning); color: #1a1a1a; }

/* Progress bar */
.progress-bar {
  width: 100%; height: 24px; background: var(--bg-input);
  border-radius: 12px; overflow: hidden; position: relative;
}
.progress-fill {
  height: 100%; background: var(--accent);
  border-radius: 12px; transition: width 0.5s ease;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 600; color: white; min-width: 40px;
}

/* Image grid */
.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.image-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 0.5rem; overflow: hidden;
}
.image-card img { width: 100%; aspect-ratio: 16/9; object-fit: contain; background: var(--bg-input); display: block; }
.image-placeholder {
  width: 100%; aspect-ratio: 16/9;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-input); color: var(--text-secondary); font-size: 2rem;
}
.image-card-body { padding: 0.75rem; }
.image-card-title { font-size: 0.875rem; font-weight: 600; margin-bottom: 0.5rem; }

/* Chapter hierarchy */
.chapter-header {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1rem; margin-bottom: 0.5rem; margin-top: 1.5rem;
  background: linear-gradient(135deg, var(--bg-secondary), var(--bg-card));
  border-left: 4px solid var(--accent); border-radius: 0.5rem;
}
.chapter-header:first-child { margin-top: 0; }
.chapter-badge {
  background: var(--accent); color: white; padding: 0.2rem 0.6rem;
  border-radius: 4px; font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
  white-space: nowrap;
}
.chapter-title-input {
  background: transparent !important; border: none !important;
  font-size: 1.1rem !important; font-weight: 700 !important; color: var(--text-primary) !important;
  padding: 0.25rem !important; flex: 1;
}
.chapter-title-input:focus { border-bottom: 2px solid var(--accent) !important; border-radius: 0 !important; }
.slide-indent { margin-left: 1.5rem; border-left: 2px solid var(--border); }

/* Collapsible */
.collapsible-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.75rem 1rem; background: var(--accent); color: white;
  border-radius: 0.5rem; cursor: pointer; font-weight: 600; font-size: 0.9rem;
}
.collapsible-header .arrow { transition: transform 0.3s; }
.collapsible-header.open .arrow { transform: rotate(180deg); }
.collapsible-body { overflow: hidden; transition: max-height 0.3s ease; max-height: 0; }
.collapsible-body.open { max-height: 2000px; }

/* Error panel */
.error-panel {
  background: rgba(239, 68, 68, 0.1); border: 1px solid var(--danger);
  border-radius: 0.5rem; padding: 1rem; margin-bottom: 1rem;
}

/* Step panels */
.step-panel { display: none; }
.step-panel.active { display: block; }

/* Summary table */
.summary-table {
  width: 100%; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 0.5rem; overflow: hidden;
}
.summary-table td, .summary-table th {
  padding: 0.75rem 1rem; text-align: center;
  border-bottom: 1px solid var(--border);
}
.summary-table th { color: var(--text-secondary); font-weight: 400; font-size: 0.8rem; }
.summary-table td { font-weight: 600; }

/* Preview cards */
.preview-card {
  display: flex; gap: 1rem; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: 0.5rem;
  overflow: hidden; margin-bottom: 0.75rem;
}
.preview-card img { width: 240px; aspect-ratio: 16/9; object-fit: cover; flex-shrink: 0; }
.preview-card-body { padding: 0.75rem; flex: 1; overflow: hidden; }
.preview-card-title { font-weight: 700; margin-bottom: 0.5rem; }
.preview-card-note { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.5; }

/* Dark mode toggle */
.dark-toggle {
  position: fixed; top: 1rem; right: 1rem;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 50%; width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 1.2rem; z-index: 50;
}

/* Delete button on section cards */
.delete-btn {
  position: absolute; top: 0.75rem; right: 0.75rem;
  background: var(--danger); border: none; color: white;
  width: 28px; height: 28px; border-radius: 4px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem;
}
.delete-btn:hover { background: var(--danger-hover); }

/* Spinner */
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3); border-top-color: white;
  border-radius: 50%; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Session ID */
.session-id { text-align: center; font-size: 0.75rem; color: var(--text-secondary); padding: 1rem 0; }

/* Style Library */
.style-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.style-card {
  background: var(--bg-card); border: 2px solid var(--border);
  border-radius: 0.75rem; overflow: hidden; cursor: pointer;
  transition: border-color 0.2s, transform 0.2s; position: relative;
}
.style-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.style-card.selected { border-color: var(--accent); box-shadow: 0 0 12px rgba(16,185,129,0.3); }
.style-previews {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px;
  height: 120px; overflow: hidden;
}
.style-previews img { width: 100%; height: 120px; object-fit: cover; }
.style-no-preview {
  grid-column: 1/-1; display: flex; align-items: center; justify-content: center;
  background: var(--bg-input); color: var(--text-secondary); font-size: 0.8rem;
}
.style-card-name { padding: 0.6rem 0.75rem; font-weight: 600; font-size: 0.9rem; }
.style-selected-badge {
  position: absolute; top: 0.5rem; right: 0.5rem;
  background: var(--accent); color: white; padding: 0.2rem 0.5rem;
  border-radius: 4px; font-size: 0.7rem; font-weight: 700;
}

/* Style Manager Modal */
.style-modal {
  display: none; position: fixed; inset: 0; z-index: 900;
  background: rgba(0,0,0,0.8);
  overflow-y: auto;
}
.style-modal.open { display: flex; justify-content: center; padding: 2rem; }
.style-modal-content {
  background: var(--bg-primary); border: 1px solid var(--border);
  border-radius: 1rem; width: 100%; max-width: 800px;
  padding: 2rem; position: relative; align-self: flex-start;
}
.style-modal-close {
  position: absolute; top: 1rem; right: 1.5rem;
  background: none; border: none; color: var(--text-secondary);
  font-size: 1.5rem; cursor: pointer;
}
.style-modal-close:hover { color: var(--text-primary); }

/* Lightbox */
.lightbox {
  display: none; position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.9); align-items: center; justify-content: center;
  cursor: zoom-out;
}
.lightbox.open { display: flex; }
.lightbox img {
  max-width: 90vw; max-height: 90vh; object-fit: contain;
  border-radius: 0.5rem; box-shadow: 0 0 40px rgba(0,0,0,0.5);
}
.lightbox-close {
  position: absolute; top: 1rem; right: 1.5rem;
  background: none; border: none; color: white;
  font-size: 2rem; cursor: pointer; z-index: 1001;
}
.lightbox-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  background: rgba(255,255,255,0.15); border: none; color: white;
  font-size: 2rem; padding: 0.75rem 1rem; cursor: pointer; z-index: 1001;
  border-radius: 0.5rem; transition: background 0.2s;
}
.lightbox-nav:hover { background: rgba(255,255,255,0.3); }
.lightbox-prev { left: 1rem; }
.lightbox-next { right: 1rem; }
.lightbox-counter {
  position: absolute; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  color: white; background: rgba(0,0,0,0.6); padding: 0.5rem 1.25rem;
  border-radius: 2rem; font-size: 0.9rem; white-space: nowrap; z-index: 1001;
}
.image-card img, .preview-card img { cursor: zoom-in; }

/* Responsive */
@media (max-width: 640px) {
  .image-grid { grid-template-columns: 1fr; }
  .preview-card { flex-direction: column; }
  .preview-card img { width: 100%; }
  .step-line { width: 40px; }
}
