*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------------------------------------------------------------- shell -- */

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: var(--shell-max);
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  flex: 1;
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -.02em;
  text-align: center;
}
.brand span { color: var(--accent); }
.topbar__title {
  flex: 1;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-dim);
}

.icon-btn {
  min-width: var(--tap);
  min-height: var(--tap);
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 18px;
}
.icon-btn:hover { background: var(--bg-raised); color: var(--text); }
.icon-btn[hidden] { visibility: hidden; display: grid; }

#screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: var(--gap);
  gap: var(--gap);
}
.screen--scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* --------------------------------------------------------------- pieces -- */

.btn {
  min-height: var(--tap);
  padding: 10px 18px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--speed), background var(--speed);
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.btn--ghost { background: transparent; }
.btn--block { width: 100%; }
.btn--sm { min-height: 36px; padding: 6px 12px; font-size: 14px; }

.row { display: flex; gap: var(--gap-sm); }
.row--wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); font-size: 13px; }
.center { text-align: center; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.delta-up { color: var(--good); }
.delta-down { color: var(--bad); }
.delta-same { color: var(--text-dim); }

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap);
}

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}
.tag--accent { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* ----------------------------------------------------------------- home -- */

.hero { text-align: center; padding: var(--gap-lg) 0 0; }
.hero__record {
  font-size: clamp(56px, 22vw, 108px);
  font-weight: 900;
  letter-spacing: -.05em;
  line-height: .9;
  margin: 0;
}
.hero__record span { color: var(--accent); }
.hero__sub { color: var(--text-dim); margin: 8px 0 0; font-size: 15px; }

.streak {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: var(--gap);
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  font-size: 14px;
}

.modes { display: flex; flex-direction: column; gap: var(--gap-sm); }

.mode-card {
  display: flex;
  align-items: center;
  gap: var(--gap);
  width: 100%;
  min-height: 64px;
  padding: 12px 14px;
  text-align: left;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: inherit;
  cursor: pointer;
  transition: border-color var(--speed), transform var(--speed);
}
.mode-card:hover { border-color: var(--border-strong); }
.mode-card:active { transform: scale(.99); }
.mode-card__icon { font-size: 26px; width: 34px; text-align: center; }
.mode-card__name { font-weight: 700; }
.mode-card__desc { font-size: 13px; color: var(--text-dim); }
.mode-card--done { opacity: .6; }

/* Statistics and history read as destinations too, so they get the same card. */
.modes--secondary { margin-top: 2px; }


/* ----------------------------------------------------------------- play -- */

.slotbar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.slot {
  min-height: 74px;
  padding: 6px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-align: center;
  overflow: hidden;
}
.slot__pos {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .06em;
  color: var(--text-faint);
}
.slot--filled { border-color: var(--border-strong); background: var(--bg-sunken); }
.slot--filled .slot__pos { color: var(--accent); }
.slot__name {
  font-size: 11px;
  font-weight: 600;
  line-height: 1.15;
  word-break: break-word;
  hyphens: auto;
}
.slot__meta { font-size: 10px; color: var(--text-faint); }
.slot--open { border-style: dashed; }
.slot--next { border-color: var(--accent); }

.playarea {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.spinbox {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--gap);
  text-align: center;
}
.spinbox__round {
  display: flex;
  justify-content: space-between;
  gap: var(--gap-sm);
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* Team and decade side by side, each re-roll directly under what it changes. */
.pickgrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.pickcard {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 70px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-raised);
  overflow: hidden;
}
.pickcard__body { display: flex; flex-direction: column; min-width: 0; }
.pickcard__kicker {
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.pickcard__value {
  font-size: clamp(15px, 4.6vw, 20px);
  font-weight: 800;
  letter-spacing: -.01em;
  line-height: 1.15;
  word-break: break-word;
}
.pickcard__value--accent { color: var(--accent); }

.skipbtn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color var(--speed), color var(--speed), transform var(--speed);
}
.skipbtn svg { flex: none; }
.skipbtn:hover:not(:disabled) { border-color: var(--accent); color: var(--text); }
.skipbtn:active:not(:disabled) { transform: scale(.98); }
.skipbtn:disabled { opacity: .45; cursor: not-allowed; }
.skipbtn:disabled span { text-decoration: line-through; }

.pickgrid.is-spinning .pickcard__value,
.pickgrid.is-spinning .pickcard__kicker,
.pickgrid.is-spinning .crest { animation: flicker 90ms steps(1) infinite; }
@keyframes flicker { 50% { opacity: .35; } }

/* Generated from franchise colours — see src/ui/crest.js. */
.crest {
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--crest-bg);
  border: 2px solid var(--crest-ring);
  color: var(--crest-ink);
  font-weight: 800;
  letter-spacing: -.02em;
  font-family: var(--font);
}
.crest--lg { width: 44px; height: 44px; font-size: 13px; }
.crest--md { width: 30px; height: 30px; font-size: 10px; }
.crest--sm { width: 24px; height: 24px; font-size: 9px; border-width: 1.5px; }

