/* Charts of the ZSAS project page (assets/js/charts.js).
   Colours come from the custom properties of site.css: amber for ZSAS, blue for the method it is compared with,
   and a muted blue-grey for every other method. The .seg control, .tablewrap and .visually-hidden are site.css rules. */

.chart {
  --chart-ours: var(--answer);
  --chart-ref: var(--ordinary);
  --chart-other: color-mix(in srgb, var(--bar) 62%, var(--ink-3));
  margin: 2rem 0 0;
}
/* the page's dark blue is too grey for a small mark; this step keeps the hue and passes the chroma check */
:root[data-theme="dark"] .chart { --chart-ref: #5d9be8; }

.chart-card { background: var(--surface); border: 1px solid var(--rule); border-radius: 0.7rem;
  padding: clamp(0.9rem, 2.2vw, 1.4rem); min-width: 0; }

/* controls: one row above the card */
.chart-controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.7rem 1.4rem; margin: 0 0 0.8rem; }
.chart-controls:empty, .chart-legend:empty { display: none; }
.chart-field { border: 0; padding: 0; margin: 0; min-width: 0; display: flex; flex-direction: column; gap: 0.3rem; }
.chart-lab { font-size: 0.8rem; font-weight: 600; color: var(--ink-3); font-stretch: var(--narrow); }
.chart-field .seg { display: inline-flex; }
.chart-field .seg label { padding: 0.34rem 0.7rem; font-size: 0.86rem; }
.chart-field select { appearance: none; -webkit-appearance: none; background: var(--sunk); border: 1px solid transparent;
  border-radius: 0.55rem; padding: 0.42rem 2rem 0.42rem 0.75rem; font-size: 0.9rem; font-weight: 600; color: var(--ink); cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 1rem) 55%, calc(100% - 0.7rem) 55%; background-size: 0.3rem 0.3rem; background-repeat: no-repeat; }
.chart-field select:hover { border-color: var(--rule); }

/* switches of the ablation */
.chart-switches { display: flex; flex-wrap: wrap; gap: 0.5rem 0.6rem; }
.chart-switch { position: relative; display: inline-flex; align-items: center; gap: 0.55rem; padding: 0.4rem 0.8rem 0.4rem 0.5rem;
  border: 1px solid var(--rule); border-radius: 999px; font-size: 0.9rem; color: var(--ink-2); cursor: pointer; user-select: none; }
.chart-switch input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.chart-switch i { flex: none; width: 1.9rem; height: 1.1rem; border-radius: 999px; background: var(--rule); position: relative; }
.chart-switch i::after { content: ""; position: absolute; top: 0.15rem; left: 0.15rem; width: 0.8rem; height: 0.8rem; border-radius: 50%;
  background: var(--surface); box-shadow: var(--lift); transition: transform 0.15s ease; }
.chart-switch:has(input:checked) { color: var(--ink); border-color: var(--ink-3); }
.chart-switch:has(input:checked) i { background: var(--chart-ours); }
.chart-switch:has(input:checked) i::after { transform: translateX(0.8rem); }
.chart-switch:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.chart-switch:has(input:disabled) { opacity: 0.55; cursor: not-allowed; border-style: dashed; }
.chart-switch:has(input:disabled) input { cursor: not-allowed; }
.chart-hint { font-size: 0.82rem; color: var(--ink-3); }
.chart-hint[hidden] { display: none; }

/* legend and read-out: text in the text inks, identity from the swatch beside it */
.chart-legend { list-style: none; display: flex; flex-wrap: wrap; gap: 0.3rem 1.2rem; margin: 0 0 0.6rem; padding: 0;
  font-size: 0.86rem; color: var(--ink-2); }
.chart-legend li { display: inline-flex; align-items: center; gap: 0.45rem; }
.chart-key { flex: none; display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 50%; background: var(--chart-other); }
.chart-key.ours { background: var(--chart-ours); }
.chart-key.ref { background: var(--chart-ref); }
.chart-key.tick { width: 2px; height: 0.9rem; border-radius: 0; background: var(--chart-ours); }
.chart-key.rule { width: 2px; height: 0.9rem; border-radius: 0; background: var(--ink-3); }
.chart-readout { margin: 0.7rem 0 0; min-height: 3.1em; font-size: 0.92rem; line-height: 1.5; color: var(--ink-2); max-width: 60rem; }
.chart-readout b { color: var(--ink); font-weight: 640; }
.chart-readout .chart-key { margin: 0 0.3rem 0 0; vertical-align: 0.02em; }
.chart-readout span { white-space: nowrap; }

