/**
 * Shared stats page shell — layout/typography contract for
 * stats.html (personal) and research-stats.html.
 * Visual source of truth: normal personal detailed stats.
 */

:root {
  --stats-ink: var(--haidex-text);
  --stats-muted: var(--haidex-text-secondary);
  --stats-line: var(--haidex-border);
  --stats-line-soft: var(--haidex-border-green);
  --stats-panel: var(--haidex-card);
  --stats-bg-soft: var(--haidex-very-light);
  --stats-accent: var(--haidex-action-primary);
  --stats-accent-deep: var(--haidex-action-primary-hover);
  --stats-accent-soft: #eef2f7;
}

* {
  box-sizing: border-box;
}

body.haidex-app {
  margin: 0 auto;
  padding: 12px 16px 28px;
  max-width: 720px;
  font-size: 14px;
  line-height: 1.5;
}

@media (min-width: 900px) {
  body.haidex-app {
    max-width: min(calc(100vw - 32px), 960px);
    padding-left: 20px;
    padding-right: 20px;
  }
}

@media (min-width: 1200px) {
  body.haidex-app {
    max-width: min(calc(100vw - 40px), 1280px);
  }
  body.haidex-app.stats-benchmark-active {
    max-width: min(calc(100vw - 40px), 1560px);
  }
}

@media (min-width: 1600px) {
  body.haidex-app.stats-benchmark-active {
    max-width: min(calc(100vw - 48px), 1720px);
  }
}

body.haidex-app h1,
.haidex-page-title {
  font-size: 1.35rem;
  margin: 4px 0 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--stats-ink);
}

.muted {
  color: var(--stats-muted);
  font-size: 12px;
  line-height: 1.5;
}

.err {
  color: #b00020;
  margin: 8px 0;
}

.warn {
  color: #6b4e00;
  background: #fff8e6;
  border: 1px solid #e6d19a;
  border-radius: 6px;
  padding: 10px 12px;
  margin: 8px 0;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-line;
}

a {
  color: var(--stats-accent-deep);
}

.panel {
  border: 1px solid var(--stats-line-soft);
  border-radius: 8px;
  padding: 14px 14px 12px;
  margin-bottom: 16px;
  background: var(--stats-panel);
}

.panel legend {
  font-weight: 700;
  font-size: 13px;
  padding: 0 4px;
  color: var(--stats-ink);
}

.ro {
  color: var(--stats-ink);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  word-break: break-word;
}

.actions {
  margin-top: 14px;
  display: flex;
  justify-content: center;
}

button.primary {
  padding: 9px 22px;
  font-size: 14px;
  font-weight: 600;
  background: var(--stats-accent);
  color: #fff;
  border: 1px solid var(--stats-accent-deep);
  border-radius: 6px;
  cursor: pointer;
  min-width: 10.5rem;
}

button.primary:hover:not(:disabled) {
  background: var(--stats-accent-deep);
}

button.primary:focus-visible {
  outline: 2px solid var(--stats-accent);
  outline-offset: 2px;
}

button.primary:disabled {
  opacity: 0.55;
  cursor: default;
}

.headline {
  border: 1px solid var(--stats-line-soft);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 14px;
  background: var(--stats-panel);
}

.headline .big {
  font-size: 1.55rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  color: var(--stats-ink);
}

.benchmark-filter-panel {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
  min-width: 0;
}

.benchmark-filter-panel > label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--stats-muted);
  margin-bottom: 3px;
  letter-spacing: 0.02em;
}

.benchmark-filter-panel .field select,
.benchmark-filter-panel select {
  width: 100%;
  max-width: 360px;
  padding: 6px 8px;
  font-size: 13px;
  border: 1px solid var(--stats-line);
  border-radius: 5px;
  background: #fff;
}

@media (max-width: 640px) {
  .benchmark-filter-panel .field select,
  .benchmark-filter-panel select {
    max-width: 100%;
  }
}

