:root {
  color-scheme: light dark;
  --fg: #1a1a1a;
  --muted: #6b7280;
  --bg: #fafafa;
  --row: #ffffff;
  --row-alt: #f3f4f6;
  --border: #e5e7eb;
  --accent: #2563eb;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fg: #e5e7eb;
    --muted: #9ca3af;
    --bg: #0b0d10;
    --row: #14171c;
    --row-alt: #181c22;
    --border: #2a2f37;
    --accent: #60a5fa;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  padding: 24px;
}
@media (max-width: 640px) {
  body { padding: 14px; }
  h1 { font-size: 18px; }
}
header { margin-bottom: 16px; }
.header-row {
  display: flex; align-items: baseline; gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.page-nav {
  display: flex; align-items: baseline; gap: 14px;
  margin-left: auto;
  font-size: 13px;
  flex-wrap: wrap;
}
.page-nav a {
  color: var(--accent);
  text-decoration: none;
}
.page-nav a:hover { text-decoration: underline; }
h1 { margin: 0; font-size: 22px; }
.muted { color: var(--muted); font-size: 13px; }

.sheet-status {
  margin: 4px 0 8px;
  font-size: 12px;
}
.sheet-status:empty { display: none; }
.sheet-status.loading::before { content: "⟳ "; }
.sheet-status.ok { color: #4ade80; }
.sheet-status.ok::before { content: "✓ "; }
.sheet-status.err { color: #fca5a5; }
.sheet-status.err::before { content: "⚠ "; }
#champion-select {
  font-size: 13px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--row);
  color: var(--fg);
  cursor: pointer;
}

.controls {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.controls input[type="search"] {
  flex: 1 1 280px;
  min-width: 200px;
  padding: 8px 10px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--row);
  color: var(--fg);
}
.controls .toggle { display: inline-flex; align-items: center; gap: 6px; }
.controls input[type="number"] {
  width: 60px; padding: 4px 6px;
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--row); color: var(--fg);
}

.board-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.board-toggle .board-btn {
  padding: 6px 14px;
  font-size: 13px;
  border: none;
  background: var(--row);
  color: var(--fg);
  cursor: pointer;
  border-right: 1px solid var(--border);
}
.board-toggle .board-btn:last-child { border-right: none; }
.board-toggle .board-btn.active {
  background: var(--accent);
  color: white;
}

.perf-filter {
  display: flex; flex-wrap: wrap; gap: 10px;
  align-items: center;
  margin-bottom: 12px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--row);
}
.perf-filter .label { color: var(--muted); font-size: 12px; }
.perf-filter .presets { display: inline-flex; gap: 4px; }
.perf-filter .preset {
  padding: 3px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}
.perf-filter .preset.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Region filter — same shape as .perf-filter / .preset. */
.region-filter {
  display: flex; flex-wrap: wrap; gap: 10px;
  align-items: center;
  margin-bottom: 12px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--row);
}
.region-filter .label { color: var(--muted); font-size: 12px; }
.region-filter .region-pills { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.region-pill {
  padding: 3px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}
.region-pill.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Tournament-performance stat strip — sits between the controls and the
   region filter. 4 dollar-amount-style badges + one inline sparkline. */
.stat-strip {
  display: flex; flex-wrap: wrap; gap: 10px;
  margin-bottom: 12px;
}
.stat-card {
  flex: 0 0 auto;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--row);
  min-width: 100px;
}
.stat-card .stat-label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stat-card .stat-value {
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.stat-card .stat-value a { color: var(--accent); text-decoration: none; }
.stat-card .stat-value a:hover { text-decoration: underline; }
#stat-sparkline { flex: 1 1 220px; min-width: 220px; }
#trend-sparkline { display: block; margin-top: 2px; }
#stat-sparkline-delta { font-size: 11px; }
#stat-sparkline-delta.trend-up { color: #4ade80; }
#stat-sparkline-delta.trend-down { color: #f87171; }
#stat-sparkline-delta.trend-flat { color: var(--muted); }

/* Composition variance panel — under the cards table, mirrors median-deck */
.composition-variance { margin-top: 16px; }
.composition-variance summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 14px;
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--row);
}
.composition-variance details[open] summary { border-radius: 8px 8px 0 0; }
.composition-variance .cv-title { font-weight: 600; }
#composition-variance {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  background: var(--bg);
}
.cv-group { padding: 8px 0; border-bottom: 1px dotted var(--border); }
.cv-group:last-child { border-bottom: none; }
.cv-group-header {
  display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px;
}
.cv-rank { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 18px; }
.cv-name { font-weight: 600; }
.cv-count { color: var(--muted); font-size: 12px; }
.cv-core, .cv-flex { font-size: 12px; line-height: 1.8; }
.cv-pill {
  display: inline-block;
  padding: 1px 6px;
  margin: 1px 2px;
  border-radius: 4px;
  background: var(--row);
  border: 1px solid var(--border);
}
.cv-pill a { color: var(--accent); text-decoration: none; }
.cv-pill a:hover { text-decoration: underline; }
.cv-flex { margin-top: 12px; padding-top: 10px; border-top: 1px dotted var(--border); }
.cv-flex-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px; }
.perf-filter .custom { font-size: 12px; color: var(--muted); }
.perf-filter input[type="number"] {
  width: 50px; padding: 3px 6px;
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--bg); color: var(--fg);
}
.perf-filter input[type="date"] {
  font: inherit;
  font-size: 12px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--fg);
  color-scheme: light dark;
}
.perf-filter .separator { color: var(--muted); }
.perf-filter .clear-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.perf-filter .clear-btn:hover { color: var(--fg); }
.perf-filter .clear-btn[hidden] { display: none; }

