/* System text with tabular numeric data. The one motion is a short fade-in. */
html {
  background: #fff;
  color: #000;
  font-family: system-ui, sans-serif;
  line-height: 1.5;
}

body {
  margin: 0 auto;
  max-width: 1400px;
  box-sizing: border-box;
  padding: 1rem;
}

a {
  color: #000;
}

header {
  border-bottom: 1px solid #000;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  padding-bottom: 0.5rem;
}

header nav {
  display: flex;
  gap: 1rem;
}

main {
  padding: 1rem 0;
}

footer {
  border-top: 1px solid #000;
  font-size: 0.85em;
  padding-top: 0.5rem;
  text-align: center;
}

table {
  border-collapse: collapse;
  width: 100%;
}

th,
td {
  border: 1px solid #000;
  padding: 0.25rem 0.5rem;
  text-align: left;
}

img {
  vertical-align: middle;
}

input,
button,
select {
  background: #fff;
  border: 1px solid #000;
  color: #000;
  font-family: system-ui, sans-serif;
  padding: 0.25rem 0.5rem;
}

/* A class rule such as `.filters label { display: inline-block }` must not unhide these. */
[hidden] {
  display: none !important;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: no-preference) {
  main {
    animation: fade-in 0.2s ease-out;
  }
}

/* Tables flow at full height: the page scrolls, never a box inside it. */
.table-wrap:focus-visible {
  outline: 2px solid #000;
  outline-offset: 2px;
}

/* The page's main table keeps its header row in view while the page scrolls. */
.list thead th {
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}

/* Horizontal scrollers contain native sticky positioning. JS moves the original
   heading within the full-height table instead; no duplicate controls or scrollbox. */
.table-wrap table.viewport-header thead {
  /* WebKit ignores relative positioning on table row groups. Sticky with no
     inset creates the stacking context above body cells without moving the head. */
  position: sticky;
  top: auto;
  z-index: 2;
  background: #fff;
}
.table-wrap table.viewport-header tbody td:first-child {
  z-index: 1;
}
.table-wrap table.viewport-header thead th,
body:has(.jump) .table-wrap table.viewport-header thead th {
  position: sticky;
  top: auto;
}

/* Section jump bar: sticky at the top of the viewport so any section is one click away. */
.jump {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  gap: 1rem;
  align-items: center;
  box-sizing: border-box;
  min-height: 2.5rem;
  padding: 0 0.5rem;
  overflow-x: auto;
  white-space: nowrap;
  background: #fff;
  border: 1px solid #000;
}

/* Keep a sticky table header below the jump bar when both are on the page. */
body:has(.jump) .list thead th {
  top: 2.5rem;
}

/* Anchored headings must not land under the jump bar. */
[id] {
  scroll-margin-top: 3rem;
}

/* "Show all N rows" toggle (no JS): rows past the tenth stay hidden until ticked. */
.show-all {
  display: block;
  margin: 0.25rem 0;
}

.show-all:not(:has(input:checked)) + .table-wrap tbody tr:nth-child(n + 11) {
  display: none;
}

/* Hero page: collapsed detail tables and the summary block's top/bottom lists. */
.section-table > summary {
  cursor: pointer;
  margin: 0.25rem 0;
}

.standouts dt {
  font-weight: bold;
  margin-top: 0.5rem;
}

.standouts dd {
  margin-left: 1rem;
}

.standouts dd p {
  margin: 0.15rem 0;
}

/* "Show N rows with too little data" toggle (no JS): those rows stay hidden until ticked. */
.low-toggle {
  display: block;
  margin: 0.25rem 0;
}

.low-toggle:not(:has(input:checked)) ~ .table-wrap tr.low-sample {
  display: none;
}

/* Phones: wide tables scroll sideways only (no height cap) and keep the name column pinned. */
@media (max-width: 40rem) {
  .table-wrap {
    overflow-x: auto;
  }

  .table-wrap th:first-child,
  .table-wrap td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: #fff;
    box-shadow: 1px 0 0 #000;
  }
}

.filters label {
  display: inline-block;
  max-width: 100%;
  vertical-align: middle;
  margin-bottom: 0.25rem;
}

.filters select {
  max-width: 100%;
}

/* Fixed width so the slider does not jump while the readout changes. */
.pick-out {
  display: inline-block;
  min-width: 5ch; /* fits "100.0" */
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  accent-color: #000;
  vertical-align: middle;
}

