/* ============================================================
   Colour schemes — every visual value is a token so the layout
   rules below never need to know which scheme is active.
   ============================================================ */

:root {
  --radius: 12px;
  /* Value-score bands. Fixed hues so a "great" score reads the same in every
     scheme; only the light theme needs darker variants for contrast. */
  --band-great: #22c55e;
  --band-good: #a3e635;
  --band-fair: #f59e0b;
  --band-poor: #ef4444;
}

body[data-theme="midnight"] {
  --bg: #0e1117;
  --bg-raised: #161b25;
  --bg-blur: rgba(14, 17, 23, 0.92);
  --border: #262d3a;
  --border-bright: #333d4e;
  --text: #e7ecf3;
  --text-dim: #8c97a8;
  --accent: #4ade80;
  --accent-dim: #1d7f4a;
  --accent-glow: rgba(74, 222, 128, 0.12);
  --on-accent: #0e1117;
  --shadow: rgba(0, 0, 0, 0.35);
  --cancel-filter: invert(0.6);
}

body[data-theme="royal"] {
  --bg: #12101c;
  --bg-raised: #1c1830;
  --bg-blur: rgba(18, 16, 28, 0.92);
  --border: #2e2748;
  --border-bright: #443a63;
  --text: #ece8f7;
  --text-dim: #9d94b8;
  --accent: #f5c451;
  --accent-dim: #8a6a1c;
  --accent-glow: rgba(245, 196, 81, 0.14);
  --on-accent: #12101c;
  --shadow: rgba(0, 0, 0, 0.45);
  --cancel-filter: invert(0.6);
}

body[data-theme="daylight"] {
  --bg: #f4f6fa;
  --bg-raised: #ffffff;
  --bg-blur: rgba(244, 246, 250, 0.92);
  --border: #dfe4ec;
  --border-bright: #c3ccda;
  --text: #1a2233;
  --text-dim: #64708a;
  --accent: #2563eb;
  --accent-dim: #7ea6f5;
  --accent-glow: rgba(37, 99, 235, 0.14);
  --on-accent: #ffffff;
  --shadow: rgba(23, 35, 60, 0.12);
  --cancel-filter: none;
  --band-great: #16a34a;
  --band-good: #65a30d;
  --band-fair: #d97706;
  --band-poor: #dc2626;
}

body[data-theme="neon"] {
  --bg: #08080d;
  --bg-raised: #101018;
  --bg-blur: rgba(8, 8, 13, 0.92);
  --border: #22222e;
  --border-bright: #3a3a52;
  --text: #e8e8f5;
  --text-dim: #8888a3;
  --accent: #22d3ee;
  --accent-dim: #0e7490;
  --accent-glow: rgba(34, 211, 238, 0.16);
  --on-accent: #08080d;
  --shadow: rgba(0, 0, 0, 0.6);
  --cancel-filter: invert(0.6);
}

/* ============================================================
   Base
   ============================================================ */

