:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --text: #16181d;
  --muted: #667085;
  --border: #e3e6eb;
  --accent: #10a36b;
  --accent-ink: #ffffff;
  --warn: #b7791f;
  --warn-bg: #fff6e0;
  --err: #d64545;
  --err-bg: #fdecec;
  --ok-bg: #e5f7ef;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  /* Chart hues: views, thumbnail changes, title changes (checked for colour blindness on both surfaces). */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #171a21;
    --panel-2: #1f232c;
    --text: #e7e9ee;
    --muted: #98a1b3;
    --border: #2a2f3a;
    --accent: #3ecf8e;
    --accent-ink: #0b1a13;
    --warn: #f0b429;
    --warn-bg: #2f2612;
    --err: #ff6b6b;
    --err-bg: #341a1a;
    --ok-bg: #11291f;
    --shadow: none;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: inherit; }
img { display: block; max-width: 100%; }
button, input, select, textarea {
  font: inherit;
  color: inherit;
}
input, select, textarea {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 0;
}
textarea { width: 100%; min-height: 90px; resize: vertical; }
button {
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}
button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 500;
}
button.danger { background: transparent; color: var(--err); border: 1px solid var(--err); font-weight: 500; }
button.small { padding: 3px 9px; font-size: 12.5px; }
button:disabled { opacity: .5; cursor: default; }

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; text-decoration: none; }
.brand img { width: 24px; height: 24px; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a { text-decoration: none; padding: 6px 10px; border-radius: 8px; color: var(--muted); }
nav a.active { background: var(--panel-2); color: var(--text); font-weight: 600; }
.quick-add { display: flex; gap: 6px; margin-left: auto; flex: 1 1 280px; max-width: 460px; }
.quick-add input { flex: 1; }

main { max-width: 1400px; margin: 0 auto; padding: 18px 20px 60px; }
.pad { padding: 20px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
h1 { font-size: 22px; margin: 0 0 6px; line-height: 1.25; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { margin: 0 0 8px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.panel > h2 .muted { font-weight: 400; font-size: 13px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input[type=search] { flex: 1 1 240px; }
.chk { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; user-select: none; color: var(--muted); }
.chk input { margin: 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  text-decoration: none;
}
.card .thumb { position: relative; aspect-ratio: 16 / 9; background: var(--panel-2); }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.card .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.card .title { font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .meta { color: var(--muted); font-size: 12.5px; }
.card .actions { display: flex; gap: 6px; margin-top: auto; padding-top: 6px; flex-wrap: wrap; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--panel-2);
  color: var(--muted);
  white-space: nowrap;
}
.badge.accent { background: var(--accent); color: var(--accent-ink); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.err { background: var(--err-bg); color: var(--err); }
.badge.ok { background: var(--ok-bg); color: var(--accent); }
.thumb .badges { position: absolute; left: 6px; top: 6px; display: flex; gap: 4px; flex-wrap: wrap; }
.thumb .badges .badge { background: rgba(0, 0, 0, .72); color: #fff; }
.thumb .badges .badge.accent { background: var(--accent); color: var(--accent-ink); }
.thumb .score { position: absolute; right: 6px; bottom: 6px; font-size: 15px; padding: 3px 9px; }

.video-head { display: grid; grid-template-columns: minmax(260px, 420px) 1fr; gap: 18px; align-items: start; }
@media (max-width: 800px) { .video-head { grid-template-columns: 1fr; } }
.video-head .hero { border-radius: var(--radius); overflow: hidden; background: var(--panel-2); aspect-ratio: 16 / 9; }
.video-head .hero img { width: 100%; height: 100%; object-fit: cover; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; margin: 10px 0; font-size: 13.5px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.status-line { padding: 8px 12px; border-radius: 8px; background: var(--panel-2); margin: 10px 0; }
.status-line.active { background: var(--ok-bg); }
.status-line.err { background: var(--err-bg); color: var(--err); }

.variants { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.variant { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.variant.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.variant .img { aspect-ratio: 16 / 9; background: var(--panel-2); cursor: zoom-in; }
.variant .img img { width: 100%; height: 100%; object-fit: contain; }
.variant .info { padding: 10px 12px; display: flex; flex-direction: column; gap: 5px; }
.variant .label { font-size: 18px; font-weight: 700; }
.files { margin-top: 4px; font-size: 12.5px; }
.files a { color: var(--accent); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
tr.current td { background: var(--ok-bg); }

.titles li { margin-bottom: 6px; }
.titles { padding-left: 18px; margin: 0; }
.tabs { display: flex; gap: 4px; margin-bottom: 14px; }
.tabs a { padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); }
.tabs a.active { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: var(--shadow); border: 1px solid var(--border); }
details > summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.help { font-size: 13px; color: var(--muted); margin: -4px 0 12px; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.kv div { background: var(--panel-2); border-radius: 8px; padding: 10px 12px; }
.kv b { display: block; font-size: 20px; }
code { font-family: var(--mono); font-size: 12.5px; background: var(--panel-2); padding: 1px 5px; border-radius: 5px; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; max-width: 420px; box-shadow: 0 4px 16px rgba(0,0,0,.2); }
.toast.err { background: var(--err); color: #fff; }
#lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .88); z-index: 60; display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: zoom-out; padding: 20px; }
#lightbox[hidden] { display: none; }
#lightbox img { max-width: 96vw; max-height: 88vh; object-fit: contain; }
.lb-caption { color: #ddd; margin-top: 10px; font-size: 13px; }
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); color: var(--text); padding: 20px; width: min(380px, 92vw); }
dialog input { width: 100%; margin: 8px 0 14px; }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Views chart on the video page */
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12.5px; color: var(--muted); margin: 2px 0 6px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.key-line { width: 16px; height: 2px; border-radius: 1px; background: var(--series-1); }
.key-mark { width: 10px; height: 10px; border-radius: 2px; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart svg:focus { outline: none; }
.chart svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .mark-label { fill: var(--text); font-size: 11.5px; }
.chart .end-label { fill: var(--text); font-size: 12px; font-weight: 600; }
.chart-tip { position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: 8px; padding: 7px 10px; font-size: 12.5px; min-width: 150px; max-width: 280px; z-index: 5; }
.chart-tip[hidden] { display: none; }
.chart-tip b { display: block; font-size: 14px; font-variant-numeric: tabular-nums; }
.chart-tip .row { gap: 6px; margin-top: 3px; flex-wrap: nowrap; }
.chart-tip .row i { flex: none; width: 12px; height: 2px; border-radius: 1px; }
.swatches { display: inline-flex; gap: 3px; vertical-align: middle; }
.swatches i { width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--border); }

/* Radar: a channel's strong videos */
.cmp-top { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin: 10px 0 12px; }
.cmp-thumb { position: relative; display: block; border-radius: 8px; overflow: hidden; aspect-ratio: 16 / 9; background: var(--panel-2); }
.cmp-thumb img { width: 100%; height: 100%; object-fit: cover; }
.cmp-thumb .badge { position: absolute; left: 6px; bottom: 6px; }
.cmp-thumb .badge { background: rgba(0, 0, 0, .72); color: #fff; font-weight: 700; }

/* Video page: changes of the main picture or title as cards */
.changes { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; margin: 10px 0; }
.change { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.change-head { display: flex; align-items: baseline; gap: 6px 8px; flex-wrap: wrap; }
.change-head .key-mark { align-self: center; flex: none; }
.change-pics { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.change-pics figure { margin: 0; min-width: 0; }
.change-pics .img { aspect-ratio: 16 / 9; background: var(--panel-2); border-radius: 6px; overflow: hidden; cursor: zoom-in; }
.change-pics .img img { width: 100%; height: 100%; object-fit: cover; }
.change-pics figcaption { font-size: 12px; color: var(--muted); margin-top: 3px; }
.change-arrow { color: var(--muted); font-size: 18px; }
.change-titles { display: flex; flex-direction: column; gap: 6px; overflow-wrap: anywhere; }
.change-titles .was { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--border); }
.change-foot { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); }
.change-foot b { color: var(--text); font-weight: 600; }
.changes-more > summary { font-weight: 500; color: var(--muted); margin: 4px 0; }
@media (max-width: 400px) { .changes { grid-template-columns: 1fr; } }
