/* See how it's done: the How block's steps at rest and its stage (site/js/how.js).
   One accent. Surfaces part by tone, and the lesson column stays one surface deep: at rest a step is a row with a
   numeral and a hairline, never a filled or shadowed card. Sizes from the short scale (15, 18 px). Lesson words keep
   the lesson's own family (inherited), so a change of the reading face reaches them; keys, tags and counts take the
   controls' token. */
section.blk.b-how {
  --how-ink: #151916;        /* on the plate 17.6:1, on the wash 15:1, on the page 16.6:1 */
  --how-second: #3d4540;     /* the second tone: on the plate 9.9:1, on the wash 8.5:1, on the page 9.3:1 */
  --how-accent: #195c40;     /* on the plate 7.9:1; white on it 7.9:1 */
  --how-on-accent: #ffffff;
  --how-wash: #e3f1e8;
  --how-plate: #ffffff;
  --how-edge: #5c665f;       /* a key's edge and a hollow dot: 5.9:1 on the plate, 5.6:1 on the page */
  --how-hair: #d6dad2;
}
[data-theme="dark"] section.blk.b-how {
  --how-ink: #f3f6f1;        /* on the plate 15.8:1, on the wash 13.4:1 */
  --how-second: #c9d2cb;     /* on the plate 11.2:1, on the wash 9.5:1 */
  --how-accent: #bddbc5;     /* on the plate 11.6:1; the dark ink on it 11:1 */
  --how-on-accent: #10231a;
  --how-wash: #202b24;
  --how-plate: #161b22;
  --how-edge: #8b968e;       /* 5.6:1 on the plate, 6.2:1 on the page */
  --how-hair: #2b3440;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) section.blk.b-how {
    --how-ink: #f3f6f1; --how-second: #c9d2cb; --how-accent: #bddbc5; --how-on-accent: #10231a;
    --how-wash: #202b24; --how-plate: #161b22; --how-edge: #8b968e; --how-hair: #2b3440;
  }
}

/* The steps at rest: a numeral tile, the line, the rest of the step under it in the second tone. With no script the
   list keeps its numerals and its rows. */
section.blk.b-how > ol { list-style: none; counter-reset: how; display: grid; margin: 14px 0 0; padding: 0; max-width: 68ch; }
section.blk.b-how > ol > li {
  counter-increment: how; position: relative; margin: 0; padding: 14px 12px 14px 60px; min-height: 64px; box-sizing: border-box;
  border-top: 1px solid var(--how-hair); border-inline-start: 4px solid transparent; border-radius: 0; background: none; box-shadow: none; outline: 0;
  color: var(--how-ink); font-size: calc(18px * var(--text-scale, 1)); line-height: 1.55; font-weight: 400;
}
section.blk.b-how.how-ready > ol > li[data-how-n]::before { content: attr(data-how-n); }
section.blk.b-how > ol > li::before {
  content: counter(how); position: absolute; left: 10px; top: 14px; width: 36px; height: 36px; border-radius: 8px;
  background: var(--how-wash); color: var(--how-ink); font: 600 18px/36px var(--ui); text-align: center;
}
section.blk.b-how .how-line { display: block; }
section.blk.b-how .how-verb { font-weight: 600; }
section.blk.b-how .how-more { display: block; margin-top: 4px; color: var(--how-second); }
/* The line Listen reads, and the line the demonstration teaches: a bar at its edge, a filled numeral and the wash. */
section.blk.b-how > ol > li.now-step, section.blk.b-how > ol > li.how-now {
  background: var(--how-wash); border-inline-start-color: var(--how-accent); border-radius: 0 8px 8px 0; outline: 0;
}
section.blk.b-how > ol > li.now-step::before, section.blk.b-how > ol > li.how-now::before { background: var(--how-accent); color: var(--how-on-accent); }
section.blk.b-how > ol > li.how-done::before { background: none; border: 2px solid var(--how-accent); box-sizing: border-box; line-height: 32px; }

