:root {
  --bg: #171a21;
  --panel: #1f2530;
  --panel2: #262d3a;
  --line: #333b4a;
  --text: #e6e9ef;
  --muted: #9aa4b6;
  --accent: #5b8cff;
  --owned: #3ecf8e;
  --master: #f5c451;
  --miss: #e2617a;
  --topbar-h: 52px;
  --tabs-h: 62px;
  --pad: max(14px, env(safe-area-inset-left));
}

* { box-sizing: border-box; }

/* Several components below set `display`, which would otherwise beat the UA's
   low-specificity [hidden] rule and leave an invisible overlay eating clicks. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}
body.locked { overflow: hidden; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.inline { display: inline; margin: 0; }
.linkbtn {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font: inherit; padding: 0;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------------ header */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  height: var(--topbar-h);
  padding: 0 var(--pad);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 700; color: var(--text); white-space: nowrap;
  font-size: 15px; letter-spacing: .2px;
}
.topbar .who { color: var(--muted); margin-left: auto; }
.search {
  flex: 1; min-width: 0; margin-left: auto;
  height: 34px; padding: 0 12px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px;
  font-size: 16px; /* 16px stops iOS zooming on focus */
}
.search::placeholder { color: var(--muted); }

.iconbtn {
  flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  background: none; border: none; border-radius: 10px;
  color: var(--muted); cursor: pointer; font-size: 22px; line-height: 1;
}
.iconbtn:hover { background: var(--panel2); color: var(--text); }

/* -------------------------------------------------------------- season bar */
.seasonbar {
  position: sticky; top: var(--topbar-h); z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 8px var(--pad) 10px;
}
.tabs {
  display: flex; gap: 6px;
  overflow-x: auto; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none;
  padding: 7px 14px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line);
  color: var(--muted); font-size: 14px; font-weight: 600;
  white-space: nowrap;
}
.tab:hover { text-decoration: none; color: var(--text); }
.tab.active {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.tab.archived:not(.active) { opacity: .62; }

.progress { margin-top: 9px; }
.bar {
  position: relative; height: 6px; border-radius: 999px;
  background: var(--panel2); overflow: hidden;
}
.bar .fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  border-radius: 999px; transition: width .2s ease;
}
.bar .fill.own { background: var(--owned); }
.bar .fill.master { background: var(--master); }
.progress-text {
  margin: 6px 0 0; font-size: 13px; color: var(--muted);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.progress-text b { color: var(--text); }

.chip {
  display: inline-block;
  padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel);
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .4px; color: var(--muted);
}
.archived-chip { color: var(--muted); }

/* ----------------------------------------------------------------- layout */
.container { max-width: 1100px; margin: 0 auto; padding: 16px var(--pad) 64px; }
.flash {
  background: #2a3140; border: 1px solid var(--line); color: var(--text);
  padding: 10px 14px; border-radius: 10px; margin-bottom: 14px;
}
.empty { color: var(--muted); text-align: center; padding: 44px 16px; }
.empty p { margin: 0 0 14px; }
.empty button.primary { width: auto; }

/* An active filter has to be visible from the board, not just inside the drawer. */
.iconbtn.has-filters { color: var(--text); position: relative; }
.iconbtn.has-filters::after {
  content: ""; position: absolute; top: 6px; right: 6px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--panel);
}

/* ------------------------------------------------------------------ board */
.group { margin-bottom: 26px; }
.group-head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 10px; flex-wrap: wrap;
}
.group-head h2 { margin: 0; font-size: 17px; }
.group-count { margin-left: auto; color: var(--muted); font-size: 13px; }

