/* Figures: the mount and row layouts every interactive figure sits in, the
   shared control widgets (buttons, readouts, check rows), the graph
   primitives, and the chapter-specific figures built on top of them.

   Split out of site-theme.css; loaded in order from _quarto.yml. */

/* Replay covers take focus on click, but only keyboard focus needs a ring.
   Apply this to both SVG roots and HTML wrappers. */
[data-cover-replay]:focus:not(:focus-visible) {
  outline: none;
}

[data-cover-replay]:focus-visible {
  outline: 2px solid var(--sfs-focus);
  outline-offset: 4px;
}

/* Small-multiple rows: interactive figures laid out side by side. */
.sfs-figure-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 0.75rem;
  margin: 1.25rem 0;
}

.sfs-figure-row > .interactive-figure-mount {
  flex: 1 1 7.5rem;
  min-width: 7rem;
  max-width: 15rem;
  margin: 0;
}

/* Wider variant: two larger panels per row (e.g. 2x2 grids). */
.sfs-figure-row.sfs-figure-row-wide > .interactive-figure-mount {
  flex-basis: 14rem;
  min-width: 12rem;
  max-width: 22rem;
}

.sfs-figure-row .sfs-figure {
  margin: 0;
}

/* Likert items: one response card can contain a short multi-item scale. */
.likert-card {
  --sfs-figure-max-width: 46rem;
  width: fit-content;
  padding: 1rem;
  border: 1px solid var(--sfs-border);
  border-radius: var(--sfs-radius-md);
  background: var(--sfs-bg);
  text-align: left;
}

.likert-card.likert-multiple {
  width: min(100%, var(--sfs-figure-max-width));
}

.likert-card.likert-align-responses {
  container-type: inline-size;
}

.likert-groups {
  display: grid;
  gap: 1.25rem 2rem;
}

.likert-multiple .likert-groups {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
}

.likert-group {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.likert-group legend {
  float: none;
  width: auto;
  margin: 0 0 0.65rem;
  padding: 0;
  color: var(--sfs-text);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.35;
}

@container (min-width: 40rem) {
  .likert-align-responses .likert-group legend {
    min-height: var(--likert-question-min-height);
  }
}

.likert-options {
  display: grid;
  gap: 0.2rem;
}

.likert-label {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  min-height: 1.55rem;
  line-height: 1.35;
  cursor: pointer;
}

.likert-button {
  flex: 0 0 auto;
  width: 1rem;
  height: 1rem;
  margin: 0.17rem 0 0;
}

.sfs-chart-wrap {
  position: relative;
  min-width: 0;
  overflow: visible;
}

.sfs-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.sfs-control-grid {
  display: grid;
  gap: var(--sfs-control-gap);
}

.sfs-control-panel {
  position: relative;
  min-width: 0;
}

.sfs-control-title {
  margin: 0 0 0.45rem;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.25;
}

.sfs-control-row {
  display: grid;
  grid-template-columns: minmax(4.5rem, auto) minmax(2.7rem, auto) 1fr;
  gap: 0.45rem;
  align-items: center;
  min-height: 1.8rem;
  margin: 0.22rem 0;
  font-size: 0.95rem;
  line-height: 1.25;
}

.sfs-check-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 1.65rem;
  margin: 0.18rem 0;
  font-size: 0.95rem;
  line-height: 1.25;
}

.sfs-check-row input[type="checkbox"],
.sfs-figure input[type="checkbox"] {
  flex: 0 0 auto;
  width: 1rem;
  height: 1rem;
}

.sfs-action-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sfs-action-gap);
  align-items: center;
}

.sfs-button,
.sfs-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--sfs-button-min-height);
  border: 1px solid var(--sfs-border);
  border-radius: var(--sfs-radius-sm);
  background: var(--sfs-bg);
  color: var(--sfs-text);
  font: inherit;
  line-height: 1.15;
  cursor: pointer;
}

.sfs-button {
  gap: 0.35rem;
  padding: 0.25rem 0.55rem;
  font-size: 0.92rem;
}

.sfs-icon-button {
  width: var(--sfs-button-min-height);
  height: var(--sfs-button-min-height);
  padding: 0;
}

.sfs-button:hover:not(:disabled),
.sfs-button:focus-visible:not(:disabled),
.sfs-icon-button:hover:not(:disabled),
.sfs-icon-button:focus-visible:not(:disabled) {
  border-color: var(--sfs-focus);
  color: var(--sfs-focus);
}

.sfs-button:focus-visible,
.sfs-icon-button:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.sfs-button:disabled,
.sfs-icon-button:disabled {
  cursor: default;
  opacity: 0.45;
}