/* plot */
.chart-plot { min-width: 0; }
.chart-pair { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 1rem clamp(1.5rem, 4vw, 3rem); align-items: start; }
.chart-panel { min-width: 0; }
.chart-sub { margin: 0 0 0.5rem; font-size: 0.92rem; font-weight: 640; color: var(--ink); }
.chart-svg { display: block; max-width: 100%; overflow: visible; font-stretch: var(--narrow); }
.chart-svg text { font-size: 12.5px; fill: var(--ink-2); }
.chart-svg .label { fill: var(--ink); font-size: 13px; }
.chart-svg .group { fill: var(--ink-3); font-size: 11.5px; font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase; }
.chart-svg .val { fill: var(--ink); font-weight: 600; }
.chart-svg .sub { fill: var(--ink-3); font-weight: 500; }
/* behind a value that would sit on a reference line: the colour of whatever is behind the row */
.chart-svg .mask { fill: var(--surface); }
.chart-svg .row.is-active .mask { fill: var(--sunk); }
.chart-svg .tick, .chart-svg .axis { fill: var(--ink-3); font-size: 12px; }
.chart-svg .grid { stroke: var(--rule-soft); stroke-width: 1; }
.chart-svg .grid.zero { stroke: var(--ink-3); }
.chart-svg .band { fill: transparent; }
.chart-svg .row, .chart-svg .point { outline: none; }
.chart-svg .row.is-active .band { fill: var(--sunk); }
.chart-svg .row:focus-visible .band { stroke: var(--focus); stroke-width: 2; }
.chart-svg .dot { fill: var(--chart-other); }
.chart-svg .dot.ref { fill: var(--chart-ref); }
.chart-svg .dot.ours { fill: var(--chart-ours); }
.chart-svg .dot.ring { stroke: var(--surface); stroke-width: 2; }
.chart-svg .row.is-active .dot.ring { stroke: var(--sunk); }
.chart-svg .link { stroke: var(--ink-3); stroke-width: 2; stroke-linecap: round; opacity: 0.55; }
.chart-svg .bar { fill: var(--chart-other); }
.chart-svg .bar.ours, .chart-svg .is-ours .bar { fill: var(--chart-ours); }
.chart-svg .mean { stroke: var(--ink-3); stroke-width: 2; }
.chart-svg .full { stroke: var(--chart-ours); stroke-width: 2; }
.chart-svg .hit { fill: transparent; }
.chart-svg .point.is-active .halo { fill: var(--sunk); }
.chart-svg .point:focus-visible .halo { stroke: var(--focus); stroke-width: 2; fill: var(--sunk); }
.chart-svg .halo { fill: transparent; }
.chart-svg .hint { fill: var(--ink-3); font-size: 12px; font-style: italic; }

/* table view */
.chart-data { margin: 0.6rem 0 0; font-size: 0.88rem; }
.chart-data summary { cursor: pointer; color: var(--link); width: max-content; padding: 0.2rem 0; }
.chart-data summary:hover { text-decoration: underline; }
.chart-data .tablewrap { margin-top: 0.6rem; }
.chart-data table { border-collapse: collapse; width: 100%; font-size: 0.86rem; }
.chart-data th, .chart-data td { padding: 0.4rem 0.7rem; border-bottom: 1px solid var(--rule-soft); text-align: right; white-space: nowrap; }
.chart-data th:first-child, .chart-data td:first-child { text-align: left; }
.chart-data thead th { color: var(--ink-3); font-weight: 600; font-size: 0.8rem; border-bottom-color: var(--rule); }
.chart-data tbody th { font-weight: 600; color: var(--ink); }
.chart-data tbody tr:last-child th, .chart-data tbody tr:last-child td { border-bottom: 0; }
.chart-data tr.is-ours th, .chart-data tr.is-ours td { background: var(--answer-soft); }

@media (max-width: 46rem) {
  .chart-pair { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  .chart-switch i::after { transition: none; }
}