.build-selectors, .build-grid, .selected-purchases, .filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.build-selectors { align-items: start; }
.build-selectors label { display: grid; gap: 0.2rem; }
.build-selectors input { max-width: 100%; min-width: 0; box-sizing: border-box; }
.build-selectors details { border: 1px solid #000; padding: 0.4rem; max-width: 100%; }
.build-selectors details[open] { flex-basis: 100%; }
.build-selectors details[open] label { display: inline-grid; }
.build-card { border: 1px solid #000; padding: 0.65rem; flex: 1 1 16rem; min-width: 0; overflow-wrap: anywhere; }
.build-card h3, .build-card p { margin: 0.3rem 0; }
.filter-chips, .selected-purchases { padding-left: 1.5rem; }
.filter-chips li, .selected-purchases li { border: 1px solid #000; padding: 0.3rem; }
header nav { flex-wrap: wrap; }
@media (max-width: 40rem) {
  .build-selectors > label, .build-selectors > details { width: 100%; }
}

.build-selectors details { box-sizing: border-box; }
.build-selectors details[open] label { grid-template-columns: minmax(0, 1fr); }
.build-selectors select { min-width: 0; max-width: 100%; }

.num {
  font-family: ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* Contrast against white: green 7.1:1; red 6.5:1 (WCAG AA). Signs stay visible. */
.positive { color: #166534; }
.negative { color: #b91c1c; }

.name-icon {
  width: 32px;
  height: 32px;
  object-fit: contain;
  margin-inline-end: 0.4rem;
}

/* Native buttons retain keyboard/focus behavior while fitting sticky headers. */
.table-sort {
  font: inherit;
  font-weight: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  padding: 0;
  text-align: inherit;
  cursor: pointer;
}
.table-sort:hover { text-decoration: underline; }
.table-sort:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }
.sort-arrow { white-space: nowrap; }

/* Builds landing: wrapping hero picker grid; tiles are plain links. */
.hero-grid {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: 0.5rem;
}
.hero-grid li { min-width: 0; }
.hero-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  height: 100%;
  box-sizing: border-box;
  padding: 0.6rem 0.4rem;
  border: 1px solid #000;
  text-align: center;
  overflow-wrap: anywhere;
}
.hero-tile:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
.hero-tile-name { display: flex; flex-direction: column; align-items: center; }
.hero-tile .name-icon { width: 48px; height: 48px; margin: 0 0 0.3rem; }
.hero-tile-games { font-variant-numeric: tabular-nums; }
.hero-find input { max-width: 100%; min-width: 0; box-sizing: border-box; }

/* Six adjacent, compact purchase columns; only horizontal overflow, no scrollboxes. */
.exact-prefix { display:grid; grid-template-columns:repeat(6,minmax(0,1fr)); gap:.75rem; align-items:start; }
.exact-prefix section { min-width:0; }
.exact-prefix section > p { min-height:3em; }
/* Keep each row inside its purchase column: a name followed by two pairs of
   metrics. Native table headers/buttons and raw sort cells remain available. */
.exact-prefix table { display:block; font-size:.85rem; }
.exact-prefix thead, .exact-prefix tbody { display:block; }
.exact-prefix thead tr { display:flex; flex-wrap:wrap; }
.exact-prefix thead { position:sticky; top:2.5rem; z-index:1; background:#fff; }
.exact-prefix thead th { flex:1 1 auto; position:static; }
.exact-prefix tbody tr { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); }
.exact-prefix tbody td:first-child { grid-column:1 / -1; position:static; }
.exact-prefix td[data-label]::before { content:attr(data-label); display:block; font:normal .75rem system-ui,sans-serif; }
.exact-prefix td { padding:.4rem; overflow-wrap:anywhere; }
.exact-prefix td small { display:block; max-width:18rem; }
.exact-prefix .chosen { outline:2px solid #166534; outline-offset:-2px; }
.exact-prefix .chosen td { background:#ecfdf5; }
.exact-prefix .chosen a { font-weight:700; }
.exact-prefix .show-all:not(:has(input:checked)) + .table-wrap tbody tr.chosen { display:grid; }

/* Chosen items remain one compact horizontal strip on phones. */
.exact-prefix-chips { flex-wrap:nowrap; overflow-x:auto; list-style:none; padding:.25rem 0; }
.exact-prefix-chips li { flex:0 0 auto; max-width:18rem; }

/* Desktop keeps all six purchase positions in view and allows viewport-sticky
   headers. Narrow screens retain native horizontal scrolling at readable widths. */
@media (max-width:70rem) {
  .exact-prefix { grid-template-columns:repeat(6,minmax(19rem,1fr)); overflow-x:auto; }
}
