/* Display font (headings, names, big numbers); body text stays the system font. */
@font-face {
  font-family: 'Rubik';
  font-style: normal;
  font-weight: 300 900;
  font-display: swap;
  src: url(fonts/rubik-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --display: Rubik, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --bg: #f4f4f6;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --line: #e2e2e6;
  --accent: #e3350d;
  --accent-soft: #fde8e3;
  --caught: #2fa35a;
  --caught-soft: #e3f5e9;
  --shiny: #d9a400;
  --shiny-soft: #fff6d6;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --card: #1e1e21;
    --text: #f2f2f4;
    --muted: #9a9aa1;
    --line: #2e2e33;
    --accent-soft: #3a1a12;
    --caught-soft: #15301f;
    --shiny-soft: #352c0b;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; }
h1, h2, .hunt-head h3, .game-row .line span:first-child, .game-btn .game-name { font-family: var(--display); font-weight: 600; }
.counter .count, .plus, .tile b { font-family: var(--display); font-weight: 700; }
.muted { color: var(--muted); }

button, select, input {
  font: inherit;
  color: inherit;
}
button {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--card);
  cursor: pointer;
}
button.primary { background: var(--accent); color: #fff; font-weight: 600; }
button.ghost { background: transparent; color: var(--muted); }
button.danger { color: var(--accent); }
button.wide { width: 100%; }
select, input[type=search], input[type=email], input[type=password], input[type=number] {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  background: var(--card);
}

/* Auth */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 360px; text-align: center; }
.auth-card img { border-radius: 18px; }
.auth-card h1 { margin: 8px 0 4px; }
.auth-card form { display: grid; gap: 10px; margin-top: 16px; }
.msg { min-height: 1.4em; color: var(--accent); }
.msg.ok { color: var(--caught); }

/* Shell */
.app { min-height: 100dvh; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.topbar h1 { font-size: 22px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { width: 30px; height: 30px; flex: 0 0 auto; filter: drop-shadow(0 1px 2px rgb(0 0 0 / .2)); }
/* Settings button: a gear with the sync status as a small dot on its corner. */
.sync-btn { position: relative; display: grid; place-items: center; width: 40px; height: 40px; padding: 0; background: transparent; color: var(--muted); }
.sync-btn .ico { width: 24px; height: 24px; }
.dot { position: absolute; top: 5px; right: 4px; width: 9px; height: 9px; border-radius: 50%; background: var(--caught); box-shadow: 0 0 0 2px var(--bg); }
.dot.busy { background: var(--shiny); }
.dot.err { background: var(--accent); }

main { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: space-around;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 1px solid var(--line);
}
.tabbar button {
  flex: 1; display: grid; gap: 2px; justify-items: center;
  background: transparent; color: var(--muted); font-size: 12px; padding: 6px;
}
.tabbar button .ico { width: 23px; height: 23px; }
.tabbar button.on { color: var(--accent); }

/* Dex */
.controls { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-bottom: 8px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 2px; flex: 0 0 auto; }
.seg button { padding: 7px 12px; background: transparent; color: var(--muted); }
.seg button.on { background: var(--accent); color: #fff; }
.seg button[data-mode=shiny].on { background: var(--shiny); }
.progress-line { font-size: 13px; color: var(--muted); }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: var(--caught); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}
.cell {
  position: relative;
  display: grid; justify-items: center; gap: 0;
  padding: 6px 4px 8px;
  border-radius: var(--radius);
  background: var(--card);
  border: 2px solid transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  /* Off-screen cells aren't laid out or painted until scrolled near (the Home dex has 1,082). */
  content-visibility: auto;
  contain-intrinsic-size: auto 96px auto 124px;
}
.cell img { width: 72px; height: 72px; opacity: .35; filter: grayscale(1); }
.cell .num { font-size: 11px; color: var(--muted); max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell .name { font-size: 12px; font-weight: 600; text-align: center; line-height: 1.2; overflow-wrap: anywhere; }
.cell.caught { background: var(--caught-soft); border-color: var(--caught); }
.cell.caught img, .cell.shiny img { opacity: 1; filter: none; }
.cell.shiny { box-shadow: inset 0 0 0 2px var(--shiny); }
.cell .badge { position: absolute; top: 4px; right: 6px; font-size: 13px; }
.cell .note-dot { position: absolute; top: 4px; left: 6px; font-size: 11px; }
/* Compact grid (Settings): sprite and number only, five across on a phone. */
.grid.compact { grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: 6px; }
.grid.compact .cell { padding: 3px 2px 4px; border-radius: 10px; contain-intrinsic-size: auto 60px auto 74px; }
.grid.compact .cell img { width: 52px; height: 52px; }
.grid.compact .cell .num { font-size: 10px; }
.grid.compact .cell .badge { top: 1px; right: 3px; font-size: 11px; }
.vdots { position: absolute; top: 4px; left: 4px; display: flex; gap: 2px; }
.vdots i { width: 7px; height: 7px; border-radius: 50%; box-shadow: 0 0 0 1px var(--card); }

/* Search, Filters and the tap mode stay in view while the dex scrolls. On a
   phone the title bar scrolls away on this tab so the pinned bar is all that stays. */
.pinbar {
  position: sticky; top: var(--topbar-h, 58px); z-index: 4;
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px;
  margin: -4px -16px 6px; padding: 4px 16px 6px;
  background: var(--bg);
}
#dex-hint { margin-bottom: 8px; }
@media (max-width: 600px) {
  .app[data-tab="dex"] .topbar { position: static; }
  .app[data-tab="dex"] .pinbar { top: 0; padding-top: calc(4px + env(safe-area-inset-top)); }
}

.cell.pop { animation: pop .35s ease-out; }
@keyframes pop { 50% { transform: scale(1.08); } }
.empty { padding: 32px 0; text-align: center; color: var(--muted); }

/* Hunts */
#new-hunt { margin-bottom: 12px; }
.hunt {
  background: var(--card); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.hunt-head { display: flex; gap: 12px; align-items: center; }
.hunt-head img { width: 64px; height: 64px; }
.hunt-head .meta { flex: 1; min-width: 0; }
.hunt-head h3 { margin: 0; font-size: 17px; }
.hunt-head .sub { font-size: 13px; color: var(--muted); }
.counter { display: flex; align-items: center; gap: 10px; margin: 12px 0 8px; }
.counter .count { flex: 1; text-align: center; font-size: 40px; font-weight: 700; font-variant-numeric: tabular-nums; background: transparent; padding: 0; }
.counter .minus { width: 56px; height: 56px; font-size: 24px; background: var(--bg); }
.plus {
  width: 100%; height: 72px; font-size: 28px; font-weight: 700;
  background: var(--accent); color: #fff; border-radius: var(--radius);
  touch-action: manipulation;
}
.plus:active { transform: scale(.98); }
.modifier { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 6px; font-size: 14px; color: var(--muted); }
.modifier button { width: 36px; height: 36px; padding: 0; background: var(--bg); font-size: 18px; }
.modifier b { min-width: 2ch; text-align: center; color: var(--text); font-variant-numeric: tabular-nums; }
.odds { font-size: 13px; color: var(--muted); text-align: center; margin-bottom: 10px; }
.hunt-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.hunt-actions button { flex: 1; background: var(--bg); font-size: 14px; }
.hunt-actions .caught-btn { background: var(--shiny-soft); color: var(--text); font-weight: 600; }
details.archive { margin: 16px 0; }
details.archive summary { cursor: pointer; color: var(--muted); padding: 8px 0; }
.mini { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 12px; padding: 8px 12px; margin-bottom: 8px; }
.mini img { width: 44px; height: 44px; }
.mini .meta { flex: 1; min-width: 0; font-size: 14px; }
.mini .meta small { display: block; color: var(--muted); }
.mini button { background: var(--bg); font-size: 13px; padding: 6px 10px; }

/* Stats */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.tile { background: var(--card); border-radius: var(--radius); padding: 14px; }
.tile b { display: block; font-size: 28px; font-variant-numeric: tabular-nums; }
.tile span { font-size: 13px; color: var(--muted); }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 16px; }
.card h2 { font-size: 16px; margin-bottom: 10px; }
.game-row { padding: 8px 0; border-top: 1px solid var(--line); }
.game-row:first-of-type { border-top: 0; }
.game-row .line { display: flex; justify-content: space-between; font-size: 14px; }
.game-row .line span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Dialogs */
dialog {
  width: min(440px, calc(100vw - 32px));
  border: 0; border-radius: 18px;
  padding: 20px;
  background: var(--card); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog h2 { font-size: 19px; margin-bottom: 12px; }
dialog form { display: grid; gap: 12px; }
dialog label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
dialog label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
dialog input, dialog select { width: 100%; }
dialog label.check input { width: auto; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }
.picker { display: grid; gap: 4px; max-height: 220px; overflow: auto; }
.picker:empty { display: none; }
.picker button { display: flex; align-items: center; gap: 8px; text-align: left; background: var(--bg); padding: 4px 10px; }
.picker button img { width: 40px; height: 40px; }
.picker button.on { outline: 2px solid var(--accent); }

.or { display: flex; align-items: center; gap: 10px; margin: 14px 0; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
button.google { width: 100%; border: 1px solid var(--line); font-weight: 600; }

/* ---- Dex extras ---------------------------------------------------------- */
.hint { margin: 0; font-size: 12px; color: var(--muted); }
.seg button { padding: 7px 10px; }
.seg button[data-mode=info].on { background: var(--text); color: var(--bg); }
.badge-strip details { background: var(--card); border-radius: 12px; padding: 8px 12px; }
.badge-strip summary { cursor: pointer; font-size: 14px; font-weight: 600; }
.badge-group { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.badge-cat { width: 100%; font-size: 12px; color: var(--muted); }
button.gym {
  padding: 5px 10px; border-radius: 999px; font-size: 12px;
  background: var(--bg); color: var(--muted); border: 1px solid var(--line);
}
button.gym.on { color: #fff; border-color: transparent; font-weight: 600; text-shadow: 0 1px 1px rgb(0 0 0 / .35); }

/* ---- Detail sheet ---------------------------------------------------------- */
dialog.sheet { width: min(560px, calc(100vw - 16px)); max-height: 92dvh; padding: 0; overflow: hidden; }
#detail-body { max-height: 92dvh; overflow-y: auto; padding: 8px 18px 22px; }
.detail-top { position: sticky; top: 0; display: flex; justify-content: space-between; background: var(--card); z-index: 1; padding: 4px 0; }
.detail-top .close { margin-left: auto; font-size: 18px; }
.detail-head { text-align: center; }
.sprites { display: flex; justify-content: center; gap: 12px; }
.sprites figure { margin: 0; }
.sprites img { width: 120px; height: 120px; }
.sprites figcaption { font-size: 12px; color: var(--muted); }
.detail-head h2 { margin: 4px 0 2px; font-size: 24px; }
.detail-head .cry { padding: 2px 6px; font-size: 18px; vertical-align: middle; }
.types { display: flex; justify-content: center; gap: 6px; margin-top: 8px; }
.type { color: #fff; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; text-shadow: 0 1px 1px rgb(0 0 0 / .3); }
.detail-sec { margin-top: 18px; }
.detail-sec h3 { margin: 0 0 8px; font-size: 15px; }
.center { text-align: center; }
.flavor { margin: 0; font-style: italic; color: var(--muted); }

.own { border-radius: 10px; background: var(--bg); margin-bottom: 6px; }
.own.has-reg { background: var(--caught-soft); }
.own.has-shiny { background: var(--shiny-soft); }
.own-row { display: flex; align-items: center; gap: 6px; padding: 6px 8px; }
.own-game { flex: 1; min-width: 0; font-size: 14px; }
.own-game small { color: var(--muted); }
.pill { padding: 5px 10px; border-radius: 999px; font-size: 12px; background: var(--card); color: var(--muted); }
.pill.on { background: var(--caught); color: #fff; font-weight: 600; }
.pill.shiny.on { background: var(--shiny); }
.chev { width: 32px; padding: 4px; text-align: center; }
.rec-edit { display: grid; gap: 6px; padding: 4px 10px 10px; }
.rec-line { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.rec-edit textarea, .rec-edit input {
  font: inherit; font-size: 14px; width: 100%;
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; background: var(--card); color: var(--text);
}
.rec-line input { width: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chips:empty { display: none; }
.chip { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); }

.stat { display: grid; grid-template-columns: 34px 34px 1fr; align-items: center; gap: 6px; font-size: 13px; margin-bottom: 4px; }
.stat span { color: var(--muted); }
.stat b { text-align: right; font-variant-numeric: tabular-nums; }
.stat i { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.stat u { display: block; height: 100%; border-radius: 4px; }

.evo-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
button.evo { display: grid; justify-items: center; gap: 0; padding: 4px 6px; background: var(--bg); font-size: 12px; }
button.evo img { width: 64px; height: 64px; }
button.evo.current { outline: 2px solid var(--accent); cursor: default; opacity: 1; }
button.evo small { font-size: 10px; color: var(--muted); }
button.evo small.yes { color: var(--caught); }
.evo-arrow { display: grid; justify-items: center; font-size: 18px; color: var(--muted); max-width: 90px; text-align: center; }
.evo-arrow small { font-size: 10px; line-height: 1.2; }
.enc { display: grid; gap: 1px; font-size: 13px; padding: 6px 0; border-top: 1px solid var(--line); }
.enc:first-of-type { border-top: 0; }
.enc span { color: var(--muted); }

/* ---- Hunt extras ---------------------------------------------------------- */
.hunt-notes { margin: 0 0 10px; font-size: 13px; color: var(--muted); white-space: pre-wrap; text-align: center; }
details.phases { margin-top: 10px; }
details.phases summary { cursor: pointer; font-size: 13px; color: var(--muted); }
.phase { display: flex; align-items: center; gap: 8px; background: var(--shiny-soft); border-radius: 10px; padding: 6px 8px; margin-top: 6px; }
.phase img { width: 40px; height: 40px; }
.phase .meta { flex: 1; min-width: 0; display: grid; font-size: 13px; }
.phase small { color: var(--muted); }
.recs { display: grid; gap: 6px; }
.recs:empty { display: none; }
.recs p { margin: 0; font-size: 13px; }
button.rec { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; text-align: left; background: var(--bg); padding: 8px 10px; font-size: 13px; }
button.rec em { font-style: normal; font-weight: 700; color: var(--caught); font-variant-numeric: tabular-nums; }
button.rec.on { outline: 2px solid var(--accent); }
dialog textarea { font: inherit; width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; background: var(--card); color: var(--text); }

/* ---- Timeline ---------------------------------------------------------- */
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.review-facts { margin: 0; padding-left: 18px; font-size: 14px; display: grid; gap: 6px; }
.memory { background: var(--shiny-soft); }
.section-title { font-size: 17px; margin: 8px 0; }
.tl-day { font-size: 13px; color: var(--muted); margin: 14px 0 6px; font-weight: 600; }
.tl-group { padding: 4px 12px; margin-bottom: 0; }
.tl-row { display: flex; align-items: baseline; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.tl-row:first-child { border-top: 0; }
.tl-icon { width: 20px; text-align: center; flex: 0 0 auto; }
.tl-label { flex: 1; min-width: 0; }
.tl-time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tint-green .tl-icon { color: var(--caught); }
.tint-yellow .tl-icon { color: var(--shiny); }
.tint-blue .tl-icon { color: #3b82f6; }
.tint-orange .tl-icon { color: #f97316; }
.tint-purple .tl-icon { color: #8b5cf6; }
#timeline-more { margin-top: 12px; }

@media (max-width: 440px) {
  .mode-row { flex-wrap: wrap; }
  .mode-row .seg { flex: 1 1 100%; }
  .mode-row .seg button { flex: 1; }
  .mode-row input { flex-basis: 100%; }
  .filter-row { display: grid; grid-template-columns: 1fr 1fr; }
  .game-btn .game-name { display: none; }
  .game-btn .game-logos { flex: 1; }
}

/* ---- Game picker ---------------------------------------------------------- */
.game-btn {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  border: 1px solid var(--line); background: var(--card); padding: 4px 10px; text-align: left;
}
.game-btn .game-logos { display: flex; gap: 4px; flex: 0 0 auto; }
.game-btn .game-logos img { height: 34px; width: auto; max-width: 72px; object-fit: contain; }
.game-btn .game-name { flex: 1; min-width: 0; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-btn .caret { color: var(--muted); }
.game-dlg-body { max-height: 92dvh; overflow-y: auto; padding: 8px 16px 20px; }
.game-dlg-body .detail-top h2 { margin: 6px 0; font-size: 19px; }
.game-group { font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
.game-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 8px; }
.game-tile {
  display: grid; justify-items: center; gap: 4px; padding: 10px 8px;
  background: var(--bg); border: 2px solid transparent; border-radius: 14px;
}
.game-tile.on { border-color: var(--accent); background: var(--accent-soft); }
.tile-logos { display: flex; justify-content: center; align-items: center; gap: 4px; height: 48px; width: 100%; }
.tile-logos img { max-height: 48px; min-width: 0; max-width: 100%; object-fit: contain; }
.tile-logos.n2 img { max-width: calc(50% - 2px); }
.tile-name { font-size: 12px; font-weight: 600; text-align: center; line-height: 1.2; }
.tile-progress { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.game-tile .bar { width: 100%; margin-top: 0; }

.row > .game-btn { flex: 2 1 0; }

/* ---- Versions (paired games) ---------------------------------------------- */
.version-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; }
.version-row button, .vbtn {
  padding: 6px 12px; border-radius: 999px; font-size: 13px;
  background: var(--card); border: 2px solid var(--vc); color: var(--text);
}
.version-row button.on, .vbtn.on { background: var(--vc); color: #fff; font-weight: 700; }
.vbtn { padding: 4px 10px; font-size: 12px; }
.rec-versions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; }
.per-version { margin-left: 6px; }
.per-version::before { content: '· '; }
.vtags { display: flex; gap: 3px; justify-content: center; flex-wrap: wrap; margin-top: 3px; }
.vtags:empty { display: none; }
.vtag {
  font-size: 9px; font-weight: 700; color: #fff; padding: 1px 5px; border-radius: 999px;
  letter-spacing: .02em; text-shadow: 0 1px 1px rgb(0 0 0 / .25);
}
.own-tags { display: flex; gap: 3px; flex-wrap: wrap; }
.own-tags:empty { display: none; }
.own-game { display: grid; gap: 2px; }

/* ---- Icons ---------------------------------------------------------------- */
.ico { width: 1.15em; height: 1.15em; flex: 0 0 auto; vertical-align: -0.2em; }
body[data-sprites="pixel"] :is(.cell, .hunt-head, .picker, .phase, .evo, .sprites, .mini) img,
img.pixel { image-rendering: pixelated; }

/* ---- Dex toolbar (compact) ---------------------------------------------- */
.progress-row { display: flex; align-items: center; gap: 10px; }
.progress-row .progress-line { flex: 1; min-width: 0; }
.badge-pill {
  display: flex; align-items: center; gap: 4px; flex: 0 0 auto;
  font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line); color: var(--text);
}
.badge-pill .ico { color: var(--shiny); }
.badge-pill[aria-expanded="true"] { border-color: var(--shiny); }
.badge-strip { background: var(--card); border-radius: 12px; padding: 4px 12px 10px; }
.toolbar { display: flex; gap: 8px; align-items: stretch; }
.searchbox {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); padding: 0 10px; color: var(--muted);
}
.searchbox input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 9px 0; outline: none; }
.searchbox:focus-within { border-color: var(--accent); }
.filter-btn {
  display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card);
  font-size: 14px; padding: 8px 12px;
}
.filter-btn.active { border-color: var(--accent); }
.filter-btn .count {
  min-width: 19px; height: 19px; border-radius: 10px; background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700; display: grid; place-items: center; padding: 0 5px;
}
.modebar { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.iconseg { flex: 0 0 auto; }
.iconseg button { display: flex; align-items: center; gap: 5px; padding: 7px 10px; font-size: 13px; }
.iconseg button .ico { width: 19px; height: 19px; }
.iconseg button[data-mode=shiny].on { background: var(--shiny); }
.iconseg button[data-mode=info].on { background: var(--text); color: var(--bg); }
.version-row { gap: 5px; }
.version-row button { padding: 5px 11px; font-size: 12px; }

/* Filters bottom sheet */
dialog.sheet.bottom {
  width: min(560px, 100vw); max-width: 100vw; margin: auto auto 0; border-radius: 20px 20px 0 0;
  max-height: 82dvh; padding: 0;
}
.filter-body {
  max-height: 82dvh; overflow-y: auto; display: grid; gap: 14px;
  padding: 8px max(16px, env(safe-area-inset-left, 0px)) calc(16px + env(safe-area-inset-bottom, 0px));
}
.filter-body h2 { margin: 0; }
.grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto; }
.filter-group h3 { margin: 0 0 6px; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.choice { display: flex; flex-wrap: wrap; gap: 6px; }
.choice button { font-size: 13px; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); }
.choice button[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: transparent; font-weight: 600; }
/* "tchip", not "type": the .type badge style would turn unselected chips white-on-white. */
.choice button.tchip[aria-pressed="true"] { background: var(--tc); color: #fff; text-shadow: 0 1px 1px rgb(0 0 0 / .3); }
.sheet-actions { display: flex; gap: 8px; position: sticky; bottom: 0; background: var(--card); padding-top: 6px; }
.sheet-actions button { flex: 1; padding: 12px; background: var(--bg); }
.sheet-actions .primary { background: var(--accent); }

/* Backup in the account dialog */
.backup { font-size: 14px; }
.backup-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 10px; }
.backup-head small { font-size: 12px; }
.backup .msg { margin: 6px 0 0; font-size: 13px; overflow-wrap: anywhere; }

/* Settings row in the account dialog */
.setting { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; }
.set-sec { border-top: 1px solid var(--line); padding: 12px 0; font-size: 14px; }
.set-sec:first-of-type { border-top: 0; padding-top: 0; }
.set-sec p { margin: 2px 0 0; overflow-wrap: anywhere; }
.set-note { display: block; font-weight: 400; font-size: 12px; line-height: 1.3; margin-top: 2px; }
.set-head { font-weight: 600; }
.set-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.set-actions button { background: var(--bg); font-size: 14px; padding: 10px 8px; }
#account-status.err { color: var(--accent); }
.setting .seg button { padding: 6px 12px; font-size: 13px; background: transparent; color: var(--muted); }
.setting .seg button.on { background: var(--accent); color: #fff; }

/* Markers drawn with icons */
.cell .badge { color: var(--shiny); top: 5px; right: 5px; }
.cell .badge .ico { width: 15px; height: 15px; }
.cell .note-dot { color: var(--muted); top: 5px; left: 5px; }
.cell .note-dot .ico { width: 14px; height: 14px; }
.caught-btn { display: flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.caught-btn .ico { color: var(--shiny); }
.pill { display: inline-flex; align-items: center; gap: 4px; }
.pill .ico { width: 14px; height: 14px; }
.cry .ico { width: 20px; height: 20px; color: var(--muted); }
.tl-icon .ico { width: 18px; height: 18px; vertical-align: -3px; }
.tint-pink .tl-icon { color: #e0559a; }
.tint-red .tl-icon { color: var(--accent); }
.card h2 .ico { margin-right: 6px; color: var(--accent); }
#filter-groups { display: grid; gap: 16px; }

/* Version-exclusive marker: outlined, unlike the filled "caught in" tags. */
.xtag {
  font-size: 9px; font-weight: 700; padding: 0 5px; border-radius: 999px;
  border: 1.5px solid var(--vc); color: var(--vc); background: var(--card); line-height: 1.5;
}

/* Toast: one-line notice above the tab bar (new version ready, can't save on this device). */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 20;
  bottom: calc(78px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 12px;
  width: max-content; max-width: calc(100vw - 24px);
  padding: 10px 14px; border-radius: 12px;
  background: var(--text); color: var(--bg);
  font-size: 14px; box-shadow: 0 6px 24px rgb(0 0 0 / .25);
}
.toast button { background: var(--bg); color: var(--text); padding: 6px 12px; font-weight: 600; flex: none; }

/* The toast sits just above the Filters sheet's buttons when it's shown inside that sheet. */
.toast { text-align: left; }

/* ---- Box view --------------------------------------------------------------- */
#view-btn { padding: 8px 10px; }
#view-btn.active { border-color: var(--accent); color: var(--accent); }
.grid.boxes { grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); gap: 12px; }
.box {
  background: var(--card); border-radius: var(--radius); padding: 10px;
  content-visibility: auto; contain-intrinsic-size: auto 330px auto 330px;
}
.box header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.box header b { font-family: var(--display); font-size: 15px; color: var(--text); }
.box header .box-count { margin-left: auto; font-variant-numeric: tabular-nums; }
.box.full header .box-count { color: var(--caught); font-weight: 600; }
.box-grid { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 4px; }
.cell.bcell { padding: 2px; border-radius: 10px; background: var(--bg); content-visibility: visible; contain-intrinsic-size: none; }
.cell.bcell.caught { background: var(--caught-soft); }
.cell.bcell img { width: 100%; height: auto; aspect-ratio: 1; max-width: 64px; }
.cell.bcell .badge { top: 1px; right: 2px; }
.cell.bcell .badge .ico { width: 11px; height: 11px; }
.cell.bcell.off { opacity: .15; pointer-events: none; }

/* ---- Mark / unmark everything shown (Filters sheet) --------------------------- */
.bulk-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.bulk-actions button { background: var(--bg); font-size: 14px; padding: 10px 12px; }
.bulk-actions button:disabled { opacity: .45; cursor: default; }

/* ---- Hunts with a keyboard ---------------------------------------------------- */
.hunt.keyed { box-shadow: inset 0 0 0 2px var(--accent); }
#hunt-hint { margin: -4px 0 12px; text-align: center; }

/* ---- Stats ------------------------------------------------------------------ */
.missing { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.missing button { padding: 2px; background: var(--bg); border-radius: 10px; }
.missing img { display: block; width: 44px; height: 44px; }
.idle-games summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 10px 0 2px; border-top: 1px solid var(--line); }

/* In-app confirm / name prompt (replaces the browser's own pop-ups). */
#ask-dlg h2 { margin-bottom: 0; }
#ask-body { margin: 0; white-space: pre-line; font-size: 14px; }
#ask-input { border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; background: var(--card); }

/* ---- Compare sheet ------------------------------------------------------------ */
.link-card { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 2px 12px; width: 100%; text-align: left; font-weight: 600; }
.link-card .muted { font-weight: 400; font-size: 13px; }
#compare-body { max-height: 92dvh; overflow-y: auto; padding: 8px 16px 22px; display: grid; gap: 12px; align-content: start; }
#compare-body .detail-top h2 { margin: 6px 0; font-size: 19px; }
.cmp-pick { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 8px; align-items: center; }
.cmp-pick button { background: var(--bg); padding: 8px 10px; }
.cmp-mode { display: flex; }
.cmp-mode .seg button.on { background: var(--accent); color: #fff; }
.cmp-mode .seg button[data-shiny="1"].on { background: var(--shiny); }
.cmp-segs button b { font-variant-numeric: tabular-nums; }
.cmp-move { display: grid; gap: 6px; }
.cmp-move p { margin: 0; font-size: 13px; }
.cmp-move p:empty { display: none; }
.cmp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 4px; }
.cmp-grid button { padding: 2px; background: var(--bg); border-radius: 10px; content-visibility: auto; contain-intrinsic-size: auto 48px auto 48px; }
.cmp-grid img { display: block; width: 100%; height: auto; aspect-ratio: 1; }
.cmp-grid button.off { opacity: .3; }
.cmp-grid .empty { grid-column: 1 / -1; }

/* ---- Move to HOME sheet --------------------------------------------------------- */
#tohome-body { max-height: 92dvh; overflow-y: auto; padding: 8px 16px 22px; display: grid; gap: 12px; align-content: start; }
#tohome-head { display: grid; gap: 12px; }
#tohome-head .detail-top h2 { margin: 6px 0; font-size: 19px; }
.th-intro { margin: 0; }
#tohome-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 6px; }
#tohome-grid button {
  display: grid; gap: 2px; justify-items: center; padding: 4px 2px 6px; background: var(--bg); border-radius: 12px;
  content-visibility: auto; contain-intrinsic-size: auto 76px auto 96px;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
#tohome-grid img { display: block; width: 64px; height: 64px; object-fit: contain; }
#tohome-grid span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
#tohome-foot { margin: 0; font-size: 13px; color: var(--muted); }

/* Saved filter sets (Filters sheet): a chip that applies the set, joined to a small delete button. */
.saved-chip { display: inline-flex; }
.choice .saved-chip button:first-child { border-radius: 999px 0 0 999px; border-right: 0; padding-right: 9px; }
.choice .saved-chip button:last-child { border-radius: 0 999px 999px 0; padding: 7px 11px 7px 9px; color: var(--muted); }
.choice .save-filter { border-style: dashed; color: var(--muted); }

/* ---- Command palette ----------------------------------------------------------- */
.top-actions { display: flex; align-items: center; gap: 2px; }
#palette-dlg { margin-top: max(7dvh, calc(env(safe-area-inset-top) + 8px)); max-height: 80dvh; }
.pal-body { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 8px; max-height: 80dvh; padding: 12px; }
#palette-input { width: 100%; font-size: 16px; padding: 11px 12px; }
#palette-list { overflow-y: auto; display: grid; gap: 2px; align-content: start; }
.pal-row { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 5px 10px; background: transparent; text-align: left; }
.pal-row.on { background: var(--bg); box-shadow: inset 0 0 0 2px var(--accent); }
.pal-art { display: grid; place-items: center; width: 36px; height: 36px; color: var(--muted); }
.pal-art img { max-width: 36px; max-height: 36px; object-fit: contain; }
.pal-art .ico { width: 22px; height: 22px; }
.pal-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pal-label small, .pal-kind { color: var(--muted); font-size: 12px; }
.pal-body .hint { text-align: center; }
.set-actions .span { grid-column: 1 / -1; }

/* ---- Wide screens ----------------------------------------------------------
   The tab bar becomes a rail down the left side; on the Dex tab the details
   sheet docks to the right of the grid instead of covering it. */
.cell { scroll-margin: calc(var(--topbar-h, 58px) + 112px) 0 84px; }
.cell:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.cell.sel { outline: 3px solid var(--text); outline-offset: 1px; }
@media (min-width: 900px) {
  .app { padding-left: 84px; padding-bottom: 24px; }
  .tabbar {
    top: 0; right: auto; width: 84px;
    flex-direction: column; justify-content: flex-start; gap: 4px;
    padding: calc(64px + env(safe-area-inset-top)) 8px 12px;
    border-top: 0; border-right: 1px solid var(--line);
  }
  .tabbar button { flex: 0 0 auto; padding: 10px 4px; border-radius: 12px; }
  .tabbar button.on { background: var(--accent-soft); }
  .toast { bottom: 24px; }
  .cell { scroll-margin-bottom: 24px; }
}
@media (min-width: 1100px) {
  .app.with-panel { padding-right: 400px; }
  #detail-dlg.docked {
    position: fixed; inset: 0 0 0 auto; z-index: 6;
    width: 400px; height: 100dvh; max-height: none; margin: 0;
    border-radius: 0; border-left: 1px solid var(--line);
  }
  #detail-dlg.docked #detail-body { height: 100%; max-height: none; }
}
