An AI skill that turns books into animated, narrated, interactive web experiences
JavaScript ai-agentsai-educationanimationclaudeclaude-codeclaude-skillsedtecheducationinteractive-textbookscormtext-to-video
refactor(player): make volume a shared control, add it to the physics book
yzr404f37d91a2e
diff --git a/site/elementary-algebra/lib/engine.css b/site/elementary-algebra/lib/engine.cssindex ed244f1..6834986 100644--- a/site/elementary-algebra/lib/engine.css+++ b/site/elementary-algebra/lib/engine.css@@ -1,3 +1,4 @@+@import url(volume.css);:root {--page: #0f1613; --board: #1d2b27; --panel: #22322d; --edge: #3a5047;--chalk: #ece8dc; --dim: #9aaba3; --faint: #5d7068;@@ -106,22 +107,6 @@ button[hidden] { display: none; }.seg.ask { background: #2d4a57; }.seg.ask i { background: var(--quiz); }.step { width: 300px; flex: none; color: var(--dim); font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: right; }-.volume { display: flex; align-items: center; flex: none; width: 44px; height: 44px; overflow: hidden;- border: 1px solid var(--edge); border-radius: 999px; background: var(--panel); color: var(--chalk); transition: width .18s ease; }-.volume .icon { width: 42px; height: 42px; border: 0; background: transparent; }-.volume:hover, .volume:focus-within { width: 166px; gap: 10px; padding-right: 12px; }-.volume:hover { background: #2b3f36; border-color: var(--faint); }-.volume:has(:focus-visible) { outline: 2px solid var(--task); outline-offset: 3px; }-.volume .icon:focus-visible { outline: none; }-.volume input { appearance: none; flex: none; width: 0; height: 42px; margin: 0; opacity: 0; background: transparent; cursor: pointer; }-.volume:hover input, .volume:focus-within input { width: 100px; opacity: 1; }-.volume input:focus-visible { outline: none; }-.volume input::-webkit-slider-runnable-track { height: 4px; border-radius: 999px;- background: linear-gradient(to right, var(--chalk) var(--volume, 100%), var(--faint) var(--volume, 100%)); }-.volume input::-webkit-slider-thumb { appearance: none; width: 12px; height: 12px; margin-top: -4px; border: 0; border-radius: 50%; background: var(--chalk); }-.volume input::-moz-range-track { height: 4px; border-radius: 999px; background: var(--faint); }-.volume input::-moz-range-progress { height: 4px; border-radius: 999px; background: var(--chalk); }-.volume input::-moz-range-thumb { width: 12px; height: 12px; border: 0; border-radius: 50%; background: var(--chalk); }/* Keep the control strip usable without scaling down its touch targets. */@media (max-width: 700px) {#frame { top: calc(50% - 50px); overflow: visible; }@@ -129,10 +114,6 @@ button[hidden] { display: none; }transform: scale(calc(1 / var(--k))); transform-origin: left top; border-radius: 0 0 12px 12px; }#bar .icon { width: 36px; height: 40px; }.step { display: none; }- .volume { width: 36px; height: 40px; }- #bar .volume .icon { width: 34px; height: 38px; }- .volume:hover, .volume:focus-within { width: 158px; }- .volume input { height: 38px; }.segs { order: 1; }.segs { min-width: 80px; margin: 0; }}@@ -224,7 +205,7 @@ svg.m { display: inline-block; overflow: visible; }@keyframes blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.1); } }@keyframes hop { 40% { transform: translateY(-12px) rotate(4deg); } }@keyframes wobble { 25% { transform: rotate(-8deg); } 75% { transform: rotate(6deg); } }-@media (prefers-reduced-motion: reduce) { .volume { transition: none; } .card, .fb, .opt, .grid .mark, .mascot * { animation: none !important; } }+@media (prefers-reduced-motion: reduce) { .card, .fb, .opt, .grid .mark, .mascot * { animation: none !important; } }a.icon { text-decoration: none; }a.btn { text-decoration: none; display: inline-block; }diff --git a/site/elementary-algebra/lib/engine.js b/site/elementary-algebra/lib/engine.jsindex e6ae7e8..de712c3 100644--- a/site/elementary-algebra/lib/engine.js+++ b/site/elementary-algebra/lib/engine.js@@ -72,15 +72,6 @@ document.body.insertAdjacentHTML('afterbegin', `<div id="frame"></button><div class="segs" id="segs"></div><div class="step" id="stepName"></div>- <div class="volume">- <button class="icon" id="bVolume" aria-label="Adjust volume" aria-controls="volume" title="Volume (0 = muted)">- <svg viewBox="0 0 24 24" aria-hidden="true">- <path d="M3 9v6h4l5 4V5L7 9z" fill="currentColor"/>- <path d="M16 8a6 6 0 0 1 0 8m3-11a10 10 0 0 1 0 14" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>- </svg>- </button>- <input id="volume" type="range" min="0" max="1" step="0.05" value="1" aria-label="Volume">- </div><button class="icon txt" id="bHelp" aria-label="Keyboard shortcuts (?)" title="Keyboard shortcuts (?)">?</button><button class="icon cc" id="bCC" aria-pressed="false" aria-label="Captions (C)" title="Captions (C)">CC</button><button class="icon" id="bFull" aria-label="Full screen">@@ -925,6 +916,8 @@ function finishCard() {/* ---------- in-picture cards ---------- */const $ = id => document.getElementById(id);+// The volume control (volume.js, volume.css) lives in its own files next to this one, the same in every book.+document.head.append(Object.assign(document.createElement('script'), { src: new URL('volume.js', document.currentScript.src) }));const kbd = s => h('kbd', '', s);const uiW = (str, size) => { ctx2d.font = `600 ${size}px ${UI}`; return ctx2d.measureText(str).width; };const RING_KEYS = ['nat', 'whole', 'int', 'rat', 'irr', 'real']; // number keys 1–6 in sorting questions@@ -1488,7 +1481,7 @@ function start(i, play) {evalTo(0);const a = P.audio = new Audio(`audio/en/${BEATS[i].id}.mp3`);a.preload = 'auto';- a.volume = +$('volume').value;+ a.volume = +($('volume')?.value ?? 1);a.onerror = () => { if (P.audio === a) soundFailed(); };const b = BEATS[i];if (b.ask) b.ask(() => { if (P.i === i) { evalTo(Infinity); start(i + 1, true); } });@@ -1574,11 +1567,6 @@ $('stage').addEventListener('click', e => {if (!b.ask && !e.target.closest('.qlayer')) togglePlay();});$('bPlay').onclick = togglePlay;-$('bVolume').onclick = () => $('volume').focus();-$('volume').oninput = () => {- $('volume').style.setProperty('--volume', +$('volume').value * 100 + '%');- if (P.audio) P.audio.volume = +$('volume').value;-};$('bBack').onclick = () => { hideCover(); back1(); };$('bRestart').onclick = restart;$('bCC').onclick = () => setCaptions(!captions);diff --git a/site/elementary-algebra/lib/volume.css b/site/elementary-algebra/lib/volume.cssnew file mode 100644index 0000000..195fe1f--- /dev/null+++ b/site/elementary-algebra/lib/volume.css@@ -0,0 +1,24 @@+/* Volume control for the player bar (volume.js); imported by engine.css. */+.volume { display: flex; align-items: center; flex: none; width: 44px; height: 44px; overflow: hidden;+ border: 1px solid var(--edge); border-radius: 999px; background: var(--panel); color: var(--chalk); transition: width .18s ease; }+.volume .icon { width: 42px; height: 42px; border: 0; background: transparent; }+.volume:hover, .volume:focus-within { width: 166px; gap: 10px; padding-right: 12px; }+.volume:hover { background: #2b3f36; border-color: var(--faint); }+.volume:has(:focus-visible) { outline: 2px solid var(--task); outline-offset: 3px; }+.volume .icon:focus-visible { outline: none; }+.volume input { appearance: none; flex: none; width: 0; height: 42px; margin: 0; opacity: 0; background: transparent; cursor: pointer; }+.volume:hover input, .volume:focus-within input { width: 100px; opacity: 1; }+.volume input:focus-visible { outline: none; }+.volume input::-webkit-slider-runnable-track { height: 4px; border-radius: 999px;+ background: linear-gradient(to right, var(--chalk) var(--volume, 100%), var(--faint) var(--volume, 100%)); }+.volume input::-webkit-slider-thumb { appearance: none; width: 12px; height: 12px; margin-top: -4px; border: 0; border-radius: 50%; background: var(--chalk); }+.volume input::-moz-range-track { height: 4px; border-radius: 999px; background: var(--faint); }+.volume input::-moz-range-progress { height: 4px; border-radius: 999px; background: var(--chalk); }+.volume input::-moz-range-thumb { width: 12px; height: 12px; border: 0; border-radius: 50%; background: var(--chalk); }+@media (max-width: 700px) {+ .volume { width: 36px; height: 40px; }+ #bar .volume .icon { width: 34px; height: 38px; }+ .volume:hover, .volume:focus-within { width: 158px; }+ .volume input { height: 38px; }+}+@media (prefers-reduced-motion: reduce) { .volume { transition: none; } }diff --git a/site/elementary-algebra/lib/volume.js b/site/elementary-algebra/lib/volume.jsnew file mode 100644index 0000000..91695ee--- /dev/null+++ b/site/elementary-algebra/lib/volume.js@@ -0,0 +1,20 @@+/* Volume control for the player bar: a speaker button that opens a slider. engine.js loads this file and reads+ #volume when it starts each beat's audio, so the control is the same in every book. */+'use strict';+{+ document.getElementById('bHelp').insertAdjacentHTML('beforebegin', `<div class="volume">+ <button class="icon" id="bVolume" aria-label="Adjust volume" aria-controls="volume" title="Volume (0 = muted)">+ <svg viewBox="0 0 24 24" aria-hidden="true">+ <path d="M3 9v6h4l5 4V5L7 9z" fill="currentColor"/>+ <path d="M16 8a6 6 0 0 1 0 8m3-11a10 10 0 0 1 0 14" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>+ </svg>+ </button>+ <input id="volume" type="range" min="0" max="1" step="0.05" value="1" aria-label="Volume">+ </div>`);+ const input = document.getElementById('volume');+ document.getElementById('bVolume').onclick = () => input.focus();+ input.oninput = () => {+ input.style.setProperty('--volume', +input.value * 100 + '%');+ if (P.audio) P.audio.volume = +input.value;+ };+}diff --git a/site/math-notebook/lib/engine.css b/site/math-notebook/lib/engine.cssindex ed244f1..6834986 100644--- a/site/math-notebook/lib/engine.css+++ b/site/math-notebook/lib/engine.css@@ -1,3 +1,4 @@+@import url(volume.css);:root {--page: #0f1613; --board: #1d2b27; --panel: #22322d; --edge: #3a5047;--chalk: #ece8dc; --dim: #9aaba3; --faint: #5d7068;@@ -106,22 +107,6 @@ button[hidden] { display: none; }.seg.ask { background: #2d4a57; }.seg.ask i { background: var(--quiz); }.step { width: 300px; flex: none; color: var(--dim); font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: right; }-.volume { display: flex; align-items: center; flex: none; width: 44px; height: 44px; overflow: hidden;- border: 1px solid var(--edge); border-radius: 999px; background: var(--panel); color: var(--chalk); transition: width .18s ease; }-.volume .icon { width: 42px; height: 42px; border: 0; background: transparent; }-.volume:hover, .volume:focus-within { width: 166px; gap: 10px; padding-right: 12px; }-.volume:hover { background: #2b3f36; border-color: var(--faint); }-.volume:has(:focus-visible) { outline: 2px solid var(--task); outline-offset: 3px; }-.volume .icon:focus-visible { outline: none; }-.volume input { appearance: none; flex: none; width: 0; height: 42px; margin: 0; opacity: 0; background: transparent; cursor: pointer; }-.volume:hover input, .volume:focus-within input { width: 100px; opacity: 1; }-.volume input:focus-visible { outline: none; }-.volume input::-webkit-slider-runnable-track { height: 4px; border-radius: 999px;- background: linear-gradient(to right, var(--chalk) var(--volume, 100%), var(--faint) var(--volume, 100%)); }-.volume input::-webkit-slider-thumb { appearance: none; width: 12px; height: 12px; margin-top: -4px; border: 0; border-radius: 50%; background: var(--chalk); }-.volume input::-moz-range-track { height: 4px; border-radius: 999px; background: var(--faint); }-.volume input::-moz-range-progress { height: 4px; border-radius: 999px; background: var(--chalk); }-.volume input::-moz-range-thumb { width: 12px; height: 12px; border: 0; border-radius: 50%; background: var(--chalk); }/* Keep the control strip usable without scaling down its touch targets. */@media (max-width: 700px) {#frame { top: calc(50% - 50px); overflow: visible; }@@ -129,10 +114,6 @@ button[hidden] { display: none; }transform: scale(calc(1 / var(--k))); transform-origin: left top; border-radius: 0 0 12px 12px; }#bar .icon { width: 36px; height: 40px; }.step { display: none; }- .volume { width: 36px; height: 40px; }- #bar .volume .icon { width: 34px; height: 38px; }- .volume:hover, .volume:focus-within { width: 158px; }- .volume input { height: 38px; }.segs { order: 1; }.segs { min-width: 80px; margin: 0; }}@@ -224,7 +205,7 @@ svg.m { display: inline-block; overflow: visible; }@keyframes blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.1); } }@keyframes hop { 40% { transform: translateY(-12px) rotate(4deg); } }@keyframes wobble { 25% { transform: rotate(-8deg); } 75% { transform: rotate(6deg); } }-@media (prefers-reduced-motion: reduce) { .volume { transition: none; } .card, .fb, .opt, .grid .mark, .mascot * { animation: none !important; } }+@media (prefers-reduced-motion: reduce) { .card, .fb, .opt, .grid .mark, .mascot * { animation: none !important; } }a.icon { text-decoration: none; }a.btn { text-decoration: none; display: inline-block; }diff --git a/site/math-notebook/lib/engine.js b/site/math-notebook/lib/engine.jsindex 8ecac77..b033470 100644--- a/site/math-notebook/lib/engine.js+++ b/site/math-notebook/lib/engine.js@@ -72,15 +72,6 @@ document.body.insertAdjacentHTML('afterbegin', `<div id="frame"></button><div class="segs" id="segs"></div><div class="step" id="stepName"></div>- <div class="volume">- <button class="icon" id="bVolume" aria-label="Adjust volume" aria-controls="volume" title="Volume (0 = muted)">- <svg viewBox="0 0 24 24" aria-hidden="true">- <path d="M3 9v6h4l5 4V5L7 9z" fill="currentColor"/>- <path d="M16 8a6 6 0 0 1 0 8m3-11a10 10 0 0 1 0 14" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>- </svg>- </button>- <input id="volume" type="range" min="0" max="1" step="0.05" value="1" aria-label="Volume">- </div><button class="icon txt" id="bHelp" aria-label="Keyboard shortcuts (?)" title="Keyboard shortcuts (?)">?</button><button class="icon cc" id="bCC" aria-pressed="false" aria-label="Captions (C)" title="Captions (C)">CC</button><button class="icon" id="bFull" aria-label="Full screen">@@ -930,6 +921,8 @@ function finishCard() {/* ---------- in-picture cards ---------- */const $ = id => document.getElementById(id);+// The volume control (volume.js, volume.css) lives in its own files next to this one, the same in every book.+document.head.append(Object.assign(document.createElement('script'), { src: new URL('volume.js', document.currentScript.src) }));const kbd = s => h('kbd', '', s);const uiW = (str, size) => { ctx2d.font = `600 ${size}px ${UI}`; return ctx2d.measureText(str).width; };const RING_KEYS = ['nat', 'whole', 'int', 'rat', 'irr', 'real']; // number keys 1–6 in sorting questions@@ -1493,7 +1486,7 @@ function start(i, play) {evalTo(0);const a = P.audio = new Audio(`audio/${CHAPTER.language || 'en'}/${BEATS[i].id}.mp3`);a.preload = 'auto';- a.volume = +$('volume').value;+ a.volume = +($('volume')?.value ?? 1);a.onerror = () => { if (P.audio === a) soundFailed(); };const b = BEATS[i];if (b.ask) b.ask(() => { if (P.i === i) { evalTo(Infinity); start(i + 1, true); } });@@ -1579,11 +1572,6 @@ $('stage').addEventListener('click', e => {if (!b.ask && !e.target.closest('.qlayer')) togglePlay();});$('bPlay').onclick = togglePlay;-$('bVolume').onclick = () => $('volume').focus();-$('volume').oninput = () => {- $('volume').style.setProperty('--volume', +$('volume').value * 100 + '%');- if (P.audio) P.audio.volume = +$('volume').value;-};$('bBack').onclick = () => { hideCover(); back1(); };$('bRestart').onclick = restart;$('bCC').onclick = () => setCaptions(!captions);diff --git a/site/math-notebook/lib/volume.css b/site/math-notebook/lib/volume.cssnew file mode 100644index 0000000..195fe1f--- /dev/null+++ b/site/math-notebook/lib/volume.css@@ -0,0 +1,24 @@+/* Volume control for the player bar (volume.js); imported by engine.css. */+.volume { display: flex; align-items: center; flex: none; width: 44px; height: 44px; overflow: hidden;+ border: 1px solid var(--edge); border-radius: 999px; background: var(--panel); color: var(--chalk); transition: width .18s ease; }+.volume .icon { width: 42px; height: 42px; border: 0; background: transparent; }+.volume:hover, .volume:focus-within { width: 166px; gap: 10px; padding-right: 12px; }+.volume:hover { background: #2b3f36; border-color: var(--faint); }+.volume:has(:focus-visible) { outline: 2px solid var(--task); outline-offset: 3px; }+.volume .icon:focus-visible { outline: none; }+.volume input { appearance: none; flex: none; width: 0; height: 42px; margin: 0; opacity: 0; background: transparent; cursor: pointer; }+.volume:hover input, .volume:focus-within input { width: 100px; opacity: 1; }+.volume input:focus-visible { outline: none; }+.volume input::-webkit-slider-runnable-track { height: 4px; border-radius: 999px;+ background: linear-gradient(to right, var(--chalk) var(--volume, 100%), var(--faint) var(--volume, 100%)); }+.volume input::-webkit-slider-thumb { appearance: none; width: 12px; height: 12px; margin-top: -4px; border: 0; border-radius: 50%; background: var(--chalk); }+.volume input::-moz-range-track { height: 4px; border-radius: 999px; background: var(--faint); }+.volume input::-moz-range-progress { height: 4px; border-radius: 999px; background: var(--chalk); }+.volume input::-moz-range-thumb { width: 12px; height: 12px; border: 0; border-radius: 50%; background: var(--chalk); }+@media (max-width: 700px) {+ .volume { width: 36px; height: 40px; }+ #bar .volume .icon { width: 34px; height: 38px; }+ .volume:hover, .volume:focus-within { width: 158px; }+ .volume input { height: 38px; }+}+@media (prefers-reduced-motion: reduce) { .volume { transition: none; } }diff --git a/site/math-notebook/lib/volume.js b/site/math-notebook/lib/volume.jsnew file mode 100644index 0000000..91695ee--- /dev/null+++ b/site/math-notebook/lib/volume.js@@ -0,0 +1,20 @@+/* Volume control for the player bar: a speaker button that opens a slider. engine.js loads this file and reads+ #volume when it starts each beat's audio, so the control is the same in every book. */+'use strict';+{+ document.getElementById('bHelp').insertAdjacentHTML('beforebegin', `<div class="volume">+ <button class="icon" id="bVolume" aria-label="Adjust volume" aria-controls="volume" title="Volume (0 = muted)">+ <svg viewBox="0 0 24 24" aria-hidden="true">+ <path d="M3 9v6h4l5 4V5L7 9z" fill="currentColor"/>+ <path d="M16 8a6 6 0 0 1 0 8m3-11a10 10 0 0 1 0 14" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>+ </svg>+ </button>+ <input id="volume" type="range" min="0" max="1" step="0.05" value="1" aria-label="Volume">+ </div>`);+ const input = document.getElementById('volume');+ document.getElementById('bVolume').onclick = () => input.focus();+ input.oninput = () => {+ input.style.setProperty('--volume', +input.value * 100 + '%');+ if (P.audio) P.audio.volume = +input.value;+ };+}diff --git a/site/science/lib/engine.css b/site/science/lib/engine.cssindex 4fcc2ff..e4e2e97 100644--- a/site/science/lib/engine.css+++ b/site/science/lib/engine.css@@ -1,3 +1,4 @@+@import url(volume.css);:root {--page: #0f1613; --board: #1d2b27; --panel: #22322d; --edge: #3a5047;--chalk: #ece8dc; --dim: #9aaba3; --faint: #5d7068;@@ -109,6 +110,16 @@ button[hidden] { display: none; }.seg.ask { background: #2d4a57; }.seg.ask i { background: var(--quiz); }.step { width: 300px; flex: none; color: var(--dim); font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: right; }+/* Keep the control strip usable without scaling down its touch targets. */+@media (max-width: 700px) {+ #frame { top: calc(50% - 50px); overflow: visible; }+ #bar { width: calc(1600px * var(--k)); height: auto; flex-wrap: wrap; gap: 6px; padding: 8px;+ transform: scale(calc(1 / var(--k))); transform-origin: left top; border-radius: 0 0 12px 12px; }+ #bar .icon { width: 36px; height: 40px; }+ .step { display: none; }+ .segs { order: 1; }+ .segs { min-width: 80px; margin: 0; }+}.sound-note { position: absolute; left: 24px; top: 20px; margin: 0; padding: 8px 18px; border-radius: 12px; background: rgba(15, 22, 19, .85); color: var(--dim); font-size: 19px; }.sound-note[hidden] { display: none; }.blanks .brow { padding: 8px 0; border-bottom: 1px solid #2e433b; }diff --git a/site/science/lib/engine.js b/site/science/lib/engine.jsindex 47fdd22..d2dc10b 100644--- a/site/science/lib/engine.js+++ b/site/science/lib/engine.js@@ -1002,6 +1002,8 @@ function finishCard() {/* ---------- in-picture cards ---------- */const $ = id => document.getElementById(id);+// The volume control (volume.js, volume.css) lives in its own files next to this one, the same in every book.+document.head.append(Object.assign(document.createElement('script'), { src: new URL('volume.js', document.currentScript.src) }));const kbd = s => h('kbd', '', s);const uiW = (str, size) => { ctx2d.font = `600 ${size}px ${UI}`; return ctx2d.measureText(str).width; };const RING_KEYS = ['nat', 'whole', 'int', 'rat', 'irr', 'real']; // number keys 1–6 in sorting questions@@ -1573,6 +1575,7 @@ function start(i, play) {evalTo(0);const a = P.audio = new Audio(`audio/${CHAPTER.language || 'en'}/${BEATS[i].id}.mp3`);a.preload = 'auto';+ a.volume = +($('volume')?.value ?? 1);// An aborted or superseded load (fast stepping, a reload) is not a failure: only a real error for the current clip// shows the note, and the note goes away as soon as a clip plays.a.onerror = () => { if (P.audio === a && a.error && a.error.code !== MediaError.MEDIA_ERR_ABORTED) soundFailed(); };@@ -1678,8 +1681,8 @@ document.addEventListener('keydown', e => {if (e.altKey || e.metaKey || e.ctrlKey) return;const k = e.key;if (!$('help').hidden) { if (k === 'Escape' || k === '?') { e.preventDefault(); toggleHelp(); } return; }- if (e.target.matches?.('input')) { // typing an answer: only Enter (check) and Escape (leave the box) are ours- if (k === 'Enter' && P.keys) { e.preventDefault(); P.keys(e); }+ if (e.target.matches?.('input')) { // Keep native input keys; only answer boxes use Enter to check.+ if (k === 'Enter' && e.target.type !== 'range' && P.keys) { e.preventDefault(); P.keys(e); }else if (k === 'Escape') e.target.blur();return;}@@ -1701,7 +1704,7 @@ document.addEventListener('keydown', e => {// Mouse clicks should not leave focus on a control, so Enter and Space keep meaning "check" and "play".$('frame').addEventListener('mousedown', e => { if (e.target.closest('button, [tabindex]')) e.preventDefault(); });$('bHelp').onclick = toggleHelp;-const fit = () => document.documentElement.style.setProperty('--k', Math.min(innerWidth / 1640, innerHeight / 1000));+const fit = () => document.documentElement.style.setProperty('--k', Math.min(innerWidth / 1640, (innerHeight - (innerWidth <= 700 ? 120 : 0)) / 1000));addEventListener('resize', fit);fit();diff --git a/site/science/lib/volume.css b/site/science/lib/volume.cssnew file mode 100644index 0000000..195fe1f--- /dev/null+++ b/site/science/lib/volume.css@@ -0,0 +1,24 @@+/* Volume control for the player bar (volume.js); imported by engine.css. */+.volume { display: flex; align-items: center; flex: none; width: 44px; height: 44px; overflow: hidden;+ border: 1px solid var(--edge); border-radius: 999px; background: var(--panel); color: var(--chalk); transition: width .18s ease; }+.volume .icon { width: 42px; height: 42px; border: 0; background: transparent; }+.volume:hover, .volume:focus-within { width: 166px; gap: 10px; padding-right: 12px; }+.volume:hover { background: #2b3f36; border-color: var(--faint); }+.volume:has(:focus-visible) { outline: 2px solid var(--task); outline-offset: 3px; }+.volume .icon:focus-visible { outline: none; }+.volume input { appearance: none; flex: none; width: 0; height: 42px; margin: 0; opacity: 0; background: transparent; cursor: pointer; }+.volume:hover input, .volume:focus-within input { width: 100px; opacity: 1; }+.volume input:focus-visible { outline: none; }+.volume input::-webkit-slider-runnable-track { height: 4px; border-radius: 999px;+ background: linear-gradient(to right, var(--chalk) var(--volume, 100%), var(--faint) var(--volume, 100%)); }+.volume input::-webkit-slider-thumb { appearance: none; width: 12px; height: 12px; margin-top: -4px; border: 0; border-radius: 50%; background: var(--chalk); }+.volume input::-moz-range-track { height: 4px; border-radius: 999px; background: var(--faint); }+.volume input::-moz-range-progress { height: 4px; border-radius: 999px; background: var(--chalk); }+.volume input::-moz-range-thumb { width: 12px; height: 12px; border: 0; border-radius: 50%; background: var(--chalk); }+@media (max-width: 700px) {+ .volume { width: 36px; height: 40px; }+ #bar .volume .icon { width: 34px; height: 38px; }+ .volume:hover, .volume:focus-within { width: 158px; }+ .volume input { height: 38px; }+}+@media (prefers-reduced-motion: reduce) { .volume { transition: none; } }diff --git a/site/science/lib/volume.js b/site/science/lib/volume.jsnew file mode 100644index 0000000..91695ee--- /dev/null+++ b/site/science/lib/volume.js@@ -0,0 +1,20 @@+/* Volume control for the player bar: a speaker button that opens a slider. engine.js loads this file and reads+ #volume when it starts each beat's audio, so the control is the same in every book. */+'use strict';+{+ document.getElementById('bHelp').insertAdjacentHTML('beforebegin', `<div class="volume">+ <button class="icon" id="bVolume" aria-label="Adjust volume" aria-controls="volume" title="Volume (0 = muted)">+ <svg viewBox="0 0 24 24" aria-hidden="true">+ <path d="M3 9v6h4l5 4V5L7 9z" fill="currentColor"/>+ <path d="M16 8a6 6 0 0 1 0 8m3-11a10 10 0 0 1 0 14" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>+ </svg>+ </button>+ <input id="volume" type="range" min="0" max="1" step="0.05" value="1" aria-label="Volume">+ </div>`);+ const input = document.getElementById('volume');+ document.getElementById('bVolume').onclick = () => input.focus();+ input.oninput = () => {+ input.style.setProperty('--volume', +input.value * 100 + '%');+ if (P.audio) P.audio.volume = +input.value;+ };+}