/* ---------- tokens ---------- */
:root {
  --bg: #0f1420;
  --bg-soft: #161d2e;
  --line: #26304a;
  --text: #e8ecf6;
  --muted: #93a0bd;
  --accent: #ffcb05;   /* Pokémon yellow */
  --accent-ink: #1d2536;
  --blue: #2a75bb;
  --radius: 12px;

  /* type palette — used on screen and on the printed cards */
  --t-normal:#a8a77a; --t-fire:#ee8130; --t-water:#6390f0; --t-electric:#e8be16;
  --t-grass:#63bc3c;  --t-ice:#74c9c6;  --t-fighting:#c22e28; --t-poison:#a33ea1;
  --t-ground:#d3ab4e;  --t-flying:#8f77e8; --t-psychic:#f95587; --t-bug:#93a41a;
  --t-rock:#a8932f;   --t-ghost:#735797; --t-dragon:#6f35fc; --t-dark:#6b5344;
  --t-steel:#9a9ab8;  --t-fairy:#d685ad;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ---------- top bar ---------- */
.stickybar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(15, 20, 32, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.topbar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 14px 20px;
}
.topbar__brand { display: flex; align-items: center; gap: 10px; }
.topbar__brand h1 { font-size: 18px; margin: 0; letter-spacing: -.2px; }
.dot {
  width: 18px; height: 18px; border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, #fff 0 14%, #e3350d 15% 100%);
  box-shadow: inset 0 0 0 2px #1d2536, 0 0 0 2px #e3350d;
}
.topbar__actions { margin-left: auto; display: flex; gap: 8px; }

.progress { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.progress__bar {
  flex: 1; height: 8px; border-radius: 99px;
  background: var(--bg-soft); border: 1px solid var(--line); overflow: hidden;
}
.progress__fill {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--blue), var(--accent));
  transition: width .25s ease;
}
.progress__label { font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- controls ---------- */
.btn {
  font: inherit; font-weight: 600; font-size: 14px;
  padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--bg-soft); color: var(--text); cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: #1e273c; border-color: #39456a; }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent); color: var(--accent-ink); border-color: #d9ab00; }
.btn--primary:hover { background: #ffd731; border-color: #d9ab00; }

.field {
  font: inherit; font-size: 14px;
  padding: 8px 10px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--bg-soft); color: var(--text);
}
.field:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.field--search { flex: 1; min-width: 200px; }
.field--area { width: 100%; min-height: 120px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; resize: vertical; }

.filters {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  padding: 0 20px 12px;
}
.filters__count { font-size: 13px; color: var(--muted); margin-left: auto; font-variant-numeric: tabular-nums; }
.hint { margin: 0; padding: 4px 20px 14px; font-size: 13px; color: var(--muted); }
.hint strong { color: var(--text); }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }

/* ---------- grid ---------- */
.grid {
  --cw: 168px;
  display: grid;
  grid-template-columns: repeat(auto-fill, var(--cw));
  justify-content: center;
  gap: 14px;
  padding: 0 20px 60px;
}
.grid .card { width: var(--cw); }

/* ---------- the card ---------- */
/* Everything inside sizes in `em`, and font-size derives from the card width,
   so the exact same markup renders as a 168px tile on screen and a 2.5in card in print. */
.card[hidden] { display: none !important; }

.card {
  --c1: var(--t-normal);
  --c2: var(--c1);
  position: relative;
  aspect-ratio: 2.5 / 3.5;
  font-size: calc(var(--cw, 168px) / 18);
  border-radius: .75em;
  padding: .5em;
  background: linear-gradient(150deg, var(--c1), var(--c2));
  color: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,.35);
  cursor: pointer;
  user-select: none;
  display: flex;
  transition: transform .12s ease, box-shadow .12s ease;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.grid .card:hover { transform: translateY(-3px); box-shadow: 0 8px 22px rgba(0,0,0,.45); }

