/* The Tutor page's stage (tutor.html), 2026-11-22. An exercise book on the dark stage: a page of
   squared paper, turned a little, the pupil's writing in a slanted hand and the tutor's notes as red
   cards in the margin. js/modes.js sets data-step on .mode-demo (0 Ask, 1 Hint, 2 Try, 3 Check,
   4 Next) and this file draws each step from it; js/mode-tutor.js adds is-picked and is-wrong for the
   pupil's answer on Try. Everything is shown unless a step hides it, so without the script (and with
   reduced motion, where the player shows the last step) the finished page reads on its own. */

.tutor-demo {
  --tb-ink: var(--c-charcoal);
  --tb-grid: oklch(46.4% 0.013 39.4 / 0.15);
  --sq: clamp(14px, 0.75rem + 0.7vw, 24px);
  /* The stage and the answer chips share one cell, so the chips lie on the desk under the book
     while staying outside the stage that screen readers skip. */
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}
.tutor-demo > .mode-stage, .tutor-demo > .tutor-try { grid-area: 1 / 1; }

.tutor-demo .mode-stage {
  display: grid; place-items: center;
  /* The bottom padding is the room the chips need. */
  padding: clamp(1.25rem, 0.8rem + 3vw, 4rem) clamp(0.85rem, 0.4rem + 3vw, 4rem) 7.75rem;
  /* Light falls from above, as from a desk lamp, so the paper reads as lying on a desk. */
  background-image: radial-gradient(ellipse 70% 60% at 50% 0%, oklch(32% 0.012 30 / 0.55), transparent 70%);
}

/* ---------- the book ---------- */

.tb-book { position: relative; width: min(100%, 54rem); transform: rotate(-1.4deg); }
/* A second sheet peeks out underneath, so it reads as a book and not as a card. */
.tb-book::before {
  content: ""; position: absolute; inset: 0.4rem -0.35rem -0.55rem 0.5rem;
  border-radius: 4px 6px 8px 4px; background: var(--c-blush); transform: rotate(1.8deg);
  box-shadow: 0 1.5rem 3rem -1rem oklch(0% 0 0 / 0.7);
}

.tb-page {
  --pl: clamp(0.9rem, 0.5rem + 2vw, 2.5rem);
  --pr: clamp(0.5rem, 0.3rem + 1vw, 1.25rem);
  --split: 0.62;
  position: relative;
  display: grid; grid-template-columns: minmax(0, 62fr) minmax(0, 38fr); align-items: start;
  padding: calc(var(--sq) * 1.2) var(--pr) calc(var(--sq) * 1.5) var(--pl);
  border-radius: 3px 6px 6px 3px;
  background-color: var(--c-paper);
  background-image:
    linear-gradient(to right, var(--tb-grid) 1px, transparent 1px),
    linear-gradient(to bottom, var(--tb-grid) 1px, transparent 1px);
  background-size: var(--sq) var(--sq);
  color: var(--tb-ink);
  font-size: clamp(1.05rem, 0.8rem + 1.1vw, 1.85rem);
  box-shadow: 0 2rem 3rem -1.5rem oklch(0% 0 0 / 0.75);
}
/* The fold of the book along the left edge. */
.tb-page::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 1.5rem; border-radius: inherit; pointer-events: none;
  background: linear-gradient(to right, oklch(31.8% 0.005 67.7 / 0.14), transparent);
}
/* The red margin line runs the full height of the page, where the second column starts. */
.tb-page::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 2px;
  left: calc(var(--pl) + (100% - var(--pl) - var(--pr)) * var(--split));
  background: oklch(52.1% 0.211 29.1 / 0.55);
}

/* ---------- the pupil's hand ---------- */

/* The site's own Chivo, slanted and a touch uneven, stands in for handwriting: no extra font. */
.tb-hand { margin: 0; font-style: italic; font-weight: var(--w-body); letter-spacing: 0.01em; line-height: 1.25; }
.tb-title { grid-column: 1 / -1; justify-self: start; margin-bottom: calc(var(--sq) * 0.5); padding-bottom: 0.08em;
  border-bottom: 2px solid currentColor; }
.tb-line { padding: calc(var(--sq) * 0.45) 0.5em calc(var(--sq) * 0.9) 0; transform-origin: left center; transform: rotate(-0.7deg); }
.tb-line--try { transform: rotate(-0.3deg); }
.tb-line--next { transform: rotate(-1deg); }
.tb-line--ask { --d0: 200ms; }

/* One word at a time, left to right, as the pupil writes. --dy gives each word a slightly different
   height on the line, the way a hand never keeps it perfectly level. */
