/*
  Charts: percentile bars, rank-change chips, sparklines, the rank-history line chart, the radar,
  the histogram, horizontal and stacked bars, counters. Colours come from --hue (a category hue,
  inherited from the closest element that sets it) with the accent as the fallback.
*/

/* ------------------------------------------------------------------ percentile bar */

.pbar {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
  width: 100%;
  font-variant-numeric: tabular-nums;
}

.pbar__track {
  position: relative;
  flex: 1 1 auto;
  max-width: 4.5rem;
  height: 4px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--rule);
}

.pbar__fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--p, 0%);
  border-radius: inherit;
  background: var(--hue, var(--accent));
  transform-origin: left center;
  animation: bar-grow 700ms var(--ease-out) both;
}

.pbar__num {
  min-width: 1.6rem;
  color: var(--muted);
  font-size: var(--fs-small);
  text-align: right;
}

@keyframes bar-grow {
  from {
    transform: scaleX(0);
  }
}

/* ------------------------------------------------------------------ rank change chip */

.chg {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  min-width: 2.1rem;
  padding: 0.05rem 0.4rem;
  border-radius: 99px;
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chg--up {
  background: var(--up-soft);
  color: var(--up);
}

.chg--down {
  background: var(--down-soft);
  color: var(--down);
}

.chg--same {
  justify-content: center;
  color: var(--faint);
}

.chg__icon {
  width: 8px;
  height: 8px;
}

.chg--compact {
  min-width: 0;
  padding: 0 0.3rem;
}

/* ------------------------------------------------------------------ sparkline */

.spark {
  display: block;
  overflow: visible;
}

.spark--empty {
  display: inline-block;
  width: 76px;
  height: 1px;
  background: var(--rule);
  vertical-align: middle;
}

.spark__line {
  stroke: var(--muted);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.spark--up .spark__line {
  stroke: var(--up);
}

.spark--down .spark__line {
  stroke: var(--down);
}

.spark__dot {
  fill: var(--ink);
}

/* ------------------------------------------------------------------ line chart */

.lchart {
  position: relative;
  border-radius: var(--radius-sm);
}

.lchart:focus-visible {
  outline: 1.5px solid var(--ink);
  outline-offset: 6px;
}

.lchart__svg {
  width: 100%;
  overflow: hidden;
}

.lchart__svg svg {
  display: block;
  max-width: none;
}

.lchart__tick line {
  stroke: var(--rule);
  stroke-width: 1;
}

.lchart__tick text,
.lchart__x {
  fill: var(--muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.lchart__endlabel {
  fill: var(--hue, var(--accent));
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.lchart__line {
  stroke: var(--hue, var(--accent));
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 0;
  animation: line-draw 1100ms var(--ease-out) both;
}

@keyframes line-draw {
  from {
    stroke-dashoffset: 1;
  }
}

.lchart__end {
  fill: var(--hue, var(--accent));
  stroke: var(--bg);
  stroke-width: 2;
}

.lchart__guide {
  stroke: var(--rule-strong);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.lchart__dot {
  fill: var(--bg);
  stroke: var(--hue, var(--accent));
  stroke-width: 2;
}

.lchart__hit {
  cursor: crosshair;
}

.lchart__tip {
  position: absolute;
  top: 0;
  left: var(--x, 50%);
  display: grid;
  gap: 0.1rem;
  min-width: 7.5rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  box-shadow: var(--shadow-lift);
  color: var(--body);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
  transform: translate(-50%, -105%);
  pointer-events: none;
}

.lchart__day {
  color: var(--muted);
}

.lchart__row--one {
  gap: 0;
}

.lchart__row--one strong {
  margin-left: 0;
  color: var(--ink);
}

.lchart__row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}

.lchart__row strong {
  margin-left: auto;
}

.lchart__swatch {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--hue, var(--accent));
}

.lchart__empty {
  padding: 2rem 0;
}

/* ------------------------------------------------------------------ radar */

.radar-wrap {
  margin: 0;
}

.radar {
  width: 100%;
  max-width: 420px;
  height: auto;
  margin: 0 auto;
  overflow: visible;
}

.radar__ring {
  fill: none;
  stroke: var(--rule);
  stroke-width: 1;
}

.radar__ring--outer {
  stroke: var(--rule-strong);
}

.radar__spoke {
  stroke: var(--rule);
  stroke-width: 1;
}

.radar__label {
  fill: var(--hue, var(--muted));
  font-size: var(--radar-label, 12.5px);
  font-weight: 600;
}

/* the values under each label: "84", or "98 · 100" in Compare (each in its player's colour) */
.radar__val {
  fill: var(--muted);
  font-size: calc(var(--radar-label, 12.5px) * 0.92);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  transition: opacity var(--ease);
}

.radar__v--0,
.radar__v--1 {
  fill: var(--hue);
}

.radar__sep {
  fill: var(--faint);
}

/* the profile shows them while the chart is pointed at or focused */
.radar--hover-values .radar__val {
  opacity: 0;
}

.radar-wrap:hover .radar--hover-values .radar__val,
.radar-wrap:focus-visible .radar--hover-values .radar__val {
  opacity: 1;
}

.radar-wrap:focus-visible {
  outline: 1.5px solid var(--ink);
  outline-offset: 4px;
  border-radius: var(--radius-sm);
}

.radar__area {
  fill: var(--hue, var(--accent));
  fill-opacity: 0.16;
  stroke: var(--hue, var(--accent));
  stroke-width: 1.75;
  stroke-linejoin: round;
}

.radar__series {
  transform-origin: 50% 50%;
  transform-box: view-box;
  animation: radar-in 800ms var(--ease-out) both;
}

.radar__series + .radar__series {
  animation-delay: 120ms;
}

.radar__dot {
  fill: var(--bg);
  stroke: var(--hue, var(--accent));
  stroke-width: 1.75;
}

@keyframes radar-in {
  from {
    opacity: 0;
    transform: scale(0.4);
  }
}

/* ------------------------------------------------------------------ histogram */

.histo {
  margin: 0;
}

.histo__plot {
  position: relative;
}

.histo__bars {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 96px;
  padding-bottom: 1px;
  border-bottom: 1px solid var(--rule-strong);
}

.histo__bar {
  position: relative;
  flex: 1 1 0;
  height: 100%;
  display: flex;
  align-items: flex-end;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 3px 3px 0 0;
  background: none;
  color: inherit;
}

button.histo__bar {
  cursor: pointer;
}

button.histo__bar:focus-visible {
  outline: 1.5px solid var(--ink);
  outline-offset: 2px;
}

/* Solid bars: the hue mixed into the panel (never see-through mud); the top 10 % in the full hue. */
.histo__fill {
  width: 100%;
  height: max(var(--v), 2px);
  border-radius: 3px 3px 1px 1px;
  background: color-mix(in oklab, var(--hue, var(--accent)) 62%, var(--surface));
  transform-origin: bottom;
  animation: histo-grow 700ms var(--ease-out) both;
  transition: height 420ms var(--ease-out), background-color var(--ease), box-shadow var(--ease);
}

.histo__bar.is-strong .histo__fill {
  background: var(--hue, var(--accent));
}

.histo__bar.is-empty .histo__fill {
  height: 2px;
  background: var(--rule-strong);
}

.histo__bar.is-mark .histo__fill,
.histo__bar:hover .histo__fill,
.histo__bar:focus-visible .histo__fill {
  background: var(--ink);
}

.histo__bar.is-picked .histo__fill {
  background: var(--ink);
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--hue, var(--accent));
}

/* Reference lines (median, top 10%): dashed, with a small tag on top. */
.histo__refs {
  position: absolute;
  inset: 0 0 1px;
  pointer-events: none;
}

.histo__line {
  position: absolute;
  top: -0.35rem;
  bottom: 0;
  left: var(--x);
  width: 0;
  border-left: 1px dashed var(--muted);
}

.histo__line--alt {
  border-left-color: var(--hue, var(--accent));
}

.histo__line-tag {
  position: absolute;
  bottom: 100%;
  left: 0;
  padding: 0 0.3rem;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.2;
  white-space: nowrap;
  transform: translate(-50%, -0.1rem);
}

.histo__line.is-start .histo__line-tag {
  transform: translate(-0.3rem, -0.1rem);
}

.histo__line.is-end .histo__line-tag {
  transform: translate(calc(-100% + 0.3rem), -0.1rem);
}

.histo__line--alt .histo__line-tag {
  color: var(--hue, var(--accent-ink));
}

@keyframes histo-grow {
  from {
    transform: scaleY(0);
  }
}

/* x axis: 0, 25, 50, 75 and 100 % of the best score */
.histo__axis {
  position: relative;
  height: 1.4rem;
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}

.histo__tick {
  position: absolute;
  top: 0;
  left: var(--x);
  transform: translateX(-50%);
  white-space: nowrap;
}

.histo__tick:first-child {
  transform: none;
}

.histo__tick:last-child {
  transform: translateX(-100%);
}

.histo__tip {
  position: absolute;
  bottom: calc(100% + 0.6rem);
  left: var(--x, 50%);
  z-index: 3;
  display: grid;
  gap: 0.15rem;
  min-width: 8.5rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  box-shadow: var(--shadow-lift);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
  transform: translateX(-50%);
  pointer-events: none;
}

.histo__tip-n {
  color: var(--ink);
  font-weight: 600;
}

.histo__tip-range {
  color: var(--muted);
}

.histo__tip-faces {
  display: inline-flex;
  align-items: center;
  margin-top: 0.25rem;
}

@media (max-width: 640px) {
  .histo__bars {
    height: 68px;
    gap: 2px;
  }

  .histo__tick:nth-child(2),
  .histo__tick:nth-child(4) {
    display: none;
  }
}

/* ------------------------------------------------------------------ horizontal bars */

.hbars {
  display: grid;
  gap: 0.15rem;
}

.hbars__row {
  display: grid;
  grid-template-columns: minmax(7rem, 11rem) minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.9rem;
  padding: 0.3rem 0;
  font-size: 0.95rem;
}

.hbars__label {
  min-width: 0;
  overflow: hidden;
  color: var(--body);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hbars__track {
  position: relative;
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--surface-2);
}

.hbars__fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--w);
  border-radius: inherit;
  background: var(--hue, var(--accent));
  opacity: 0.85;
  transform-origin: left;
  animation: bar-grow 800ms var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 40ms);
}

