:root {
  color-scheme: dark;
  /* Atom One Dark — soft warm blue-grey base + iconic #61AFEF accent */
  --bg: #1B1F25;
  --surface: #21252B;
  --surface-2: #282C34;
  --surface-3: #2C313A;
  --row-alt: #242830;
  --ink: #D7DAE0;
  --muted: #7F8896;
  --line: #2F3540;
  --input-bg: #15181D;
  --accent: #61AFEF;
  --accent-strong: #4A9FE6;
  --accent-2: #E5C07B;
  --danger: #E06C75;
  --info: #56B6C2;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.42);
  --shadow-hover: 0 24px 60px rgba(0, 0, 0, 0.55);
  --radius: 10px;
  --radius-sm: 6px;
  --font: "Manrope", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body[data-theme="light"] {
  color-scheme: light;
  /* Light theme: gray body anchors a white, airy panel.
     Inside the panel, every elevated surface (header, hover, zebra, caption)
     is a subtle off-white — *lighter* than the body bg, *barely* tinted off the
     panel. Topbar buttons sit on the gray body and are also off-white pills
     (lighter than body), not darker — keeps the whole UI feeling "light". */
  --bg: #DEE2EA;
  --surface: #FFFFFF;
  --surface-2: #F4F6FA;
  --surface-3: #ECEFF5;
  --row-alt: #FAFBFD;
  --ink: #383A42;
  --muted: #6B7280;
  --line: #E5E8EE;
  --input-bg: #E2E7F0;
  --accent: #3A6EE8;
  --accent-strong: #2754C9;
  --accent-2: #B57309;
  --danger: #E45649;
  --info: #0184BC;
  --shadow: 0 10px 30px rgba(36, 43, 64, 0.10);
  --shadow-hover: 0 22px 50px rgba(36, 43, 64, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: geometricPrecision;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.app {
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  width: 100%;
  padding: 16px 20px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(18px);
}

.title-block {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
}

.app-icon {
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  border-radius: 22%; /* iOS-app rounded square */
  object-fit: cover;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
}

.title-text {
  min-width: 0;
}

h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.title-block p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.title-block p.stale-notice {
  color: var(--accent-2);
  font-weight: 600;
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 600;
  font-size: 13px;
  transition: background-color 140ms ease, color 140ms ease;
}

.button:hover {
  background: var(--surface-3);
  color: var(--accent);
}

.button.full {
  width: 100%;
  margin-top: 10px;
}

.button.primary {
  background: var(--accent);
  color: var(--surface);
}

.button.primary:hover {
  background: var(--accent-strong);
  color: var(--surface);
}

.button svg,
.icon-action svg,
.filter-button svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

/* 3-state segmented control: To play / All / Played */
.view-mode {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}

.view-mode-btn {
  background: transparent;
  border: 0;
  padding: 5px 12px;
  min-height: 30px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-radius: 4px;
  transition: background-color 140ms ease, color 140ms ease;
}

.view-mode-btn:hover {
  color: var(--ink);
}

.view-mode-btn.is-active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

main {
  width: 100%;
  min-width: 0;
  min-height: 0;
  max-width: 100vw;
  padding: 4px 16px 16px;
  overflow: hidden;
  display: grid;
  /* Active-filter chip bar (auto, collapses to nothing when hidden) above the
     scrollable table panel (takes the rest). */
  grid-template-rows: auto minmax(0, 1fr);
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 2px 2px 8px;
}

.active-filters[hidden] {
  display: none;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 2px 6px 2px 10px;
  border: 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}

.filter-chip:hover {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

.filter-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.filter-chip-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  font-size: 14px;
  line-height: 1;
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

.filter-chip:hover .filter-chip-x {
  background: color-mix(in srgb, var(--accent) 34%, transparent);
}

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

.table-panel {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}

.table-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 6px 14px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  /* The caption ("Showing N of M") is a fixed summary, not table data, so it sits
     in its OWN panel grid row (.table-panel: minmax(0,1fr) auto), BELOW the scroll
     container — it never scrolls, vertically or horizontally. The panel's
     border-radius + overflow:hidden clip its bottom corners. On mobile the panel
     is display:block, so it simply flows after the card list. */
}

.table-wrap {
  width: 100%;
  height: 100%;
  min-height: 0;
  max-width: 100%;
  overflow-y: auto;
  overflow-x: hidden;
}

table {
  width: 100%;
  min-width: 0;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

/* Below 1350px the table is too cramped for everything: the verdict column
   goes first (it's the most text-heavy and the least essential), and the rest
   of the table gets horizontal scroll so columns stay readable instead of
   squashing. Below 720px the mobile card layout takes over. */
@media (max-width: 1349.98px) and (min-width: 720.02px) {
  .table-wrap {
    overflow-x: auto;
  }

  .table-wrap table {
    min-width: 1100px;
  }

  th.verdict-col,
  .verdict-cell {
    display: none;
  }
}

th,
td {
  padding: 10px 10px;
  vertical-align: middle;
  text-align: left;
  overflow-wrap: break-word;
  word-break: normal;
}

th {
  position: sticky;
  top: 0;
  /* Above scrolling content (rows are z-index 1) but BELOW a hovered row
     (z-index 20): the desktop image-zoom on hover should paint OVER the sticky
     column header. In the normal (non-hover) state the header stays on top.
     (Mobile is the opposite — there the header is always topmost via the
     .top-actions / thead z-index:60/59 rules in the mobile media query, and
     the image-zoom is disabled anyway.) */
  z-index: 10;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  white-space: nowrap;
}

tbody tr {
  background: var(--surface);
  transition: background-color 100ms ease;
  /* position:relative WITHOUT z-index — does not create a stacking context, so
     the row never lifts above the sticky header. Only the image-cell does that
     (on hover), via its own z-index. The header always covers a hovered row. */
  position: relative;
}

tbody tr:nth-child(even) {
  background: var(--row-alt);
}

tbody tr:hover {
  background: var(--surface-3);
  /* No z-index here on purpose: a row hover must NOT lift the row above the
     sticky header. Only the zoomed image is the exception (.image-cell:hover,
     z-index 50 > th 10). */
}

/* Played rows are dimmed only in the "All" view (where they share space with
   unplayed). In the "Played" view it's literally the played-only list — full
   opacity. In "To play" they're filtered out entirely.

   Dim the CELLS, not the <tr>. opacity on the <tr> would make it a stacking
   context, which traps the image-zoom inside the row — so a played game's
   hover behaved differently from an active one (zoom couldn't escape the
   header/footer). Per-cell opacity keeps the <tr> context-free, so
   .image-cell:hover (z-index 50) escapes identically for played and active
   rows. Desktop only — mobile dims the whole card (no zoom there to trap), see
   the mobile media query. */
@media (min-width: 720.02px) {
  body[data-view-mode="all"] tbody tr.is-played td {
    opacity: 0.55;
  }
}

.th-control {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  min-height: 32px;
  padding: 0 6px;
  border-radius: var(--radius-sm);
  /* Very subtle "this is a field" tint — barely lighter than the th strip on
     dark, barely darker on light. Just enough to read as interactive, not loud. */
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  transition: background-color 140ms ease;
}

.th-control:hover {
  background: color-mix(in srgb, var(--ink) 12%, transparent);
}

.th-sort {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  cursor: pointer;
}

.th-sort:hover .th-label {
  color: var(--accent);
}

.filter-button {
  width: 18px;
  height: 22px;
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 18px;
  border: 0;
  padding: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  overflow: hidden;
  transition: color 140ms ease, background-color 140ms ease;
}

.filter-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.filter-button svg,
.filter-button svg * {
  pointer-events: none;
}

.th-control:hover:not(:has(.th-sort:hover)) .filter-button {
  color: var(--accent);
  background-color: color-mix(in srgb, var(--accent) 14%, transparent);
}

.th-control.has-active-filter {
  background-color: color-mix(in srgb, var(--accent) 12%, transparent);
}

.th-control.has-active-filter .filter-button {
  color: var(--accent);
}

/* Active sort column: a thin underline at the bottom of the whole th cell
   (direction isn't visualized — only "this column is the sort key"). */
th.is-active-sort {
  box-shadow: inset 0 -2px 0 0 var(--accent);
}

.th-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  min-width: 0;
  overflow: visible;
}

/* Column widths — labels + chevron must always fit. */
.image-col,
.image-cell {
  width: 120px;
}

th:nth-child(2),
.title-cell {
  width: 10%;
}

th:nth-child(3) {
  width: 78px;
}

th:nth-child(4) {
  width: 13%;
}

th:nth-child(5) {
  width: 96px;
}

th:nth-child(6) {
  width: 96px;
}

th:nth-child(7) {
  width: 100px;
}

th:nth-child(8) {
  width: 90px;
}

th:nth-child(9) {
  width: 116px;
}

th:nth-child(10) {
  width: 82px;
}

th:nth-child(11),
.verdict-cell {
  width: auto;
  min-width: 180px;
}

th:nth-child(12),
.link-col {
  width: 56px;
}

th:nth-child(13),
.action-col {
  width: 52px;
}

.image-cell {
  position: relative;
  z-index: 1;
}

.image-cell a {
  display: block;
  position: relative; /* positioning context for the hover-preview overlay */
}

/* Hover preview overlay (microtrailer <video> or screenshot crossfade) shares the
   thumbnail box and scales identically to the static-image hover zoom, so it sits
   exactly on top of it. pointer-events:none lets clicks fall through to the store
   link. Hidden (opacity 0) until JS adds .preview-on once playback/crossfade is up,
   so the static header is always the visible floor — no blank frame, graceful
   fallback on any error. */
.image-cell video.preview,
.image-cell .preview-shots {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-sm);
  object-fit: cover;
  overflow: hidden;
  opacity: 0;
  transform: scale(4);
  transform-origin: left center;
  box-shadow: var(--shadow-hover);
  z-index: 50;
  pointer-events: none;
  transition: opacity 300ms ease;
}

.image-cell video.preview {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--surface-2);
}

.image-cell .preview-shots img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 450ms ease;
}

