:root {
  color-scheme: dark;
  --bg: #0e131a;
  --surface: #161d27;
  --raised: #1d2632;
  --hairline: #263140;
  --text: #e6ebf1;
  --muted: #8d99aa;
  --need: #f0524a;            /* "want": red */
  --green: #4cc38a;
  --on-need: #1a0807;         /* text on red/green name bars */
  --on-have: #04170d;
  --accent-text: #0e131a;
  --shadow: 0 10px 30px rgba(0, 0, 0, .5);
  --scrim: rgba(0, 0, 0, .55);
  --danger: #ff8a7a;
  --tier-unique: #e3b341;
  --tier-special: #b58cf0;
  /* In-game rarity slot backgrounds, sampled from the inventory UI. Same in both schemes: they are game art. */
  --rar-legendary: linear-gradient(180deg, #302d26 0%, #6f5d23 45%, #a3881d 100%);
  --rar-epic: linear-gradient(180deg, #29272b 0%, #4b3052 55%, #63396e 100%);
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f2f4f7;
    --surface: #ffffff;
    --raised: #e6eaf0;
    --hairline: #d3dae3;
    --text: #17202b;
    --muted: #596779;
    --need: #d32f2f;
    --green: #1b9660;
    --on-need: #ffffff;
    --on-have: #ffffff;
    --accent-text: #ffffff;
    --shadow: 0 10px 30px rgba(20, 30, 45, .22);
    --scrim: rgba(20, 30, 45, .4);
    --danger: #b3261e;
    --tier-unique: #a87a00;
    --tier-special: #7c4dc4;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
button { font: inherit; color: inherit; cursor: pointer; }

/* header */
.top {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 8px 12px; padding: 10px 14px;
  border-bottom: 1px solid var(--hairline);
  position: sticky; top: 0; z-index: 5; background: var(--bg);
}
.brand h1 { margin: 0; font-size: 14px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; }
.legend { margin: 2px 0 0; font-size: 11px; color: var(--muted); }
.lg { margin-left: 6px; }
.lg:first-child { margin-left: 0; }
.lg.need { color: var(--need); }
.lg.have { color: var(--green); }
.actions { display: flex; align-items: center; gap: 8px; }
.me-wrap { position: relative; }

.chip {
  background: var(--surface); border: 1px solid var(--hairline); border-radius: 999px;
  padding: 6px 12px; min-height: 34px; font-size: 13px;
}
.chip:hover { border-color: var(--muted); }
.chip.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
#names-toggle[aria-pressed="true"] { border-color: var(--need); color: var(--need); }
#names-toggle[aria-pressed="true"]::before { content: "\2713\00a0"; }

.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 170px; z-index: 30;
  background: var(--surface); border: 1px solid var(--hairline); border-radius: 10px;
  box-shadow: var(--shadow); padding: 4px; display: flex; flex-direction: column;
}
.menu button { background: none; border: 0; text-align: left; padding: 9px 10px; border-radius: 6px; }
.menu button:hover { background: var(--raised); }

/* board */
.board { padding: 14px; max-width: 1400px; margin: 0 auto; }
.tier + .tier { margin-top: 26px; }
.tier { scroll-margin-top: calc(var(--top-h, 110px) + 10px); } /* --top-h = sticky header height, set in app.js */
.tier-head {
  display: flex; align-items: center; gap: 7px; margin: 0 0 10px 1px;
  font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.tier-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.tier[data-tier="unique"] .tier-dot { background: var(--tier-unique); }
.tier[data-tier="special"] .tier-dot { background: var(--tier-special); }
.tier-crate { margin-left: 4px; font-weight: 500; letter-spacing: .02em; text-transform: none; color: var(--muted); opacity: .85; }
.colls {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(330px, 100%), 1fr)); gap: 12px;
}
/* each collection is its own panel so neighbouring collections don't run together */
.coll {
  background: var(--surface); border: 1px solid var(--hairline); border-radius: 10px;
  padding: 8px 8px 6px;
}
.jump { margin-top: 2px; font-size: 11px; color: var(--muted); }
.jump a { color: var(--muted); text-decoration: none; }
.jump a:hover { color: var(--text); text-decoration: underline; }
.status { color: var(--muted); text-align: center; margin: 40px 0; }
.coll-label { margin: 0 0 6px 1px; font-size: 11px; color: var(--muted); letter-spacing: .03em; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; align-items: start; } /* icons line up even when bar counts differ */

.tile {
  position: relative; display: block; padding: 0; border: 0; background: none;
  border-radius: 4px; min-width: 0;
  transition: opacity .2s, box-shadow .2s;
}
.face {
  display: block; aspect-ratio: 1; padding: 4px; background: var(--raised);
  border: 1px solid rgba(0, 0, 0, .35); border-radius: 4px; overflow: hidden;
}
.tier[data-tier="unique"] .face { background: var(--rar-legendary); }
.tier[data-tier="special"] .face { background: var(--rar-epic); }
.face img { width: 100%; height: 100%; object-fit: contain; display: block; }
.strip {
  display: flex; height: 3px; margin-top: 3px; border-radius: 2px; overflow: hidden;
}
.strip i { flex: 1; display: block; background: transparent; }
.strip .n { background: var(--need); }
.strip .h { background: var(--green); }
.tile.match .strip { height: 5px; }
.strip[hidden], .bars[hidden] { display: none; }
.bars { display: flex; flex-direction: column; gap: 2px; margin-top: 3px; text-align: left; }
.bar {
  display: flex; height: 15px; line-height: 15px; padding: 0 4px; border-radius: 3px;
  font-size: 10.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bar .who { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.bar .when { flex: none; white-space: pre; }
.bar.bn { background: var(--need); color: var(--on-need); }
.bar.bh { background: var(--green); color: var(--on-have); }
.bar.old { opacity: .35; }
.bar.more { color: var(--muted); font-weight: 500; padding: 0 2px; }
/* match: a crisp ring + soft glow, strong enough to read on the gold/purple slots */
.tile.match.m-need .face {
  border-color: var(--need);
  box-shadow: 0 0 0 1px var(--need), 0 0 14px color-mix(in srgb, var(--need) 55%, transparent);
}
.tile.match.m-have .face {
  border-color: var(--green);
  box-shadow: 0 0 0 1px var(--green), 0 0 14px color-mix(in srgb, var(--green) 55%, transparent);
}
.tile[aria-expanded="true"] .face { outline: 2px solid var(--text); outline-offset: -1px; }

/* corner labels styled like the game's stack counts: white, bold, dark shadow */
.mark, .qty {
  position: absolute; font-weight: 700; line-height: 1; color: #fff; pointer-events: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .9), 0 0 3px rgba(0, 0, 0, .6);
}
.mark { right: 6px; bottom: 5px; font-size: 13px; }               /* how many I have */
.qty { left: 6px; bottom: 5px; font-size: 11px; opacity: .85; }   /* copies the collection needs */
.face { position: relative; }
.mark.dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--need);
  top: 6px; right: 6px; bottom: auto; box-shadow: 0 0 0 1.5px rgba(0, 0, 0, .55);
}

/* popover */
.pop {
  position: fixed; z-index: 20; width: 300px; max-width: calc(100vw - 16px);
  background: var(--surface); border: 1px solid var(--hairline); border-radius: 12px;
  box-shadow: var(--shadow); padding: 14px;
}
.pop-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.pop-title { display: flex; flex-direction: column; min-width: 0; }
.pop-title strong { font-size: 16px; }
.pop-sub { color: var(--muted); font-size: 12px; }
.icon-btn { background: none; border: 0; font-size: 24px; line-height: 1; padding: 2px 8px; color: var(--muted); border-radius: 6px; }
.pop-edit, .pop-ro { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--hairline); }
.need-btn {
  width: 100%; padding: 10px; border-radius: 8px; background: var(--raised);
  border: 1px solid var(--hairline); font-weight: 600;
}
.need-btn[aria-pressed="true"] { background: var(--need); color: var(--accent-text); border-color: var(--need); }
.need-btn[aria-pressed="true"]::after { content: " \2713"; }
.have-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.row-label { flex: 1; color: var(--muted); }
.step {
  width: 38px; height: 38px; border-radius: 8px; border: 1px solid var(--hairline);
  background: var(--raised); font-size: 20px; line-height: 1;
}
.step:disabled { opacity: .35; cursor: default; }
#pop-count { min-width: 2ch; text-align: center; font-size: 17px; font-variant-numeric: tabular-nums; }
.pop-msg { margin: 8px 0 0; min-height: 0; color: var(--danger); font-size: 13px; }
.pop-msg:empty { display: none; }
.pop-lists { margin: 12px 0 0; padding-top: 10px; border-top: 1px solid var(--hairline); display: grid; gap: 6px; font-size: 14px; }
.pop-lists > div { display: flex; gap: 10px; }
.pop-lists dt { width: 74px; flex: none; color: var(--muted); }
.pop-lists dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.pop-lists .old { color: var(--muted); }
.pop-lists .none { color: var(--muted); }