.benchmark-filter-panel select:focus-visible {
  outline: 2px solid var(--stats-accent);
  outline-offset: 1px;
}

.filter-compare-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.filter-compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 18px;
  align-items: start;
}

@media (max-width: 768px) {
  .filter-compare-grid {
    grid-template-columns: 1fr;
  }
}

.filter-compare-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.filter-compare-col-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--stats-muted);
  letter-spacing: 0.02em;
}

.filter-compare-col .ro {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  word-break: break-word;
}

.filter-compare-col--muted .scope-collapse-summary {
  color: #8a97a5;
}

.stats-result-meta-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--stats-muted);
  letter-spacing: 0.03em;
  margin-bottom: 10px;
}

.stats-result-meta-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px 16px;
  align-items: start;
}

@media (max-width: 900px) {
  .stats-result-meta-summary {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 420px) {
  .stats-result-meta-summary {
    grid-template-columns: 1fr;
  }
}

.stats-result-meta-item {
  min-width: 0;
}

.stats-result-meta-item-value {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--stats-ink);
  word-break: break-word;
}

.stats-result-meta-item-value--text {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
}

.stats-result-meta-item-label {
  margin-top: 3px;
  font-size: 12px;
  color: var(--stats-muted);
  font-weight: 600;
}

.stats-result-meta-games {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 4px;
}

.stats-result-meta-games-unit {
  font-size: 14px;
  font-weight: 600;
  color: var(--stats-ink);
}

.stats-result-meta-games-empty {
  display: block;
  width: 100%;
  font-size: 12px;
  color: #8a4b08;
  margin-top: 4px;
  font-weight: 500;
}

#result {
  margin-top: 4px;
}

.stats-catnav {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  margin: 8px 0 10px;
  padding: 8px 10px;
  background: var(--stats-panel);
  border: 1px solid var(--stats-line);
  border-radius: 8px;
}