.image-cell .preview-shots img.is-on {
  opacity: 1;
}

.image-cell.preview-on video.preview,
.image-cell.preview-on .preview-shots {
  opacity: 1;
}

.image-cell img {
  display: block;
  width: 100px;
  aspect-ratio: 460 / 215;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  transition: transform 200ms ease, box-shadow 200ms ease;
  transform-origin: left center;
}

.image-cell:hover {
  z-index: 50;
}

.image-cell:hover img {
  transform: scale(4);
  box-shadow: var(--shadow-hover);
  position: relative;
  z-index: 50;
}

.title-cell {
  min-width: 0;
}

.game-link {
  display: inline-block;
  color: var(--ink);
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
  overflow-wrap: anywhere;
  transition: color 140ms ease;
}

.game-link:hover {
  color: var(--accent);
}

.price-link {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
  transition: color 140ms ease;
}

.price-link:hover {
  color: var(--accent-strong);
}

.number-cell {
  font-weight: 600;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
  color: var(--ink);
}

/* Rating cell: the Wilson score big, with a muted "<reviews> · <Steam %>"
   sub-caption beneath it (right-aligned, inherited from .number-cell). */
.wilson-score {
  display: block;
  font-weight: 600;
  font-size: 14px;
  line-height: 1.1;
}

