/* Dimensionality reduction explainer. Site-wide tokens (--bg, --fg, --muted,
   --line, --line-strong, --soft, --surface, --grid) come from
   /assets/css/index.css. Series colours are stepped separately for light and
   dark; the categorical order follows the site's validated palette. */

.dr {
  --c1: #2a78d6;
  --c2: #eb6834;
  --c3: #1baf7a;
  --c4: #eda100;
  --c5: #e87ba4;
  --c6: #008300;
  --c7: #6250d6;
  --c8: #e34948;
  --c9: #9c6b30;
  --c10: #6b7280;
  /* Sequential (blue, light → dark) and diverging (blue ↔ grey ↔ red) */
  --seq-lo: #cde2fb;
  --seq-hi: #0d366b;
  --div-pos: #2a78d6;
  --div-neg: #e34948;
  --div-mid: #f0efec;
  --ink: var(--fg);
  --ink2: #52514e;
  --axis: #c3c2b7;
  --halo: rgba(255, 255, 255, 0.9);
  --brush: rgba(42, 120, 214, 0.1);
  max-width: 960px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .dr {
    --c1: #3987e5;
    --c2: #d95926;
    --c3: #199e70;
    --c4: #c98500;
    --c5: #d55181;
    --c6: #0ca30c;
    --c7: #9085e9;
    --c8: #e66767;
    --c9: #b07c3c;
    --c10: #9aa1ad;
    --seq-lo: #1c3555;
    --seq-hi: #b7d3f6;
    --div-pos: #3987e5;
    --div-neg: #e66767;
    --div-mid: #383835;
    --ink2: #c3c2b7;
    --axis: #4a4e55;
    --halo: rgba(21, 23, 26, 0.85);
    --brush: rgba(57, 135, 229, 0.14);
  }
}

:root[data-theme='dark'] .dr {
  --c1: #3987e5;
  --c2: #d95926;
  --c3: #199e70;
  --c4: #c98500;
  --c5: #d55181;
  --c6: #0ca30c;
  --c7: #9085e9;
  --c8: #e66767;
  --c9: #b07c3c;
  --c10: #9aa1ad;
  --seq-lo: #1c3555;
  --seq-hi: #b7d3f6;
  --div-pos: #3987e5;
  --div-neg: #e66767;
  --div-mid: #383835;
  --ink2: #c3c2b7;
  --axis: #4a4e55;
  --halo: rgba(21, 23, 26, 0.85);
  --brush: rgba(57, 135, 229, 0.14);
}

.dr [hidden] {
  display: none !important;
}

.dr h2 {
  font-family: 'Merriweather', serif;
  font-weight: 700;
  font-size: 1.15rem;
  margin: 52px 0 8px;
}

.dr h3 {
  font-size: 0.95rem;
  font-weight: 500;
  margin: 28px 0 6px;
}

.dr .intro,
.dr .hint,
.dr .how-card p,
.dr .pitfalls li {
  line-height: 1.6;
  font-weight: 300;
}

.dr .hint {
  color: var(--muted);
  font-size: 0.92rem;
  margin: 0 0 12px;
}

.dr .hint.fine {
  font-size: 0.82rem;
  margin-top: 14px;
}

.dr a:not(.back) {
  color: var(--c1);
}

.dr select,
.dr input,
.dr button {
  font: inherit;
}

.dr b,
.dr strong {
  font-weight: 500;
}

/* Intro cards --------------------------------------------------------------*/

.explain4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 20px;
}

.explain4 > div {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.86rem;
  line-height: 1.55;
  font-weight: 300;
  color: var(--muted);
}

.explain4 b {
  display: block;
  margin-bottom: 4px;
  color: var(--ink);
  font-size: 0.95rem;
}

/* Dataset picker -----------------------------------------------------------*/

.ds-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin: 8px 0 14px;
}

.ds-opt {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.ds-opt:hover {
  border-color: var(--line-strong);
  box-shadow: 0 2px 12px var(--shadow);
}

.ds-opt[aria-checked='true'] {
  border-color: var(--ink);
  box-shadow: 0 0 0 1px var(--ink);
}

.ds-opt:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 2px;
}