.stats-catnav a {
  display: inline-block;
  padding: 4px 10px;
  border: 1px solid var(--stats-line);
  border-radius: 999px;
  background: #f3f6f9;
  color: var(--stats-ink);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.stats-catnav a:hover:not(.is-active) {
  background: var(--stats-accent-soft);
  border-color: #b8c7d8;
}

.stats-catnav a.is-active,
.stats-catnav a[aria-current="true"] {
  background: #d7e6f7;
  border: 2px solid var(--stats-accent);
  padding: 3px 9px;
  color: var(--stats-accent-deep);
  font-weight: 700;
  box-shadow: inset 0 -2px 0 var(--stats-accent);
}

.stats-catnav a:focus-visible {
  outline: 2px solid var(--stats-accent);
  outline-offset: 2px;
}

@media (max-width: 640px) {
  .stats-catnav {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: 12px;
}

th,
td {
  border: 1px solid #ccc;
  padding: 5px 8px;
}

.summary-table th {
  background: #eee;
  text-align: left;
  font-weight: 600;
  width: 42%;
}

th {
  background: #eee;
  text-align: left;
  font-weight: 600;
}

td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.summary-table td.num {
  font-size: 1.05rem;
  font-weight: 600;
}

@media (min-width: 768px) {
  table.summary-table.compact-stat-table:not(.benchmark-compare-inline) {
    width: auto;
    max-width: none;
  }
  table.summary-table.compact-stat-table:not(.benchmark-compare-inline) th {
    width: auto;
    white-space: nowrap;
  }
  table.summary-table.compact-stat-table:not(.benchmark-compare-inline) td.num {
    width: auto;
    white-space: nowrap;
  }

  /* Simple comparison (self vs bench / A vs B): content-sized compact, both pages. */
  table.summary-table.benchmark-compare-inline:not(.wide-table):not(:has(.bench-cell)) {
    width: auto;
    max-width: none;
  }
  table.summary-table.benchmark-compare-inline:not(.wide-table):not(:has(.bench-cell)) th,
  table.summary-table.benchmark-compare-inline:not(.wide-table):not(:has(.bench-cell)) td {
    white-space: nowrap;
  }
  table.summary-table.benchmark-compare-inline:not(.wide-table):not(:has(.bench-cell)) th {
    width: auto;
  }
  table.summary-table.benchmark-compare-inline:not(.wide-table):not(:has(.bench-cell)) td.num {
    width: auto;
  }
  table.summary-table.benchmark-compare-inline:not(.wide-table):not(:has(.bench-cell)) thead th.bench-col-player {
    white-space: nowrap;
    word-break: normal;
  }
}

table.wide-table {
  font-size: 11px;
  line-height: 1.4;
}

table.wide-table th,
table.wide-table td {
  padding: 4px 6px;
  text-align: right;
}

table.wide-table th:first-child,
table.wide-table td:first-child {
  text-align: left;
}

table.wide-table th {
  width: auto;
  white-space: nowrap;
}

@media (min-width: 768px) {
  table.wide-table {
    font-size: 12px;
    line-height: 1.4;
  }
  table.wide-table th,
  table.wide-table td {
    padding: 6px 8px;
  }
}

.table-scroll {
  overflow-x: auto;
  max-width: 100%;
  margin-bottom: 12px;
  -webkit-overflow-scrolling: touch;
}

.table-scroll > table {
  margin-bottom: 0;
}

/* Plan A: pin row-label column while horizontal-scrolling wide tables only. */
.table-scroll > table.wide-table > thead > tr > th:first-child,
.table-scroll > table.wide-table > tbody > tr > th:first-child,
.table-scroll > table.wide-table > tbody > tr > td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #fff;
  box-shadow: 2px 0 0 rgba(28, 36, 48, 0.12);
}

.table-scroll > table.wide-table > thead > tr > th:first-child {
  z-index: 2;
  background: #eee;
}

.table-scroll > table.wide-table > tbody > tr > th:first-child {
  background: #eee;
}

.stat-section {
  margin-top: 8px;
  max-width: 100%;
  border: 1px solid var(--stats-line);
  border-radius: 8px;
  background: var(--stats-panel);
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(28, 36, 48, 0.03);
  /* Keep section title clear of sticky .stats-catnav after category switch. */
  scroll-margin-top: 5.5rem;
}

.stat-section:first-of-type {
  margin-top: 4px;
}

.stat-section > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
  color: var(--stats-ink);
  background: #eef3f8;
  list-style: none;
  border-bottom: 1px solid transparent;
  word-break: break-word;
  cursor: pointer;
  user-select: none;
}

.stat-section > summary::-webkit-details-marker {
  display: none;
}

.stat-section > summary::marker {
  content: "";
}

.stat-section > summary::before {
  content: "›";
  flex-shrink: 0;
  width: 1em;
  font-size: 16px;
  font-weight: 700;
  color: var(--stats-accent-deep);
  line-height: 1;
  transition: transform 0.12s ease;
}

.stat-section[open] > summary {
  background: #e4edf7;
  border-bottom-color: var(--stats-line);
}

.stat-section[open] > summary::before {
  transform: rotate(90deg);
  color: var(--stats-accent);
}

.stat-section > summary:hover {
  background: var(--stats-accent-soft);
}

.stat-section > summary:focus-visible {
  outline: 2px solid var(--stats-accent);
  outline-offset: -2px;
}

.stat-section > .inner {
  background: #fff;
  padding: 10px 14px 14px;
}

.metric-block {
  max-width: 100%;
  min-width: 0;
  margin-bottom: 16px;
}

.metric-block:last-child {
  margin-bottom: 4px;
}

.metric-block > .metric-block-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 8px;
  row-gap: 4px;
  margin: 0 0 10px;
  padding-bottom: 4px;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
  color: var(--stats-ink);
  border-bottom: 1px solid var(--stats-line-soft);
}

