:root {
  --bg: #12151c;
  --bg-2: #1a1e27;
  --surface: #222733;
  --surface-2: #2b3140;
  --border: #343b4c;
  --text: #e8ebf2;
  --muted: #9aa3b5;
  --accent: #6aa5ff;
  --star: #f5c542;
  --danger: #e5534b;

  --c-uncategorized: #8a93a6;
  --c-yes: #3fb67b;
  --c-maybe: #e8a93a;
  --c-no: #e5534b;

  --card: 220px;
  --radius: 12px;
  --shadow: 0 8px 30px rgb(0 0 0 / 0.35);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f4f7;
    --bg-2: #ffffff;
    --surface: #ffffff;
    --surface-2: #eef0f4;
    --border: #d9dde5;
    --text: #1b1f29;
    --muted: #5d6576;
    --accent: #2c6fdc;
    --star: #e0a800;
    --c-uncategorized: #6b7385;
    --c-yes: #22945c;
    --c-maybe: #c98510;
    --c-no: #d23c34;
    --shadow: 0 8px 30px rgb(20 30 50 / 0.15);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
/* category colour, inherited by tabs, cards and buttons */
.cat-uncategorized { --c: var(--c-uncategorized); }
.cat-yes { --c: var(--c-yes); }
.cat-maybe { --c: var(--c-maybe); }
.cat-no { --c: var(--c-no); }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100vh; font-size: 15px; line-height: 1.4; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.hidden { display: none !important; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 4px 8px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=password], textarea, select {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

/* ---------- login ---------- */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 16px;
}
.login form {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px; display: grid; gap: 14px; box-shadow: var(--shadow);
}
.login h1 { margin: 0; font-size: 22px; display: flex; align-items: center; }
.login label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.login .error { color: var(--danger); min-height: 1.2em; font-size: 14px; }
.logo { display: inline-grid; grid-template-columns: 1fr 1fr; gap: 3px; width: 26px; height: 26px; flex: none; margin-right: 10px; }
.logo i { border-radius: 3px; }
.logo i:nth-child(1) { background: var(--c-yes); }
.logo i:nth-child(2) { background: var(--c-maybe); }
.logo i:nth-child(3) { background: var(--c-uncategorized); }
.logo i:nth-child(4) { background: var(--c-no); }

/* ---------- header ---------- */
header.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.top-row { display: flex; align-items: center; gap: 12px; padding: 10px 16px; flex-wrap: wrap; }
.top-row h1 { font-size: 18px; margin: 0; margin-right: auto; display: flex; align-items: center; min-width: 0; }
.top-row h1 span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sync { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.sync.error { color: var(--danger); }
.spin { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.user-chip { font-size: 13px; color: var(--muted); }
.user-chip b { color: var(--text); }

/* ---------- category tabs ---------- */
.tabs { display: flex; gap: 8px; padding: 0 16px 10px; overflow-x: auto; scrollbar-width: none; align-items: stretch; }
.tab {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px 9px 12px; border-radius: 10px;
  border: 2px solid color-mix(in srgb, var(--c) 45%, transparent);
  background: color-mix(in srgb, var(--c) 10%, var(--bg-2));
  font-weight: 600; white-space: nowrap; transition: background .15s, transform .1s;
}
.tab .icon {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--c); color: #fff; font-size: 13px; font-weight: 800;
}
.tab .count {
  min-width: 28px; padding: 1px 8px; border-radius: 999px; text-align: center;
  background: color-mix(in srgb, var(--c) 25%, transparent); font-variant-numeric: tabular-nums;
}
.tab .count small { opacity: .7; font-weight: 500; }
.tab:hover { background: color-mix(in srgb, var(--c) 18%, var(--bg-2)); }
.tab.active { background: var(--c); border-color: var(--c); color: #fff; box-shadow: 0 4px 14px color-mix(in srgb, var(--c) 40%, transparent); }
.tab.active .icon { background: rgb(255 255 255 / .25); }
.tab.active .count { background: rgb(255 255 255 / .25); }
.tab.drop-target { transform: scale(1.06); outline: 3px dashed var(--c); outline-offset: 2px; }
.tab-spacer { flex: 1; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; padding: 12px 16px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; background: var(--bg-2); }
.seg button { border: 0; background: transparent; padding: 6px 11px; font-size: 13.5px; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--surface-2); color: var(--accent); font-weight: 600; }
.toolbar label { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--muted); }
.toolbar .grow { flex: 1; }
.hint-short { display: none; }
.hint { font-size: 13px; color: var(--muted); padding: 0 16px 8px; }
.filter-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--text); font-size: 13px;
}
.filter-pill button { border: 0; background: transparent; padding: 0 4px; font-size: 15px; line-height: 1; }