.r-rare { color: #6bc1ff; border-color: #2f5a7a; }
.r-epic { color: #c48bff; border-color: #5a3f7a; }
.r-legendary { color: #ffcf6b; border-color: #7a6330; }
.r-mythic { color: #ff8f6b; border-color: #7a4030; }
.r-special { color: var(--muted); }

.variant-grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
}

.card.sprite {
  position: relative;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: border-color .12s ease, background .12s ease;
}
.card.sprite:hover { border-color: #47526a; }
.card.sprite.owned { border-color: var(--owned); background: #1c2a26; }
.card.sprite.mastered { border-color: var(--master); background: #2a2620; }

.thumb { position: relative; aspect-ratio: 1; }
.thumb img {
  width: 100%; height: 100%; object-fit: contain;
  display: block; opacity: .45; transition: opacity .12s ease;
}
.card.sprite.owned .thumb img { opacity: 1; }

.mark {
  position: absolute; top: 2px; right: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  display: none; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #10151c;
}
.card.sprite.owned .mark.own { display: flex; background: var(--owned); }
.card.sprite.mastered .mark.own { display: none; }
.card.sprite.mastered .mark.master { display: flex; background: var(--master); }

.card-foot {
  display: flex; align-items: center; gap: 4px;
  margin-top: 6px;
}
.theme {
  flex: 1; min-width: 0;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.theme-basic { color: #cdd3df; }
.theme-gold { color: #f5c451; }
.theme-candy { color: #ff8fc7; }
.theme-galaxy { color: #a48bff; }
.theme-gem { color: #6bd6ff; }
.theme-holofoil { color: #7bf5c4; }
.theme-cube { color: #ff8f6b; }
.theme-quack { color: #ffd76b; }
.theme-cheat { color: #7ad4ff; }

.info {
  flex: none; width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: 6px;
  color: var(--muted); cursor: pointer; padding: 0;
}
.info:hover { background: var(--panel2); color: var(--text); }

.dots { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 5px; min-height: 7px; }
.dot { width: 7px; height: 7px; border-radius: 50%; }
.dot.own { background: var(--owned); }
.dot.miss { background: var(--miss); opacity: .55; }
.dot.self { box-shadow: 0 0 0 2px var(--panel), 0 0 0 3px var(--text); }
body.nodots .dots { display: none; }

/* Compact: flatten every group into one dense grid. */
body.compact .group { display: contents; }
body.compact .group-head { display: none; }
body.compact .variant-grid { display: contents; }
body.compact .board {
  display: grid; gap: 7px;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
}
body.compact .card-foot, body.compact .dots { display: none; }
body.compact .card.sprite { padding: 5px; border-radius: 9px; }

/* ----------------------------------------------------------------- drawer */
.drawer-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, .55);
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 50;
  width: 100%;   /* full-width sheet on phones; a side panel from 480px up */
  background: var(--panel); border-left: 1px solid var(--line);
  padding: 0 var(--pad) calc(24px + env(safe-area-inset-bottom));
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform .18s ease;
  visibility: hidden;
}
.drawer.open { transform: none; visibility: visible; }
@media (prefers-reduced-motion: reduce) { .drawer { transition: none; } }

.drawer-head {
  position: sticky; top: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.drawer-head h2 { margin: 0; font-size: 16px; }
.drawer-sec { padding: 16px 0; border-bottom: 1px solid var(--line); }
.drawer-sec h3 {
  margin: 0 0 12px; font-size: 12px; text-transform: uppercase;
  letter-spacing: .6px; color: var(--muted);
}
.drawer-foot {
  border-bottom: none;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.drawer-foot p { margin: 0; }

.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; min-height: 44px; cursor: pointer; font-size: 15px;
}
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.slider {
  position: absolute; inset: 0; border-radius: 999px;
  background: var(--panel2); border: 1px solid var(--line);
  transition: background .15s ease;
}
.slider::before {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--muted); transition: transform .15s ease, background .15s ease;
}
.switch input:checked + .slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); background: #fff; }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }

.field {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; min-height: 44px; font-size: 15px;
}
.field select {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font-size: 15px; min-width: 140px;
}

.leaderboard { margin: 0; padding-left: 20px; }
.leaderboard li {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 5px 0; color: var(--muted);
}
.leaderboard li.self { color: var(--text); font-weight: 600; }
.leaderboard b { color: var(--master); }

/* ------------------------------------------------------------------ modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0, 0, 0, .6);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal {
  position: relative;
  width: min(440px, 100%); max-height: 80vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 18px;
}
.modal h2 { margin: 0 36px 12px 0; font-size: 17px; }
.modal .close { position: absolute; top: 6px; right: 6px; }
.owner-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.owner-cols h4 { margin: 0 0 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; }
.owner-cols ul { margin: 0; padding-left: 18px; }
.owner-cols li { padding: 2px 0; }
.count { color: var(--muted); font-weight: 400; }

/* ------------------------------------------------------------------- auth */
.auth {
  max-width: 340px; margin: 8vh auto 0; background: var(--panel);
  padding: 26px; border-radius: 14px; border: 1px solid var(--line);
}
.auth h1 { margin-top: 0; font-size: 20px; }
.auth label { display: block; margin: 14px 0; color: var(--muted); font-size: 14px; }
.auth input {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); font-size: 16px;
}
button.primary {
  background: var(--accent); color: #fff; border: none; padding: 11px 16px;
  border-radius: 9px; font-size: 15px; cursor: pointer; width: 100%; margin-top: 8px;
}
button.primary:hover { filter: brightness(1.08); }

/* ------------------------------------------------------------------ admin */
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th, .admin-table td {
  text-align: left; padding: 8px; border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.admin-table th { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.admin-thumb { width: 40px; height: 40px; object-fit: contain; display: block; }
.admin-table input[type="url"], .admin-table input[type="text"] {
  width: 100%; padding: 7px 9px; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 7px; font-size: 14px;
}
.admin-wrap { overflow-x: auto; }
.sync-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 16px; margin-bottom: 22px;
}
.sync-card h2 { margin: 0 0 6px; font-size: 16px; }
.sync-card p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.sync-card button.primary { width: auto; }

/* ----------------------------------------------------------------- wider */
@media (min-width: 480px) {
  .drawer { width: 360px; }
}

@media (min-width: 640px) {
  :root { --pad: max(20px, env(safe-area-inset-left)); }
  .brand { font-size: 16px; }
  .search { max-width: 320px; }
  .variant-grid { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); }
  body.compact .board { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
  .group-head h2 { font-size: 19px; }
}
