@@ -194,7 +219,7 @@ export function mountLesson(cfg) {
${cfg.answer ? `
-
${esc(pick(UI.codeLive))}
+ ${esc(pick(UI.codeLive))}
${langBar(langs, state.lang, ' mini')}
@@ -253,6 +278,9 @@ export function mountLesson(cfg) {
const scrub = $('[data-scrub]', root);
scrub.max = String(state.steps.length - 1);
scrub.value = String(state.i);
+ // what a screen reader says for the scrubber: "Step 2 of 12: tally"
+ const where = pick(UI.stepOf).replace('{i}', state.i + 1).replace('{n}', state.steps.length);
+ scrub.setAttribute('aria-valuetext', pick(s.tag) ? `${where}: ${pick(s.tag)}` : where);
$('[data-count]', root).textContent = `${state.i + 1} / ${state.steps.length}`;
}
@@ -287,15 +315,21 @@ export function mountLesson(cfg) {
state.i = Math.max(0, Math.min(state.steps.length - 1, i));
render();
}
+ // The narration is a live region, so a screen reader reads each step the
+ // reader moves to. While playing it goes quiet — a step every 700 ms would
+ // queue up faster than it can be read — and speaks again on stop.
+ const narrate = (on) => $('[data-narration]', root)?.setAttribute('aria-live', on ? 'polite' : 'off');
function stop() {
clearInterval(state.timer);
state.timer = null;
const b = $('[data-act="play"]', root);
if (b) b.textContent = pick(UI.play);
+ narrate(true);
}
function play() {
if (state.i >= state.steps.length - 1) state.i = 0;
$('[data-act="play"]', root).textContent = pick(UI.pause);
+ narrate(false);
state.timer = setInterval(() => {
if (state.i >= state.steps.length - 1) return stop();
go(state.i + 1);
@@ -310,8 +344,7 @@ export function mountLesson(cfg) {
function setLangAll(id) {
state.lang = id;
- document.querySelectorAll('[data-lang]').forEach((b) =>
- b.setAttribute('aria-selected', String(b.dataset.lang === id)));
+ selectTabs(document.querySelectorAll('[data-lang]'), (b) => b.dataset.lang === id);
document.querySelectorAll('[data-pane]').forEach((p) => { p.hidden = p.dataset.pane !== id; });
render();
}
@@ -321,9 +354,32 @@ export function mountLesson(cfg) {
state.input = structuredClone(input);
(cfg.controls || []).forEach((c) => {
const el = $(`[data-field="${c.key}"]`, root);
- if (el) { el.value = format(c, state.input[c.key]); el.classList.remove('bad'); }
+ if (el) { el.value = format(c, state.input[c.key]); markBad(el, null); }
});
rebuild();
+ syncStale();
+ }
+
+ /* A field whose text does not parse: marked on the field itself, tied to the
+ * warning for a screen reader, and — while any field is bad — the player
+ * dims to say it still shows the last input that worked. */
+ const badFields = () => [...root.querySelectorAll('[data-field].bad')];
+ function markBad(el, msg) {
+ el.classList.toggle('bad', msg != null);
+ if (msg != null) {
+ el.dataset.err = msg;
+ el.setAttribute('aria-invalid', 'true');
+ el.setAttribute('aria-describedby', 'f-warn');
+ } else {
+ delete el.dataset.err;
+ el.removeAttribute('aria-invalid');
+ el.removeAttribute('aria-describedby');
+ }
+ }
+ function syncStale() {
+ const bad = badFields();
+ $('.player', root)?.classList.toggle('is-stale', bad.length > 0);
+ if (bad.length) showWarn(`${bad[0].dataset.err} — ${pick(UI.stale)}`);
}
function showWarn(msg) {
@@ -339,14 +395,15 @@ export function mountLesson(cfg) {
const spec = cfg.controls.find((c) => c.key === el.dataset.field);
try {
state.input[spec.key] = spec.parse ? spec.parse(el.value) : el.value;
- el.classList.remove('bad');
+ markBad(el, null);
} catch (err) {
- el.classList.add('bad');
- showWarn(err.message);
+ markBad(el, err.message);
+ syncStale();
return;
}
stop();
rebuild();
+ syncStale();
});
});
const scrub = $('[data-scrub]', root);
@@ -358,8 +415,7 @@ export function mountLesson(cfg) {
if (card) {
stop();
state.mode = card.dataset.mode;
- root.querySelectorAll('[data-mode]').forEach((b) =>
- b.setAttribute('aria-selected', String(b.dataset.mode === state.mode)));
+ selectTabs(root.querySelectorAll('[data-mode]'), (b) => b.dataset.mode === state.mode);
rebuild();
return;
}
@@ -372,10 +428,15 @@ export function mountLesson(cfg) {
});
// Arrow keys and space — never while someone is typing, and only while the
- // walkthrough is on screen, so a widget elsewhere keeps its own keys.
+ // walkthrough is on screen, so a widget elsewhere keeps its own keys. A
+ // modified key is the browser's (Alt+← is Back), a tab's arrows move between
+ // tabs, and space on a focused control presses that control, not Play.
+ root.addEventListener('keydown', tabKeys);
document.addEventListener('keydown', (e) => {
+ if (e.altKey || e.ctrlKey || e.metaKey) return;
if (e.target.closest('input,textarea,select,[contenteditable]')) return;
- if (e.target.closest('#q-widget')) return;
+ if (e.target.closest('#q-widget, [role="tab"]')) return;
+ if (e.key === ' ' && e.target.closest('button, a[href], summary, [role="button"]')) return;
const r = root.getBoundingClientRect();
if (r.bottom < 0 || r.top > innerHeight) return;
const name = { ArrowRight: 'next', ArrowLeft: 'prev', ' ': 'play' }[e.key];
@@ -528,7 +589,7 @@ function renderSolutions(cfg, activeLang) {
return `
-
${esc(pick(m.name))}${m.sub ? ` · ${esc(pick(m.sub))}` : ''}${meta.tag ? `${esc(meta.tag)}` : ''}
+
${esc(pick(m.name))}${m.sub ? ` · ${esc(pick(m.sub))}` : ''}${meta.tag ? `${esc(meta.tag)}` : ''}
${badge(l.id, m.id)}
${meta.desc ? `
${pick(meta.desc)}
` : `
${esc(pick(m.cost))}
`}
@@ -538,6 +599,7 @@ function renderSolutions(cfg, activeLang) {
}).join('')}
`).join('')}`;
+ host.onkeydown = tabKeys;
host.onclick = (e) => {
const langBtn = e.target.closest('[data-lang]');
// the live code panel's tab switches every tab and pane on the page
diff --git a/src/styles/base.css b/src/styles/base.css
index 94fc4eb..0486054 100644
--- a/src/styles/base.css
+++ b/src/styles/base.css
@@ -19,10 +19,12 @@ body{
-webkit-font-smoothing:antialiased;
}
.wrap{max-width:1140px;margin:0 auto;padding-inline:20px;padding-block:32px 56px}
-h1,h2,h3{font-family:Archivo,"IBM Plex Sans",sans-serif;font-weight:700;text-wrap:balance;margin:0}
+/* .as-h2 and .as-h3 give a deeper heading the look of a shallower one, so the
+ outline can nest properly without the page changing how it looks. */
+h1,h2,h3,.as-h2,.as-h3{font-family:Archivo,"IBM Plex Sans",sans-serif;font-weight:700;text-wrap:balance;margin:0}
h1{font-size:clamp(28px,4.6vw,42px);letter-spacing:-.022em;line-height:1.05}
-h2{font-size:19px;letter-spacing:-.01em}
-h3{font-size:14px;letter-spacing:-.005em;font-weight:600}
+h2,.as-h2{font-size:19px;letter-spacing:-.01em}
+h3,.as-h3{font-size:14px;letter-spacing:-.005em;font-weight:600}
p{margin:0}
code,.mono{font-family:"IBM Plex Mono",ui-monospace,SFMono-Regular,Menlo,monospace;font-variant-numeric:tabular-nums}
.eyebrow{
diff --git a/src/styles/lesson.css b/src/styles/lesson.css
index 20ee0bb..4af8239 100644
--- a/src/styles/lesson.css
+++ b/src/styles/lesson.css
@@ -26,6 +26,10 @@ input:focus-visible,button:focus-visible,select:focus-visible{outline:2px solid
/* A widget chip that is the current choice (presetChips marks it aria-pressed). */
.chip[aria-pressed="true"]{border-color:var(--accent);color:var(--accent);background:var(--accent-soft);font-weight:600}
.warn{color:var(--down);font-size:12.5px;flex-basis:100%}
+/* A field that does not parse, and the player still showing the last input
+ that did: dimmed, not hidden, so the reader can compare. */
+input.bad{border-color:var(--down);box-shadow:0 0 0 1px var(--down)}
+.player.is-stale [data-strip],.player.is-stale .narration,.player.is-stale .bench{opacity:.5;transition:opacity .15s}
/* ---------- array strip ---------- */
.strip-head{display:flex;flex-wrap:wrap;gap:10px;justify-content:space-between;align-items:baseline;margin-bottom:12px}
@@ -196,7 +200,7 @@ td.mono{font-variant-numeric:tabular-nums}
}
.lang:hover{color:var(--accent)}
.lang[aria-selected="true"]{background:var(--surface);color:var(--ink);font-weight:600;box-shadow:0 1px 2px rgba(0,0,0,.12)}
-.src-head h2{margin-right:auto}
+.src-head h3{margin-right:auto}
.tagpill{
font-family:"IBM Plex Mono",monospace;font-size:10.5px;font-weight:500;color:var(--accent);
background:var(--accent-soft);border-radius:5px;padding:2px 7px;margin-left:8px;
@@ -250,9 +254,13 @@ td.mono{font-variant-numeric:tabular-nums}
background:var(--surface);border:1px solid var(--line);border-radius:999px;padding:5px 13px 5px 8px;
}
.jump a:hover{border-color:var(--accent);color:var(--accent)}
-/* The problem on LeetCode, after the part chips. */
-.jump a.lc{padding-left:13px}
-.jump a.lc b{width:auto;padding:0 6px;border-radius:999px}
+/* The problem on LeetCode, after the part chips: a plain link past a rule,
+ not another pill, so leaving the page does not look like moving down it. */
+.jump a.lc{background:none;border-color:transparent;color:var(--ink-3);padding-inline:6px;text-underline-offset:3px}
+.jump a.lc:hover{border-color:transparent;text-decoration:underline}
+.jump a.lc b{width:auto;height:auto;padding:0;border-radius:0;background:none;color:inherit;font-weight:600}
+.jump a:not(.lc) + a.lc{position:relative;margin-left:9px}
+.jump a:not(.lc) + a.lc::before{content:"";position:absolute;left:-9px;top:50%;height:16px;margin-top:-8px;border-left:1px solid var(--line-2)}
.jump b{
font-family:"IBM Plex Mono",monospace;font-size:11px;color:var(--accent);background:var(--accent-soft);
width:18px;height:18px;border-radius:50%;display:flex;align-items:center;justify-content:center;
@@ -317,6 +325,7 @@ td.mono{font-variant-numeric:tabular-nums}
/* Burmese stacks tall: give it room, and never let the script be squeezed */
:root[data-ui="my"] body{line-height:1.85;font-size:15px}
:root[data-ui="my"] h1,:root[data-ui="my"] h2,:root[data-ui="my"] h3,
+:root[data-ui="my"] .as-h2,:root[data-ui="my"] .as-h3,
:root[data-ui="my"] .atab-name,:root[data-ui="my"] .part h2{
font-family:"Noto Sans Myanmar","Padauk",Archivo,sans-serif;line-height:1.5;letter-spacing:0;
}
@@ -416,6 +425,41 @@ td.mono{font-variant-numeric:tabular-nums}
.player .bench > .panel{border-left:1px solid var(--line);padding:16px 18px}
@media (max-width:900px){.player .bench > .panel{border-left:0;border-top:1px solid var(--line)}}
+/* The transport and narration stay under the masthead while the reader looks
+ down at the stage and the code, and let go at the end of the player. Not on
+ a short window, where they would cover too much of it. */
+@media (min-height:600px){
+ .player-run{position:sticky;top:56px;z-index:5;box-shadow:0 8px 12px -12px rgba(0,0,0,.4)}
+ /* whatever takes keyboard focus below scrolls clear of the bar */
+ .player .bench *{scroll-margin-top:200px}
+}
+/* On a phone only the buttons stick, as one row (two below ~330px): with
+ the narration too it took a third of the screen. The narration stays in
+ the flow above the stage. */
+@media (max-width:560px){
+ .player-run{display:contents}
+ .player .transport{
+ position:sticky;top:56px;z-index:5;gap:6px;
+ padding:8px 14px;background:var(--sunk);border-top:1px solid var(--line);
+ box-shadow:0 8px 12px -12px rgba(0,0,0,.4);
+ }
+ .player .transport .btn{min-height:40px;padding-inline:9px}
+ .player .transport input[type=range]{flex:1 1 36px;min-width:36px}
+ .player .transport .counter{font-size:12px}
+ .player .narration{margin:10px 14px 14px}
+ .player .bench *{scroll-margin-top:130px}
+}
+
+/* The array strip wraps onto more rows rather than scrolling sideways, with
+ room under each row for the pointer labels. */
+[data-strip]{flex-wrap:wrap}
+[data-strip]:has(.ptr){row-gap:26px}
+@media (max-width:560px){
+ [data-strip]{gap:5px}
+ [data-strip] > .cell,[data-strip] > .has-ptr > .cell{width:36px;height:44px;font-size:15px}
+ [data-strip] > .cell.wide,[data-strip] > .has-ptr > .cell.wide{width:auto;min-width:40px;padding-inline:6px}
+}
+
/* 2·3 — going deeper: the price, then the questions */
.deeper{display:flex;flex-direction:column;gap:22px}
.deeper-block{display:flex;flex-direction:column;gap:6px}
@@ -426,3 +470,11 @@ td.mono{font-variant-numeric:tabular-nums}
.report h3{margin:0 0 6px;font-size:16px}
.report p{margin:0 0 12px;color:var(--ink-2);font-size:14px;line-height:1.55}
.report-links{display:flex;flex-wrap:wrap;gap:8px}
+
+/* ---------- touch ---------- */
+/* On a touch screen the small controls grow to 40px tall — taller, not wider,
+ so rows keep their line breaks. */
+@media (pointer:coarse),(max-width:560px){
+ .chip,.lang,.lang-bar.mini .lang,.lang-opt,.copy,.btn.ex-load{min-height:40px}
+ .jump a{min-height:40px}
+}
diff --git a/src/styles/site.css b/src/styles/site.css
index 3310116..823174c 100644
--- a/src/styles/site.css
+++ b/src/styles/site.css
@@ -159,3 +159,10 @@ a.ptitle::after{content:"";position:absolute;inset:0;border-radius:inherit}
.site-foot a:hover{color:var(--accent)}
.site-foot .foot-link{color:var(--accent);text-decoration:underline;text-underline-offset:2px}
.site-foot .sep{margin-inline-start:auto}
+
+/* On a touch screen the masthead's links and theme button grow to 40px, still
+ inside its 56px bar. */
+@media (pointer:coarse),(max-width:560px){
+ .masthead nav a{display:inline-flex;align-items:center;min-height:40px}
+ .theme-btn{width:40px;height:40px}
+}
diff --git a/src/styles/tokens.css b/src/styles/tokens.css
index db9f7cd..b3170ab 100644
--- a/src/styles/tokens.css
+++ b/src/styles/tokens.css
@@ -1,8 +1,11 @@
/* Palette and shape, in all three theme states: system, forced light,
forced dark. Every other stylesheet reads colour only through these.
Text colours clear WCAG AA (4.5:1) on every background they sit on —
- ground, surface, sunk and the soft tints; npm run audit checks it. */
+ ground, surface, sunk and the soft tints; npm run audit checks it.
+ color-scheme follows the theme so native parts — scrollbars, range
+ tracks, number spinners — are drawn dark on the dark theme too. */
:root{
+ color-scheme:light;
--ground:#EEF2F2;
--surface:#FFFFFF;
--sunk:#E3E9EA;
@@ -24,6 +27,7 @@
}
@media (prefers-color-scheme: dark){
:root:not([data-theme="light"]){
+ color-scheme:dark;
--ground:#0C1315;
--surface:#141E21;
--sunk:#0F1A1D;
@@ -44,6 +48,7 @@
}
}
:root[data-theme="dark"]{
+ color-scheme:dark;
--ground:#0C1315;
--surface:#141E21;
--sunk:#0F1A1D;