/* Sprite Compare — mobile-first, no external assets.
   Layout scales from a 320px phone up to a desktop browser purely with a
   fluid grid; there is no separate "desktop mode" to keep in sync. */

:root {
  --bg: #0e1117;
  --bg-elev: #161b24;
  --bg-elev-2: #1d2430;
  --line: #262f3d;
  --text: #e6edf6;
  --text-dim: #93a1b5;
  --accent: #5b9cff;
  --a: #4dd4a4;
  --b: #ff8a5c;
  --good: #4dd4a4;
  --bad: #ff6b7a;
  --shadow: 0 6px 24px rgba(0, 0, 0, .45);
  --radius: 14px;
  --tap: 44px;

  --r-common: #9aa4b2;
  --r-uncommon: #4bd25a;
  --r-rare: #2f9bff;
  --r-epic: #b05cff;
  --r-legendary: #ff9d2b;
  --r-mythic: #ffd23f;
  --r-special: #ff5cc8;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f7fb;
    --bg-elev: #ffffff;
    --bg-elev-2: #eef2f8;
    --line: #d9e0ea;
    --text: #16202e;
    --text-dim: #5c6c80;
    --shadow: 0 4px 18px rgba(20, 35, 60, .12);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

body { padding-bottom: env(safe-area-inset-bottom); }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px 8px;
  max-width: 1100px;
  margin: 0 auto;
}

.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .2px;
}

.topbar-actions { display: flex; gap: 6px; }

.icon-btn {
  min-width: var(--tap);
  min-height: var(--tap);
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--text-dim);
}
.icon-btn:hover, .icon-btn:focus-visible { color: var(--text); background: var(--bg-elev-2); }
.icon-btn.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.viewtabs {
  display: flex;
  gap: 4px;
  padding: 0 14px 8px;
  max-width: 1100px;
  margin: 0 auto;
}

.viewtab {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
}
.viewtab.is-active { background: var(--text); color: var(--bg); border-color: var(--text); }

main { max-width: 1100px; margin: 0 auto; padding: 14px 14px 40px; }

/* ---------- person pickers ---------- */

.pickers {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr;
}

.picker {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 10px 6px;
}

.picker-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text-dim);
}

.picker-name { font-weight: 700; color: var(--text); font-size: 15px; }

.side-badge {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 800;
  color: #08111c;
}
.side-a { background: var(--a); }
.side-b { background: var(--b); }

