/* Pokémon Master-Set Tracker — phone first, desktop still welcome.
   Grown from the Mac app's stylesheet; the differences are all about thumbs:
   bigger tap targets, two-column card grid, modals as bottom sheets. */

:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #1b1f2a;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #e3350d;      /* Pokémon red */
  --brand-2: #ffcb05;    /* Pokémon yellow */
  --accent: #2a75bb;     /* Pokémon blue */
  --good: #16a34a;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.06);
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420; --panel: #171d2b; --ink: #e8eaf0; --muted: #97a0b5;
    --line: #263043; --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* Must beat the `display:flex` rules below, or hidden elements still show. */
[hidden] { display: none !important; }
html, body { margin: 0; overscroll-behavior-y: contain; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; }

/* ---------------------------------------------------------------- topbar -- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; cursor: pointer; }
.pokeball {
  width: 20px; height: 20px; border-radius: 50%;
  background: linear-gradient(var(--brand) 0 50%, #fff 50% 100%);
  border: 2px solid #222; position: relative; flex: none;
}
.pokeball::after { content: ""; position: absolute; inset: 45% 0 0 0; height: 2px; background: #222; }
.topbar-controls { display: flex; align-items: center; gap: 6px; }

/* --------------------------------------------------------------- buttons -- */
.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 10px 14px; border-radius: 10px; cursor: pointer; font-size: 14px;
  font-weight: 600; font-family: inherit; min-height: 42px;
}
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 12px; min-height: 34px; }
.btn.icon { padding: 8px 10px; font-size: 17px; min-width: 42px; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: default; }
@media (hover: hover) { .btn:hover { border-color: var(--accent); } }