.rating-sub {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-width: 0;
}

.tag,
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 9px;
  border: 0;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge.good {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
}

.badge.info {
  background: color-mix(in srgb, var(--info) 18%, transparent);
  color: var(--info);
}

.badge.warn {
  background: color-mix(in srgb, var(--accent-2) 22%, transparent);
  color: var(--accent-2);
}

.badge.bad {
  background: color-mix(in srgb, var(--danger) 20%, transparent);
  color: var(--danger);
}

.badge.muted {
  background: var(--surface-3);
  color: var(--muted);
}

.tag.tier {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.3px;
}

.badge.ending {
  font-weight: 600;
}

.detail {
  display: inline-block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.verdict-col,
.verdict-cell {
  min-width: 0;
  max-width: none;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
}

.youtube-link {
  width: 34px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-decoration: none;
  cursor: pointer;
  transition: transform 140ms ease, filter 140ms ease;
}

.youtube-link .yt-icon {
  width: 26px;
  height: 26px;
}

.youtube-link .yt-icon-body,
.youtube-link .yt-icon-play {
  transition: fill 160ms ease;
}

.youtube-link .yt-icon-body {
  fill: var(--muted);
}

.youtube-link .yt-icon-play {
  fill: var(--surface);
}

/* Light up the icon when the row is hovered (or the icon itself). */
tbody tr:hover .youtube-link .yt-icon-body {
  fill: #FF0000;
}

tbody tr:hover .youtube-link .yt-icon-play {
  fill: #FFFFFF;
}

.youtube-link:hover {
  transform: scale(1.08);
  filter: drop-shadow(0 2px 6px rgba(255, 0, 0, 0.45));
}

.youtube-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.action-col,
.action-cell {
  text-align: center;
}

.icon-action {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* Strip the native iOS Safari button chrome (a stray rounded ring/outline
     and box-shadow it draws around bare buttons). Desktop is unaffected since
     the button already has no border or background. */
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  box-shadow: none;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease;
}

.icon-action:hover {
  background: var(--surface-3);
  color: var(--accent);
}

/* Played-toggle: satisfying YouTube-like check.
   - Off state: outlined gray circle.
   - On state: green-filled circle (#22C55E) with a white check.
   - Activation animation (~720ms):
     1. Ring fills green + scale punch with overshoot.
     2. Tick is drawn in two pen-like strokes — first the short stroke
        going down-right, then a brief pause, then the longer up-right
        stroke. Each segment uses stroke-dashoffset 1 → 0.
     3. Eight green particles burst radially out of the icon. */
.played-toggle {
  position: relative;
  overflow: visible;
}

.played-toggle .check-icon {
  width: 22px;
  height: 22px;
  overflow: visible;
  position: relative;
  z-index: 2;
}

.played-toggle .check-icon-ring {
  fill: transparent;
  transition: fill 260ms cubic-bezier(0.4, 0, 0.2, 1),
              stroke 260ms cubic-bezier(0.4, 0, 0.2, 1);
}

.played-toggle .check-icon-tick {
  stroke: #FFFFFF;
  /* Linear easing keeps the pen velocity constant — when the second stroke
     picks up right after the first ends, the eye reads it as one continuous
     motion that just changes direction, with no decel/accel pause. */
  transition: stroke-dashoffset 180ms linear;
}

.played-toggle[data-played="true"] .check-icon-ring {
  fill: #22C55E;
  stroke: #22C55E;
}

.played-toggle[data-played="true"] .check-icon-tick-down {
  stroke-dashoffset: 0;
  transition-delay: 150ms;
  transition-duration: 120ms;
}

.played-toggle[data-played="true"] .check-icon-tick-up {
  stroke-dashoffset: 0;
  transition-delay: 270ms;   /* exactly when the down stroke finishes */
  transition-duration: 210ms;
}

/* Scale punch on activation only (uncheck stays calm). */
.played-toggle.is-toggling .check-icon {
  animation: played-punch 620ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes played-punch {
  0%   { transform: scale(1); }
  18%  { transform: scale(1.32); }
  42%  { transform: scale(0.92); }
  100% { transform: scale(1); }
}

/* Particle burst — 8 dots fly radially out from the icon center. */
.particle-burst {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.particle {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #4ADE80;
  opacity: 0;
  transform: translate(-50%, -50%);
}

.particle:nth-child(odd)  { background: #22C55E; }
.particle:nth-child(even) { background: #86EFAC; width: 3px; height: 3px; }

.played-toggle.is-toggling .particle {
  animation: particle-fly 720ms cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}

.played-toggle.is-toggling .particle:nth-child(even) {
  animation-duration: 640ms;
  animation-delay: 40ms;
}

@keyframes particle-fly {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(var(--angle)) translateY(-2px) scale(0.4);
  }
  18% {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(var(--angle)) translateY(-14px) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(var(--angle)) translateY(-30px) scale(0.4);
  }
}

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

.filter-popover {
  position: fixed;
  z-index: 100;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-hover);
}

/* The option list (.checkbox-list) gets a JS-computed max-height that reserves
   room for the footer below it, so the buttons are always visible and the
   popover grows with content up to the viewport. */
.popover-footer {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.popover-footer .button {
  flex: 1;
}

.popover-title {
  margin-bottom: 10px;
  font-weight: 700;
  font-size: 13px;
}

/* Second range heading inside a multi-control popover (the Rating popover's
   "Reviews" section sits below the Steam % grid). */
.popover-subhead {
  margin: 14px 0 8px;
  font-weight: 700;
  font-size: 13px;
}

.filter-input {
  width: 100%;
  min-height: 36px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  color: var(--ink);
  padding: 8px 12px;
  outline: 0;
  font-size: 13px;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 8%, transparent);
  transition: background-color 140ms ease, box-shadow 140ms ease;
}

.filter-input:focus {
  background: var(--input-bg);
  box-shadow: inset 0 0 0 1px var(--accent), 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent);
}

.range-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.checkbox-list {
  display: grid;
  gap: 6px;
  overflow: auto;       /* max-height set inline by openFilter (viewport-aware) */
  padding-right: 4px;
}

.check-row {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 8px;
  align-items: center;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
}

.check-row.with-subtitle {
  align-items: flex-start;
  padding: 4px 0;
}

.check-row.with-subtitle input {
  margin-top: 2px;
}

.check-row-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.filter-subtitle {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
  line-height: 1.35;
}

.filter-divider {
  margin: 8px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.facet-section {
  display: grid;
  gap: 5px;
}

.facet-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 1px;
}

/* Right-aligned (count side) "All / None" toggle that selects/clears every tag
   in this axis. */
.facet-all {
  -webkit-appearance: none;
  appearance: none;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  letter-spacing: inherit;
  cursor: pointer;
}

.facet-all:hover {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}

.check-row.faceted {
  grid-template-columns: 18px 1fr auto;
  align-items: center;
}

.check-row.faceted .check-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.check-count {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.check-row.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.check-row.disabled input {
  cursor: not-allowed;
}

.check-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.video-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-modal[hidden] {
  display: none;
}

/* Pre-buffer state: the modal is in the DOM and the iframe is laid out at full
   size (so the browser actually buffers/decodes the muted video) but the user
   sees and hears nothing. We hide the backdrop + close button, make the frame
   invisible + click-through, and skip the pop animation. On the real click the
   [data-prebuffer] attribute is removed and the frame becomes visible instantly
   with the already-buffered video. opacity:0 (not visibility:hidden) keeps the
   iframe rendering; pointer-events:none lets clicks pass through to the row. */
.video-modal[data-prebuffer] {
  pointer-events: none;
}
.video-modal[data-prebuffer] .video-modal-backdrop,
.video-modal[data-prebuffer] .video-modal-close {
  opacity: 0;
}
.video-modal[data-prebuffer] .video-modal-frame {
  opacity: 0;
  animation: none;
}

.video-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(6px);
  cursor: pointer;
}

.video-modal-frame {
  position: relative;
  width: min(92vw, 1100px);
  aspect-ratio: 16 / 9;
  background-color: #000;
  background-size: cover;
  background-position: center;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  animation: video-pop 160ms ease-out;
}

@keyframes video-pop {
  from {
    transform: scale(0.96);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .video-modal-frame { animation: none; }
}

.video-modal-close {
  position: absolute;
  top: -44px;
  right: 0;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #FFFFFF;
  cursor: pointer;
  transition: background-color 140ms ease;
}

.video-modal-close:hover {
  background: rgba(255, 255, 255, 0.28);
}

.video-modal-close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.video-modal-close svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
}

.video-modal iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

@media (max-width: 720px) {
  .video-modal-close {
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.65);
  }
  .video-modal-frame {
    width: 100vw;
    border-radius: 0;
  }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 120;
  transform: translateX(-50%) translateY(18px);
  opacity: 0;
  pointer-events: none;
  border-radius: var(--radius);
  background: var(--surface-3);
  color: var(--ink);
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: var(--shadow-hover);
  transition: opacity 140ms ease, transform 140ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─────────────────────────────────────────────
   Mobile (< 720px) — table → card grid
   ───────────────────────────────────────────── */
@media (max-width: 720px) {
  /* Let the document flow to its natural height and scroll via the viewport
     (so window.scrollY drives the title-collapse). The global rule pins
     html/body to 100% + overflow:hidden for the desktop fixed-layout. */
  html,
  body {
    height: auto;
    /* overflow-x: clip (not hidden) — `hidden` forces overflow-y to `auto`,
       which turns html into a scroll container and breaks position:sticky on
       the topbar. `clip` trims sideways overflow without creating a scroller,
       so the document scrolls via the viewport and sticky works. */
    overflow-x: clip;
    overflow-y: visible;
  }

  .app {
    /* Block (not grid) on mobile: a grid item can only stick within its own
       auto-sized track, so a grid topbar scrolls away. As a block child it
       sticks against the tall document and stays pinned. */
    display: block;
    height: auto;
    min-height: 100vh;
  }

  /* display:contents removes the topbar box and promotes the title-block +
     top-actions into the .app block flow. That lets the title scroll away as
     ordinary content (constant document height → no jump), while the controls
     bar below it is independently sticky. */
  .topbar {
    display: contents;
  }

  .title-block {
    padding: 12px 12px 8px;
  }

  /* Controls bar: its own sticky strip pinned to the top. view-mode on the
     left, Reset + theme pushed to the right edge (margin-left:auto on Reset). */
  .top-actions {
    position: sticky;
    top: 0;
    /* Header sits above ALL content (cards hover at z-index 20, image zoom at
       50) — nothing may paint over it. Stays below the filter popover (100)
       and the video modal (200), which are intentional overlays. */
    z-index: 60;
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    align-items: center;
    padding: 8px 12px;
    background: color-mix(in srgb, var(--bg) 94%, transparent);
    backdrop-filter: blur(12px);
  }

  .top-actions .view-mode {
    min-width: 0;
    flex: 0 1 auto;
  }

  /* Push Reset (and the theme button after it) to the right edge. */
  #resetFiltersButton {
    margin-left: auto;
  }

  /* Controls must fit on one line near phone widths: drop the Reset "filters"
     word, theme = icon only. */
  .btn-label-extra {
    display: none;
  }

  .icon-only-mobile .btn-label {
    display: none;
  }

  .icon-only-mobile {
    padding: 0 10px;
  }

  h1 {
    font-size: 22px;
  }

  main {
    padding: 4px 12px 16px;
    overflow: visible;
  }

  .table-panel {
    height: auto;
    background: transparent;
    box-shadow: none;
    border-radius: 0;
    display: block;
    /* Must be visible (desktop sets it to hidden) — otherwise it becomes a
       scroll container and the sticky filter strip sticks inside it / scrolls
       away instead of pinning to the viewport. */
    overflow: visible;
  }

  .table-footer {
    padding: 8px 4px 0;
    background: transparent;
    justify-content: flex-start;
  }

  .table-wrap {
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr {
    display: block;
  }

  /* Horizontally-scrollable filter strip; stays pinned right under the
     (collapsing) topbar so filters are reachable at any scroll position. */
  thead {
    position: sticky;
    top: var(--controls-h, 52px);
    /* Just under the controls bar (60) but still above all content, so a
       hovered card (z-index 20) can never paint over the filter strip. */
    z-index: 59;
    /* Same translucent frosted backdrop as the controls bar — together they
       read as one monolithic blurred header, not a solid grey block. */
    background: color-mix(in srgb, var(--bg) 94%, transparent);
    backdrop-filter: blur(12px);
    margin: 0 -12px;
    padding: 8px 12px;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    scrollbar-width: thin;
    display: block;
  }

  /* The active-sort underline marks a table column — meaningless in the card
     view's horizontal chip strip. Drop it. */
  th.is-active-sort {
    box-shadow: none;
  }

  thead tr {
    display: inline-flex;
    gap: 6px;
  }

  thead th {
    position: static;
    display: inline-block;
    width: auto;
    min-width: auto;
    padding: 0;
    background: transparent;
  }

  thead th.image-col,
  thead th.verdict-col,
  thead th.link-col,
  thead th.action-col {
    display: none;
  }

  thead .th-control {
    background: var(--surface-2);
    border-radius: 999px;
    padding: 4px 10px;
    min-height: 34px;
    width: auto;
  }

  tbody {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-top: 12px;
  }

  /* Each row becomes a card. Use flex-wrap so children flow naturally
     instead of stacking on top of each other (the previous grid-area
     attempt put 8 cells in the same grid cell). */
  tbody tr {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 8px;
    padding: 12px;
    border-radius: var(--radius);
    background: var(--surface) !important;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
  }

  body[data-theme="light"] tbody tr {
    box-shadow: 0 2px 10px rgba(36, 43, 64, 0.06);
  }

  /* The card box-shadow fades into nothing at the very bottom of the list, so
     the last card has no delineated bottom edge. Add an explicit divider using
     the same row-separator token desktop rows use. */
  tbody tr:last-child {
    border-bottom: 1px solid var(--line);
  }

  tbody tr.is-played {
    opacity: 0.6;
  }

  td {
    padding: 0;
    background: transparent !important;
    overflow-wrap: normal;
    word-break: normal;
  }

  /* Order: image (1), title (2), meta-chips (3-7), genres (8), ending (9),
     oneCopy (10), verdict (11), actions (12-13). Use order + flex-basis. */
  td.image-cell {
    order: 1;
    flex: 1 0 100%;
    width: 100%;
  }

  td.image-cell img {
    width: 100%;
    height: auto; /* let aspect-ratio compute the height; the HTML height="47" attr
                     (a presentational hint with no CSS height to override it) was
                     pinning the image to a flat 47px strip on mobile */
    aspect-ratio: 460 / 215;
    transform: none !important;
    box-shadow: none !important;
  }

  .image-cell:hover {
    z-index: auto;
  }

  .image-cell:hover img {
    transform: none !important;
    box-shadow: none !important;
  }

  /* Touch has no hover: the preview auto-plays on the card the user is most likely
     looking at (centred in the viewport — see mobilePreview in app.js). So the
     overlay video/screenshots fill the full-width image box at its real size, NOT
     the desktop scale(4) zoom (which would balloon off the card). */
  .image-cell video.preview,
  .image-cell .preview-shots {
    transform: none !important;
    box-shadow: none !important;
    border-radius: var(--radius-sm);
    z-index: 1;
  }

  td.title-cell {
    order: 2;
    flex: 1 0 100%;
    min-width: 0;
  }

  td.title-cell .game-link {
    display: block;
    font-size: 17px;
    line-height: 1.25;
    word-break: normal;
    overflow-wrap: break-word;
  }

  /* Numeric chip row: year/rating/players/hours/price */
  tr td.number-cell {
    flex: 0 0 auto;
    width: auto;
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
    padding: 4px 10px;
    background: var(--surface-2);
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    text-align: left;
    color: var(--ink);
  }

  tr td:nth-child(3) { order: 3; }
  tr td:nth-child(6) { order: 4; }
  tr td:nth-child(7) { order: 5; }
  tr td:nth-child(8) { order: 6; }
  tr td:nth-child(10) { order: 7; }

  tr td:nth-child(3)::before  { content: "Year";    color: var(--muted); font-weight: 500; }
  tr td:nth-child(6)::before  { content: "★";       color: var(--accent-2); font-weight: 700; }
  tr td:nth-child(7)::before  { content: "Players"; color: var(--muted); font-weight: 500; }
  tr td:nth-child(8)::before  { content: "Hours";   color: var(--muted); font-weight: 500; }
  tr td:nth-child(10)::before { content: "Price";   color: var(--muted); font-weight: 500; }

  tr td:nth-child(10) .price-link {
    color: var(--accent);
  }

  /* Genres + ending + oneCopy in a flex row (full width, wraps) */
  tr td:nth-child(4) { order: 8; flex: 1 0 100%; }
  tr td:nth-child(5) { order: 9; flex: 0 0 auto; }
  tr td:nth-child(9) { order: 10; flex: 0 0 auto; }

  tr td:nth-child(4) .tag-list {
    gap: 4px;
  }

  td.verdict-cell {
    order: 11;
    flex: 1 0 100%;
    min-width: 0;
    margin-top: 4px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--muted);
  }

  /* Action row: YouTube + hide button, full width with space-between */
  tr td:nth-child(12),
  tr td:nth-child(13) {
    order: 12;
  }

  tr td:nth-child(12) {
    flex: 1 0 auto;
  }

  tr td:nth-child(13) {
    flex: 0 0 auto;
    margin-left: auto;
  }

  td.action-cell {
    text-align: right;
  }

  .youtube-link {
    width: 44px;
    height: 32px;
  }
  .youtube-link .yt-icon {
    width: 30px;
    height: 30px;
  }
  /* No hover on touch — show the red icon by default on mobile. */
  .youtube-link .yt-icon-body {
    fill: #FF0000;
  }
  .youtube-link .yt-icon-play {
    fill: #FFFFFF;
  }

  .filter-popover {
    left: 12px !important;
    right: 12px;
    width: auto !important;
    max-width: calc(100vw - 24px);
  }
}
