:root {
  --bg: #14161d;
  --bg-raised: #1c1f29;
  --bg-hover: #242835;
  --border: #2e3342;
  --text: #e8eaf0;
  --text-dim: #9aa0b0;
  --accent: #e8534a;
  --accent-soft: rgba(232, 83, 74, 0.15);
  --ok: #4caf7d;
  --warn: #e0a93e;
  --radius: 8px;
}

* { box-sizing: border-box; }

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

a { color: var(--text); text-decoration: none; }
a:hover { color: var(--accent); }

h1, h2, h3 { line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.6rem 1.25rem;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--accent);
  white-space: nowrap;
}
.brand:hover { color: var(--accent); }

/* Desktop: the menu wrapper dissolves (display:contents) and flex `order`
   restores the classic row — brand, nav, search, user. The hamburger only
   exists on narrow screens (media query below). */
.brand { order: 0; }
.topbar-menu { display: contents; }
.nav { display: flex; gap: 1rem; order: 1; }
.nav a {
  color: var(--text-dim);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
}
.nav a:hover { color: var(--text); background: var(--bg-hover); }
.nav a.active { color: var(--text); background: var(--bg-hover); }

.searchbox { margin-left: auto; order: 2; }
.searchbox input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.35rem 0.7rem;
  width: 220px;
}
.searchbox input:focus { outline: 1px solid var(--accent); }

.userbox { display: flex; align-items: center; gap: 0.5rem; color: var(--text-dim); order: 3; }
.userbox .adminbox { display: flex; align-items: center; gap: 0.4rem; }

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 2.5rem;
  height: 2.35rem;
  padding: 0 0.55rem;
  order: 4;
}
.nav-toggle span {
  display: block;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}
.nav-toggle:hover { background: var(--bg-hover); }

@media (max-width: 880px) {
  .topbar { flex-wrap: wrap; gap: 0.6rem; padding: 0.5rem 0.8rem; }
  .searchbox { flex: 1 1 0; min-width: 0; }
  .searchbox input { width: 100%; }
  .nav-toggle { display: flex; }
  .topbar-menu {
    display: none;
    order: 5;
    flex-basis: 100%;
    flex-direction: column;
    gap: 0.3rem;
    border-top: 1px solid var(--border);
    padding-top: 0.5rem;
  }
  .topbar-menu.open { display: flex; }
  .topbar-menu .nav { flex-direction: column; gap: 0.1rem; }
  .topbar-menu .nav a { font-size: 1.02rem; padding: 0.55rem 0.5rem; }
  .topbar-menu .userbox {
    flex-wrap: wrap;
    row-gap: 0.4rem;
    border-top: 1px solid var(--border);
    padding: 0.55rem 0.5rem 0.25rem;
  }
}

.linklike {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: inherit;
  padding: 0;
}
.linklike:hover { color: var(--accent); text-decoration: underline; }

.content { max-width: 1400px; margin: 0 auto; padding: 1.25rem; }

/* ---------- Auth pages ---------- */
.auth-card {
  max-width: 380px;
  margin: 10vh auto;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
}

.stacked-form { display: flex; flex-direction: column; gap: 0.9rem; }
.stacked-form label { display: flex; flex-direction: column; gap: 0.3rem; color: var(--text-dim); }
.stacked-form input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.5rem 0.7rem;
}