/* ---------------------------------------------------------------- layout -- */
main { padding: 16px; max-width: 1200px; margin: 0 auto; padding-bottom: calc(28px + var(--safe-b)); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; margin: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.banner { padding: 9px 16px; background: var(--brand-2); color: #333; font-size: 13px; font-weight: 600; text-align: center; }
.banner.bad { background: var(--brand); color: #fff; }

/* ----------------------------------------------------------- sign-in page -- */
.auth-wrap { min-height: 100svh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 26px 22px; box-shadow: var(--shadow); width: 100%; max-width: 380px; }
.auth-card .pokeball { display: block; width: 34px; height: 34px; border-width: 3px; margin-bottom: 12px; }
.auth-card h1 { font-size: 21px; margin: 0 0 4px; }
.auth-card p.sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.auth-card input { width: 100%; }
.auth-msg { font-size: 13px; margin: 12px 0 0; padding: 10px 12px; border-radius: 9px; }
.auth-msg.err { background: #fee2e2; color: #991b1b; }
.auth-msg.ok  { background: #dcfce7; color: #14532d; }
@media (prefers-color-scheme: dark) {
  .auth-msg.err { background: #45191c; color: #fecaca; }
  .auth-msg.ok  { background: #14331f; color: #bbf7d0; }
}
.auth-switch { margin-top: 16px; text-align: center; font-size: 14px; }
.linkish { color: var(--accent); cursor: pointer; font-weight: 600; text-decoration: underline; background: none; border: none; font-size: inherit; font-family: inherit; }

/* -------------------------------------------------------------- dashboard -- */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.collection-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px; box-shadow: var(--shadow); cursor: pointer;
}
.collection-card h3 { margin: 0 0 4px; font-size: 17px; }
.kind-chip { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.preview-wall { display: flex; gap: 4px; margin: 10px 0; }
.preview-wall img { width: 40px; height: 56px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); background: var(--bg); }
.new-card {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 2px dashed var(--line); color: var(--muted); font-weight: 700; min-height: 120px; text-align: center;
}

/* --------------------------------------------------------------- progress -- */
.progress { height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; margin: 8px 0; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--good), #4ade80); }
.progress.variant > span { background: linear-gradient(90deg, var(--accent), #60a5fa); }
.stat-line { display: flex; justify-content: space-between; font-size: 13px; gap: 8px; }
.value-line { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ------------------------------------------------------------- card grid -- */
/* minmax(0, …) not just 1fr: a grid track's default minimum is min-content, so
   a long card name (which is nowrap) would push the column wider than its share
   and shove the right-hand column off the screen edge. */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
@media (max-width: 430px) { .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } }
.tcard { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px; box-shadow: var(--shadow); min-width: 0; }
.tcard .imgwrap { position: relative; border-radius: 8px; overflow: hidden; aspect-ratio: 245/342; background: var(--bg); cursor: pointer; }
.tcard img.card-img { width: 100%; height: 100%; object-fit: cover; display: block; transition: filter .2s ease; }
.tcard.unowned img.card-img { filter: grayscale(1) contrast(.9) brightness(.96); opacity: .82; }
.tcard.complete .imgwrap { outline: 3px solid var(--good); outline-offset: -3px; }
.tcard .cardnum { font-size: 11px; color: var(--muted); margin-top: 4px; display: flex; justify-content: space-between; gap: 6px; }
.tcard .cardname { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 6px; }
.tcard .cardset { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wish-star { position: absolute; top: 2px; right: 2px; cursor: pointer; font-size: 21px; line-height: 1;
  padding: 6px; filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }
.wish-star.on { color: var(--brand-2); }
.wish-star.off { color: rgba(255,255,255,.92); }

/* ------------------------------------------------------------------ chips -- */
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.chip {
  font-size: 12px; padding: 6px 10px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg); color: var(--muted);
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.chip.owned { background: var(--good); border-color: var(--good); color: #fff; }
.chip.uncounted { opacity: .45; text-decoration: line-through; }
.chip.big { font-size: 14px; padding: 9px 14px; }
.chip.busy { opacity: .55; }

/* ---------------------------------------------------------------- detail -- */
.detail { display: grid; grid-template-columns: 230px 1fr; gap: 20px; align-items: start; }
@media (max-width: 680px) { .detail { grid-template-columns: 1fr; } .detail-img { max-width: 220px; margin: 0 auto; display: block; } }
.detail-img { width: 100%; border-radius: 10px; box-shadow: var(--shadow); background: var(--bg); }
.detail-body h2 { margin: 0 0 6px; font-size: 20px; }
.detail-meta { font-size: 13px; line-height: 1.6; margin: 0 0 14px; }

/* --------------------------------------------------------- forms & filters -- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px;
  background: var(--panel); padding: 11px; border-radius: 12px; border: 1px solid var(--line); }
.toolbar > * { flex: 1 1 140px; }
/* Stacked variant (the "new master set" form). Without this the 140px
   flex-basis becomes a 140px minimum *height* on every child, leaving big
   gaps between the fields. */
.toolbar.stack { flex-direction: column; align-items: stretch; }
.toolbar.stack > * { flex: 0 0 auto; }
input[type=text], input[type=search], input[type=email], input[type=password], select {
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); color: var(--ink); font-size: 16px; /* 16px stops iOS zooming on focus */
  font-family: inherit; width: 100%; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 13px; }
.field label { font-size: 13px; font-weight: 600; }
.checks { display: flex; flex-wrap: wrap; gap: 6px; }
.checks label { display: flex; align-items: center; gap: 7px; font-size: 14px;
  border: 1px solid var(--line); border-radius: 999px; padding: 8px 13px; background: var(--bg); cursor: pointer; }
.checks input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; border: none; background: var(--panel); padding: 11px 8px; cursor: pointer;
  color: var(--ink); font-weight: 600; font-size: 14px; font-family: inherit; }
.seg button.active { background: var(--accent); color: #fff; }
.suggestions { border: 1px solid var(--line); border-radius: 10px; max-height: 260px; overflow: auto;
  background: var(--panel); margin-top: -6px; margin-bottom: 12px; }
.suggestions div { padding: 12px; cursor: pointer; display: flex; justify-content: space-between;
  gap: 10px; border-bottom: 1px solid var(--line); }
.suggestions div:last-child { border-bottom: none; }
.count-badge { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ----------------------------------------------------------------- modal -- */
.modal-host { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex;
  align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: var(--radius); padding: 20px; max-width: 560px;
  width: 100%; box-shadow: var(--shadow); max-height: 88vh; overflow: auto;
  -webkit-overflow-scrolling: touch; }
.modal.wide { max-width: 760px; }
.modal h2 { margin-top: 0; font-size: 19px; }
/* On a phone a centred box is fiddly — slide it up from the bottom instead. */
@media (max-width: 600px) {
  .modal-host { align-items: flex-end; padding: 0; }
  .modal, .modal.wide { max-width: 100%; border-radius: 18px 18px 0 0;
    max-height: 92svh; padding: 20px 16px calc(24px + var(--safe-b)); }
}

/* ------------------------------------------------------------- odds & ends -- */
.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.spinner { width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; display: inline-block; animation: spin 1s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.hint { font-size: 12px; color: var(--muted); }
.offline-note { background: var(--brand-2); color: #333; }