.ds-opt canvas {
  width: 100%;
  height: 54px;
  border-radius: 4px;
  background: var(--soft);
}

.ds-opt .t {
  font-weight: 500;
  font-size: 0.9rem;
}

.ds-opt .s {
  font-size: 0.76rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.ds-opt .tag {
  align-self: flex-start;
  margin-top: -2px;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.68rem;
  color: var(--muted);
}

.card {
  margin: 4px 0 18px;
  padding: 16px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.ds-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px 24px;
  align-items: flex-start;
}

.ds-head h3 {
  margin: 0 0 4px;
  font-family: 'Merriweather', serif;
  font-weight: 700;
  font-size: 1.05rem;
}

.ds-shape {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.ds-opts {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  align-items: flex-end;
}

.ds-desc {
  margin: 12px 0 8px;
  line-height: 1.6;
  font-weight: 300;
  font-size: 0.93rem;
}

.ds-source {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.5;
}

/* Controls -----------------------------------------------------------------*/

.field,
.slider {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.field select {
  padding: 5px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

.slider > span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.slider output {
  font-family: 'Roboto Mono', monospace;
  color: var(--ink);
}

.slider input[type='range'] {
  width: 100%;
  accent-color: var(--ink);
}

.check {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
}

.check input {
  accent-color: var(--ink);
}

.btns {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.btn {
  padding: 6px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.btn:hover {
  border-color: var(--muted);
}

.btn.small {
  padding: 4px 10px;
  font-size: 0.8rem;
}

.how {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px 24px;
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 300;
}

.how b {
  color: var(--ink);
}

/* Legend -------------------------------------------------------------------*/

.legend-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 18px;
  margin: 6px 0 10px;
  min-height: 30px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
  font-size: 0.85rem;
  color: var(--ink);
  align-items: center;
}

.legend button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px 3px 7px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  color: var(--ink);
  font-size: 0.85rem;
  cursor: pointer;
  transition: opacity 0.15s, border-color 0.15s;
}

.legend button:hover {
  border-color: var(--line);
}

.legend button[aria-pressed='true'] {
  border-color: var(--line-strong);
}

.legend.isolating button[aria-pressed='false'] {
  opacity: 0.4;
}

.legend .count {
  color: var(--muted);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.legend .ramp {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.legend .ramp i {
  display: inline-block;
  width: 140px;
  height: 10px;
  border-radius: 3px;
}

.sw {
  display: inline-block;
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

/* Panels -------------------------------------------------------------------*/

.panels {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.panel {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
}

.panel header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 10px 14px 0;
}

.panel h3 {
  margin: 0;
  font-family: 'Merriweather', serif;
  font-weight: 700;
  font-size: 0.98rem;
}

.status {
  font-size: 0.76rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.status b {
  color: var(--ink);
  font-weight: 500;
}

.status .busy::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--c1);
  animation: pulse 1s ease-in-out infinite;
  vertical-align: 0;
}

@keyframes pulse {
  50% {
    opacity: 0.25;
  }
}

.stage {
  position: relative;
  aspect-ratio: 1 / 0.86;
  margin: 6px 0 0;
}

.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.stage .bar {
  position: absolute;
  left: 0;
  top: 0;
  height: 2px;
  width: 0;
  background: var(--c1);
  transition: width 0.1s linear, opacity 0.4s;
  opacity: 0;
}

.pctl {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: flex-end;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--grid);
  min-height: 62px;
}

.pctl .mini {
  flex: 1 1 120px;
  font-size: 0.8rem;
  gap: 4px;
}

.pctl .note {
  margin: 0;
  align-self: center;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.5;
}

.pctl .note b {
  color: var(--ink);
}

.readout {
  min-height: 1.5em;
  margin: 12px 0 0;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--soft);
  font-size: 0.88rem;
  line-height: 1.6;
  font-weight: 300;
}

.readout:empty {
  display: none;
}

.readout b {
  font-weight: 500;
}

.readout .mono {
  font-family: 'Roboto Mono', monospace;
  font-size: 0.82rem;
}

/* Charts -------------------------------------------------------------------*/

.chart {
  width: 100%;
  position: relative;
}

.chart svg {
  display: block;
  overflow: visible;
  font-family: 'Roboto', sans-serif;
}

.grid-line {
  stroke: var(--grid);
  shape-rendering: crispEdges;
}

.axis-line {
  stroke: var(--axis);
  shape-rendering: crispEdges;
}

.tick {
  fill: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.lbl {
  fill: var(--ink);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.lbl.muted {
  fill: var(--muted);
}

.bar-fill {
  fill: var(--c1);
}

.bar-fill.dim {
  fill: var(--axis);
}

.cum-line {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2;
  stroke-linejoin: round;
}

.cum-dot {
  fill: var(--ink);
  stroke: var(--surface);
  stroke-width: 2;
}

.hit {
  fill: transparent;
  cursor: default;
}

.load-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.load-grid figure {
  margin: 0;
}

.load-grid figcaption {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.load-grid figcaption b {
  color: var(--ink);
}

.digit-load {
  display: flex;
  gap: 14px;
  align-items: center;
}

.digit-load canvas {
  width: 132px;
  height: 132px;
  image-rendering: pixelated;
  border-radius: 4px;
  border: 1px solid var(--line);
}

.digit-load p {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.5;
  font-weight: 300;
}

.div-key {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 6px;
}

.div-key i {
  display: inline-block;
  width: 110px;
  height: 8px;
  border-radius: 3px;
}

/* How it works -------------------------------------------------------------*/

.how-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.how-card {
  padding: 4px 18px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.how-card h3 {
  margin: 14px 0 4px;
}

.how-card p {
  font-size: 0.9rem;
  margin: 8px 0;
}

.how-card .eq {
  overflow-x: auto;
  overflow-y: hidden;
  margin: 6px 0;
}

.dr .katex {
  font-size: 1.02em;
}

/* Pitfalls -----------------------------------------------------------------*/

.pitfalls {
  padding-left: 22px;
  margin: 0;
}

.pitfalls li {
  margin-bottom: 14px;
  font-size: 0.93rem;
}

.pitfalls li > div {
  display: inline;
}

.pitfalls li .btn {
  margin-left: 8px;
  vertical-align: 1px;
}

/* Table --------------------------------------------------------------------*/

.table-wrap {
  margin-top: 8px;
  overflow-x: auto;
}

.stats {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.stats th,
.stats td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--grid);
  vertical-align: top;
  line-height: 1.45;
}

.stats thead th {
  font-weight: 500;
}

.stats td:first-child {
  color: var(--muted);
  white-space: nowrap;
}

.stats td {
  font-weight: 300;
}

/* Tooltip ------------------------------------------------------------------*/

.tip {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  padding: 8px 10px;
  background: rgba(30, 30, 30, 0.94);
  color: #fff;
  font-family: 'Roboto', sans-serif;
  font-size: 0.8rem;
  line-height: 1.5;
  border-radius: 6px;
  max-width: 260px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}

.tip .row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tip .sw {
  width: 9px;
  height: 9px;
}

.tip b {
  font-weight: 500;
}

.tip .sub {
  color: rgba(255, 255, 255, 0.7);
}

.tip .mono {
  font-family: 'Roboto Mono', monospace;
}

.tip table {
  border-collapse: collapse;
  margin-top: 4px;
}

.tip td {
  padding: 0 8px 0 0;
  color: rgba(255, 255, 255, 0.75);
}

.tip td + td {
  color: #fff;
  font-family: 'Roboto Mono', monospace;
  text-align: right;
}

.tip canvas {
  display: block;
  margin-top: 6px;
  width: 64px;
  height: 64px;
  image-rendering: pixelated;
  border-radius: 3px;
}

/* Responsive ---------------------------------------------------------------*/

@media (max-width: 760px) {
  .explain4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .panels,
  .how-grid,
  .load-grid,
  .how {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 460px) {
  .explain4 {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .status .busy::before {
    animation: none;
  }
}
