:root {
  --bg: #15171c;
  --surface: #1d2027;
  --surface-2: #262a33;
  --surface-3: #2e333d;
  --border: #323742;
  --border-soft: #272b33;
  --text: #eceef2;
  --muted: #9aa1ad;
  --muted-2: #6b7280;
  --gold: #e8b04b;
  --gold-soft: rgba(232, 176, 75, 0.14);
  --gold-line: rgba(232, 176, 75, 0.4);
  --green: #4fb477;
  --red: #e06a5b;
  --shadow: 0 18px 50px -20px rgba(0, 0, 0, 0.7);
  --radius: 14px;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --display: 'Space Grotesk', system-ui, sans-serif;
  --body: 'Inter', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(232, 176, 75, 0.06), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button, input, select { font-family: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 6px; }

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 14px;
  padding: 14px clamp(16px, 4vw, 40px);
  background: rgba(21, 23, 28, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-soft);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand .mark {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: linear-gradient(160deg, var(--surface-3), var(--surface));
  border: 1px solid var(--border);
  display: grid; place-items: center;
}
.brand .mark svg { width: 20px; height: 20px; }
.brand h1 {
  font-family: var(--display);
  font-size: 1.06rem; font-weight: 600; letter-spacing: -0.01em; margin: 0;
}
.brand h1 b { color: var(--gold); font-weight: 600; }
.brand .tag { font-size: .7rem; color: var(--muted-2); letter-spacing: .04em; text-transform: uppercase; }
.spacer { flex: 1; }

.dest-pill {
  display: flex; align-items: center; gap: 9px;
  max-width: 320px;
  padding: 8px 12px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: .82rem; cursor: pointer; transition: border-color .15s, background .15s;
}
.dest-pill:hover { border-color: var(--gold-line); }
.dest-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted-2); flex: none; }
.dest-pill.connected .dot { background: var(--green); box-shadow: 0 0 0 3px rgba(79, 180, 119, .18); }
.dest-pill .dest-label { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dest-pill.connected .dest-label { color: var(--text); }
.dest-pill .dest-name { font-family: var(--mono); font-size: .78rem; }

/* ---------- Layout ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: clamp(18px, 3vw, 32px) clamp(16px, 4vw, 40px) 120px; }

.setup {
  display: grid; gap: 14px;
  grid-template-columns: 1.4fr 1fr 1fr;
  margin-bottom: 22px;
}
@media (max-width: 820px) { .setup { grid-template-columns: 1fr 1fr; } .setup .field-folder { grid-column: 1 / -1; } }
@media (max-width: 540px) { .setup { grid-template-columns: 1fr; } }

.field { display: flex; flex-direction: column; gap: 7px; }
.field label {
  font-size: .72rem; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); font-weight: 600;
}
.field .hint { font-size: .72rem; color: var(--muted-2); }
.input, .select {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); border-radius: 11px; padding: 12px 14px; font-size: .92rem;
  transition: border-color .15s, background .15s;
}
.input::placeholder { color: var(--muted-2); }
.input:focus, .select:focus { border-color: var(--gold-line); background: var(--surface-2); }
.select { appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239aa1ad' stroke-width='2.5'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 38px;
}
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* segmented quality toggle */
.seg { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 11px; padding: 4px; gap: 4px; }
.seg button {
  flex: 1; background: transparent; border: 0; color: var(--muted);
  padding: 9px 10px; border-radius: 8px; font-size: .82rem; font-weight: 500; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; transition: .15s;
}
.seg button small { font-size: .66rem; color: var(--muted-2); font-weight: 400; }
.seg button[aria-pressed="true"] { background: var(--gold-soft); color: var(--gold); }
.seg button[aria-pressed="true"] small { color: var(--gold); opacity: .8; }

/* ---------- Dropzone ---------- */
.dropzone {
  border: 1.5px dashed var(--border); border-radius: var(--radius);
  background: linear-gradient(180deg, var(--surface), rgba(29, 32, 39, 0.4));
  padding: clamp(28px, 6vw, 54px); text-align: center; cursor: pointer;
  transition: border-color .18s, background .18s, transform .18s;
  position: relative;
}
.dropzone:hover { border-color: var(--gold-line); }
.dropzone.drag { border-color: var(--gold); background: var(--gold-soft); transform: scale(1.005); }
.dropzone .dz-icon {
  width: 52px; height: 52px; margin: 0 auto 14px; border-radius: 14px;
  background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center;
}
.dropzone .dz-icon svg { width: 26px; height: 26px; stroke: var(--gold); }
.dropzone h2 { font-family: var(--display); font-weight: 500; font-size: 1.05rem; margin: 0 0 6px; }
.dropzone p { color: var(--muted); font-size: .86rem; margin: 0; }
.dropzone .browse { color: var(--gold); text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 22px 0 14px;
}
.count-chip {
  font-family: var(--mono); font-size: .82rem; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 7px 12px;
}
.count-chip b { color: var(--gold); }
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: 10px; font-size: .85rem; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px; transition: .15s;
}
.btn:hover { border-color: var(--gold-line); background: var(--surface-2); }
.btn svg { width: 16px; height: 16px; }
.btn.ghost { background: transparent; }
.btn.danger:hover { border-color: var(--red); color: var(--red); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary {
  margin-left: auto; background: var(--gold); color: #1a1206; border: 1px solid var(--gold);
  font-weight: 600; padding: 11px 20px; font-size: .9rem;
}
.btn-primary:hover { background: #f1bd5f; border-color: #f1bd5f; }
.btn-primary:disabled { background: var(--surface-2); color: var(--muted-2); border-color: var(--border); }
@media (max-width: 540px) { .btn-primary { margin-left: 0; width: 100%; justify-content: center; } }

/* ---------- Grid ---------- */
.grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.card {
  position: relative; border-radius: 12px; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
  aspect-ratio: 1 / 1; cursor: pointer; transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--gold-line); }
.card.selected { border-color: var(--gold); }
.card.selected::after { content: ''; position: absolute; inset: 0; box-shadow: inset 0 0 0 2px var(--gold); border-radius: 12px; pointer-events: none; }
.card img { width: 100%; height: 100%; object-fit: cover; display: block; background: var(--surface-2); }
.card .check {
  position: absolute; top: 9px; left: 9px; width: 24px; height: 24px; border-radius: 7px;
  background: rgba(21, 23, 28, 0.7); border: 1.5px solid rgba(255,255,255,.4);
  display: grid; place-items: center; backdrop-filter: blur(4px);
}
.card.selected .check { background: var(--gold); border-color: var(--gold); }
.card .check svg { width: 14px; height: 14px; stroke: #1a1206; opacity: 0; }
.card.selected .check svg { opacity: 1; }
/* sequence badge = the signature element */
.card .seq {
  position: absolute; top: 9px; right: 9px;
  font-family: var(--mono); font-size: .72rem; font-weight: 600;
  background: var(--gold); color: #1a1206; padding: 3px 7px; border-radius: 6px;
  opacity: 0; transform: translateY(-3px); transition: .15s;
  letter-spacing: .03em;
}
.card.selected .seq { opacity: 1; transform: none; }
.card .meta {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: linear-gradient(transparent, rgba(15, 16, 20, 0.92));
  padding: 22px 10px 8px; font-size: .68rem; color: #d7dae0;
}
.card .meta .fname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .meta .fsize { font-family: var(--mono); color: var(--muted); font-size: .64rem; display: block; margin-top: 1px; }
.card .rm {
  position: absolute; bottom: 8px; right: 8px; width: 24px; height: 24px; border-radius: 7px;
  background: rgba(21, 23, 28, 0.78); border: 1px solid var(--border); display: grid; place-items: center;
  opacity: 0; transition: .15s;
}
.card:hover .rm { opacity: 1; }
.card .rm svg { width: 13px; height: 13px; stroke: var(--red); }

.empty { text-align: center; color: var(--muted-2); padding: 50px 0; font-size: .9rem; }

/* ---------- Progress overlay ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 60; display: none;
  align-items: center; justify-content: center; padding: 24px;
  background: rgba(13, 14, 18, 0.78); backdrop-filter: blur(6px);
}
.overlay.show { display: flex; }
.panel {
  width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 26px; box-shadow: var(--shadow);
}
.panel h3 { font-family: var(--display); font-weight: 600; margin: 0 0 4px; font-size: 1.1rem; }
.panel .sub { color: var(--muted); font-size: .85rem; margin: 0 0 20px; }
.bar { height: 10px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0%; border-radius: 99px;
  background: linear-gradient(90deg, var(--gold), #f3c877); transition: width .2s ease; }
.prog-row { display: flex; justify-content: space-between; align-items: baseline; margin-top: 12px; }
.prog-row .pct { font-family: var(--mono); font-size: 1.4rem; font-weight: 600; color: var(--gold); }
.prog-row .frac { font-family: var(--mono); font-size: .82rem; color: var(--muted); }
.cur-file { margin-top: 10px; font-family: var(--mono); font-size: .76rem; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel .done-ico { width: 54px; height: 54px; margin: 0 auto 14px; border-radius: 50%;
  background: rgba(79,180,119,.16); display: grid; place-items: center; }
.panel .done-ico svg { width: 28px; height: 28px; stroke: var(--green); }
.panel-actions { display: flex; gap: 10px; margin-top: 20px; }
.panel-actions .btn { flex: 1; justify-content: center; }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 80;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: var(--surface-3); border: 1px solid var(--border); color: var(--text);
  padding: 11px 16px; border-radius: 11px; font-size: .85rem; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 9px; max-width: 90vw;
  animation: pop .25s ease;
}
.toast .ico { width: 18px; height: 18px; flex: none; }
.toast.err { border-color: var(--red); }
.toast.ok .ico { stroke: var(--green); }
.toast.err .ico { stroke: var(--red); }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* note banner */
.note {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--gold);
  border-radius: 10px; padding: 12px 14px; margin-bottom: 20px; font-size: .82rem; color: var(--muted);
}
.note svg { width: 16px; height: 16px; stroke: var(--gold); flex: none; margin-top: 2px; }
.note b { color: var(--text); font-weight: 600; }
.note button { background: none; border: 0; color: var(--muted-2); cursor: pointer; margin-left: auto; font-size: 1rem; line-height: 1; padding: 0 2px; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

@media (max-width: 560px) {
  .brand .tag { display: none; }
  .brand h1 { font-size: 1rem; white-space: nowrap; }
  .topbar { gap: 10px; padding: 12px 16px; }
  .dest-pill { padding: 8px 10px; font-size: .78rem; }
}
