/* v4 teacher-checked steps: sketch pad, writing, equation, map; loaded after steps.css.
   Everything lives inside the stage band (20–78%), so no touch target reaches the top band or the corners.
   Grids size themselves with container query units (cqw/cqh) of the step root. */

:root {
  --teacher-pad-surface: var(--color-surface, #ffffff);
  --teacher-pad-edge: rgba(93, 107, 138, 0.16);
  --teacher-pad-guide: rgba(93, 107, 138, 0.28);
  --teacher-pad-radius: calc(var(--radius) * 0.6);
  --teacher-pad-aspect: 1.25;
  /* Kept small and in the corner so it is not hit by accident (it also needs a hold, see config.eraseHoldMs). */
  --teacher-eraser-size: clamp(32px, calc(var(--item-size) * 0.28), 76px);
  --teacher-cross: var(--color-error, #e53935);
  --teacher-numeral-1: #e65100;
  --teacher-numeral-2: #2e7d32;
  --teacher-numeral-3: #1565c0;
  --teacher-numeral-4: #ad1457;
  --map-neutral: #e3e8f1;
  --map-border: #ffffff;
  --map-label-outline: #ffffff;
  --teacher-toggle-ms: 220ms;
}

/* ===== Sketch pad (js/sketch.js) ===== */
.sketch-pad {
  position: relative;
  overflow: hidden;
  border-radius: var(--teacher-pad-radius);
  background: var(--teacher-pad-surface);
  box-shadow: var(--shadow-item), inset 0 0 0 max(2px, 0.25vmin) var(--teacher-pad-edge);
  touch-action: none;
}

/* Writing line: a faint dashed baseline the numerals can sit on. */
.sketch-pad::before {
  content: '';
  position: absolute;
  left: 9%;
  right: 9%;
  bottom: 22%;
  border-top: max(2px, 0.28vmin) dashed var(--teacher-pad-guide);
  pointer-events: none;
}

.sketch-pad__canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.sketch-pad__erase {
  position: absolute;
  right: calc(var(--teacher-eraser-size) * 0.18);
  bottom: calc(var(--teacher-eraser-size) * 0.18);
  z-index: 1;
  width: var(--teacher-eraser-size);
  height: var(--teacher-eraser-size);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--teacher-eraser-size) * 0.2);
  border: max(2px, 0.22vmin) solid var(--teacher-pad-edge);
  border-radius: 50%;
  background: var(--teacher-pad-surface);
  color: var(--color-muted);
  box-shadow: 0 0.3vmin 0.8vmin rgba(47, 58, 86, 0.14);
  cursor: pointer;
  touch-action: none;
}

.sketch-pad__erase:active { transform: scale(0.92); }

/* Hold progress ring, the same look as the ▶ / ↻ ring (css/styles.css hold-fill). */
.sketch-pad__erase::after {
  content: '';
  position: absolute;
  inset: calc(var(--teacher-eraser-size) * -0.14);
  border-radius: 50%;
  background: conic-gradient(var(--color-highlight) calc(var(--hold-progress) * 1%), transparent 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
  opacity: 0;
  pointer-events: none;
}

.sketch-pad__erase.is-holding::after {
  opacity: 1;
  animation: hold-fill var(--hold-ms) linear forwards;
}

.sketch-pad__erase:focus-visible {
  outline: max(3px, 0.3vmin) solid var(--color-primary);
  outline-offset: 2px;
}

.sketch-pad__erase-icon {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

/* ===== Writing: numerals above drawing boxes, up to 2 × 5 ===== */
.writing-step {
  --writing-columns: 5;
  --writing-rows: 2;
  --writing-label-height: clamp(30px, 7vh, 150px);
  --writing-inner-gap: calc(var(--gap) * 0.25);
  container-type: size;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(var(--writing-columns), auto);
  place-content: center;
  gap: var(--gap);
}

.writing-cell {
  --cell-width: calc((100cqw - (var(--writing-columns) - 1) * var(--gap)) / var(--writing-columns));
  --cell-height: calc((100cqh - (var(--writing-rows) - 1) * var(--gap)) / var(--writing-rows));
  --pad-height: calc(var(--cell-height) - var(--writing-label-height) - var(--writing-inner-gap));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--writing-inner-gap);
  min-width: 0;
}

.writing-label {
  height: var(--writing-label-height);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--writing-label-height) * 0.92);
  font-weight: 900;
  line-height: 1;
  color: var(--teacher-numeral-1);
  pointer-events: none;
}

