/* stats.css — the Stats page. Tokens only (see DESIGN.md); every class is prefixed stats-.
   The page reuses the kit from styles.css (.eyebrow, .display-lg/.display-md with one <em>,
   .lede, .num, .card, .card--stitched, .well, .chip, .btn--ghost) and adds only layout. */

.stats {
  display: grid;
  gap: var(--section);
  color: var(--boba);
}

/* ---------- header: eyebrow, Cherry headline, one-sentence lede ---------- */

.stats-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--gap);
  margin-bottom: var(--gap);
  text-align: center;
}

.stats-head__title { color: var(--cherry); }
.stats-head__lede { text-wrap: balance; }

/* ---------- KPI row: plain paper tiles, rounded tabular numbers ---------- */

.stats-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--gap);
}

.stats-offline {
  margin: 0;
  padding: var(--pad);
  font-weight: 600;
  text-align: center;
  color: var(--cocoa);
}

.stats-tile {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  padding: 22px var(--pad) var(--pad);
}

.stats-tile__value {
  margin: 0;
  font-size: var(--fs-number);
  line-height: 1;
  color: var(--boba);
}

.stats-tile__cap {
  margin: 0;
  font-size: var(--fs-caption);
  font-weight: 600;
  line-height: 1.4;
  color: var(--taro);
}

/* ---------- your taste: the stitched keepsake, a Petal bow on its top edge ---------- */

.stats-taste {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  align-items: center;
  gap: var(--pad) 40px;
  margin-block: var(--gap);
  padding: 44px 40px 36px;
}

/* the bow overlaps the top stitch the way it does on the contender frames */
.stats-taste__bow {
  position: absolute;
  left: 50%;
  top: -32px;
  z-index: 2;
  width: 92px;
  height: auto;
  translate: -50% 0;
  pointer-events: none;
}

.stats-taste__main {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
}

.stats-taste__title { color: var(--cherry); }

.stats-taste__scoreRow {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--gap);
  max-width: 100%;
  margin-top: 6px;
}

.stats-taste__score {
  font-size: var(--fs-display-lg);
  line-height: 0.9;
  letter-spacing: -0.02em;
  color: var(--boba);
}

.stats-taste__name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stats-taste__note {
  margin: 0;
  color: var(--cocoa);
}

/* three facts on a shared subgrid, so a label that wraps pushes every value down together */
.stats-taste__facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: auto auto auto;
  gap: 8px var(--gap);
  min-width: 0;
  padding: 22px var(--pad);
}

.stats-fact {
  display: grid;
  grid-row: span 3;
  grid-template-rows: subgrid;
  min-width: 0;
}

.stats-fact > .micro { align-self: end; }

.stats-taste__facts--empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.stats-taste__emptyArt {
  width: 40px;
  height: auto;
  rotate: -8deg;
}

.stats-fact__value {
  font-size: var(--fs-number);
  line-height: 1;
  color: var(--boba);
}

.stats-fact__cap {
  font-size: var(--fs-caption);
  font-weight: 600;
  line-height: 1.35;
  color: var(--taro);
}

.stats-empty {
  margin: 0;
  padding: 4px var(--gap);
  font-weight: 600;
  text-align: center;
  color: var(--cocoa);
}

/* ---------- the distribution chart ---------- */

.stats-chart {
  min-width: 0;
  padding: 36px 40px 30px;
}

/* Hello Kitty with her bouquet peeks over the chart card's top-right corner */
.stats-chart::after {
  content: "";
  position: absolute;
  right: 30px;
  top: -30px; /* rises into the 32px gap, never onto the card above */
  width: 76px;
  aspect-ratio: 1;
  background: url("/assets/stickers/emoji/glowing-star.webp") center / contain no-repeat;
  rotate: 6deg;
  pointer-events: none;
}

.stats-chart__head {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: var(--gap);
}

.stats-chart__title { color: var(--cherry); }

.stats-chart__cap {
  margin: 0;
  color: var(--cocoa);
}

.stats-chart__plot {
  position: relative;
  min-width: 0;
}

.stats-chart__svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

/* axis text wears text tokens, never the bar colour */
.stats-chart__svg text {
  font-family: var(--font-body);
  font-size: var(--fs-micro);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  fill: var(--taro);
}

.stats-grid { stroke: var(--blush); }
.stats-axis { stroke: var(--lace); }
.stats-hit { fill: transparent; }

