:root {
  --body: #ffffff;
  --panel: #f4f6fb;
  --panel-raised: #e9edfa;
  --display: #eef1f8;
  --line: #dbe1ee;
  --line-soft: #e7ebf5;
  --paper: #131b30;
  --paper-dim: #5c6785;
  --blue: #2f3fae;
  --mint: #1f9d5c;
  --error: #b3261e;
  --radius: 4px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding-block: env(safe-area-inset-top, 0px) env(safe-area-inset-bottom, 0px);
  font-family: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--body);
  color: var(--paper);
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, monospace;
}

.console {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 1.25rem 4rem;
}

/* ---- top bar ---- */

.topbar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  padding: 2.5rem 0 1.75rem;
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 700;
  font-size: 2rem;
  letter-spacing: -0.02em;
}

.logo-mark {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
}

/* ---- scan panel ---- */

.scan-panel {
  padding-top: 1.75rem;
}

.lead {
  max-width: 38ch;
  margin: 0;
  color: var(--paper-dim);
  font-size: 1.05rem;
  line-height: 1.5;
  letter-spacing: -0.005em;
}

/* ---- game selector ---- */

.game-select {
  display: flex;
  gap: 0.7rem;
  margin: 0 0 1.3rem;
}

.game-tile {
  position: relative;
  flex: 1 1 0;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.8rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.game-tile input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.game-tile .led {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  transition: background-color 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.game-tile .game-name {
  flex: 1 1 auto;
  font-weight: 600;
  font-size: 0.98rem;
  color: var(--paper-dim);
}

.game-tile .game-count {
  flex: 0 0 auto;
  font-size: 0.78rem;
  color: var(--paper-dim);
}

.game-tile:has(input:checked) {
  border-color: var(--blue);
  background: var(--panel-raised);
}

.game-tile:has(input:checked) .led {
  background: var(--blue);
  border-color: var(--blue);
  box-shadow: 0 0 6px 1px rgba(47, 63, 174, 0.4);
}

.game-tile:has(input:checked) .game-name {
  color: var(--paper);
}

.game-tile:has(input:checked) .game-count {
  color: var(--blue);
}

.game-tile:has(input:focus-visible) {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.search-box {
  position: relative;
}

.prompt {
  position: absolute;
  left: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--blue);
  font-family: "IBM Plex Mono", monospace;
  font-size: 1.1rem;
  pointer-events: none;
}

#search-input {
  width: 100%;
  font-family: "IBM Plex Sans", sans-serif;
  font-size: 1.05rem;
  padding: 0.85rem 1rem 0.85rem 2.2rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--display);
  color: var(--paper);
}

#search-input::placeholder {
  color: var(--paper-dim);
}

#search-input:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 10;
  margin: 0;
  padding: 0.3rem 0;
  list-style: none;
  background: var(--body);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 28px rgba(19, 27, 48, 0.14);
  max-height: 420px;
  overflow-y: auto;
}

.suggestions li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 1rem;
  border-left: 2px solid transparent;
  cursor: pointer;
}

.suggestions li.active {
  background: var(--panel-raised);
  border-left-color: var(--blue);
}

.sugg-thumb {
  flex: 0 0 auto;
  width: 30px;
  height: 42px;
  border-radius: 3px;
  background: var(--panel);
  overflow: hidden;
}

