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

:root {
  --bg: #0d0d0f;
  --surface: #16181c;
  --surface2: #1e2027;
  --border: #2a2d38;
  --accent: #6c63ff;
  --accent2: #a78bfa;
  --text: #e8eaf0;
  --text-muted: #7b7f91;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 10px;
  --radius-lg: 16px;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  height: 58px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: .45rem;
  text-decoration: none;
  color: var(--text);
}

nav { display: flex; gap: .5rem; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .55rem 1.2rem;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all .15s;
  text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #5a52e0; transform: translateY(-1px); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); }
.btn-sm { padding: .35rem .8rem; font-size: 12px; }
.btn-danger { background: var(--danger); color: #fff; }
.run-btn { margin-top: 1.5rem; padding: .7rem 2rem; font-size: 14px; }

/* ── Drop zone ───────────────────────────────────────────────────────────── */
.drop-section { padding: 2rem; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 3rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
  background: var(--surface);
}
.dropzone:hover, .dropzone.drag-over {
  border-color: var(--accent);
  background: rgba(108,99,255,.06);
}
.drop-icon { font-size: 2.5rem; margin-bottom: .5rem; }
.dropzone p { color: var(--text-muted); }
.dropzone .sub { font-size: 12px; margin-top: .25rem; }
.link { color: var(--accent); cursor: pointer; text-decoration: underline; }

/* File list */
.file-list {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}
.file-chip {
  display: flex;
  align-items: center;
  gap: .4rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .3rem .75rem;
  font-size: 12px;
  max-width: 220px;
}
.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip button {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 14px; padding: 0; line-height: 1;
}
.file-chip button:hover { color: var(--danger); }

/* ── Workspace ───────────────────────────────────────────────────────────── */
.workspace { padding: 0 2rem 3rem; }

/* Tab bar */
.tab-bar {
  display: flex;
  gap: .25rem;
  overflow-x: auto;
  padding: .5rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
  scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }

.tab {
  padding: .5rem 1.1rem;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: all .15s;
}
.tab:hover { color: var(--text); background: var(--surface2); }
.tab.active { background: var(--accent); color: #fff; }

/* Panels */
.panel { display: none; }
.panel.active { display: block; }

.panel h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 1.2rem;
  color: var(--text);
}

/* Form grid */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.2rem;
  margin-bottom: .5rem;
}

.field { display: flex; flex-direction: column; gap: .4rem; }
.field label { font-size: 12px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .4px; }

.toggle-field { flex-direction: row; align-items: center; justify-content: space-between; }
.toggle-field > label:first-child { text-transform: none; font-size: 13px; color: var(--text); letter-spacing: 0; }

input[type="text"],
input[type="number"],
select,
textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: .55rem .8rem;
  font-size: 13px;
  outline: none;
  width: 100%;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

input[type="range"] {
  accent-color: var(--accent);
  width: 100%;
  height: 6px;
  cursor: pointer;
}

.color-input {
  width: 48px !important;
  height: 36px;
  padding: 2px;
  border-radius: var(--radius);
  cursor: pointer;
  flex-shrink: 0;
}

/* Toggle */
.toggle { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle span {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: .2s;
}
.toggle span::after {
  content: '';
  position: absolute;
  left: 3px; top: 3px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: .2s;
}
.toggle input:checked + span { background: var(--accent); }
.toggle input:checked + span::after { transform: translateX(18px); }

/* Checkbox group */
.checkbox-group { display: flex; flex-wrap: wrap; gap: .5rem; }
.checkbox-group label {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .35rem .75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
  transition: border-color .15s;
}
.checkbox-group label:hover { border-color: var(--accent); }
.checkbox-group input[type="checkbox"] { accent-color: var(--accent); }

/* Utilities */
.hidden { display: none !important; }
.row { display: flex; align-items: center; }
.gap-8 { gap: .5rem; }
.hint { font-size: 12px; color: var(--text-muted); margin-top: .25rem; }

/* ── Pipeline ─────────────────────────────────────────────────────────────── */
.pipeline-controls { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: 1rem; }
.pipeline-controls select { width: auto; }

#pipeline-ops { display: flex; flex-direction: column; gap: .75rem; }

.pipeline-step {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.pipeline-step-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .75rem;
}
.pipeline-step-header h4 { font-size: 13px; font-weight: 600; color: var(--accent2); }
.step-num {
  width: 22px; height: 22px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff;
  margin-right: .5rem; flex-shrink: 0;
}
.pipeline-step .form-grid { margin-bottom: 0; }

/* ── Results ──────────────────────────────────────────────────────────────── */
.results {
  margin-top: 2rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}
.results h3 { font-size: 1rem; font-weight: 700; margin-bottom: 1rem; }

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.result-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform .15s;
}
.result-card:hover { transform: translateY(-2px); }

.result-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  background: repeating-conic-gradient(#222 0% 25%, #1a1a1a 0% 50%) 0 0 / 16px 16px;
  display: block;
}

.result-card-body { padding: .75rem; }
.result-card-body p { font-size: 11px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-card-body a {
  display: inline-block;
  margin-top: .4rem;
  font-size: 12px;
  color: var(--accent2);
  text-decoration: none;
}
.result-card-body a:hover { text-decoration: underline; }

.result-zip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.zip-icon { font-size: 2rem; }

.result-error {
  background: rgba(239,68,68,.08);
  border: 1px solid rgba(239,68,68,.3);
  border-radius: var(--radius);
  padding: .75rem;
  font-size: 12px;
  color: var(--danger);
}

/* ── Loading ──────────────────────────────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(4px);
  z-index: 999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}
.spinner {
  width: 44px; height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-msg { color: var(--text-muted); font-size: 14px; }

/* ── Guided Mask Editor ───────────────────────────────────────────────────────── */
.mask-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.87);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.mask-inner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: min(980px, 97vw);
  max-height: 94vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.mask-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .8rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.mask-header h3 { font-size: .95rem; font-weight: 700; }
.mask-toolbar {
  display: flex; align-items: center; gap: .5rem;
  padding: .6rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap; flex-shrink: 0;
}
.tool-btn {
  padding: .35rem .85rem;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--surface2);
  color: var(--text); cursor: pointer;
  font-size: 12px; font-weight: 600;
  transition: all .15s; white-space: nowrap;
}
.tool-btn.active { border-color: var(--accent); background: rgba(108,99,255,.15); }
.tool-sep { width: 1px; height: 22px; background: var(--border); flex-shrink: 0; }