.roster-controls { display: flex; flex-direction: column; gap: 6px; }
.search--sm { min-height: 38px; padding: 8px 10px; font-size: 14px; }
.roster-count {
  margin-left: auto;
  font-family: var(--font-num);
  font-size: 12px;
  color: var(--text-faint);
}

.roster-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Column labels share the card's grid so the headings sit over their numbers. */
.sortbar {
  display: grid;
  grid-template-columns: 38px 1fr 38px 38px 38px;
  gap: 8px;
  align-items: center;
  padding: 2px 9px 6px;
}
.sortbar--blind { display: flex; padding: 2px 9px 6px; }
.sortbar__lead { grid-column: 1 / 3; display: flex; align-items: center; gap: 8px; }

.sorth {
  min-height: 28px;
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  text-align: right;
  white-space: nowrap;
  cursor: pointer;
}
.sortbar__lead .sorth { margin-left: auto; }
.sorth:hover { color: var(--text); }
.sorth.is-active { color: var(--accent); }
.sorth__dir { margin-left: 2px; }

/* Static twin of .sortbar for the picker, which has nothing to sort. */
.pickhead {
  display: grid;
  grid-template-columns: 38px 1fr 38px 38px 38px;
  gap: 8px;
  padding: 0 9px 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-faint);
  text-align: right;
}

.chip--sm {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 28px;
  padding: 3px 9px;
  font-size: 11px;
}

.roster {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 2px;
}

.pcard {
  display: grid;
  grid-template-columns: 38px 1fr 38px 38px 38px;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: var(--tap);
  padding: 8px 10px;
  text-align: left;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: inherit;
  cursor: pointer;
  transition: border-color var(--speed), transform var(--speed);
}
.pcard--blind { grid-template-columns: 38px 1fr auto; gap: 10px; }
.pcard:hover:not(:disabled) { border-color: var(--accent); }
.pcard:active:not(:disabled) { transform: scale(.99); }
.pcard:disabled { opacity: .35; cursor: not-allowed; }
.pcard__pos {
  font-size: 11px;
  font-weight: 800;
  text-align: center;
  padding: 3px 0;
  border-radius: 5px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
}
.pcard__id { display: flex; flex-direction: column; min-width: 0; }
.pcard__name { font-weight: 600; font-size: 15px; line-height: 1.2; }
.pcard__sub { font-size: 12px; color: var(--text-faint); }
.pcard__stat {
  font-family: var(--font-num);
  font-size: 13px;
  color: var(--text-dim);
  text-align: right;
}
.pcard__hidden { font-size: 12px; color: var(--text-faint); letter-spacing: .12em; }
.pcard__key {
  display: none;
  margin-left: 6px;
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--font-num);
  font-size: 10px;
  font-weight: 400;
  color: var(--text-faint);
  vertical-align: middle;
}
@media (hover: hover) and (pointer: fine) { .pcard__key { display: inline-block; } }

/* --------------------------------------------------------------- result -- */

.result { display: flex; flex-direction: column; gap: var(--gap); }

.record {
  font-size: clamp(54px, 20vw, 96px);
  font-weight: 900;
  letter-spacing: -.04em;
  line-height: 1;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.record span { color: var(--accent); }
.record--perfect { color: var(--accent); text-shadow: 0 0 28px rgba(240, 128, 60, .45); }

.verdict { text-align: center; color: var(--text-dim); margin-top: -4px; }

.delta-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius);
  background: var(--bg-sunken);
  border: 1px dashed var(--border-strong);
  font-size: 14px;
}

