/* Stats page: records, leaderboards, heat matrix, boss board. See DESIGN.md.
   Widths come from .wN classes (also used by member.css) because inline styles are blocked by the CSP. */
.stats-page { display: flex; flex-direction: column; gap: 56px; min-width: 0; padding-top: 8px; }
.stats-page > section { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* Ledger heading: display face, rule runs to the right edge */
.section-title {
  font: 800 var(--fs-xl) / 1 var(--font-display); text-transform: uppercase; letter-spacing: 0.02em;
  display: flex; align-items: center; gap: 16px;
}
.section-title::after { content: ""; flex: 1; height: 1px; background: var(--line-strong); }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.w0 { width: 0; } .w5 { width: 5%; } .w10 { width: 10%; } .w15 { width: 15%; } .w20 { width: 20%; }
.w25 { width: 25%; } .w30 { width: 30%; } .w35 { width: 35%; } .w40 { width: 40%; } .w45 { width: 45%; }
.w50 { width: 50%; } .w55 { width: 55%; } .w60 { width: 60%; } .w65 { width: 65%; } .w70 { width: 70%; }
.w75 { width: 75%; } .w80 { width: 80%; } .w85 { width: 85%; } .w90 { width: 90%; } .w95 { width: 95%; }
.w100 { width: 100%; }

.stats-page .swatch { border-radius: var(--radius-sm); border: 0; width: 10px; height: 10px; flex: none; }
.stats-page a { text-decoration-color: var(--accent); }

/* Records: a ruled row of totals, not tiles */
.records {
  display: grid; grid-template-columns: repeat(2, 1fr); margin: 0;
  border-top: 1px solid var(--line-strong); border-bottom: 1px solid var(--line);
}
.rec { padding: 14px 0 12px; min-width: 0; display: flex; flex-direction: column; gap: 2px; border-bottom: 1px solid var(--line); }
.rec:nth-last-child(-n+2) { border-bottom: 0; }
.rec:nth-child(even) { padding-left: 16px; border-left: 1px solid var(--line); }
.rec dt { font-size: var(--fs-xs); color: var(--muted); }
.rec-total { font: 800 var(--fs-3xl) / 1 var(--font-display); letter-spacing: 0.02em; }
.rec-holder { font-size: var(--fs-xs); color: var(--muted); margin-top: 4px; }
.rec-holder a { color: var(--text); font-weight: 600; }

/* Leaderboards: the only panelled elements on the page */
.lb-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
.lb-card { padding: 16px 16px 10px; min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.lb-title {
  font: 800 var(--fs-lg) / 1 var(--font-display); text-transform: uppercase; letter-spacing: 0.02em;
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding-bottom: 10px; border-bottom: 1px solid var(--line);
}
.lb-note { font: 400 var(--fs-xs) var(--font); text-transform: none; letter-spacing: 0; color: var(--muted); }
.lb-list { margin: 0; padding: 0; list-style: none; }
.lb-row {
  display: grid; grid-template-columns: 1.8em 1fr auto; column-gap: 10px; align-items: center;
  padding: 7px 0 8px; border-bottom: 1px solid var(--line);
}
.lb-row:last-child { border-bottom: 0; }
.lb-rank { font: 700 var(--fs-md) / 1 var(--font-display); color: var(--muted); text-align: right; }
.lb-name { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; min-width: 0; font-size: var(--fs-sm); font-weight: 500; }
.lb-value { text-align: right; white-space: nowrap; font: 700 var(--fs-md) / 1 var(--font-display); letter-spacing: 0.02em; }
.lb-detail { font: 400 var(--fs-xs) var(--font); color: var(--muted); margin-right: 8px; letter-spacing: 0; }
.meter { grid-column: 2 / -1; height: 3px; border-radius: var(--radius-sm); background: var(--surface-3); overflow: hidden; margin-top: 2px; }
.bar { display: block; height: 100%; }
.meter .bar { background: var(--cls); }
.lb-row.is-first { padding: 12px 0 12px; }
.lb-row.is-first .lb-rank { font-size: var(--fs-2xl); color: var(--brass); }
.lb-row.is-first .lb-name { font-size: var(--fs-md); font-weight: 600; }
.lb-row.is-first .lb-value { font-size: var(--fs-2xl); color: var(--brass); }
.lb-row.is-first .meter { height: 4px; }

/* Heat matrix */
.matrix-wrap { overflow-x: auto; max-width: 100%; border-top: 1px solid var(--line-strong); }
.matrix { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 960px; font-size: var(--fs-sm); }
.matrix th, .matrix td { white-space: nowrap; text-align: left; padding: 0; }
.matrix td.num, .matrix th.num { text-align: right; }
.matrix td.num { padding: 0 14px; height: 44px; border-bottom: 1px solid var(--bg); border-left: 1px solid var(--bg); }
.matrix td.empty { color: var(--muted); background: transparent; border-bottom-color: var(--line); }
.matrix .h0 { background: var(--heat-0); }
.matrix .h1 { background: var(--heat-1); }
.matrix .h2 { background: var(--heat-2); }
.matrix .h3 { background: var(--heat-3); }
.matrix .h4 { background: var(--heat-4); }
.matrix td.best { font-weight: 700; }

.matrix thead th { background: var(--bg); position: sticky; z-index: 2; }
.matrix .group-row th { top: var(--sticky-top, 0px); height: 34px; }
.matrix .col-row th { top: calc(var(--sticky-top, 0px) + 34px); border-bottom: 1px solid var(--line-strong); }
.matrix th.group {
  text-align: left; padding: 0 14px; border-left: 1px solid var(--line);
  font: 800 var(--fs-md) / 1 var(--font-display); text-transform: uppercase; letter-spacing: 0.02em;
}
.matrix th.corner { top: var(--sticky-top, 0px); vertical-align: bottom; border-bottom: 1px solid var(--line-strong); z-index: 4; }
.th-btn, .row-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; min-width: 44px;
  background: none; border: 0; padding: 0 14px; color: inherit; text-align: inherit; transition: color 0.12s ease;
}
.th-btn { font-size: var(--fs-xs); font-weight: 500; color: var(--muted); width: 100%; justify-content: flex-end; }
.matrix th.corner .th-btn { justify-content: flex-start; padding-left: 0; }
.th-btn:hover { color: var(--text); }
.matrix th[aria-sort="ascending"] .th-btn, .matrix th[aria-sort="descending"] .th-btn { color: var(--accent); }
.sort-ico { flex: none; }
.sort-ico.desc { transform: rotate(180deg); }
.matrix thead th.is-hot { background: var(--surface-3); }
.matrix thead th.is-hot .th-btn { color: var(--text); }

.matrix tbody th {
  position: sticky; left: 0; z-index: 1; background: var(--bg); text-align: left;
  border-bottom: 1px solid var(--line); min-width: 190px; font-weight: 600;
}
.matrix tbody th .row-btn { padding-left: 0; width: 100%; font-weight: 600; text-align: left; }
.row-name { overflow-wrap: normal; }
.row-ico { color: var(--faint); transform: rotate(90deg); margin-left: auto; transition: transform 0.12s ease; }
.row-btn[aria-expanded="true"] .row-ico { transform: rotate(180deg); color: var(--accent); }
.data-row:hover th, .data-row.is-open th { background: var(--surface-2); }
.data-row:hover td, .data-row.is-open td { box-shadow: inset 0 0 0 999px rgba(239, 231, 218, 0.07); }

.detail-row[hidden] { display: none; }
.detail-row td { white-space: normal; padding: 0; border-bottom: 1px solid var(--line-strong); background: var(--surface); }
.detail-inner { position: sticky; left: 0; width: min(560px, calc(100vw - 40px)); padding: 12px 14px 16px 0; display: flex; flex-direction: column; gap: 8px; }
.detail-head { display: flex; justify-content: space-between; gap: 16px; font-size: var(--fs-xs); }
.detail-link { font-weight: 600; color: var(--accent); }
.detail-bosses { display: flex; flex-direction: column; }
.detail-bosses li { display: grid; grid-template-columns: 1fr auto 3em; gap: 12px; padding: 4px 0; border-bottom: 1px solid var(--line); font-size: var(--fs-sm); }
.detail-bosses li:last-child { border-bottom: 0; }
.db-inst { color: var(--muted); }
.db-count { text-align: right; font-weight: 600; }

/* Boss board: one ruled table, grouped under dungeon sub-headers */
.boss-wrap { max-width: 100%; }
.boss-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.boss-table thead th { text-align: left; font: 500 var(--fs-xs) var(--font); color: var(--muted); padding: 0 12px 6px 0; border-bottom: 1px solid var(--line-strong); }
.boss-table th.num, .boss-table td.num { text-align: right; padding-right: 20px; }
.boss-table .inst-row th { text-align: left; padding: 28px 0 6px; border-bottom: 1px solid var(--line-strong); }
.boss-table tbody:first-of-type .inst-row th { padding-top: 14px; }
.inst-row th { display: table-cell; }
.inst-name { font: 800 var(--fs-xl) / 1 var(--font-display); text-transform: uppercase; letter-spacing: 0.02em; margin-right: 16px; }
.inst-total { font-size: var(--fs-xs); font-weight: 400; color: var(--muted); }
.boss-row th, .boss-row td { text-align: left; vertical-align: top; padding: 8px 12px 8px 0; border-bottom: 1px solid var(--line); }
.boss-row .boss-name { font-weight: 600; width: 28%; }
.boss-row td.boss-kills { font: 700 var(--fs-lg) / 1.2 var(--font-display); width: 12%; }
.boss-who ul { display: flex; flex-wrap: wrap; gap: 2px 18px; }
.boss-who li { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }

/* States, restyled here for this page only */
.stats-page .state, .stats-page + .state { border: 0; border-top: 1px solid var(--line); border-radius: 0; }

@media (min-width: 600px) {
  .lb-grid { grid-template-columns: repeat(2, 1fr); }
  .records { grid-template-columns: repeat(3, 1fr); }
  .rec:nth-last-child(-n+2) { border-bottom: 1px solid var(--line); }
  .rec:nth-last-child(-n+3) { border-bottom: 0; }
  .rec:nth-child(even) { padding-left: 0; border-left: 0; }
  .rec:not(:nth-child(3n+1)) { padding-left: 16px; border-left: 1px solid var(--line); }
}

@media (min-width: 880px) {
  .stats-page { gap: 64px; }
  .lb-grid { grid-template-columns: repeat(3, 1fr); }
  .records { grid-template-columns: repeat(6, 1fr); }
  .rec { border-bottom: 0 !important; }
  .rec:not(:first-child) { padding-left: 16px; border-left: 1px solid var(--line); }
  .rec:first-child { padding-left: 0; border-left: 0; }
  .rec-total { font-size: var(--fs-4xl); }
  .th-btn, .row-btn { min-height: 32px; }
  .lb-name { min-height: 28px; }
}

/* Wide enough to need no sideways scroll: the sticky header then follows the viewport */
@media (min-width: 1100px) {
  .matrix-wrap { overflow: visible; }
  .matrix { min-width: 0; }
  .matrix tbody th { position: static; }
}
