/* Coach stats page (/coach/stats): the window picker, the treemap of
   where his board score goes, the bars of board score lost over time and
   the tooltip they share. coach-stats.js draws them. */

body.page-coach-stats { --mode: var(--mino-J); }

.stats-main {
  width: min(1200px, 100%);
}

.stats-sub {
  margin: 0.3rem 0 0;
  font-size: 0.9rem;
}

.stats-body {
  display: grid;
  gap: 1.2rem;
}

.stats-notice p {
  margin: 0 0 0.8rem;
  color: var(--muted);
}

/* The window picker: one row of buttons, the picked one lit in the
   page's colour, like the account tabs. */

.seg {
  display: inline-flex;
  gap: 0.2rem;
  padding: 0.2rem;
  border-radius: 0.6rem;
  background: rgba(0, 0, 0, 0.45);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5), 0 1px 0 rgba(255, 255, 255, 0.05);
}

.seg button {
  padding: 0.4rem 0.7rem;
  border: 1px solid transparent;
  border-radius: 0.45rem;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: var(--text-min);
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.12s ease, background 0.12s ease;
}

.seg button:hover {
  color: var(--text);
}

.seg button[aria-pressed="true"] {
  border-color: var(--mode-line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0) 55%),
    var(--mode-faint);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  color: #fff;
}

/* While a window loads, the panels keep the last one, dimmed. */
.stats-body.is-loading .panel {
  opacity: 0.5;
  transition: opacity 0.15s ease;
}

/* The legend: a swatch and a name per family, each opening what counts. */

.stats-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1rem;
  margin: 0 0 0.7rem;
}

.stats-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.1rem 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: var(--text-min);
  cursor: pointer;
}

.stats-legend-item:hover {
  color: var(--text);
}

.stats-swatch {
  display: inline-block;
  flex: none;
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 3px;
  background: var(--fam);
}

/* The treemap: every box placed absolutely by coach-stats.js. Families
   are an outline in their colour; kinds and leaves are smoked glass like
   .panel, tinted with the family's colour (--fam). Every box but the
   smallest has a title bar across its top, like window chrome: a darker
   shade of the family's colour, lit a little from above, with a hairline
   under it. Text is --text on every tint and every bar. */

.stats-treemap {
  position: relative;
  height: 440px;
}

@media (min-width: 761px) {
  .stats-treemap {
    height: 560px;
  }
}

/* On a portrait screen (layout.css) the treemap takes some of the height
   to spare, so more boxes are big enough for a title bar and a board. */
@media (min-width: 901px) and (max-aspect-ratio: 4/5) {
  .stats-treemap {
    height: clamp(560px, 36vh, 960px);
  }
}

.stats-treemap.is-empty {
  height: auto;
}

.tm-box {
  position: absolute;
  box-sizing: border-box;
}

/* A box less tall than its bar and border (a family 22 or 23px tall, the
   one kind of a small family) cuts the bar at its border. */
.tm-family {
  overflow: hidden;
  border: 2px solid color-mix(in srgb, var(--fam) 55%, transparent);
  border-radius: 7px;
}

.tm-kind,
.tm-leaf {
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--fam) 45%, rgba(255, 255, 255, 0.08));
  border-radius: 5px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.tm-kind {
  background:
    linear-gradient(180deg,
      rgba(255, 255, 255, 0.045) 0%,
      rgba(255, 255, 255, 0.015) 38%,
      rgba(255, 255, 255, 0) 38.5%),
    color-mix(in srgb, var(--fam) 7%, var(--panel));
}

.tm-leaf {
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg,
      rgba(255, 255, 255, 0.045) 0%,
      rgba(255, 255, 255, 0.015) 38%,
      rgba(255, 255, 255, 0) 38.5%),
    color-mix(in srgb, var(--fam) 14%, var(--panel));
  color: var(--text);
  text-decoration: none;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.tm-leaf:hover,
.tm-leaf:focus-visible {
  border-color: var(--fam);
  background:
    linear-gradient(180deg,
      rgba(255, 255, 255, 0.06) 0%,
      rgba(255, 255, 255, 0.02) 38%,
      rgba(255, 255, 255, 0) 38.5%),
    color-mix(in srgb, var(--fam) 24%, var(--panel));
  color: var(--text);
  text-decoration: none;
}

/* A title bar: 20px (statsview.js BAR) at every level, the name on one
   line and cut with an ellipsis, never dropped. A family's name is
   bolder. --shade is how much of the family's colour is in it; hovered,
   a little more. */
.tm-bar {
  --shade: 42%;
  display: block;
  flex: none;
  box-sizing: border-box;
  width: 100%;
  height: 20px;
  margin: 0;
  padding: 0 0.4rem;
  overflow: hidden;
  border: 0;
  border-bottom: 1px solid color-mix(in srgb, var(--fam) 50%, black);
  border-radius: 4px 4px 0 0;
  background:
    linear-gradient(180deg,
      rgba(255, 255, 255, 0.12) 0%,
      rgba(255, 255, 255, 0.04) 50%,
      rgba(255, 255, 255, 0) 52%,
      rgba(0, 0, 0, 0.14) 100%),
    color-mix(in srgb, var(--fam) var(--shade), #0b0c0f);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
  color: var(--text);
  font: inherit;
  font-size: var(--text-min);
  font-weight: 600;
  line-height: 19px;
  text-align: left;
  text-overflow: ellipsis;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.55);
  white-space: nowrap;
}

