/* Reusable pieces for the demos. Colours come from tokens.css; --accent follows the slide. */

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 52px;
  padding: 10px 24px;
  border: 3px solid var(--line);
  border-radius: 0;
  background: var(--bg-raised);
  color: var(--text);
  box-shadow: 4px 4px 0 var(--accent);
  font-family: var(--font-head);
  font-weight: 700;
  font-size: var(--fs-small);
  cursor: pointer;
  transition: background-color var(--t-fast) linear, transform var(--t-fast) var(--ease);
}
.btn:hover {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}
.btn:active {
  transform: scale(0.97);
}
.btn.primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--line);
  box-shadow: 4px 4px 0 var(--line);
}
.btn.primary:hover {
  background: color-mix(in srgb, var(--accent) 85%, white);
}
.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ---------------------------------------------------------------- cards and callouts */

.card {
  background: var(--bg-raised);
  border: 3px solid var(--line);
  border-radius: 0;
  box-shadow: 4px 4px 0 var(--line);
  padding: calc(var(--gap) * 1.1);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card h3 {
  color: var(--accent);
}

.callout {
  border-left: 6px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--bg-raised));
  border-radius: 0 var(--radius-small) var(--radius-small) 0;
  padding: 14px 22px;
  font-size: var(--fs-small);
}
.callout strong {
  color: var(--accent);
}

/* Formulas sit at the bottom of a slide, always visible. */
.formula-bar {
  width: min(1080px, 100%);
  align-self: center;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.formula-bar .formula {
  margin: 0;
  padding: 8px 14px;
  border-radius: 0;
  background: var(--bg-raised);
  border: 3px solid var(--line);
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  line-height: 1.35;
}
.formula-bar:has(.is-active) .formula:not(.is-active) {
  opacity: 0.85;
}
.formula-bar .formula.is-active {
  border-color: var(--accent);
  box-shadow: 4px 4px 0 var(--accent);
}
.formula-bar {
  flex-shrink: 0;
}
.sym {
  position: relative;
  display: inline;
  padding: 0 1px;
  border: 0;
  border-bottom: 2px dashed currentColor;
  background: none;
  color: inherit;
  font: inherit;
  line-height: inherit;
  vertical-align: baseline;
  cursor: help;
}
.sym .tip {
  display: none;
  position: absolute;
  z-index: 6;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  width: max-content;
  max-width: 260px;
  padding: 8px 10px;
  border: 3px solid var(--line);
  background: var(--bg-raised);
  color: var(--text);
  box-shadow: 4px 4px 0 var(--line);
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
  text-align: left;
  white-space: normal;
}
.sym:hover .tip,
.sym:focus .tip,
.sym:focus-visible .tip,
.sym.on .tip {
  display: block;
}
.formula-bar .recon {
  color: var(--coral);
  font-weight: 700;
}
.formula-bar .kl {
  color: var(--sky);
  font-weight: 700;
}

/* A slightly tilted label for the one joke per slide. */
.sticker {
  display: inline-block;
  padding: 8px 18px;
  background: var(--sunflower);
  color: var(--bg);
  font-family: var(--font-head);
  font-weight: 700;
  font-size: var(--fs-small);
  border: 3px solid var(--line);
  border-radius: 0;
  transform: rotate(-3deg);
  box-shadow: 4px 4px 0 var(--line);
}
.sticker.tilt-right {
  transform: rotate(3deg);
}

/* ---------------------------------------------------------------- cat canvas */

/* 64x64 images drawn at native size and scaled up crisply.
   The pixels inside are the model or dataset image; the frame is chrome. */
.cat-canvas {
  display: block;
  width: var(--cat-size, 256px);
  height: var(--cat-size, 256px);
  aspect-ratio: 1;
  image-rendering: pixelated;
  border-radius: 0;
  background: #1c1612;
  border: 4px solid var(--line);
  box-shadow: 6px 6px 0 var(--accent);
}
.cat-canvas.small {
  --cat-size: 96px;
  border-width: 3px;
  box-shadow: 3px 3px 0 var(--accent);
}
@media (max-width: 760px) {
  .cat-canvas {
    --cat-size: min(60vw, 220px);
  }
  .cat-canvas.small {
    --cat-size: 64px;
  }
}

/* ---------------------------------------------------------------- big slider */

.slider {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 640px;
}
.slider-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  font-size: var(--fs-small);
}
.slider-value {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent);
  font-size: var(--fs-body);
}
.slider input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 44px;              /* big touch target */
  background: transparent;
  cursor: pointer;
  touch-action: none;        /* dragging the slider never scrolls the page */
}
.slider input[type="range"]::-webkit-slider-runnable-track {
  height: 18px;
  border-radius: 0;
  background: linear-gradient(90deg, var(--accent) var(--fill, 0%), var(--bg-sunken) var(--fill, 0%));
  border: 3px solid var(--line);
  box-sizing: border-box;
}
.slider input[type="range"]::-moz-range-track {
  height: 18px;
  border-radius: 0;
  background: linear-gradient(90deg, var(--accent) var(--fill, 0%), var(--bg-sunken) var(--fill, 0%));
  border: 3px solid var(--line);
  box-sizing: border-box;
}
.slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  /* Centres a 22px thumb on an 18px track in Chrome. */
  margin-top: -5px;
  border-radius: 0;
  background: var(--bg-raised);
  border: 3px solid var(--line);
  box-sizing: border-box;
  box-shadow: 3px 3px 0 var(--line);
}
.slider input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 0;
  background: var(--bg-raised);
  border: 3px solid var(--line);
  box-sizing: border-box;
}
.slider-ticks {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  color: var(--text-soft);
}

