/* Step renderers added in v3 (intro, show, prompt size, missing image). Loaded after styles.css. */

/*
 * Show layout budget (landscape 16:9; --item-size = 14vmin = 14vh, --gap = 1.8vw = 3.2vh):
 *   stage 58vh; card chrome = padding 2.8vh + inner gap 0.84vh + 2-line label 6.44vh (2.8vmin × 1.15 × 2) ≈ 10.1vh.
 *   No big image, 2 rows of image cards: 2 × (10.1 + 16) + 3.2 row gap = 55.4vh ≤ 58vh.
 *   Big image + 2 rows: card image capped at 9vh → rows 2 × 19.1 + 3.2 = 41.4vh; the big image (flex-shrink,
 *   basis ≤ 28vh) gets 58 − 41.4 − 3.84 step gap ≈ 12.8vh. With one row it keeps its full 28vh.
 */
:root {
  --color-error: #e53935;
  --color-error-strong: #c62828;
  --color-error-soft: rgba(229, 57, 53, 0.06);
  --show-stage-height: 58vh;
  --show-image-height: min(28vh, calc(var(--item-size) * 2.2));
  --show-card-width: clamp(120px, calc(var(--item-size) * 1.9), 21vw);
}

/* ===== Missing image (for the content editor) ===== */
.content-missing {
  width: 80%;
  height: 80%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4%;
  border: max(3px, 0.35vmin) dashed var(--color-error);
  border-radius: calc(var(--radius) * 0.5);
  background: var(--color-error-soft);
  color: var(--color-error-strong);
  font-family: var(--font-main);
  font-size: clamp(12px, 1.6vmin, 32px);
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  overflow-wrap: anywhere;
  pointer-events: none;
}

/* ===== Prompt: item size (0.4–1.6) scales the whole card ===== */
.choice {
  --size: 1;
  width: calc(var(--item-size) * 1.45 * var(--size));
  height: calc(var(--item-size) * 1.45 * var(--size));
  font-size: calc(var(--item-size) * 0.85 * var(--size));
}

.choice.is-correct.is-quiet { animation: none; }

/* ===== Intro: tap a card, its name appears ===== */
.intro-card {
  --size: 1;
  position: relative;
  width: calc(var(--item-size) * 1.45 * var(--size));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--item-size) * 0.08);
  cursor: pointer;
  touch-action: none;
}

.intro-card > .content-image,
.intro-card > .content-missing {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  padding: 10%;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-item);
}

.intro-label {
  min-height: 1.3em;
  max-width: 100%;
  font-size: clamp(18px, 3.4vmin, 72px);
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  overflow-wrap: break-word;
  color: var(--color-text);
  visibility: hidden;
  opacity: 0;
  transition: opacity 250ms ease-out;
  pointer-events: none;
}

.intro-card.is-revealed .intro-label {
  visibility: visible;
  opacity: 1;
}

/* ===== Show: teacher-led, no touch ===== */
.show-step {
  --show-card-image-max: 16vh;
  width: 100%;
  height: 100%;
  max-height: var(--show-stage-height);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--gap) * 1.2);
  min-height: 0;
}

.show-step--with-image { --show-card-image-max: 9vh; }

/* Shrinks (down to 0) before the card rows overflow the stage. */
.show-image {
  align-self: stretch;
  flex: 0 1 var(--show-image-height);
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.show-image > .content-image,
.show-image > .content-missing {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.show-step > .row {
  flex: 0 0 auto;
  max-width: 100%;
}

.show-card {
  position: relative;
  /* 7 text cards: 5 per row at most → two rows inside a ~84vw stage. */
  width: var(--show-card-width);
  min-height: calc(var(--item-size) * 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--item-size) * 0.06);
  padding: calc(var(--item-size) * 0.1);
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-item);
}

.show-card > .content-image,
.show-card > .content-missing {
  width: 100%;
  height: min(var(--show-card-image-max), calc(var(--show-card-width) * 0.8));
  object-fit: contain;
}

.show-card-label {
  max-width: 100%;
  font-size: clamp(16px, 2.8vmin, 56px);
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  overflow-wrap: break-word;
  hyphens: manual;
  color: var(--color-text);
}

.show-card--text .show-card-label {
  font-size: clamp(18px, 3.1vmin, 66px);
}

.show-card-marker {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--item-size) * 0.5);
  font-weight: 800;
  color: var(--color-surface);
}

/* Hidden cards keep their final size (no layout jump on reveal); only the "?" shows. */
.show-card.is-concealed > :not(.show-card-marker) { visibility: hidden; }
.show-card.is-concealed > .show-card-marker { display: flex; }
.show-card.is-concealed { background: var(--color-zone-default); }

/* ===================== v4 touch steps (find, mixing, growing, cards) ===================== */
/*
 * Everything stays inside the stage band (20–78% of the height, 8vw side padding), so no touch
 * target reaches the top 20% band or a screen corner. Animations touch transform/opacity only.
 */