.tm-family > .tm-bar {
  border-radius: 5px 5px 0 0;
}

button.tm-bar {
  cursor: pointer;
}

.tm-bar-family {
  font-weight: 800;
}

.tm-leaf:hover > .tm-bar,
.tm-leaf:focus-visible > .tm-bar,
button.tm-bar:hover {
  --shade: 48%;
}

.tm-leaf:focus-visible,
button.tm-bar:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: -2px;
}

/* A leaf's board: under its bar, in what is left of the leaf less 6px
   all round (statsview.js LEAF_PAD less the border). */
.tm-board {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 6px;
}

.tm-board svg {
  display: block;
}

.stats-empty {
  margin: 0;
  padding: 2rem 0;
  color: var(--muted);
  text-align: center;
}

/* What counts: every family and kind with its line. */

.stats-criteria-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.stats-criteria-head .panel-title {
  margin: 0;
}

.stats-criteria-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr));
  gap: 1rem 1.6rem;
  margin-top: 0.6rem;
}

.crit-head {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0 0 0.25rem;
  font-size: 0.95rem;
}

.crit-line {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-size: var(--text-min);
}

.crit-kinds {
  margin: 0;
  font-size: var(--text-min);
}

.crit-kinds dt {
  margin-top: 0.4rem;
  font-weight: 700;
}

.crit-kinds dd {
  margin: 0.1rem 0 0;
  color: var(--muted);
}

.crit-family .is-marked {
  border-radius: 4px;
  background: color-mix(in srgb, var(--fam) 18%, transparent);
  color: var(--text);
}

.crit-kinds dt.is-marked,
.crit-kinds dd.is-marked,
.crit-line.is-marked,
.crit-head.is-marked {
  padding: 0.1rem 0.35rem;
}

/* The tables under the charts, closed until asked for. */

.stats-table {
  margin-top: 0.8rem;
  font-size: var(--text-min);
}

.stats-table summary {
  color: var(--muted);
  cursor: pointer;
}

.stats-table summary:hover {
  color: var(--text);
}

.stats-table-scroll {
  overflow-x: auto;
}

.stats-table table {
  margin-top: 0.4rem;
}

.stats-table th .stats-swatch {
  margin-right: 0.35rem;
}

.stats-table th {
  white-space: nowrap;
}

.stats-table .num {
  text-align: right;
}

/* The tooltip the treemap and the bars share. */

.stats-tip {
  position: fixed;
  z-index: 50;
  max-width: min(22rem, calc(100vw - 16px));
  padding: 0.6rem 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0) 40%),
    #1b1c21;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.6);
  color: var(--text);
  font-size: var(--text-min);
  line-height: 1.4;
  pointer-events: none;
}

.stats-tip p {
  margin: 0;
}

.stats-tip p + p {
  margin-top: 0.35rem;
}

.tip-what {
  color: var(--muted);
}

.tip-figures {
  font-weight: 700;
}

.tip-key {
  display: inline-block;
  width: 0.8rem;
  height: 2px;
  margin-right: 0.4rem;
  border-radius: 1px;
  background: var(--fam);
  vertical-align: middle;
}

.tip-split {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.4rem;
}

.tip-pie svg {
  display: block;
}

.stats-tip table {
  width: auto;
  font-size: var(--text-min);
}

.stats-tip th,
.stats-tip td {
  padding: 0.12rem 0.4rem;
  border: 0;
}

.stats-tip th {
  font-size: var(--text-min);
}

.stats-tip tbody tr:hover td,
.stats-tip tr:hover td {
  background: none;
}

.stats-tip .num {
  text-align: right;
}

.tip-kinds {
  margin-top: 0.4rem;
}

/* The bars: drawn at the panel's width, in the site's type. Gridlines
   are solid hairlines; text is never a family colour. */

.stats-bars svg {
  display: block;
  overflow: visible;
}

.stats-bars text {
  fill: var(--muted);
  font-family: var(--font-ui);
  font-size: var(--text-min);
  font-variant-numeric: tabular-nums;
}

.stats-bars .bars-axis-title {
  font-size: var(--text-min);
  font-weight: 700;
  letter-spacing: 0.06em;
}

.bars-grid {
  stroke: rgba(143, 144, 154, 0.14);
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.bars-base {
  stroke: rgba(143, 144, 154, 0.32);
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.bar-hit {
  cursor: default;
  outline: none;
}

.bar-hit:hover,
.bar-hit:focus-visible {
  fill: rgba(255, 255, 255, 0.05);
}

.bar-hit:focus-visible {
  stroke: var(--text);
  stroke-width: 1;
}

/* What counts: a kind's Drill link after its name, and under a kind that
   splits, a Drill link for each of its pieces in the window. */
.crit-kinds .crit-drill {
  margin-left: 0.35rem;
  font-size: var(--text-min);
  font-weight: 700;
}

.crit-kinds .crit-drills .crit-drill {
  margin-left: 0;
}