* { 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;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s, color 0.2s;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- masthead + toolbar ---------- */

.masthead {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-blur);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.masthead-inner {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 12px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 24px 0;
}

.masthead h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

/* The wordmark leans on the scheme's accent so it recolours with the theme:
   "yeah" in accent, "nah" in the body text colour, the TLD dimmed. */
.wordmark {
  font-size: 22px;
  font-weight: 750;
  letter-spacing: -0.03em;
}

.wordmark-yeah { color: var(--accent); }
.wordmark-nah { color: var(--text); }
.wordmark-tld { color: var(--text-dim); font-weight: 600; }

.tagline {
  margin: 0;
  color: var(--text-dim);
  font-size: 13px;
}

/* Shown only on narrow screens — see the small-screen block at the foot of
   this file, which is also where the collapsed state is defined. */
.toolbar-toggles {
  display: none;
  gap: 8px;
  margin-left: auto;
}

.toolbar-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 9px 14px;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.toolbar-toggle svg {
  width: 16px; height: 16px;
  fill: none;
  stroke: var(--text-dim);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.toolbar-toggle .chevron {
  width: 14px; height: 14px;
  transition: transform 0.2s;
}

.toolbar-toggle[aria-expanded="false"] .chevron { transform: rotate(-90deg); }

/* Collapsed reads as "filters are off", so the control loses its accent. */
.toolbar-toggle[aria-expanded="true"] {
  background: var(--accent-glow);
  border-color: var(--accent-dim);
}

.toolbar-toggle[aria-expanded="true"] svg:not(.chevron) { stroke: var(--accent); }

.counts {
  margin: 0 0 0 auto;
  color: var(--text-dim);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  /* Top, not centre: the filter group is the taller of the two because it
     carries the range filters, and centring floated the style group's controls
     half a row below it. */
  align-items: flex-start;
  gap: 12px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 24px;
}

/* The toolbar holds two groups: what you are looking at (filter) and how it
   looks (style). Each is a wrapping row of its own controls. */
.toolbar-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  /* Keeps the group's own rows packed at its top once it is stretched below,
     so the first row of each group starts at the same height. */
  align-content: flex-start;
  gap: 12px;
}

/* A narrow basis lets the filter group wrap its own controls onto a second row
   rather than shoving the style group off the end of the toolbar. */
#group-filter { flex: 1 1 280px; }
#group-style { flex: 0 1 auto; }

/* A rule rather than a gap, so the split survives the row wrapping. Stretching
   runs it the full height of the toolbar instead of just the shorter group's. */
.toolbar-group + .toolbar-group {
  align-self: stretch;
  padding-left: 20px;
  border-left: 1px solid var(--border);
}

.group-label {
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.field { position: relative; display: flex; }
.search-field { flex: 1 1 220px; max-width: 320px; }

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  fill: none;
  stroke: var(--text-dim);
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}

input[type="search"],
select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 9px;
  font: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input[type="search"] { padding-left: 36px; }
input[type="search"]::-webkit-search-cancel-button { filter: var(--cancel-filter); }

select {
  appearance: none;
  padding-right: 34px;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
                    linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% + 1px), calc(100% - 13px) calc(50% + 1px);
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

input[type="search"]:focus, select:focus {
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.hint {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  padding: 1px 6px;
  border: 1px solid var(--border-bright);
  border-radius: 5px;
  color: var(--text-dim);
  font: 600 11px ui-monospace, "SF Mono", Menlo, monospace;
  pointer-events: none;
  transition: opacity 0.15s;
}

.search-field:focus-within .hint { opacity: 0; }

/* ---------- range filters ---------- */

/* Sits inside the filter group, so the toolbar has already supplied the page
   gutters; taking a full flex row puts it on its own line under the controls. */
.filters {
  flex-basis: 100%;
  margin: 0;
  padding: 0;
}

.filters summary {
  width: max-content;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

.filters summary:hover { color: var(--text); }

.filter-body {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 20px;
  padding-top: 14px;
}

/* ------------------------------------------------------------
   Hidden merchants — only present once there are some, and its
   whole job is to make every hide reversible.
   ------------------------------------------------------------ */

.hidden-panel {
  flex-basis: 100%;
  margin: 0;
  padding: 0;
}

.hidden-panel summary {
  width: max-content;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.hidden-panel summary:hover { color: var(--text); }

.hidden-count {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  margin-left: 4px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent-glow);
  color: var(--accent);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.hidden-body { padding-top: 12px; }

.hidden-items {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  /* Capped so hiding fifty merchants cannot push the grid off the screen. */
  max-height: 132px;
  overflow-y: auto;
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
}

/* Each name is the button, so unhiding one is a single tap on an obvious target
   rather than hunting for an x. */
.unhide {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 5px 11px;
  background: var(--bg-raised);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.unhide::after {
  content: "×";
  color: var(--accent);
  font-size: 14px;
  line-height: 1;
}

.unhide:hover { color: var(--text); border-color: var(--border-bright); }

.hidden-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

/* ------------------------------------------------------------
   Undo — catches a mis-tapped hide at the moment it happens.
   ------------------------------------------------------------ */

.undo-bar {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 14px 11px 18px;
  background: var(--bg-raised);
  border: 1px solid var(--border-bright);
  border-radius: 999px;
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 13px;
  max-width: calc(100vw - 32px);
  transform: translate(-50%, 12px);
  opacity: 0;
  transition: opacity 0.18s, transform 0.18s;
}

/* An author display: value outranks the UA stylesheet's [hidden] rule, so
   without this the bar would sit on screen permanently. Same for the panel. */
.undo-bar[hidden],
.hidden-panel[hidden] { display: none; }

.undo-bar.visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

.undo-action {
  padding: 6px 12px;
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: 999px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.undo-action:hover { filter: brightness(1.08); }

.slider {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 210px;
}

.slider label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--text-dim);
  font-size: 12px;
}

.slider output {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--border-bright);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 15px; height: 15px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.reset {
  padding: 9px 15px;
  background: var(--bg-raised);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.reset:hover { color: var(--text); border-color: var(--border-bright); }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}

.toggle:hover { border-color: var(--border-bright); }
.toggle:has(:checked) { color: var(--text); }

.toggle input {
  appearance: none;
  position: relative;
  width: 16px; height: 16px;
  margin: 0;
  border: 1.5px solid var(--border-bright);
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.toggle input:checked {
  background: var(--accent);
  border-color: var(--accent);
}

/* Masked rather than a coloured data URI, so the tick follows the scheme. */
.toggle input:checked::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--on-accent);
  -webkit-mask: var(--tick) center / 12px no-repeat;
  mask: var(--tick) center / 12px no-repeat;
}

:root {
  --tick: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.5l3 3 6-6' fill='none' stroke='%23fff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* ---------- cards ---------- */

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 16px;
}

/* The wrapper exists so the pin button can sit over the card without being
   nested inside the anchor, which would be invalid and unfocusable. */
.card-wrap {
  position: relative;
  display: flex;
  animation: card-in 420ms cubic-bezier(0.2, 0.7, 0.3, 1) backwards;
  animation-delay: calc(var(--stagger, 0) * 28ms);
}

.card-wrap.no-stagger { animation: none; }

@keyframes card-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .card-wrap { animation: none !important; }
}

.card {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 18px;
  background: var(--bg-raised);
  /* Higher-value bonuses carry a warmer border, so the grid reads as a heat
     map rather than a uniform wall of boxes. */
  border: 1px solid color-mix(
    in oklab, var(--accent-dim) calc(var(--intensity, 0) * 55%), var(--border)
  );
  border-radius: var(--radius);
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

/* Guarded: a touch browser leaves :hover stuck on the last-tapped card, so the
   lift would persist after the user has moved on. */
@media (hover: hover) {
  .card:hover {
    border-color: var(--accent-dim);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--shadow);
  }
}

.card:focus-visible {
  border-color: var(--accent-dim);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--shadow);
  outline: none;
}

.card-wrap.active .card {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.card-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  /* Keeps the heading clear of the two buttons parked in the corner. */
  padding-right: 52px;
  margin-bottom: 4px;
}

.rank {
  flex: none;
  margin-top: 1px;
  font-size: 14px;
  line-height: 1.2;
}

.logo {
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  width: 22px; height: 22px;
  margin-top: 1px;
  overflow: hidden;
  border-radius: 6px;
  background: hsl(var(--hue, 210) 45% 42%);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}

/* Sits over the monogram, so removing it on error reveals the letter again. */
.logo img {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;
}

.logo:has(img) { background: var(--bg); }

.favourite {
  position: absolute;
  top: 12px; right: 12px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
}

.card-wrap:hover .favourite,
.card-wrap.pinned .favourite,
.favourite:focus-visible { opacity: 1; }

.favourite:hover { background: var(--bg); }

.favourite svg {
  width: 15px; height: 15px;
  fill: none;
  stroke: var(--text-dim);
  stroke-width: 1.6;
  stroke-linejoin: round;
}

.card-wrap.pinned .favourite svg {
  fill: var(--band-fair);
  stroke: var(--band-fair);
}

/* Sits immediately left of the pin, sharing its reveal-on-hover behaviour so the
   card corner stays quiet until you go looking. */
.hide-toggle {
  position: absolute;
  top: 12px; right: 42px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
}

.card-wrap:hover .hide-toggle,
.card-wrap.is-hidden .hide-toggle,
.hide-toggle:focus-visible { opacity: 1; }

.hide-toggle:hover { background: var(--bg); }

.hide-toggle svg {
  width: 15px; height: 15px;
  fill: none;
  stroke: var(--text-dim);
  stroke-width: 1.6;
  stroke-linejoin: round;
}

/* The eye is struck through only while the merchant is visible: the icon shows
   what the button will do, not what the current state is. */
.card-wrap.is-hidden .hide-slash { display: none; }
.card-wrap.is-hidden .hide-toggle svg { stroke: var(--accent); }

/* A hidden card is only ever on screen because you searched for it or asked to
   see them, so it reads as set aside rather than as part of the list. */
.card-wrap.is-hidden .card {
  opacity: 0.55;
  border-style: dashed;
}

.card-wrap.is-hidden:hover .card { opacity: 1; }

.hidden-badge {
  position: absolute;
  top: 12px; left: 12px;
  z-index: 2;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border-bright);
  color: var(--text-dim);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

mark {
  padding: 0 1px;
  border-radius: 3px;
  background: var(--accent-glow);
  color: var(--accent);
}

.merchant {
  flex: 1;
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.bonus-name {
  display: block;
  margin-bottom: 14px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.phone {
  flex: none;
  width: 15px; height: 15px;
  margin-top: 3px;
  fill: none;
  stroke: var(--text-dim);
  stroke-width: 1.8;
  stroke-linecap: round;
}

.stats { margin: 0 0 auto; }

.stats > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 0;
  font-size: 13px;
}

.stats dt { color: var(--text-dim); }

.stats dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 550;
}

/* The amount row doubles as a bar chart of the bonus relative to the largest. */
.stat-amount {
  margin: 0 -7px;
  padding: 3px 7px;
  border-radius: 5px;
  background: linear-gradient(
    90deg,
    var(--accent-glow) calc(var(--intensity, 0) * 100%),
    transparent calc(var(--intensity, 0) * 100%)
  );
}

.stat-amount dd { color: var(--accent); font-weight: 700; }

/* Only rendered when non-zero, which is rare enough to be worth flagging. */
.stat-rollover dt, .stat-rollover dd { color: var(--band-fair); }

.score {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.score[data-band="great"] { --band: var(--band-great); }
.score[data-band="good"] { --band: var(--band-good); }
.score[data-band="fair"] { --band: var(--band-fair); }
.score[data-band="poor"] { --band: var(--band-poor); }

.score-label {
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.score-bar {
  flex: 1;
  height: 5px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
}

.score-fill {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: var(--band);
}

.score-value {
  min-width: 20px;
  color: var(--band);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* ============================================================
   Articles — tiles at the head of the grid, opening in place
   ============================================================ */

/* The seed list is the server-rendered original. Once app.js has read it into
   grid tiles it is redundant, so it is hidden only when the script actually ran:
   a visitor without JavaScript keeps a plain, readable list of links. */
body.js .article-seed { display: none; }

.article-seed {
  margin: 0 0 24px;
  padding: 0;
}
.article-seed h2 { font-size: 15px; margin: 0 0 10px; }
.article-seed ul { margin: 0; padding-left: 18px; }
.article-seed li { margin-bottom: 14px; }
.article-seed a { color: var(--accent); }

.tile-article {
  position: relative;
  display: flex;
  animation: card-in 0.32s ease both;
  animation-delay: calc(var(--stagger, 0) * 40ms);
}
.tile-article.no-stagger { animation: none; }

.tile-link {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  padding: 16px;
  border-radius: var(--radius);
  /* Reads as a different kind of thing from a merchant card without being a
     different visual language: same radius, same raised surface, accent border. */
  background: var(--bg-raised);
  border: 1px solid var(--accent-dim);
  color: var(--text);
  text-decoration: none;
}

@media (hover: hover) {
  .tile-link:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    transition: transform 0.15s, border-color 0.15s;
  }
}

.tile-kicker {
  color: var(--accent);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.tile-title {
  margin: 0;
  font-size: 16px;
  line-height: 1.3;
}

.tile-summary {
  margin: 0;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.5;
}

.tile-more {
  margin-top: auto;
  padding-top: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}

/* One guide is plenty when the grid is a single column, and the list and
   spotlight layouts have their own idea of how wide a cell should be. Trimming
   in CSS rather than JavaScript avoids measuring the column count, which an
   auto-fill grid will not tell you honestly. */
@media (max-width: 640px) {
  .tile-article:nth-of-type(n + 2) { display: none; }
}
body[data-layout="list"] .tile-article:nth-of-type(n + 2) { display: none; }
body[data-layout="spotlight"] .tile-article:nth-of-type(n + 3) { display: none; }

.article-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: start center;
  padding: 24px 16px;
  overflow-y: auto;
  background: color-mix(in oklab, var(--bg) 82%, transparent);
  backdrop-filter: blur(3px);
}
.article-overlay[hidden] { display: none; }

body.article-open { overflow: hidden; }

.article-sheet {
  position: relative;
  width: min(720px, 100%);
  padding: 28px 28px 36px;
  background: var(--bg-raised);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.article-close {
  position: absolute;
  top: 10px; right: 10px;
  width: 44px; height: 44px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}
.article-close:hover { color: var(--text); }

.article-sheet h2 {
  margin: 0 44px 4px 0;
  font-size: 26px;
  line-height: 1.2;
}

.article-meta {
  margin: 0 0 20px;
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Article bodies are author-written Markdown, so these rules have to cover
   every tag the sanitiser allows rather than only the ones used so far. */
#article-content { font-size: 15px; line-height: 1.7; }
#article-content h2 { margin: 28px 0 8px; font-size: 19px; }
#article-content h3 { margin: 22px 0 6px; font-size: 16px; }
#article-content h4 { margin: 18px 0 6px; font-size: 14px; }
#article-content p, #article-content ul, #article-content ol { margin: 0 0 14px; }
#article-content ul, #article-content ol { padding-left: 22px; }
#article-content li { margin-bottom: 5px; }
#article-content a { color: var(--accent); }
#article-content code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--bg);
  font-size: 0.9em;
}
#article-content pre {
  overflow-x: auto;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--bg);
}
#article-content pre code { padding: 0; background: none; }
#article-content blockquote {
  margin: 0 0 14px;
  padding-left: 14px;
  border-left: 2px solid var(--accent-dim);
  color: var(--text-dim);
}
#article-content img { max-width: 100%; height: auto; }
#article-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 14px;
  font-size: 14px;
}
#article-content th, #article-content td {
  padding: 7px 9px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
