:root {
  --bg: #14161c;
  --panel: #1c1f28;
  --panel-border: #2c313f;
  --text: #e8eaf0;
  --text-dim: #9aa1b4;
  --accent: #5fb4ff;
  --accent-dim: #2a4a66;
  --good: #4caf82;
  --warn: #e0a83c;
  --bad: #e0603c;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Any element that also sets its own `display` (flex/grid panels, mostly)
 * would otherwise defeat the `hidden` attribute -- author-specified
 * `display` always beats the UA stylesheet's `[hidden] { display: none }`
 * regardless of selector specificity, since origin outranks specificity in
 * the cascade. This is the one appropriate use of !important: its entire
 * job is making sure `hidden` always wins here, not toggle a look. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--panel-border);
}

.topbar h1 {
  font-size: 1.1rem;
  margin: 0;
  letter-spacing: 0.02em;
}

.cv-status {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.cv-status .dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--bad);
  display: inline-block;
}
.cv-status.loading .dot { background: var(--warn); animation: pulse 1.2s infinite; }
.cv-status.ready .dot { background: var(--good); animation: none; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.layout {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
  max-width: 900px;
  margin: 0 auto;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  min-width: 0;
}

.panel.preview { padding: 0.85rem; }

h2 {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 0 0.75rem;
}

.file-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.file-slot {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  cursor: pointer;
  min-width: 0;
  flex: 1;
}

.file-slot canvas {
  width: 100%;
  height: 80px;
  background: #0b0c10;
  border: 1px dashed var(--panel-border);
  border-radius: 6px;
  object-fit: contain;
}

#swapBtn {
  align-self: center;
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
  flex-shrink: 0;
}

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

.batch-picker {
  display: flex;
  gap: 0.5rem;
}
.batch-picker button { font-size: 0.8rem; }

.batch-review {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--panel-border);
}

.pair-list {
  list-style: none;
  margin: 0.5rem 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.pair-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  background: #171a22;
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
}
.pair-row .pair-num {
  color: var(--text-dim);
  min-width: 1.5em;
}
.pair-row .pair-files {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pair-row.exported { border-left: 3px solid var(--good); }
.pair-row.low-confidence {
  border-left: 3px solid var(--warn);
  background: #241d16;
}
.pair-row.low-confidence .pair-files { color: var(--warn); }
.pair-row.repaired {
  border-left: 3px solid var(--accent);
  background: #16202a;
}
.pair-row.repaired .pair-files { color: var(--accent); }
.pair-row button {
  padding: 0.15rem 0.45rem;
  font-size: 0.75rem;
  flex-shrink: 0;
}

#startQueueBtn { width: 100%; }

.queue-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding: 0.5rem;
  background: #171a22;
  border-radius: 6px;
  font-size: 0.8rem;
}
.queue-nav button { flex-shrink: 0; padding: 0.35rem 0.6rem; font-size: 0.78rem; }
#queuePosition { flex: 1; text-align: center; color: var(--text-dim); }
#exitQueueBtn { background: transparent; }

button {
  background: var(--accent-dim);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 0.5rem 0.8rem;
  font-size: 0.85rem;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.mode-toggle {
  display: flex;
  gap: 1rem;
  font-size: 0.85rem;
  margin-bottom: 0.4rem;
}
.mode-toggle label { display: flex; align-items: center; gap: 0.35rem; cursor: pointer; }

.mode-hint {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin: 0 0 0.75rem;
  min-height: 2.2em;
}

#autoAlignBtn { width: 100%; padding: 0.65rem; font-weight: 600; }

.progress-line {
  font-size: 0.78rem;
  color: var(--text-dim);
  min-height: 1.2em;
  margin-top: 0.4rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  cursor: pointer;
  margin-bottom: 0.5rem;
}

.tone-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--panel-border);
}
.tone-group label { display: flex; align-items: center; gap: 0.4rem; cursor: pointer; }

.sliders {
  margin-top: 0.6rem;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem 0.75rem;
}

.sliders label {
  display: flex;
  flex-direction: column;
  font-size: 0.72rem;
  color: var(--text-dim);
  gap: 0;
}

.sliders label.span-4,
.sliders button.span-4 {
  grid-column: 1 / -1;
}

@media (max-width: 600px) {
  .file-row { flex-direction: column; }
  #swapBtn { align-self: center; }
  .sliders { grid-template-columns: 1fr 1fr; }
}

.slider-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.sliders input[type="range"] { width: 100%; height: 1.1rem; margin: 0; }
.sliders output { font-size: 0.72rem; color: var(--text); }

#resetSlidersBtn { margin-top: 0.15rem; padding: 0.35rem 0.6rem; font-size: 0.78rem; }

.confidence-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.15rem 0.75rem;
  font-size: 0.82rem;
  margin: 0 0 0.75rem;
}
.confidence-grid dt { color: var(--text-dim); }
.confidence-grid dd { margin: 0; }

.coverage-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 28px);
  gap: 3px;
  max-width: 180px;
  margin-bottom: 0.75rem;
}
.coverage-grid .cell {
  border-radius: 3px;
  background: #2c313f;
}
.coverage-grid .cell.filled { background: var(--good); }
.coverage-grid .cell.sparse { background: var(--warn); }
.coverage-grid .cell.empty { background: var(--bad); opacity: 0.55; }

.verdict {
  font-size: 0.85rem;
  margin: 0;
  padding: 0.5rem;
  border-radius: 6px;
  background: #171a22;
  border-left: 3px solid var(--text-dim);
}
.verdict.good { border-left-color: var(--good); }
.verdict.warn { border-left-color: var(--warn); }
.verdict.bad { border-left-color: var(--bad); }

.preview-tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}
.preview-tabs .tab {
  background: transparent;
  border-bottom: 2px solid transparent;
  border-radius: 0;
}
.preview-tabs .tab.active {
  border-bottom-color: var(--accent);
  color: var(--accent);
}

.canvas-wrap {
  position: relative;
  background: #0b0c10;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 460px;
  overflow: hidden;
}

#previewCanvas {
  max-width: 100%;
  max-height: 82vh;
  cursor: crosshair;
}

.canvas-hint {
  position: absolute;
  bottom: 0.5rem;
  left: 0.5rem;
  right: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  text-align: center;
  pointer-events: none;
  text-shadow: 0 1px 2px #000;
}

.wiggle-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.6rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}
.wiggle-controls label { display: flex; align-items: center; gap: 0.4rem; flex: 1; }
.wiggle-controls input[type="range"] { flex: 1; }

.export-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
