:root {
  --bg: #0f1220;
  --panel: #171b2e;
  --panel-2: #1e2338;
  --border: #2b3153;
  --text: #eef0fb;
  --text-dim: #9aa0c3;
  --accent: #7c6cff;
  --accent-2: #5ee6c2;
  --success: #34c98f;
  --danger: #ff6b6b;
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: linear-gradient(160deg, #0f1220 0%, #14182b 55%, #10131f 100%);
  color: var(--text);
  min-height: 100vh;
}

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.home-link {
  align-self: flex-start;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 4px;
}

.home-link:hover { color: var(--text); }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.site-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.brand-logo {
  height: 34px;
  width: auto;
  display: block;
  background: #fff;
  border-radius: 8px;
  padding: 4px 8px;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.site-nav a {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

.site-nav a:hover { color: var(--text); background: var(--panel-2); }

.site-nav a.active {
  color: white;
  background: linear-gradient(135deg, var(--accent), #9b8cff);
}

.header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-icon { font-size: 1.6rem; }

.tagline {
  color: var(--text-dim);
  margin: 0;
  font-size: 0.95rem;
  max-width: 520px;
}

.main {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 56px 24px;
  text-align: center;
  transition: border-color 0.2s ease, background 0.2s ease;
  cursor: pointer;
}

.drop-zone.dragover {
  border-color: var(--accent);
  background: var(--panel-2);
}

.drop-inner { display: flex; flex-direction: column; align-items: center; gap: 8px; }

.drop-icon { font-size: 2.6rem; margin-bottom: 4px; }

.drop-title { font-size: 1.1rem; font-weight: 600; margin: 0; }

.drop-sub { color: var(--text-dim); margin: 0; font-size: 0.85rem; }

.drop-hint { color: var(--text-dim); font-size: 0.8rem; margin-top: 10px; }

.btn {
  border: none;
  border-radius: 999px;
  padding: 12px 26px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease, box-shadow 0.12s ease;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #9b8cff);
  color: white;
  box-shadow: 0 8px 24px -8px rgba(124, 108, 255, 0.6);
}

.btn-success {
  background: linear-gradient(135deg, var(--success), var(--accent-2));
  color: #06251a;
  box-shadow: 0 8px 24px -8px rgba(52, 201, 143, 0.5);
}

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

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

.hidden { display: none !important; }

.workspace {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 720px) {
  .panels { grid-template-columns: 1fr; }
}

.step-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.step-indicator {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
}

.step-dot {
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-weight: 600;
}

.step-dot.active {
  background: linear-gradient(135deg, var(--accent), #9b8cff);
  border-color: transparent;
  color: white;
}

.step-arrow {
  color: var(--text-dim);
}

#edit-step,
#review-step {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.review-intro {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-dim);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}

.review-frame {
  min-height: 320px;
  max-height: 70vh;
}

.review-frame canvas {
  max-width: 100%;
  max-height: 70vh;
  display: block;
  object-fit: contain;
}

.review-meta {
  margin: 0;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* Without this, a grid item defaults to min-width/height: auto, so a
     zoomed (large, explicit-pixel-size) canvas inside would grow the whole
     panel — and the page — to fit it instead of being clipped and
     scrolled by .canvas-frame.zoomed below. */
  min-width: 0;
  min-height: 0;
}

.panel h3 {
  margin: 0;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

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

.zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}

.zoom-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  width: 24px;
  height: 24px;
  line-height: 1;
  border-radius: 50%;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.zoom-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }

.zoom-btn.zoom-fit {
  width: auto;
  min-width: 40px;
  border-radius: 999px;
  padding: 0 8px;
  font-size: 0.72rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.canvas-frame {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  min-height: 280px;
  max-height: 420px;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0b0d18;
}

.canvas-frame img,
.canvas-frame canvas {
  max-width: 100%;
  max-height: 420px;
  display: block;
  object-fit: contain;
}

.canvas-frame canvas {
  cursor: none;
  touch-action: none;
}

/* Zoomed: the canvas gets an explicit pixel size (set from JS) instead of
   auto-fitting, and the frame becomes a scrollable viewport onto it. */
.canvas-frame.zoomed {
  overflow: auto;
  align-items: flex-start;
  justify-content: flex-start;
}

.canvas-frame.zoomed canvas {
  max-width: none;
  max-height: none;
}

.brush-cursor {
  position: absolute;
  border: 2px solid white;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), inset 0 0 0 1px rgba(0, 0, 0, 0.6);
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 5;
}

.brush-cursor.mode-restore { border-color: var(--accent-2); }
.brush-cursor.mode-erase { border-color: #ff8a8a; }

.retouch-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.retouch-hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.retouch-hint strong { color: var(--text); }

.retouch-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.tool-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-2);
  padding: 4px 4px 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.tool-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.tool-btn.active {
  background: linear-gradient(135deg, var(--accent), #9b8cff);
  color: white;
}

.brush-size-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.btn-sm {
  padding: 8px 16px;
  font-size: 0.82rem;
}

.retouch-feedback {
  margin: 0;
  font-size: 0.82rem;
  color: #ffd76a;
  background: rgba(255, 215, 106, 0.1);
  border: 1px solid rgba(255, 215, 106, 0.3);
  border-radius: 8px;
  padding: 8px 12px;
}

.export-panel {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}

.export-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.export-field select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.85rem;
}

.export-checkbox {
  cursor: pointer;
}

.export-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.export-hint {
  display: block;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-dim);
}
.export-hint:empty { display: none; }

.checkerboard {
  background-image:
    linear-gradient(45deg, #2a2f4a 25%, transparent 25%),
    linear-gradient(-45deg, #2a2f4a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2f4a 75%),
    linear-gradient(-45deg, transparent 75%, #2a2f4a 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  background-color: #1c2036;
}

.result-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 0.9rem;
  text-align: center;
  padding: 0 20px;
}

.result-placeholder.hidden { display: none; }

.spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
  display: none;
}

.spinner.active { display: block; }

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

.progress-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.2s ease;
}

.progress-label {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
}

.actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.78rem;
}

.footer code {
  background: var(--panel-2);
  padding: 2px 6px;
  border-radius: 4px;
}

.legal-links {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 14px;
}

.legal-links a {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.76rem;
}

.legal-links a:hover {
  color: var(--text);
  text-decoration: underline;
}
