:root {
  --bg: #0d0d0d;
  --panel: #1a1a1a;
  --border: #2a2a2a;
  --text: #e8e8e8;
  --muted: #888;
  --accent: #d4ff5a;
  --error: #ff6b6b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 16px;
  min-height: 100vh;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

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

h2 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 1rem;
}

main {
  padding: 1.25rem;
  max-width: 640px;
  margin: 0 auto;
}

section { display: block; }
section[hidden] { display: none; }

button, .capture-button, label.capture-button {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

button {
  background: var(--accent);
  color: #000;
  border: none;
  padding: 0.9rem 1.25rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  margin-top: 0.75rem;
}
button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
button.danger {
  color: var(--error);
  border-color: var(--error);
}
button:active { transform: scale(0.99); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Header collection-count button */
button.count {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  width: auto;
  margin: 0;
  font-variant-numeric: tabular-nums;
}
button.count:active { background: var(--panel); }

/* ── Mode toggle (Movie / TV) ─────────────────────────────────────────── */

.mode-section {
  margin-bottom: 1rem;
}
.mode-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.4rem;
}
.mode-switch {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 0.25rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  isolation: isolate;
  user-select: none;
  -webkit-user-select: none;
}
.mode-switch-thumb {
  position: absolute;
  top: 0.25rem;
  bottom: 0.25rem;
  left: 0.25rem;
  width: calc(50% - 0.25rem);
  background: var(--accent);
  border-radius: 999px;
  z-index: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s ease;
  pointer-events: none;
}
.mode-switch[data-mode="tv"] .mode-switch-thumb {
  transform: translateX(100%);
}
.mode-switch-option {
  position: relative;
  z-index: 1;
  background: transparent;
  color: #6a6a6a;
  border: none;
  padding: 0.7rem 0.5rem;
  margin: 0;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.95rem;
  width: auto;
  cursor: pointer;
  transition: color 0.2s ease;
}
.mode-switch[data-mode="movie"] .mode-switch-option[data-mode="movie"],
.mode-switch[data-mode="tv"] .mode-switch-option[data-mode="tv"] {
  color: #000;
}
.mode-switch-option:active {
  transform: none;
}
.mode-hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0.5rem 0 0;
  padding: 0;
  text-align: center;
  line-height: 1.4;
}

/* ── Capture screen ───────────────────────────────────────────────────── */

.capture-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.capture-button {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  min-height: 28vh;
  border: 2px dashed var(--border);
  border-radius: 12px;
  background: var(--panel);
  cursor: pointer;
  text-align: center;
  padding: 1.5rem;
}
.capture-button span {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--accent);
}
.capture-button small {
  color: var(--muted);
  font-size: 0.85rem;
}
.capture-button:active { background: #222; }

.secondary-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.secondary-actions > button { margin-top: 0; }

.spend-row,
.lifetime-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  font-size: 0.75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  flex-wrap: wrap;
  text-align: center;
}
.spend-row > button,
.lifetime-row > button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.15rem 0.5rem;
  font-size: 0.7rem;
  width: auto;
  margin: 0;
  border-radius: 4px;
}
.lifetime-row {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  flex-direction: column;
  gap: 0.5rem;
}

/* ── Common rows ──────────────────────────────────────────────────────── */

.row {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}
.row > button { margin-top: 0; }

.muted {
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 1rem;
}

.error {
  color: var(--error);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

/* ── Spinner ──────────────────────────────────────────────────────────── */

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 3rem auto 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

#processing-status {
  text-align: center;
  color: var(--muted);
}

/* ── Item lists (review, collection, manual results) ─────────────────── */

#match-list, #collection-list, #manual-results {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
#match-list li,
#collection-list li,
#manual-results li {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
}

#collection-list li,
#manual-results li {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

#match-list li {
  display: flex;
  flex-direction: column;
  gap: 0;
}
#match-list .row-main {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}
#match-list img,
#collection-list img,
#manual-results img {
  width: 40px;
  height: 60px;
  object-fit: cover;
  border-radius: 4px;
  background: #000;
  flex-shrink: 0;
}
#match-list .meta,
#collection-list .meta,
#manual-results .meta {
  flex: 1;
  min-width: 0;
}
#match-list .title,
#collection-list .title,
#manual-results .title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#match-list .year,
#collection-list .year,
#manual-results .year {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#match-list .remove,
#collection-list .remove {
  background: transparent;
  color: var(--error);
  border: 1px solid var(--border);
  padding: 0.4rem 0.6rem;
  width: auto;
  margin: 0;
  font-size: 0.85rem;
  flex-shrink: 0;
}

#match-list li.unmatched {
  border-color: var(--error);
}

/* ── Retry form (in review screen) ───────────────────────────────────── */

#match-list .retry-form {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.5rem;
}
#match-list .retry-input {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #000;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
}
#match-list .retry-btn {
  background: var(--accent);
  color: #000;
  border: none;
  padding: 0.4rem 0.7rem;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 600;
  width: auto;
  margin: 0;
  cursor: pointer;
  flex-shrink: 0;
}
#match-list .retry-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* ── Alternatives picker ─────────────────────────────────────────────── */

#match-list .alt-toggle {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0.4rem 0;
  margin: 0.4rem 0 0;
  font-size: 0.8rem;
  text-align: left;
  width: auto;
  text-decoration: underline;
}
#match-list .alt-toggle:active { transform: none; }

#match-list > li > .alt-toggle {
  width: auto;
  align-self: flex-start;
}

#match-list .alternatives {
  list-style: none;
  padding: 0;
  margin: 0.6rem 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
}
#match-list .alternatives li {
  display: flex;
  align-items: center;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.7rem;
  gap: 0.85rem;
}
#match-list .alternatives img {
  width: 70px;
  height: 105px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}
#match-list .alt-meta {
  flex: 1;
  min-width: 0;
}
#match-list .alt-title {
  font-size: 0.95rem;
  font-weight: 500;
  white-space: normal;
  word-break: break-word;
  line-height: 1.3;
}
#match-list .alt-year {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 0.2rem;
}
#match-list .pick-alt {
  background: var(--accent);
  color: #000;
  border: none;
  padding: 0.5rem 0.85rem;
  width: auto;
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  flex-shrink: 0;
  border-radius: 6px;
}

/* Duplicate badge in review */
#match-list li.duplicate {
  border-color: #6b6b32;
  opacity: 0.85;
}
#match-list .badge {
  display: inline-block;
  background: #3a3a1a;
  color: #d4ff5a;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  margin-left: 0.3rem;
  vertical-align: middle;
  white-space: nowrap;
}

/* Confidence badges — only shown for medium/low */
#match-list .badge.conf-med {
  background: #3a2f1a;
  color: #ffcc66;
}
#match-list .badge.conf-low {
  background: #3a1a1a;
  color: #ff9966;
}
#match-list li.needs-check {
  border-color: #5a4a2a;
}

/* ── Manual add screen ───────────────────────────────────────────────── */

#manual-search-form {
  display: grid;
  grid-template-columns: 1fr 90px;
  gap: 0.5rem;
}
#manual-search-form button {
  grid-column: 1 / -1;
  margin-top: 0;
}
#manual-search-form input {
  padding: 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
}

#manual-results .add-manual {
  background: var(--accent);
  color: #000;
  border: none;
  padding: 0.4rem 0.7rem;
  width: auto;
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  flex-shrink: 0;
}
#manual-results .add-manual:disabled {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

/* ── Login screen ────────────────────────────────────────────────────── */

#login-screen input {
  width: 100%;
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
}