button, .btn {
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  font-size: 0.95rem;
  padding: 0.45rem 1rem;
}
button:hover, .btn:hover { filter: brightness(1.1); color: #fff; }

.btn-secondary, button.btn-secondary {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-small, button.btn-small { padding: 0.2rem 0.6rem; font-size: 0.85rem; }

.btn-danger, button.btn-danger {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
}
.btn-danger:hover, button.btn-danger:hover {
  background: var(--accent);
  color: #fff;
  filter: none;
}

/* Account management rows: reset-password field + destructive action sit
   together and wrap on narrow screens rather than stretching the table. */
.accounts-table td { vertical-align: middle; }
.account-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.account-actions .inline-form { display: inline-flex; gap: 0.3rem; margin: 0; }
.account-actions input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.2rem 0.5rem;
  font-size: 0.85rem;
  width: 9rem;
}

.error { color: var(--accent); }
.muted { color: var(--text-dim); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }

/* Fix-data fold: red + auto-open when a TRUE mismatch (both sides populated,
   disagreeing) is present — mere gaps stay quiet, they auto-fill on accept */
summary.fixfold-warn { color: var(--accent); font-weight: 600; }
details.fixfold-alert {
  border-left: 3px solid var(--accent);
  padding-left: 0.6rem;
}
tr.row-true-mismatch > td { background: var(--accent-soft); }

/* Data-quality queue */
.dq-table td { vertical-align: top; }
.dq-value { margin: 0.1rem 0; }
.dq-value > code { color: var(--accent); }

/* ---------- Card grids ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
}

/* Zoom levels (floating -/+ control in base.html, persisted per browser).
   'small' guarantees at least 2 tiles per row even on a 344px-wide screen
   (Galaxy Z Fold outer display); 'large' is the roomy browse view. */
html[data-zoom="small"] .card-grid {
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 0.5rem;
}
html[data-zoom="small"] .card-tile { padding: 0.4rem; gap: 0.25rem; }
html[data-zoom="small"] .card-tile .card-name { font-size: 0.78rem; }
html[data-zoom="small"] .card-tile .card-meta { display: none; }
html[data-zoom="small"] .card-tile .card-price { font-size: 0.78rem; }
/* Dense grid: the (coarse-pointer-enlarged) qty stepper would overflow a
   ~100px tile — compact it; small zoom is a browse-first density anyway. */
html[data-zoom="small"] .qty-control button {
  min-width: 1.9rem;
  min-height: 1.9rem;
  width: 1.9rem;
  height: 1.9rem;
  font-size: 0.95rem;
}
html[data-zoom="small"] .qty-control { gap: 0.2rem; }
html[data-zoom="small"] .qty-control .qty { min-width: 1.1rem; font-size: 0.85rem; }
html[data-zoom="large"] .card-grid {
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
}

.zoom-ctl {
  position: fixed;
  right: 0.9rem;
  bottom: 1.1rem;
  z-index: 60;
  display: flex;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}
.zoom-ctl[hidden] { display: none; }
.zoom-ctl button {
  background: none;
  color: var(--text);
  width: 2.7rem;
  height: 2.7rem;
  padding: 0;
  font-size: 1.35rem;
  line-height: 1;
  border-radius: 0;
}
.zoom-ctl button:first-child { border-right: 1px solid var(--border); }
.zoom-ctl button:hover { background: var(--bg-hover); }
.zoom-ctl button:disabled { color: var(--border); background: none; cursor: default; }

.card-tile {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  transition: transform 0.1s ease;
}
.card-tile:hover { transform: translateY(-2px); border-color: var(--text-dim); }
.card-tile img { width: 100%; border-radius: 6px; display: block; }
.card-tile .card-name { font-size: 0.9rem; font-weight: 600; }
.card-tile .card-meta { font-size: 0.8rem; color: var(--text-dim); }
/* Prices on equivalent/card tiles — one row per priced variant, cheapest
   first: dimmed variant label left, price right (tabular digits so amounts
   align down the tile). Divider separates prices from the card text above. */
.card-tile .card-price {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-top: auto;
  padding-top: 0.4rem;
  border-top: 1px solid var(--border);
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--ok);
}
.card-tile .card-price .muted { font-weight: 400; font-size: 0.78rem; }
.card-tile .variant-price {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem 0.6rem;
  font-variant-numeric: tabular-nums;
  /* Rows carrying qty controls wrap instead of squashing the label into
     'Normal - ...' — the controls drop to their own line when tight. */
  flex-wrap: wrap;
}
.card-tile .variant-label {
  color: var(--text-dim);
  font-weight: 400;
  font-size: 0.78rem;
  flex: 1 1 auto;
  min-width: 0;
}
.card-tile .variant-price .qty-control { margin-left: auto; flex-shrink: 0; }

/* Tiles that carry interactive controls wrap the linked part in .tile-link
   (an <a> can't contain the add buttons), so the link inherits the tile's
   column layout. */
.card-tile .tile-link {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}
.card-tile .value-line {
  border-top: 1px dashed var(--border);
  padding-top: 0.2rem;
  margin-top: 0.1rem;
}

/* In-tile expander for a card's non-default variants (set-page tap-to-add):
   stays inside the tile, no navigation. */
.card-tile .variant-more { font-size: 0.8rem; }
.card-tile .variant-more summary {
  cursor: pointer;
  color: var(--text-dim);
  font-weight: 400;
  padding: 0.15rem 0;
  list-style-position: inside;
  user-select: none;
}
.card-tile .variant-more summary:hover { color: var(--accent); }
.card-tile .variant-more[open] summary { margin-bottom: 0.15rem; }
.card-tile .variant-more .variant-price { margin: 0.15rem 0; }