#article-content hr {
  margin: 24px 0;
  border: none;
  border-top: 1px solid var(--border);
}

/* ============================================================
   Server-rendered document pages — /merchants and /bonuses

   Plain documents that work with no JavaScript. They borrow the
   theme tokens from body[data-theme] and nothing else, so none of
   the four layouts or the grid machinery applies here.
   ============================================================ */

body.doc {
  display: block;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px 64px;
}

.doc-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 0;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.doc-wordmark {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-decoration: none;
}

.doc-nav { display: flex; flex-wrap: wrap; gap: 18px; }
.doc-nav a { color: var(--text-dim); font-size: 14px; text-decoration: none; }
.doc-nav a:hover { color: var(--text); }

.doc-main h1 { margin: 0 0 12px; font-size: 28px; line-height: 1.2; }
.doc-main h2 { margin: 32px 0 10px; font-size: 19px; }

.lead {
  max-width: 68ch;
  margin: 0 0 16px;
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1.65;
}
.lead a { color: var(--accent); }
.lead strong { color: var(--text); }

.doc-foot {
  margin-top: 48px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.6;
}
.doc-foot p { max-width: 76ch; margin: 0 0 10px; }
.doc-foot nav { display: flex; gap: 16px; margin-top: 14px; }
.doc-foot a { color: var(--text-dim); }

