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

:root {
  --bg:          #f0f2f5;
  --surface:     #ffffff;
  --border:      #e0e4ea;
  --accent:      #4f6ef7;
  --accent-dark: #3a55d4;
  --text:        #1a1d23;
  --text-muted:  #6b7280;
  --radius:      10px;
  --shadow:      0 2px 8px rgba(0,0,0,.08);
  --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ── App shell ─────────────────────────────────────────────────────────────── */
.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

/* ── Header ────────────────────────────────────────────────────────────────── */
.header {
  margin-bottom: 28px;
}

.header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
}

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

.header p {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* ── Card ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 20px 24px;
  margin-bottom: 20px;
}

.card h2 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: 14px;
}

/* ── Drop zone ─────────────────────────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 36px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  background: #f8f9fb;
  user-select: none;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--accent);
  background: #eef1fe;
}

.drop-zone .icon {
  font-size: 36px;
  margin-bottom: 10px;
  display: block;
}

.drop-zone p {
  font-size: 13px;
  color: var(--text-muted);
}

.drop-zone p strong {
  color: var(--accent);
}

/* ── Controls ──────────────────────────────────────────────────────────────── */
.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 16px;
}

.control-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-row label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.slider-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.slider-wrap input[type=range] {
  flex: 1;
  accent-color: var(--accent);
  height: 4px;
  cursor: pointer;
}

.slider-val {
  min-width: 32px;
  text-align: right;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 7px;
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s, opacity .12s, transform .08s;
}

.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

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

.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }

.btn-outline {
  background: transparent;
  color: var(--accent);
  border: 1.5px solid var(--accent);
}

.btn-outline:hover:not(:disabled) { background: #eef1fe; }

.convert-wrap {
  margin-top: 18px;
  display: flex;
  justify-content: flex-end;
}

/* ── Progress ──────────────────────────────────────────────────────────────── */
.progress-wrap {
  margin-top: 12px;
}

.progress-track {
  height: 5px;
  background: var(--border);
  border-radius: 9px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 9px;
  transition: width .2s ease;
  width: 0%;
}

.progress-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 5px;
}

/* ── Preview section ───────────────────────────────────────────────────────── */
.preview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.preview-grid--two {
  grid-template-columns: 1fr 1fr;
}

.preview-pane {
  background: #f7f8fa;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-pane img,
.preview-pane .svg-inner {
  width: 100%;
}

#stitch-canvas {
  width:100%;
  height:100%;
}

.preview-pane canvas:not(#stitch-canvas) {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.preview-pane .svg-inner svg {
  width: 100%;
  height: 100%;
}

.preview-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 8px;
}

.preview-col {
  display: flex;
  flex-direction: column;
}

/* ── Stats bar ─────────────────────────────────────────────────────────────── */
.stats {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

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

/* ── Palette ───────────────────────────────────────────────────────────────── */
.palette {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.swatch-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.swatch {
  display: inline-block;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,.1);
  flex-shrink: 0;
}

.swatch-label {
  font-size: 11px;
  font-family: monospace;
  color: var(--text-muted);
}

/* ── Download row ──────────────────────────────────────────────────────────── */
.download-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ── Editor ────────────────────────────────────────────────────────────────── */
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.editor-toolbar-spacer {
  flex: 1;
}

.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
}

.editor-nudge-group {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}

.btn-xs {
  padding: 3px 8px;
  font-size: 11px;
  line-height: 1;
  min-width: 28px;
}

.editor-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 16px;
  min-height: 500px;
}

.editor-sidebar {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8f9fb;
  padding: 8px;
  overflow-y: auto;
  max-height: 500px;
}

.editor-layer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .1s;
  margin-bottom: 2px;
}

.editor-layer:hover {
  background: #eef1fe;
}

.editor-layer--hidden {
  opacity: 0.4;
}

.editor-layer--dragover {
  border-top: 2px solid var(--accent);
}

.editor-layer-swatch {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,.1);
  flex-shrink: 0;
}

.editor-layer-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1;
}

.editor-layer-hex {
  font-size: 12px;
  font-weight: 600;
  font-family: monospace;
  color: var(--text);
}

.editor-layer-count {
  font-size: 10px;
  color: var(--text-muted);
}

.editor-layer-vis {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 2px;
  opacity: 0.6;
}

.editor-layer-vis:hover {
  opacity: 1;
}

.editor-canvas-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafafa;
  overflow: hidden;
  position: relative;
}

.editor-canvas-wrap svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  .preview-grid { grid-template-columns: 1fr; }
  .controls { grid-template-columns: 1fr; }
}