.mask-editor-body {
  display: flex; gap: .75rem;
  padding: .75rem;
  flex: 1; min-height: 0; overflow: hidden;
}
.mask-canvas-section {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
}
.mask-result-section {
  width: 240px; flex-shrink: 0; display: flex; flex-direction: column; gap: 0;
}
.mask-section-label {
  font-size: 11px; color: var(--text-muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: .4px; margin-bottom: .35rem;
}
.mask-canvas-wrap {
  flex: 1; overflow: auto; position: relative;
  background: repeating-conic-gradient(#1a1a1a 0% 25%, #222 0% 50%) 0 0 / 18px 18px;
  cursor: none; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  min-height: 180px;
}
#me-base-canvas {
  display: block; position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}
#me-ann-canvas {
  display: block; position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  cursor: none;
}
.mask-result-wrap {
  flex: 1; min-height: 150px;
  background: repeating-conic-gradient(#1a1a1a 0% 25%, #222 0% 50%) 0 0 / 14px 14px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius); overflow: hidden;
}
#me-result-canvas { max-width: 100%; max-height: 100%; display: block; }

#me-cursor {
  position: fixed; pointer-events: none;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.85);
  transform: translate(-50%, -50%);
  z-index: 300; opacity: 0;
  transition: border-color .1s, width .05s, height .05s;
}

/* ── Mode switcher ───────────────────────────────────────────────────────────── */
.mode-switcher {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
  margin-bottom: .25rem;
}
.mode-btn {
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  padding: .75rem 1rem;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  transition: all .15s;
}
.mode-btn span { font-weight: 400; font-size: 11px; color: var(--text-muted); }
.mode-btn:hover { border-color: var(--accent); color: var(--text); }
.mode-btn.active { border-color: var(--accent); background: rgba(108,99,255,.12); color: var(--text); }

/* scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