/* A wide table on a narrow screen scrolls inside its own box rather than
   forcing the whole page sideways. */
.table-scroll {
  overflow-x: auto;
  margin: 0 0 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.directory {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.directory th, .directory td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.directory thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-raised);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.directory tbody tr:nth-child(even) { background: var(--bg-raised); }
.directory tbody tr:hover { background: var(--accent-glow); }
.directory tbody th { font-weight: 600; }
.directory a { color: var(--accent); text-decoration: none; }
.directory a:hover { text-decoration: underline; }
.directory .num { text-align: right; font-variant-numeric: tabular-nums; }
.directory .score-cell { color: var(--text); font-weight: 700; }

.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--border-bright);
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 0 0 28px;
}

.pager-pages {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.pager-page, .pager-step {
  display: inline-block;
  min-width: 38px;
  padding: 8px 12px;
  border: 1px solid var(--border-bright);
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  text-decoration: none;
}
.pager-page:hover, .pager-step:hover { color: var(--text); border-color: var(--accent-dim); }

.pager-page.current {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
  color: var(--on-accent);
  font-weight: 700;
}
.pager-step.disabled { opacity: 0.35; }

/* The prose is the reason a category page is indexed at all, so it gets the
   measure and rhythm of an article rather than of a caption. */
.category-intro { max-width: 68ch; font-size: 16px; line-height: 1.7; }
.category-intro p { margin: 0 0 16px; }
.category-intro strong { color: var(--text); }
.category-intro a { color: var(--accent); }

.category-more { margin-top: 36px; }
.category-more ul { margin: 0; padding-left: 20px; }
.category-more li { margin-bottom: 6px; }
.category-more a { color: var(--accent); }

.guide-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin: 24px 0 32px;
  padding: 0;
  list-style: none;
}

