/* Worked solutions: maths inside an answer, the class board beside it
   (board.js), and the way to the subject a question belongs to. */

/* ---------- maths in an answer ---------- */

/* maths written between backticks: left to right inside Arabic, in a face
   with real mathematical glyphs */
.bubble .m {
  unicode-bidi: isolate;
  font-family: "Cambria Math", "STIX Two Math", "Latin Modern Math", "Times New Roman", serif;
  font-size: 1.06em;
}

/* ---------- the class board: its own window ---------- */

/* the panel the book opens in has two tabs once there is a board */
.panel-tabs {
  display: flex; gap: 4px; flex: none;
  padding: 8px 10px 0;
}
.panel-tabs[hidden] { display: none; }
@media (max-width: 640px) { .panel-tabs { padding-block-start: calc(8px + env(safe-area-inset-top, 0px)); } }
.panel-tab {
  all: unset; cursor: pointer;
  padding: 7px 16px;
  border-radius: 12px 12px 0 0;
  font-size: .88rem; font-weight: 600;
  color: var(--text-2);
  border: 1px solid transparent; border-block-end: 0;
}
.panel-tab:hover { color: var(--text); background: var(--wash); }
.panel-tab.is-on { color: var(--text); background: var(--glass); border-color: var(--rim); }
.panel-tab:focus-visible { outline: 2px solid var(--hl); outline-offset: -2px; }

/* the board's tab: the book's bar, search, page and footer step aside */
.panel--board .panel-bar,
.panel--board .find,
.panel--board .find-results,
.panel--board .panel-body,
.panel--board .panel-foot { display: none !important; }

.board-view {
  flex: 1; min-block-size: 0;
  display: flex; flex-direction: column;
  padding: 10px;
}
.board-view[hidden] { display: none; }
.board-view .board { flex: 1; min-block-size: 0; display: flex; flex-direction: column; }
.board-view .board-slate { flex: 1; min-block-size: 0; overflow-y: auto; }

