/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0d1117;
  --bg2:         #161b22;
  --bg3:         #21262d;
  --border:      #30363d;
  --text:        #e6edf3;
  --muted:       #8b949e;
  --gold:        #c9a84c;
  --gold-dim:    #7a6530;

  --common:      #a0a0a0;
  --uncommon:    #9fcce5;
  --rare:        #c9a84c;
  --mythic:      #e86f3a;

  --W: #f5f0d6; --W-text: #555;
  --U: #1464a0; --U-text: #fff;
  --B: #3c3c3c; --B-text: #ccc;
  --R: #c82020; --R-text: #fff;
  --G: #006634; --G-text: #fff;
  --C: #999;    --C-text: #fff;

  --radius: 6px;
  --card-w: 200px;
}

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  display: flex;
  flex-direction: column;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.header-logo { font-size: 22px; }
.header-title { font-size: 18px; font-weight: 700; color: var(--gold); letter-spacing: -0.3px; }

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

#setSelect {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 10px;
  border-radius: var(--radius);
  font-size: 13px;
  min-width: 260px;
  cursor: pointer;
}
#setSelect:focus { outline: 1px solid var(--gold); }

.packs-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}
#numPacks {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 8px;
  border-radius: var(--radius);
  width: 52px;
  text-align: center;
  font-size: 13px;
}

#openPacks {
  background: var(--gold);
  color: #000;
  border: none;
  padding: 8px 18px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: opacity .15s;
  white-space: nowrap;
}
#openPacks:hover:not(:disabled) { opacity: .85; }
#openPacks:disabled { opacity: .4; cursor: not-allowed; }

.stats-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
}
.stat-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg3);
  border: 1px solid var(--border);
  padding: 3px 9px;
  border-radius: 20px;
}
.stat-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ── View nav ────────────────────────────────────────────────────────────── */
.view-nav {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 8px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 5px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: all .15s;
}
.tab:hover { color: var(--text); border-color: var(--border); }
.tab.active { background: var(--bg3); color: var(--text); border-color: var(--border); }

.tab-extras { display: flex; align-items: center; gap: 12px; margin-left: auto; }

.group-by { display: flex; align-items: center; gap: 6px; }
.group-label { color: var(--muted); font-size: 12px; }
.grp {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 4px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  transition: all .15s;
}
.grp:hover { color: var(--text); }
.grp.active { color: var(--gold); border-color: var(--gold-dim); }

.filter-input {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 10px;
  border-radius: var(--radius);
  font-size: 13px;
  width: 200px;
}
.filter-input:focus { outline: 1px solid var(--gold); }

/* ── Main content ────────────────────────────────────────────────────────── */
main { flex: 1; overflow: auto; padding: 20px; }

/* ── Splash ─────────────────────────────────────────────────────────────── */
.splash {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 300px;
  text-align: center;
  gap: 16px;
  color: var(--muted);
}
.splash h2 { color: var(--text); font-size: 20px; }
.splash-pips { display: flex; gap: 10px; font-size: 28px; }
.pip {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 16px;
}
.pip-W { background: var(--W); color: var(--W-text); }
.pip-U { background: var(--U); color: var(--U-text); }
.pip-B { background: var(--B); color: var(--B-text); }
.pip-R { background: var(--R); color: var(--R-text); }
.pip-G { background: var(--G); color: var(--G-text); }

/* ── Loading / error ────────────────────────────────────────────────────── */
.loading, .error-msg {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  font-size: 16px;
}
.error-msg { color: #e05252; }

/* ── Mana pips (inline) ──────────────────────────────────────────────────── */
.mana-pips { display: flex; gap: 3px; align-items: center; flex-wrap: wrap; }
.mp {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px;
  border-radius: 50%;
  font-size: 10px; font-weight: 700;
  border: 1px solid rgba(255,255,255,.15);
  flex-shrink: 0;
}
.mp-W { background: var(--W); color: var(--W-text); }
.mp-U { background: var(--U); color: var(--U-text); }
.mp-B { background: var(--B); color: var(--B-text); }
.mp-R { background: var(--R); color: var(--R-text); }
.mp-G { background: var(--G); color: var(--G-text); }
.mp-C, .mp-X, .mp-Y, .mp-Z, .mp-num { background: #666; color: #fff; }
.mp-phyrexian { background: #888; color: #fff; }

/* ── Rarity badge ────────────────────────────────────────────────────────── */
.rarity {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
}
.rarity-common   { color: var(--common);   background: rgba(160,160,160,.12); }
.rarity-uncommon { color: var(--uncommon); background: rgba(159,204,229,.12); }
.rarity-rare     { color: var(--rare);     background: rgba(201,168,76,.12);  }
.rarity-mythic   { color: var(--mythic);   background: rgba(232,111,58,.12);  }

/* ── Foil indicator ─────────────────────────────────────────────────────── */
.foil-badge {
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 3px;
  background: linear-gradient(135deg, #a0f0ff, #ff90e0, #ffe0a0);
  color: #000;
  font-weight: 700;
}

/* ── TABLE VIEW ──────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead { position: sticky; top: 0; z-index: 5; }
th {
  background: var(--bg2);
  border-bottom: 2px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th:hover { color: var(--text); }
th.sorted { color: var(--gold); }
th .sort-arrow { margin-left: 4px; opacity: .6; }
td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:hover td { background: var(--bg3); cursor: pointer; }
.td-name { font-weight: 600; min-width: 160px; }
.td-cost { min-width: 80px; }
.td-cmc  { width: 50px; text-align: center; color: var(--muted); }
.td-type { color: var(--muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.td-pt   { width: 60px; text-align: center; font-variant-numeric: tabular-nums; }
.td-rar  { width: 80px; }
.td-eur  { width: 70px; text-align: right; font-variant-numeric: tabular-nums; }
.td-foil { width: 50px; text-align: center; }

/* ── GALLERY VIEW ────────────────────────────────────────────────────────── */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-w), 1fr));
  gap: 14px;
}
.card-thumb {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: transform .15s, border-color .15s, box-shadow .15s;
  position: relative;
}
.card-thumb:hover {
  transform: translateY(-4px) scale(1.02);
  border-color: var(--gold-dim);
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  z-index: 2;
}
.card-thumb img {
  width: 100%;
  aspect-ratio: 63/88;
  object-fit: cover;
  display: block;
}
.card-thumb .no-image {
  width: 100%;
  aspect-ratio: 63/88;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg3);
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  padding: 12px;
  gap: 6px;
}
.card-thumb .no-image .no-img-name { font-weight: 700; color: var(--text); font-size: 12px; }
.card-thumb-footer {
  padding: 6px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  font-size: 11px;
  background: var(--bg2);
}
.card-thumb-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.foil-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(160,240,255,.08), rgba(255,144,224,.08), rgba(255,224,160,.08));
  pointer-events: none;
}