/* Horizontal chip strip: thumb-friendly on a phone, wraps to a row on desktop. */
.chiprow {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.chiprow::-webkit-scrollbar { height: 4px; }
.chiprow::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

.chip {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}
.chip:disabled { opacity: .35; }
.picker[data-side="a"] .chip.is-on { background: var(--a); border-color: var(--a); color: #08111c; }
.picker[data-side="b"] .chip.is-on { background: var(--b); border-color: var(--b); color: #1a0d05; }

.swap-btn {
  justify-self: center;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 4px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
}
.swap-btn svg { width: 14px; height: 14px; }
.swap-btn:hover { color: var(--text); }

/* ---------- summary ---------- */

.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.stat {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 8px;
  text-align: center;
  min-width: 0;
}
.stat-shared { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }

.stat-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-value { display: block; font-size: 24px; font-weight: 800; line-height: 1.2; }
.stat-sub { display: block; font-size: 11px; color: var(--text-dim); }

/* ---------- filters ---------- */

.filters { margin-top: 14px; }

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 7px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.tab .n {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--bg-elev-2);
  font-size: 12px;
  color: var(--text);
}
.tab.is-on { background: var(--text); color: var(--bg); border-color: var(--text); }
.tab.is-on .n { background: color-mix(in srgb, var(--bg) 25%, transparent); color: var(--bg); }

.filter-row { display: flex; gap: 8px; margin-top: 8px; }

.search {
  flex: 1;
  min-height: var(--tap);
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
}
.search::placeholder { color: var(--text-dim); }
.search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.ghost-btn {
  min-height: var(--tap);
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
}
.ghost-btn:hover { color: var(--text); }
.ghost-btn.wide { width: 100%; margin-top: 12px; }

/* ---------- sprite grid ---------- */

.grid {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
}

.card {
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-top: 3px solid var(--rarity, var(--line));
  border-radius: 12px;
  padding: 8px 6px 7px;
  text-align: center;
  min-width: 0;
}

.card img {
  width: 100%;
  max-width: 76px;
  aspect-ratio: 1;
  object-fit: contain;
  margin: 0 auto 4px;
  display: block;
  image-rendering: -webkit-optimize-contrast;
}

.card .nm {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.card .meta {
  margin-top: 3px;
  font-size: 10px;
  color: var(--text-dim);
  display: flex;
  justify-content: center;
  gap: 5px;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .2px;
}
.badge.owned { background: color-mix(in srgb, var(--good) 22%, transparent); color: var(--good); }
.badge.mastered { background: color-mix(in srgb, var(--r-mythic) 22%, transparent); color: var(--r-mythic); }
.badge.missing { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }

.card.dim img { filter: grayscale(1); opacity: .45; }

/* list mode — denser, easier to scan long "missing" lists on a phone */
.grid.list { grid-template-columns: 1fr; gap: 6px; }
.grid.list .card {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 10px;
  text-align: left;
  border-top: 1px solid var(--line);
  border-left: 3px solid var(--rarity, var(--line));
  padding: 6px 10px;
}
.grid.list .card img { width: 40px; max-width: 40px; margin: 0; }
.grid.list .card .nm { font-size: 14px; }
.grid.list .card .meta { margin: 0; justify-content: flex-end; }

/* ---------- everyone board ---------- */

.board { display: grid; gap: 8px; margin-top: 6px; }

.board-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.rank { font-size: 13px; font-weight: 800; color: var(--text-dim); min-width: 20px; }
.board-name { font-weight: 700; min-width: 0; }
.board-label { display: block; font-size: 12px; color: var(--text-dim); font-weight: 400; overflow-wrap: anywhere; }
.board-num { text-align: right; }
.board-num b { font-size: 20px; }
.board-num span { display: block; font-size: 11px; color: var(--text-dim); }

.bar {
  grid-column: 1 / -1;
  height: 6px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  overflow: hidden;
}
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--a), var(--accent)); }

/* ---------- people sheet ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  z-index: 30;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 31;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg-elev);
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow);
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
}
@media (min-width: 720px) {
  .sheet {
    left: 50%;
    right: auto;
    bottom: auto;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(520px, 92vw);
    border-radius: 18px;
    border: 1px solid var(--line);
  }
  .sheet-grab { display: none; }
}

.sheet-grab {
  width: 40px;
  height: 4px;
  border-radius: 4px;
  background: var(--line);
  margin: 4px auto 10px;
}

.sheet h2 { margin: 0 0 12px; font-size: 18px; }
.sheet h3 { margin: 18px 0 8px; font-size: 14px; color: var(--text-dim); }

.people-list { display: grid; gap: 6px; }

.person-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev-2);
}
.person-row .who { min-width: 0; }
.person-row b { display: block; }
.person-row small { color: var(--text-dim); overflow-wrap: anywhere; }

.del-btn {
  min-width: 38px;
  min-height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--bad);
  font-weight: 700;
}

.add-form { display: grid; gap: 8px; }
.add-form input {
  min-height: var(--tap);
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  color: var(--text);
}
.add-form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.primary-btn {
  min-height: var(--tap);
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #08111c;
  font-weight: 700;
}
.primary-btn:disabled { opacity: .6; }

.add-error { margin: 4px 0 0; color: var(--bad); font-size: 13px; }

/* ---------- misc ---------- */

.status {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text-dim);
  font-size: 14px;
}
.status.err { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }

.empty, .hint, .fetched { color: var(--text-dim); font-size: 13px; }
.empty { text-align: center; padding: 28px 10px; }
.hint { margin: 4px 0 10px; }
.fetched { margin-top: 18px; text-align: center; font-size: 11px; }

/* Any author rule that sets `display` outranks the UA stylesheet's
   `[hidden] { display: none }`, so elements with a display of their own —
   .add-form, .icon-btn, .view — stayed visible when JS set hidden = true.
   One global rule instead of remembering to patch each class as it bites. */
[hidden] { display: none !important; }

@media (min-width: 720px) {
  .pickers { grid-template-columns: 1fr auto 1fr; align-items: start; }
  .swap-btn { margin-top: 28px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}

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