:root {
  color-scheme: dark;
  --bg: #12141a;
  --panel: #1a1d26;
  --panel-2: #222633;
  --line: #2b3040;
  --text: #e8eaf0;
  --dim: #9097ab;
  --accent: #e0b04a;
  --accent-ink: #14161c;
  --good: #5cc98a;
  --bad: #e5645f;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font:
    14px/1.5 system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
}

/* ---------- controls ---------- */
button,
select,
input,
.btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 12px;
  font: inherit;
  text-decoration: none;
  transition:
    border-color 0.12s,
    background 0.12s;
}
button,
.btn,
select,
summary,
th {
  cursor: pointer;
}
button:hover,
.btn:hover,
select:hover,
input:hover {
  border-color: #4a5068;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button:disabled,
.btn.disabled {
  cursor: not-allowed;
  opacity: 0.5;
}
button.primary,
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
button.primary:hover,
.btn.primary:hover {
  filter: brightness(1.08);
}
button.link {
  background: none;
  border: 0;
  padding: 4px 6px;
  color: var(--dim);
  text-decoration: underline;
}
button.link:hover {
  color: var(--text);
}
input[type="search"] {
  min-width: 0;
}

/* ---------- layout ---------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  align-items: center;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
h1 {
  font-size: 18px;
  margin: 0;
  color: var(--accent);
  letter-spacing: 0.4px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  flex: none;
}
.spacer {
  flex: 1;
}
#status {
  color: var(--dim);
  font-size: 13px;
}
#status.live {
  color: var(--good);
}
#status.warn {
  color: var(--bad);
}
main {
  padding: 20px 24px 48px;
  max-width: 1120px;
  margin: 0 auto;
}
.hint {
  color: var(--dim);
  font-size: 12px;
}

.site-footer {
  max-width: 1100px;
  margin: 32px auto 24px;
  padding: 0 16px;
  text-align: center;
}
.site-footer a {
  color: inherit;
  text-decoration: underline;
}

/* ---------- account panel ---------- */
.account-panel {
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}
#accountForm {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
  max-width: 1072px;
  margin: 0 auto;
}
#accountForm strong {
  align-self: center;
  margin-right: 6px;
}
#accountForm label {
  display: grid;
  gap: 4px;
  color: var(--dim);
  font-size: 12px;
}
#accountMessage {
  flex-basis: 100%;
  min-height: 1.5em;
  color: var(--bad);
}

/* Account settings: change password, delete account. */
.settings-forms {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  max-width: 1072px;
  margin: 0 auto;
}
.settings-form {
  display: grid;
  align-content: start;
  gap: 8px;
  flex: 1 1 280px;
  max-width: 420px;
}
.settings-form label {
  display: grid;
  gap: 4px;
  color: var(--dim);
  font-size: 12px;
}
.settings-form label.check {
  display: flex;
  align-items: center;
  gap: 6px;
}
.settings-form p {
  margin: 0;
}
.settings-form .hint[role="alert"] {
  min-height: 1.5em;
}
.settings-form .hint.ok {
  color: var(--good);
}
.settings-form .hint.err {
  color: var(--bad);
}
.danger-btn {
  border-color: var(--bad);
  color: var(--bad);
}
#settingsClose {
  display: block;
  max-width: 1072px;
  margin: 10px auto 0;
}

/* ---------- scope + filters ---------- */
.scope-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.scope-switch {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.scope-switch button {
  border-color: transparent;
  background: transparent;
}
.scope-switch button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.profile-search {
  position: relative;
  margin-left: auto;
}
.profile-search input {
  width: 220px;
}
.results {
  position: absolute;
  z-index: 10;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.4);
}
.results li {
  padding: 6px 10px;
  border-radius: 5px;
  cursor: pointer;
}
.results li.active,
.results li:hover {
  background: var(--line);
}
.results li.none {
  color: var(--dim);
  cursor: default;
}
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  margin-bottom: 16px;
  color: var(--dim);
}
.controls label {
  display: flex;
  align-items: center;
  gap: 8px;
}
.controls input[type="number"] {
  width: 76px;
}

/* ---------- overview cards ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.note {
  margin: -8px 0 18px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.stat b {
  display: block;
  font-size: 24px;
  font-variant-numeric: tabular-nums;
}
.stat span {
  color: var(--dim);
  font-size: 12px;
}
/* The Abandoned card's "count as losses" switch, on the number's line so the card keeps the
   same height as the others. */
