/* Shared pieces: fields, search, heads, tables, tabs, lists, grids, states. */

.ink {
  color: var(--ink);
}

/* Search matches: ink and a heavier weight, no accent. */
mark {
  background: none;
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}

/* ------------------------------------------------------------------ fields */

.field {
  width: 100%;
  min-width: 0;
  padding: 0.5rem 0;
  border: 0;
  border-bottom: 1px solid var(--control);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-size: 0.95rem;
  line-height: 1.4;
  transition: border-color var(--ease), box-shadow var(--ease);
  -webkit-appearance: none;
  appearance: none;
}

.field::placeholder {
  color: var(--muted);
  opacity: 1;
}

.field:hover {
  border-bottom-color: var(--muted);
}

.field:focus,
.field:focus-visible {
  outline: none;
  border-bottom-color: var(--ink);
  box-shadow: 0 1px 0 var(--ink);
}

.field[aria-invalid="true"] {
  border-bottom-color: var(--accent);
  box-shadow: 0 1px 0 var(--accent);
}

.field::-webkit-search-cancel-button {
  filter: grayscale(1);
}

.field--select {
  width: auto;
  padding-right: 1.25rem;
  background-image: none;
  cursor: pointer;
}

.select {
  position: relative;
}

.select::after {
  content: "";
  position: absolute;
  right: 0.15rem;
  top: 50%;
  width: 6px;
  height: 6px;
  border-right: 1px solid var(--muted);
  border-bottom: 1px solid var(--muted);
  transform: translateY(-75%) rotate(45deg);
  pointer-events: none;
}

.field--select option {
  background: var(--bg);
  color: var(--ink);
}

/* ------------------------------------------------------------------ search (header + pickers) */

.search {
  position: relative;
  width: 10.5rem;
}

.search .field {
  font-size: var(--fs-small);
}

/* In the header the field has no resting underline (it would run parallel to the header hairline);
   its placeholder names it, and hover / focus draw the line. */
.site-header .search .field {
  border-bottom-color: transparent;
}

.site-header .search .field:hover {
  border-bottom-color: var(--control);
}

.site-header .search .field:focus {
  border-bottom-color: var(--ink);
}

/* Header field: a magnifier on the left and a "/" key hint on the right (hover devices, until focused or
   filled) make it read as a field, not as a fifth nav link. */
.search__icon {
  position: absolute;
  left: 0;
  top: 50%;
  width: 14px;
  height: 14px;
  color: var(--muted);
  transform: translateY(-50%);
  pointer-events: none;
}

.search--header .search__input {
  padding-left: 1.4rem;
  padding-right: 1.6rem;
}

.search__key {
  position: absolute;
  right: 0;
  top: 50%;
  min-width: 1.15rem;
  padding: 0 0.3rem;
  border: 1px solid var(--rule);
  color: var(--muted);
  font-size: var(--fs-xs);
  line-height: 1.35;
  text-align: center;
  transform: translateY(-50%);
  pointer-events: none;
}

.search__input:focus ~ .search__key,
.search__input:not(:placeholder-shown) ~ .search__key {
  display: none;
}

@media (hover: none), (max-width: 960px) {
  .search__key {
    display: none;
  }

  .search--header .search__input {
    padding-right: 0;
  }
}

.search__list {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  z-index: 60;
  width: 19rem;
  max-height: min(60vh, 26rem);
  overflow-y: auto;
  border: 1px solid var(--rule);
  background: var(--bg);
}

.search__option {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.9rem;
  border-top: 1px solid var(--rule);
  color: var(--body);
  font-size: 0.95rem;
  cursor: pointer;
}

.search__option:first-child {
  border-top: 0;
}

.search__option[aria-selected="true"] {
  background: var(--bg-hover);
  color: var(--ink);
}

.search__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search__online {
  color: var(--accent);
  font-size: var(--fs-xs);
}

.search__rank {
  color: var(--muted);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}

.search__status {
  padding: 0.7rem 0.9rem;
  color: var(--muted);
  font-size: var(--fs-small);
}

/* Desktop header: the field's box spans the header's height, so the suggestions open with their top
   border lying exactly on the header's bottom hairline (no stepped double rule). */
@media (min-width: 961px) {
  .site-header .header-panel {
    align-self: stretch;
  }

  .site-header .search {
    display: flex;
    align-items: center;
    align-self: stretch;
  }

  .site-header .search__list {
    top: 100%;
  }
}

@media (max-width: 960px) {
  .search {
    width: 100%;
  }

  .search__list {
    left: 0;
    width: auto;
  }

  /* In the mobile menu the field sits in the open panel: show its underline. */
  .site-header .search .field {
    border-bottom-color: var(--control);
  }
}

