/* MTG RapTrack — the one stylesheet for the whole app.
   Mobile-first: the base styles target a ~390px phone screen, and the
   media query at the bottom gently widens things on bigger screens.
   Buttons and other tap targets are at least 44px tall (SPEC.md). */

:root {
  /* One central place for every color used in the app. */
  --bg: #f5f2ec;          /* page background */
  --card-bg: #ffffff;     /* row/card background */
  --text: #26221c;        /* main text */
  --muted: #7a6f60;       /* secondary text */
  --accent: #6b46c1;      /* purple — buttons, top bar */
  --line: #e2dccf;        /* borders */
  --good: #3f9d63;        /* green — owned/progress */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  /* The system font stack: uses each device's native font, loads nothing. */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* --- top bar ------------------------------------------------------------ */
.topbar {
  position: sticky;  /* stays visible while scrolling long checklists */
  top: 0;
  z-index: 10;
  background: var(--accent);
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;  /* app name left, user + logout right */
  align-items: center;
}
.topbar-user { color: #e6ddf7; font-size: 0.9rem; }
.topbar-user a { color: #fff; }

/* --- login page (Phase 3) --------------------------------------------------- */
.login-form { display: grid; gap: 0.9rem; max-width: 340px; margin: 1rem 0; }
.login-form label { display: grid; gap: 0.3rem; font-weight: 600; }
.login-form input {
  min-height: 44px;
  font-size: 1rem;
  padding: 0 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card-bg);
}
.error { color: #b3261e; font-weight: 600; }
.app-name {
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.05rem;
}

main {
  padding: 1rem;
  max-width: 700px;   /* keeps lines readable on desktop */
  margin: 0 auto;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
h1 { font-size: 1.35rem; margin: 0.25rem 0 0.75rem; }

/* --- buttons (44px minimum = comfortable thumb target) ------------------ */
.btn, .step, .filter-btn, .result {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card-bg);
  color: var(--text);
  font-size: 1rem;
  padding: 0 0.9rem;
  cursor: pointer;
}
.btn.primary {
  display: inline-flex;
  align-items: center;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
}
/* links styled as buttons (e.g. "All owned" on the home page) */
a.btn { display: inline-flex; align-items: center; text-decoration: none; }
.head-actions { display: flex; gap: 0.4rem; }

/* --- shared list layout -------------------------------------------------- */
.set-list, .card-list, .result-list {
  list-style: none;
  margin: 1rem 0;
  padding: 0;
  display: grid;
  gap: 0.6rem;
}

/* --- home page: set rows -------------------------------------------------- */
.set-card {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem;
  text-decoration: none;
  color: inherit;
}
.set-icon { width: 30px; height: 30px; }
/* small set symbol shown inline next to text (headings, search results) */
.icon-inline {
  width: 18px;
  height: 18px;
  vertical-align: -3px;
  margin-right: 6px;
}
.set-info { flex: 1; display: grid; gap: 0.3rem; }
.set-name { font-weight: 600; }
.set-count { color: var(--muted); font-size: 0.9rem; }

/* the green completion bar */
.bar {
  height: 8px;
  background: var(--line);
  border-radius: 4px;
  overflow: hidden;
}
.bar-fill { height: 100%; background: var(--good); }

.empty, .status { color: var(--muted); }

/* --- search boxes (add-set page, set page, collection page) --------------- */
.search-box {
  width: 100%;
  min-height: 44px;
  font-size: 1rem;
  padding: 0 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card-bg);
  margin: 0.25rem 0 0.5rem;
}

/* rows that don't match the current search text get hidden */
.card-row[data-match="0"] { display: none; }
.result {
  width: 100%;
  text-align: left;
  padding: 0.6rem 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
/* the "›" on name suggestions, hinting that they're tappable;
   margin-left:auto pushes it to the right edge of the button */
.chevron { color: var(--muted); font-size: 1.2rem; margin-left: auto; }

/* --- set page: controls row ----------------------------------------------- */
.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 0.25rem 0 0.5rem;
}
.filters { display: flex; gap: 0.4rem; }
.filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.variant-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 44px;
  color: var(--muted);
  cursor: pointer;
}
.variant-toggle input { width: 22px; height: 22px; }

/* --- set page: card rows --------------------------------------------------- */
.card-row {
  display: flex;
  gap: 0.7rem;
  align-items: center;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.5rem 0.7rem;
}
/* owned cards get a green outline so they're easy to spot while scrolling */
.card-row[data-owned="1"] { border-color: var(--good); }

.thumb {
  width: 42px;
  height: 58px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--line);  /* grey placeholder while the image loads */
  flex-shrink: 0;
  cursor: pointer;          /* thumbnails are tappable (opens the big image) */
}