.stat-head {
  display: flex;
  align-items: center;
  gap: 12px;
}
.stat-toggle {
  display: inline-flex;
  align-items: center;
  padding: 4px 0; /* a bigger click target than the switch itself, without adding height */
  border: 0;
  background: none;
  cursor: pointer;
}
.stat-toggle:hover {
  background: none;
}
.stat-toggle .switch-track {
  position: relative;
  flex: none;
  width: 28px;
  height: 16px;
  border-radius: 999px;
  background: var(--line);
  transition: background 0.15s;
}
.stat-toggle .switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--dim);
  transition: transform 0.15s, background 0.15s;
}
.stat-toggle[aria-checked="true"] .switch-track {
  background: var(--accent);
}
.stat-toggle[aria-checked="true"] .switch-knob {
  transform: translateX(12px);
  background: var(--accent-ink);
}
.stat-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- tabs ---------- */
nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
nav button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 600;
}

/* ---------- table ---------- */
#view.loading {
  opacity: 0.55;
  transition: opacity 0.15s;
}
.table-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.table-tools input {
  width: 220px;
}
.table-tools select {
  max-width: min(240px, 60vw);
}
.row-count {
  margin-left: auto;
  color: var(--dim);
  font-size: 12px;
}
.table-wrap {
  max-height: 70vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
table {
  width: 100%;
  border-collapse: collapse;
}
th,
td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
tbody tr:last-child td {
  border-bottom: 0;
}
tbody tr:hover {
  background: var(--panel-2);
}
th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel-2);
  color: var(--dim);
  font-weight: 600;
  user-select: none;
}
th:hover {
  color: var(--text);
}
th[aria-sort="ascending"]::after {
  content: " \25B2";
  font-size: 10px;
}
th[aria-sort="descending"]::after {
  content: " \25BC";
  font-size: 10px;
}
td.num {
  font-variant-numeric: tabular-nums;
}

/* ---------- compare (Card WR, Card pick rate, Relic WR) ---------- */
.compare-cell {
  width: 1%;
  padding-right: 0;
}
.compare-cell input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}
.compare-panel {
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--panel);
}
.compare-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.compare-head .link {
  margin-left: auto;
}
.compare-limit:empty {
  display: none;
}
.compare-panel > .hint {
  margin: 6px 0 0;
}
.compare-wrap {
  overflow-x: auto;
}
.compare-table {
  width: auto;
}
.compare-table th,
.compare-table td {
  position: static;
  background: none;
  border-bottom-color: var(--line);
}
.compare-table tbody tr:hover {
  background: none;
}
.compare-table thead th {
  position: relative;
  min-width: 150px;
  vertical-align: bottom;
  text-align: center;
  color: var(--text);
}
.compare-table thead img {
  display: block;
  margin: 0 auto 6px;
}
.compare-card {
  height: auto;
  max-width: 150px;
}
.compare-name {
  display: block;
  white-space: normal;
}
.compare-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  padding: 0 6px;
  font-size: 12px;
  line-height: 20px;
}
.compare-table tbody th {
  color: var(--dim);
}
.compare-table tbody td {
  text-align: center;
}
.compare-table td.dim {
  color: var(--dim);
}
.compare-table td.best {
  box-shadow: inset 0 0 0 1px var(--good);
  border-radius: 4px;
}
.compare-table td.best .pct::after {
  content: " ★";
  color: var(--accent);
}
/* Let the character column hug its logo instead of stretching across the table. */
td.char-cell {
  width: 1%;
}
button.user-link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
button.user-link:hover,
a.user-link:hover {
  filter: brightness(1.2);
}
a.user-link {
  color: var(--accent);
  text-underline-offset: 2px;
}
/* ---------- multiplayer ---------- */
td.mates-cell {
  min-width: 180px;
}
.mate {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 8px;
}
.mate + .mate {
  margin-top: 4px;
}
.mate-wr {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.mate-wr.good {
  color: var(--good);
}
.mate-wr.bad {
  color: var(--bad);
}
.char-list {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.coop-tag {
  padding: 0 6px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: var(--accent);
  font-size: 11px;
  line-height: 16px;
  white-space: nowrap;
}
/* ---------- Trends chart ---------- */
.trend-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 12px;
}
.trend-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  margin-bottom: 8px;
}
.trend-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  color: var(--dim);
}
.trend-summary b {
  color: var(--text);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}