/* ------------------------------------------------------------------ heads & players */

.head {
  display: inline-block;
  flex: none;
  width: var(--size, 24px);
  height: var(--size, 24px);
  background: none;
  box-shadow: inset 0 0 0 1px var(--rule); /* hidden by the skin; outlines a missing one */
  vertical-align: middle;
}

.head__img {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.who {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  vertical-align: middle;
}

.who__head {
  display: inline-flex;
  flex: none;
}

.who__name {
  color: var(--ink);
  font-weight: 500;
}

.online {
  display: inline-block;
  flex: none;
  width: 6px;
  height: 6px;
  background: var(--accent);
  vertical-align: middle;
}

/* ------------------------------------------------------------------ tables */

.table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.table th {
  padding: 0 0.75rem 0.75rem 0;
  border-bottom: 1px solid var(--rule);
  color: var(--muted);
  font-size: var(--fs-small);
  font-weight: 400;
  text-align: left;
  white-space: nowrap;
}

.table td {
  padding: 0.8rem 0.75rem 0.8rem 0;
  border-bottom: 1px solid var(--rule);
  vertical-align: middle;
}

/* The last column ends exactly on the hairline's right edge. */
.table th:last-child,
.table td:last-child {
  padding-right: 0;
}

.table .c-rank {
  width: 3.5rem;
}

.table td.c-rank {
  color: var(--muted);
}

.table .c-name {
  min-width: 0;
}

.table .c-score {
  width: 7.5rem;
  text-align: right;
  white-space: nowrap;
}

.table td.c-score {
  color: var(--ink);
}

.table .c-pct {
  width: 6rem;
  padding-left: 1.5rem;
  color: var(--muted);
  text-align: right;
}

.entry.is-top td.c-rank,
.table--player td.c-rank {
  color: var(--ink);
}

.table--player .is-global td {
  font-weight: 500;
}

/* A score of zero: "—" in the rank and score columns, muted. */
.entry.is-zero td.c-rank,
.entry.is-zero td.c-score {
  color: var(--muted);
}

/* No filled surfaces: hovering a row underlines its name, an open row only loses its hairline.
   Hover only where there is a real pointer: after a tap the underline would stay stuck. */
.row.is-expandable {
  cursor: pointer;
}

@media (hover: hover) {
  .row:hover .who__name,
  .row:hover .c-name .plain {
    text-decoration-line: underline;
    text-decoration-color: var(--underline);
  }
}

/* An expandable row's name cell: content on the left, the chevron toggle at its right end (no extra
   column, so the last column still ends on the hairline's right edge). */
.cell-split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-width: 0;
}

.cell-split__main {
  min-width: 0;
}

.entry.is-open .row td {
  border-bottom-color: transparent;
}

.detail td {
  padding-top: 0.3rem;
  padding-bottom: 0.3rem;
  border-bottom: 0;
  color: var(--body);
  font-size: var(--fs-small);
}

.entry.is-open .detail:last-child td {
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--rule);
}

.table--board .d-label {
  padding-left: calc(24px + 0.65rem);
}

.table--player .d-label {
  padding-left: 1.25rem;
}

.d-value {
  margin-left: 0.6rem;
  color: var(--muted);
  white-space: nowrap;
}

/* Global breakdown: the category percentile sits in the Percentile column; phones hide that column,
   so there it follows the label instead. */
.d-value--narrow {
  display: none;
}

/* The breakdown explains the ranking: quieter than it (muted points, body-coloured labels). */
.table td.d-points {
  color: var(--muted);
}

.table td.d-points.is-neg {
  color: var(--body);
}

.detail .plain {
  color: var(--body);
}

.row-toggle {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  margin: -0.25rem -0.25rem -0.25rem 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--underline);
}

.row-toggle:hover,
.row-toggle[aria-expanded="true"] {
  color: var(--muted);
}

@media (hover: hover) {
  .row:hover .row-toggle {
    color: var(--muted);
  }
}

.chev {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  transition: transform var(--ease), opacity var(--ease);
}

.row-toggle[aria-expanded="true"] .chev {
  transform: rotate(180deg);
}

/* With a mouse, chevrons only appear on the row being pointed at (or focused, or open):
   forty of them in a column is noise. Touch screens always show them. */
@media (hover: hover) {
  .row-toggle .chev {
    opacity: 0;
  }

  .row:hover .chev,
  .row-toggle:focus-visible .chev,
  .row-toggle[aria-expanded="true"] .chev {
    opacity: 1;
  }
}

