:root {
  --bg: #14161f;
  --bg2: #1c1f2b;
  --bg3: #252938;
  --line: #323749;
  --text: #e8eaf2;
  --muted: #9aa0b4;
  --accent: #e5484d;
  --gold: #f5c518;
  --green: #46c46e;
  --red: #ff6b6b;
  --blue: #6ea8fe;
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--bg3); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
.hidden { display: none !important; }

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg2); border-bottom: 1px solid var(--line);
  padding: 8px 10px calc(8px); display: flex; flex-direction: column; gap: 8px;
}
.topbar-row { display: flex; align-items: center; gap: 8px; }
.logo { font-size: 19px; font-weight: 800; letter-spacing: -0.5px; }
.logo span { color: var(--accent); }
.tabs { margin-left: auto; display: flex; gap: 4px; }
.tab { padding: 6px 14px; border-radius: 999px; color: var(--muted); font-weight: 600; }
.tab.active { background: var(--bg3); color: var(--text); }

.pager { display: flex; align-items: center; gap: 2px; }
.page-label { font-weight: 700; padding: 6px 8px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.page-label small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; line-height: 1; }
#jumpInput { flex: 1; min-width: 60px; }

.btn {
  background: var(--bg3); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 14px; font-weight: 600;
}
.btn:active { transform: translateY(1px); }
.btn.icon { padding: 8px 10px; line-height: 1; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.subtle { color: var(--muted); }
.btn.danger { color: var(--red); border-color: #5c3038; }
.btn:disabled { opacity: 0.45; cursor: default; }

.seg { display: flex; background: var(--bg3); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { padding: 7px 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.seg button.active { background: var(--accent); color: #fff; }
.seg.wide { margin: 10px 12px 0; }
.seg.wide button { flex: 1; }

/* ---- binder grid ---- */
main { max-width: 760px; margin: 0 auto; padding: 10px; }
#gridView { touch-action: pan-y; } /* horizontal drags are page turns, not scroll */
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.pocket {
  position: relative; aspect-ratio: 5 / 7; border-radius: 8px; overflow: hidden;
  background: var(--bg2); border: 1px solid var(--line); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.pocket img.card { width: 100%; height: 100%; object-fit: cover; display: block; }
.pocket.unowned img.card { filter: grayscale(0.85) brightness(0.55); }
.pocket .flag {
  position: absolute; font-size: 10px; font-weight: 700; padding: 2px 5px; border-radius: 5px;
}
.flag.owned { right: 3px; bottom: 3px; background: rgba(20, 22, 31, 0.75); color: var(--green); }
.flag.wanted { left: 3px; top: 3px; color: var(--gold); font-size: 13px; text-shadow: 0 1px 2px #000; }
.flag.mirror { right: 3px; top: 3px; background: rgba(20, 22, 31, 0.75); color: var(--blue); }
.flag.qty { left: 3px; bottom: 3px; background: rgba(20, 22, 31, 0.75); color: var(--text); }
/* stacks above the quantity when a card has both */
.flag.lang { left: 3px; bottom: 20px; background: rgba(20, 22, 31, 0.75); color: var(--blue); letter-spacing: 0.3px; }
.pocket.highlight { outline: 3px solid var(--gold); outline-offset: -1px; }

/* paper slip placeholder */
.slip {
  width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; text-align: center; padding: 4px;
  background:
    repeating-linear-gradient(0deg, transparent 0 21px, rgba(110, 168, 254, 0.12) 21px 22px),
    linear-gradient(160deg, #f2ead8, #e5dcc4);
  color: #57503c;
}
.slip .num { font-size: 11px; font-weight: 700; color: #8a7f60; }
.slip img { width: 55%; image-rendering: pixelated; opacity: 0.9; }
.slip .nm { font-size: 10.5px; font-weight: 700; line-height: 1.15; word-break: break-word; }

/* ---- overlays / sheet ---- */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(8, 9, 14, 0.72);
  display: flex; align-items: flex-end; justify-content: center;
}
.login-card {
  margin: auto; background: var(--bg2); border: 1px solid var(--line); border-radius: 14px;
  padding: 26px; width: min(92vw, 340px); display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.sheet {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 94dvh; overflow-y: auto;
  border-radius: 16px 16px 0 0; border: 1px solid var(--line); border-bottom: none;
  padding-bottom: 24px;
}
@media (min-width: 600px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 16px; max-height: 90dvh; }
}
.sheet-head {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: 12px; background: var(--bg2); border-bottom: 1px solid var(--line);
}
.sheet-head h2 { flex: 1; font-size: 17px; text-align: center; }
.star { color: var(--muted); font-size: 18px; }
.star.on { color: var(--gold); }

#sheetBody { padding: 12px; }
.cardpane { display: flex; flex-direction: column; gap: 12px; }
.card-hero { display: flex; gap: 12px; }
.card-hero img { width: 42%; max-width: 190px; border-radius: 9px; align-self: flex-start; }
.card-hero .meta { flex: 1; display: flex; flex-direction: column; gap: 3px; font-size: 14px; }
.card-hero .meta b { font-size: 16px; }
.muted { color: var(--muted); }
.kind-badge {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: var(--bg3); color: var(--muted); width: fit-content;
}
.kind-badge.secret { background: #3a2b45; color: #d3a6ff; }
.kind-badge.special { background: #45372b; color: #ffcf99; }
.mirror-note {
  background: #1d2740; border: 1px solid #2c3a63; color: var(--blue);
  border-radius: 8px; padding: 8px 10px; font-size: 13px;
}

.form-grid, .fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid .full, .fields .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > label { font-size: 12px; color: var(--muted); font-weight: 600; }
.check { display: flex; align-items: center; gap: 8px; padding: 8px 0; font-weight: 600; }
.check input { width: 19px; height: 19px; accent-color: var(--accent); }

.pricebox { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.pricebox .big { font-size: 21px; font-weight: 800; }
.delta.up { color: var(--green); } .delta.down { color: var(--red); }

.btnrow { display: flex; gap: 8px; flex-wrap: wrap; }
.btnrow .btn { flex: 1; text-align: center; }

/* picker */
.picker-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.printing {
  display: flex; gap: 10px; align-items: center; background: var(--bg2);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 7px; cursor: pointer;
}
.printing img { width: 44px; border-radius: 4px; background: var(--bg3); min-height: 60px; }
.printing .info { flex: 1; min-width: 0; }
.printing .info .set { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.notes-block { padding: 4px 12px 0; display: flex; flex-direction: column; gap: 4px; }
.notes-block label { font-size: 12px; color: var(--muted); font-weight: 600; }
.notes-block textarea { width: 100%; resize: vertical; }

/* ---- pack entry ---- */
.pack-form {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 14px;
}
.pack-row { display: flex; gap: 8px; }
.pack-row input { flex: 1; font-size: 18px; }
.small { font-size: 12.5px; }
.pack-entry {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 9px 12px; margin-bottom: 6px; font-size: 14px;
}
.pack-entry.err { border-color: #5c3038; }
.pack-entry .btn { padding: 5px 10px; font-size: 13px; }
.pack-entry img { width: 34px; border-radius: 3px; }
.pack-entry i.v { font-style: normal; color: var(--blue); }
/* the card's other printings, one tap to re-label the slot */
.pack-variants { display: flex; gap: 6px; flex-wrap: wrap; width: 100%; }
.pack-variants .btn { padding: 3px 9px; font-size: 12.5px; }

/* ---- missing list ---- */
.missing-controls { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.missing-controls select { flex: 1; min-width: 120px; }
.small-check { padding: 0; white-space: nowrap; font-size: 14px; }
.missing-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 12px; margin-bottom: 5px; cursor: pointer; font-size: 14.5px;
}
.missing-row img { width: 36px; height: 36px; image-rendering: pixelated; }
.missing-row .num { color: var(--muted); font-variant-numeric: tabular-nums; width: 44px; }
.missing-row .nm { font-weight: 600; flex: 1; }
.missing-row .tag { font-size: 11.5px; color: var(--muted); background: var(--bg3); border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.missing-row .tag.warn { color: #ffcf99; }
/* tap target big enough for a thumb; dim until it's a wanted card */
.missing-row .star-btn {
  color: var(--muted); opacity: 0.4; font-size: 18px; line-height: 1;
  padding: 6px 2px 6px 8px; margin: -6px 0; -webkit-tap-highlight-color: transparent;
}
.missing-row .star-btn.on { color: var(--gold); opacity: 1; }

@media (max-width: 430px) {
  .tab { padding: 6px 9px; font-size: 14px; }
  .logo { font-size: 17px; }
}

/* ---- stats ---- */
.stat-tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 560px) { .stat-tiles { grid-template-columns: repeat(3, 1fr); } }
.tile { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.tile .v { font-size: 21px; font-weight: 800; }
.tile .l { font-size: 12px; color: var(--muted); }
.tile .v.pos { color: var(--green); } .tile .v.neg { color: var(--red); }

.stats-section { margin-top: 18px; }
.stats-section h3 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 8px; }
.genbar { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 13px; }
.genbar .name { width: 92px; }
.genbar .bar { flex: 1; height: 12px; background: var(--bg3); border-radius: 999px; overflow: hidden; }
.genbar .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #ff8a5c); border-radius: 999px; }
.genbar .cnt { width: 118px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.genbar .cnt .pct { display: inline-block; width: 42px; text-align: right; color: var(--text); }
.setrow { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.setrow:last-child { border-bottom: none; }

.error { color: var(--red); font-size: 13px; min-height: 1em; }
.ok-msg { color: var(--green); font-size: 13px; }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--bg3); border: 1px solid var(--line); color: var(--text);
  border-radius: 999px; padding: 9px 18px; z-index: 90; font-weight: 600; font-size: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5); max-width: 90vw; text-align: center;
}
.spin { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- inventory ---- */
.inv-add { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; }
.inv-add select { width: 100%; margin-bottom: 8px; }
.inv-add #invQty { width: 64px; }
.inv-controls { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.inv-controls #invSearch { flex: 1 1 160px; }
.inv-totals { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.inv-group h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); margin: 14px 0 6px; }
.inv-row {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 7px 12px; margin-bottom: 5px;
}
.inv-row img, .inv-row .inv-noimg { width: 34px; height: 47px; object-fit: cover; border-radius: 3px; background: var(--bg3); flex: none; }
.inv-row .inv-main { flex: 1; min-width: 0; }
.inv-row .nm { font-weight: 600; }
.inv-row .qty { color: var(--gold); }
.inv-row .set { font-size: 12.5px; }
.inv-row .tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.inv-row .tag { font-size: 11px; color: var(--muted); background: var(--bg3); border-radius: 999px; padding: 1px 7px; }
.inv-row .tag.warn { color: #ffcf99; }
.inv-row .inv-val { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }

/* ---- destructive controls sit apart and look it ---- */
.danger-zone { border-color: #5c3038; }
.danger-zone h3 { color: var(--red); }
#snapSelect { flex: 1; min-width: 180px; }