.guide-list a {
  display: block;
  height: 100%;
  padding: 18px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
}

@media (hover: hover) {
  .guide-list a:hover { border-color: var(--accent-dim); }
}

.guide-list h2 { margin: 0 0 8px; font-size: 17px; line-height: 1.3; }
.guide-list p { margin: 0 0 12px; color: var(--text-dim); font-size: 13.5px; line-height: 1.55; }
.guide-count { color: var(--accent); font-size: 12px; font-weight: 600; }

@media (max-width: 640px) {
  body.doc { padding: 0 16px 48px; }
  .doc-main h1 { font-size: 23px; }
  .directory th, .directory td { padding: 8px 10px; }
}

/* Links out of the page footer on the app itself. */
.site-links {
  margin: 28px 0 0;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.7;
}
.site-links a { color: var(--accent); }

.noscript-fallback { margin-top: 28px; font-size: 14px; line-height: 1.6; }
.noscript-fallback h2 { font-size: 16px; }
.noscript-fallback a { color: var(--accent); }

.empty {
  padding: 60px 0;
  color: var(--text-dim);
  text-align: center;
}

/* ============================================================
   Layout: sidebar — controls move into a full-height left rail
   ============================================================ */

body[data-layout="sidebar"] {
  display: grid;
  grid-template-columns: 250px 1fr;
  align-items: start;
}