.trend-mode {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.trend-mode button {
  border-color: transparent;
  background: transparent;
  padding: 4px 10px;
}
.trend-mode button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.trend-chart + .trend-chart {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.playrate {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}
.playrate-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 124px;
  align-items: center;
  gap: 12px;
}
.playrate-name {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}
.playrate-head {
  display: block;
  height: 30px;
  width: auto;
  max-width: none;
}
.playrate-row.dim {
  opacity: 0.4;
}
.playrate-track {
  height: 16px;
  border-radius: 4px;
  background: var(--panel-2);
  overflow: hidden;
}
.playrate-bar {
  display: block;
  height: 100%;
  width: var(--w);
  background: var(--c);
  border-radius: 4px;
}
.playrate-value {
  color: var(--dim);
  font-size: 12px;
  text-align: right;
  white-space: nowrap;
}
@media (max-width: 560px) {
  .playrate-row {
    grid-template-columns: 40px minmax(0, 1fr);
  }
  .playrate-value {
    grid-column: 2;
    text-align: left;
  }
}
.trend-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 10px;
  margin: 0 0 4px;
  font-size: 15px;
}
.trend-title .swatch {
  align-self: center;
  margin-right: -4px;
}
.trend-sub {
  color: var(--dim);
  font-size: 12px;
  font-weight: 400;
}
.trend-canvas {
  position: relative;
}
.trend-svg {
  display: block;
  width: 100%;
  height: auto;
  touch-action: pan-y;
}
.trend-svg .grid {
  stroke: var(--line);
  stroke-width: 1;
}
.trend-svg .grid.mid {
  stroke: #4a5068;
  stroke-dasharray: 4 4;
}
.trend-svg .axis {
  fill: var(--dim);
  font-size: 11px;
}
.trend-svg .axis.dim {
  opacity: 0.75;
}
.trend-svg .trend-line {
  fill: none;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.trend-svg .guide {
  stroke: var(--dim);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}
.trend-tip {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  min-width: 150px;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.4);
  font-size: 12px;
  line-height: 1.6;
  white-space: nowrap;
}
.trend-tip .tip-title {
  color: var(--dim);
  margin-bottom: 2px;
}
.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border-radius: 50%;
  vertical-align: baseline;
}
.trend-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 4px 10px;
  min-height: 32px;
}
.legend-item[aria-pressed="false"] {
  opacity: 0.4;
}
.legend-item:disabled {
  opacity: 1;
  cursor: default;
}
.legend-item .legend-rate {
  color: var(--dim);
  font-size: 12px;
  margin-left: 4px;
}
.trend-wrap .hint {
  margin: 10px 0 0;
}

/* Trends: top 5 cards and relics by win rate, side by side (stacked on narrow screens). */
.top-grid {
  display: grid;
  /* min(): never wider than the panel, so a phone gets one full-width column instead of overflow. */
  grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr));
  gap: 14px 28px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
/* Side by side, not stacked: no divider between the two (the grid has its own above). */
.top-grid .trend-chart + .trend-chart {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}
.top-bars .trend-title {
  font-weight: 600;
}
.top-list {
  display: grid;
  gap: 4px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}