.sandbox-banner {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  padding: 8px 12px;
  border-radius: var(--radius);
  background: rgba(240, 128, 60, .12);
  border: 1px solid var(--accent-dim);
  font-size: 13px;
}

.lineup { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.lineup__item {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 100%;
  text-align: left;
  color: inherit;
}
button.lineup__item { cursor: pointer; }
button.lineup__item:hover { border-color: var(--accent); }
.lineup__pos { font-weight: 800; font-size: 12px; color: var(--accent); }
.lineup__rating { font-family: var(--font-num); font-size: 13px; color: var(--text-dim); }
.lineup__item--swapped { border-color: var(--accent); }
.lineup__item--moved { border-color: var(--neutral); }

/* ------------------------------------------------------------ breakdown -- */

.bd-section { margin-top: var(--gap); }
.bd-section h3 {
  font-size: 13px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 0 0 var(--gap-sm);
}

.bd-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.bd-table th, .bd-table td { padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--border); }
.bd-table th:first-child, .bd-table td:first-child { text-align: left; }
.bd-table th { color: var(--text-faint); font-weight: 600; font-size: 12px; }
.bd-table td.num, .bd-table th.num { font-family: var(--font-num); }
.bd-table tfoot td { font-weight: 700; border-bottom: 0; }

.bd-players { display: flex; flex-direction: column; }

.bd-player {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: none;
  color: inherit;
  padding: var(--gap-sm) 0;
  font: inherit;
}
.bd-player--tap {
  cursor: pointer;
  padding: var(--gap-sm) 10px;
  margin-bottom: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
}
.bd-player--tap:hover { border-color: var(--accent); }
.bd-player--tap:active { transform: scale(.995); }
.bd-player--swapped { border-color: var(--accent) !important; }
.bd-player--moved { border-color: var(--neutral) !important; }

.bd-player__head { display: flex; align-items: baseline; gap: 8px; }
.bd-player__name { font-weight: 700; }
.bd-player__total { margin-left: auto; font-family: var(--font-num); font-weight: 700; }
.bd-player__parts {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-dim);
  font-family: var(--font-num);
}
.bd-note { display: block; font-size: 12px; color: var(--text-faint); margin-top: 4px; }
.bd-warn { color: var(--bad); }

.bd-total {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0 2px;
  font-weight: 600;
}
.bd-total__val {
  font-family: var(--font-num);
  font-weight: 700;
  min-width: 56px;
  text-align: right;
}

.bd-mod { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.bd-mod__val { font-family: var(--font-num); font-weight: 700; min-width: 56px; text-align: right; }
.bd-mod__body { flex: 1; display: flex; flex-direction: column; gap: 1px; }
.bd-mod__name { font-size: 14px; }
.bd-mod__why { font-size: 12px; color: var(--text-faint); line-height: 1.3; }

/* Collapsed by default; native <details> keeps the keyboard behaviour free. */
.bd-collapse {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
}
.bd-collapse > summary {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  min-height: var(--tap);
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 600;
  list-style: none;
}
.bd-collapse > summary::-webkit-details-marker { display: none; }
.bd-collapse > summary::after {
  content: "▾";
  color: var(--text-faint);
  transition: transform var(--speed);
}
.bd-collapse[open] > summary::after { transform: rotate(180deg); }
.bd-collapse[open] > summary { border-bottom: 1px solid var(--border); }
.bd-collapse__val { font-family: var(--font-num); font-weight: 700; }
.bd-collapse__body { padding: 4px 12px 12px; }

.bd-explain td { vertical-align: top; padding: 8px 4px; }
.bd-explain .bd-term { font-family: var(--font-num); color: var(--text); white-space: nowrap; }
.bd-explain .num { white-space: nowrap; font-weight: 700; }
.bd-where { text-align: left !important; color: var(--text-dim); font-size: 12px; line-height: 1.4; }

.formula {
  font-family: var(--font-num);
  font-size: 12px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  overflow-x: auto;
  white-space: pre;
  color: var(--text-dim);
}

/* --------------------------------------------------------------- grades -- */

.grade {
  display: inline-grid;
  place-items: center;
  min-width: 26px;
  height: 22px;
  padding: 0 5px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--bg-sunken);
  font-family: var(--font-num);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: -.02em;
  color: var(--text-dim);
}
.grade--sm { min-width: 22px; height: 18px; font-size: 10px; }
.grade--lg { min-width: 34px; height: 30px; font-size: 16px; border-radius: 8px; }