body[data-layout="sidebar"] .masthead {
  height: 100vh;
  border-bottom: none;
  border-right: 1px solid var(--border);
}

body[data-layout="sidebar"] .masthead-inner {
  display: block;
  padding: 24px 20px 0;
}

body[data-layout="sidebar"] .counts { margin: 10px 0 0; }

body[data-layout="sidebar"] .toolbar {
  flex-direction: column;
  align-items: stretch;
  padding: 20px;
}

/* The sidebar's flex axis is vertical, so the groups stack and the rule that
   divides them has to move from their side to their top. */
body[data-layout="sidebar"] .toolbar-group {
  flex: 0 0 auto;
  flex-direction: column;
  align-items: stretch;
}

body[data-layout="sidebar"] .toolbar-group + .toolbar-group {
  padding-left: 0;
  padding-top: 16px;
  border-left: none;
  border-top: 1px solid var(--border);
}

/* Same vertical-axis trap as the search box above: the "take a full row" basis
   would become a full-height one and push the filters out over the cards. */
body[data-layout="sidebar"] .filters { flex-basis: auto; }

/* The column flex axis is vertical here, so a flex-basis would set the
   height of the search box rather than its width. */
body[data-layout="sidebar"] .search-field {
  flex: 0 0 auto;
  max-width: none;
}