:root {
  --v4-ink: #2f3a56;
  --v4-ink-soft: rgba(47, 58, 86, 0.22);
  --v4-paper: #fffdf8;
  --v4-ceramic-light: #ffffff;
  --v4-ceramic-dark: #dfe5f2;
  --v4-ceramic-edge: #c3cde3;
  --v4-paint-empty: #eef1f8;
  --v4-card-back: #5c6bc0;
  --v4-card-back-line: rgba(255, 255, 255, 0.28);
  --v4-step-pad: 0.8vh;
}

/* ===== Find: tap every shape of the target kind ===== */
.find-step {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(var(--gap) * 2.4);
  padding: var(--v4-step-pad) 0;
  min-height: 0;
}

/* Picture fills the stage beside the target column; find.js lays shapes out for its measured aspect. */
.find-board {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  padding: calc(var(--item-size) * 0.06);
  background:
    radial-gradient(circle, var(--v4-ink-soft) 0.12vmin, transparent 0.16vmin) 0 0 / 4.5% 4.5%,
    var(--v4-paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow-item);
}

.find-picture {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.find-shape {
  stroke: var(--v4-ink-soft);
  stroke-width: 6;
  stroke-linejoin: round;
  /* P.motion pop/shake scale and move around the shape's own center. */
  transform-box: fill-box;
  transform-origin: center;
  cursor: pointer;
  touch-action: none;
}

.find-shape.is-found {
  stroke: var(--v4-ink);
  stroke-width: 22;
  paint-order: stroke;
  filter: drop-shadow(0 0 1.4vmin var(--color-highlight)) drop-shadow(0 0 0.5vmin var(--color-highlight));
}

.find-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--gap) * 1.2);
}

/* What to look for: neutral color, so the child matches the form, not the fill. */
.find-target {
  width: calc(var(--item-size) * 1.7);
  aspect-ratio: 1;
  padding: calc(var(--item-size) * 0.2);
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-item);
}

.find-target svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  fill: var(--v4-paper);
  stroke: var(--v4-ink);
  stroke-width: 6;
  stroke-linejoin: round;
}

.find-counter {
  max-width: calc(var(--item-size) * 1.9);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: calc(var(--item-size) * 0.1);
}

.find-counter-dot {
  width: calc(var(--item-size) * 0.24);
  height: calc(var(--item-size) * 0.24);
  border-radius: 50%;
  border: calc(var(--item-size) * 0.035) solid var(--v4-ink-soft);
  background: var(--color-surface);
}

.find-counter-dot.is-found {
  border-color: var(--color-success);
  background: var(--color-success);
}

/* ===== Mixing: paint pots → bowl → spoon ===== */
.mixing-step {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  min-height: 0;
}

.mixing-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(var(--gap) * 2.4);
}

/* Goal color in a dashed frame: decor only, never a touch target. */
.mixing-target {
  width: calc(var(--item-size) * 1.5);
  aspect-ratio: 1;
  padding: calc(var(--item-size) * 0.16);
  border: calc(var(--item-size) * 0.04) dashed var(--v4-ink-soft);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  pointer-events: none;
}

.mixing-target-blob {
  display: block;
  width: 100%;
  height: 100%;
}

/* The bowl is the drop zone: a ceramic body with the paint surface as its rim. */
.zone.mixing-bowl {
  position: relative;
  display: block;
  width: calc(var(--item-size) * 2.7);
  height: calc(var(--item-size) * 1.45);
  margin-top: calc(var(--item-size) * 0.45);
  padding: 0;
  border: calc(var(--item-size) * 0.04) solid var(--v4-ceramic-edge);
  border-top: none;
  border-radius: 0 0 50% 50% / 0 0 100% 100%;
  background: linear-gradient(180deg, var(--v4-ceramic-light), var(--v4-ceramic-dark));
  box-shadow: var(--shadow-item);
}

.mixing-paint {
  position: absolute;
  left: -2%;
  right: -2%;
  top: calc(var(--item-size) * -0.42);
  height: calc(var(--item-size) * 0.84);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(var(--item-size) * 0.12);
  overflow: hidden;
  border: calc(var(--item-size) * 0.04) solid var(--v4-ceramic-edge);
  border-radius: 50%;
  background: var(--paint, var(--v4-paint-empty));
  box-shadow: inset 0 0.8vmin 1.6vmin rgba(47, 58, 86, 0.18);
}

.mixing-drop {
  width: calc(var(--item-size) * 0.5);
  height: calc(var(--item-size) * 0.34);
  border-radius: 50%;
  background: var(--paint);
  box-shadow: inset 0 -0.5vmin 0.8vmin rgba(0, 0, 0, 0.18);
}

/* A circle wider than the oval paint, clipped by it: turning it shows only the color bands moving. */
.mixing-swirl {
  position: absolute;
  z-index: 1;
  left: 0;
  top: 50%;
  width: 100%;
  aspect-ratio: 1;
  margin-top: -50%;
  border-radius: 50%;
  background: conic-gradient(var(--swirl-from) 0 25%, var(--swirl-to) 0 50%, var(--swirl-from) 0 75%, var(--swirl-to) 0);
  opacity: 0;
  pointer-events: none;
}