/* Only the top grades earn colour; the rest stay quiet. */
.grade--S {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 0 14px rgba(240, 128, 60, .45);
}
.grade--Ap { border-color: var(--accent); color: var(--accent); }
.grade--A { border-color: var(--good); color: var(--good); }
.grade--B { color: var(--text); }
.grade--F { border-color: var(--bad); color: var(--bad); }

.verdict__line { display: flex; align-items: center; justify-content: center; gap: 8px; }
.verdict > .faint { display: block; margin-top: 2px; }

/* ------------------------------------------------------------ statistics -- */

.stats-card { display: flex; flex-direction: column; gap: var(--gap-sm); }
.stats-row { display: flex; gap: var(--gap-sm); }
.stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-align: center;
}
.stat strong { font-family: var(--font-num); font-size: 20px; font-weight: 800; }
.stat span { font-size: 11px; color: var(--text-faint); }
.stats-tags {
  width: 100%;
  justify-content: center;
}
.stats-tags .tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  font-size: 13px;
}

.arc-block { margin-top: 2px; }
.arc-row {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.arc-row__body { flex: 1; line-height: 1.35; }

/* -------------------------------------------------------------- history -- */

.chip-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* Filter rows span the list and share the width between them, rather than
   huddling at the left with a ragged tail. */
.chip-row--spread {
  width: 100%;
  justify-content: space-between;
}
.chip-row--spread .chip {
  flex: 1 1 auto;
  justify-content: center;
  min-height: 40px;
  padding: 8px 14px;
  font-size: 14px;
}
.chip-row--spread .chip .grade { height: 22px; min-width: 26px; font-size: 12px; }
.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  min-height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }

.hist-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }

.hist-row {
  display: grid;
  /* Fixed, so the colour blocks line up in a column instead of following the
     width of each score. */
  grid-template-columns: 120px 1fr;
  align-items: stretch;
  width: 100%;
  padding: 0;
  text-align: left;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: inherit;
  cursor: pointer;
  overflow: hidden;
}
.hist-row:hover { border-color: var(--accent); }

/* The grade colours the whole score block, so a run of results reads as a
   column of colour before you read a single number. */
.hist-row__lead {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--g-color) 15%, transparent);
  border-right: 1px solid color-mix(in srgb, var(--g-color) 35%, transparent);
}
.hist-row__rec {
  font-family: var(--font-num);
  font-weight: 800;
  font-size: 17px;
  white-space: nowrap;
  color: var(--g-color);
}
.hist-row__body { padding: 10px 10px 10px 8px; min-width: 0; }

.hist-row--S  { --g-color: var(--accent); }
.hist-row--Ap { --g-color: var(--accent); }
.hist-row--A  { --g-color: var(--good); }
.hist-row--B  { --g-color: var(--neutral); }
.hist-row--C  { --g-color: var(--text); }
.hist-row--D  { --g-color: var(--text-dim); }
.hist-row--F  { --g-color: var(--bad); }

.hist-row__names {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.3;
}
.hist-row__meta { display: block; font-size: 11px; color: var(--text-faint); margin-top: 2px; }

.empty { text-align: center; color: var(--text-faint); padding: var(--gap-lg); }

/* ----------------------------------------------------------------- tabs -- */

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
}
.tab {
  flex: 1;
  min-height: 36px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.tab.is-active { background: var(--bg-raised); color: var(--text); box-shadow: var(--shadow); }

/* -------------------------------------------------------------- compare -- */

.cmp-wrap { overflow-x: auto; }

.cmp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: fixed;
}
.cmp-table th,
.cmp-table td { padding: 7px 4px; border-bottom: 1px solid var(--border); }
.cmp-table td { text-align: right; font-family: var(--font-num); color: var(--text-dim); }

.cmp-corner { width: 86px; }
.cmp-label {
  width: 86px;
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  color: var(--text-faint);
}