/* ---------------------------------------------------------------- toggle switch */

.toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  font-size: var(--fs-small);
  user-select: none;
}
.toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}
.toggle-track {
  position: relative;
  flex-shrink: 0;
  width: 64px;
  height: 36px;
  border-radius: 0;
  background: var(--bg-sunken);
  border: 3px solid var(--line);
  box-shadow: 3px 3px 0 var(--line);
  transition: background-color var(--t-fast) linear;
}
.toggle-track::after {
  content: "";
  position: absolute;
  top: 7px;
  left: 7px;
  width: 22px;
  height: 22px;
  border-radius: 0;
  border: 3px solid var(--line);
  box-sizing: border-box;
  background: var(--bg-raised);
  transition: transform var(--t-fast) var(--ease), background-color var(--t-fast) linear;
}
.toggle input:checked + .toggle-track {
  background: color-mix(in srgb, var(--accent) 35%, var(--bg-sunken));
  border-color: var(--line);
}
.toggle input:checked + .toggle-track::after {
  transform: translateX(28px);
  background: var(--stamp);
}
.toggle input:focus-visible + .toggle-track {
  outline: 3px solid var(--sunflower);
  outline-offset: 3px;
}

/* ---------------------------------------------------------------- tabs */

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px;
  border-radius: 0;
  background: var(--bg-sunken);
  border: 3px solid var(--line);
  width: fit-content;
  max-width: 100%;
}
.tab {
  padding: 8px 22px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text-soft);
  font-family: var(--font-head);
  font-weight: 600;
  font-size: var(--fs-small);
  cursor: pointer;
  transition: background-color var(--t-fast) linear, color var(--t-fast) linear;
}
.tab:hover {
  color: var(--text);
}
.tab[aria-selected="true"] {
  background: var(--accent);
  color: var(--bg);
}

/* ---------------------------------------------------------------- probability bars */

.prob-bars {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px 16px;
  width: 100%;
  max-width: 560px;
  font-size: var(--fs-small);
}
.prob-label {
  font-family: var(--font-head);
  font-weight: 600;
}
.prob-track {
  height: 24px;
  border-radius: 12px;
  background: var(--bg-sunken);
  border: 2px solid var(--line);
  overflow: hidden;
}
.prob-fill {
  height: 100%;
  width: 0;
  background: var(--bar-colour, var(--accent));
  transition: width var(--t-med) var(--ease);
}
.prob-value {
  font-family: var(--font-mono);
  min-width: 4.5ch;
  text-align: right;
}
.prob-bars .top .prob-label,
.prob-bars .top.prob-value {
  color: var(--bar-colour, var(--accent));
}

/* ---------------------------------------------------------------- readout */

.readout {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
}
.readout-label {
  font-size: var(--fs-label);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-soft);
}
.readout-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: var(--fs-h3);
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- cat picker */