.top-row {
  display: grid;
  grid-template-columns: minmax(0, 11rem) 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 46px; /* fits a card picture, so card and relic rows line up across the two charts */
}
.top-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.top-name .icon-cell {
  max-width: 100%;
}
/* The track is the 0-100% scale: a hairline-quiet band one step off the panel. */
.top-track {
  height: 18px;
  background: var(--panel-2);
  border-radius: 0 4px 4px 0;
}
.top-bar {
  height: 100%;
  border-radius: 0 4px 4px 0; /* rounded data end, square at the 0% baseline */
}
.top-value {
  min-width: 6.5rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.top-value span {
  color: var(--dim);
  font-size: 12px;
}
.top-more {
  margin-top: 8px;
  font-size: 12px;
}
@media (max-width: 600px) {
  .top-row {
    grid-template-columns: minmax(0, 8.5rem) minmax(40px, 1fr) auto;
    gap: 8px;
  }
  .top-value {
    min-width: 0;
  }
  /* "wins/runs" moves under the percentage so the row fits a phone. */
  .top-value span {
    display: block;
  }
}
.trend-wrap .top-empty {
  margin-top: 8px;
}
.asc-icon {
  display: block;
  max-width: none;
}
.icon-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.cell-icon {
  display: block;
  flex: none;
  width: 32px;
  height: 32px;
  max-width: none;
  object-fit: contain; /* monster art comes in all shapes */
}
.card-preview {
  position: fixed;
  z-index: 50;
  width: 240px;
  pointer-events: none; /* never steals the hover from the row underneath */
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.6));
}
.card-preview[hidden] {
  display: none;
}
.card-preview img {
  display: block;
  width: 240px;
  height: auto;
}
.icon-cell:has(.card-thumb) {
  cursor: zoom-in;
}
.icon-cell[data-relic] {
  cursor: help;
}
/* Relic hover popup: icon, name, rarity and what the relic does. */
.relic-preview {
  position: fixed;
  z-index: 50;
  width: 280px;
  padding: 12px 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  pointer-events: none; /* never steals the hover from the row underneath */
}
.relic-preview[hidden] {
  display: none;
}
.relic-preview-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.relic-preview-head img {
  width: 48px;
  height: 48px;
  flex: none;
}
.relic-preview strong {
  display: block;
  font-size: 15px;
}
.relic-rarity {
  color: var(--accent);
  font-size: 12px;
}
.relic-preview p {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}
.area-thumb {
  display: block;
  flex: none;
  border-radius: 4px;
  object-fit: cover;
}
.cell-icon.card-thumb {
  width: 34px;
  height: 42px; /* cards are taller than wide */
}
.fight-type {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.fight-icon-slot {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
}
.fight-icon {
  display: block;
  max-width: none;
}
.char-logo {
  display: block;
  max-width: none;
}
.char-filter {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 100%;
  min-width: 0;
}
#charPicker {
  min-width: 0;
}
.char-picker {
  display: flex;
  flex-wrap: nowrap; /* one row; scrolls sideways on very narrow screens */
  gap: 6px;
  overflow-x: auto;
  padding: 2px;
}
.char-picker button {
  display: inline-flex;
  flex: none;
  align-items: center;
  min-height: 34px;
  padding: 3px 8px;
  color: var(--dim);
}
.char-picker button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--panel-2);
  box-shadow: 0 0 0 1px var(--accent);
  color: var(--text);
}
td.result-win,
td.result-loss {
  font-weight: 600;
}
td.result-win {
  color: var(--good);
}
td.result-loss {
  color: var(--bad);
}
.pct {
  display: block;
}
.pct.good {
  color: var(--good);
}
.pct.bad {
  color: var(--bad);
}
.bar {
  display: block;
  height: 3px;
  margin-top: 3px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
  min-width: 60px;
}
.bar::after {
  content: "";
  display: block;
  height: 100%;
  width: var(--w, 0);
  background: currentColor;
}
.bar.good {
  color: var(--good);
}
.bar.bad {
  color: var(--bad);
}
.empty {
  padding: 36px 20px;
  text-align: center;
  color: var(--dim);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.err {
  padding: 14px;
  color: var(--bad);
  border: 1px solid var(--bad);
  border-radius: var(--radius);
  white-space: pre-wrap;
}

/* ---------- drop overlay ---------- */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: rgb(18 20 26 / 0.88);
  border: 3px dashed var(--accent);
  color: var(--accent);
  font-size: 22px;
  font-weight: 600;
  pointer-events: none;
}