.sfs-button .bi,
.sfs-icon-button .bi {
  flex: 0 0 auto;
  line-height: 1;
}

.sfs-readout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.25rem;
  min-height: 3.35rem;
  margin: 0 0 0.35rem;
  color: var(--sfs-text);
  font-size: 0.95rem;
  line-height: 1.35;
}

.sfs-readout[hidden] {
  display: none !important;
}

.sfs-readout-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.45rem;
  min-width: 0;
  align-items: baseline;
}

.sfs-readout-label {
  flex: 0 0 auto;
  color: var(--sfs-muted);
  font-weight: 700;
}

.sfs-readout-value {
  min-width: 0;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

.sfs-graph {
  max-width: 100%;
  height: auto;
  overflow: visible;
  color: var(--sfs-text);
  font-family: var(--bs-body-font-family);
}

.sfs-graph text {
  fill: var(--graph-text-color);
  font-family: inherit;
}

.sfs-graph .sfs-graph-title {
  fill: var(--sfs-text);
  font-size: var(--sfs-figure-title-size);
  font-weight: 700;
}

.sfs-graph .sfs-graph-label,
.sfs-axis-label {
  fill: var(--sfs-text);
  font-size: var(--sfs-figure-label-size);
}

.sfs-graph .sfs-graph-tick-label,
.sfs-graph .sfs-graph-legend text,
.sfs-tick-label {
  fill: var(--graph-text-color);
  font-size: var(--sfs-figure-tick-size);
}

.sfs-graph .sfs-graph-domain,
.sfs-graph .sfs-graph-tick-line,
.sfs-axis path,
.sfs-axis line {
  stroke: var(--graph-axis-color);
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
}

.sfs-axis text {
  fill: var(--graph-text-color);
}

.sfs-graph .sfs-graph-grid .tick line {
  stroke: var(--graph-grid-color);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.sfs-graph .sfs-graph-grid text {
  display: none;
}

.sfs-graph .sfs-graph-grid .domain {
  display: none;
}

.sfs-graph .sfs-graph-bar {
  fill: var(--graph-bar-fill);
  stroke: var(--graph-bar-stroke);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.sfs-graph .sfs-graph-block {
  fill: var(--graph-block-fill);
  stroke: var(--graph-block-stroke);
  shape-rendering: crispEdges;
}

.sfs-graph .sfs-graph-line {
  stroke: var(--graph-line-color);
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.sfs-graph .sfs-graph-area {
  fill-opacity: 0.16;
}

.sfs-graph .sfs-graph-point {
  fill: var(--graph-point-fill);
  stroke: var(--graph-point-stroke);
  stroke-width: 1.2;
  vector-effect: non-scaling-stroke;
}

.sfs-graph .sfs-graph-legend line {
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.sfs-graph .sfs-graph-reference-marker line {
  vector-effect: non-scaling-stroke;
}

.sfs-graph .sfs-graph-reference-marker text {
  font-size: var(--sfs-figure-label-size);
  font-weight: 700;
}

.sfs-data-emphasis {
  color: var(--graph-data-color);
  font-weight: 700;
}

/* One physical card frame for full hands and compact sampling displays.
   Never scale or rotate a face during reveal: keep small type and pips crisp. */
.sfs-card {
  --card-ink: #242628;
  --card-red: #b73542;
  --card-paper: #fffefa;
  position: relative;
  box-sizing: border-box;
  color: var(--card-ink);
  background: linear-gradient(145deg, #fff 0%, var(--card-paper) 75%, #f4f1e9 100%);
  border: 1px solid #babbb6;
  border-radius: 0.48rem;
  box-shadow: 0 1px 0 #fff inset, 0 2px 0 #d9d7cf, 0 4px 7px #00000013;
}
.sfs-card.is-red { color: var(--card-red); }
.sfs-card::after {
  content: "";
  position: absolute;
  inset: 5%;
  border-radius: 0.25rem;
  border: 1px solid #fff8;
  background-color: #2c716a;
  background-image: repeating-linear-gradient(45deg, transparent 0 6px, #ffffff24 6px 7px),
    repeating-linear-gradient(-45deg, transparent 0 6px, #ffffff24 6px 7px);
  box-shadow: 0 0 0 2px #2c716a;
  visibility: hidden;
}
.sfs-card-art { display: block; width: 100%; height: 100%; }
.sfs-card.is-face-down > *,
.sfs-card-hand.is-pending .sfs-card > * { visibility: hidden; }
.sfs-card.is-face-down::after,
.sfs-card-hand.is-pending .sfs-card::after { visibility: visible; }
.sfs-card-hand {
  display: grid;
  grid-template-columns: repeat(var(--card-columns), minmax(0, 1fr));
  gap: clamp(0.5rem, 2vw, 0.9rem);
  width: 100%;
  max-width: calc(var(--card-columns) * 6.25rem + (var(--card-columns) - 1) * 0.9rem);
  margin: 1.5rem auto 1.75rem;
}
.sfs-card-hand > .sfs-card { aspect-ratio: 5 / 7; min-width: 0; }
.sfs-card-hand-compact { max-width: 34rem; gap: 0.4rem; }
.sfs-card-compact {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.08rem;
}
.sfs-card-compact .cie-card-rank { font-weight: 700; font-size: 0.95rem; line-height: 1; }
.sfs-card-compact .cie-card-suit { font-size: 1.05rem; line-height: 1; }
.sfs-card-hand.is-dealt .sfs-card:not(.is-face-down) {
  animation: sfs-card-lift 300ms ease-out var(--card-delay) both;
}
.sfs-card-hand.is-dealt .sfs-card:not(.is-face-down) > * {
  animation: sfs-card-face 300ms step-end var(--card-delay) both;
}
.sfs-card-hand.is-dealt .sfs-card:not(.is-face-down)::after {
  animation: sfs-card-back 300ms step-end var(--card-delay) both;
}
@keyframes sfs-card-lift {
  0%, 100% { box-shadow: 0 1px 0 #fff inset, 0 2px 0 #d9d7cf, 0 4px 7px #00000013; }
  40% { box-shadow: 0 1px 0 #fff inset, 0 2px 0 #d9d7cf, 0 6px 12px #00000028; }
}
@keyframes sfs-card-face {
  0% { visibility: hidden; }
  40%, 100% { visibility: visible; }
}
@keyframes sfs-card-back {
  0% { visibility: visible; }
  40%, 100% { visibility: hidden; }
}
@media (prefers-reduced-motion: reduce) {
  .sfs-card-hand .sfs-card, .sfs-card-hand .sfs-card > *, .sfs-card-hand .sfs-card::after { animation: none !important; }
  .sfs-card-hand.is-pending .sfs-card:not(.is-face-down) > * { visibility: visible; }
  .sfs-card-hand.is-pending .sfs-card:not(.is-face-down)::after { visibility: hidden; }
}
html[data-motion="reduced"] .sfs-card-hand .sfs-card,
html[data-motion="reduced"] .sfs-card-hand .sfs-card > *,
html[data-motion="reduced"] .sfs-card-hand .sfs-card::after { animation: none !important; }
html[data-motion="reduced"] .sfs-card-hand.is-pending .sfs-card:not(.is-face-down) > * { visibility: visible; }
html[data-motion="reduced"] .sfs-card-hand.is-pending .sfs-card:not(.is-face-down)::after { visibility: hidden; }

/* Chapter 5 cover: one abstract block distribution, with the original-score
   ruler retained while its aligned z-score ruler emerges beneath it. The
   blocks come from the shared graph generator and use the standard series
   palette; the ruler colors preserve the chapter's instructional grammar. */
.z-score-cover,
.z-score-cover .zsc-source-graph {
  width: 100%;
}

.z-score-cover .zsc-source-graph {
  margin: 0;
  max-width: none;
}

.z-score-cover .zsc-source-graph {
  overflow: hidden;
}

.z-score-cover .sfs-graph-block {
  stroke-width: 1.25;
}

.z-score-cover .zsc-axis .sfs-graph-domain,
.z-score-cover .zsc-axis .sfs-graph-tick-line {
  stroke-width: 1.7;
}

.z-score-cover .zsc-math-label {
  font-family: var(--sfs-math-font-family);
  font-size: 1.08rem;
  font-style: italic;
  font-weight: 400;
}

.z-score-cover .zsc-raw-axis .sfs-graph-domain,
.z-score-cover .zsc-raw-axis .sfs-graph-tick-line {
  stroke: var(--graph-axis-color);
}

.z-score-cover .zsc-raw-axis .zsc-math-label {
  fill: var(--graph-axis-color);
}

.z-score-cover .zsc-z-axis .sfs-graph-domain,
.z-score-cover .zsc-z-axis .sfs-graph-tick-line {
  stroke: var(--graph-data-color);
}

.z-score-cover .zsc-z-axis .zsc-math-label {
  fill: var(--graph-data-color);
}

/* Chapter 5 aligned raw-score and z-score examples. Each panel is composed
   from the shared histogram/curve/block generators, with the same compact
   ruler layer added below its original x axis. */
.sfs-figure-row.sfs-standardization-comparison-row > .interactive-figure-mount {
  flex: 1 1 20rem;
  min-width: min(100%, 17rem);
  max-width: 30rem;
}

.standardized-score-graph,
.standardized-score-graph .ss-source-graph {
  width: 100%;
  margin: 0 auto;
}

.standardized-score-graph .ss-source-graph > svg,
.standardized-score-graph > svg {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}

.standardized-score-graph .ss-axis-side-label {
  fill: var(--sfs-muted);
  font-size: var(--sfs-figure-tick-size);
  font-weight: 600;
}

.standardized-score-graph .ss-z-axis-side-label,
.standardized-score-graph .ss-z-axis .sfs-graph-tick-label {
  fill: var(--graph-data-color);
  font-weight: 700;
}

.standardized-score-graph .ss-z-axis .sfs-graph-domain,
.standardized-score-graph .ss-z-axis .sfs-graph-tick-line {
  stroke: var(--graph-data-color);
  stroke-width: 1.5;
}

.standardized-score-graph .ss-mean-line {
  stroke: var(--sfs-muted);
  stroke-width: 1.35;
  stroke-dasharray: 3 4;
  vector-effect: non-scaling-stroke;
}

.standardized-score-graph .ss-sd-line {
  stroke: var(--sfs-muted);
  stroke-width: 1.2;
  stroke-dasharray: 1 4;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.standardized-score-graph .ss-stat-label {
  fill: var(--sfs-muted);
  font-family: var(--sfs-math-font-family);
  font-size: var(--sfs-figure-tick-size);
  font-style: italic;
  font-weight: 600;
  paint-order: stroke;
  stroke: var(--sfs-bg);
  stroke-width: 3px;
  stroke-linejoin: round;
}

/* Chapter 5 standardization tutorial: one stationary distribution with
   interchangeable physical-looking coordinate strips beneath it. */
.standardization-ruler {
  --sr-focus: var(--graph-data-color);
}

.standardization-ruler .sr-chart-wrap {
  overflow: hidden;
}

.standardization-ruler .sr-plot-stage {
  position: relative;
  width: 100%;
  overflow: hidden;
}

.standardization-ruler .sr-plot-layer {
  position: absolute;
  inset: 0;
  will-change: transform, opacity;
}

.standardization-ruler .sr-shared-plot,
.standardization-ruler .sr-ruler-svg {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  overflow: hidden;
}

.standardization-ruler .sr-ruler {
  pointer-events: none;
  will-change: transform, opacity;
}

.standardization-ruler .sr-ruler-title {
  font-weight: 400;
}

.standardization-ruler .sr-ruler-operation {
  fill: var(--graph-axis-color);
  font-weight: 600;
  opacity: 0;
}

.standardization-ruler .sr-ruler-testWorking .sfs-graph-tick-label {
  font-variant-numeric: tabular-nums;
}

.standardization-ruler .sr-ruler.is-focus .sr-ruler-title {
  fill: var(--graph-axis-color);
}

/* Blue consistently identifies the unchanged standardized scale. */
.standardization-ruler .sr-ruler.sr-ruler-testZ .sr-ruler-title,
.standardization-ruler .sr-ruler.sr-ruler-testZ .sfs-graph-tick-label {
  fill: var(--graph-data-color);
}

.standardization-ruler .sr-ruler.sr-ruler-testZ .sfs-graph-domain,
.standardization-ruler .sr-ruler.sr-ruler-testZ .sfs-graph-tick-line {
  stroke: var(--graph-data-color);
}

@media (prefers-reduced-motion: reduce) {
  .standardization-ruler .sr-ruler,
  .standardization-ruler .sr-plot-layer {
    animation: none !important;
    transition: none !important;
  }
}

/* CI diagrams: responsive SVG coordinates preserve readable labels on phones. */
.ci-interval-system { width: 100%; max-width: 42rem; margin: 1.25rem auto; }
/* Scoped to the figure's own svg: the construction figure embeds card art svgs
   that must keep the card's ink and type sizes. */
.ci-interval-system svg.sfs-svg { display: block; width: 100%; overflow: visible; color: var(--bs-body-color); }
.ci-interval-system svg.sfs-svg text { fill: currentColor; font-family: inherit; font-size: 13px; }
.ci-interval-system .tick text { font-size: 12px; }
.ci-diagram-readout { text-align: center; font-size: .85rem; margin: .5rem 0; min-height: 2.5em; font-variant-numeric: tabular-nums; }
.ci-diagram-readout:empty { display: none; }
.ci-construction-viewport { overflow: hidden; }
.ci-construction-scene, .ci-construction-source { display: flow-root; }
.ci-construction-cards { height: 112px; display: flex; align-items: center; justify-content: center; }
.ci-construction-cards .sfs-card-hand { margin: 0; width: auto; max-width: 100%; gap: .45rem; grid-template-columns: repeat(var(--card-columns), minmax(0, 60px)); }
@media (max-width: 480px) {
  .ci-construction-cards { height: 85px; }
  .ci-construction-cards .sfs-card-hand { grid-template-columns: repeat(var(--card-columns), minmax(0, 43px)); gap: .3rem; }
}
.ci-construction-source > .ci-sample-label { min-height: 0; margin: .3rem 0; }
.ci-construction-scene > .ci-diagram-readout:empty { display: block; }

/* Factor sliders: one colored row per input beneath a plot (power, CI width).
   Each row sets --sp-factor-color. */
.sp-factors {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-width: min(100%, 30rem);
  min-height: 2.6rem;
  margin: 0.4rem auto 0;
}

/* The distribution explorer's strip collapses until a step reveals a slider
   (distribution-generator.js slides it open); the row fades in after. */
.sp-factors.dpe-factors.is-empty {
  min-height: 0;
  margin-top: 0;
}

.sp-factors.dpe-factors .sp-factor {
  animation-delay: 280ms;
  animation-fill-mode: backwards;
}

.sp-factor {
  --sp-factor-ink: color-mix(in srgb, var(--sp-factor-color) 72%, var(--sfs-text));
  --sp-track: color-mix(in srgb, var(--sfs-text) 18%, var(--sfs-bg));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem 0.9rem;
  padding: 0.3rem 0.65rem;
  border-radius: var(--sfs-radius-sm, 4px);
  background: color-mix(in srgb, var(--sp-factor-color) 9%, transparent);
  animation: sp-factor-in 700ms ease-out;
}

.sp-factor[hidden],
.sp-factor input[hidden] {
  display: none;
}

/* The answer sits beneath the sliders that produce it. */
.sp-factor.is-output {
  order: 1;
  justify-content: center;
  font-size: 1.1rem;
}

.sp-factor.is-output .sp-factor-slider {
  flex: 0 0 auto;
}

.sp-factor.is-output .sp-factor-value {
  min-width: 0 !important;
}

.sp-factor input {
  accent-color: var(--sp-factor-color);
}

.sp-factor-slider {
  display: flex;
  flex: 1 1 15rem;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
  margin: 0;
}

.sp-factor-value {
  flex: 0 0 auto;
  color: var(--sp-factor-ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Drawn by hand: with accent-color alone, Chromium paints the unfilled
   track dark beside a light accent (the orange) and white beside a dark
   one, differently in each theme. */
.sp-factor input[type="range"] {
  flex: 1 1 8rem;
  width: auto;
  min-width: 3rem;
  height: 1.2rem;
  margin: 0;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.sp-factor input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--sp-factor-color) var(--sp-fill, 50%), var(--sp-track) var(--sp-fill, 50%));
}

.sp-factor input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: var(--sp-track);
}

.sp-factor input[type="range"]::-moz-range-progress {
  height: 6px;
  border-radius: 3px;
  background: var(--sp-factor-color);
}

.sp-factor input[type="range"]::-webkit-slider-thumb {
  width: 1.05rem;
  height: 1.05rem;
  margin-top: calc(3px - 0.525rem);
  border: 2px solid var(--sfs-bg);
  border-radius: 50%;
  background: var(--sp-factor-color);
  box-shadow: 0 0 0 1px var(--sp-factor-color);
  -webkit-appearance: none;
}

.sp-factor input[type="range"]::-moz-range-thumb {
  width: 0.85rem;
  height: 0.85rem;
  border: 2px solid var(--sfs-bg);
  border-radius: 50%;
  background: var(--sp-factor-color);
  box-shadow: 0 0 0 1px var(--sp-factor-color);
}

.sp-factor input[type="range"]:focus-visible {
  outline: 2px solid var(--sfs-focus);
  outline-offset: 2px;
}

.sp-factor-check {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  font-size: 0.95rem;
}

@keyframes sp-factor-in {
  from {
    opacity: 0;
    transform: translateY(6px);
    background: color-mix(in srgb, var(--sp-factor-color) 30%, transparent);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sp-factor { animation: none; }
}