.type-filters {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-bottom: 12px;
  align-items: center;
}
.type-filters .label { color: var(--muted); font-size: 12px; margin-right: 4px; }
.type-filters .pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--row);
  cursor: pointer;
  user-select: none;
  font-size: 12px;
  text-transform: capitalize;
}
.type-filters .pill input { margin: 0; }
.type-filters .pill.off { opacity: 0.45; text-decoration: line-through; }
.type-filters .toggle-all {
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
  background: none; border: none; padding: 3px 6px;
}
.type-filters .toggle-all:hover { text-decoration: underline; }

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 720px; }
th, td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
td { white-space: nowrap; }
td:first-child { white-space: normal; }
th {
  position: sticky; top: 0;
  background: var(--bg);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.dim { color: var(--muted); }

.rarity {
  display: inline-block;
  margin-left: 4px;
  font-size: 11px;
  line-height: 1;
  vertical-align: 1px;
  font-variant-emoji: text;
}
.rarity-common   { color: #9ca3af; } /* gray */
.rarity-uncommon { color: #38bdf8; } /* light blue */
.rarity-rare     { color: #ec4899; } /* pink */
.rarity-epic     { color: #f97316; } /* orange */
.rarity-showcase { color: #facc15; } /* yellow */

#card-thumb {
  position: fixed;
  z-index: 1000;
  width: 260px;
  height: auto;
  border-radius: 12px;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  background: var(--row);
}
@media (hover: none), (pointer: coarse) {
  #card-thumb { display: none !important; }
}

td.clickable {
  cursor: pointer;
  user-select: none;
}
td.clickable:hover { background: rgba(96, 165, 250, 0.12); }
td.clickable .chev {
  display: inline-block;
  width: 10px;
  color: var(--muted);
  margin-right: 2px;
  font-size: 10px;
}
tr.expanded td.clickable .chev { color: var(--accent); }
tr.expanded { background: rgba(96, 165, 250, 0.05) !important; }

tr.deck-list-row td {
  background: var(--row-alt);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px 14px;
}
.deck-list-summary { margin: 0 0 6px; font-size: 12px; }
.deck-list {
  list-style: none;
  margin: 0; padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 4px 18px;
}
.deck-list li {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 12px;
  padding: 2px 0;
  border-bottom: 1px dotted var(--border);
  list-style: none;
}
.deck-list li::marker { content: ""; }
.deck-list li:last-child { border-bottom: none; }
.deck-list .qty {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  min-width: 24px;
  text-align: right;
}
.deck-list .rank {
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: var(--muted);
  min-width: 80px;
}
.deck-list a { color: var(--accent); text-decoration: none; flex: 1; }
.deck-list a:hover { text-decoration: underline; }
.deck-list .date {
  font-variant-numeric: tabular-nums;
  font-size: 11px;
}
th .arrow { display: inline-block; margin-left: 4px; opacity: 0.5; font-size: 11px; }
th.sort-active .arrow { opacity: 1; color: var(--accent); }
tbody tr:nth-child(odd) { background: var(--row); }
tbody tr:nth-child(even) { background: var(--row-alt); }
tbody tr:hover { background: rgba(96, 165, 250, 0.08); }

td a { color: var(--accent); text-decoration: none; }
td a:hover { text-decoration: underline; }
.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--row-alt);
  border: 1px solid var(--border);
  font-size: 11px;
  margin-right: 4px;
  text-transform: capitalize;
}

/* Domain colours sampled from riftdecks rune icons. */
.tag.domain-body      { color: #ec8f2f; border-color: rgba(236,143,47,0.5); background: rgba(236,143,47,0.14); }
.tag.domain-calm      { color: #72a666; border-color: rgba(114,166,102,0.5); background: rgba(114,166,102,0.14); }
.tag.domain-chaos     { color: #b189d6; border-color: rgba(136,102,169,0.55); background: rgba(136,102,169,0.16); }
.tag.domain-fury      { color: #e43f47; border-color: rgba(228,63,71,0.5); background: rgba(228,63,71,0.14); }
.tag.domain-mind      { color: #3f8cb8; border-color: rgba(63,140,184,0.5); background: rgba(63,140,184,0.14); }
.tag.domain-order     { color: #d9bf28; border-color: rgba(217,191,40,0.55); background: rgba(217,191,40,0.16); }
.tag.domain-colorless { color: #94a3b8; border-color: rgba(160,160,160,0.5); background: rgba(216,216,216,0.14); }

/* Legend-chip — shared by staples, collection. Round pill linking back to
   /?champion=<slug>. `.solo` is the highlighted style for cards used by
   only one legend. */
.legend-chip {
  display: inline-block;
  padding: 1px 8px;
  margin: 1px 4px 1px 0;
  border-radius: 999px;
  background: var(--row);
  border: 1px solid var(--border);
  color: var(--fg);
  text-decoration: none;
  white-space: nowrap;
  font-size: 12px;
}
.legend-chip:hover { background: var(--row-alt); }
.legend-chip .pct,
.legend-chip .qty {
  color: var(--muted);
  margin-left: 4px;
  font-variant-numeric: tabular-nums;
}
.legend-chip.solo {
  background: rgba(96, 165, 250, 0.12);
  border-color: var(--accent);
}

/* Missing-cards highlight — shared by staples, collection. */
td.missing-pos {
  color: #f87171;
  font-weight: 600;
}

/* The motto banner — top-of-page reminder that dashboards send you to hell.
   Inlined on index.html. Minimize state persists via localStorage. */
.motto {
  position: relative;
  max-width: 380px;
  margin: 12px auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #0b0b0b;
  line-height: 0;
}
.motto[hidden] { display: none; }
.motto-img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 110px;
  object-fit: contain;
}
.motto-toggle {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 22px;
  height: 22px;
  padding: 0;
  font-size: 14px;
  line-height: 1;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 4px;
  cursor: pointer;
  z-index: 2;
}
.motto-toggle:hover { background: rgba(0, 0, 0, 0.75); }
.motto-show {
  display: inline-flex;
  align-items: center;
  margin: 8px 0 12px;
  padding: 2px 10px;
  font-size: 11px;
  color: var(--muted);
  background: var(--row);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font-style: italic;
}
.motto-show:hover { color: var(--fg); }
.motto-show[hidden] { display: none; }

.bar {
  display: inline-block;
  width: 60px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin-left: 6px;
  vertical-align: middle;
  overflow: hidden;
}
.bar > span {
  display: block; height: 100%;
  background: var(--accent);
}

#empty-state { text-align: center; padding: 32px; color: var(--muted); }

.median-deck {
  margin: 16px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--row);
}
.median-deck summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 14px;
  display: flex; align-items: center; gap: 12px;
  flex-wrap: wrap;
  border-bottom: 1px solid transparent;
}
.median-mode-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.median-mode-toggle .mode-btn {
  padding: 4px 10px;
  font-size: 12px;
  border: none;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  border-right: 1px solid var(--border);
}
.median-mode-toggle .mode-btn:last-child { border-right: none; }
.median-mode-toggle .mode-btn.active {
  background: var(--accent);
  color: white;
}
.copy-btn {
  padding: 4px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  white-space: nowrap;
}
.copy-btn:hover { background: var(--row-alt); }
.copy-btn.copied {
  background: #16a34a;
  border-color: #16a34a;
  color: white;
}

/* Back-link used in every sub-page header to return to the main dashboard. */
.back-link {
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
}
.back-link:hover { text-decoration: underline; }

/* En-route toggle row — shared by closeness / cart / diff / staples /
   collection. Per-page margin overrides go in each page's CSS. */
.enroute-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
}
.enroute-toggle input { margin: 0; }
.enroute-toggle .muted { font-size: 12px; }

/* Dynamic container for per-lock-tab toggles (rendered by ensureLockToggles
   in utils.js). Lays out adjacent to the en-route toggle. */
.lock-toggles {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
}
.lock-toggle { font-size: 13px; }
#median-meta {
  padding: 8px 14px 0;
  font-size: 12px;
  line-height: 1.45;
}
#median-meta a { color: var(--accent); text-decoration: none; }
#median-meta a:hover { text-decoration: underline; }
#median-meta strong { color: var(--fg); font-weight: 600; }
.median-deck details[open] summary { border-bottom-color: var(--border); }
.median-deck summary::-webkit-details-marker { display: none; }
.median-deck summary::before {
  content: "▸";
  font-size: 11px;
  color: var(--muted);
  margin-right: 4px;
  transition: transform 0.15s;
}
.median-deck details[open] summary::before { transform: rotate(90deg); }
.median-deck .median-title { font-weight: 600; font-size: 14px; }
.median-deck #median-content {
  padding: 12px 14px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.median-section h3 {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.median-section h3 .target { color: var(--fg); }
.median-section h3 .target.short { color: #d97706; }
.median-section ul {
  list-style: none;
  margin: 0; padding: 0;
  font-size: 13px;
}
.median-section li {
  display: flex;
  gap: 8px;
  padding: 2px 0;
  border-bottom: 1px dotted var(--border);
}
.median-section li:last-child { border-bottom: none; }
.median-section .qty {
  display: inline-block;
  min-width: 22px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.median-section .name { flex: 1; }
.median-section .pct {
  font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.median-section .name a { color: var(--accent); text-decoration: none; }
.median-section .name a:hover { text-decoration: underline; }