.sugg-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.sugg-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sugg-name {
  color: var(--paper);
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sugg-name strong {
  color: var(--blue);
  font-weight: 600;
}

.sugg-sets {
  color: var(--paper-dim);
  font-size: 0.72rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sugg-sets:empty {
  display: none;
}

.sep {
  color: var(--line);
  margin: 0 0.35em;
}

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

.filters {
  margin-top: 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.filter-group {
  display: flex;
  align-items: baseline;
  gap: 0.8rem;
}

.filter-label {
  flex: 0 0 auto;
  width: 3.4rem;
  font-size: 0.82rem;
  color: var(--paper-dim);
}

.filter-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.1rem;
}

.toggle-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.88rem;
  color: var(--paper);
  cursor: pointer;
}

.toggle-chip input {
  accent-color: var(--blue);
  cursor: pointer;
}

.toggle-chip .count {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
  color: var(--paper-dim);
}

/* ---- results ---- */

.results {
  margin-top: 2rem;
}

.results.reveal {
  animation: reveal 0.35s ease-out;
}

@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.results-meta {
  margin: 0 0 0.75rem;
  color: var(--paper-dim);
  font-size: 0.8rem;
}

/* ---- offer grid: one tile per shop's own listing, cheapest first, each ---- */
/* showing that shop's own product photo (it varies by printing/foil/edition) */

.offer-list {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.9rem;
}

.offer-row {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
}

.offer-row:hover {
  border-color: var(--blue);
  background: var(--panel-raised);
}

.offer-row:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.offer-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 7;
  background: var(--display);
  overflow: hidden;
}

.offer-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.offer-thumb-empty {
  width: 100%;
  height: 100%;
  display: block;
  background: repeating-linear-gradient(
    135deg,
    var(--line-soft),
    var(--line-soft) 4px,
    transparent 4px,
    transparent 9px
  );
}

.offer-price {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 0.2rem 0.5rem;
  border-radius: 3px;
  background: var(--blue);
  font-family: "IBM Plex Mono", monospace;
  font-weight: 600;
  font-size: 0.95rem;
  color: #ffffff;
  box-shadow: 0 1px 4px rgba(20, 33, 61, 0.25);
}

.offer-info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.7rem 0.8rem 0.8rem;
}

.offer-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--paper);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.offer-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--paper-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* A long shop name truncates; the condition after it never does. */
.offer-shop {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.offer-condition {
  flex: 0 0 auto;
}

.stock-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--mint);
  flex: 0 0 auto;
}

.empty-state,
.loading {
  color: var(--paper-dim);
  padding: 1rem 0;
}

.error-state {
  color: var(--error);
  padding: 1rem 0;
}

.failed-shops-note {
  color: var(--paper-dim);
  font-size: 0.85rem;
  margin: 0.75rem 0 0;
}

@media (prefers-reduced-motion: reduce) {
  .results.reveal {
    animation: none;
  }
}

@media (max-width: 680px) {
  .offer-list {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ---- footer ---- */

.site-footer {
  border-top: 1px solid var(--line);
  margin-top: clamp(3rem, 8vw, 5rem);
  padding-top: 1.5rem;
}

.site-footer-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
}

.site-footer-main strong {
  font-size: 0.98rem;
  color: var(--paper);
}

.site-footer-main p {
  margin: 0.2rem 0 0;
  font-size: 0.82rem;
  color: var(--paper-dim);
}

.site-footer nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 1rem;
}

.footer-link {
  color: var(--blue);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.3rem 0;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 0.25rem;
  transition: text-decoration-color 0.15s ease;
}

.footer-link:hover,
.footer-link:focus-visible {
  text-decoration-color: currentColor;
}

.footer-policy-links {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0 0.6rem;
}

.footer-policy-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--paper-dim);
}

.footer-legal {
  border-top: 1px solid var(--line);
  margin-top: 1.1rem;
  padding-top: 0.9rem;
}

.footer-legal p {
  margin: 0;
  max-width: 60ch;
  font-size: 0.76rem;
  line-height: 1.5;
  color: var(--paper-dim);
}

.footer-legal p + p {
  margin-top: 0.6rem;
}

@media (max-width: 480px) {
  .site-footer-main {
    align-items: stretch;
    flex-direction: column;
  }

  .site-footer nav {
    justify-content: flex-start;
  }

  .wordmark {
    font-size: 1.6rem;
  }

  .game-select {
    flex-wrap: wrap;
  }

  .game-tile {
    flex: 1 1 45%;
  }

  .offer-list {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.6rem;
  }
}