.writing-cell:nth-child(4n + 2) .writing-label { color: var(--teacher-numeral-2); }
.writing-cell:nth-child(4n + 3) .writing-label { color: var(--teacher-numeral-3); }
.writing-cell:nth-child(4n + 4) .writing-label { color: var(--teacher-numeral-4); }

/* v5.1: MEB upright print font (--font-school, set by letters.js from config); the rounded font when it is missing. */
.writing-label > .content-text { font-family: var(--font-school, var(--font-main)); }

.writing-label > .content-image,
.writing-label > .content-missing {
  width: auto;
  height: 100%;
  aspect-ratio: 1;
}

.writing-cell > .sketch-pad {
  height: var(--pad-height);
  width: min(var(--cell-width), calc(var(--pad-height) * var(--teacher-pad-aspect)));
}

/* ===== Equation: pictures, then "a op b =" and one drawing box ===== */
.equation-step {
  --equation-gap: var(--gap);
  container-type: size;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--equation-gap) * 1.2);
}

.equation-objects {
  --equation-count: 1;
  /* Fits all pictures plus the operator on one line; never taller than ~38% of the stage. */
  --equation-object: min(38cqh, var(--item-size) * 1.15,
    calc((100cqw - var(--equation-gap) * 2) / (var(--equation-count) + 1.4)));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(var(--equation-object) * 0.3);
  max-width: 100%;
}

.equation-group {
  display: flex;
  align-items: center;
  gap: calc(var(--equation-object) * 0.06);
}

.equation-object {
  position: relative;
  width: var(--equation-object);
  height: var(--equation-object);
  display: flex;
  align-items: center;
  justify-content: center;
}

.equation-object > .content-image,
.equation-object > .content-missing {
  width: 100%;
  height: 100%;
}

.equation-object > .content-text { font-size: calc(var(--equation-object) * 0.8); }

/* Taken away: faded picture under a red cross. */
.equation-object--removed > * { opacity: 0.32; filter: grayscale(0.6); }

.equation-object--removed::after {
  --cross-half: max(2px, calc(var(--equation-object) * 0.045));
  content: '';
  position: absolute;
  inset: 6%;
  background:
    linear-gradient(to top right, transparent calc(50% - var(--cross-half)), var(--teacher-cross) calc(50% - var(--cross-half)),
      var(--teacher-cross) calc(50% + var(--cross-half)), transparent calc(50% + var(--cross-half))),
    linear-gradient(to bottom right, transparent calc(50% - var(--cross-half)), var(--teacher-cross) calc(50% - var(--cross-half)),
      var(--teacher-cross) calc(50% + var(--cross-half)), transparent calc(50% + var(--cross-half)));
  pointer-events: none;
}

.equation-operator {
  font-size: calc(var(--equation-object) * 0.9);
  font-weight: 900;
  line-height: 1;
  color: var(--color-primary);
  pointer-events: none;
}

.equation-line {
  --equation-pad-height: min(44cqh, 34cqw);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(var(--equation-gap) * 1.2);
}

.equation-numbers {
  font-size: min(20cqh, 12cqw);
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
  word-spacing: 0.08em;
  color: var(--color-text);
  pointer-events: none;
}

.equation-answer {
  height: var(--equation-pad-height);
  width: calc(var(--equation-pad-height) * var(--teacher-pad-aspect));
}

/* ===== Map: tap a region, it takes its color and shows its name ===== */
.map-step {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.map-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.map-region {
  fill: var(--map-neutral);
  stroke: var(--map-border);
  stroke-width: max(2px, 0.35vmin);
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.map-region path { vector-effect: non-scaling-stroke; }

.map-region--interactive {
  cursor: pointer;
  touch-action: none;
}

.map-region.is-revealed { fill: var(--region-color); }

.map-label {
  font-family: var(--font-main);
  font-weight: 900;
  text-anchor: middle;
  dominant-baseline: central;
  fill: var(--color-text);
  stroke: var(--map-label-outline);
  stroke-width: 0.2em;
  stroke-linejoin: round;
  paint-order: stroke;
  opacity: 0;
  transition: opacity var(--teacher-toggle-ms) ease-out;
  pointer-events: none;
}

.map-label.is-revealed { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .map-label { transition: none; }
  .sketch-pad__erase:active { transform: none; }
}