/* Pack-opening flow on phones/tablets: the +/- add controls must be real
   thumb targets, and tile text a touch larger. */
@media (pointer: coarse) {
  .qty-control button {
    min-width: 2.4rem;
    min-height: 2.4rem;
    font-size: 1.1rem;
  }
  .qty-control .qty { min-width: 2rem; font-size: 1rem; }
  .card-tile .card-price { font-size: 0.95rem; }
  .card-tile .variant-more summary { padding: 0.4rem 0; }
}

/* Filter/sort bars: allow wrapping into rows on narrow screens instead of
   overflowing. */
.filter-bar { flex-wrap: wrap; row-gap: 0.5rem; }
.filter-bar .qty-range { display: inline-flex; gap: 0.3rem; }
.filter-bar .qty-range input { width: 4.6rem; }
.filter-bar .group-toggles {
  display: inline-flex;
  gap: 0.9rem;
  flex-wrap: wrap;
  color: var(--text-dim);
  font-size: 0.85rem;
}
.filter-bar .group-toggles label {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
  white-space: nowrap;
}

/* Wants: one group per want — header line of badges/status, then the
   fulfilling options as price-compared tiles. */
.want-group { margin-bottom: 1rem; }
.want-group.fulfilled { opacity: 0.75; }
.want-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.7rem;
}
.want-header .want-remove { margin-left: auto; }

/* Attribution footer (Bulbapedia CC BY-NC-SA requires visible credit). */
.site-footer {
  max-width: 1400px;
  margin: 2rem auto 1rem;
  padding: 0.8rem 1.25rem;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.78rem;
}
.site-footer a { color: var(--text-dim); }
@media (max-width: 700px) {
  .filter-bar select, .filter-bar input[type="search"] { flex: 1 1 45%; min-width: 8.5rem; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.6rem; }
}

.card-tile.owned { border-color: var(--ok); }

.img-placeholder {
  width: 100%;
  aspect-ratio: 63 / 88;
  background: var(--bg-hover);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 0.8rem;
  text-align: center;
  padding: 0.5rem;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 0.75rem;
  padding: 0.05rem 0.55rem;
  white-space: nowrap;
}
.badge.owned { border-color: var(--ok); color: var(--ok); }
.badge.accent { border-color: var(--accent); color: var(--accent); }
.badge.warn { border-color: var(--warn); color: var(--warn); }

/* ---------- Tables ---------- */
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--border); }
th { color: var(--text-dim); font-weight: 600; font-size: 0.85rem; }
tr:hover td { background: var(--bg-raised); }

