:root {
  --bg: #0e1015;
  --bg-elev: #161922;
  --bg-elev-2: #1f2330;
  --line: #2a3142;
  --ink: #e7ebf3;
  --ink-dim: #8c96a8;
  --accent: #7aa2ff;
  --accent-dim: #4a6fcc;
  --good: #6fd07a;
  --warn: #f0c060;
  --bad: #f07a7a;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  --r: 10px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(122, 162, 255, 0.08), transparent),
    var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ─────────── Header ─────────── */
.bar {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 18px 32px;
  border-bottom: 1px solid var(--line);
  background: rgba(22, 25, 34, 0.7);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.brand-mark {
  color: var(--accent);
  font-size: 18px;
}

.brand-name {
  font-weight: 600;
  letter-spacing: 0.3px;
}

.brand-sub {
  color: var(--ink-dim);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 2px 8px;
  background: rgba(111, 208, 122, 0.15);
  color: var(--good);
  border-radius: 4px;
  border: 1px solid rgba(111, 208, 122, 0.3);
  text-transform: uppercase;
  cursor: help;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 32px 64px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ─────────── Cards & sections ─────────── */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 22px 26px;
  box-shadow: var(--shadow);
  animation: slideIn 240ms ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card h2 {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 12px;
}

.lede {
  margin: 0 0 16px;
  color: var(--ink-dim);
  font-size: 14px;
}

.lede strong {
  color: var(--ink);
}

.step-num {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: white;
  font-size: 12px;
  font-weight: 700;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 6px 0;
}

.row+.row {
  margin-top: 8px;
}

label {
  color: var(--ink-dim);
}

label.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  cursor: pointer;
}

label strong {
  color: var(--ink);
  margin: 0 6px;
  font-weight: 700;
}

/* ─────────── Inputs ─────────── */
input[type="text"],
input[type="number"] {
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 9px 12px;
  border-radius: 6px;
  font-size: 14px;
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace;
}

input[type="text"] {
  flex: 1;
  min-width: 240px;
}

input[type="number"] {
  width: 80px;
}

input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  min-width: 200px;
}

/* ─────────── Buttons ─────────── */
button,
.button-like {
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  color: var(--ink);
  padding: 9px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 120ms ease;
  font-family: inherit;
  display: inline-block;
}

button:hover,
.button-like:hover {
  background: #262b3a;
}

button.primary,
.button-like.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0c1226;
  font-weight: 600;
}

button.primary:hover {
  background: #95b5ff;
}

button.primary.big {
  padding: 12px 24px;
  font-size: 15px;
}