/* ---------- grid & cards ---------- */
main { padding: 0 16px 60px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(var(--card), 100%), 1fr)); gap: 14px; }

/* ---------- category sections (accordions) ---------- */
.section {
  margin-top: 16px; border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--c) 35%, var(--border));
  background: color-mix(in srgb, var(--c) 4%, var(--bg));
  scroll-margin-top: calc(var(--header-h, 110px) + 10px);
  transition: outline-color .1s;
}
.section-head {
  cursor: pointer; user-select: none; -webkit-user-select: none;
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 10px 14px;
  background: color-mix(in srgb, var(--c) 14%, var(--bg-2));
  border-bottom: 1px solid color-mix(in srgb, var(--c) 35%, var(--border));
  border-radius: calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0 0;
}
.section.collapsed .section-head { border-bottom: 0; border-radius: calc(var(--radius) - 1px); }
.section-toggle {
  display: flex; align-items: center; gap: 10px; margin-right: auto; padding: 2px 4px 2px 0;
  border: 0; background: transparent; font-size: 17px; font-weight: 700; text-align: left;
}
.section-toggle .chev { display: inline-block; width: 14px; color: var(--muted); transition: rotate .15s; }
.section:not(.collapsed) .section-toggle .chev { rotate: 90deg; }
.section-toggle .icon {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--c); color: #fff; font-size: 14px; font-weight: 800;
}
.section-toggle .count {
  min-width: 30px; padding: 1px 9px; border-radius: 999px; text-align: center; font-size: 14px;
  background: color-mix(in srgb, var(--c) 28%, transparent); font-variant-numeric: tabular-nums;
}
.section-toggle .count small { opacity: .7; font-weight: 500; }
.section-head .seg, .section-head select { cursor: auto; }
.section-head:hover .section-toggle .chev { color: var(--text); }
.section-head select.small { padding: 5px 8px; font-size: 13px; }
.section-body { padding: 14px; }
.section.collapsed .section-body { display: none; }
.section.drop-target { outline: 3px dashed var(--c); outline-offset: 3px; }
.section.drop-target .empty-drop { border-style: solid; color: var(--text); background: color-mix(in srgb, var(--c) 12%, transparent); }
.section.drop-target .section-head { background: color-mix(in srgb, var(--c) 28%, var(--bg-2)); }
.empty-drop {
  display: none; padding: 26px 16px; text-align: center; color: var(--muted);
  border: 2px dashed color-mix(in srgb, var(--c) 40%, var(--border)); border-radius: 10px;
}
.grid:empty { display: none; }
.grid:empty + .empty-drop { display: block; }
.section .summary { margin-top: 18px; }
body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select: none; }