/* Keys. */
.how-start, .how-controls button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; box-sizing: border-box; min-height: 44px; min-width: 44px;
  border-radius: 8px; font: 600 15px/1.2 var(--ui); cursor: pointer; box-shadow: none; white-space: nowrap; -webkit-tap-highlight-color: transparent;
}
/* The key that opens the stage: the block's one filled key. */
.how-start { margin: 10px 0 2px; padding: 12px 18px 12px 14px; min-height: 48px; border: 0; background: var(--how-accent); color: var(--how-on-accent); font-size: 18px; }
.how-start[hidden] { display: none; }
.how-start svg, .how-controls svg { flex: none; display: block; }
.how-start:focus-visible, .how-controls button:focus-visible, .how-dots:focus-visible { outline: 2px solid var(--how-ink); outline-offset: 3px; }
section.blk.b-how:not(.how-open) > .how-controls, section.blk.b-how:not(.how-open) > .how-dots,
section.blk.b-how:not(.how-open) > .how-status, section.blk.b-how:not(.how-open) > .how-board { display: none; }

/* The stage. Each row of the grid takes its content's height: a row that scrolls sideways must not fold to nothing
   when the stage fills a screen of fixed height. */
section.blk.b-how.how-open { display: grid; grid-template-columns: minmax(0, 1fr); grid-auto-rows: max-content; row-gap: 12px; scroll-margin-top: 76px; }
section.blk.b-how.how-open > * { min-width: 0; margin-block: 0; }
section.blk.b-how.how-open > ol { display: grid !important; max-width: none; }
.how-controls { display: flex; flex-wrap: nowrap; align-items: center; gap: 8px; min-height: 50px; box-sizing: border-box; padding: 3px; margin-inline: -3px; overflow-x: auto; scrollbar-width: none; color: var(--how-ink); }
.how-controls::-webkit-scrollbar { display: none; }
.how-controls button { flex: 0 0 auto; padding: 8px 10px; border: 1.5px solid var(--how-edge); background: var(--how-plate); color: var(--how-ink); }
.how-controls .how-play { border-color: var(--how-accent); background: var(--how-accent); color: var(--how-on-accent); padding-inline: 12px 16px; }
.how-controls button[aria-disabled="true"] { border-style: dashed; cursor: default; }
.how-controls .how-close { margin-inline-start: auto; }
.how-controls .how-speed { min-width: 58px; font-variant-numeric: tabular-nums; }
/* Replay, Full screen and Close are glyph keys with names; their words show where the stage fills a screen. */
.how-controls .how-wide { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.how-dots { display: flex; align-items: center; gap: 4px; height: 44px; margin-block: -8px !important; cursor: pointer; border-radius: 6px; touch-action: manipulation; }
.how-dot { flex: 1 1 0; min-width: 4px; height: 8px; box-sizing: border-box; border: 1.5px solid var(--how-edge); border-radius: 4px; background: transparent; }
.how-dot-on { border-color: var(--how-accent); background: var(--how-accent); }
.how-dot-now { height: 14px; border-radius: 5px; }
.how-dot-part { margin-inline-start: 10px; }
/* The status line is for a screen reader: the dots, the marked line and the board's tag say the same to the eye. It
   shows when it has something more to say (no sound, a blocked start). */
.how-status { position: absolute; width: 1px; height: 1px; margin: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; font: 600 15px/1.4 var(--ui); color: var(--how-second); }
.how-status.how-noted { position: static; width: auto; height: auto; overflow: visible; clip-path: none; white-space: normal; }

/* The board: a plate. The figure, the rows the steps write, and the words being said. */
.how-board {
  display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: 12px; padding: 16px; border: 1px solid var(--how-hair); border-radius: 12px;
  background: var(--how-plate); color: var(--how-ink);
}
.how-board > audio { display: none; }
.how-tag { margin: 0; font: 600 15px/1.4 var(--ui); color: var(--how-accent); }
.how-figure {
  min-width: 0; max-height: 44vh; overflow: auto; --solve-accent: var(--how-accent); --curve: var(--how-accent); --mid: var(--how-accent); --gold: var(--how-accent);
  color: var(--how-ink);
}
section.blk.b-how:not(.how-shows-problem) .how-figure, .how-figure:empty { display: none; }
section.blk.b-how .how-figure figure.fig { margin: 0 !important; padding: 0 !important; min-height: 0 !important; background: none !important; box-shadow: none !important; border: 0 !important; }
.how-figure figcaption, .how-figure .fig-play { display: none; }
/* The picture fills the board's width. Its labels keep the picture's own proportions and the floor (how.js, fitLabels). */
section.blk.b-how .how-figure svg, section.blk.b-how .how-figure figure.fig svg.plot { display: block; width: 100% !important; max-width: none !important; height: auto !important; max-height: 40vh !important; margin: 0 !important; color: inherit; }
.how-figure svg text { fill: currentColor; opacity: 1; }
section.blk.b-how .how-figure svg text.tk { fill: var(--how-second) !important; opacity: 1 !important; }
/* A label sits on a rim of the board's colour, so a curve or a grid line behind it never crosses it out. */
section.blk.b-how .how-figure svg text { paint-order: stroke fill; stroke: var(--how-plate); stroke-width: 3px; stroke-linejoin: round; }
/* A label the picture writes twice at one place shows once. */
section.blk.b-how .how-figure [data-how-twin] { display: none !important; }
section.blk.b-how .how-figure svg text.tk[data-how-under] { visibility: hidden !important; }
.how-figure svg .ax { stroke: currentColor; }
.how-figure svg .grid { stroke: currentColor; stroke-opacity: .25; }
.how-figure .solve-added { display: inline; }
.how-figure [data-drawn="0"] { visibility: hidden !important; }
/* A layout of written rows (a division) grows as its rows are written: an unwritten row keeps no room. */
.how-figure .note-words { display: grid; gap: 0; }
.how-figure .note-words p { margin: 0; padding: 8px 0; border-bottom: 1px solid var(--how-hair); font-size: calc(18px * var(--text-scale, 1)); line-height: 1.5; font-weight: 600; color: var(--how-ink); }
.how-figure .note-words p[data-drawn="0"] { display: none !important; }
.how-figure table { font-size: calc(18px * var(--text-scale, 1)); line-height: 1.5; color: var(--how-ink); }

.how-work { display: grid; max-height: 36vh; overflow: auto; }
/* The answer stands under the figure whole: its box holds the results, the figure every mark. */
section.blk.b-how[data-how-beat="answer"] .how-work { display: none; }
.how-work:not(:has(> .how-row:not([hidden]))) { display: none; }
.how-row { display: grid; grid-template-columns: 28px minmax(0, 1fr); column-gap: 10px; align-items: baseline; padding: 8px 10px 8px 2px; border-inline-start: 4px solid transparent; font-size: calc(18px * var(--text-scale, 1)); line-height: 1.5; color: var(--how-ink); }
.how-row[hidden] { display: none; }
.how-row-n { font: 600 15px/1.5 var(--ui); color: var(--how-second); text-align: center; }
.how-row-line { min-width: 0; overflow-wrap: break-word; }
/* A line already written keeps one line of the board; the line being written stands whole. */
.how-row:not(.how-row-now) .how-row-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.how-row-now { background: var(--how-wash); border-inline-start-color: var(--how-accent); border-radius: 0 8px 8px 0; }
.how-row-now .how-row-n { color: var(--how-ink); }

.how-caption { display: grid; gap: 8px; align-content: start; }
.how-caption:not(:has(> :not(:empty))) { display: none; }
.how-say { font-size: calc(18px * var(--text-scale, 1)); line-height: 1.55; font-weight: 400; color: var(--how-ink); overflow-wrap: break-word; }
.how-say .how-verb { font-weight: 600; }
.how-say .how-more { display: inline; color: inherit; margin: 0; }
.how-say .how-line { display: inline; }
.how-say.how-answer { padding: 12px 14px; border-radius: 8px; background: var(--how-wash); font-weight: 600; }
.how-say.how-answer .lbl { display: block; font: 600 15px/1.4 var(--ui); color: var(--how-second); }
.how-why { font-size: calc(18px * var(--text-scale, 1)); line-height: 1.55; font-weight: 400; color: var(--how-second); }
.how-why:empty, .how-say:empty { display: none; }
.how-w.how-unwritten { visibility: hidden; }
.how-changed { font-weight: 600; text-decoration: underline; text-decoration-color: var(--how-accent); text-decoration-thickness: 3px; text-underline-offset: 5px; }

/* A phone: the stage stacks, and the list shows the line being taught alone, so the figure stays on the screen. */
@media (max-width: 899px) {
  section.blk.b-how.how-open > ol > li:not(.how-now) { display: none; }
  section.blk.b-how.how-open > ol:not(:has(> li.how-now)) { display: none !important; }
  section.blk.b-how.how-open > ol > li.how-now { border-top: 0; }
  /* The line above the board already holds the words being taught. */
  section.blk.b-how[data-how-beat="method"] .how-say { display: none; }
  /* The board shows the newest line and the one before it, under a figure that leaves them room. */
  .how-row:not(.how-row-near) { display: none; }
  .how-figure { max-height: 34vh; }
  section.blk.b-how .how-figure svg, section.blk.b-how .how-figure figure.fig svg.plot { max-height: 30vh !important; }
}
/* One row from 320 px: seven keys of 44 px (the speed 48) fit a 328 px column with 2 px between them; under 360 px
   Replay leaves the row (Play reads Replay at the end, and the first dot starts again). */
@media (max-width: 479px) {
  .how-controls { gap: 4px; }
  .how-controls .how-play span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .how-controls button, .how-controls .how-play { padding-inline: 0; }
  .how-controls .how-speed { min-width: 48px; }
  .how-board { padding: 12px; }
}
@media (max-width: 399px) {
  .how-controls { gap: 2px; }
}
@media (max-width: 359px) {
  .how-controls .how-replay { display: none; }
}
@media (min-width: 900px) {
  section.blk.b-how.how-open { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); column-gap: 24px; align-items: start; }
  section.blk.b-how.how-open > * { grid-column: 1 / -1; }
  section.blk.b-how.how-open > ol { grid-column: 1; }
  /* Beside the board the method keeps its own scroll under the keys (the script measures the room, --how-list-max). */
  section.blk.b-how.how-open:not(.how-is-full) > ol { max-height: var(--how-list-max, none); overflow-y: auto; overscroll-behavior: contain; }
  section.blk.b-how.how-open > .how-board { grid-column: 2; position: sticky; top: calc(var(--how-pin, 64px) + 20px); }
  section.blk.b-how.how-open:not(:has(> ol)) > .how-board { grid-column: 1 / -1; }
  /* The room to the right of the reading column, measured by the script (--how-wide). */
  section.blk.b-how.how-open:not(.how-is-full) { width: var(--how-wide, auto); }
  section.blk.b-how.how-is-full .how-controls .how-wide { position: static; width: auto; height: auto; overflow: visible; clip-path: none; }
  section.blk.b-how.how-is-full .how-controls button { padding-inline: 12px 14px; }
  /* Beside the method the board stands whole on a laptop's screen: the figure, the newest rows and the reason. */
  section.blk.b-how.how-open:not(.how-is-full) .how-figure { max-height: 38vh; }
  section.blk.b-how.how-open:not(.how-is-full) .how-figure svg, section.blk.b-how.how-open:not(.how-is-full) .how-figure figure.fig svg.plot { max-height: 34vh !important; }
  section.blk.b-how.how-open:not(.how-is-full) .how-work { max-height: 27vh; }
  /* At the answer the figure gives the boxed answer room under it. */
  section.blk.b-how.how-open:not(.how-is-full)[data-how-beat="answer"] .how-figure svg,
  section.blk.b-how.how-open:not(.how-is-full)[data-how-beat="answer"] .how-figure figure.fig svg.plot { max-height: 26vh !important; }
}