button.ghost,
.button-like.ghost {
  background: transparent;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.fallback-picker {
  cursor: pointer;
}

/* ─────────── Status text ─────────── */
.status {
  margin-top: 10px;
  font-size: 13px;
  color: var(--ink-dim);
  min-height: 18px;
}

.status.ok {
  color: var(--good);
}

.status.warn {
  color: var(--warn);
}

.status.bad {
  color: var(--bad);
}

.hint {
  color: var(--ink-dim);
  font-size: 13px;
}

.subhint {
  margin-top: 6px;
  font-size: 12px;
}

.subhint strong {
  color: var(--ink);
}

.hidden {
  display: none !important;
}

/* Visually hide an element but keep it focusable/clickable. Used for the
 * <input type="file"> behind the "Pick folder…" button — the `hidden` HTML
 * attribute would do display:none which Firefox refuses to dispatch click
 * to. This pattern is safe across all browsers. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.mode-badge {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid var(--line);
  color: var(--ink-dim);
  background: var(--bg-elev-2);
}

.mode-badge.fsa {
  color: var(--good);
  border-color: rgba(111, 208, 122, 0.3);
}

.mode-badge.fallback {
  color: var(--warn);
  border-color: rgba(240, 192, 96, 0.3);
}

.global-error {
  background: rgba(240, 122, 122, 0.1);
  border-bottom: 1px solid var(--bad);
  color: var(--bad);
  padding: 10px 32px;
  font-size: 13px;
  font-family: ui-monospace, monospace;
  position: sticky;
  top: 60px;
  z-index: 9;
}

.usage-card {
  margin-top: 20px;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px 22px;
}

.usage-head {
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--good);
}

.usage-block+.usage-block {
  margin-top: 16px;
}

.usage-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--ink-dim);
  margin-bottom: 6px;
}

.usage-cmd {
  background: #0a0d14;
  border: 1px solid var(--line);
  padding: 10px 14px;
  border-radius: 6px;
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--ink);
  margin: 0 0 6px;
  overflow-x: auto;
}

.usage-cmd code em {
  color: var(--accent);
  font-style: normal;
}

.usage-block code {
  color: var(--accent);
  font-family: ui-monospace, monospace;
  font-size: 12px;
}

.hash-options select {
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace;
  margin-left: 6px;
}

.kbd {
  display: inline-block;
  padding: 0 6px;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg-elev-2);
  color: var(--ink);
  margin: 0 2px;
}

/* ─────────── Progress bar ─────────── */
.progress-shell {
  width: 100%;
  height: 6px;
  background: var(--bg-elev-2);
  border-radius: 3px;
  margin-top: 12px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  width: 0%;
  transition: width 80ms ease;
}

/* ─────────── Extension table ─────────── */
.ext-table {
  width: 100%;
  margin-top: 14px;
  border-collapse: collapse;
  font-size: 13px;
}

.ext-table th,
.ext-table td {
  text-align: left;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
}

.ext-table th {
  color: var(--ink-dim);
  font-weight: 500;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.6px;
  background-color: transparent;
}

.ext-table tr:nth-child(even) {
  background-color: transparent;
}

.ext-table tr:hover td {
  background-color: var(--bg-elev-2);
}

.ext-table th.num,
.ext-table td.num {
  text-align: right;
}

.ext-table td.num {
  font-family: ui-monospace, monospace;
}

.ext-table tr.highlight td {
  color: var(--accent);
}

.ext-table tr.unsupported td {
  color: var(--ink-dim);
}

.ext-table tr.unsupported td:first-child::after {
  content: " (skipped)";
  font-size: 11px;
}

/* ─────────── Threshold row ─────────── */
.threshold-row {
  gap: 16px;
}

.threshold-label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 220px;
}

.slider-end-label {
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.8px;
  font-weight: 600;
  color: var(--ink-dim);
}

/* ─────────── Carousel ─────────── */
#carousel {
  margin-top: 16px;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.carousel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

#cluster-counter {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.3px;
}

.cluster-stage {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: flex-start;
  min-height: 320px;
}

.thumb {
  width: 280px;
  background: #0a0d14;
  border: 2px solid transparent;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: all 150ms ease;
  display: flex;
  flex-direction: column;
  user-select: none;
  position: relative;
  /* anchor for .rotate-btn */
}

.thumb img {
  width: 100%;
  height: 280px;
  object-fit: contain;
  background: #000;
  transition: opacity 150ms ease, filter 150ms ease, transform 180ms ease;
  display: block;
}

/* Rotate-90 overlay. Hidden by default; appears on card hover so the cluster
 * still reads as a clean photo grid at rest. Click-stopped in JS so it doesn't
 * also toggle the card's deselect state. */
.rotate-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: var(--ink);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 150ms ease, background 150ms ease;
  display: grid;
  place-items: center;
  backdrop-filter: blur(4px);
}

.thumb:hover .rotate-btn,
.rotate-btn:focus-visible {
  opacity: 1;
}

.rotate-btn:hover {
  background: rgba(122, 162, 255, 0.85);
  color: #0c1226;
}

.thumb .thumb-meta {
  padding: 8px 10px;
  font-size: 11px;
  font-family: ui-monospace, monospace;
  color: var(--ink-dim);
  word-break: break-all;
}

.thumb .thumb-state {
  padding: 4px 10px 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--good);
}

.thumb:hover {
  border-color: var(--accent-dim);
}

.thumb.deselected {
  border-color: var(--bad);
}

.thumb.deselected img {
  opacity: 0.25;
  filter: grayscale(1);
}

.thumb.deselected .thumb-state {
  color: var(--bad);
}

.carousel-foot {
  margin-top: 14px;
}

/* ─────────── Footer ─────────── */
.footer {
  text-align: center;
  padding: 32px;
  color: var(--ink-dim);
  font-size: 12px;
  border-top: 1px solid var(--line);
  margin-top: 32px;
}

.footer a {
  color: var(--ink-dim);
  text-decoration: underline;
}

.footer a:hover {
  color: var(--ink);
}