/* ── STACKS VIEW ─────────────────────────────────────────────────────────── */
.stacks {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  overflow-x: auto;
  padding-bottom: 12px;
  min-height: 400px;
}
.stack-col {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-shrink: 0;
  width: 220px;
  overflow: hidden;
}
.stack-header {
  padding: 10px 12px;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}
.stack-count {
  margin-left: auto;
  background: var(--bg3);
  color: var(--muted);
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 400;
}
.stack-color-bar {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.stack-cards { padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.stack-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: background .1s;
  min-width: 0;
}
.stack-card:hover { background: var(--bg3); }
.stack-card-art {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg3);
}
.stack-card-art-placeholder {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  background: var(--bg3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.stack-card-info { flex: 1; min-width: 0; }
.stack-card-name {
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stack-card-sub { font-size: 11px; color: var(--muted); display: flex; gap: 6px; align-items: center; }

/* ── Color group helpers ──────────────────────────────────────────────────── */
.col-W { border-top: 3px solid var(--W); }
.col-U { border-top: 3px solid var(--U); }
.col-B { border-top: 3px solid #666; }
.col-R { border-top: 3px solid var(--R); }
.col-G { border-top: 3px solid var(--G); }
.col-multi { border-top: 3px solid #d4af37; }
.col-colorless { border-top: 3px solid #999; }
.col-land { border-top: 3px solid #8b6914; }
.col-common   { border-top: 3px solid var(--common); }
.col-uncommon { border-top: 3px solid var(--uncommon); }
.col-rare     { border-top: 3px solid var(--rare); }
.col-mythic   { border-top: 3px solid var(--mythic); }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
}
.modal.open {
  pointer-events: auto;
  opacity: 1;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(4px);
}
.modal-dialog {
  position: relative;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 900px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 60px rgba(0,0,0,.7);
  transform: scale(.96);
  transition: transform .2s;
}
.modal.open .modal-dialog { transform: scale(1); }

.modal-close {
  position: absolute;
  top: 12px; right: 14px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--muted);
  width: 30px; height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  z-index: 1;
  transition: color .15s;
}
.modal-close:hover { color: var(--text); }

.modal-body {
  display: flex;
  gap: 24px;
  padding: 24px;
  flex-wrap: wrap;
}
.modal-img-wrap {
  flex-shrink: 0;
  width: 320px;
}
.modal-img-wrap img {
  width: 100%;
  border-radius: 10px;
  display: block;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.modal-img-wrap .modal-no-img {
  width: 100%;
  aspect-ratio: 63/88;
  background: var(--bg3);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
  gap: 8px;
}
.modal-details { flex: 1; min-width: 240px; display: flex; flex-direction: column; gap: 14px; }
.modal-name { font-size: 22px; font-weight: 800; line-height: 1.2; }
.modal-type { color: var(--muted); font-size: 13px; }
.modal-cost { display: flex; align-items: center; gap: 8px; }
.modal-section { font-size: 13px; line-height: 1.6; }
.modal-section .label { font-size: 10px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 4px; }
.modal-oracle { font-size: 13px; line-height: 1.7; }
.modal-flavor { font-size: 12px; color: var(--muted); font-style: italic; line-height: 1.6; border-left: 2px solid var(--border); padding-left: 10px; }
.modal-pt { font-size: 20px; font-weight: 800; }
.modal-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); }

/* ── Utilities ────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
