.topbar-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 8px;
}
.topbar-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.topbar-icon[aria-pressed="true"] {
  border-color: var(--accent2);
  color: var(--accent2);
}

body.mode-stats .capture-notice,
body.mode-stats .select-status,
body.mode-stats .nocap,
body.mode-stats .onboarding,
body.mode-stats .stats-summary,
body.mode-stats .dance-gallery,
body.mode-stats .stage,
body.mode-stats .foot,
body.mode-stats .pwa-prompt {
  display: none;
}
body.mode-stats {
  overflow: auto;
}
body.mode-stats .topbar {
  position: relative;
  inset: auto;
  z-index: auto;
}
body.mode-stats.mode-dance .source-picker-control:not([hidden]) {
  display: none;
}
body.mode-dance .stats-summary {
  display: none;
}

@media (min-width: 700px) and (max-width: 1024px) and (orientation: portrait) and (min-aspect-ratio: 3 / 4) {
  body.mode-stats.mode-dance .topbar {
    width: auto;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 12px;
    padding: calc(10px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) 10px
      calc(14px + env(safe-area-inset-left));
  }
  body.mode-stats.mode-dance .topbar h1 {
    margin-right: auto;
  }
}

.stats-summary {
  width: min(calc(100% - 28px), 1120px);
  margin: 14px auto 0;
}
.stats-summary[hidden] {
  display: none;
}
.stats-summary button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  min-height: 52px;
  padding: 10px 14px;
  border-color: #2a2a38;
  background: linear-gradient(110deg, #ff2d7817, #34e5ff0f);
  text-align: left;
}
.stats-summary span {
  color: var(--dim);
  font-size: 12px;
}
.stats-summary b {
  color: var(--fg);
  font-size: 12px;
  white-space: nowrap;
}

.stats-page {
  width: min(calc(100% - 28px), 960px);
  margin: 0 auto;
  padding: 26px 0 calc(40px + env(safe-area-inset-bottom));
}
.stats-page[hidden] {
  display: none;
}
.stats-page-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}
.stats-page-head h2,
.stats-page-head p {
  margin: 0;
}
.stats-page-head h2 {
  font-size: clamp(24px, 4vw, 34px);
  letter-spacing: -0.04em;
}
.stats-page-head p {
  margin-top: 3px;
  color: var(--dim);
  font-size: 12px;
}
.stats-back {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 20px;
}
.stats-overview {
  padding: 18px;
  border: 1px solid #292936;
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 90% 0, #34e5ff14, transparent 34%),
    radial-gradient(circle at 0 100%, #ff2d7814, transparent 38%), var(--panel);
}
.stats-overview dl {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
}
.stats-overview div {
  min-width: 0;
}
.stats-overview dt {
  color: var(--dim);
  font-size: 11px;
}
.stats-overview dd {
  margin: 5px 0 0;
  overflow-wrap: anywhere;
  font-size: clamp(17px, 3vw, 24px);
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}
.stats-empty {
  margin: 18px 0 0;
  padding: 34px 18px;
  border: 1px dashed #2a2a38;
  border-radius: var(--radius);
  color: var(--dim);
  text-align: center;
}
.stats-empty[hidden],
.global-stats-content[hidden] {
  display: none;
}
.global-stats-content {
  --padtop: 18px;
  --plot: 148px;
  margin-top: 18px;
  padding: 18px;
  border: 1px solid #292936;
  border-radius: var(--radius);
  background: var(--panel);
}
.stats-filter {
  margin-top: 10px;
}
.results-filter label {
  display: flex;
  align-items: center;
  gap: 8px;
}
.chart-track.metric-time:not(.grouped) .bar {
  width: 64px;
}
.chart-track.metric-time .bar-val {
  white-space: nowrap;
}
.stats-filter-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}
.stats-filter-controls label {
  display: grid;
  flex: 0 1 auto;
  min-width: 90px;
  gap: 5px;
  color: var(--dim);
  font-size: 11px;
}
.stats-filter-controls label[hidden] {
  display: none;
}
.stats-filter-controls select {
  min-height: 38px;
  padding: 6px 30px 6px 10px;
  border: 1px solid #2a2a38;
  border-radius: 8px;
  background: #10101a;
  color: var(--fg);
  font: inherit;
}
.stats-filter-controls select:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: 2px;
}
.stats-filter-context {
  min-height: 1.4em;
  margin: 10px 0 0;
  color: var(--dim);
  font-size: 11px;
  text-align: right;
}
.global-chart {
  margin-top: 8px;
}
.global-stats-foot {
  margin-top: 10px;
}

@media (max-width: 600px) {
  .stats-page {
    padding-top: 18px;
  }
  .stats-overview dl {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .global-stats-content {
    --plot: 112px;
    padding: 14px;
  }
  .stats-filter-controls {
    justify-content: stretch;
  }
  /* 필터가 셋이 되면서 한 줄에 끼면 select 글자가 잘린다 — 좁으면 줄을 넘긴다. */
  .stats-filter-controls label {
    flex: 1 1 140px;
  }
  .stats-filter-controls select {
    width: 100%;
  }
  .stats-summary button {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }
}

@media (hover: none), (pointer: coarse) {
  .topbar-icon,
  .stats-filter-controls select {
    min-width: 44px;
    min-height: 44px;
  }
}