.hbars__value {
  min-width: 3.5rem;
  color: var(--ink);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

@media (max-width: 640px) {
  .hbars__row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.2rem 0.75rem;
  }

  .hbars__track {
    grid-column: 1 / -1;
    grid-row: 2;
  }
}

/* ------------------------------------------------------------------ stacked bar */

.stack {
  margin: 0;
}

.stack__bar {
  display: flex;
  gap: 2px;
  height: 14px;
  overflow: hidden;
  border-radius: 99px;
}

.stack__seg {
  flex: 0 0 var(--w);
  min-width: 3px;
  background: var(--seg, var(--hue));
  transform-origin: left;
  animation: bar-grow 900ms var(--ease-out) both;
}

.stack__legend {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.35rem 1.5rem;
  margin-top: 1rem;
  font-size: var(--fs-small);
  font-variant-numeric: tabular-nums;
}

.stack__legend li {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.stack__swatch {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: var(--seg, var(--hue));
  transform: translateY(1px);
}

.stack__name {
  color: var(--body);
}

.stack__val {
  margin-left: auto;
  color: var(--ink);
  font-weight: 500;
}

.stack__pct {
  min-width: 2.75rem;
  color: var(--muted);
  text-align: right;
}

/* ------------------------------------------------------------------ counters */

.counter {
  font-variant-numeric: tabular-nums;
}

.lchart__svg.is-redrawn .lchart__line {
  animation: none;
}

/* ------------------------------------------------------------------ mini bar (48 px share) */

.minibar {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 5px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--surface-3);
  vertical-align: middle;
}

.minibar__fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--p);
  border-radius: inherit;
  background: var(--hue, var(--accent));
  transform-origin: left;
  animation: bar-grow 700ms var(--ease-out) both;
}