.metric-block > .metric-block-title > .metric-block-title-text {
  min-width: 0;
  max-width: 100%;
  word-break: break-word;
}

.metric-block .metric-body {
  max-width: 100%;
  min-width: 0;
}

@media (max-width: 767px) {
  .metric-block {
    margin-bottom: 12px;
  }

  .metric-block > .metric-block-title {
    margin-bottom: 8px;
    font-size: 13px;
  }
}

.metric-block--paid .paid-lock {
  font-size: 12px;
  margin: 0 0 10px;
  padding: 6px 8px;
  color: #7a5c00;
  background: #fff8e1;
  border: 1px solid #e0c080;
  border-radius: 4px;
}

.metric-block--paid .paid-lock a {
  color: #5c4400;
  font-weight: 700;
}

/* PLUS badge look: /shared/plan_badge.css (.cond-paid-badge). */
.paid-lock .cond-paid-badge {
  margin-right: 6px;
}

table.benchmark-compare-inline thead th.bench-col-player {
  white-space: normal;
  word-break: break-word;
  line-height: 1.35;
  font-size: 11px;
  font-weight: 600;
}

.details-breakdown-section {
  margin-bottom: 12px;
  max-width: 100%;
  min-width: 0;
}

.details-breakdown-title {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--stats-ink);
}

/* —— Plan B: tier hierarchy / KPI / block grid / detail group —— */

.stats-tier-heading {
  margin: 14px 0 10px;
  padding: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--stats-accent-deep);
  border: none;
}

.stats-tier-heading:first-child {
  margin-top: 2px;
}

.stats-primary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 14px;
  width: 100%;
}

.stats-kpi-card {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--stats-line);
  border-radius: 8px;
  background: linear-gradient(180deg, #f7fafc 0%, #fff 55%);
  box-shadow: 0 1px 0 rgba(28, 36, 48, 0.04);
}

.stats-kpi-label-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 8px;
  row-gap: 4px;
  margin: 0 0 6px;
}

.stats-kpi-label {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--stats-muted);
  line-height: 1.3;
  min-width: 0;
  word-break: break-word;
}

.stats-kpi-values {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stats-kpi-value {
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--stats-ink);
  line-height: 1.25;
  word-break: break-word;
}

.stats-kpi-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 8px;
}

.stats-kpi-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--stats-muted);
  min-width: 0;
  flex: 1 1 auto;
  word-break: break-word;
}

.stats-kpi-line .stats-kpi-value {
  font-size: 1.05rem;
  flex: 0 1 auto;
}

.stats-block-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 16px;
  margin: 0 0 12px;
  width: 100%;
  align-items: start;
}

.stats-block-grid-item {
  min-width: 0;
  margin-bottom: 0;
}

.stats-block-full {
  width: 100%;
}

.stats-detail-group {
  margin: 12px 0 4px;
  border: 1px solid var(--stats-line);
  border-radius: 8px;
  background: #fafbfc;
  overflow: hidden;
}

.stats-detail-summary {
  display: list-item;
  cursor: pointer;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 700;
  color: var(--stats-accent-deep);
  background: #f0f4f8;
  user-select: none;
}

.stats-detail-summary:hover {
  background: var(--stats-accent-soft);
}

.stats-detail-summary:focus-visible {
  outline: 2px solid var(--stats-accent);
  outline-offset: -2px;
}

.stats-detail-body {
  padding: 4px 12px 12px;
  background: #fff;
}

.stats-detail-body > .stats-tier-heading {
  margin-top: 8px;
}

@media (max-width: 1199px) {
  .stats-primary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 767px) {
  .stats-primary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .stats-kpi-value {
    font-size: 1.1rem;
  }

  .stats-block-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
}

@media (max-width: 420px) {
  .stats-primary-grid {
    grid-template-columns: 1fr;
  }
}