/* ---------- run page (run.js) ---------- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
tr.run-row {
  cursor: pointer;
}
button.details-btn {
  padding: 3px 10px;
  font-size: 12px;
  color: var(--accent);
  border-color: var(--accent);
  background: none;
}
button.details-btn:hover {
  background: var(--accent);
  color: var(--accent-ink);
}
body.run-open {
  overflow: hidden;
}
/* Below the card and relic popups (z-index 50), above everything else on the page. */
.run-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 32px 16px;
  background: rgb(8 9 12 / 0.78);
  overflow-y: auto;
}
.run-dialog {
  position: relative;
  width: min(1080px, 100%);
  padding: 22px 24px 24px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 18px 60px rgb(0 0 0 / 0.5);
}
.run-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 16px;
  line-height: 1;
}
.run-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 24px;
  padding-right: 40px; /* room for the close button */
}
.run-head-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 22px;
}
.run-stat {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.run-stat small {
  color: var(--dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.run-stat b {
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}
.run-stat.hp b {
  color: var(--bad);
}
.run-stat.gold b {
  color: var(--accent);
}
.run-head-side {
  text-align: right;
  font-size: 13px;
  line-height: 1.6;
}
.run-head-side .seed {
  font-family: ui-monospace, Consolas, monospace;
  letter-spacing: 0.5px;
}
.run-result {
  grid-column: 1 / -1;
  margin: 6px 0 0;
  font-size: 16px;
  font-weight: 600;
}
.run-result.win {
  color: var(--good);
}
.run-result.loss {
  color: var(--bad);
  display: flex;
  align-items: center;
  gap: 10px;
}
.result-monster {
  width: 48px;
  height: 48px;
  object-fit: contain; /* monster art comes in all shapes */
  flex: none;
}
.run-potions {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 13px;
}
.dim {
  color: var(--dim);
}
.run-people {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  margin-top: 8px;
  font-size: 13px;
}
.run-partial {
  margin: 12px 0 0;
}
.run-section {
  margin-top: 20px;
}
.run-section h3 {
  margin: 0 0 10px;
  font-size: 15px;
  color: var(--accent);
}
.run-section h3 .dim {
  font-weight: 400;
}
.run-map {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.run-map-row {
  display: grid;
  grid-template-columns: 100px 1fr;
  align-items: center;
  gap: 12px;
}
.run-map-area {
  text-align: right;
  font-weight: 600;
}
.run-map-rooms {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.map-room {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: 1px solid transparent;
}
.map-room:hover {
  background: var(--panel-2);
  border-color: var(--line);
}
.map-room.died {
  border-color: var(--bad);
}
.map-room img {
  width: 30px;
  height: 30px;
  object-fit: contain;
}
.run-relics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.run-relics .icon-cell.relic-only > span {
  display: none; /* icon only; the name is in the popup and tooltip */
}
.run-relics .icon-cell .cell-icon {
  width: 40px;
  height: 40px;
}
.relic-chip {
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
}
.run-deck {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 2px 16px;
}
.icon-cell.mini {
  gap: 5px;
  vertical-align: middle;
}
.icon-cell.mini .cell-icon.card-thumb {
  width: 18px;
  height: 22px;
}
.icon-cell.mini .cell-icon {
  width: 20px;
  height: 20px;
}
.icon-cell.upgraded > span {
  color: var(--good);
}
.icon-cell.enchanted > span {
  color: #c89bff;
}
.run-log.table-wrap {
  max-height: none;
}
.run-log td {
  vertical-align: top;
}
.run-log td.log-what {
  white-space: normal;
  min-width: 260px;
}
.run-log tr.died td {
  background: rgb(229 100 95 / 0.08);
}
.run-log tr.flash td {
  background: rgb(224 176 74 / 0.18);
  transition: background 0.3s;
}
.log-room {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.log-room img {
  width: 24px;
  height: 24px;
  object-fit: contain;
}
.log-room img.log-monster {
  width: 36px;
  height: 36px;
  margin: -6px 0; /* taller than the text; don't stretch the row */
  flex: none;
}
.log-line + .log-line {
  margin-top: 2px;
}
.log-label {
  display: inline-block;
  min-width: 82px;
  color: var(--dim);
}

@media (max-width: 640px) {
  .run-overlay {
    padding: 0;
  }
  .run-dialog {
    border-radius: 0;
    min-height: 100%;
    padding: 18px 16px;
  }
  .run-head {
    grid-template-columns: 1fr;
  }
  .run-head-side {
    text-align: left;
  }
  .run-map-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  .run-map-area {
    text-align: left;
  }
}

@media (max-width: 640px) {
  .topbar,
  .account-panel {
    padding-inline: 14px;
  }
  main {
    padding-inline: 14px;
  }
  .profile-search {
    margin-left: 0;
    width: 100%;
  }
  .profile-search input {
    width: 100%;
  }
  #accountForm label,
  #accountForm input {
    width: 100%;
  }
  .table-tools input {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* ---------- personal achievements ---------- */
.achievements-title {
  margin: 4px 0 2px;
  font-size: 20px;
}
.badges {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  margin-top: 14px;
}
.badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 22px 18px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.badge h3 {
  margin: 6px 0 0;
  font-size: 17px;
}
.badge p {
  margin: 0;
}
.badge-desc {
  color: var(--dim);
  font-size: 13px;
}
.badge-status {
  font-size: 13px;
  font-weight: 600;
}
.badge-medal {
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 3px solid var(--line);
  background: var(--panel-2);
  color: var(--dim);
}
.badge-medal svg {
  width: 46px;
  height: 46px;
}
.badge.earned {
  border-color: var(--accent);
}
.badge.earned .badge-medal {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 18px rgb(224 176 74 / 0.35);
}
.badge.earned .badge-status {
  color: var(--accent);
}
.badge.locked .badge-medal > * {
  filter: grayscale(1);
  opacity: 0.45;
}
.badge.locked .badge-status {
  color: var(--dim);
}
.badge-chars {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 10px;
  margin-top: 6px;
}
.badge-chars .missing {
  filter: grayscale(1);
  opacity: 0.35;
}
/* Earned under an earlier requirement: still earned, with a muted border and a note. */
.badge.earned.outdated {
  border-style: dashed;
}
.badge.earned.outdated .badge-medal {
  box-shadow: none;
}
.outdated-tag {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  border: 1px solid var(--dim);
  border-radius: 999px;
  color: var(--dim);
  font-size: 11px;
  font-weight: 600;
  vertical-align: middle;
}
.badge-outdated {
  color: var(--dim);
  font-size: 12px;
}