/* Petal Strong, not Petal: plain Petal fails the lightness band and chroma floor on white
   (validator: L 0.82, C 0.099). Petal Strong vs Cherry separates at deltaE 18 under CVD. */
.stats-bar { fill: var(--petal-strong); }
.stats-bar--mark { fill: var(--cherry); }
.stats-band:hover .stats-bar { fill: var(--petal); }
.stats-band:hover .stats-bar--mark { fill: var(--cherry-deep); }

.stats-note__lead { stroke: var(--mauve); }
.stats-note__dot { fill: var(--cherry); stroke: var(--white); }

.stats-chart__svg .stats-note__text {
  font-size: var(--fs-caption);
  font-weight: 800;
  fill: var(--boba);
}

.stats-chart__svg .stats-note__num { fill: var(--cocoa); }

.stats-tip {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  display: grid;
  gap: 2px;
  padding: 8px var(--gap);
  transform: translate(-50%, -100%);
  background: var(--white);
  border: 1px solid var(--lace);
  border-radius: var(--r-ctl);
  box-shadow: var(--shadow-paper);
  white-space: nowrap;
  pointer-events: none;
}

/* beside the marked bar instead of above it (js sets left to the tooltip's own edge) */
.stats-tip--side { transform: translate(0, -50%); }

.stats-tip__val {
  font: 800 var(--fs-body)/1.2 var(--font-body);
  font-variant-numeric: tabular-nums;
  color: var(--boba);
}

.stats-tip__lab {
  font: 600 var(--fs-caption)/1.2 var(--font-body);
  color: var(--taro);
}

/* the table twin of the chart */
.stats-table { margin-top: 18px; }
.stats-table summary::-webkit-details-marker { display: none; }

.stats-table__scroll {
  overflow-x: auto;
  margin-top: var(--gap);
}

.stats-table table {
  width: 100%;
  max-width: 420px;
  border-collapse: collapse;
  font: 600 var(--fs-caption)/1.4 var(--font-body);
  color: var(--cocoa);
}

.stats-table th,
.stats-table td {
  padding: 8px var(--gap) 8px 0;
  text-align: left;
  border-bottom: 1px solid var(--blush);
}

.stats-table th {
  font-size: var(--fs-micro);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--taro);
}

.stats-table th:last-child,
.stats-table td.num {
  padding-right: 0;
  text-align: right;
}

.stats-table td.num {
  font-size: var(--fs-body);
  color: var(--boba);
}

.stats-table__you {
  margin-left: 6px;
  padding-block: 0;
  background: var(--petal-soft);
  color: var(--cherry-deep);
}

/* ---------- how it scores ---------- */

.stats-explain {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  align-items: start;
  gap: var(--pad) 48px;
  padding: 40px;
  overflow: hidden;
}

.stats-explain__head {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.stats-explain__title { color: var(--cherry); }

/* Momo sits at the foot of the headline column, tilted like the duel mascots */
.stats-explain__art {
  width: 128px;
  height: auto;
  margin-top: auto;
  padding-top: var(--pad);
  rotate: -6deg;
}

.stats-explain__body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stats-explain__body p {
  margin: 0;
  font-size: var(--fs-lede);
  line-height: 1.5;
  color: var(--cocoa);
  text-wrap: pretty;
}

/* ---------- narrow ---------- */

@media (max-width: 960px) {
  .stats-taste {
    grid-template-columns: minmax(0, 1fr);
  }
}

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

  .stats-tile {
    padding: 18px 18px 20px;
  }

  .stats-taste {
    padding: 40px 22px 22px;
  }

  .stats-taste__facts {
    gap: 8px;
    padding: 16px;
  }

  .stats-chart {
    padding: 28px 20px 20px;
  }

  .stats-chart::after {
    right: 14px;
    top: -28px;
    width: 58px;
  }

  .stats-explain {
    grid-template-columns: minmax(0, 1fr);
    padding: 28px 22px;
  }

  /* Momo tucks into the corner beside the headline instead of taking a row */
  .stats-explain__head {
    position: relative;
    padding-right: 84px;
  }

  .stats-explain__art {
    position: absolute;
    right: -6px;
    top: -6px;
    width: 76px;
    margin: 0;
    padding: 0;
  }

  .stats-explain__body p {
    font-size: var(--fs-body);
  }
}