.cmp-head {
  position: relative;
  vertical-align: bottom;
  text-align: center;
  padding: 8px 4px;
}
.cmp-head .crest { margin: 0 auto; }
.cmp-head__name {
  display: block;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.15;
  margin-top: 4px;
  overflow-wrap: anywhere;
}
.cmp-head__meta { display: block; font-size: 10px; color: var(--text-faint); font-weight: 400; }
.cmp-remove {
  position: absolute;
  top: 0;
  right: 0;
  width: 22px;
  height: 22px;
  border: 0;
  background: none;
  color: var(--text-faint);
  font-size: 12px;
  cursor: pointer;
}
.cmp-remove:hover { color: var(--bad); }

.cmp-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 100%;
  min-height: 62px;
  padding: 8px 4px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.cmp-slot:hover { border-color: var(--accent); color: var(--text); }
.cmp-slot__plus { font-size: 20px; line-height: 1; }

.cmp-best { color: var(--accent); font-weight: 700; }
.cmp-divider th {
  padding-top: 14px;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-faint);
  border-bottom: 0;
}
.cmp-total th, .cmp-total td { font-weight: 800; font-size: 15px; border-bottom: 0; }
.cmp-total td { color: var(--text); }
.cmp-total .cmp-best { color: var(--accent); }
.cmp-empty {
  text-align: center !important;
  font-family: var(--font);
  color: var(--text-faint);
  padding: var(--gap-lg) 8px !important;
}

/* ------------------------------------------------------------- rankings -- */

.rank-head { text-align: center; }
.rank-title { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.rank-sub { margin: 2px 0 0; font-size: 14px; color: var(--accent); }

.rank-list {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: rank;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rank-row {
  display: grid;
  grid-template-columns: 24px 24px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: var(--tap);
  padding: 8px 10px;
  text-align: left;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: inherit;
  cursor: pointer;
}
.rank-row:hover { border-color: var(--accent); }
.rank-row__no {
  font-family: var(--font-num);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-faint);
  text-align: right;
}
.rank-row__body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.rank-row__name { font-weight: 600; font-size: 15px; line-height: 1.2; }
.rank-row__meta { font-size: 12px; color: var(--text-faint); }
.rank-row__num { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; }
.rank-row__rating { font-family: var(--font-num); font-weight: 700; font-size: 15px; color: var(--accent); }
.rank-row__line { font-family: var(--font-num); font-size: 11px; color: var(--text-dim); white-space: nowrap; }

/* The top three carry the gold. */
.rank-list li:nth-child(-n+3) .rank-row { border-color: var(--border-strong); }
.rank-list li:nth-child(-n+3) .rank-row__no { color: var(--accent); }

/* ---------------------------------------------------------------- modal -- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 0;
}
@media (min-width: 600px) { .modal-backdrop { align-items: center; padding: var(--gap); } }

.modal {
  width: 100%;
  max-width: var(--shell-max);
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow);
  padding-bottom: env(safe-area-inset-bottom);
  animation: slide-up var(--speed) ease-out;
}
@media (min-width: 600px) { .modal { border-radius: var(--radius-lg); } }
@keyframes slide-up { from { transform: translateY(24px); opacity: 0; } }

.modal__head {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.modal__title { flex: 1; font-weight: 700; margin: 0; font-size: 16px; }
.modal__body { flex: 1; min-height: 0; overflow-y: auto; padding: var(--gap); display: flex; flex-direction: column; gap: var(--gap-sm); }
.modal__foot { padding: var(--gap); border-top: 1px solid var(--border); display: flex; gap: var(--gap-sm); }

.search {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-sunken);
  color: var(--text);
}
.filter-row { display: flex; gap: 6px; }
.filter-row select {
  flex: 1;
  min-height: 38px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-sunken);
}

/* ---------------------------------------------------------------- toast -- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  animation: slide-up var(--speed) ease-out;
}

/* ------------------------------------------------------------- doc text -- */

.prose { font-size: 15px; }
.prose h2 { font-size: 18px; margin: var(--gap-lg) 0 var(--gap-sm); }
.prose h3 { font-size: 15px; margin: var(--gap) 0 4px; }
.prose p, .prose li { color: var(--text-dim); }
.prose ul { padding-left: 20px; margin: var(--gap-sm) 0; }
.prose code {
  font-family: var(--font-num);
  font-size: 13px;
  background: var(--bg-sunken);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--text);
}