.tb-w, .tb-title {
  --i: 0; --dy: 0em;
  display: inline-block;
  transform: translateY(var(--dy));
  transition: opacity 360ms var(--ease-out-quart), transform 560ms var(--ease-out-expo);
  transition-delay: calc(var(--d0, 0ms) + var(--i) * 110ms);
}
.tb-title { display: block; }
.tb-w:nth-child(3n+2) { --dy: -0.04em; }
.tb-w:nth-child(3n) { --dy: 0.035em; }
.tb-w:nth-child(2) { --i: 1; }
.tb-w:nth-child(3) { --i: 2; }
.tb-w:nth-child(4) { --i: 3; }
.tb-w:nth-child(5) { --i: 4; }
.tb-w:nth-child(6) { --i: 5; }
.tb-w:nth-child(7) { --i: 6; }

/* A fraction is a number over a number with a bar between them, as a pupil writes it. */
.tb-frac { display: inline-grid; vertical-align: middle; margin: 0 0.08em; font-size: 0.82em; line-height: 1.08; text-align: center; }
.tb-frac__n, .tb-frac__d { display: block; min-width: 1.1em; padding-inline: 0.12em; }
.tb-frac__n { padding-bottom: 0.04em; border-bottom: 0.085em solid currentColor; border-radius: 0 0 1px 1px; }
.tb-frac__d { padding-top: 0.04em; }

/* The open place for the pupil's answer: a dashed box that blinks while the demo waits on Try. */
.tb-blank { position: relative; }
.tb-blank::before {
  content: ""; position: absolute; inset: 0.12em -0.04em -0.04em; border: 1.5px dashed var(--c-red); border-radius: 0.2em;
  opacity: 0; transition: opacity var(--dur) var(--ease-out-quart);
}
.tutor-demo[data-step="2"]:not(.is-picked) .tb-blank::before { opacity: 1; animation: tb-blink 1.1s ease-in-out infinite alternate; }
@keyframes tb-blink { to { opacity: 0.3; } }

.tb-pick { position: relative; display: inline-block; transition: opacity 300ms var(--ease-out-quart), transform 420ms var(--ease-out-expo); }
.tutor-demo[data-step="2"]:not(.is-picked) .tb-pick { opacity: 0; transform: translateY(-0.2em); transition-duration: 120ms; }
/* A wrong answer is struck through, the way a pupil would. It only animates on the way in, so the
   stroke never shrinks across the right answer that replaces it. */
.tb-pick::after {
  content: ""; position: absolute; left: -0.2em; right: -0.2em; top: 52%; height: 0.1em; border-radius: 1px;
  background: var(--c-red); transform-origin: left center; transform: rotate(-16deg) scaleX(0);
}
.tutor-demo.is-wrong[data-step="2"] .tb-pick::after { transform: rotate(-16deg) scaleX(1); transition: transform 300ms var(--ease-out-quart) 120ms; }

.tb-tick {
  display: inline-block; width: 1.05em; height: 1.05em; margin-left: 0.35em; vertical-align: middle;
  fill: none; stroke: var(--c-red); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round;
  transform-origin: 20% 80%;
  transition: opacity 260ms var(--ease-out-quart) 300ms, transform 520ms var(--ease-out-expo) 300ms;
}

/* ---------- the tutor's notes ---------- */

.tb-margin { display: grid; padding: calc(var(--sq) * 0.3) 0 calc(var(--sq) * 0.6) clamp(0.45rem, 0.3rem + 0.8vw, 1rem); }
/* The wrong-answer note and the yes share one place in the margin; only one shows at a time. */
.tb-margin > .tb-note { grid-area: 1 / 1; align-self: start; }
.tb-note {
  --r: 1deg; --wait: 240ms;
  display: flex; gap: 0.45em; align-items: flex-start; margin: 0; padding: 0.6em 0.75em 0.65em;
  border-radius: 10px; background: var(--c-red); color: var(--c-paper);
  font-size: max(12px, clamp(0.75rem, 0.6rem + 0.45vw, 1rem)); font-style: normal; font-weight: var(--w-ui); line-height: 1.35; letter-spacing: 0;
  box-shadow: 0 0.6rem 1rem -0.6rem oklch(0% 0 0 / 0.55);
  transform: rotate(var(--r));
  transition: opacity 320ms var(--ease-out-quart), transform 560ms var(--ease-out-expo);
  transition-delay: var(--wait);
}
.tb-note .petal { width: 0.55em; height: 0.9em; margin-top: 0.2em; color: oklch(100% 0 0 / 0.72); }
.tb-note--wrong { --r: -1.2deg; --wait: 200ms; }
.tb-note--right { --r: 0.8deg; --wait: 600ms; }
/* The last note waits until the pupil has written the whole line. */
.tb-note--done { --r: -0.6deg; --wait: 900ms; }