@media (max-width: 640px) {
  .table .c-pct {
    display: none;
  }

  .table .c-rank {
    width: 2.25rem;
  }

  .table .c-score {
    width: auto;
  }

  /* With the percentile hidden, a score that is now the last visible column ends on the edge. */
  .table .c-score:nth-last-child(2) {
    padding-right: 0;
  }

  .table--board .d-label {
    padding-left: 0;
  }

  .d-value--narrow {
    display: inline;
  }
}

/* Very narrow phones (320–360px): names may break rather than push the page sideways. */
@media (max-width: 360px) {
  .row-toggle {
    width: 1.5rem;
  }

  .cell-split {
    gap: 0.4rem;
  }

  .who {
    gap: 0.4rem;
  }

  .who__name {
    overflow-wrap: anywhere;
  }
}

/* ------------------------------------------------------------------ tabs, sort links, pager, toolbar */

.tabs--bar {
  margin-bottom: 2.5rem;
  border-bottom: 1px solid var(--rule);
}

.tabs__list {
  display: flex;
  gap: 1.75rem;
  overflow-x: auto;
  scrollbar-width: none;
}

/* On phones the tab row scrolls edge to edge instead of being clipped at the gutter. */
@media (max-width: 760px) {
  .tabs--bar .tabs__list {
    margin-inline: calc(-1 * var(--gutter));
    padding-inline: var(--gutter);
    scroll-padding-inline: var(--gutter);
  }
}

.tabs__list::-webkit-scrollbar {
  display: none;
}

.tab {
  position: relative;
  display: inline-flex;
  align-items: baseline;
  gap: 0.4rem;
  padding: 0.85rem 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: var(--fs-small);
  text-decoration: none;
  white-space: nowrap;
  transition: color var(--ease);
}

.tab:hover {
  color: var(--ink);
}

.tab[aria-current="page"],
.tab[aria-pressed="true"] {
  color: var(--ink);
}

/* The active underline is its own 1px bar. (An inset box-shadow bled down the sides of tabs that
   start at fractional x positions, drawing a thin box around the active tab.) */
.tab[aria-current="page"]::after,
.tab[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: var(--accent);
}

.tab__count {
  color: var(--muted);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 2rem;
  margin-bottom: 1.5rem;
}

.toolbar > .field {
  flex: 0 1 18rem;
  width: auto;
}

.toolbar__count {
  margin-left: auto;
  color: var(--muted);
  font-size: var(--fs-small);
  font-variant-numeric: tabular-nums;
}

/* Nothing to count: no box, so it takes no gap and the field reaches the right edge. */
.toolbar__count:empty {
  display: none;
}

@media (max-width: 640px) {
  .toolbar--board {
    flex-wrap: nowrap;
    gap: 1rem;
  }

  .toolbar--board > .field {
    flex: 1 1 auto;
  }

  .toolbar--board .toolbar__count {
    white-space: nowrap;
  }
}

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 2rem;
  margin-top: 2rem;
  font-size: var(--fs-small);
}

.pager__info {
  color: var(--muted);
}

.pager__off {
  color: var(--underline);
}

.sorts {
  font-size: var(--fs-small);
}

.sort {
  color: var(--muted);
  text-decoration: none;
}

.sort.is-current {
  color: var(--ink);
  text-decoration-line: underline;
  text-decoration-color: var(--ink);
  text-underline-offset: 0.35em;
}

/* ------------------------------------------------------------------ lists (activity, advancements, fights) */

.lines {
  border-top: 1px solid var(--rule);
}

.line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 2rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--rule);
}

.line:focus {
  outline: none;
}

/* Rows focused after "Show all" (keyboard): a visible ring. */
.line:focus-visible {
  outline: 1.5px solid var(--ink);
  outline-offset: 2px;
}

.line__main,
.line__text {
  flex: 1;
  min-width: 0;
}

.line__text {
  color: var(--body);
}

.line__text .plain {
  font-weight: 500;
}

.line__title {
  color: var(--ink);
  font-weight: 500;
}

.line__tag {
  margin-left: 0.6rem;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 400;
}

.line__desc,
.line__meta {
  color: var(--muted);
  font-size: var(--fs-small);
}