.card {
  position: relative; background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border); overflow: hidden; display: flex; flex-direction: column;
  box-shadow: inset 0 4px 0 var(--c); user-select: none; -webkit-user-select: none;
}
.card .thumb {
  position: relative; aspect-ratio: 4 / 3; background: var(--surface-2); cursor: zoom-in; overflow: hidden;
  margin-top: 4px;
}
.card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; -webkit-user-drag: none; }
.card .thumb:hover img { transform: scale(1.03); }
.card .badges { position: absolute; top: 6px; left: 6px; right: 6px; display: flex; gap: 5px; flex-wrap: wrap; pointer-events: none; }
.badge {
  font-size: 11px; font-weight: 700; letter-spacing: .02em; padding: 2px 7px; border-radius: 999px;
  background: rgb(0 0 0 / .62); color: #fff; backdrop-filter: blur(4px);
}
.badge.new { background: var(--accent); }
.badge.rare { background: #8b5cf6; }
.badge.cat { background: var(--c); }
.card .body { padding: 8px 10px 10px; display: grid; gap: 7px; }
.card .row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.card .meta { font-size: 12px; color: var(--muted); display: flex; gap: 10px; }
.card .total { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; display: inline-flex; align-items: center; gap: 4px; }
.card .total .s { color: var(--star); }
.card .total small { color: var(--muted); font-weight: 500; }
.card .thumb { -webkit-touch-callout: none; cursor: grab; }
.card .thumb:active { cursor: grabbing; }
.card.pressing .thumb img { transform: scale(.96); transition: transform .35s; }
.card.dragging { opacity: .35; outline: 2px dashed var(--accent); }
.card.drop-slot {
  border: 2px dashed var(--accent); box-shadow: none;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.card.ghost {
  position: fixed; z-index: 100; pointer-events: none; opacity: .92; box-shadow: var(--shadow); transform-origin: 0 0;
  transition: none; rotate: 2deg;
}

.stars { display: inline-flex; gap: 1px; }
.stars button {
  border: 0; background: transparent; padding: 0 1px; font-size: 18px; line-height: 1; color: var(--border);
  transition: transform .1s, color .1s;
}
.stars button.on { color: var(--star); }
.stars button:hover { transform: scale(1.2); }
.stars.big button { font-size: 30px; }
.stars:hover button { color: var(--star); }
.stars button:hover ~ button { color: var(--border); }

.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.quick button {
  border: 1px solid color-mix(in srgb, var(--c) 50%, transparent); background: transparent; border-radius: 7px;
  padding: 4px 0; font-weight: 800; font-size: 13px; color: var(--c);
}
.quick button:hover { background: color-mix(in srgb, var(--c) 18%, transparent); }
.quick button.on { background: var(--c); color: #fff; border-color: var(--c); }

.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); font-size: 12px; border: 1px solid var(--border); max-width: 100%;
}
.chip .n { font-size: 10.5px; font-weight: 700; padding: 0 5px; border-radius: 999px; background: color-mix(in srgb, var(--c-yes) 30%, transparent); }
.chip.rare { border-color: #8b5cf6; }
.chip.rare .n { background: #8b5cf6; color: #fff; }
.chip button { border: 0; background: transparent; padding: 0 0 0 2px; color: var(--muted); font-size: 14px; line-height: 1; }
.chip button:hover { color: var(--danger); }

/* ---------- Yes summary ---------- */
.summary {
  margin-top: 28px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: inset 4px 0 0 var(--c-yes);
}
.summary h2 { margin: 0 0 4px; font-size: 18px; }
.summary .sub { color: var(--muted); font-size: 13.5px; margin-bottom: 14px; }
.bars { display: grid; grid-template-columns: minmax(80px, max-content) 1fr auto; gap: 6px 12px; align-items: center; }
.bars .name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .bar { height: 14px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bars .bar i { display: block; height: 100%; background: var(--c-yes); border-radius: 4px; }
.bars .val { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 14px; text-align: right; min-width: 2ch; }
.bars .zero .name, .bars .zero.val { color: var(--muted); }

/* ---------- side panel (people) ---------- */
.backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / .5); z-index: 40; }
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100vw); z-index: 41;
  background: var(--bg-2); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.panel header { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.panel header h2 { margin: 0; font-size: 17px; margin-right: auto; }
.panel .content { overflow-y: auto; padding: 14px 16px 30px; display: grid; gap: 14px; align-content: start; }
.panel form { display: flex; gap: 8px; }
.panel form input { flex: 1; min-width: 0; }
.people-table { display: grid; gap: 4px; }
.person-row {
  display: grid; grid-template-columns: 1fr auto auto auto; gap: 8px; align-items: center;
  padding: 8px 10px; border-radius: 9px; background: var(--surface); border: 1px solid var(--border);
}
.person-row.rare { border-color: #8b5cf6; }
.person-row .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-row .nm small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.pill { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; font-variant-numeric: tabular-nums; }
.pill.yes { background: color-mix(in srgb, var(--c-yes) 25%, transparent); }
.pill.cand { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.legend { font-size: 12.5px; color: var(--muted); }

/* ---------- viewer ---------- */
.viewer {
  position: fixed; inset: 0; z-index: 50; background: rgb(8 10 14 / .96); color: #e8ebf2;
  display: grid; grid-template-columns: 1fr 380px;
}
.viewer .stage { position: relative; display: grid; place-items: center; min-height: 0; min-width: 0; padding: 16px; }
.viewer .stage img, .viewer .stage video { max-width: 100%; max-height: calc(100vh - 32px); object-fit: contain; border-radius: 6px; }
.viewer .nav {
  position: absolute; top: 50%; translate: 0 -50%; width: 46px; height: 64px; border-radius: 10px; border: 0;
  background: rgb(0 0 0 / .45); color: #fff; font-size: 26px;
}
.viewer .nav:hover { background: rgb(0 0 0 / .7); }
.viewer .nav:disabled { opacity: .25; cursor: default; }
.viewer .nav.prev { left: 12px; }
.viewer .nav.next { right: 12px; }
.viewer .close {
  position: absolute; top: 12px; left: 12px; z-index: 1;
  /* the viewer is always dark, so don't inherit the light-theme button colours */
  background: rgb(0 0 0 / .55); color: #fff; border-color: rgb(255 255 255 / .25);
}
.viewer .close:hover { background: rgb(0 0 0 / .8); border-color: rgb(255 255 255 / .5); }
.viewer .pos { position: absolute; bottom: 14px; left: 50%; translate: -50% 0; font-size: 13px; color: #aab; background: rgb(0 0 0 / .5); padding: 3px 10px; border-radius: 999px; }
.viewer aside {
  background: var(--bg-2); color: var(--text); border-left: 1px solid var(--border); overflow-y: auto;
  padding: 16px; display: grid; gap: 18px; align-content: start;
}
.viewer aside h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.catpick { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.catpick button {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 9px; font-weight: 700;
  border: 2px solid color-mix(in srgb, var(--c) 50%, transparent); background: color-mix(in srgb, var(--c) 8%, transparent);
}
.catpick button.on { background: var(--c); border-color: var(--c); color: #fff; }
.catpick kbd, .kbd { font: 11px ui-monospace, monospace; padding: 1px 5px; border-radius: 4px; border: 1px solid currentColor; opacity: .6; margin-left: auto; }
.ratings-list { display: grid; gap: 3px; font-size: 13.5px; margin-top: 8px; }
.ratings-list div { display: flex; justify-content: space-between; }
.ratings-list .s { color: var(--star); letter-spacing: 1px; }
.comments { display: grid; gap: 10px; }
.comment { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.comment .who { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.comment .who b { color: var(--text); }
.comment .who button { margin-left: auto; border: 0; background: transparent; color: var(--muted); font-size: 12px; }
.comment .who button:hover { color: var(--danger); }
.comment p { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.comment-form { display: grid; gap: 6px; }
.comment-form textarea { resize: vertical; min-height: 60px; }
.add-person { display: flex; gap: 6px; margin-top: 8px; }
.add-person input { flex: 1; min-width: 0; }
dl.info { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 13.5px; }
dl.info dt { color: var(--muted); }
dl.info dd { margin: 0; overflow-wrap: anywhere; }

#toast {
  position: fixed; bottom: 20px; left: 50%; translate: -50% 0; z-index: 200;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 16px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s;
  max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; }
#toast.err { border-color: var(--danger); }

@media (max-width: 860px) {
  .viewer { grid-template-columns: 1fr; grid-template-rows: 55vh 1fr; }
  .viewer .stage img, .viewer .stage video { max-height: calc(55vh - 24px); }
  .viewer aside { border-left: 0; border-top: 1px solid var(--border); }
  .viewer .nav { width: 38px; height: 52px; }
}
@media (max-width: 600px) {
  :root { --card: 150px; }
  .top-row { padding: 8px 12px; }
  .tabs, .toolbar, .hint { padding-left: 12px; padding-right: 12px; }
  main { padding: 0 12px 60px; }
  .grid { gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(var(--card), calc(50% - 5px)), 1fr)); }
  .size-control { display: none !important; }
  .card .body { padding: 7px 8px 8px; }
  .stars button { font-size: 16px; padding: 0; }
  .tab { padding: 6px 8px; gap: 6px; }
  .tab .label { display: none; }
  .tabs { gap: 6px; }
  .section-body { padding: 10px; }
  .section-head { padding: 8px 10px; }
  .section-head .seg { width: 100%; }
  .section-head .seg button { flex: 1; padding: 5px 4px; font-size: 12.5px; }
  .hint-long { display: none; }
  .hint-short { display: inline !important; }
  .user-chip span { display: none; }
}
@media (hover: none) {
  .card .thumb:hover img { transform: none; }
}