/* ---------- Panels & layout helpers ---------- */
.panel {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.row { display: flex; gap: 1rem; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 260px; }

.toolbar {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.toolbar select, .toolbar input {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.35rem 0.6rem;
}

.stat-tiles { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.stat-tile {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 1.2rem;
  min-width: 140px;
}
.stat-tile .stat-value { font-size: 1.6rem; font-weight: 700; }
.stat-tile .stat-label { color: var(--text-dim); font-size: 0.85rem; }

/* Narrow screens: stats become a tight 3-up grid instead of a tall stack —
   the numbers are orientation, not the destination; the workbenches below
   must be reachable without a scroll marathon. */
@media (max-width: 700px) {
  .stat-tiles {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.45rem;
    margin-bottom: 0.8rem;
  }
  .stat-tile { min-width: 0; padding: 0.45rem 0.55rem; }
  .stat-tile .stat-value { font-size: 1.05rem; line-height: 1.3; }
  .stat-tile .stat-label { font-size: 0.68rem; line-height: 1.3; }
  /* A tile carrying per-language badges (curation dashboard) needs the row. */
  .stat-tile:has(.badge) { grid-column: 1 / -1; }
}

.progress {
  background: var(--bg-hover);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}
.progress > div { background: var(--ok); height: 100%; }

/* ---------- Quantity stepper ---------- */
.qty-control { display: inline-flex; align-items: center; gap: 0.4rem; }
.qty-control button {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text);
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 6px;
  line-height: 1;
}
.qty-control button:hover { border-color: var(--accent); color: var(--accent); }
.qty-control .qty { min-width: 1.6rem; text-align: center; font-weight: 600; }
.qty-control .qty.zero { color: var(--text-dim); }

/* ---------- Curation ---------- */
.proposal-pair { display: flex; gap: 1rem; align-items: flex-start; }
.proposal-pair img { width: 180px; max-width: 100%; border-radius: 6px; }
/* Queue proposal panels (pair-3col = two card columns + actions): the card
   columns are FIXED-width so the Accept/Reject column never shifts with the
   (variable-length) text under the cards — stable click targets prevent
   misclicks (owner request 2026-07-23). Scoped by class because the manual-
   decision rows reuse .proposal-pair with a different structure. */
.pair-3col > div:nth-child(1),
.pair-3col > div:nth-child(2) {
  flex: 0 0 200px;
  min-width: 0;
  overflow-wrap: break-word;
}
.pair-3col > div:nth-child(3) { flex: 1 1 auto; min-width: 0; }

/* Narrow screens: the two cards sit side by side at half width and the
   evidence/actions drop below at full width — nothing bleeds off-screen.
   The action column still keeps ITS internal layout, so Accept/Reject stay
   adjacent and the cursor-anchored autoscroll keeps them under the thumb. */
@media (max-width: 700px) {
  .proposal-pair { flex-wrap: wrap; gap: 0.6rem; }
  .pair-3col > div:nth-child(1),
  .pair-3col > div:nth-child(2) { flex: 1 1 calc(50% - 0.6rem); }
  .pair-3col > div:nth-child(3) { flex: 1 1 100%; }
  .proposal-pair img { width: 100%; max-width: 220px; }
  .content { padding: 0.8rem; }
  .panel { padding: 0.75rem; overflow-x: auto; }
  .site-footer { padding: 0.8rem; }
}

/* Decided-state bar badges that double as Undo buttons. */
.badge-btn {
  cursor: pointer;
  border: none;
  font: inherit;
  font-size: 0.8rem;
}
.badge-btn:hover { filter: brightness(1.25); text-decoration: underline; }

/* name_en editor label: names the card the field writes to (the reviewed
   non-EN card), so an asymmetric false-positive pairing can't be misread as
   "confirm the proposed match's name". */
.propname-label {
  display: block;
  font-size: 0.8rem;
  margin: 0.4rem 0 0.2rem;
}

.variant-checks { display: flex; gap: 0.7rem; flex-wrap: wrap; }
.variant-checks label {
  display: inline-flex;
  gap: 0.3rem;
  align-items: center;
  color: var(--text-dim);
  font-size: 0.85rem;
}

fieldset { border: 1px solid var(--border); border-radius: var(--radius); }

/* ---------- sets view ----------
   Era jump nav, collapsible era sections, and the set tile grid.
   New rules only — nothing above this block is restyled. */
.era-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 1rem;
}
.era-nav a {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 0.78rem;
  padding: 0.1rem 0.6rem;
  white-space: nowrap;
}
.era-nav a:hover { border-color: var(--accent); color: var(--accent); }

details.set-era > summary {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  user-select: none;
}
/* display:flex suppresses the native marker; draw our own so open/closed
   state stays visible */
details.set-era > summary::before {
  content: '\25B8'; /* ▸ */
  color: var(--text-dim);
  font-size: 0.85rem;
}
details.set-era[open] > summary::before { content: '\25BE'; /* ▾ */ }
details.set-era > summary h2 { margin: 0; font-size: 1.15rem; }
details.set-era > summary .era-meta { font-size: 0.85rem; }
details.set-era > summary:hover h2 { color: var(--accent); }

.set-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.9rem;
  margin-top: 1rem;
}

.set-tile {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  transition: transform 0.1s ease, border-color 0.1s ease;
}
.set-tile:hover {
  transform: translateY(-2px);
  border-color: var(--text-dim);
  color: var(--text); /* keep body text neutral; title carries the accent */
}
.set-tile:hover .set-tile-title { color: var(--accent); }

.set-tile-art {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  overflow: hidden;
}
.set-tile-art .set-logo {
  max-height: 100%;
  max-width: 100%;
  object-fit: contain;
}
.set-tile-art .set-symbol {
  max-height: 32px;
  max-width: 44px;
  object-fit: contain;
  flex-shrink: 0;
}
.set-tile-art .set-art-name {
  font-weight: 700;
  font-size: 1.02rem;
  line-height: 1.25;
  text-align: center;
  color: var(--text-dim);
}

.set-tile-title { font-weight: 600; font-size: 0.92rem; line-height: 1.3; }
.set-tile-native { font-size: 0.8rem; line-height: 1.3; }
.set-tile-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.8rem;
  margin-top: auto; /* pin meta + progress to the tile bottom */
}
.set-tile-progress {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.set-tile-progress .progress { flex: 1; }
.set-tile-progress .set-owned { font-size: 0.75rem; white-space: nowrap; }

.set-tile.not-imported { opacity: 0.55; }
.set-tile.not-imported:hover { opacity: 0.85; }
