:root {
  --bg: #14161a;
  --surface: #1c1f26;
  --surface-raised: #22262f;
  --border: #2c3038;
  --text: #e8e6e1;
  --text-dim: #9a9fab;
  --text-faint: #666b78;
  --amber: #e8a33d;
  --amber-dim: #b9852f;
  --teal: #4fb8a8;
  --danger: #d96c5f;
  --success: #6fbf73;
  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
}

body {
  padding-left: 22px;
  min-height: 100vh;
}

/* Decorative sprocket rail down the left edge, evoking a film strip */
.sprocket-rail {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 22px;
  background: repeating-linear-gradient(
    to bottom,
    #0d0f12 0px, #0d0f12 10px,
    transparent 10px, transparent 20px
  );
  border-right: 1px solid var(--border);
}
.sprocket-rail::before {
  content: '';
  position: absolute;
  top: 14px; left: 7px;
  width: 8px; height: 8px;
  border-radius: 2px;
  background: var(--bg);
  box-shadow: 0 20px 0 var(--bg), 0 40px 0 var(--bg), 0 60px 0 var(--bg), 0 80px 0 var(--bg),
    0 100px 0 var(--bg), 0 120px 0 var(--bg), 0 140px 0 var(--bg), 0 160px 0 var(--bg),
    0 180px 0 var(--bg), 0 200px 0 var(--bg), 0 220px 0 var(--bg), 0 240px 0 var(--bg),
    0 260px 0 var(--bg), 0 280px 0 var(--bg), 0 300px 0 var(--bg);
}

a { color: var(--amber); }

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

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  font-size: 26px;
  color: var(--amber);
}
.brand-text h1 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.02em;
}
.brand-text p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-dim);
}

main {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 24px 80px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
}

.panel-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.frame-index {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--bg);
  background: var(--amber);
  padding: 2px 6px;
  border-radius: 3px;
}

/* Buttons */
.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 9px 16px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--amber); color: #1a1408; }
.btn-primary:hover:not(:disabled) { background: #f0af4e; }
.btn-secondary { background: var(--surface-raised); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--amber-dim); }
.btn-ghost { background: transparent; color: var(--text-dim); border-color: var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--text-dim); }
.btn-icon { padding: 6px 10px; }
.btn-small { padding: 5px 10px; font-size: 12px; }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: rgba(217,108,95,0.1); }

/* Scan panel */
.type-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 14px;
}
.type-btn {
  background: var(--surface-raised);
  color: var(--text-dim);
  border: none;
  padding: 8px 18px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.type-btn.active { background: var(--amber); color: #1a1408; }

.path-row { display: flex; gap: 10px; }
.path-row input {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 13px;
  background: #101216;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 12px;
}
.path-row input:focus { outline: none; border-color: var(--amber-dim); }

.hint { font-size: 12px; color: var(--text-faint); margin: 10px 0 0; }
.hint code { font-family: var(--font-mono); color: var(--text-dim); }

.scan-status {
  margin-top: 14px;
}
.scan-status-text {
  font-size: 13px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  margin: 0;
}
.scan-status.error .scan-status-text { color: var(--danger); }

.progress-bar {
  height: 6px;
  background: #101216;
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--amber);
  transition: width 0.3s ease;
}

/* Results */
.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.results-header .panel-title { margin-bottom: 0; }
.results-actions { display: flex; align-items: center; gap: 14px; }
.selected-count { font-size: 12px; color: var(--text-dim); }

.items-list { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

.item-row {
  display: grid;
  grid-template-columns: auto 44px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 12px 14px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.item-row.status-error { border-color: rgba(217,108,95,0.4); }
.item-row.status-applied { opacity: 0.55; }
.item-row.status-deleted { opacity: 0.5; }
.item-row.status-deleted .path-line.old { text-decoration: line-through; }

.item-check { accent-color: var(--amber); width: 16px; height: 16px; }

.item-poster {
  width: 44px; height: 66px;
  object-fit: cover;
  border-radius: 3px;
  background: #101216;
  border: 1px solid var(--border);
}
.item-poster.placeholder {
  display: flex; align-items: center; justify-content: center;
  color: var(--text-faint); font-size: 10px; text-align: center;
}

.item-paths { min-width: 0; }
.path-line {
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.path-line.old { color: var(--text-faint); text-decoration: line-through; text-decoration-color: rgba(217,108,95,0.5); }
.path-line.new { color: var(--teal); margin-top: 3px; }
.path-line.new::before { content: '→ '; color: var(--text-faint); text-decoration: none; }
.item-error { font-size: 12px; color: var(--danger); margin-top: 4px; }

.item-meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.confidence-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 3px;
  border: 1px solid var(--border);
}
.confidence-badge.high { color: var(--success); border-color: rgba(111,191,115,0.4); }
.confidence-badge.mid { color: var(--amber); border-color: rgba(232,163,61,0.4); }
.confidence-badge.low { color: var(--danger); border-color: rgba(217,108,95,0.4); }
.status-pill {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

.item-actions { display: flex; flex-direction: column; gap: 6px; }

.empty-note { color: var(--text-faint); font-size: 13px; margin: 0; }

/* History */
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
}
.history-item .meta { color: var(--text-dim); font-family: var(--font-mono); font-size: 12px; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(10,11,13,0.7);
  align-items: center; justify-content: center;
  z-index: 50;
  padding: 20px;
  display: none;
}
/* The [hidden] attribute must win over the flex layout below, otherwise
   the overlay stays visible (and un-clickable-through) even when JS sets
   element.hidden = true, since author rules beat the UA [hidden] default
   regardless of specificity. */
.modal-overlay:not([hidden]) {
  display: flex;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-family: var(--font-display); font-size: 16px; margin: 0; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.field span { font-weight: 600; }
.field input {
  font-family: var(--font-mono);
  font-size: 13px;
  background: #101216;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 11px;
}
.field small { color: var(--text-faint); font-size: 11px; }

.override-results { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; max-height: 320px; overflow-y: auto; }
.override-candidate {
  display: flex; gap: 12px; align-items: center;
  padding: 10px; background: var(--surface-raised);
  border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer;
}
.override-candidate:hover { border-color: var(--amber-dim); }
.override-candidate img { width: 36px; height: 54px; object-fit: cover; border-radius: 3px; }
.override-candidate .cand-title { font-weight: 600; font-size: 13px; }
.override-candidate .cand-year { color: var(--text-dim); font-size: 12px; }

.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 100;
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--success); color: var(--success); }

@media (max-width: 640px) {
  .item-row { grid-template-columns: auto 1fr; }
  .item-poster { display: none; }
}