.mixing-mix {
  width: calc(var(--item-size) * 1.15);
  height: calc(var(--item-size) * 1.15);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--color-primary);
  box-shadow: var(--shadow-item);
  cursor: pointer;
  touch-action: none;
  transition: opacity 200ms ease-out;
}

.mixing-mix:disabled {
  opacity: 0.35;
  cursor: default;
  box-shadow: none;
}

.mixing-mix svg {
  width: 62%;
  height: 62%;
  fill: var(--color-surface);
  pointer-events: none;
}

.mixing-step > .row { gap: calc(var(--gap) * 2); }

.mixing-pot {
  width: calc(var(--item-size) * 1.1);
  height: calc(var(--item-size) * 1.1);
}

.mixing-pot svg {
  width: 82%;
  height: 82%;
  pointer-events: none;
  fill: var(--v4-paint-empty);
  stroke: var(--v4-ceramic-edge);
  stroke-width: 3;
  stroke-linejoin: round;
}

.mixing-pot .mixing-pot-paint { stroke: none; }

/* Solved: the pots rest (keep their tile, which .item.is-locked would strip). */
.mixing-pot.is-locked {
  opacity: 0.45;
  background: var(--color-surface);
  box-shadow: none;
}

/* ===== Growing: tools onto the soil, the plant grows ===== */
.growing-step {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(var(--gap) * 3);
  padding: var(--v4-step-pad) 0;
  min-height: 0;
}

.growing-step > .row { flex-direction: column; }

.zone.growing-bed {
  position: relative;
  width: calc(var(--item-size) * 2.8);
  height: min(100%, calc(var(--item-size) * 3.6));
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-end;
  flex-wrap: nowrap;
  gap: 0;
  padding: calc(var(--item-size) * 0.1);
  background: rgba(255, 255, 255, 0.45);
}

.growing-plant {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  /* Grows out of the soil line. */
  transform-origin: 50% 100%;
}

.growing-plant > .content-image,
.growing-plant > .content-missing {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: 50% 100%;
}

.growing-soil {
  flex: 0 0 auto;
  height: calc(var(--item-size) * 0.9);
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Stage images bring their own soil: the bare pot is only shown before the first stage. */
.growing-plant:not(:empty) + .growing-soil { display: none; }

.growing-soil > .content-image,
.growing-soil > .content-missing {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.growing-tool.is-used {
  opacity: 0.25;
  transition: opacity 300ms ease-out;
}

/* ===== Cards: face-down questions, one opens big at a time ===== */
.cards-step {
  --cards-move-ms: 550ms;
  --cards-height: min(25vh, 20vw);
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(5, auto);
  gap: calc(var(--gap) * 0.9) var(--gap);
}

.cards-card {
  position: relative;
  z-index: 1;
  width: calc(var(--cards-height) * 0.74);
  height: var(--cards-height);
  perspective: 1400px;
  cursor: pointer;
  touch-action: none;
  transition: transform var(--cards-move-ms) cubic-bezier(0.22, 1, 0.36, 1), opacity 250ms ease-out;
}

.cards-card.is-open { z-index: 20; }

.cards-step.has-open .cards-card:not(.is-open),
.cards-card.is-locked { pointer-events: none; }

.cards-card.is-locked { opacity: 0.4; }

.cards-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform var(--cards-move-ms) ease-in-out;
}

.cards-card.is-face-up .cards-inner { transform: rotateY(180deg); }

.cards-back,
.cards-front {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: calc(var(--radius) * 0.8);
  backface-visibility: hidden;
  box-shadow: var(--shadow-item);
}

.cards-back {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--v4-card-back);
  border: calc(var(--item-size) * 0.05) solid var(--color-surface);
}

.cards-back-pattern {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: var(--v4-card-back-line);
  stroke-width: 1.4;
}

.cards-back-pattern circle {
  fill: var(--v4-card-back-line);
  stroke: none;
}

.cards-back-marker {
  position: relative;
  width: 52%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--color-surface);
  color: var(--v4-card-back);
  font-size: calc(var(--cards-height) * 0.26);
  font-weight: 900;
  line-height: 1;
}

.cards-front {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10%;
  background: var(--color-surface);
  transform: rotateY(180deg);
}

.cards-question {
  margin: 0;
  max-width: 100%;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  overflow-wrap: break-word;
  color: var(--color-text);
}

/* Answered: back in its slot, face-up, ringed in green. */
.cards-card.is-done:not(.is-open) .cards-front {
  box-shadow: inset 0 0 0 calc(var(--item-size) * 0.05) var(--color-success), var(--shadow-item);
}

@media (prefers-reduced-motion: reduce) {
  .cards-card,
  .cards-inner,
  .growing-tool.is-used,
  .mixing-mix { transition: none; }
}