.card__frame {
  flex: 1;
  display: flex; flex-direction: column;
  border-radius: .45em;
  background: linear-gradient(#fffdf6, #f2f0e6);
  color: #1d2536;
  padding: .45em .5em .4em;
  overflow: hidden;
}

.card__top {
  display: flex; justify-content: space-between; align-items: center;
  font-size: .78em; font-weight: 700; letter-spacing: .04em;
}
.card__num { color: #7c8598; font-variant-numeric: tabular-nums; }
.card__gen {
  background: linear-gradient(150deg, var(--c1), var(--c2));
  color: #fff; border-radius: 99px; padding: .1em .6em;
  text-shadow: 0 1px 1px rgba(0,0,0,.35);
}

.card__art {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  margin: .2em 0;
  border-radius: .4em;
  background: #f5f5f0; /* fallback if color-mix is unsupported */
  background: color-mix(in srgb, var(--c1) 9%, #fff);
}
body.art-pixel .card__art img,
.sheets--pixel .card__art img { image-rendering: pixelated; }

.card__art img {
  width: var(--art-w, 92%); height: auto; max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 .12em .1em rgba(0,0,0,.22));
}

.card__name {
  margin: .1em 0 .15em;
  font-size: 1.28em; line-height: 1.15; font-weight: 800;
  letter-spacing: -.01em; text-align: center;
  overflow-wrap: anywhere;
}
.card--longname .card__name { font-size: 1.02em; }

.card__types { display: flex; gap: .25em; justify-content: center; margin-bottom: .35em; }
.pill {
  font-size: .68em; font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
  color: #fff; padding: .18em .6em; border-radius: 99px;
  text-shadow: 0 1px 1px rgba(0,0,0,.35);
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}

.card__region {
  text-align: center;
  font-size: .68em; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: #fff; border-radius: .3em; padding: .25em .55em;
  background: linear-gradient(90deg, var(--c1), var(--c2));
  text-shadow: 0 1px 1px rgba(0,0,0,.35);
}

/* owned state (screen only) */
.card--owned { opacity: .45; filter: saturate(.4); }
.card--owned::after {
  content: "✓ OWNED";
  position: absolute; inset: auto 0 42% 0;
  text-align: center;
  font-size: .8em; font-weight: 900; letter-spacing: .1em;
  color: #fff; background: rgba(20,150,80,.92);
  padding: .3em 0;
  transform: rotate(-8deg);
}

/* ---------- modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6,9,16,.7); padding: 20px;
}
.modal[hidden] { display: none; }
.modal__panel {
  width: min(520px, 100%);
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px;
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
}
.modal__panel h2 { margin: 0 0 16px; font-size: 18px; }
.modal__actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 12px; font-size: 14px; }
.row .field { flex: 1; max-width: 340px; }
.rowinput { display: flex; align-items: center; gap: 10px; flex: 1; max-width: 400px; }
.rowinput input { flex: 1; accent-color: var(--accent); }
.rowinput output { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 132px; text-align: right; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 10px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.note { font-size: 12.5px; color: var(--muted); line-height: 1.5; margin: 14px 0 0; }
.note strong { color: var(--text); }
.note--count { color: var(--accent); font-weight: 600; }

/* ---------- print sheets ---------- */
/* Parked off-screen rather than display:none — images inside a hidden subtree
   never load, which printed blank sprites. */
.sheets {
  position: absolute;
  top: 0;
  left: -20000px;
  width: 8.5in;
}

.sheet {
  --cw: 2.5in;
  display: grid;
  grid-template-columns: repeat(3, var(--cw));
  grid-template-rows: repeat(3, calc(var(--cw) * 1.4));
  justify-content: center;
  padding: .1in 0; /* minimal top clearance; every extra inch risks a page spill */
  background: #fff;
  page-break-after: always; /* legacy alias — Safari honours this one */
  break-after: page;
}
.sheet:last-child { page-break-after: auto; break-after: auto; }
.sheet--4 {
  --cw: 3.75in;
  grid-template-columns: repeat(2, var(--cw));
  grid-template-rows: repeat(2, calc(var(--cw) * 1.4));
}

.sheet .card {
  width: var(--cw);
  box-shadow: none;
  border-radius: 0;
  cursor: default;
}
.sheet .card__frame { border-radius: .3em; }

/* cut guides */
.sheets--guides .card { outline: .5pt dashed rgba(0,0,0,.45); outline-offset: 0; }

/* artwork size — the sprite is most of the ink on a card */
.sheets--art-md { --art-w: 62%; }
.sheets--art-sm { --art-w: 42%; }

/* ink saver */
.sheets--ink .card { background: #fff; padding: .12em; }
.sheets--ink .card__frame {
  background: #fff;
  border: .1em solid var(--c1);
}
.sheets--ink .card__art { background: none; }

@media print {
  @page { size: letter portrait; margin: 0; }
  html, body { background: #fff; }
  .stickybar, .hint, .grid, .empty, .modal { display: none !important; }
  .sheets { position: static; left: auto; width: auto; }
  .sheets .card, .sheets .pill, .sheets .card__gen, .sheets .card__region {
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
}
