* { box-sizing: border-box; }
:root {
  color-scheme: dark;
  --bg: #14171c;
  --panel: #1c2128;
  --border: #2d333b;
  --text: #e6edf3;
  --muted: #7d8590;
  --accent: #e5a00d;
  --accent-2: #1f6feb;
  --good: #3fb950;
  --bad: #f85149;
  --warn: #d29922;
}
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}
header h1 { margin: 0; font-size: 18px; letter-spacing: 0.02em; }
main { padding: 24px; max-width: 1100px; margin: 0 auto; }
button {
  background: var(--accent);
  color: #000;
  border: 0;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}
button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
button:disabled { opacity: 0.5; cursor: not-allowed; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
input:focus-visible {
  outline-color: var(--accent);
  border-color: var(--accent);
}

.sort-hint { color: var(--muted); opacity: 0.5; font-size: 10px; }
table.shows th.sortable:hover .sort-hint { opacity: 1; }
.muted { color: var(--muted); font-size: 13px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
}
.card + .card { margin-top: 16px; }

.pin {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 28px;
  letter-spacing: 8px;
  padding: 8px 16px;
  background: #0d1117;
  border-radius: 6px;
  display: inline-block;
}

table.shows {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}
table.shows th, table.shows td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
table.shows th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
@media (min-width: 601px) { table.shows th { white-space: nowrap; } }
table.shows th.sortable { cursor: pointer; user-select: none; }
table.shows th.sortable:hover { color: var(--text); }
table.shows th.active { color: var(--accent); }
table.shows th.num, table.shows td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.shows tr.show-row { cursor: pointer; transition: background 80ms ease; }
table.shows tr.show-row:hover { background: rgba(255,255,255,0.08); }
table.shows tr.detail td { background: #0d1117; padding: 0; }

.bar {
  display: inline-block;
  width: 120px;
  height: 8px;
  background: #30363d;
  border-radius: 4px;
  overflow: hidden;
  vertical-align: middle;
  margin-right: 8px;
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--good);
}
.bar.warn > span { background: var(--warn); }
.bar.bad > span { background: var(--bad); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  margin-left: 4px;
}
.badge.tvmaze { background: rgba(31, 111, 235, 0.18); color: #79b8ff; cursor: help; }
.badge.low { background: rgba(210, 153, 34, 0.18); color: var(--warn); }
.badge.complete { background: rgba(63, 185, 80, 0.18); color: var(--good); }
.badge.unresolved { background: rgba(248, 81, 73, 0.18); color: var(--bad); }
.badge.hidden { background: rgba(125, 133, 144, 0.22); color: var(--muted); }

.filter-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  flex-wrap: wrap;
}
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
}
.filter-chip input { margin: 0; cursor: pointer; }
.filter-chip:hover { border-color: var(--accent); }

.match-panel { margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px dashed var(--border); }
.match-status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.match-status > .muted { flex: 1 1 200px; min-width: 0; }
.match-status button { white-space: nowrap; }
.match-status code { background: #0d1117; padding: 2px 6px; border-radius: 4px; font-size: 12px; }
.match-form { margin-top: 12px; }
.match-row { display: flex; gap: 8px; margin-bottom: 8px; }
.match-row input {
  flex: 1;
  background: #0d1117;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
}
.match-results { margin-top: 8px; max-height: 360px; overflow-y: auto; }
.match-result {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 6px;
  background: #0d1117;
}
.match-result button { flex-shrink: 0; align-self: flex-start; }
.match-result-main { flex: 1; min-width: 0; font-size: 13px; }
.match-summary {
  font-size: 12px;
  margin-top: 4px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.show-detail {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}
.show-detail h3 { margin: 0 0 12px; font-size: 14px; color: var(--muted); }
.season-group { margin-bottom: 16px; }
.season-group h4 { margin: 8px 0 6px; font-size: 13px; color: var(--text); }
.season-group ul { margin: 0; padding-left: 18px; }
.season-group li { padding: 4px 0; font-size: 13px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.season-group li .i-own-this {
  background: transparent;
  color: var(--text);
  padding: 4px 10px;
  font-size: 11px;
  min-height: 28px;
  border: 1px solid var(--border);
  border-radius: 4px;
  flex-shrink: 0;
}
.season-group li .i-own-this:hover { border-color: var(--accent); color: var(--accent); }
.pricing {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px dashed var(--border);
}
.pricing h4 { margin: 0 0 10px; font-size: 14px; }
.offer { padding: 6px 0; }
.offer .price { color: var(--accent); font-weight: 700; }
.offer .label { color: var(--muted); margin-right: 8px; }
.offer.cheapest { font-size: 16px; }
.volume {
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  margin: 6px 0;
  font-size: 13px;
}
.progress {
  height: 6px;
  background: #30363d;
  border-radius: 3px;
  overflow: hidden;
  margin-top: 8px;
}
.progress > div {
  height: 100%;
  background: var(--accent);
  transition: width 200ms ease;
}
.error { color: var(--bad); margin-top: 8px; }

.pricing-loading {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.pricing-loading-text { flex: 1; font-size: 13px; }
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

#toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  box-shadow: 0 4px 18px rgba(0,0,0,0.5);
  animation: toastIn 180ms ease-out;
  pointer-events: auto;
}
.toast.toast-leaving { animation: toastOut 150ms ease-in forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px); } }
.toast-action {
  background: transparent;
  color: var(--accent);
  border: 0;
  padding: 8px 14px;
  min-height: 36px;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
}

.itunes-link {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 10px;
  min-height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  color: var(--accent-2);
  font-size: 12px;
}
.itunes-link:hover { border-color: var(--accent-2); }

/* Tablet: shrink coverage bar and tighten padding so bar + percent fit on one line. */
@media (max-width: 900px) {
  .bar { width: 80px; }
  table.shows th, table.shows td { padding: 10px 8px; }
  table.shows td:nth-child(3) { white-space: nowrap; }
}

/* Mobile portrait. */
@media (max-width: 600px) {
  header { padding: 10px 12px; flex-wrap: wrap; gap: 8px; }
  header h1 { font-size: 16px; }
  main { padding: 12px; }
  table.shows th:nth-child(2), table.shows td:nth-child(2) { display: none; }
  table.shows th, table.shows td { padding: 12px 8px; font-size: 12px; }
  table.shows td.num { font-size: 12px; }
  .filter-bar { gap: 6px; padding: 8px; }
  .filter-count { width: 100%; text-align: left; margin: 4px 0 0 0; font-size: 11px; }
  .bar { width: 50px; }
  .season-group li .i-own-this { min-height: 32px; padding: 6px 12px; font-size: 12px; }
  .pricing-loading { align-items: flex-start; }
  .offer.cheapest { font-size: 14px; line-height: 1.4; }
  #toast-container { bottom: 12px; left: 12px; right: 12px; transform: none; }
}

/* Narrow phones: drop the sync timestamp from the filter bar to keep one line. */
@media (max-width: 420px) {
  .filter-count .count-sync { display: none; }
}

/* Respect reduced motion preference. */
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; border-top-color: var(--muted); }
  .toast { animation: none; }
  .toast.toast-leaving { animation: none; opacity: 0; }
  table.shows tr.show-row { transition: none; }
}

/* Sign-in / sign-up gate */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 320px;
  margin-top: 16px;
}
.auth-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}
.auth-field input {
  background: #0d1117;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
.auth-form button { margin-top: 4px; align-self: flex-start; }
.auth-toggle { margin-top: 16px; }
.auth-toggle a { color: var(--accent); }
