/* Patch-token PCA explorer and charts (static/js/pca.js). Built on the tokens in style.css. */

/* Explorer: image picker and patch grid on the left, compare stage on the right, encoder strip below. */
.article > .pca-explorer { width: 100%; margin: 2rem 0 0; }
/* The picker column is sized so its bottom meets the 430 px stage, leaving no gap above the encoder strip. */
.pca-grid { display: grid; grid-template-columns: minmax(0, 20.75rem) minmax(0, 1fr); gap: 2rem; align-items: start; }
.pca-label { margin: 0 0 0.5rem; font-size: 0.71875rem; font-weight: 500; line-height: 1.4; color: var(--quiet); }
.thumbs { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0.3125rem; margin: 0 0 1.25rem; }
.thumb {
  padding: 0; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; background: var(--bg);
  aspect-ratio: 1; line-height: 0; cursor: pointer; transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.thumb:hover { border-color: var(--rule-strong); }
.thumb.is-active { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.pca-seg { display: flex; flex-wrap: wrap; gap: 0.375rem; }
.pca-seg button {
  font: 500 0.75rem/1.3 var(--sans); padding: 0.375rem 0.75rem; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--rule-strong); background: var(--bg); color: var(--body);
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.pca-seg button:hover { border-color: var(--accent); color: var(--ink); }
.pca-seg button.is-active { background: var(--button); border-color: var(--button); color: var(--button-text); }

.pca-stage {
  --split: 50%; position: relative; width: 100%; max-width: 430px; aspect-ratio: 1; margin: 0 0 0 auto;
  border-radius: 8px; overflow: hidden; background: var(--panel); cursor: ew-resize;
  touch-action: pan-y; user-select: none; -webkit-user-select: none;
}
.pca-stage img { position: absolute; inset: 0; display: block; width: 100%; height: 100%; pointer-events: none; }
.pca-map {
  position: absolute; inset: 0; pointer-events: none; background-repeat: no-repeat;
  image-rendering: pixelated; clip-path: inset(0 0 0 var(--split));
}
.pca-handle {
  position: absolute; top: 0; bottom: 0; left: var(--split); width: 2px; margin-left: -1px; pointer-events: none;
  background: #fff; box-shadow: 0 0 0 1px rgb(0 0 0 / 14%);
}
.pca-handle::after {
  content: ""; position: absolute; top: 50%; left: 50%; width: 28px; height: 28px; margin: -14px 0 0 -14px;
  border-radius: 50%; box-shadow: 0 1px 4px rgb(0 0 0 / 30%);
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 28 28'%3E%3Cpath d='M11 9 6 14l5 5M17 9l5 5-5 5' fill='none' stroke='%2357534e' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 28px no-repeat;
}
.pca-tag {
  position: absolute; top: 0.5rem; padding: 0.2em 0.5em; border-radius: 4px; pointer-events: none;
  font: 500 0.6875rem/1.3 var(--sans); color: #fff; background: rgb(28 25 23 / 55%);
}
.pca-tag.l { left: 0.5rem; }
.pca-tag.r { right: 0.5rem; }

.pca-strip { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0.625rem; margin-top: 1.25rem; }
.pca-strip .cell { padding: 0; border: 0; background: none; font: inherit; color: inherit; text-align: center; cursor: pointer; }
.pca-strip .map {
  display: block; aspect-ratio: 1; border-radius: 6px; background-repeat: no-repeat; image-rendering: pixelated;
  box-shadow: 0 0 0 1px var(--rule); transition: box-shadow 0.15s ease;
}
.pca-strip .cell:hover .map { box-shadow: 0 0 0 1px var(--rule-strong); }
.pca-strip .cell.is-active .map { box-shadow: 0 0 0 2px var(--ink); }
.pca-strip .cell:focus-visible { outline-offset: 4px; border-radius: 6px; }
.pca-strip .lab { display: block; margin-top: 0.45rem; font-size: 0.75rem; font-weight: 500; line-height: 1.4; color: var(--quiet); }
.pca-strip .par { display: block; font-size: 0.6875rem; line-height: 1.4; color: var(--faint); font-variant-numeric: tabular-nums; }
.pca-strip .cell.is-active .lab { color: var(--ink); font-weight: 650; }

/* Encoder names in running text never break at their hyphen. */
.nowrap { white-space: nowrap; }

/* K400 charts: one series each, points in the encoder colours of the paper's figures. */
.pca-charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2rem; }
.pca-chart { position: relative; }
.pca-chart-title { margin: 0 0 0.25rem; text-align: center; font-size: 0.8125rem; font-weight: 600; color: var(--ink); }
.pca-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.pca-chart svg text { font-family: var(--sans); font-size: 10px; fill: var(--faint); }
.pca-chart svg .lab { font-size: 11px; fill: var(--quiet); }
.pca-chart svg .gl { stroke: var(--rule); stroke-width: 1; }
.pca-chart svg .ln { fill: none; stroke: var(--faint); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.pca-chart svg .eb { stroke: var(--faint); stroke-width: 1.2; }
.pca-chart svg .pt { stroke: var(--bg); stroke-width: 2; transition: r 0.1s ease; }
.pca-chart svg .pt.on { r: 6; }
.pca-chart svg .hit { fill: transparent; outline: none; }
.pca-tip {
  position: absolute; z-index: 1; width: max-content; pointer-events: none;
  padding: 0.45rem 0.6rem; border: 1px solid var(--rule); border-radius: 0.375rem;
  background: var(--bg); color: var(--ink); box-shadow: 0 3px 12px rgb(0 0 0 / 12%);
  font-size: 0.75rem; line-height: 1.4; transform: translate(-50%, calc(-100% - 12px));
  opacity: 0; transition: opacity 0.1s ease;
}
.pca-tip.on { opacity: 1; }
.pca-tip.below { transform: translate(-50%, 12px); }
.pca-tip b { display: block; font-weight: 650; font-variant-numeric: tabular-nums; }
.pca-tip span { display: block; color: var(--quiet); }
.pca-table { margin: 1rem 0 0; text-align: center; }
.pca-table summary { display: inline-block; cursor: pointer; font-size: 0.75rem; font-weight: 500; color: var(--quiet); }
.pca-table summary:hover { color: var(--ink); }
.pca-table table { max-width: 560px; margin-top: 0.5rem; }

@media (max-width: 860px) {
  .pca-grid { grid-template-columns: minmax(0, 1fr); gap: 1.25rem; }
  .thumbs { max-width: 22rem; }
  .pca-stage { max-width: none; }
  .pca-charts { grid-template-columns: minmax(0, 1fr); max-width: 30rem; margin-inline: auto; }
}
@media (max-width: 640px) {
  .pca-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  .thumb, .pca-seg button, .pca-strip .map, .pca-chart svg .pt, .pca-tip { transition: none; }
}
