/* Interactive board and PrismaPhysics controls (src/interactive.board.js).
   Only present while an interactive step is mounted, which needs the
   PRISMA_INTERACTIVE_BOARD switch; uses the study room's tokens, so it
   follows the light and dark schemes.

   Two parts: the deck docked at the bottom of the figure (time bar,
   sliders, values now, small graph) and, in the step's text, what explains
   them (title, what to try, the formulas and the CAS check). */

/* ── The step's part ─────────────────────────────────────────────────── */

.prisma-ix {
  max-height: min(340px, 44vh);
  min-height: 0;
  overflow-y: auto;
  padding: 12px 18px 14px;
  border-top: 1px solid var(--study-line, #d6ddd8);
  background: var(--study-paper, #fbfaf6);
  color: var(--study-ink, #173247);
  font-family: var(--study-body, system-ui, sans-serif);
  font-size: 13px;
  line-height: 1.45;
  display: grid;
  gap: 10px;
  align-content: start;
}

/* Under the step's explanation: no height cap (the thread scrolls), a quiet
   card. */
.prisma-ix.prisma-ix-in-step {
  max-height: none;
  overflow: visible;
  margin-top: 14px;
  padding: 12px 14px 14px;
  border: 1px solid var(--study-line, #d6ddd8);
  border-radius: 10px;
  background: var(--study-card, #fff);
}

/* The step reads in one column at every width: its text, then what
   explains the controls, both as wide as the conversation. Side by side in
   the conversation's column (about 460 px on a desktop) each part kept
   about 220 px: names and formulas took three or four lines and "$x=1$"
   wrapped (live evaluation, 20 Oct; phones had it under 980 px). */
html.study-v2-enabled .message.lesson-step-active:has(> .prisma-ix-in-step) {
  flex-wrap: wrap;
}

html.study-v2-enabled .message.lesson-step-active:has(> .prisma-ix-in-step) > .bubble,
.prisma-ix.prisma-ix-in-step {
  flex: 1 1 100%;
  min-width: 0;
}

.prisma-ix-title {
  margin: 0;
  font-family: var(--study-heading, Georgia, serif);
  font-size: 17px;
  font-weight: 500;
}

.prisma-ix-meaning {
  margin: 2px 0 0;
  color: var(--study-muted, #4f6470);
}

.prisma-ix-where,
.prisma-ix-drag-hint {
  margin: 0;
  color: var(--study-muted, #4f6470);
  font-size: 12px;
}

.prisma-ix-where::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--study-accent, #077487);
  vertical-align: 1px;
}

.prisma-ix-section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin-bottom: 4px;
}

.prisma-ix-section-head h4 {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.prisma-ix-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid currentColor;
}

/* Verified: the accent. Live / simulated: the ochre, clearly different. */
.prisma-ix-badge-verified {
  color: var(--study-accent, #077487);
}

.prisma-ix-badge-live,
.prisma-ix-badge-simulation {
  color: #8a5a22;
  border-style: dashed;
}

.prisma-ix-claim-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

/* A formula: its name and the CAS badge on one row, the formula under them
   across the whole width, then its value now. */
.prisma-ix-claim {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 8px;
  align-items: center;
}

/* A name longer than its column breaks, rather than run under the badge. */
.prisma-ix-claim-label {
  font-weight: 600;
  overflow-wrap: break-word;
}

.prisma-ix-claim-tex {
  grid-column: 1 / -1;
}

.prisma-ix-claim .prisma-ix-badge {
  grid-row: 1;
  grid-column: 2;
  align-self: start;
}

.prisma-ix-claim-value {
  grid-column: 1 / -1;
  color: var(--study-muted, #4f6470);
  font-size: 12px;
}

.prisma-ix-claim-value.is-verified {
  color: var(--study-accent, #077487);
  font-weight: 600;
}

.prisma-ix-check {
  grid-column: 1 / -1;
  justify-self: start;
  min-height: 28px;
  padding: 2px 10px;
  border: 1px solid var(--study-accent, #077487);
  border-radius: 999px;
  background: transparent;
  color: var(--study-accent, #077487);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.prisma-ix-check:disabled {
  opacity: 0.55;
  cursor: default;
}

/* ── The deck on the figure ──────────────────────────────────────────── */

.prisma-ix-deck {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 7;
  display: grid;
  gap: 6px;
  max-height: 52%;
  padding: 6px 14px 10px;
  border-top: 1px solid var(--study-line, #d6ddd8);
  background: var(--study-paper, #fbfaf6);
  color: var(--study-ink, #173247);
  font-family: var(--study-body, system-ui, sans-serif);
  font-size: 13px;
  line-height: 1.35;
  box-shadow: 0 -10px 24px -18px var(--study-shadow, rgba(23, 50, 71, 0.35));
  container-type: inline-size;
}

.prisma-ix-deck.is-collapsed {
  padding-bottom: 6px;
}

.prisma-ix-deck-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 38px;
  min-width: 0;
}

.prisma-ix-deck-name {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 24ch;
  overflow: hidden;
  font-family: var(--study-heading, Georgia, serif);
  font-size: 15px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.prisma-ix-deck-toggle {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  margin-left: auto;
  padding: 0 10px;
  border: 1px solid var(--study-control-line, #b9c4bd);
  border-radius: 999px;
  background: transparent;
  color: var(--study-muted, #4f6470);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.prisma-ix-deck-toggle:hover {
  border-color: var(--study-accent, #077487);
  color: var(--study-accent, #077487);
}

.prisma-ix-deck-chevron {
  width: 7px;
  height: 7px;
  border-right: 1.6px solid currentColor;
  border-bottom: 1.6px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
}

.prisma-ix-deck.is-collapsed .prisma-ix-deck-chevron {
  transform: translateY(2px) rotate(-135deg);
}

/* Sliders on the left with the values now under them; the small graph
   (or the energy bars) on the right. */
.prisma-ix-deck-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "params" "values";
  align-items: start;
  gap: 6px 22px;
  min-height: 0;
  overflow-y: auto;
  padding-top: 7px;
  border-top: 1px dashed var(--study-line, #d6ddd8);
}

.prisma-ix-deck-body:has(.prisma-ix-extras) {
  grid-template-columns: minmax(0, 1fr) minmax(130px, 210px);
  grid-template-areas: "params extras" "values extras";
}

.prisma-ix-deck-body[hidden] {
  display: none;
}

/* Sliders side by side: as many columns as fit. */
.prisma-ix-params {
  grid-area: params;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 6px 18px;
  align-content: start;
  min-width: 0;
}

/* The symbol and its value on one line, the slider under them and the
   words last, small (the label's parts are laid out by the row's grid). */
.prisma-ix-param {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "symbol value" "range range" "words words";
  align-items: baseline;
  column-gap: 8px;
  min-width: 0;
}

.prisma-ix-label {
  display: contents;
}

.prisma-ix-symbol {
  grid-area: symbol;
  color: var(--study-ink, #173247);
  font-size: 14px;
}

.prisma-ix-label-text {
  grid-area: words;
  min-width: 0;
  overflow: hidden;
  color: var(--study-muted, #4f6470);
  font-size: 11.5px;
  line-height: 1.2;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: default;
}

.prisma-ix-param .prisma-ix-value {
  grid-area: value;
}

.prisma-ix-param .prisma-ix-range {
  grid-area: range;
}

/* Read by screen readers (aria-describedby); the row's tooltip shows it. */
.prisma-ix-help {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.prisma-ix-range,
.prisma-ix-scrub {
  width: 100%;
  min-height: 22px;
  margin: 0;
  accent-color: var(--study-accent, #077487);
}

.prisma-ix-value,
.prisma-ix-clock {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}

.prisma-ix-clock {
  min-width: 84px;
}

/* The values now: one line (the badge, then x = …, y = …). */
.prisma-ix-readouts {
  grid-area: values;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 14px;
  min-width: 0;
}

.prisma-ix-readouts .prisma-ix-section-head {
  margin: 0;
}

.prisma-ix-readouts .prisma-ix-section-head h4 {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.prisma-ix-list {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 16px;
  margin: 0;
}

.prisma-ix-pair {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
}

.prisma-ix-list dt {
  color: var(--study-muted, #4f6470);
}

.prisma-ix-list dd {
  margin: 0;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.prisma-ix-readouts .prisma-ix-badge {
  padding: 0 6px;
  font-size: 10.5px;
}

.prisma-ix-extras {
  grid-area: extras;
  display: grid;
  gap: 6px;
  min-width: 0;
}

/* The time bar: in the deck's top row, next to the figure's name. */
.prisma-ix-time {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.prisma-ix-scrub {
  flex: 1 1 120px;
  width: auto;
  min-width: 80px;
}

.prisma-ix-button,
.prisma-ix-speed {
  min-width: 32px;
  min-height: 32px;
  border: 1px solid var(--study-control-line, #b9c4bd);
  border-radius: 8px;
  background: var(--study-control-bg, #fff);
  color: var(--study-ink, #173247);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
}

/* Play is the main action: filled. */
#prismaIxPlay {
  min-width: 40px;
  border-color: var(--study-accent, #077487);
  background: var(--study-accent, #077487);
  color: var(--study-on-accent, #fff);
}

.prisma-ix-button:hover {
  border-color: var(--study-accent, #077487);
  color: var(--study-accent, #077487);
}

#prismaIxPlay:hover {
  color: var(--study-on-accent, #fff);
  filter: brightness(1.08);
}

.prisma-ix-button:focus-visible,
.prisma-ix-speed:focus-visible,
.prisma-ix-range:focus-visible,
.prisma-ix-scrub:focus-visible,
.prisma-ix-deck-toggle:focus-visible,
.prisma-ix-check:focus-visible {
  outline: var(--study-focus-width, 2px) solid var(--study-accent, #077487);
  outline-offset: var(--study-focus-offset, 2px);
}

.prisma-ix-speed {
  font-size: 13px;
  padding: 0 4px;
}

.prisma-ix-graph {
  margin: 0;
}

.prisma-ix-graph svg {
  width: 100%;
  height: 58px;
  display: block;
  background: var(--study-canvas, #f1f3ef);
  border-radius: 6px;
}

.prisma-ix-graph-line {
  fill: none;
  stroke: var(--study-accent, #077487);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.prisma-ix-graph-cursor {
  stroke: var(--study-ochre, #b8844c);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.prisma-ix-graph-zero {
  stroke: var(--study-line, #d6ddd8);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.prisma-ix-graph figcaption {
  margin-top: 2px;
  color: var(--study-muted, #4f6470);
  font-size: 11.5px;
}

.prisma-ix-energy {
  display: grid;
  gap: 3px;
}

.prisma-ix-energy-row {
  display: grid;
  grid-template-columns: 64px 1fr;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
}

.prisma-ix-energy-track {
  height: 8px;
  border-radius: 4px;
  background: var(--study-canvas, #f1f3ef);
  overflow: hidden;
}

.prisma-ix-energy-fill {
  display: block;
  height: 100%;
  width: 0;
}

.prisma-ix-energy-kinetic {
  background: var(--study-accent, #077487);
}

.prisma-ix-energy-potential {
  background: var(--study-ochre, #b8844c);
}

.prisma-ix-energy-energy {
  background: var(--study-ink, #173247);
}

/* The study room resolves its scheme on <html data-study-theme>. */
html[data-study-theme="dark"] .prisma-ix-badge-live,
html[data-study-theme="dark"] .prisma-ix-badge-simulation {
  color: #e0b07a;
}

/* The board ends where the deck starts (the room's own furniture moves up
   with it: study-experience-v2.css reads --ix-deck too). */
html.study-v2-enabled body.prisma-ix-board #pizarraApp {
  bottom: var(--ix-deck, 0px);
}

/* The controls say how to use the figure; its pan/zoom hint gives way. */
body.prisma-ix-board .study-v2-board-hint {
  display: none;
}

/* Classic view, no active step: the explanation takes a row of its own
   between the canvas and the footer. */
html.study-v2-enabled body.board-mode.prisma-ix-open .whiteboard-container {
  grid-template-rows: 44px minmax(0, 1fr) auto 26px;
}

@media (max-width: 1180px) {
  html.study-v2-enabled body.board-mode.prisma-ix-open .whiteboard-container {
    grid-template-rows: auto minmax(0, 1fr) auto 24px;
  }
}

/* A narrower figure: the name gives its room to the time bar; a narrow
   one puts everything in one column. */
@container (max-width: 600px) {
  .prisma-ix-deck-name {
    display: none;
  }

  /* Three sliders or more need the row: the small graph gives way (the
     board draws the motion itself); the energy bars stay. */
  .prisma-ix-deck-body:has(.prisma-ix-param:nth-child(3)) .prisma-ix-graph {
    display: none;
  }

  .prisma-ix-deck-body:has(.prisma-ix-param:nth-child(3)):not(:has(.prisma-ix-energy)) {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "params" "values";
  }
}

@container (max-width: 420px) {
  .prisma-ix-deck-body:has(.prisma-ix-extras) {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "params" "values" "extras";
  }
}

@media (max-width: 980px) {
  /* The figure first, at its own height: the deck adds to it, above the
     row of board tools. */
  html.study-v2-enabled body.prisma-ix-board #pizarraApp {
    bottom: calc(44px + var(--ix-deck, 0px));
  }

  .prisma-ix-deck {
    bottom: 44px;
    max-height: none;
    padding-inline: 10px;
  }

  .prisma-ix-deck-name {
    display: none;
  }

  .prisma-ix-deck-body {
    overflow: visible;
  }

  html.study-v2-enabled body.board-mode.prisma-ix-open:not(.study-v2-board-hidden):not(.study-v2-expanded) .whiteboard-container {
    grid-template-rows: auto calc(var(--study-figure-height) + 44px + var(--ix-deck, 0px)) auto 24px;
  }

  .prisma-ix {
    max-height: none;
  }
}

/* v3 at the same widths: the board is a card pinned under the title bar,
   with no tool row under the drawing (study-experience-v3.css). The card
   grows by the deck's height, so the drawing keeps its own: with the card's
   fixed height the sliders left a 390 px phone a 44 px strip of drawing, the
   rest under the deck (tests/interactive_ai.spec.js, 20 Oct). */
@media (max-width: 980px) {
  html.study-v2-enabled.study-v3 body.prisma-ix-board #pizarraApp {
    bottom: var(--ix-deck, 0px);
  }

  html.study-v2-enabled.study-v3 .prisma-ix-deck {
    bottom: 0;
  }

  html.study-v2-enabled.study-v3
    body.board-mode.prisma-ix-board:not(.study-v2-board-hidden):not(.study-v2-expanded)
    .whiteboard-container {
    grid-template-rows: auto calc(var(--study-figure-height) + var(--ix-deck, 0px)) 0 !important;
  }
}

/* A narrow conversation (the figure above it, v2 and v3) reads the step in
   one column too (see .prisma-ix-in-step): side by side, a 390 px phone left
   the text about 115 px and the panel 210 (demo check, 20 Oct). */
@media (max-width: 980px) {
  /* The time bar never runs into "Parámetros": the time controls keep their
     least width (min-width: auto) and, when that and the button do not fit
     one row, the button takes a row of its own. The slider's least width is
     its min-width; its own width (a range input's 129 px) does not count. */
  .prisma-ix-deck-bar {
    flex-wrap: wrap;
    row-gap: 6px;
  }

  .prisma-ix-time {
    flex: 1 1 0;
    min-width: auto;
  }

  .prisma-ix-scrub {
    width: 0;
  }
}

@media (max-width: 520px) {
  .prisma-ix-speed,
  #prismaIxBack,
  #prismaIxForward {
    display: none;
  }

  /* On a phone the slider gives way down to 40 px: with its 80 px the clock
     ran into "Parámetros" at 390 px (demo check, 20 Oct). One row from about
     375 px; narrower, the button goes under the time controls. */
  .prisma-ix-scrub {
    min-width: 40px;
  }
}
