:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-surface: #334155;
  --accent-color: #10b981;
  --accent-hover: #059669;
  --accent-glow: rgba(16, 185, 129, 0.25);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #475569;
  --danger: #ef4444;
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background-color: rgba(30, 41, 59, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #10b981, #06b6d4);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.logo-icon svg {
  width: 22px;
  height: 22px;
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-text h1 span {
  color: var(--accent-color);
}

.brand-text .tagline {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  gap: 10px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.btn-primary {
  background-color: var(--accent-color);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--accent-hover);
  box-shadow: 0 4px 12px var(--accent-glow);
}

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

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

.btn-secondary:hover {
  background-color: #3e4f68;
}

.btn-outline {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

.btn-outline:hover {
  color: var(--text-main);
  border-color: var(--text-muted);
}

/* Main Workspace */
.workspace {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: radial-gradient(circle at 50% 20%, #1e293b 0%, #0f172a 100%);
}

.stage {
  display: none;
  flex-direction: column;
  height: 100%;
  padding: 16px 24px;
  position: relative;
}

.stage.active {
  display: flex;
}

.stage-instructions {
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.viewport-box {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #000000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border-color);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

/* Stage 1: Camera */
.camera-box video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.camera-box canvas#cameraGuideOverlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.camera-status {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.camera-icon-pulse {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 3px solid var(--accent-color);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.9); opacity: 0.7; }
  50% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.7; }
}

.camera-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 16px 0 6px 0;
}

.btn-shutter {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: white;
  border: 4px solid var(--accent-color);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
  box-shadow: 0 0 20px var(--accent-glow);
}

.btn-shutter:hover {
  transform: scale(1.05);
}

.btn-shutter:active {
  transform: scale(0.95);
}

.shutter-inner {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background-color: var(--accent-color);
}

/* Stage 2: Crop Canvas */
.crop-box {
  position: relative;
  cursor: crosshair;
}

.canvas-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

#cropCanvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* Magnifying Loupe */
.loupe {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 3px solid var(--accent-color);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  background: #000;
  pointer-events: none;
  z-index: 20;
}

.loupe.hidden {
  display: none;
}

.loupe-crosshair {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.loupe-crosshair::before,
.loupe-crosshair::after {
  content: '';
  position: absolute;
  background: #10b981;
}

.loupe-crosshair::before {
  top: 0; left: 7px; width: 2px; height: 16px;
}

.loupe-crosshair::after {
  top: 7px; left: 0; width: 16px; height: 2px;
}

/* Stage 3: Enhance & Preview */
.preview-box canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.filter-selector {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 14px 0 6px 0;
  overflow-x: auto;
}

.filter-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 80px;
}

.filter-chip:hover {
  background: var(--bg-surface);
  color: var(--text-main);
  border-color: var(--text-muted);
}

.filter-chip.active {
  background: rgba(16, 185, 129, 0.15);
  border-color: var(--accent-color);
  color: var(--text-main);
}

.chip-preview {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
}

.original-swatch { background: linear-gradient(135deg, #f59e0b, #ef4444); }
.magic-swatch { background: linear-gradient(135deg, #10b981, #3b82f6); color: white; }
.bw-swatch { background: #000; color: #fff; border: 1px solid #fff; font-weight: bold; font-size: 0.65rem; }
.gray-swatch { background: linear-gradient(135deg, #e2e8f0, #475569); }
.lighten-swatch { background: #fef08a; color: #854d0e; }

/* Stage Toolbar */
.stage-toolbar {
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 12px 0 4px 0;
}

/* Bottom Multi-Page Tray */
.pages-tray {
  background-color: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: 12px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 170px;
}

.tray-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.tray-header h3 {
  font-size: 0.85rem;
  color: var(--text-main);
  font-weight: 600;
}

.tray-tip {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.thumbnail-list {
  display: flex;
  align-items: center;
  gap: 14px;
  overflow-x: auto;
  min-height: 85px;
  padding-bottom: 4px;
}

.empty-tray-msg {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
}

.page-thumb-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.page-thumb-card:hover {
  transform: translateY(-2px);
}

.page-thumb-card canvas {
  width: 60px;
  height: 80px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border-color);
  background: white;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.page-thumb-card.active canvas {
  border-color: var(--accent-color);
}

.thumb-badge {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 600;
}

.thumb-del-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  background: var(--danger);
  color: white;
  border-radius: 50%;
  border: none;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