.line__side {
  display: flex;
  flex: none;
  flex-direction: column;
  align-items: flex-end;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.line__share {
  white-space: nowrap;
}

/* "· Diamond sword": a detail never splits from its dot (see metaBits). */
.meta-bit {
  white-space: nowrap;
}

.line__time {
  flex: none;
  color: var(--muted);
  font-size: var(--fs-small);
  white-space: nowrap;
}

.line__mark {
  display: inline-block;
  width: 1.1rem;
  color: var(--muted);
}

.is-win .line__mark {
  color: var(--ink);
}

.line--empty {
  display: block;
  color: var(--muted);
}

.list-meta {
  margin: -0.75rem 0 1.25rem;
}

.more {
  margin-top: 1.25rem;
  font-size: var(--fs-small);
}

/* Phones: the side column (time, share) goes under the text instead of squeezing it. */
@media (max-width: 640px) {
  .line {
    flex-direction: column;
    align-items: stretch;
    gap: 0.1rem;
  }

  .line__side {
    flex-direction: row;
    align-items: baseline;
    gap: 0.75rem;
    font-size: var(--fs-small);
    text-align: left;
  }
}

/* ------------------------------------------------------------------ hairline grid (cards) */

.grid {
  display: grid;
  gap: 0 3rem;
}

/* Builds: three columns, rows separated by air as well as the hairline. */
.grid--3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  row-gap: 2.5rem;
}

/* Home categories: 4 columns on wide screens, 2 below, so 8 categories never leave a hole. */
.grid--4 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2.5rem 2rem;
}

@media (min-width: 1100px) {
  .grid--4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 1.5rem 0 0.5rem;
  border-top: 1px solid var(--rule);
}

.card .label {
  margin-bottom: 1.25rem;
}

/* Lists start on the same line across a row of cards, whatever the title length. */
.card .mini,
.card .mini__empty {
  margin-top: auto;
  padding-top: 0.75rem;
}

.card__title {
  margin: 0 0 0.5rem;
}

.card__title a {
  color: var(--ink);
}

.card__text {
  color: var(--body);
  font-size: 0.98rem;
  line-height: 1.6;
}

.mini {
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.mini__row {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.3rem 0;
}

.mini__rank {
  width: 1.1rem;
  flex: none;
  color: var(--muted);
}

.mini__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.mini__score {
  color: var(--body);
}

.mini__empty {
  color: var(--muted);
  font-size: var(--fs-small);
}

/* Phones only: the arrow that ends a category row, and the short category name. */
.card__go,
.card__name--short {
  display: none;
}

@media (max-width: 900px) {
  .grid--3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .grid--3,
  .grid--4 {
    grid-template-columns: minmax(0, 1fr);
  }

  .grid--4 {
    gap: 0;
    border-bottom: 1px solid var(--rule);
  }

  .card {
    padding-bottom: 2rem;
  }

  /* Home categories: one hairline row each, name · leader · score →, instead of a top-3 card. */
  .card--cat {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, auto) auto;
    align-items: baseline;
    column-gap: 1rem;
    padding: 0.8rem 0;
  }

  .card--cat .card__title {
    margin: 0;
    font-size: var(--fs-body);
    font-weight: 500;
    letter-spacing: 0;
  }

  .card--cat .mini,
  .card--cat .mini__empty {
    margin: 0;
    padding: 0;
  }

  .card--cat .mini__row {
    gap: 0.75rem;
    padding: 0;
  }

  .card--cat .mini__row:nth-child(n + 2),
  .card--cat .mini__rank {
    display: none;
  }

  .card--cat .mini__name {
    font-weight: 400;
  }

  .card--cat .mini__score {
    color: var(--muted);
  }

  .card--cat .card__go {
    display: inline;
    color: var(--muted);
    text-decoration: none;
  }

  .card--cat .card__name:not(:last-child) {
    display: none;
  }

  .card--cat .card__name--short {
    display: inline;
  }
}

/* ------------------------------------------------------------------ highlights (definition list) */

.facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0 3rem;
}

.fact {
  padding: 1rem 0 1.4rem;
  border-top: 1px solid var(--rule);
}

.fact__label {
  color: var(--muted);
  font-size: var(--fs-small);
}

.fact__value {
  margin-top: 0.15rem;
  color: var(--ink);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.fact__sub {
  color: var(--muted);
  font-size: var(--fs-small);
}

@media (max-width: 760px) {
  .facts {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 1.5rem;
  }

  .fact__value {
    font-size: 1.25rem;
  }
}

/* ------------------------------------------------------------------ states */

.state {
  max-width: var(--measure);
}

p.state__title {
  color: var(--ink);
  font-size: 1.125rem;
  font-weight: 600;
}

h2.state__title {
  font-size: 1.5rem;
}

h1.state__title {
  font-size: var(--fs-h2);
}

.state__text {
  margin-top: 0.5rem;
  color: var(--muted);
}

.page-head .state__text {
  margin-top: 1.25rem;
  font-size: var(--fs-lede);
}

.state__actions {
  margin-top: 1.5rem;
}

.ghost-rows {
  border-top: 1px solid var(--rule);
}

.ghost-row {
  height: 3.5rem;
  border-bottom: 1px solid var(--rule);
}

.nomatch {
  padding: 1.25rem 0;
  color: var(--muted);
}

.nomatch p + p {
  margin-top: 0.5rem;
}