/* ---------- the steps ----------
   Ask: the question. Hint: and the hint. Try: and the pupil's line, its answer open.
   Check: and the tick and the tutor's yes. Next: and the worked line and the last note. */

.tutor-demo:is([data-step="0"], [data-step="1"]) .tb-line--try .tb-w,
.tutor-demo:is([data-step="0"], [data-step="1"], [data-step="2"], [data-step="3"]) .tb-line--next .tb-w,
.tutor-demo.is-blank .tb-line--ask .tb-w,
.tutor-demo.is-blank .tb-title {
  opacity: 0; transform: translate(-0.3em, 0.15em); transition-duration: 150ms; transition-delay: 0s;
}
/* is-blank wipes the question at once so it can be written again on the next round. */
.tutor-demo.is-blank .tb-line--ask .tb-w, .tutor-demo.is-blank .tb-title { transition: none; }

.tutor-demo[data-step="0"] .tb-note--hint,
.tutor-demo:is([data-step="0"], [data-step="1"], [data-step="2"]) .tb-note--right,
.tutor-demo:is([data-step="0"], [data-step="1"], [data-step="2"], [data-step="3"]) .tb-note--done,
.tutor-demo:not(.is-wrong) .tb-note--wrong,
.tutor-demo:not([data-step="2"]) .tb-note--wrong {
  opacity: 0; transform: translateX(0.9rem) rotate(calc(var(--r) + 3deg)); transition-duration: 150ms; transition-delay: 0s;
}

.tutor-demo:is([data-step="0"], [data-step="1"], [data-step="2"]) .tb-tick {
  opacity: 0; transform: scale(0.3) rotate(-25deg); transition-duration: 120ms; transition-delay: 0s;
}

/* ---------- the pupil's answer, picked by the visitor ---------- */

.tutor-try {
  z-index: var(--z-raised); align-self: end; justify-self: center;
  display: flex; flex-direction: column; align-items: center; gap: var(--s-2);
  margin-bottom: clamp(1rem, 0.8rem + 1vw, 1.75rem);
}
.tutor-try__k { color: var(--ink-muted); font-size: var(--t-small); font-weight: var(--w-strong); }
.tutor-try__chips { display: flex; gap: var(--s-2); }
.tutor-chip {
  min-width: 3.5rem; min-height: 2.75rem; padding: 0 1.1rem;
  border: 1px solid var(--rule-firm); border-radius: 999px;
  background: var(--bg-raised); color: var(--ink-muted);
  font: inherit; font-size: 1.15rem; font-weight: var(--w-display); cursor: pointer;
  transition: opacity var(--dur) var(--ease-out-quart), transform var(--dur) var(--ease-out-quart),
    background-color var(--dur) var(--ease-out-quart), color var(--dur) var(--ease-out-quart), box-shadow var(--dur) var(--ease-out-quart);
}
.tutor-chip[aria-disabled="true"] { opacity: 0.45; cursor: default; }
.tutor-chip:focus-visible { outline: 2px solid var(--c-petal); outline-offset: 3px; }
/* On Try the chips light up like paper and lift a little: this is where the visitor joins in. */
.tutor-demo[data-step="2"] .tutor-chip {
  opacity: 1; transform: translateY(-2px);
  background: var(--c-paper); border-color: var(--c-paper); color: var(--c-charcoal);
  box-shadow: 0 0 0 3px oklch(52.1% 0.211 29.1 / 0.6);
}
.tutor-demo[data-step="2"] .tutor-chip:hover { transform: translateY(-3px); box-shadow: 0 0 0 3px var(--c-red); }
.tutor-demo[data-step="2"] .tutor-chip.is-wrong {
  opacity: 0.55; transform: none; box-shadow: none;
  text-decoration: line-through 2px var(--c-red);
}
/* After the check the right answer stays marked, in the tutor's red. */
.tutor-demo:is([data-step="3"], [data-step="4"]) .tutor-chip[data-answer="12"] {
  opacity: 1; background: var(--c-red); border-color: var(--c-red); color: var(--c-paper);
}

/* ---------- phones ---------- */

@media (max-width: 560px) {
  .tb-book { transform: rotate(-1deg); }
  .tb-page { --split: 0.56; grid-template-columns: minmax(0, 56fr) minmax(0, 44fr); }
  /* The margin is narrow here; the words need the room more than the petal does. */
  .tb-note .petal { display: none; }
}

/* ---------- reduced motion: every state appears at once ---------- */

@media (prefers-reduced-motion: reduce) {
  .tutor-demo .tb-w, .tutor-demo .tb-title, .tutor-demo .tb-note, .tutor-demo .tb-tick,
  .tutor-demo .tb-pick, .tutor-demo .tb-pick::after, .tutor-demo .tb-blank::before, .tutor-chip { transition: none; }
  .tutor-demo .tb-blank::before { animation: none; }
}