@media (max-width: 600px) {
  .pop {
    left: 0 !important; right: 0; top: auto !important; bottom: 0; width: auto; max-width: none;
    border-radius: 16px 16px 0 0; border-bottom: 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
    animation: sheet .18s ease-out;
  }
  .step { width: 44px; height: 44px; }
  .board { padding: 10px; }
  .colls { gap: 14px; }
  .coll { padding: 6px 6px 5px; }
  .bar { font-size: 10px; padding: 0 3px; letter-spacing: -.01em; }
}
@keyframes sheet { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

/* dialogs */
dialog {
  background: var(--surface); color: var(--text); border: 1px solid var(--hairline);
  border-radius: 14px; padding: 18px; width: min(360px, calc(100vw - 24px)); box-shadow: var(--shadow);
}
dialog::backdrop { background: var(--scrim); }
dialog h2 { margin: 0 0 12px; font-size: 17px; }
dialog label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
dialog input {
  display: block; width: 100%; margin-top: 4px; padding: 10px; font: inherit; font-size: 16px;
  color: var(--text); background: var(--bg); border: 1px solid var(--hairline); border-radius: 8px;
}
dialog p { margin: 0 0 14px; }
.err { color: var(--danger); font-size: 13px; min-height: 0; }
.err:empty { display: none; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: 10px;
  max-width: calc(100vw - 24px); font-size: 14px; box-shadow: var(--shadow);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