.cat-pick {
  padding: 0;
  border: 3px solid transparent;
  border-radius: 0;
  background: none;
  cursor: pointer;
  transition: border-color var(--t-fast) linear, transform var(--t-fast) var(--ease);
}
.cat-pick canvas {
  display: block;
  width: 64px;
  height: 64px;
  border-radius: 0;
  image-rendering: pixelated;
}
.cat-pick:hover {
  transform: translateY(-3px);
}
.cat-pick[aria-pressed="true"] {
  border-color: var(--line);
  box-shadow: 4px 4px 0 var(--accent);
}
@media (max-width: 760px) {
  .cat-pick canvas {
    width: 44px;
    height: 44px;
  }
}

/* ---------------------------------------------------------------- "still training" card */

.training-card {
  flex-direction: row;
  align-items: center;
  gap: 20px;
  max-width: 560px;
}
.training-card .mascot {
  width: 120px;
  flex-shrink: 0;
}
.training-card code {
  color: var(--accent);
}

/* Anything a finger drags inside a demo (canvases, maps) must not scroll the page. */
.interactive {
  touch-action: none;
}

.training-card.compact {
  gap: 10px;
  padding: 12px 16px;
  max-width: 260px;
  font-size: var(--fs-label);
}
.training-card.compact .mascot {
  width: 56px;
}
.training-card.compact h3 {
  font-size: var(--fs-small);
}

/* ---------------------------------------------------------------- flip switch (two named sides) */

.flip {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  font-family: var(--font-head);
  font-weight: 600;
  font-size: var(--fs-small);
  user-select: none;
}
.flip-side {
  border: 0;
  background: none;
  padding: 4px 2px;
  color: var(--text-soft);
  cursor: pointer;
  transition: color var(--t-fast) linear;
}
.flip-side.on {
  color: var(--accent);
}
.flip .toggle-track {
  width: 76px;
  height: 36px;
  border-radius: 0;
}
.flip .toggle-track::after {
  top: 7px;
  left: 7px;
  width: 22px;
  height: 22px;
  background: var(--bg-raised);
}
.flip .toggle input:checked + .toggle-track::after {
  transform: translateX(40px);
  background: var(--stamp);
}
/* Both sides are "on" states, so the track keeps the accent colour either way. */
.flip .toggle-track,
.flip .toggle input:checked + .toggle-track {
  background: color-mix(in srgb, var(--accent) 30%, var(--bg-sunken));
  border-color: var(--accent);
}

/* A grid of images to choose from (cats, dogs, wild animals). */
.image-picker {
  display: grid;
  grid-template-columns: repeat(var(--picker-cols, 4), auto);
  gap: 8px;
  justify-content: center;
}

/* A slot whose model is missing: the canvas stays (keeps the layout), the card covers it. */
.is-missing {
  position: relative;
}
.is-missing > canvas {
  visibility: hidden;
}
.missing {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 1;
}
.missing .training-card.compact {
  max-width: 100%;
}

/* Verdict chips on the anomaly slide and the latent-map slide. */
.verdict-chip {
  padding: 6px 20px;
  border-radius: 0;
  border: 3px solid var(--line);
  font-family: var(--font-head);
  font-weight: 700;
  font-size: var(--fs-body);
  color: var(--bg);
  background: var(--mint);
}
.verdict-chip:empty {
  display: none;
}

@media (max-width: 760px) {
  .tab {
    padding: 6px 12px;
  }
}

/* ---------------------------------------------------------------- KaTeX maths (js/math.js) */

.katex {
  font-size: 1.1em;
}
.formula-bar .katex {
  font-size: 1.3em;
}
.katex .recon {
  color: var(--coral);
}
.katex .kl {
  color: var(--sky);
}
/* Explainable symbols inside typeset maths keep the dashed underline and the tip bubble. */
.katex .sym {
  display: inline-block;
  padding: 0 1px;
  border-bottom: 2px dashed currentColor;
}
.katex .sym:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.katex .tip {
  font-style: normal;
}

/* "What lives here?" decoded tiles laid over a latent map (js/decodegrid.js). */
.latent-map {
  position: relative;
}
.decode-grid {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  image-rendering: auto;
}

/* Phones: wide formulas scroll sideways inside their box instead of overflowing the slide,
   and the cat pickers on the explainer slides wrap to two rows. */
@media (max-width: 760px) {
  .katex-display,
  .formula-bar .formula,
  .loss-tex {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .num-picker .image-picker,
  .size-picker .image-picker,
  .worlds-picker .image-picker {
    --picker-cols: 4 !important; /* beats the inline column count */
  }
}
