/* Theme palettes. Night is the :root default (see its block), so the page is right before JS. */
:root[data-theme="charcoal"] {
  color-scheme: dark;
  --bg: #18171a; --bg2: #211f23; --panel: #242226; --panel2: #34313a; --line: #3b373d;
  --text: #f1ece4; --muted: #a39b90; --accent: #f2b632; --onaccent: #1d1606;
  --owned: #f2b632; --bar: #f2b632; --head: #f2b632; --cardbg: #2e2b30;
  --error: #ff6b7a;
  /* extras derived per theme */
  --page-bg: var(--bg);
  --onbg: var(--text); --onbg-muted: var(--muted); --onbg-error: var(--error);
  --top-bg: var(--bg2); --top-border: 2px solid var(--line);
  --brand: var(--head); --brand-shadow: none; --head-shadow: none;
  --tile-shadow: none; --card-shadow: none; --card-owned-shadow: none;
  --onowned: #1d1606;
  --seg-on-bg: var(--accent); --seg-on-shadow: none;
  --track-bg: var(--panel2); --track-border: 0 solid transparent;
  --pct-color: #fff7e8; --pct-shadow: 0 0 2px #000, 0 0 3px #000, 0 1px 1px #000;
  --hint-bg: var(--bg); --hint-shadow: 0 6px 18px #000a;
  --btn-bg: var(--accent); --btn-shadow: none;
  --top-extra: 0px;
}
:root[data-theme="warm"] {
  color-scheme: dark;
  --bg: #2b1d14; --bg2: #3a2719; --panel: #f3e3c3; --panel2: #e6cfa3; --line: #8a5a2b;
  --text: #3b2614; --muted: #7a5a3a; --accent: #e0a526; --onaccent: #3b2614;
  --owned: #4f9a2b; --bar: #4f9a2b; --head: #f6d27a; --cardbg: #fff4dc;
  --error: #b3261e;
  --page-bg: var(--bg);
  --onbg: #f3e3c3; --onbg-muted: #cdb48a; --onbg-error: #ff9a8f;
  --top-bg: linear-gradient(#4a3020, #3a2719); --top-border: 4px solid #8a5a2b; --top-extra: 2px;
  --brand: var(--head); --brand-shadow: 0 2px 0 #000; --head-shadow: 0 2px 0 #000;
  --tile-shadow: inset 0 0 0 2px #fff6, 0 3px 0 #8a5a2b; --card-shadow: 0 3px 0 #8a5a2b;
  --card-owned-shadow: 0 3px 0 #8a5a2b;
  --onowned: #2b1d14;
  --seg-on-bg: linear-gradient(#f6c94d, #d9921a); --seg-on-shadow: inset 0 -3px 0 #a86a10;
  --track-bg: #d9c08f; --track-border: 2px solid #8a5a2b;
  --pct-color: #fff; --pct-shadow: 0 0 2px #2b1d14, 0 0 3px #2b1d14, 0 1px 1px #2b1d14;
  --hint-bg: var(--cardbg); --hint-shadow: 0 6px 18px #000a;
  --btn-bg: linear-gradient(#f6c94d, #d9921a); --btn-shadow: inset 0 -3px 0 #a86a10;
}
:root[data-theme="day"] {
  color-scheme: light;
  --bg: #e9f4fb; --bg2: #4aa3df; --panel: #ffffff; --panel2: #e3edf4; --line: #c9dbe8;
  --text: #1d3344; --muted: #52707f; --accent: #2f8fd6; --onaccent: #ffffff;
  --owned: #3fae3a; --bar: #3fae3a; --head: #1d3344; --cardbg: #f6fafd;
  --error: #c62828;
  --page-bg: var(--bg);
  --onbg: var(--text); --onbg-muted: var(--muted); --onbg-error: var(--error);
  --top-bg: linear-gradient(#5bb3ea, #3d95d3); --top-border: 2px solid #2f8fd6;
  --brand: #fff; --brand-shadow: 0 2px 0 #1f6ea8; --head-shadow: none;
  --tile-shadow: 0 2px 6px #1d334414; --card-shadow: 0 2px 6px #1d334414;
  --card-owned-shadow: 0 2px 6px #1d334414;
  --onowned: #12283a;
  --seg-on-bg: var(--accent); --seg-on-shadow: none;
  --track-bg: var(--panel2); --track-border: 0 solid transparent;
  --pct-color: #12283a; --pct-shadow: none;
  --hint-bg: var(--panel); --hint-shadow: 0 6px 18px #1d334440;
  --top-error: var(--error); --top-error-bg: var(--panel); --top-error-pad: 2px 10px;
  --btn-bg: var(--accent); --btn-shadow: none;
}

/* Night: muted slate-navy, flat panels, cornflower-blue accent and blue progress. Deliberately no cyan/violet glow or gold headings. */
:root, :root[data-theme="night"] {
  color-scheme: dark;
  --bg: #121a27; --bg2: #18212f; --panel: #1c2635; --panel2: #263244; --line: #2e3a4d;
  --text: #dbe3ec; --muted: #8a99ad; --accent: #7aa7ff; --onaccent: #0b1630;
  --owned: #5b95f5; --bar: #5b95f5; --head: #b4ccff; --cardbg: #1f2a3a;
  --error: #ff7b86;
  --page-bg: var(--bg);
  --onbg: var(--text); --onbg-muted: var(--muted); --onbg-error: var(--error);
  --top-bg: var(--bg2); --top-border: 1px solid var(--line);
  --brand: var(--head); --brand-shadow: none; --head-shadow: none;
  --tile-shadow: none; --card-shadow: 0 1px 0 #0b111b; --card-owned-shadow: 0 1px 0 #0b111b;
  --onowned: #081530;
  --seg-on-bg: var(--accent); --seg-on-shadow: none;
  --track-bg: var(--panel2); --track-border: 0 solid transparent;
  --pct-color: #f4f7fa; --pct-shadow: 0 0 2px #0b111b, 0 0 3px #0b111b, 0 1px 1px #0b111b;
  --hint-bg: var(--panel); --hint-shadow: 0 6px 18px #0008;
  --btn-bg: var(--accent); --btn-shadow: none;
  --top-extra: 0px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--page-bg);
  color: var(--onbg);
  font: 16px/1.4 "Baloo 2", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }
[hidden] { display: none !important; }

.top {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px calc(12px - var(--top-extra));
  background: var(--top-bg);
  border-bottom: var(--top-border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  color: var(--brand);
  text-shadow: var(--brand-shadow);
  font-weight: 800;
  font-size: 1.15rem;
  text-decoration: none;
}

.last-player {
  display: grid;
  min-width: 0;
  max-width: 260px;
  margin-left: auto;
  align-self: stretch;
  align-content: center;
  padding: 3px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  line-height: 1.25;
}
.last-player:hover { border-color: var(--accent); }
.last-caption { color: var(--muted); font-size: 0.7rem; }
.last-line {
  display: flex;
  gap: 6px;
  align-items: baseline;
  min-width: 0;
  white-space: nowrap;
}
.last-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.last-tag { flex: none; color: var(--muted); font-size: 0.75rem; }
.search-error { flex-basis: 100%; margin: 0; min-height: 0; }
.search { display: flex; gap: 8px; flex: 1 1 260px; max-width: 460px; min-width: 0; }
.search button { flex: 0 0 auto; }

input[type="text"], input[type="password"], textarea {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  background: var(--panel);
  color: var(--text);
  border: 2px solid var(--line);
  border-radius: 8px;
  font: inherit;
}
input[type="text"]:focus, input[type="password"]:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
input[type="text"]:focus, input[type="password"]:focus, textarea:focus { border-color: var(--accent); outline: none; }

button {
  padding: 10px 16px;
  background: var(--btn-bg);
  box-shadow: var(--btn-shadow);
  color: var(--onaccent);
  border: 2px solid transparent;
  border-radius: 8px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
button:hover { filter: brightness(1.1); }
button:disabled { opacity: 0.6; cursor: default; }

main { flex: 1 0 auto; width: 100%; max-width: 1100px; margin: 0 auto; padding: 16px; }
.site-footer { flex-shrink: 0; width: 100%; max-width: 1100px; margin: 0 auto; padding: 8px 16px 20px; font-size: 12px; color: var(--onbg-muted); text-align: center; }

.site-footer .disclaimer { display: block; margin-top: 2px; opacity: 0.85; }
.landing { padding: 24px 0; }
.landing h1 { margin: 0 0 8px; color: var(--head); text-shadow: var(--head-shadow); }
.landing p { color: var(--onbg-muted); max-width: 640px; }
.import-box { display: grid; gap: 10px; max-width: 640px; margin-top: 16px; }
.import-box textarea {
  font: 0.85rem monospace;
  min-height: 120px;
  resize: vertical;
}
.import-box button { justify-self: start; }
.import-box ol { color: var(--onbg-muted); margin: 0; padding-left: 20px; }
.recent-title { margin: 32px 0 8px; font-size: 1.1rem; color: var(--head); text-shadow: var(--head-shadow); }
.recent { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: grid;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
}
.chip:hover { border-color: var(--accent); }
.chip small { color: var(--muted); }

.player-head h1 { margin: 0; font-size: 1.5rem; color: var(--head); text-shadow: var(--head-shadow); }
.player-head .sub { color: var(--onbg-muted); }

.notice {
  margin: 12px 0 0;
  padding: 10px 14px;
  background: var(--panel2);
  border-left: 4px solid var(--owned);
  border-radius: 8px;
  color: var(--text);
}

.overall, .cat {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--tile-shadow);
}
.overall, .cat, .card { color: var(--text); }
.overall { margin: 16px 0 12px; }
.row { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.row .num { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cat .row { flex-direction: column; gap: 0; }
.overall .row { font-size: 1.1rem; font-weight: 700; }

.bar { position: relative; height: 18px; background: var(--track-bg); border: var(--track-border); box-sizing: border-box; border-radius: 9px; overflow: hidden; }
.bar .pct {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  color: var(--pct-color);
  text-shadow: var(--pct-shadow);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.bar > i {
  display: block;
  height: 100%;
  width: var(--pct, 0%);
  background: var(--bar);
  transition: width 0.25s ease;
}
/* Animations Off (set from the toggle) or the OS asks for reduced motion. */
:root[data-motion="off"] *, :root[data-motion="off"] *::before, :root[data-motion="off"] *::after {
  transition: none !important;
  animation: none !important;
}
@media (prefers-reduced-motion: reduce) {
  :root:not([data-motion="on"]) *, :root:not([data-motion="on"]) *::before, :root:not([data-motion="on"]) *::after {
    transition: none !important;
    animation: none !important;
  }
}
.overall .bar { height: 22px; border-radius: 11px; }
.overall .bar .pct { font-size: 0.8rem; }
.alltime { color: var(--muted); font-size: 0.8rem; margin-top: 6px; }
.cat.empty-year { opacity: 0.45; }

.cats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }

.filters { display: flex; flex-direction: column; gap: 8px; margin: 20px 0 8px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
/* First row: three equal groups filling the container. */
.filter-row.segs { display: grid; grid-template-columns: repeat(3, 1fr); }
.filter-row.segs .seg { width: 100%; }
.filter-row.segs > * { min-width: 0; }
.filter-row.segs .seg button { flex: 1 1 auto; padding: 0 12px; white-space: nowrap; }
/* Below ~960px three equal columns cannot hold the longest labels on one line (measured need ~294px per group): stack them. */
@media (max-width: 960px) {
  .filter-row.segs { grid-template-columns: 1fr; }
  .filter-row.segs .seg button { flex: 1 1 0; }
}
.top .theme-switch { flex: none; margin-left: auto; }
.last-player[hidden] ~ .search { margin-left: auto; }
.top .theme-switch button { padding: 0 12px; }
/* Every control shares one height, border and radius. */
.top .seg, .filters .seg, .filters .chip-toggle, .filters select, .filters input[type="text"] {
  box-sizing: border-box;
  height: 40px;
  border: 2px solid var(--line);
  border-radius: 8px;
}
.seg { display: flex; overflow: hidden; }
.seg button {
  border: 0;
  border-radius: 0;
  background: var(--panel);
  color: var(--muted);
  padding: 0 14px;
}
.seg button { box-shadow: none; }
.seg button.on { background: var(--seg-on-bg); box-shadow: var(--seg-on-shadow); color: var(--onaccent); }
.filters .chip-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  justify-content: center;
  white-space: nowrap;
  box-shadow: none;
  background: var(--panel);
  color: var(--muted);
}
.filters .chip-toggle.on { background: var(--seg-on-bg); box-shadow: var(--seg-on-shadow); color: var(--onaccent); border-color: var(--line); }
.filters .chip-toggle img { display: block; }
.filters input[type="text"] { padding: 0 12px; }
.filters select {
  padding: 0 12px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
}
/* Second row shares the grid: [epic | year] [name] [animations toggle]. */
.pair { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px; }
.pair > select { min-width: 0; width: 100%; }
.filter-row.segs input[type="text"] { width: 100%; max-width: none; }
.filters .anim-toggle { width: 100%; }
.filters select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

h2.village {
  margin: 28px 0 4px;
  color: var(--head);
  text-shadow: var(--head-shadow);
  font-size: 1.35rem;
  border-bottom: 2px solid var(--line);
}
h3.kind { margin: 16px 0 0; font-size: 1.05rem; color: var(--head); text-shadow: var(--head-shadow); }
h4.section { margin: 12px 0 8px; color: var(--onbg-muted); font-weight: 600; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); grid-auto-rows: 1fr; gap: 8px; }

.card {
  position: relative;
  background: var(--cardbg);
  border: 2px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--card-shadow);
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 6px 24px;
}
.card.owned {
  border-color: var(--owned);
  box-shadow: var(--card-owned-shadow);
}
.card.owned::after {
  content: "\2713";
  position: absolute;
  top: 6px;
  left: 6px;
  width: 22px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  border-radius: 50%;
  background: var(--owned);
  color: var(--onowned);
  font-weight: 800;
  font-size: 0.8rem;
}

.card img {
  width: 84px;
  height: 84px;
  object-fit: contain;
  background: var(--panel2);
  border-radius: 8px;
}
.card img.epic {
  position: absolute;
  bottom: 6px;
  right: 6px;
  width: 26px;
  height: auto;
  background: none;
  border-radius: 0;
  pointer-events: none;
}
.card.missing img:not(.epic) { filter: grayscale(0.6); opacity: 0.55; }
.card .name {
  font-size: 0.85rem;
  text-align: center;
  line-height: 1.2;
  overflow-wrap: anywhere;
  min-height: 2.4em;
}
.card.missing .name { color: var(--muted); }
/* Year sits in the reserved bottom strip so it never changes card height. */
.card .year {
  color: var(--muted);
  font-size: 0.7rem;
  position: absolute;
  bottom: 6px;
  left: 0;
  right: 0;
  text-align: center;
  line-height: 16px;
  pointer-events: none;
}
.card .info {
  box-shadow: none;
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 50%;
  font-size: 0.8rem;
  font-style: italic;
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--line);
}
.card .hint {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  z-index: 5;
  margin-top: 4px;
  padding: 8px 10px;
  background: var(--hint-bg);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 8px;
  font-size: 0.8rem;
  min-width: 200px;
  max-width: 280px;
  max-height: 40vh;
  overflow-y: auto;
  box-shadow: var(--hint-shadow);
  transform: var(--hint-transform, none);
}
.card:hover .hint, .card.show-hint .hint { display: block; }
/* One popover at a time: a pinned one wins over hovering others. */
main:has(.card.show-hint) .card:not(.show-hint) .hint { display: none !important; }
@media (hover: none) { .card:hover:not(.show-hint) .hint { display: none; } }

.empty, .msg { color: var(--onbg-muted); text-align: center; padding: 24px 0; }
.top .search-error { color: var(--top-error, var(--onbg-error)); background: var(--top-error-bg, transparent); padding: var(--top-error-pad, 0); border-radius: 8px; }
.landing p.error { color: var(--onbg-error); }
.error { color: var(--onbg-error); min-height: 1.4em; margin: 6px 0; }

@media (max-width: 600px) {
  .card .hint {
    position: fixed;
    left: 16px;
    right: 16px;
    top: auto;
    bottom: 16px;
    margin: 0;
    min-width: 0;
    max-width: none;
    max-height: 40vh;
    transform: none !important;
  }
}

@media (max-width: 520px) {
  .top { padding: 10px 16px calc(10px - var(--top-extra)); }
  main { padding: 12px 16px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
  .card .name { min-height: 3.6em; }
  .filter-row.segs { grid-template-columns: 1fr; }
  .top .theme-switch { width: 100%; }
  .filters .seg { width: 100%; }
  .seg button { flex: 1; padding: 8px 6px; }
  .filters input, .filters select { max-width: none; width: 100%; }
  .card img { width: 68px; height: 68px; }
}

/* Admin page (admin.html) */
button.secondary {
  background: var(--panel);
  box-shadow: none;
  color: var(--text);
  border-color: var(--line);
}
.admin-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.admin-decide { margin-top: 20px; }
.admin-result { max-width: 900px; }
.admin-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.admin-list .chip { display: flex; gap: 10px; align-items: center; }
.admin-list .chip img { flex: none; object-fit: contain; }
