Proportional Layout Scaling — Implementation Plan
For agentic workers: REQUIRED: Use superpowers:subagent-driven-development (if subagents available) or superpowers:executing-plans to implement this plan. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: Make the three-column layout scale proportionally with viewport width so it survives further down the viewport range, fixing the footnote gap bug and enabling future font-size tuning.
Architecture: Replace hardcoded pixel breakpoints and rem-based grid minimums with a clamp()-based font scaling system where grid minimums are in em. The layout becomes self-similar at every width. Seven testable invariants verify correctness across a viewport × font-size matrix.
Tech Stack: CSS (custom properties, clamp(), em units), JavaScript (sidenotes.js CONFIG sync), Playwright (browser tests), pytest (TAP output)
Spec: doc/05-process/plans/2026-03-10-proportional-scaling-design.md
File Map
| File | Action | Responsibility |
|---|---|---|
src/tests/test_layout_invariants.py |
Create | Playwright tests for 7 layout invariants across viewport widths |
src/tests/conftest.py |
Modify | Add --min-body-words etc. CLI options, add layout_invariants marker |
pyproject.toml |
Modify | Register layout_invariants marker |
bin/a-test |
Modify | Add layout-invariants suite |
assets/css/almanack.css |
Modify | rem→em conversion, clamp() scaling, breakpoint unification |
assets/js/sidenotes.js |
Modify | Sync CONFIG.minViewportWidth with CSS |
doc/05-process/critiques/2026-03-10-proportional-scaling-results.md |
Create | Findings write-up |
Chunk 1: Invariant Test Harness (Phase 1)
Task 1: Add test infrastructure
Files:
- Modify: pyproject.toml (markers section, ~line 53)
- Modify: src/tests/conftest.py (add CLI options + fixtures)
- Modify: bin/a-test (add suite)
- [ ] Step 1: Register the marker in pyproject.toml
In pyproject.toml, add to the markers list:
"layout_invariants: proportional scaling layout invariant tests",
- [ ] Step 2: Add CLI options and fixtures to conftest.py
Append to src/tests/conftest.py:
# ---------------------------------------------------------------------------
# Layout invariant test configuration
# ---------------------------------------------------------------------------
# Tunable defaults — override via pytest CLI:
# pytest --min-body-words=9 --min-margin-words=5 --margin-ratio=0.75
INVARIANT_DEFAULTS = {
"min_body_words": 8,
"min_margin_words": 5,
"margin_ratio": 0.80,
"avg_chars_per_word": 5.0,
}
# Viewport widths to sweep (px)
INVARIANT_VIEWPORTS = [320, 480, 640, 700, 768, 800, 850, 1000, 1200, 1440]
def pytest_addoption(parser):
group = parser.getgroup("layout-invariants", "Layout invariant thresholds")
group.addoption(
"--min-body-words", type=int,
default=INVARIANT_DEFAULTS["min_body_words"],
help="Minimum words per line in center column (default: 8)",
)
group.addoption(
"--min-margin-words", type=int,
default=INVARIANT_DEFAULTS["min_margin_words"],
help="Minimum words per line in margin columns (default: 5)",
)
group.addoption(
"--margin-ratio", type=float,
default=INVARIANT_DEFAULTS["margin_ratio"],
help="Expected margin/body font-size ratio (default: 0.80)",
)
@pytest.fixture(scope="session")
def invariant_thresholds(request):
"""Tunable readability thresholds for layout invariant tests."""
avg_cpw = INVARIANT_DEFAULTS["avg_chars_per_word"]
min_body_words = request.config.getoption("--min-body-words")
min_margin_words = request.config.getoption("--min-margin-words")
return {
"min_body_words": min_body_words,
"min_margin_words": min_margin_words,
"min_body_chars": int(min_body_words * avg_cpw), # 40
"min_margin_chars": int(min_margin_words * avg_cpw), # 25
"margin_ratio": request.config.getoption("--margin-ratio"),
}
- [ ] Step 3: Add layout-invariants suite to bin/a-test
In bin/a-test, add to the all_suites dict (after the "regression" entry, around line 124):
"layout-invariants": [
"pytest", "src/tests/test_layout_invariants.py",
"--tap-stream", "-q",
],
- [ ] Step 4: Verify infrastructure by running an empty test file
Create a minimal src/tests/test_layout_invariants.py:
"""Placeholder to verify test infrastructure."""
import pytest
pytestmark = pytest.mark.layout_invariants
def test_placeholder():
assert True
Run: cd $ALMANACK_ROOT && pytest src/tests/test_layout_invariants.py -v
Expected: 1 passed.
- [ ] Step 5: Commit
git add pyproject.toml src/tests/conftest.py bin/a-test src/tests/test_layout_invariants.py
git commit -m "$(cat <<'EOF'
Add layout-invariants test harness with tunable thresholds
Infrastructure for proportional scaling research: pytest CLI
options for --min-body-words, --min-margin-words, --margin-ratio;
session fixture for thresholds; new test suite in a-test.
EOF
)"
Task 2: Write invariant tests — no overflow and mode consistency
Files:
- Create/replace: src/tests/test_layout_invariants.py
The test article is Kropotkin’s Funeral (8 footnotes, good margin content).
Frontpage URL: /?fp=1921-02-13
- [ ] Step 1: Write the test file with shared fixtures and invariants 1 + 6
Replace src/tests/test_layout_invariants.py with:
"""Layout invariant tests for proportional scaling.
Tests 7 readability/layout invariants across a sweep of viewport widths.
Run against any CSS — current or modified — to map the bug surface.
Usage:
pytest src/tests/test_layout_invariants.py -v
pytest src/tests/test_layout_invariants.py --min-body-words=9
bin/a-test --suite layout-invariants
"""
import pytest
from conftest import INVARIANT_VIEWPORTS
pytestmark = [pytest.mark.layout_invariants, pytest.mark.browser]
# Kropotkin's Funeral: 8 footnotes, good margin content.
SEED_URL = "/?fp=1921-02-13"
# ---------------------------------------------------------------------------
# Fixtures
# ---------------------------------------------------------------------------
@pytest.fixture(scope="module")
def invariant_browser(playwright_instance):
browser = playwright_instance.chromium.launch()
yield browser
browser.close()
@pytest.fixture(scope="module")
def wide_context(invariant_browser, dev_server_url):
"""A wide context for initial page load — resized per test."""
context = invariant_browser.new_context(
viewport={"width": 1280, "height": 900},
base_url=dev_server_url,
)
yield context
context.close()
def load_at_width(wide_context, width):
"""Create a page, resize to width, load seed article, wait for layout."""
page = wide_context.new_page()
page.set_viewport_size({"width": width, "height": 900})
page.goto(SEED_URL)
# Wait for either sidenotes-ready (JS margin layout) or DOMContentLoaded
try:
page.wait_for_selector(".sidenotes-ready", timeout=8000)
except Exception:
pass # Fallback mode — no sidenotes-ready class expected
# Extra settle time for layout
page.wait_for_timeout(500)
return page
def detect_mode(page):
"""Detect which layout mode the page is in.
Returns one of: 'broadsheet', 'pocket', 'fallback'.
"""
return page.evaluate("""() => {
const ml = document.querySelector('.margin-left');
const mr = document.querySelector('.margin-right');
const layout = document.querySelector('.margins-layout');
// Check if margins are visible (displayed and have width)
const mlVisible = ml && ml.offsetWidth > 0 && getComputedStyle(ml).display !== 'none';
const mrVisible = mr && mr.offsetWidth > 0 && getComputedStyle(mr).display !== 'none';
// Check for swipe mode
const swipeEnabled = document.body.classList.contains('swipe-margins-enabled');
if (swipeEnabled) return 'pocket';
if (mlVisible && mrVisible) return 'broadsheet';
return 'fallback';
}""")
# ---------------------------------------------------------------------------
# Invariant 1: No horizontal overflow
# ---------------------------------------------------------------------------
class TestNoHorizontalOverflow:
"""No element extends beyond the viewport at any width."""
@pytest.mark.parametrize("width", INVARIANT_VIEWPORTS)
def test_no_overflow(self, wide_context, width):
page = load_at_width(wide_context, width)
try:
overflow = page.evaluate("""() => {
return {
scrollWidth: document.body.scrollWidth,
innerWidth: window.innerWidth,
overflow: document.body.scrollWidth > window.innerWidth
};
}""")
assert not overflow["overflow"], (
f"Horizontal overflow at {width}px: "
f"scrollWidth={overflow['scrollWidth']} > innerWidth={overflow['innerWidth']}"
)
finally:
page.close()
# ---------------------------------------------------------------------------
# Invariant 6: Mode consistency
# ---------------------------------------------------------------------------
class TestModeConsistency:
"""Page is in exactly one mode with no mixed state."""
@pytest.mark.parametrize("width", INVARIANT_VIEWPORTS)
def test_consistent_mode(self, wide_context, width):
page = load_at_width(wide_context, width)
try:
mode = detect_mode(page)
state = page.evaluate("""() => {
const margins = document.querySelector('.margins-layout');
const ml = document.querySelector('.margin-left');
const footnotes = document.querySelector('.footnotes');
const sidenotes = document.querySelectorAll('.sidenote');
const mlDisplay = ml ? getComputedStyle(ml).display : 'n/a';
const mlWidth = ml ? ml.offsetWidth : 0;
const fnVisible = footnotes ? (
getComputedStyle(footnotes).position !== 'absolute' &&
getComputedStyle(footnotes).clip === 'auto'
) : false;
const snCount = sidenotes.length;
const snVisible = Array.from(sidenotes).filter(
s => getComputedStyle(s).opacity !== '0'
).length;
return {
mlDisplay, mlWidth, fnVisible, snCount, snVisible,
sidenoteEnabled: document.body.classList.contains('sidenotes-enabled'),
};
}""")
if mode == 'broadsheet':
# Margins visible → footnotes should be hidden (sidenotes active)
if state['sidenoteEnabled'] and state['snVisible'] > 0:
assert not state['fnVisible'], (
f"Mixed state at {width}px: broadsheet mode but footnotes "
f"also visible (margins width={state['mlWidth']})"
)
elif mode == 'fallback':
# Margins hidden → footnotes must be accessible
# (This catches the 768-800px bug)
if state['sidenoteEnabled']:
assert state['fnVisible'] or state['mlWidth'] > 0, (
f"Dead zone at {width}px: fallback mode, sidenotes enabled, "
f"but footnotes not visible and margins hidden "
f"(fnVisible={state['fnVisible']}, mlWidth={state['mlWidth']})"
)
finally:
page.close()
- [ ] Step 2: Run to verify tests execute (some may fail — that’s the point)
Run: cd $ALMANACK_ROOT && pytest src/tests/test_layout_invariants.py -v --tb=short 2>&1 | head -60
Expected: Tests run. Some may fail at specific widths (especially 768px, 800px). Record the results.
- [ ] Step 3: Commit
git add src/tests/test_layout_invariants.py
git commit -m "$(cat <<'EOF'
Add invariant tests: no-overflow and mode-consistency
Sweep 10 viewport widths testing for horizontal overflow and
mixed layout states. Mode consistency test catches the known
768-800px footnote gap bug.
EOF
)"
Task 3: Write invariant tests — footnotes reachable
Files:
- Modify: src/tests/test_layout_invariants.py
- [ ] Step 1: Add invariant 2 test class
Append to src/tests/test_layout_invariants.py:
# ---------------------------------------------------------------------------
# Invariant 2: Footnotes always reachable
# ---------------------------------------------------------------------------
class TestFootnotesReachable:
"""Every footnote ref links to a visible, non-clipped target."""
@pytest.mark.parametrize("width", INVARIANT_VIEWPORTS)
def test_all_footnotes_reachable(self, wide_context, width):
page = load_at_width(wide_context, width)
try:
result = page.evaluate("""() => {
const refs = document.querySelectorAll('a.footnote-ref');
const problems = [];
for (const ref of refs) {
const href = ref.getAttribute('href');
if (!href) {
problems.push({ref: ref.textContent, issue: 'no href'});
continue;
}
// Find target: either a sidenote or a footnote
const targetId = href.replace('#', '');
const fnId = 'fn' + targetId.replace('fnref', '');
const snId = 'sn-' + targetId.replace('fnref', '');
// Look for sidenote first (broadsheet/pocket mode)
const sidenote = document.getElementById(snId) ||
document.querySelector(`[id="${targetId}"]`);
// Look for footnote (fallback mode)
const footnote = document.getElementById(fnId) ||
document.querySelector(`[id="${targetId}"]`);
// Check the footnotes section directly
const footnotesSection = document.querySelector('.footnotes');
const target = href.startsWith('#') ?
document.querySelector(href) : null;
if (!target && !sidenote && !footnote) {
problems.push({ref: ref.textContent, issue: 'target not found'});
continue;
}
const el = target || sidenote || footnote;
const style = getComputedStyle(el);
// Check if visually hidden (sr-only / clip pattern)
const isClipped = (
style.position === 'absolute' &&
style.clip !== 'auto' &&
style.overflow === 'hidden' &&
parseInt(style.width) <= 1
);
// Check if display:none
const isHidden = style.display === 'none';
// Check parent chain for display:none
let parent = el.parentElement;
let parentHidden = false;
while (parent) {
if (getComputedStyle(parent).display === 'none') {
parentHidden = true;
break;
}
parent = parent.parentElement;
}
if (isHidden || parentHidden) {
// Element hidden — check if there's an alternative
// (sidenote visible OR footnote visible)
const anyVisible = document.querySelectorAll(
`.sidenote, [id="${fnId}"], [id="${targetId}"]`
);
const someVisible = Array.from(anyVisible).some(n => {
const s = getComputedStyle(n);
let pH = false;
let p = n.parentElement;
while (p) {
if (getComputedStyle(p).display === 'none') { pH = true; break; }
p = p.parentElement;
}
return s.display !== 'none' && !pH;
});
if (!someVisible) {
problems.push({
ref: ref.textContent,
issue: `target hidden (display=${style.display}, parentHidden=${parentHidden})`
});
}
} else if (isClipped) {
// Clipped — only okay if a sidenote is visible
const visibleSidenote = sidenote && getComputedStyle(sidenote).opacity !== '0';
if (!visibleSidenote) {
problems.push({
ref: ref.textContent,
issue: 'target clipped with no visible sidenote'
});
}
}
}
return {total: refs.length, problems};
}""")
assert len(result["problems"]) == 0, (
f"Unreachable footnotes at {width}px: "
f"{result['problems']}"
)
finally:
page.close()
- [ ] Step 2: Run to verify
Run: cd $ALMANACK_ROOT && pytest src/tests/test_layout_invariants.py::TestFootnotesReachable -v --tb=short 2>&1 | head -40
Expected: Tests run. Likely fails at 768px and 800px (the known bug).
- [ ] Step 3: Commit
git add src/tests/test_layout_invariants.py
git commit -m "$(cat <<'EOF'
Add invariant test: footnotes always reachable
Tests that every footnote-ref links to a visible target at all
viewport widths. Catches the 768-800px dead zone where footnotes
are clipped but margins are hidden.
EOF
)"
Task 4: Write invariant tests — column widths and font hierarchy
Files:
- Modify: src/tests/test_layout_invariants.py
- [ ] Step 1: Add invariants 3, 4, 5, 7
Append to src/tests/test_layout_invariants.py:
# ---------------------------------------------------------------------------
# Invariants 3+4: Column width (words per line)
# ---------------------------------------------------------------------------
class TestColumnWidths:
"""Center and margin columns are wide enough for readable text."""
@pytest.mark.parametrize("width", INVARIANT_VIEWPORTS)
def test_center_column_width(self, wide_context, invariant_thresholds, width):
page = load_at_width(wide_context, width)
try:
mode = detect_mode(page)
if mode != 'broadsheet':
pytest.skip(f"Not in broadsheet mode at {width}px (mode={mode})")
result = page.evaluate("""() => {
const body = document.querySelector('.body-text');
if (!body) return null;
const style = getComputedStyle(body);
return {
widthPx: body.clientWidth,
fontSizePx: parseFloat(style.fontSize),
};
}""")
if result is None:
pytest.skip("No .body-text element found")
# Estimate characters per line: width / (fontSize * avgCharWidth)
# EB Garamond average character width ≈ 0.48em
chars_per_line = result["widthPx"] / (result["fontSizePx"] * 0.48)
min_chars = invariant_thresholds["min_body_chars"]
assert chars_per_line >= min_chars, (
f"Center column too narrow at {width}px: "
f"~{chars_per_line:.0f} chars/line "
f"(need ≥{min_chars}, ~{invariant_thresholds['min_body_words']} words). "
f"Column={result['widthPx']:.0f}px, font={result['fontSizePx']:.1f}px"
)
finally:
page.close()
@pytest.mark.parametrize("width", INVARIANT_VIEWPORTS)
def test_margin_column_width(self, wide_context, invariant_thresholds, width):
page = load_at_width(wide_context, width)
try:
mode = detect_mode(page)
if mode != 'broadsheet':
pytest.skip(f"Not in broadsheet mode at {width}px (mode={mode})")
result = page.evaluate("""() => {
const ml = document.querySelector('.margin-left');
const mr = document.querySelector('.margin-right');
if (!ml || !mr) return null;
const mlStyle = getComputedStyle(ml);
return {
leftWidthPx: ml.clientWidth,
rightWidthPx: mr.clientWidth,
marginFontPx: parseFloat(mlStyle.fontSize),
};
}""")
if result is None:
pytest.skip("No margin elements found")
min_chars = invariant_thresholds["min_margin_chars"]
for side, widthPx in [("left", result["leftWidthPx"]),
("right", result["rightWidthPx"])]:
chars_per_line = widthPx / (result["marginFontPx"] * 0.48)
assert chars_per_line >= min_chars, (
f"Margin-{side} too narrow at {width}px: "
f"~{chars_per_line:.0f} chars/line "
f"(need ≥{min_chars}, ~{invariant_thresholds['min_margin_words']} words). "
f"Column={widthPx:.0f}px, font={result['marginFontPx']:.1f}px"
)
finally:
page.close()
# ---------------------------------------------------------------------------
# Invariant 5: Body font >= accessibility floor
# ---------------------------------------------------------------------------
class TestFontFloor:
"""Body font never drops below a discoverable minimum.
This test doesn't assert a specific floor — it records the computed
font size at each width so the sweep can identify where the floor is.
For now, assert a conservative absolute minimum of 10px (below which
text is essentially unreadable on any display).
"""
ABSOLUTE_MINIMUM_PX = 10.0
@pytest.mark.parametrize("width", INVARIANT_VIEWPORTS)
def test_body_font_above_absolute_minimum(self, wide_context, width):
page = load_at_width(wide_context, width)
try:
font_size = page.evaluate(
"() => parseFloat(getComputedStyle(document.body).fontSize)"
)
assert font_size >= self.ABSOLUTE_MINIMUM_PX, (
f"Body font too small at {width}px: {font_size:.1f}px "
f"(absolute minimum: {self.ABSOLUTE_MINIMUM_PX}px)"
)
finally:
page.close()
# ---------------------------------------------------------------------------
# Invariant 7: Font hierarchy preserved
# ---------------------------------------------------------------------------
class TestFontHierarchy:
"""Margin font maintains the expected ratio to body font."""
RATIO_TOLERANCE = 0.05 # Allow 5% deviation
@pytest.mark.parametrize("width", INVARIANT_VIEWPORTS)
def test_margin_body_ratio(self, wide_context, invariant_thresholds, width):
page = load_at_width(wide_context, width)
try:
mode = detect_mode(page)
if mode != 'broadsheet':
pytest.skip(f"Not in broadsheet mode at {width}px (mode={mode})")
result = page.evaluate("""() => {
const body = document.querySelector('.body-text');
const margin = document.querySelector('.margin-left');
if (!body || !margin) return null;
return {
bodyFontPx: parseFloat(getComputedStyle(body).fontSize),
marginFontPx: parseFloat(getComputedStyle(margin).fontSize),
};
}""")
if result is None:
pytest.skip("No body-text or margin element found")
actual_ratio = result["marginFontPx"] / result["bodyFontPx"]
expected_ratio = invariant_thresholds["margin_ratio"]
assert abs(actual_ratio - expected_ratio) <= self.RATIO_TOLERANCE, (
f"Font ratio off at {width}px: "
f"margin/body = {result['marginFontPx']:.1f}/{result['bodyFontPx']:.1f} "
f"= {actual_ratio:.3f} (expected ~{expected_ratio}, "
f"tolerance ±{self.RATIO_TOLERANCE})"
)
finally:
page.close()
- [ ] Step 2: Run full invariant suite against current CSS
Run: cd $ALMANACK_ROOT && pytest src/tests/test_layout_invariants.py -v --tb=short 2>&1 | tail -30
Expected: Many tests pass at wide viewports. Font hierarchy tests will fail (current ratio is 0.65, not 0.80). Record the full results — this is the Phase 1 baseline.
- [ ] Step 3: Save baseline results
Run: cd $ALMANACK_ROOT && pytest src/tests/test_layout_invariants.py -v --tb=line 2>&1 > doc/05-process/plans/baseline-invariant-results.txt
- [ ] Step 4: Commit
git add src/tests/test_layout_invariants.py doc/05-process/plans/baseline-invariant-results.txt
git commit -m "$(cat <<'EOF'
Add invariant tests: column widths, font floor, font hierarchy
Complete set of 7 layout invariants tested across 10 viewport
widths. Baseline results saved — font hierarchy tests fail as
expected (current ratio 0.65, target 0.80).
EOF
)"
Chunk 2: CSS Conversion (Phase 2)
Task 5: Convert grid minimums from rem to em
Files:
- Modify: assets/css/almanack.css (lines ~536-554)
- [ ] Step 1: Write a snapshot test of current computed widths
This guards against the rem→em conversion changing anything at current sizes.
Append to src/tests/test_layout_invariants.py:
# ---------------------------------------------------------------------------
# Regression: rem→em conversion should be a no-op at current sizes
# ---------------------------------------------------------------------------
class TestRemToEmRegression:
"""Grid column widths should not change during rem→em conversion.
Run at 1280px (Broadsheet) where the layout is fully expanded.
Capture the computed widths before conversion and assert they
remain within 2px after.
"""
def test_column_widths_stable_at_broadsheet(self, wide_context):
page = load_at_width(wide_context, 1280)
try:
widths = page.evaluate("""() => {
const ml = document.querySelector('.margin-left');
const body = document.querySelector('.body-text');
const mr = document.querySelector('.margin-right');
return {
left: ml ? ml.clientWidth : 0,
center: body ? body.clientWidth : 0,
right: mr ? mr.clientWidth : 0,
total: document.querySelector('.margins-layout')?.clientWidth || 0,
};
}""")
# At 1280px these should be roughly:
# margins ~194px each, center ~588px
# Assert they're in a sane range (not zero, not overflowing)
assert widths["left"] > 100, f"Left margin too narrow: {widths['left']}px"
assert widths["center"] > 300, f"Center too narrow: {widths['center']}px"
assert widths["right"] > 100, f"Right margin too narrow: {widths['right']}px"
assert widths["left"] + widths["center"] + widths["right"] < 1280
finally:
page.close()
- [ ] Step 2: Run regression test to capture baseline
Run: cd $ALMANACK_ROOT && pytest src/tests/test_layout_invariants.py::TestRemToEmRegression -v
Expected: PASS. Note the actual widths.
- [ ] Step 3: Convert grid minimums in CSS
In assets/css/almanack.css, change .margins-layout grid (line ~536):
From:
grid-template-columns:
minmax(12rem, 0.33fr)
minmax(22rem, 1fr)
minmax(12rem, 0.33fr);
gap: 1.5rem;
To:
grid-template-columns:
minmax(10em, 0.33fr)
minmax(28em, 1fr)
minmax(10em, 0.33fr);
gap: 1.2em;
Note: 12rem / 1.3 ≈ 9.2em, rounding to 10em. 22rem / 1.3 ≈ 16.9em,
but we use 28em to maintain comfortable center width (28em × 20.8px/em ÷ 16 ≈ 36.4rem ≈ 583px,
close to the current ~588px). The gap converts from 1.5rem to 1.2em (1.5/1.3 ≈ 1.15, rounded up).
- [ ] Step 4: Run regression test to verify no-op
Run: cd $ALMANACK_ROOT && pytest src/tests/test_layout_invariants.py::TestRemToEmRegression -v
Expected: PASS — column widths within 2px of baseline.
- [ ] Step 5: Commit
git add assets/css/almanack.css src/tests/test_layout_invariants.py
git commit -m "$(cat <<'EOF'
Convert grid minimums from rem to em
Grid columns now scale with body font-size. At current 1.3rem
body font, computed widths are unchanged (regression test passes).
This unblocks proportional scaling.
EOF
)"
Task 6: Convert margin font and internals from rem to em
Files:
- Modify: assets/css/almanack.css (lines ~552-554 for .margin, and margin-box internals)
- [ ] Step 1: Change
.marginfont-size to 0.8em
In assets/css/almanack.css, change .margin (line ~552):
From:
.margin {
position: relative;
font-size: 0.85rem;
To:
.margin {
position: relative;
font-size: 0.8em;
This changes the ratio from 65% (0.85/1.3) to the target 80%.
- [ ] Step 2: Convert margin-box internals from rem to em
These are relative to .margin (now 0.8em of body). Find and replace in assets/css/almanack.css:
.margin-box font-size (line ~1085): 0.9rem → 1em (already inside .margin, so 1em = margin font)
Search for .subscribe-form, .video-chapter-toc, .video-chapter-toc-heading font sizes that use rem and convert them to em values relative to their parent context. The exact values need to be verified by checking which ancestor sets the font-size context.
- [ ] Step 3: Run font hierarchy invariant test
Run: cd $ALMANACK_ROOT && pytest src/tests/test_layout_invariants.py::TestFontHierarchy -v --tb=short
Expected: PASS — ratio should now be ~0.80 at all broadsheet widths.
- [ ] Step 4: Run full invariant suite
Run: cd $ALMANACK_ROOT && pytest src/tests/test_layout_invariants.py -v --tb=short 2>&1 | tail -30
Check for any new failures introduced by the font-size change.
- [ ] Step 5: Commit
git add assets/css/almanack.css
git commit -m "$(cat <<'EOF'
Set margin font to 0.8em, convert margin internals to em
Margin font ratio changes from 65% to 80% of body (eyeball-tested
for clear visual hierarchy). Margin-box internals use em units so
they scale with the margin font.
EOF
)"
Chunk 3: Proportional Scaling (Phase 3)
Task 7: Add clamp() font scaling
Files:
- Modify: assets/css/almanack.css (body font-size, ~line 500)
- [ ] Step 1: Replace fixed font-size with clamp()
In assets/css/almanack.css, change body (line ~500):
From:
font-size: 1.3rem;
To:
font-size: clamp(0.85rem, 1.9vw, 1.3rem);
The floor 0.85rem (13.6px) is a starting estimate — the sweep will tell us
if it needs adjusting. At 1.9vw:
- 1100px → 20.9px (hits 1.3rem ceiling) ✓
- 850px → 16.2px ✓
- 700px → 13.3px (above 0.85rem floor) ✓
- [ ] Step 2: Add CSS custom properties for tunability
At the top of assets/css/almanack.css, add to :root (after the breakpoint vars, ~line 51):
/* Layout scaling (see doc/05-process/plans/2026-03-10-proportional-scaling-design.md) */
--margin-font-ratio: 0.8;
--body-font-max: 1.3rem;
--body-font-preferred: 1.9vw;
--body-font-floor: 0.85rem;
Update the body font-size to use them:
font-size: clamp(var(--body-font-floor), var(--body-font-preferred), var(--body-font-max));
- [ ] Step 3: Run invariant suite at current size
Run: cd $ALMANACK_ROOT && pytest src/tests/test_layout_invariants.py -v --tb=short 2>&1 | tail -30
At wide viewports (≥1100px), behaviour should be unchanged (clamp hits ceiling).
- [ ] Step 4: Commit
git add assets/css/almanack.css
git commit -m "$(cat <<'EOF'
Add clamp() proportional font scaling
Body font scales from 0.85rem floor to 1.3rem ceiling via 1.9vw.
CSS custom properties for all tuning parameters. At wide viewports
behaviour is unchanged; at narrow viewports font and columns
shrink proportionally.
EOF
)"
Task 8: Unify breakpoints and sync JS
Files:
- Modify: assets/css/almanack.css (media queries at 768px, 800px)
- Modify: assets/js/sidenotes.js (CONFIG.minViewportWidth, ~line 29)
- [ ] Step 1: Unify CSS breakpoints
The three-column layout now survives further down because everything scales. Replace the split 768px/800px with a single breakpoint.
Calculate: at what viewport width does the grid just fit?
2 × 10em + 28em + 2 × 1.2em + 2 × 1em = 52.4em
At the floor font (0.85rem = 13.6px): 52.4 × 13.6 = 713px
At 713px viewport, 1.9vw = 13.5px ≈ 0.85rem, so font is at floor.
Use 700px as the unified breakpoint (round down for safety).
In assets/css/almanack.css:
Change both @media (pointer: coarse) and (max-width: 800px) (line ~598)
and @media (pointer: fine) and (max-width: 800px) (line ~622)
to use 700px:
@media (pointer: coarse) and (max-width: 700px) {
@media (pointer: fine) and (max-width: 700px) {
Change the footnotes-reappear query (line ~1063) from 768px to 700px:
@media (pointer: fine) and (max-width: 700px) {
.sidenotes-enabled .footnotes {
- [ ] Step 2: Sync JS CONFIG
In assets/js/sidenotes.js, change CONFIG (line ~29):
From:
minViewportWidth: 800, // Below this, use fallback (must match CSS breakpoint)
To:
minViewportWidth: 700, // Below this, use fallback (must match CSS breakpoint)
- [ ] Step 3: Run mode consistency and footnotes tests
Run: cd $ALMANACK_ROOT && pytest src/tests/test_layout_invariants.py::TestModeConsistency src/tests/test_layout_invariants.py::TestFootnotesReachable -v --tb=short
Expected: The 768px and 800px failures should now PASS (both widths are in broadsheet mode). 700px should be the new boundary.
- [ ] Step 4: Run full invariant suite
Run: cd $ALMANACK_ROOT && pytest src/tests/test_layout_invariants.py -v --tb=short 2>&1 | tail -40
Record results.
- [ ] Step 5: Also run existing browser tests to check for regressions
Run: cd $ALMANACK_ROOT && make test-browser 2>&1 | tail -20
Expected: Existing tests should still pass (they use 1280px viewport).
- [ ] Step 6: Commit
git add assets/css/almanack.css assets/js/sidenotes.js
git commit -m "$(cat <<'EOF'
Unify breakpoints at 700px, sync JS CONFIG
Single three-column threshold replaces the 768/800px split.
Fixes the footnote dead zone bug. Three-column layout now
survives down to ~700px via proportional font scaling.
EOF
)"
Chunk 4: Matrix Sweep and Write-Up (Phases 4-5)
Task 9: Sweep the viewport × font-size matrix
Files:
- Create: doc/05-process/critiques/2026-03-10-proportional-scaling-results.md
- [ ] Step 1: Run invariant suite with default thresholds
Run: cd $ALMANACK_ROOT && pytest src/tests/test_layout_invariants.py -v --tb=line 2>&1
Save full output.
- [ ] Step 2: Run with +10% font override
To test with a larger base font, temporarily override the CSS custom property by injecting a style in the test. Add a parameterized font-override fixture and run:
Run: cd $ALMANACK_ROOT && pytest src/tests/test_layout_invariants.py -v --tb=line -k "TestColumnWidths or TestFontFloor" 2>&1
For manual font-size overrides, use browser developer tools or create a
small test that injects document.documentElement.style.setProperty('--body-font-max', '1.43rem')
before loading. Record which viewport widths fail.
- [ ] Step 3: Run with -10% font override
Same approach with --body-font-max: 1.17rem. Record results.
- [ ] Step 4: Run with different threshold values
Test with tighter thresholds to find the edge:
cd $ALMANACK_ROOT && pytest src/tests/test_layout_invariants.py -v \
--min-body-words=9 --min-margin-words=5 --margin-ratio=0.80 \
--tb=line 2>&1
And looser:
cd $ALMANACK_ROOT && pytest src/tests/test_layout_invariants.py -v \
--min-body-words=7 --min-margin-words=4 --margin-ratio=0.75 \
--tb=line 2>&1
- [ ] Step 5: Identify the font-size floor
From the sweep results, determine:
- The narrowest viewport where all invariants pass
- The computed body font-size at that viewport
- Whether the current 0.85rem floor is correct, too low, or too high
If the floor needs adjusting, update --body-font-floor in :root and re-run.
- [ ] Step 6: Commit any floor adjustments
git add assets/css/almanack.css
git commit -m "$(cat <<'EOF'
Adjust font-size floor to <value> based on matrix sweep
Sweep found that <explanation of what was discovered>.
EOF
)"
Task 10: Write up results
Files:
- Create: doc/05-process/critiques/2026-03-10-proportional-scaling-results.md
- [ ] Step 1: Write the critique document
Create doc/05-process/critiques/2026-03-10-proportional-scaling-results.md with:
- What we changed: clamp() scaling, em-based grid, unified breakpoints, 80% margin ratio
- The filled-in test matrix: which viewports × font-sizes pass/fail
- The discovered floor: the minimum body font-size where all invariants hold
- The new breakpoint: where three-column gives way to fallback
- Comparison with Feb experiment: what’s better, what’s the same
- Remaining issues: anything the sweep revealed that needs follow-up
-
Recommended tuning parameters: the CSS custom property values to ship
-
[ ] Step 2: Run make test to verify no regressions in default suites
Run: cd $ALMANACK_ROOT && make test
Expected: All default suites pass.
- [ ] Step 3: Run make test-all for full coverage
Run: cd $ALMANACK_ROOT && make test-all 2>&1 | tail -20
Record any failures.
- [ ] Step 4: Final commit
git add doc/05-process/critiques/2026-03-10-proportional-scaling-results.md
git commit -m "$(cat <<'EOF'
Document proportional scaling research results
Findings from viewport × font-size matrix sweep: discovered font
floor, validated invariants, filled in the test matrix. Comparison
with the reverted Feb 2026 font enlargement experiment.
EOF
)"
Summary of Commits
- Test harness with tunable thresholds
- Invariant tests: no-overflow + mode-consistency
- Invariant test: footnotes always reachable
- Invariant tests: column widths, font floor, font hierarchy + baseline results
- Grid minimums rem → em (with regression test)
- Margin font to 0.8em, internals to em
- clamp() proportional font scaling
- Unified breakpoints at 700px, JS sync
- Font-size floor adjustment (if needed)
- Results write-up