Skip to content

1.16 part 9/18: Games: the Red night light in every game's stylesheet - #180

Closed
epheterson wants to merge 1 commit into
line/1.16.0-08-games-newfrom
line/1.16.0-09-games-red
Closed

epheterson wants to merge 1 commit into
line/1.16.0-08-games-newfrom
line/1.16.0-09-games-red

Conversation

@epheterson

@epheterson epheterson commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Part 9 of 18 of Zimi 1.16.0: Games: the Red night light in every game's stylesheet. Base: line/1.16.0-08-games-new (part 8); the diff shows only this part's files. The PR carries the not-a-release label and the version stays 1.15.7, so merging it cuts no release. Merge in order (1 to 17, then 18) with a merge commit, not a squash.

What this is

The Games shell (part 6) already has a Red night theme for its own tokens. The older games write colours straight into their stylesheets, so in Red they stayed light. This part adds a generator that gives every games stylesheet a Red twin of each rule that holds a colour literal, plus a drift test and one browser test.

What changes

  • scripts/games_red.py: for each zimi/builtin/games/*.css it finds every declaration holding a hex, rgb() or rgba() colour and appends a twin under :root.gs.night-red. Each colour is mapped by luminance onto black-to-red (white becomes #ff2010, black stays black, alpha is kept).
  • scripts/games_red.py details: rules inside prefers-color-scheme: dark are unwrapped (Red is dark), light-only rules, @keyframes, @font-face and similar at-rules are skipped, and the twins keep source order so later overrides still win. python3 scripts/games_red.py rewrites the blocks, --check exits 1 if one is stale.
  • 55 stylesheets change; 47 of them get a block between /* Red, generated by scripts/games_red.py ... */ and /* end Red */, appended at the end of the file.
  • 31 stylesheets also get one hand-written line, /* Red (games.css): ... */, that sets the file's own custom properties (for example the 2048 tile ramp, the Mahjong face and edge) under :root.gs.night-red. The generator skips custom properties on :root on purpose.
  • tests/test_games_red_generated.py: fails if any stylesheet's block differs from what the script would write, and checks the colour mapping.
  • tests/test_games_mahjong_red_browser.py: in Red, every ink in a tile of both Mahjong games is near black on the red face.
  • Layout edits that are not Red, in the same files: fiveletters.css (how-to-play example rows, a larger tap box for keys on a coarse pointer, a help button), minicrossword.css (the same key tap box), cribbage.css (peg-board tick labels 6px to 11px), backgammon.css (point numbers 10px to 12px), hex.css (the board's height budget 205px to 292px), wikirace.css (trail scrollbar rule removed), kart.css (a portrait media block).
  • world.css: a landscape block for the square-board games (Walls, Fourfold, Polyominoes, Checkers, Reversi, Go): board on the left, status and controls stacked beside it.

How to review

  • Read scripts/games_red.py first: blocks (the brace and string scanner), red_selector (which selectors are skipped) and generated (comments are stripped before scanning, so a colour inside a comment never produces a twin).
  • Then open one generated block, for example the end of zimi/builtin/games/mahjong.css or world.css, and check that each twin keeps its property list and only the colours change.
  • Risk: a rule whose colour comes only through var() gets no twin and relies on the token values in games.css. Nothing here runs on the server path.
  • Skip: the generated blocks in the 55 stylesheets (they are the script's output; --check proves it) and the 31 one-line token overrides after a quick look that each uses :root.gs.night-red.
  • Rides here: the Five Letters how-to-play and help-button rules in fiveletters.css style markup that lands in part 10 (fiveletters.js, fiveletters.html), so they are unused until then. The world.css landscape block and the key tap boxes belong to the phone and landscape pass (part 10) by subject; they are here because they sit in the same stylesheets the generator rewrote.

Tests

  • tests/test_games_red_generated.py (quick, no browser): every stylesheet's generated block is current, and convert maps white, black, alpha colours and var() values as stated.
  • tests/test_games_mahjong_red_browser.py: the glyph inks of mahjong.html and mahjong4.html tiles are near black in Red at a 390px touch viewport.

Summary by Sourcery

Extend the Games stylesheets with synchronized Red night-theme coverage while improving mobile and landscape presentation across selected games.

New Features:

  • Add Red night-theme styling across game-specific colour literals and stylesheet tokens for the games collection.
  • Add a landscape layout for square-board games and improve touch, readability, and responsive layouts in several games.

Bug Fixes:

  • Ensure Mahjong tile glyphs remain readable against Red tile faces.
  • Restore visible scrolling controls for WikiRace trails.

Enhancements:

  • Add a generator and drift checks to keep Red stylesheet overrides synchronized across games.

Tests:

  • Add generated-style validation and colour-conversion tests.
  • Add browser coverage for Mahjong rendering in Red mode.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@epheterson epheterson added the not-a-release Ships nothing; CI skips the version check label Nov 23, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Add the generator that scans game stylesheets, converts literal colours into Red-theme twins, and supports rewriting or checking generated blocks.

  • scripts/games_red.py L1-215

UI

Add Red-theme colour overrides and generated rule twins across the game stylesheets, alongside the listed layout and sizing adjustments.

  • zimi/builtin/games/2048.css L19-20
  • zimi/builtin/games/backgammon.css L5-6, L22, L38-48
  • zimi/builtin/games/blast.css L5-8
  • zimi/builtin/games/carrom.css L5-6, L24-27
  • zimi/builtin/games/checkers.css L5-6, L15-24
  • zimi/builtin/games/chess.css L26-30
  • zimi/builtin/games/chesspuzzles.css L10-14
  • zimi/builtin/games/chinesecheckers.css L5-6, L27-39
  • zimi/builtin/games/circuit.css L10-13
  • zimi/builtin/games/crazyeights.css L7-11
  • zimi/builtin/games/cribbage.css L6, L11-18
  • zimi/builtin/games/dominoes.css L5-6, L52-59
  • zimi/builtin/games/dotsandboxes.css L5-6
  • zimi/builtin/games/draughts.css L5-6, L23-33
  • zimi/builtin/games/echo.css L16-20
  • zimi/builtin/games/fiveletters.css L7-8, L32-34, L46-57
  • zimi/builtin/games/fleet.css L30-41
  • zimi/builtin/games/fourinarow.css L5-6, L24-28
  • zimi/builtin/games/go.css L5-6, L35-40
  • zimi/builtin/games/gomoku.css L5-6, L21-25
  • zimi/builtin/games/goproblems.css L5-6, L15-18
  • zimi/builtin/games/hex.css L5-8, L21-26
  • zimi/builtin/games/hnefatafl.css L5-6, L30-42
  • zimi/builtin/games/janggi.css L5-6, L37-43
  • zimi/builtin/games/jigsaw.css L20-24
  • zimi/builtin/games/kart.css L69-77
  • zimi/builtin/games/koikoi.css L14-18
  • zimi/builtin/games/ludo.css L5-6, L44-53
  • zimi/builtin/games/mahjong.css L5-6, L29-34
  • zimi/builtin/games/mahjong4.css L5-6, L65-71
  • zimi/builtin/games/makruk.css L5-6, L18-21
  • zimi/builtin/games/mancala.css L5-6, L19-24
  • zimi/builtin/games/memory.css L35-38
  • zimi/builtin/games/minesweeper.css L17-18, L72-75
  • zimi/builtin/games/minicrossword.css L36-38
  • zimi/builtin/games/morris.css L5-6, L25-31
  • zimi/builtin/games/pixel.css L7-10
  • zimi/builtin/games/quizzical.css L24-28
  • zimi/builtin/games/reversi.css L5-6, L20-25
  • zimi/builtin/games/roadrush.css L4-7
  • zimi/builtin/games/scopa.css L4-7
  • zimi/builtin/games/shogi.css L5-6, L53-61
  • zimi/builtin/games/skydetective.css L9-12
  • zimi/builtin/games/snakesandladders.css L5-6, L29-33
  • zimi/builtin/games/sokoban.css L8-9
  • zimi/builtin/games/sudoku.css L9-10
  • zimi/builtin/games/teenpatti.css L3-6
  • zimi/builtin/games/timeline.css L20-24
  • zimi/builtin/games/ur.css L5-6, L36-45
  • zimi/builtin/games/whereintheworld.css L27-30
  • zimi/builtin/games/wikirace.css L7
  • zimi/builtin/games/world.css L28-46
  • zimi/builtin/games/xiangqi.css L5-6, L39-44
  • zimi/builtin/games/yacht.css L26-29
  • zimi/builtin/games/zimcity.css L7-8

Tests

Add a drift check and converter assertions for generated Red rules, plus browser coverage that Mahjong tile glyphs remain readable in Red.

  • tests/test_games_mahjong_red_browser.py L1-38
  • tests/test_games_red_generated.py L1-22

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@epheterson epheterson mentioned this pull request Nov 23, 2026
@epheterson
epheterson force-pushed the line/1.16.0-08-games-new branch from b9589c2 to 7d5a2e5 Compare November 23, 2026 10:07
@epheterson
epheterson force-pushed the line/1.16.0-09-games-red branch from 1d0a378 to 9151986 Compare November 23, 2026 10:07

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="scripts/games_red.py" line_range="207" />
<code_context>
+        if want != have:
+            stale.append(fn)
+            if "--check" not in argv:
+                with open(path, "w", encoding="utf-8") as f:
+                    f.write(want)
+    if stale:
</code_context>
<issue_to_address>
**Generator overwrites external files**

When a contributor-controlled `.css` symlink in `GAMES` points outside the tree and a maintainer runs the documented rewrite mode, the rewrite's `open(path, "w")` follows the symlink and writes generated stylesheet contents to its target, corrupting the maintainer's external file.

Reject symlinks and verify each resolved stylesheet path remains inside `GAMES` before reading or writing it.
</issue_to_address>

### Comment 2
<location path="zimi/builtin/games/world.css" line_range="35" />
<code_context>
+  .bg-main:not(.is-rail):has(> :is(.wl-wrap, .ff-board, .po-board, .bg-board, .wk-board)) > :not(.wl-wrap, .ff-board, .po-board) { grid-column: 2; max-width: 100%; }
</code_context>
<issue_to_address>
**Boards appear in controls column**

When a game with a direct-child `.bg-board` or `.wk-board` is shown in landscape at a height of 520px or less, `> :not(.wl-wrap, .ff-board, .po-board)` also matches those board children, so its later `grid-column: 2` overrides their `grid-column: 1` placement and leaves the board in the controls column.

Exclude `.bg-board` and `.wk-board` from the controls selector, or target the controls explicitly.
</issue_to_address>

### Comment 3
<location path="scripts/games_red.py" line_range="23-24" />
<code_context>
+BEGIN = "/* Red, generated by scripts/games_red.py from the rules above: do not edit. */"
+END = "/* end Red */"
+RED = ":root.gs.night-red"
+HEX = re.compile(r"#([0-9a-fA-F]{8}|[0-9a-fA-F]{6}|[0-9a-fA-F]{3})\b")
+RGB = re.compile(r"rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)")
+SKIP_AT = ("@keyframes", "@-webkit-keyframes", "@font-face", "@page", "@property", "@import", "@charset")
+
</code_context>
<issue_to_address>
**Some colours stay unchanged in Red mode**

When a game stylesheet uses valid CSS colour syntax outside the regex patterns, such as `#RGBA` or percentage/space-separated `rgb()` or `rgba()`, `HEX` and `RGB`/`has_colour` do not recognize those forms, so the colour is not converted and its original hue remains visible in Red mode.

Extend the colour matching and conversion to cover the valid CSS colour syntaxes used by game stylesheets.
</issue_to_address>

Sourcery assessment

Approval pending. 3 findings to address first.

Blocking findings: scripts/games_red.py:207, zimi/builtin/games/world.css:35, scripts/games_red.py:24


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread scripts/games_red.py
if want != have:
stale.append(fn)
if "--check" not in argv:
with open(path, "w", encoding="utf-8") as f:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Generator overwrites external files

When a contributor-controlled .css symlink in GAMES points outside the tree and a maintainer runs the documented rewrite mode, the rewrite's open(path, "w") follows the symlink and writes generated stylesheet contents to its target, corrupting the maintainer's external file.

Reject symlinks and verify each resolved stylesheet path remains inside GAMES before reading or writing it.

Prompt for AI agents
In `scripts/games_red.py` at line 207:

**Generator overwrites external files**

When a contributor-controlled `.css` symlink in `GAMES` points outside the tree and a maintainer runs the documented rewrite mode, the rewrite's `open(path, "w")` follows the symlink and writes generated stylesheet contents to its target, corrupting the maintainer's external file.

Reject symlinks and verify each resolved stylesheet path remains inside `GAMES` before reading or writing it.

.bg-main:not(.is-rail):has(> :is(.wl-wrap, .ff-board, .po-board, .bg-board, .wk-board)) { --side: calc(100vw - 2 * var(--gutter) - var(--sp-4)); --board: min(100svh - var(--bar-h) - 44px, var(--side) - 300px, 560px);
display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: 1fr repeat(6, auto) 1fr; column-gap: var(--sp-4); row-gap: var(--sp-2); align-content: center; justify-content: center; justify-items: center; align-items: center; }
.bg-main:not(.is-rail):has(> :is(.wl-wrap, .ff-board, .po-board, .bg-board, .wk-board)) > :is(.wl-wrap, .ff-board, .po-board, .bg-board, .wk-board) { --hs: var(--board); --fs: var(--board); --ps: var(--board); --bs: var(--board); grid-column: 1; grid-row: 1 / span 8; }
.bg-main:not(.is-rail):has(> :is(.wl-wrap, .ff-board, .po-board, .bg-board, .wk-board)) > :not(.wl-wrap, .ff-board, .po-board) { grid-column: 2; max-width: 100%; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Boards appear in controls column

When a game with a direct-child .bg-board or .wk-board is shown in landscape at a height of 520px or less, > :not(.wl-wrap, .ff-board, .po-board) also matches those board children, so its later grid-column: 2 overrides their grid-column: 1 placement and leaves the board in the controls column.

Exclude .bg-board and .wk-board from the controls selector, or target the controls explicitly.

Prompt for AI agents
In `zimi/builtin/games/world.css` at line 35:

**Boards appear in controls column**

When a game with a direct-child `.bg-board` or `.wk-board` is shown in landscape at a height of 520px or less, `> :not(.wl-wrap, .ff-board, .po-board)` also matches those board children, so its later `grid-column: 2` overrides their `grid-column: 1` placement and leaves the board in the controls column.

Exclude `.bg-board` and `.wk-board` from the controls selector, or target the controls explicitly.

Comment thread scripts/games_red.py
Comment on lines +23 to +24
HEX = re.compile(r"#([0-9a-fA-F]{8}|[0-9a-fA-F]{6}|[0-9a-fA-F]{3})\b")
RGB = re.compile(r"rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Some colours stay unchanged in Red mode

When a game stylesheet uses valid CSS colour syntax outside the regex patterns, such as #RGBA or percentage/space-separated rgb() or rgba(), HEX and RGB/has_colour do not recognize those forms, so the colour is not converted and its original hue remains visible in Red mode.

Extend the colour matching and conversion to cover the valid CSS colour syntaxes used by game stylesheets.

Prompt for AI agents
In `scripts/games_red.py` at lines 23-24:

**Some colours stay unchanged in Red mode**

When a game stylesheet uses valid CSS colour syntax outside the regex patterns, such as `#RGBA` or percentage/space-separated `rgb()` or `rgba()`, `HEX` and `RGB`/`has_colour` do not recognize those forms, so the colour is not converted and its original hue remains visible in Red mode.

Extend the colour matching and conversion to cover the valid CSS colour syntaxes used by game stylesheets.

@epheterson
epheterson force-pushed the line/1.16.0-08-games-new branch from 7d5a2e5 to 87f5336 Compare November 23, 2026 10:52
@epheterson
epheterson force-pushed the line/1.16.0-09-games-red branch from 9151986 to fd2590f Compare November 23, 2026 10:52
@epheterson
epheterson force-pushed the line/1.16.0-08-games-new branch from 87f5336 to 173a003 Compare November 23, 2026 16:37
@epheterson
epheterson force-pushed the line/1.16.0-09-games-red branch from fd2590f to 445cb99 Compare November 23, 2026 16:37
@epheterson
epheterson force-pushed the line/1.16.0-08-games-new branch from 173a003 to 74fbfb9 Compare November 23, 2026 16:44
@epheterson
epheterson force-pushed the line/1.16.0-09-games-red branch from 445cb99 to 729e9a3 Compare November 23, 2026 16:44
@epheterson

Copy link
Copy Markdown
Owner Author

Reviewed here; included in the release PR #189.

@epheterson epheterson closed this Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

not-a-release Ships nothing; CI skips the version check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant