:root {
  --bg: #0d0f1a;
  --panel: #161a2b;
  --panel-2: #1e2338;
  --text: #e8eaf4;
  --muted: #9097b3;
  --accent: #3d7bff;
  --brand-orange: #f2a93b; /* from the logo's d-pad */
  --brand-teal: #47a3a7;   /* from the logo's lens */
  --sale: #ffcc33;
  --ps1: #9aa3b5;
  --ps2: #3d7bff;
  --ps3: #c2c8d6;
  --classic: #2ecc8f;
  --port: #8a7dff;
  --remaster: #ff8a3d;
  --remake: #ff4d6d;
  --radius: 10px;
  --font-body: 'Miranda Sans', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-brand: 'Josefin Sans', system-ui, sans-serif;
  font-family: var(--font-body);
}

* { box-sizing: border-box; }

/* Make the hidden attribute win over display: flex etc. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

.wrap { max-width: 1280px; margin: 0 auto; padding: 0 20px; }

/* Header */
.site-header {
  padding: 36px 0 24px;
  background: linear-gradient(180deg, #1a2150 0%, var(--bg) 100%);
}
/* Phones: title + account on top, search full width below.
   Desktop: title | search | account on one line, using the empty middle. */
.header-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "brand account" "search search";
  align-items: start;
  gap: 16px;
}
.header-row > :first-child { grid-area: brand; }
.header-search { grid-area: search; }
/* Same height as the logo mark, content centered, so Sign in (and the
   search box on desktop) sit on the title's center line. */
.account {
  grid-area: account;
  min-height: clamp(48px, 7vw, 64px);
  display: flex;
  align-items: center;
}
@media (min-width: 960px) {
  .header-row {
    grid-template-columns: auto minmax(260px, 1fr) auto;
    grid-template-areas: "brand search account";
    column-gap: 32px;
  }
  .header-search {
    min-height: clamp(48px, 7vw, 64px);
    display: flex;
    align-items: center;
  }
}
.account-signed-in { display: flex; align-items: center; gap: 10px; }
.account-email { font-size: 0.85rem; color: var(--muted); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 6px;
  padding: 8px 14px;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary:hover { filter: brightness(1.15); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }

/* Sign-in dialog */
.signin {
  background: var(--panel);
  color: var(--text);
  border: 1px solid #2a3050;
  border-radius: var(--radius);
  padding: 24px;
  width: min(420px, 92vw);
}
.signin-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.6);
  z-index: 100;
}
.signin[open] {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  z-index: 101;
  /* Visible, not auto: password managers inject their dropdown inside the
     dialog, and a scroll container would trap it behind a scrollbar. */
  overflow: visible;
}
.signin h2 { margin: 0 0 6px; font-size: 1.2rem; }
.signin-help { margin: 0 0 16px; color: var(--muted); font-size: 0.9rem; }
.signin label { display: block; font-size: 0.85rem; margin-bottom: 4px; }
.signin input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid #2a3050;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}
.signin-status { min-height: 1.2em; font-size: 0.85rem; color: var(--sale); }
.signin-actions { display: flex; justify-content: flex-end; gap: 8px; }

.logo {
  margin: 0;
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: clamp(1.9rem, 4.2vw, 2.8rem); /* Josefin runs small, so a touch bigger */
  letter-spacing: 0;
  line-height: 1;
  display: flex;
  align-items: center;
  gap: 14px;
}
.logo span { color: var(--brand-orange); }
.logo-mark {
  width: clamp(48px, 7vw, 64px);
  height: auto;
  /* The mark's navy ring is close to the page color; a faint teal glow
     keeps its outline readable on the dark header. */
  filter: drop-shadow(0 0 6px rgb(71 163 167 / 0.45));
}
.tagline { margin: 4px 0 0; color: var(--muted); }
.meta { margin: 8px 0 0; font-size: 0.85rem; color: var(--muted); }

/* Controls */
.controls {
  display: grid;
  gap: 14px;
  padding-top: 8px;
  padding-bottom: 8px;
}
#search {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  border-radius: var(--radius);
  border: 1px solid #2a3050;
  background: var(--panel);
  color: var(--text);
}
#search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Console and Type sit side by side when there's room, stack when not. */
.chip-row { display: flex; flex-wrap: wrap; gap: 14px 32px; }
.chips { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chips legend { float: left; margin-right: 6px; color: var(--muted); font-size: 0.85rem; }
.chips label {
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid #2a3050;
  font-size: 0.9rem;
  user-select: none;
}
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips label:has(input:checked) { background: var(--accent); border-color: var(--accent); color: #fff; }
.chips label:has(input:focus-visible) { outline: 2px solid #fff; }

.row { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; }
.toggle, .sort { font-size: 0.9rem; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.sort select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid #2a3050;
  border-radius: 6px;
  padding: 6px 8px;
}
.btn-ghost {
  margin-left: auto;
  background: transparent;
  color: var(--muted);
  border: 1px solid #2a3050;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
}
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }

.results { color: var(--muted); font-size: 0.9rem; }

/* Grid */
.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  /* 280px min fits two store buttons + wishlist/flag side by side. */
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}

/* Each card borrows the grid's rows (subgrid), so title, badges, dates and
   "Available on:" line up across a row no matter how much text each has.
   Rows: image, title, badges, dates, stores. */
.card {
  position: relative;
  display: grid;
  grid-row: span 5;
  grid-template-rows: subgrid;
  row-gap: 8px;
  align-content: start;
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid #22284a;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.card:hover { transform: translateY(-2px); border-color: #34407a; }

/* Platform tint: a faint wash fading down from the top of the card body,
   plus a matching border. Kept subtle on purpose. */
.card.plat-ps    { --plat: 0 112 209; }   /* PlayStation blue */
.card.plat-xbox  { --plat: 16 124 16; }   /* Xbox green */
.card.plat-pc    { --plat: 144 151 179; } /* PC-only: muted grey */
.card.plat-multi { --plat: 232 234 244; } /* multi-platform: soft white */
.card[class*='plat-'] {
  background:
    linear-gradient(180deg, rgb(var(--plat) / 0.13), rgb(var(--plat) / 0.03) 55%, transparent),
    var(--panel);
  border-color: rgb(var(--plat) / 0.35);
}
.card.plat-multi { background: linear-gradient(180deg, rgb(var(--plat) / 0.06), transparent 55%), var(--panel); border-color: rgb(var(--plat) / 0.16); }
.card[class*='plat-']:hover { border-color: rgb(var(--plat) / 0.6); }
.card.is-flagged { opacity: 0.45; }

.card-img {
  aspect-ratio: 1 / 1;
  width: 100%;
  object-fit: cover;
  background: var(--panel-2);
  display: block;
}

/* The wrapper steps aside so its children sit directly in the card's subgrid. */
.card-body { display: contents; }
.card-body > * { padding-inline: 14px; }
.card-title { padding-top: 4px; }
.stores { align-self: start; padding-bottom: 14px; }
.card-title { margin: 0; font-size: 1rem; font-weight: 700; line-height: 1.25; }

/* Form controls don't inherit fonts by default. */
button, input, select { font-family: inherit; }

.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 7px;
  border-radius: 4px;
  color: #0d0f1a;
}
.badge.PS1 { background: var(--ps1); }
.badge.PS2 { background: var(--ps2); color: #fff; }
.badge.PS3 { background: var(--ps3); }
.badge.Classic { background: var(--classic); }
.badge.Port { background: var(--port); color: #fff; }
.badge.Remaster { background: var(--remaster); }
.badge.Remake { background: var(--remake); color: #fff; }
.badge.New { background: var(--sale); }
.badge.Delisted { background: #5a2330; color: #ffb3c0; }
.badge.AtRisk { background: #ff9f43; cursor: help; }

.dates { margin: 0; font-size: 0.8rem; color: var(--muted); display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; }
.dates dt { font-weight: 600; }
.dates dd { margin: 0; }

/* "Available on:" store rows: logo chip + price, whole row is the link. */
.stores { display: grid; gap: 6px; }
.stores-head { display: flex; align-items: center; justify-content: space-between; font-size: 0.8rem; color: var(--muted); }
.card-tools { display: flex; gap: 6px; }
.store-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 4px 10px 4px 4px;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid #2a3050;
  color: var(--text);
  text-decoration: none;
}
.store-row:hover { border-color: var(--muted); }
.store-status { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
/* Delisted: no link, logo desaturated, row dimmed. */
.store-row.is-delisted { opacity: 0.6; border-style: dashed; }
.store-row.is-delisted:hover { border-color: #2a3050; }
.store-row.is-delisted .store-logo { filter: grayscale(1); }
.store-row:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
.store-logo {
  display: grid;
  place-items: center;
  width: 44px;
  height: 34px;
  border-radius: 6px;
  flex: none;
}
.store-ps .store-logo { background: #0070d1; }   /* PlayStation blue */
.store-steam .store-logo { background: #2a475e; } /* Steam slate */
.store-gog .store-logo { background: #86328a; }   /* GOG purple */
.price { font-size: 1.15rem; font-weight: 700; }
.price.on-sale { color: var(--sale); }
.price-was { color: var(--muted); text-decoration: line-through; font-size: 0.85rem; }
.discount {
  background: var(--sale);
  color: #0d0f1a;
  font-weight: 800;
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 4px;
}

.btn-wish, .btn-flag { min-height: 32px; min-width: 36px; }
.btn-flag {
  background: var(--panel-2);
  border: 1px solid #2a3050;
  border-radius: 6px;
  padding: 0 10px;
  cursor: pointer;
  font-size: 1rem;
  filter: grayscale(1);
}
.btn-flag:hover, .is-flagged .btn-flag { filter: none; }

.btn-wish {
  background: var(--panel-2);
  border: 1px solid #2a3050;
  border-radius: 6px;
  padding: 0 10px;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--muted);
}
.btn-wish:hover { color: var(--sale); }
.btn-wish.is-on { color: var(--sale); border-color: var(--sale); }
.card.is-wished { border-color: rgb(255 204 51 / 0.5); }

.unsub { padding-top: 60px; max-width: 560px; }
.unsub a { color: var(--accent); }

.site-footer { padding: 40px 20px; color: var(--muted); font-size: 0.8rem; text-align: center; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--accent);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
}

/* ---------- Filter bar + panel ---------- */
.bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; }
.bar-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.btn-filters {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid #2a3050;
  border-radius: 6px;
  padding: 6px 12px;
  font-weight: 600;
  cursor: pointer;
}
.btn-filters:hover { border-color: var(--muted); }
.filter-count {
  min-width: 1.4em;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  text-align: center;
}

/* Desktop: a dropdown under the Filters button (app.js places it).
   Popovers render in the browser's top layer, above everything. */
.filters-panel {
  position: fixed;
  inset: auto;
  margin: 0;
  width: min(440px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  padding: 18px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid #2a3050;
  border-radius: var(--radius);
  box-shadow: 0 16px 40px rgb(0 0 0 / 0.5);
}
.filters-panel:popover-open { display: grid; gap: 16px; }
.filters-panel::backdrop { background: transparent; }
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel-head h2 { margin: 0; font-size: 1.05rem; }
.panel-close { background: none; border: 0; color: var(--muted); font-size: 1.5rem; line-height: 1; cursor: pointer; padding: 0 4px; }
.panel-close:hover { color: var(--text); }
/* In the panel, each group's label sits on its own line above the chips. */
.filters-panel .chips legend { float: none; display: block; width: 100%; margin: 0 0 8px; padding: 0; }
.panel-foot { display: flex; align-items: center; gap: 10px; border-top: 1px solid #2a3050; padding-top: 14px; }
.panel-foot .btn-primary { margin-left: auto; }
.panel-foot .btn-ghost { margin-left: 0; }
.btn-link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 6px 0; font-weight: 600; }
.btn-link:hover { text-decoration: underline; }

/* Phones: slides up from the bottom as a sheet. */
@media (max-width: 640px) {
  .filters-panel {
    inset: auto 0 0 0;
    width: 100%;
    max-height: 85vh;
    border-radius: 16px 16px 0 0;
    border-bottom: 0;
  }
  .filters-panel::backdrop { background: rgb(0 0 0 / 0.5); }
  .filters-panel:popover-open { animation: sheet-up 0.18s ease-out; }
}
@keyframes sheet-up { from { transform: translateY(30px); opacity: 0.6; } }
@media (prefers-reduced-motion: reduce) { .filters-panel:popover-open { animation: none; } }

/* Active filter pills */
.active-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.active-pills:empty { display: none; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px 4px 12px;
  border-radius: 999px;
  background: rgb(61 123 255 / 0.15);
  border: 1px solid rgb(61 123 255 / 0.5);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}
.pill:hover { background: rgb(61 123 255 / 0.28); }
.pill span[aria-hidden] { font-size: 1.05rem; line-height: 1; color: var(--muted); }