.board {
  --slate: #1f3a2c;
  --chalk: #f4f1e6;
  --chalk-y: #ffe27a;
  --chalk-b: #a9d8ff;
  --chalk-p: #ffb8cb;
  border-radius: 14px;
  padding: 10px 10px 0;
  background: linear-gradient(160deg, #8a5a32, #5f3b1f 55%, #7a4d2a);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18), 0 22px 44px -28px rgba(0, 0, 0, .75);
  color: var(--chalk);
}
.board-bar {
  display: flex; align-items: center; gap: 8px; flex: none;
  padding: 0 4px 10px;
  color: var(--text);
  font-size: .9rem; font-weight: 600;
}
.board-title { display: inline-flex; align-items: center; gap: 8px; flex: none; }
.board-title .ico { inline-size: 18px; block-size: 18px; }
.board-src { margin-inline-start: auto; min-inline-size: 0; display: flex; }
.board-page {
  all: unset; cursor: pointer;
  padding: 4px 12px; border-radius: 999px;
  background: var(--hl); color: var(--hl-ink);
  font-size: .8rem; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-inline-size: 100%;
}
.board-page:hover { filter: brightness(1.05); }
.board-btn {
  all: unset; cursor: pointer; display: grid; place-items: center; flex: none;
  inline-size: 34px; block-size: 34px; border-radius: 10px;
  color: var(--text-2);
}
.board-src:empty + .board-btn { margin-inline-start: auto; }
.board-btn:hover { background: var(--wash); color: var(--text); }
.board-btn .ico { inline-size: 18px; block-size: 18px; }
.board-page:focus-visible, .board-btn:focus-visible { outline: 2px solid var(--hl); outline-offset: 2px; }

/* in the conversation, only the way back to the board */
.board-chip {
  all: unset; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
  margin-block-start: var(--s3);
  padding: 8px 14px 8px 12px;
  border-radius: 12px;
  background: linear-gradient(160deg, #24432f, #1b3326);
  border: 2px solid #6b4423;
  color: #f4f1e6;
  font-size: .9rem; font-weight: 600;
  box-shadow: 0 10px 22px -16px rgba(0, 0, 0, .8);
  transition: transform .2s var(--ease), filter .2s;
}
.board-chip .ico { inline-size: 18px; block-size: 18px; color: #ffe27a; }
.board-chip:hover { transform: translateY(-1px); filter: brightness(1.1); }
.board-chip:focus-visible { outline: 2px solid var(--hl); outline-offset: 2px; }

/* the slate: dark green, a little uneven, the ghost of the last lesson rubbed
   out across it */
.board-slate {
  position: relative;
  display: flex; flex-direction: column; gap: 6px;
  min-block-size: 120px;
  padding: 18px 20px 20px;
  border-radius: 6px;
  background:
    radial-gradient(120% 70% at 20% 15%, rgba(255, 255, 255, .055), transparent 60%),
    radial-gradient(90% 60% at 85% 90%, rgba(255, 255, 255, .04), transparent 60%),
    radial-gradient(40% 25% at 70% 30%, rgba(255, 255, 255, .03), transparent 70%),
    linear-gradient(175deg, #24432f, var(--slate) 60%, #1b3326);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .35), inset 0 0 40px rgba(0, 0, 0, .35);
  font-family: var(--sans);
  font-size: 1.02rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
  /* chalk: soft edges, a little dust */
  text-shadow: 0 0 1px rgba(255, 255, 255, .55), 0 0 7px rgba(255, 255, 255, .12);
}
.board .bd-m {
  unicode-bidi: isolate;
  font-family: "Cambria Math", "STIX Two Math", "Latin Modern Math", "Times New Roman", serif;
  font-size: 1.12em;
}
.bd-problem {
  padding-block-end: 8px; margin-block-end: 4px;
  border-block-end: 2px dashed rgba(244, 241, 230, .28);
  font-weight: 600;
}
.bd-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.bd-label { color: var(--chalk-p); font-size: .86em; font-weight: 600; flex: none; }
.bd-label::after { content: ":"; }
.bd-list { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.bd-rule .bd-label { color: var(--chalk-b); }
.bd-rule .bd-m { font-size: 1.22em; }
.bd-step {
  display: flex; align-items: baseline; gap: 8px;
  margin-block-start: 8px;
  color: var(--chalk-y);
  font-size: .92em; font-weight: 600;
}
.bd-n {
  display: inline-grid; place-items: center; flex: none;
  inline-size: 1.6em; block-size: 1.6em;
  border: 1.5px solid currentColor; border-radius: 50%;
  font-size: .82em; line-height: 1;
}
/* the working lines up under its step, each line written left to right */
.bd-line { padding-inline-start: 2.2em; }
/* pieces of working joined by a word: 2x - 3 = 0  أو  x - 1 = 0 */
.bd-joined { display: flex; flex-wrap: wrap; align-items: baseline; gap: .2em .7em; }
.bd-join { font-size: .8em; opacity: .7; }
.bd-answer {
  align-self: flex-start;
  display: inline-flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px;
  margin-block-start: 12px;
  padding: 6px 14px;
  border: 2px solid var(--chalk-y);
  border-radius: 12px 16px 10px 18px;
  color: var(--chalk-y);
  font-weight: 700;
  transform: rotate(-.6deg);
}
.bd-answer .bd-label { color: inherit; }
.bd-answer .bd-m { font-size: 1.18em; }

/* each line is written, not shown: it goes on the way chalk does, from the
   side the line starts on */
.board .bd-in { animation: chalk-rtl .6s cubic-bezier(.3, .7, .2, 1) var(--d, 0s) both; }
:root:not([dir="rtl"]) .board .bd-in { animation-name: chalk-ltr; }
@keyframes chalk-ltr {
  from { clip-path: inset(0 100% 0 0); opacity: .4; }
  to { clip-path: inset(0 0 0 0); opacity: 1; }
}
@keyframes chalk-rtl {
  from { clip-path: inset(0 0 0 100%); opacity: .4; }
  to { clip-path: inset(0 0 0 0); opacity: 1; }
}

/* the ledge, with chalk and the duster */
.board-tray { position: relative; block-size: 16px; }
.board-tray .chalk, .board-tray .eraser { position: absolute; inset-block-start: 4px; border-radius: 3px; }
.board-tray .chalk { inline-size: 30px; block-size: 6px; background: #f2efe4; inset-inline-start: 22%; box-shadow: 0 1px 0 rgba(0, 0, 0, .3); }
.board-tray .chalk--y { background: var(--chalk-y); inset-inline-start: calc(22% + 40px); inline-size: 22px; transform: rotate(-4deg); }
.board-tray .eraser {
  inset-block-start: 1px; inline-size: 46px; block-size: 10px; inset-inline-end: 18%;
  background: linear-gradient(#6b6f77 0 45%, #e9e2cf 45%);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .35);
}

/* enlarged: the board fills the window, the way it fills the front of a class */
.board-view.is-big {
  position: fixed; inset: 0; z-index: 90;
  max-inline-size: none; margin: 0;
  display: flex; flex-direction: column; justify-content: center;
  padding: max(16px, 4vh) max(16px, 5vw);
  border-radius: 0;
  background: rgba(8, 12, 10, .72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: none;
  animation: none;
}
.board-view.is-big .board-bar, .board-view.is-big .board { inline-size: min(1100px, 100%); margin-inline: auto; box-sizing: border-box; }
.board-view.is-big .board-bar, .board-view.is-big .board-btn { color: #f4f1e6; }
.board-view.is-big .board-btn:hover { background: rgba(255, 255, 255, .1); }
.board-view.is-big .board { flex: 0 1 auto; max-block-size: 86vh; }
.board-view.is-big .board-slate { font-size: clamp(1.1rem, 2.1vw, 1.6rem); padding: 4vh 4vw; }
body.board-open { overflow: hidden; }

@media (max-width: 520px) {
  .board-slate { padding: 14px 14px 16px; font-size: .96rem; }
  .bd-line { padding-inline-start: 1.2em; }
  .board-page { font-size: .72rem; }
}
@media (prefers-reduced-motion: reduce) {
  .board .bd-in { animation: none; }
}

/* ---------- take it to the right subject ---------- */

.go-acts {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-block-start: var(--s3);
}
.sources + .go-acts { padding-block-start: var(--s3); border-block-start: 1px solid var(--hair); }
.go-note { flex-basis: 100%; font-size: .86rem; color: var(--text-2); }
.go-act {
  all: unset; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 16px; border-radius: 999px;
  background: var(--hl); color: var(--hl-ink);
  font-size: .92rem; font-weight: 700;
  transition: transform .2s var(--ease), filter .2s;
}
.go-act:hover { transform: translateY(-1px); filter: brightness(1.05); }
.go-act:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* ---------- the chat explains, the board shows ---------- */

/* each explained step leads to its lines on the board */
.bubble li { position: relative; }
.step-go {
  all: unset; cursor: pointer;
  display: inline-grid; place-items: center; vertical-align: middle;
  inline-size: 26px; block-size: 22px; margin-inline-start: 6px;
  border-radius: 6px;
  background: linear-gradient(160deg, #24432f, #1b3326);
  color: #ffe27a;
  box-shadow: inset 0 0 0 1.5px #6b4423;
  transition: transform .15s var(--ease), filter .15s;
}
.step-go .ico { inline-size: 14px; block-size: 14px; }
.step-go:hover { transform: translateY(-1px); filter: brightness(1.15); }
.step-go:focus-visible { outline: 2px solid var(--hl); outline-offset: 2px; }
.bubble > .board-chip:first-child { margin-block: 0 var(--s3); }

/* the step being talked about, chalked over in yellow */
.board-slate .is-focus { animation: step-focus 2.2s ease-out; border-radius: 6px; }
@keyframes step-focus {
  0%, 35% { background: rgba(255, 226, 122, .2); box-shadow: 0 0 0 6px rgba(255, 226, 122, .2); }
  100% { background: transparent; box-shadow: 0 0 0 6px transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .board-slate .is-focus { animation: none; background: rgba(255, 226, 122, .2); }
}

/* ---------- the board, redrawn (v2) ----------
   Laid out the way a teacher uses a real board: the subject and the day in
   the corner, the problem across the top, what is given, asked and used in a
   column of its own, and the steps down the middle, each numbered, joined by
   a chalk line, with its units checked underneath. The numbers the problem
   gives are chalked in pink wherever they come back, so the eye can follow
   each one into the working. */

.board {
  /* the frame: oak, grain and all */
  background:
    repeating-linear-gradient(92deg, rgba(0, 0, 0, .07) 0 2px, transparent 2px 9px),
    linear-gradient(160deg, #96633a, #6a4223 55%, #835331);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .22),
    inset 0 -2px 0 rgba(0, 0, 0, .25),
    0 22px 44px -28px rgba(0, 0, 0, .75);
}

.board-slate {
  container-type: inline-size;
  display: block;
  padding: 16px 22px 22px;
  background:
    /* chalk dust: fine grain over the whole slate */
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .06 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    /* where yesterday's lesson was rubbed out */
    radial-gradient(60% 18% at 72% 22%, rgba(255, 255, 255, .045), transparent 70%),
    radial-gradient(45% 14% at 25% 70%, rgba(255, 255, 255, .035), transparent 70%),
    radial-gradient(120% 70% at 20% 15%, rgba(255, 255, 255, .05), transparent 60%),
    linear-gradient(175deg, #24432f, var(--slate) 60%, #1a3125);
  background-attachment: local;
}

/* the corner: subject and day, small, the way a teacher starts the board */
.bd-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  margin-block-end: 10px;
  font-size: .78em; color: rgba(244, 241, 230, .62);
}
.bd-subject { font-weight: 600; border-block-end: 1.5px solid rgba(244, 241, 230, .3); padding-block-end: 1px; }
.bd-date:empty, .bd-subject:empty { display: none; }

.bd-top .bd-problem { font-size: 1.04em; margin-block-end: 14px; }

.bd-body { display: grid; gap: 14px 22px; grid-template-columns: minmax(0, 1fr); align-items: start; }
.bd-side { order: -1; display: grid; gap: 8px; padding: 10px 12px; border: 1.5px dashed rgba(244, 241, 230, .22); border-radius: 10px; background: rgba(255, 255, 255, .025); }
.bd-side[hidden] { display: none; }
.bd-side .bd-row { flex-direction: column; align-items: flex-start; gap: 2px; }
.bd-side .bd-list { flex-direction: column; gap: 2px; }
@container (min-width: 560px) {
  .bd-body { grid-template-columns: minmax(0, 1fr) minmax(190px, 34%); }
  .bd-body:has(> .bd-side[hidden]) { grid-template-columns: minmax(0, 1fr); }
  .bd-side { order: 0; position: sticky; top: 0; }
}

.bd-main { display: grid; gap: 4px; min-width: 0; }

/* each step: its number in a chalk circle, joined to the next by a line */
.bd-block { position: relative; padding-inline-start: 2.5em; padding-block-end: 12px; display: grid; gap: 3px; }
.bd-block::before {
  content: ""; position: absolute;
  inset-inline-start: .78em; top: 1.75em; bottom: 0;
  border-inline-start: 1.5px dashed rgba(244, 241, 230, .2);
}
/* the circle sits inside the step's own line (pulled into the margin), so the
   chalk-writing animation, which clips to that line, still draws it */
.bd-block .bd-step { margin-block-start: 0; margin-inline-start: -2.5em; gap: .7em; }
.bd-block .bd-n { inline-size: 1.75em; block-size: 1.75em; font-size: .86em; background: #1f3a2c; position: relative; z-index: 1; }
.bd-block .bd-line { padding-inline-start: 0; }

/* the numbers the problem gave, followed into the working */
.board .bd-v { color: var(--chalk-p); font-weight: 600; }

/* units, cancelled down: the line that saves the marks */
.bd-units {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px;
  margin-block: 1px 2px; padding-inline-start: 10px;
  border-inline-start: 2px solid rgba(169, 216, 255, .4);
  color: var(--chalk-b); font-size: .84em;
}
.bd-ulabel { font-weight: 600; opacity: .85; }
.bd-ulabel::after { content: ":"; }
.bd-tick { color: #a6f0b8; font-weight: 700; }

/* the answer: boxed and underlined twice, like it is in every exercise book */
.bd-main .bd-answer { justify-self: start; position: relative; margin-block-start: 6px; }
.bd-main .bd-answer::after {
  content: ""; position: absolute; inset-inline: 10px; bottom: -9px; height: 5px;
  border-block: 1.5px solid rgba(255, 226, 122, .55);
}

/* step by step: the rest of the board stays covered until asked for */
.board .is-hidden { display: none !important; }
.board-pager {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 8px 0 0; color: #f4f1e6; font-size: .86rem; font-weight: 600;
}
.board-pager[hidden] { display: none; }
.board-pager .board-btn { color: #f4f1e6; background: rgba(0, 0, 0, .22); }
.board-pager .board-btn:hover { background: rgba(0, 0, 0, .35); }
.board-pager .board-next { background: #ffe27a; color: #1d1500; }
.board-pager .board-btn:disabled { opacity: .35; cursor: default; }
.board-pos { min-inline-size: 9em; text-align: center; font-variant-numeric: tabular-nums; }

.board-btn--text { inline-size: auto; padding-inline: 10px; display: inline-flex; gap: 6px; font-size: .82rem; font-weight: 600; }
.board-btn--text[aria-pressed="true"] { background: var(--hl); color: var(--hl-ink); }

@media (max-width: 520px) {
  .board-slate { padding: 12px 14px 16px; }
  .bd-block { padding-inline-start: 2.2em; }
  .bd-block .bd-step { margin-inline-start: -2.2em; }
  .board-btn--text span { display: none; }
}

/* in Arabic the next step is to the left */
:root[dir="rtl"] .board-pager .ico { transform: scaleX(-1); }

/* ---------- the board, animated ----------
   Every movement is one a real board makes: the slate is wiped before a new
   solution, each line goes on with the chalk's tip at its leading edge and
   settles from soft to sharp, a step's circle is drawn round its number, the
   line to the next step is drawn down, a number the problem gave glows where
   it is used and in the side column at once, the units' tick lands, and the
   answer is boxed, underlined twice and tapped with the chalk. */

@property --sweep { syntax: "<angle>"; inherits: false; initial-value: 360deg; }

/* items are as wide as their writing, so the chalk stops where the words do */
.board .bd-line, .board .bd-units, .board .bd-step, .board .bd-row, .board .bd-problem {
  inline-size: fit-content; max-inline-size: 100%; position: relative;
}

/* writing: the chalk settles from soft to sharp as it goes on */
.board .bd-in { animation: chalk-rtl .7s cubic-bezier(.3, .7, .2, 1) var(--d, 0s) both; }
:root:not([dir="rtl"]) .board .bd-in { animation-name: chalk-ltr; }
@keyframes chalk-rtl {
  0% { clip-path: inset(0 0 0 100%); filter: blur(1.4px); opacity: .5; }
  70% { filter: blur(0); opacity: 1; }
  100% { clip-path: inset(0 0 0 0); filter: none; opacity: 1; }
}
@keyframes chalk-ltr {
  0% { clip-path: inset(0 100% 0 0); filter: blur(1.4px); opacity: .5; }
  70% { filter: blur(0); opacity: 1; }
  100% { clip-path: inset(0 0 0 0); filter: none; opacity: 1; }
}

/* the chalk's tip, riding the edge of what is being written */
.board .bd-in::after {
  content: ""; position: absolute; z-index: 2; pointer-events: none;
  top: 50%; inset-inline-start: 0;
  inline-size: 7px; block-size: 7px; margin-block-start: -3.5px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0 30%, rgba(255, 255, 255, .55) 55%, transparent 72%);
  box-shadow: 0 0 10px 3px rgba(255, 255, 255, .28), 0 0 22px 6px rgba(255, 226, 122, .12);
  opacity: 0;
  animation: chalk-tip .7s cubic-bezier(.3, .7, .2, 1) var(--d, 0s) both;
}
@keyframes chalk-tip {
  0% { inset-inline-start: -6px; opacity: 1; }
  88% { opacity: 1; }
  100% { inset-inline-start: calc(100% - 8px); opacity: 0; }
}

/* the eraser: a fresh board before a solution is written */
.board-slate::before {
  content: ""; position: absolute; z-index: 3; pointer-events: none;
  inset-block: 0; inset-inline-start: -40%; inline-size: 40%;
  background: linear-gradient(90deg, transparent, rgba(236, 232, 214, .16) 30%, rgba(236, 232, 214, .26) 50%, rgba(236, 232, 214, .16) 70%, transparent);
  filter: blur(6px);
  opacity: 0;
}
.board-slate.is-wiping::before { animation: wipe .75s cubic-bezier(.6, 0, .3, 1) both; }
@keyframes wipe {
  0% { inset-inline-start: -40%; opacity: 1; }
  100% { inset-inline-start: 100%; opacity: .6; }
}

/* the yellow chalk is in the teacher's hand while the board is written */
.board-tray .chalk--y { transition: transform .45s cubic-bezier(.3, .7, .2, 1), opacity .3s; }
.board.is-writing .board-tray .chalk--y { transform: translateY(-16px) rotate(-38deg); opacity: 0; }

/* a step's circle drawn round its number */
.board .bd-step.bd-in .bd-n {
  -webkit-mask: conic-gradient(#000 var(--sweep), transparent 0);
  mask: conic-gradient(#000 var(--sweep), transparent 0);
  animation: circle-draw .55s cubic-bezier(.4, 0, .2, 1) calc(var(--d, 0s) + .05s) both;
}
@keyframes circle-draw { from { --sweep: 0deg; } to { --sweep: 360deg; } }

/* and the line down to the next step */
.board .bd-block:has(> .bd-step.bd-in)::before {
  transform-origin: top;
  animation: line-down .8s ease-out calc(var(--d-line, .5s)) both;
}
@keyframes line-down { from { transform: scaleY(0); } to { transform: scaleY(1); } }

/* a given number glowing where it is used, and in the side column at once */
.board .bd-v { display: inline-block; }
.board .bd-v.ping { animation: v-ping 1.2s ease-out var(--pd, 0s) both; }
@keyframes v-ping {
  0% { transform: none; text-shadow: none; }
  25% { transform: scale(1.18); text-shadow: 0 0 10px rgba(255, 184, 203, .95), 0 0 22px rgba(255, 184, 203, .45); }
  100% { transform: none; text-shadow: none; }
}

/* the units are right: the tick lands */
.board .bd-units.bd-in .bd-tick { display: inline-block; animation: tick-in .55s cubic-bezier(.3, 1.6, .5, 1) calc(var(--d, 0s) + .55s) both; }
@keyframes tick-in {
  0% { transform: scale(0) rotate(-25deg); opacity: 0; }
  60% { color: #d6ffe0; text-shadow: 0 0 10px rgba(166, 240, 184, .9); }
  100% { transform: none; opacity: 1; }
}

/* the answer: boxed, underlined twice, tapped with the chalk */
.board .bd-main .bd-answer.bd-in { animation: answer-in .8s cubic-bezier(.3, .7, .2, 1) var(--d, 0s) both; }
@keyframes answer-in {
  0% { clip-path: inset(0 0 0 100%); transform: rotate(-.6deg) scale(.97); filter: blur(1.4px); }
  65% { clip-path: inset(0 0 0 0); transform: rotate(-.6deg) scale(1.035); filter: none; }
  80% { transform: rotate(-.6deg) scale(.995); }
  100% { clip-path: inset(-20px -20px -30px -20px); transform: rotate(-.6deg); }
}
:root:not([dir="rtl"]) .board .bd-main .bd-answer.bd-in { animation-name: answer-in-ltr; }
@keyframes answer-in-ltr {
  0% { clip-path: inset(0 100% 0 0); transform: rotate(-.6deg) scale(.97); filter: blur(1.4px); }
  65% { clip-path: inset(0 0 0 0); transform: rotate(-.6deg) scale(1.035); filter: none; }
  80% { transform: rotate(-.6deg) scale(.995); }
  100% { clip-path: inset(-20px -20px -30px -20px); transform: rotate(-.6deg); }
}
.board .bd-main .bd-answer.bd-in::after {
  /* the double underline, struck across after the box (replaces the tip) */
  inline-size: auto; block-size: 5px; inset-inline: 10px; top: auto; bottom: -9px; margin: 0;
  border-radius: 0; background: none; box-shadow: none;
  border-block: 1.5px solid rgba(255, 226, 122, .55);
  transform-origin: right; opacity: 1;
  animation: underline .45s cubic-bezier(.4, 0, .2, 1) calc(var(--d, 0s) + .7s) both;
}
:root:not([dir="rtl"]) .board .bd-main .bd-answer.bd-in::after { transform-origin: left; }
@keyframes underline { from { transform: scaleX(0); } to { transform: scaleX(1); } }
/* chalk dust where the chalk tapped the box */
.board .bd-main .bd-answer.bd-in::before {
  content: ""; position: absolute; inset: -6px; pointer-events: none; border-radius: 16px;
  background:
    radial-gradient(circle at 12% 20%, rgba(255, 255, 255, .55) 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 88% 30%, rgba(255, 255, 255, .5) 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 70% 90%, rgba(255, 226, 122, .6) 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 30% 85%, rgba(255, 255, 255, .45) 0 1px, transparent 2px),
    radial-gradient(circle at 50% 5%, rgba(255, 255, 255, .4) 0 1px, transparent 2px);
  opacity: 0;
  animation: dust 1s ease-out calc(var(--d, 0s) + .55s) both;
}
@keyframes dust {
  0% { opacity: 0; transform: scale(.85); }
  25% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.25); }
}

/* the step a student tapped from the chat: ringed in chalk */
.board-slate .bd-block.is-focus { animation: none; }
.board-slate .bd-block.is-focus::after {
  content: ""; position: absolute; inset: -6px -8px 2px; pointer-events: none;
  border: 2px dashed rgba(255, 226, 122, .85); border-radius: 14px 18px 12px 20px;
  animation: ring 2.4s ease-out both;
}
@keyframes ring {
  0% { opacity: 0; transform: scale(1.06); }
  15% { opacity: 1; transform: none; }
  75% { opacity: 1; }
  100% { opacity: 0; }
}

/* enlarging: the board comes forward, like walking up to it */
.board-view.is-big .board { animation: board-forward .4s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes board-forward { from { transform: scale(.94); opacity: .5; } }

@media (prefers-reduced-motion: reduce) {
  .board .bd-in, .board .bd-in::after, .board .bd-in::before, .board .bd-in .bd-n, .board .bd-in .bd-tick,
  .board .bd-v.ping, .board-slate.is-wiping::before, .board .bd-block::before,
  .board-view.is-big .board, .board-slate .bd-block.is-focus::after { animation: none !important; }
  .board .bd-in:not(.bd-answer)::after { display: none; }
  .board.is-writing .board-tray .chalk--y { transform: none; opacity: 1; }
}

/* ---------- the board, dramatic ----------
   Turned up: the board swings into place, the chalk writes heavier with sparks and dust settling off each
   line, step numbers are stamped, values flare, and the answer gets its
   moment -- the board dims round it, it slams in, the board shakes, chalk
   dust bursts, and it glows gold. */

.board { position: relative; isolation: isolate; }

/* the board swings into place, and dust puffs off the frame as it lands */
.board.is-arriving { animation: board-arrive .95s cubic-bezier(.2, 1.35, .35, 1) both; transform-origin: 50% 0; }
@keyframes board-arrive {
  0% { transform: translateY(-36px) rotate(-2.2deg) scale(.95); opacity: 0; }
  55% { transform: translateY(5px) rotate(.6deg) scale(1.005); opacity: 1; }
  75% { transform: translateY(-2px) rotate(-.25deg); }
  100% { transform: none; }
}
.board.is-arriving::after {
  content: ""; position: absolute; z-index: 4; inset-inline: 6%; bottom: -14px; height: 40px; pointer-events: none;
  background:
    radial-gradient(40px 16px at 15% 60%, rgba(236, 228, 210, .35), transparent 70%),
    radial-gradient(60px 20px at 45% 50%, rgba(236, 228, 210, .3), transparent 70%),
    radial-gradient(50px 18px at 78% 65%, rgba(236, 228, 210, .32), transparent 70%);
  filter: blur(3px);
  animation: frame-puff .9s ease-out .45s both;
}
@keyframes frame-puff {
  0% { opacity: 0; transform: scale(.6) translateY(4px); }
  35% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.5) translateY(-10px); }
}

/* heavier chalk: settles down onto the board, sparks at the tip */
.board .bd-in { animation-duration: .85s; }
@keyframes chalk-rtl {
  0% { clip-path: inset(0 0 0 100%); filter: blur(2px); opacity: .4; transform: translateY(-3px); }
  70% { filter: blur(0); opacity: 1; transform: translateY(.5px); }
  100% { clip-path: inset(0 0 0 0); filter: none; opacity: 1; transform: none; }
}
@keyframes chalk-ltr {
  0% { clip-path: inset(0 100% 0 0); filter: blur(2px); opacity: .4; transform: translateY(-3px); }
  70% { filter: blur(0); opacity: 1; transform: translateY(.5px); }
  100% { clip-path: inset(0 0 0 0); filter: none; opacity: 1; transform: none; }
}
.board .bd-in::after {
  inline-size: 10px; block-size: 10px; margin-block-start: -5px;
  box-shadow:
    0 0 12px 4px rgba(255, 255, 255, .38),
    0 0 30px 10px rgba(255, 226, 122, .2),
    -8px 6px 0 -3px rgba(255, 255, 255, .7),
    -14px 12px 0 -4px rgba(255, 255, 255, .5),
    -5px 16px 0 -4px rgba(255, 226, 122, .6);
  animation-duration: .85s;
}
/* chalk dust drifting off a line once it is written */
.board .bd-line.bd-in::before, .board .bd-units.bd-in::before {
  content: ""; position: absolute; inset-inline: 0; top: 70%; height: 22px; pointer-events: none;
  background-image:
    radial-gradient(rgba(240, 236, 220, .55) 0 1px, transparent 1.6px),
    radial-gradient(rgba(240, 236, 220, .35) 0 .8px, transparent 1.4px);
  background-size: 17px 13px, 11px 9px;
  background-position: 0 0, 6px 4px;
  opacity: 0;
  animation: chalk-dust 1.6s ease-out calc(var(--d, 0s) + .3s) both;
}
@keyframes chalk-dust {
  0% { opacity: 0; transform: translateY(-6px); }
  25% { opacity: .9; }
  100% { opacity: 0; transform: translateY(16px); }
}

/* step numbers: circle drawn, then the number stamped in */
.board .bd-step.bd-in .bd-n {
  animation:
    circle-draw .6s cubic-bezier(.4, 0, .2, 1) calc(var(--d, 0s) + .05s) both,
    stamp .45s cubic-bezier(.3, 1.8, .5, 1) calc(var(--d, 0s) + .55s) both;
}
@keyframes stamp {
  0% { transform: scale(1.7); box-shadow: 0 0 0 0 rgba(255, 226, 122, .7); }
  60% { box-shadow: 0 0 0 10px rgba(255, 226, 122, 0); }
  100% { transform: none; }
}

/* values flare, with a ripple */
.board .bd-v { position: relative; }
@keyframes v-ping {
  0% { transform: none; text-shadow: none; }
  22% { transform: scale(1.45) translateY(-2px); text-shadow: 0 0 14px rgba(255, 184, 203, 1), 0 0 30px rgba(255, 120, 160, .65); }
  60% { transform: scale(1.08); }
  100% { transform: none; text-shadow: none; }
}
.board .bd-v.ping::after {
  content: ""; position: absolute; inset: -6px -8px; border-radius: 50%; pointer-events: none;
  border: 2px solid rgba(255, 184, 203, .9);
  animation: ripple .9s ease-out var(--pd, 0s) both;
}
@keyframes ripple {
  0% { transform: scale(.4); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: scale(1.9); opacity: 0; }
}

/* the units tick: bigger landing, and a green flash down the line */
@keyframes tick-in {
  0% { transform: scale(0) rotate(-40deg); opacity: 0; }
  55% { transform: scale(1.9) rotate(8deg); color: #e2ffe9; text-shadow: 0 0 16px rgba(166, 240, 184, 1); opacity: 1; }
  100% { transform: none; opacity: 1; }
}
.board .bd-units.bd-in { animation-name: chalk-rtl, units-flash; animation-duration: .85s, 1.2s; animation-delay: var(--d, 0s), calc(var(--d, 0s) + .6s); animation-fill-mode: both; }
:root:not([dir="rtl"]) .board .bd-units.bd-in { animation-name: chalk-ltr, units-flash; }
@keyframes units-flash {
  0%, 100% { border-inline-start-color: rgba(169, 216, 255, .4); }
  30% { border-inline-start-color: #a6f0b8; box-shadow: inset 6px 0 18px -10px rgba(166, 240, 184, .8); }
}

/* the answer's moment: slam, gold glow */
@keyframes answer-in {
  0% { clip-path: inset(-20px -20px -30px -20px); transform: rotate(-.6deg) scale(1.9); opacity: 0; filter: blur(6px); }
  45% { transform: rotate(-.6deg) scale(.94); opacity: 1; filter: none; }
  62% { transform: rotate(-.6deg) scale(1.05); }
  78% { transform: rotate(-.6deg) scale(.99); }
  100% { clip-path: inset(-20px -20px -30px -20px); transform: rotate(-.6deg); opacity: 1; }
}
@keyframes answer-in-ltr {
  0% { clip-path: inset(-20px -20px -30px -20px); transform: rotate(-.6deg) scale(1.9); opacity: 0; filter: blur(6px); }
  45% { transform: rotate(-.6deg) scale(.94); opacity: 1; filter: none; }
  62% { transform: rotate(-.6deg) scale(1.05); }
  78% { transform: rotate(-.6deg) scale(.99); }
  100% { clip-path: inset(-20px -20px -30px -20px); transform: rotate(-.6deg); opacity: 1; }
}
.board .bd-main .bd-answer.bd-in {
  animation: answer-in 1s cubic-bezier(.3, .7, .2, 1) var(--d, 0s) both, answer-glow 2.4s ease-out calc(var(--d, 0s) + .7s) both;
}
:root:not([dir="rtl"]) .board .bd-main .bd-answer.bd-in { animation-name: answer-in-ltr, answer-glow; }
@keyframes answer-glow {
  0% { box-shadow: 0 0 0 0 rgba(255, 226, 122, 0); }
  25% { box-shadow: 0 0 34px 6px rgba(255, 226, 122, .45), inset 0 0 18px rgba(255, 226, 122, .25); }
  100% { box-shadow: 0 0 14px 0 rgba(255, 226, 122, .12); }
}

/* the spotlight on the answer */
.board-spot {
  position: absolute; z-index: 3; pointer-events: none;
  inset: 10px 10px 26px; border-radius: 6px;
  background: radial-gradient(circle at var(--sx, 50%) var(--sy, 50%), transparent 0 var(--sr, 90px), rgba(0, 0, 0, .62) calc(var(--sr, 90px) + 90px));
  opacity: 0;
}
.board-spot.on { animation: spot 2.6s ease-in-out both; }
@keyframes spot { 0% { opacity: 0; } 18%, 70% { opacity: 1; } 100% { opacity: 0; } }

/* the board shakes as the answer lands */
.board.is-impact { animation: impact .5s cubic-bezier(.3, .6, .4, 1); }
@keyframes impact {
  0%, 100% { transform: none; }
  15% { transform: translate(-3px, 2px) rotate(-.3deg); }
  30% { transform: translate(3px, -1px) rotate(.25deg); }
  50% { transform: translate(-2px, 1px); }
  70% { transform: translate(1px, 0); }
}

/* chalk dust flung out */
.bd-dust {
  position: absolute; z-index: 6; pointer-events: none;
  inline-size: 5px; block-size: 5px; margin: -2.5px 0 0 -2.5px; border-radius: 50%;
  background: rgba(244, 241, 230, .95);
  box-shadow: 0 0 6px rgba(255, 255, 255, .6);
  animation: fling 1.25s cubic-bezier(.2, .7, .3, 1) both;
}
.bd-dust--y { background: #ffe27a; box-shadow: 0 0 8px rgba(255, 226, 122, .8); }
@keyframes fling {
  0% { transform: translate(0, 0) scale(var(--s, 1)); opacity: 1; }
  70% { opacity: .9; }
  100% { transform: translate(var(--dx, 40px), calc(var(--dy, 0px) + 40px)) scale(calc(var(--s, 1) * .3)); opacity: 0; }
}

/* step by step: the spotlight on the step being shown */
.board.is-presenting .bd-block { transition: opacity .4s, filter .4s; }
.board.is-presenting .bd-block:not(.is-current) { opacity: .35; filter: blur(.4px); }
.board.is-presenting .bd-block.is-current { text-shadow: 0 0 1px rgba(255, 255, 255, .7), 0 0 14px rgba(255, 255, 255, .18); }

@media (prefers-reduced-motion: reduce) {
  .board.is-arriving, .board.is-arriving::after, .board .bd-in::before,
  .board .bd-step.bd-in .bd-n, .board .bd-v.ping::after, .board .bd-units.bd-in, .board .bd-main .bd-answer.bd-in,
  .board-spot.on, .board.is-impact, .bd-dust { animation: none !important; }
  .bd-dust { display: none; }
  .board.is-presenting .bd-block:not(.is-current) { filter: none; }
}

/* the wipe's soft band crosses the board, never makes it scroll sideways */
.board-view .board-slate { overflow-x: hidden; }

/* ---------- the comparison table, the diagram, "change the numbers" ----------
   Chalk like the rest: ruled lines drawn by hand, the book's page on every
   cell, a picture beside the working, and sliders for the givens. */

/* a comparison: the things across the top, the points down the side */
.bd-compare-wrap { overflow-x: auto; margin-block-start: 4px; }
.bd-compare { inline-size: 100%; border-collapse: collapse; font-size: .96em; table-layout: fixed; }
.bd-compare thead th:first-child { inline-size: 22%; }
.bd-compare th, .bd-compare td { padding: 10px 12px; text-align: start; vertical-align: top; border-block-end: 1.5px solid rgba(244, 241, 230, .2); }
.bd-compare thead th { color: var(--chalk-y); font-size: 1.08em; border-block-end-width: 2.5px; border-block-end-color: rgba(255, 226, 122, .55); }
.bd-compare thead th:first-child { color: var(--chalk-p); font-size: .86em; font-weight: 600; }
.bd-compare tbody th { color: var(--chalk-p); font-weight: 600; font-size: .88em; }
.bd-compare td + td, .bd-compare th + td { border-inline-start: 1.5px dashed rgba(244, 241, 230, .14); }
.bd-compare tbody tr:last-child > * { border-block-end: 0; }
.bd-pg { font: 600 .72em/1 var(--sans); color: var(--chalk-b); background: rgba(169, 216, 255, .1); border: 1px solid rgba(169, 216, 255, .35);
  border-radius: 999px; padding: 3px 7px; margin-inline-start: 4px; cursor: pointer; vertical-align: 2px; white-space: nowrap; text-shadow: none; }
.bd-pg:hover { background: rgba(169, 216, 255, .2); }

/* the teacher's drawing */
.bd-fig { display: grid; gap: 4px; }
.bd-ftitle { color: var(--chalk-b); font-size: .84em; font-weight: 600; }
.bd-svg { inline-size: 100%; block-size: auto; max-block-size: 340px; overflow: visible; direction: ltr; }
.bd-svg .bd-ink { fill: none; stroke-width: 2.3; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1; stroke-dashoffset: 1;
  animation: bd-draw .9s cubic-bezier(.45, 0, .2, 1) var(--d, 0s) forwards; filter: drop-shadow(0 0 2px rgba(255, 255, 255, .25)); }
.bd-svg .bd-ink.bd-dash { stroke-dasharray: none; stroke-dashoffset: 0; stroke-dasharray: 5 6; animation: bd-fade .6s ease var(--d, 0s) both; }
.bd-svg .bd-head, .bd-svg .bd-dot { animation: bd-fade .3s ease calc(var(--d, 0s) + .8s) both; }
.bd-svg-t { font: 600 13px/1 var(--sans); unicode-bidi: plaintext; animation: bd-fade .4s ease .9s both; paint-order: stroke; stroke: rgba(20, 40, 28, .85); stroke-width: 3px; }
.bd-svg.is-still .bd-ink, .bd-svg.is-still .bd-head, .bd-svg.is-still .bd-dot, .bd-svg.is-still .bd-svg-t { animation: none; stroke-dashoffset: 0; opacity: 1; }
@keyframes bd-draw { to { stroke-dashoffset: 0; } }
@keyframes bd-fade { from { opacity: 0; } }

/* a process: stages in boxes, an arrow down to each */
.bd-flow { display: grid; gap: 22px; justify-items: center; padding-block: 6px 4px; position: relative; }
.bd-fstep { position: relative; display: flex; align-items: center; gap: 10px; min-inline-size: min(100%, 300px); max-inline-size: 100%;
  padding: 10px 16px; border: 2px solid rgba(244, 241, 230, .8); border-radius: 10px 14px 9px 13px; animation: bd-fade .6s ease var(--d, 0s) both; }
.bd-fstep:not(:last-child)::after { content: ""; position: absolute; inset-inline-start: 50%; top: 100%; inline-size: 2px; block-size: 18px; margin-top: 2px;
  background: var(--chalk); }
.bd-fstep:not(:last-child)::before { content: ""; position: absolute; inset-inline-start: calc(50% - 5px); top: calc(100% + 13px); border: 6px solid transparent;
  border-top-color: var(--chalk); border-bottom: 0; }
.bd-fn { flex: none; display: grid; place-items: center; inline-size: 26px; block-size: 26px; border-radius: 50%; border: 1.5px solid var(--chalk-y); color: var(--chalk-y); font-size: .82em; font-weight: 700; }
.bd-flow.is-cycle::after { content: "↺"; position: absolute; inset-inline-end: 4px; top: 50%; translate: 0 -50%; font-size: 2em; color: var(--chalk-y); }
.bd-figure { display: grid; gap: 10px; }
.bd-figure .bd-ftitle { font-size: 1.05em; color: var(--chalk-y); }
.bd-figure .bd-svg { max-block-size: 480px; }

/* change the numbers */
.bd-calc { display: grid; gap: 8px; padding: 10px 12px; border-radius: 10px; border: 1.5px solid rgba(255, 226, 122, .45); background: rgba(255, 226, 122, .05); }
.bd-calc-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.bd-calc-t { color: var(--chalk-y); font-weight: 700; }
.bd-calc-hint, .bd-calc-note { margin: 0; font-size: .78em; color: rgba(244, 241, 230, .7); text-shadow: none; }
.bd-calc-note { color: var(--chalk-y); }
.bd-calc-reset { font: 600 .74em/1 var(--sans); color: var(--chalk); background: none; border: 1px solid rgba(244, 241, 230, .35); border-radius: 999px; padding: 5px 9px; cursor: pointer; }
.bd-knob { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; }
.bd-kl { color: var(--chalk-p); font-weight: 600; font-size: .9em; }
.bd-knob output { font-family: "Cambria Math", "STIX Two Math", "Times New Roman", serif; min-inline-size: 5.5ch; text-align: end; color: var(--chalk-p); }
.bd-knob input[type=range] { inline-size: 100%; accent-color: #ffe27a; cursor: grab; }
.bd-knob input[type=range]:active { cursor: grabbing; }
.board-slate.is-tuned .bd-answer { border-style: dashed; }

@media (prefers-reduced-motion: reduce) {
  .bd-svg .bd-ink, .bd-svg .bd-head, .bd-svg .bd-dot, .bd-svg-t, .bd-fstep { animation: none; stroke-dashoffset: 0; opacity: 1; }
}

/* the lab: the drawing and the sliders, side by side under the working */
.bd-lab { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px 22px; align-items: start;
  margin-block-start: 14px; padding-block-start: 14px; border-block-start: 1.5px dashed rgba(244, 241, 230, .2); }
.bd-lab:has(> :only-child) { grid-template-columns: minmax(0, 520px); justify-content: center; }
.bd-lab .bd-svg { max-block-size: 360px; }
.bd-calc-ans { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; padding: 8px 10px; border-radius: 8px;
  border: 2px solid var(--chalk-y); color: var(--chalk-y); }
.bd-calc-ans .bd-label { color: inherit; }
.bd-calc-ans .bd-m { font-size: 1.1em; }