/* Auto margins would suppress the grid item's stretch and shrink main to
   fit-content, leaving the card grid stranded in the middle of the column. */
body[data-layout="sidebar"] main {
  max-width: none;
  margin: 0;
  padding: 24px;
}

/* ============================================================
   Layout: list — one dense aligned row per merchant
   ============================================================ */

body[data-layout="list"] .grid {
  grid-template-columns: 1fr;
  gap: 8px;
}

body[data-layout="list"] .card {
  flex-direction: row;
  align-items: center;
  gap: 18px;
  padding: 12px 18px;
}

body[data-layout="list"] .card:hover { transform: none; }

body[data-layout="list"] .card-head {
  flex: none;
  width: 190px;
  margin-bottom: 0;
}

body[data-layout="list"] .merchant { font-size: 14px; }

body[data-layout="list"] .bonus-name {
  flex: 1;
  margin-bottom: 0;
  font-size: 12px;
}

body[data-layout="list"] .stats {
  display: flex;
  gap: 22px;
  margin: 0;
}

body[data-layout="list"] .stats > div {
  flex-direction: column;
  align-items: flex-end;
  gap: 0;
  width: 92px;
  padding: 0;
}

body[data-layout="list"] .stats dt {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* The amount bar and the full-width score rail both assume a stacked card. */
body[data-layout="list"] .stat-amount {
  margin: 0;
  padding: 0;
  background: none;
}

body[data-layout="list"] .score {
  flex: none;
  width: 86px;
  margin: 0;
  padding: 0;
  border-top: none;
}

body[data-layout="list"] .score-label { display: none; }

/* Both parked on the left here, where the row has space the stats do not use:
   the pin above the midline, the hide button below it. */
body[data-layout="list"] .card { padding-left: 38px; }
body[data-layout="list"] .card-head { padding-right: 0; }

body[data-layout="list"] .favourite {
  top: 50%;
  right: auto;
  left: 6px;
  transform: translateY(-100%);
}

body[data-layout="list"] .hide-toggle {
  top: 50%;
  right: auto;
  left: 6px;
  transform: translateY(0);
}

body[data-layout="list"] .hidden-badge {
  top: 6px;
  left: auto;
  right: 10px;
}

/* ============================================================
   Layout: spotlight — the bonus amount carries the card
   ============================================================ */

body[data-layout="spotlight"] .grid {
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

body[data-layout="spotlight"] .card { text-align: center; }

/* Symmetric padding so the corner buttons do not pull the heading off centre. */
body[data-layout="spotlight"] .card-head {
  justify-content: center;
  padding: 0 52px;
}
body[data-layout="spotlight"] .bonus-name { margin-bottom: 16px; }

body[data-layout="spotlight"] .stats > div:first-child {
  flex-direction: column;
  align-items: center;
  gap: 0;
  margin-bottom: 12px;
  padding-bottom: 14px;
  border-bottom: 1px dashed var(--border);
}

body[data-layout="spotlight"] .stats > div:first-child dt {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

body[data-layout="spotlight"] .stats > div:first-child dd {
  color: var(--accent);
  font-size: 30px;
  font-weight: 700;
  line-height: 1.25;
}

/* The figure is already the loudest thing on the card; the bar behind it just
   reads as a stray block at this size. */
body[data-layout="spotlight"] .stat-amount {
  margin: 0;
  padding: 0 0 14px;
  background: none;
}

/* ============================================================
   Small screens — the sidebar and list layouts fold back down
   ============================================================ */

@media (max-width: 760px) {
  body[data-layout="sidebar"] { grid-template-columns: 1fr; }
  body[data-layout="sidebar"] .masthead {
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  body[data-layout="list"] .card { flex-wrap: wrap; gap: 10px; }
  body[data-layout="list"] .card-head { width: auto; flex: 1 1 100%; }
  body[data-layout="list"] .stats { flex-wrap: wrap; gap: 14px; }
}

@media (max-width: 640px) {
  .masthead-inner, .toolbar, main { padding-left: 16px; padding-right: 16px; }
  .counts { margin-left: 0; flex-basis: 100%; }
  .search-field { max-width: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }

  /* Full width rather than two-up: the option text ("Colours: Midnight") is
     long enough that a half-width select truncates it mid-word. Tighter gaps
     and padding buy back the vertical space instead. */
  .toolbar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    padding-top: 12px;
    padding-bottom: 12px;
  }
  .field { width: 100%; }
  .field select { width: 100%; }

  .masthead-inner { gap: 6px 12px; padding-top: 14px; }
  .tagline { flex-basis: 100%; }

  .toolbar-toggles { display: flex; }

  /* Expanded, the header is ~435px tall — sticky it would pin two thirds of a
     667px phone screen for the whole scroll, so it scrolls away instead. */
  .masthead { position: static; }

  /* Each group collapses on its own, so you can keep the filters to hand
     without the style pickers taking up a phone screen. */
  .toolbar-group[data-collapsed="true"] { display: none; }

  /* Inline, the label would eat into the search box and leave it narrower than
     every control stacked beneath it. */
  .toolbar-group { gap: 8px; }
  .group-label { flex-basis: 100%; }

  /* Stacked, the vertical rule between groups would be a stray mark. */
  .toolbar-group + .toolbar-group {
    padding-left: 0;
    padding-top: 12px;
    border-left: none;
    border-top: 1px solid var(--border);
  }

  /* With both groups away the header is short enough to pin, which keeps the
     toggles reachable without scrolling back to the top. */
  body.controls-collapsed .toolbar { display: none; }
  body.controls-collapsed .masthead { position: sticky; top: 0; }
  body.controls-collapsed .masthead-inner { padding-bottom: 12px; }

  /* Safari zooms the whole page when a focused control's text is under 16px. */
  #search, .toolbar select { font-size: 16px; }
}

/* ============================================================
   Touch input — no hover to reveal things with, and fingers are
   coarser than a mouse pointer.
   ============================================================ */

@media (hover: none) {
  /* Hover was the only way to reveal the pin button, so on a phone it was
     invisible and the feature undiscoverable. */
  .favourite {
    opacity: 1;
    width: 44px; height: 44px;
    top: 2px; right: 2px;
  }
  .favourite svg { width: 19px; height: 19px; }

  /* Two full 44px targets side by side, which is why .card-head reserves 52px
     plus this button's width rather than the 24px one pin needed. */
  .hide-toggle {
    opacity: 1;
    width: 44px; height: 44px;
    top: 2px; right: 46px;
  }
  .hide-toggle svg { width: 19px; height: 19px; }

  /* Both targets are 44px wide now, so the heading needs the room they take. */
  .card-head { padding-right: 92px; }
  body[data-layout="spotlight"] .card-head { padding: 0 92px; }

  /* Stacked rather than side by side: a list row is not tall enough for two
     44px targets in a column, so the card gives them a wider left gutter. */
  body[data-layout="list"] .card { padding-left: 54px; }
  body[data-layout="list"] .card-head { padding-right: 0; }
  body[data-layout="list"] .favourite { left: 2px; right: auto; transform: translateY(-100%); }
  body[data-layout="list"] .hide-toggle { left: 2px; right: auto; transform: translateY(0); }

  /* The keyboard shortcut it advertises does not exist on a touch device. */
  .hint { display: none; }

  /* Padding grows the grabbable area to 24px while background-clip keeps the
     painted track its original 4px. */
  input[type="range"] {
    height: 24px;
    padding: 10px 0;
    background-clip: content-box;
  }
  input[type="range"]::-webkit-slider-thumb { width: 20px; height: 20px; }
  input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; }

  .filters summary { padding: 10px 0; }
}