/* Full screen: the browser's own, or the window filled where a browser gives an element none. */
section.blk.b-how:fullscreen, section.blk.b-how.how-fill {
  box-sizing: border-box; width: 100%; max-width: none; margin: 0; padding: 20px clamp(16px, 4vw, 56px) 32px; overflow: auto;
  background: var(--bg); color: var(--ink); align-content: start;
}
section.blk.b-how.how-fill { position: fixed; inset: 0; z-index: 60; }
section.blk.b-how:fullscreen::backdrop { background: var(--bg); }
section.blk.b-how.how-is-full .how-figure { max-height: 62vh; }
section.blk.b-how.how-is-full .how-figure svg, section.blk.b-how.how-is-full .how-figure figure.fig svg.plot { max-height: 58vh !important; }
section.blk.b-how.how-is-full .how-work { max-height: none; }
section.blk.b-how.how-is-full .how-board { top: 0; }

@media (prefers-reduced-motion: reduce) {
  section.blk.b-how *, section.blk.b-how *::before, section.blk.b-how *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media (forced-colors: active) {
  section.blk.b-how > ol > li.now-step, section.blk.b-how > ol > li.how-now, .how-row-now { outline: 2px solid Highlight; outline-offset: -2px; }
  .how-dot { border-color: CanvasText; }
  .how-dot-on { background: Highlight; border-color: Highlight; }
  .how-changed { text-decoration-color: Highlight; }
  .how-start, .how-controls button { border: 1.5px solid ButtonText; }
}
@media print {
  .how-start, .how-controls, .how-dots, .how-status, .how-board { display: none !important; }
  section.blk.b-how.how-open > ol > li { display: block !important; }
  section.blk.b-how.how-open > ol { max-height: none !important; overflow: visible !important; }
}