/* --- all-owned collection page --------------------------------------------- */
.owned-section h2 { font-size: 1.05rem; margin: 1.2rem 0 0.4rem; }
.owned-qty { display: grid; gap: 0.25rem; justify-items: end; }
.qty-badge {
  background: var(--line);
  border-radius: 6px;
  padding: 0.2rem 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}
.qty-badge.foil { background: #ecd9a3; }  /* gold-ish to mark foils */

/* --- find-a-card page ------------------------------------------------------ */
.printings-title { font-size: 1.05rem; margin: 1rem 0 0.25rem; }
.price-line { color: var(--text); font-weight: 600; }
.owned-line { color: var(--good); }
/* .step.add-btn (two classes) so this outranks the square .step sizing,
   which is meant for the +/- symbols on the set-page steppers */
.step.add-btn {
  width: auto;
  font-size: 0.95rem;
  padding: 0 0.7rem;
  white-space: nowrap;
}

/* --- tap-to-enlarge card image overlay ----------------------------------- */
#lightbox {
  position: fixed;          /* covers the whole screen, above everything */
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
#lightbox[hidden] { display: none; }
#lightbox img {
  max-width: 92vw;          /* never wider/taller than the screen */
  max-height: 85vh;
  border-radius: 14px;
}
.card-info { flex: 1; min-width: 0; display: grid; gap: 0.15rem; }
.card-name { font-weight: 600; overflow-wrap: anywhere; }
.card-meta { color: var(--muted); font-size: 0.85rem; }

.steppers { display: grid; gap: 0.35rem; }
.stepper { display: flex; align-items: center; gap: 0.35rem; }
.step { width: 44px; padding: 0; font-size: 1.3rem; line-height: 1; }
.qty { min-width: 1.6rem; text-align: center; font-weight: 600; }
.finish-label { color: var(--muted); font-size: 0.8rem; width: 2rem; }

/* --- Owned / Missing filters ------------------------------------------------
   The buttons set data-filter on the list; these rules hide non-matching
   rows. Pure CSS, so filtering is instant even on 500-card sets. */
.card-list[data-filter="owned"] .card-row[data-owned="0"] { display: none; }
.card-list[data-filter="missing"] .card-row[data-owned="1"] { display: none; }

/* --- money summaries (Phase 2) ---------------------------------------------- */
.totals { margin: 0.25rem 0 0.75rem; color: var(--muted); }
.totals strong { color: var(--text); }
.totals a { color: var(--accent); }

/* "most valuable owned" / "most expensive missing" mini-lists */
.mini-lists { display: grid; gap: 0.9rem; margin: 0 0 0.75rem; }
.mini-lists h3 { font-size: 0.95rem; margin: 0 0 0.3rem; }
.mini-lists ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.25rem; }
.mini-lists li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
}

/* --- missing report (the printable buylist) ---------------------------------- */
.buylist { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.buylist th, .buylist td {
  text-align: left;
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid var(--line);
}
.buylist .num { text-align: right; }

/* --- footer ------------------------------------------------------------------ */
.footer {
  max-width: 700px;
  margin: 2rem auto 0;
  padding: 1rem;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.9rem;
}

/* --- printing (the missing report is designed to be printed) ------------------ */
@media print {
  .topbar, .footer, .no-print { display: none; }
  body { background: #fff; }
}

/* --- slightly wider screens -------------------------------------------------- */
@media (min-width: 600px) {
  h1 { font-size: 1.7rem; }
  .mini-lists { grid-template-columns: 1fr 1fr; }
}
