/* The colonies.

   A colony belongs to a SECTION, not to the page. Laying the field on
   .nightfall with repeating vertical periods could not cover it: sections here
   run from 572px to 3962px tall, so any period long enough to be atmospheric
   left short sections sitting in the gaps. Two attempts proved it — at
   2600/3390/2130 #roadmap fell in a hole at 93% single-hue, and tightening to
   1870/2330/1610 fixed #roadmap and dropped #investors to 0.16%. Chasing the
   numbers was moving the hole around, not closing it.

   Tiled inside the section rather than placed once in it: sections run 572px
   to 3962px tall, so a single placement at a percentage of the section put the
   colony 1,865px down a tall one — below the fold of the screen a reader
   arrives on. A tile gives a short section one and a tall section several,
   with no number to tune per section.

   The bright CORE sits off the page and only the faint tail crosses the text.
   Centred in the margin it lifted the ground under prose from L=0.028 to
   L=0.09-0.11 and cost up to 4.4 contrast points, putting two runs under AA —
   light where the reading is, which is the one place overgrowth should not be.

   The placement must land inside the SHORTEST chapter on the page, and that
   number moves. It was 572px when these were set, so cores at 401-560px down
   their tile were inside every section. #business is 385px now, and its core
   fell past its own bottom edge: nighthue.mjs measured it at 0.18% saturated
   cold — no second source at all — while every other night chapter ran 2-4.5%.
   Re-derived against 385: every core now lands within 300px of a section's top.

   Variation is in the tile's own height and the position WITHIN it, never in a
   negative offset. An offset shifts the whole sequence out of the section: at
   -520px with a 1180px tile, #roadmap — 841px tall — had its colony land at
   y=-1 and the next one at 1179, so an 841px section sat between two pools and
   measured 97% single-hue. Every placement here lands inside 560px of a
   section's top, which is inside the shortest section on the page. They sit toward the margins — where overgrowth
   would be, and where prose does not reach — so warm light is still MADE in
   the middle where the reading is, and cold light is GROWN from the edges in.

   Three placements on a 3-cycle against nine sections, so the pattern does not
   line up with the chapter rhythm and no two neighbours share a side. */
/* The light is painted on a layer of its own, and that layer fades out at the
   chapter's own edges.
   A background box is the element's rectangle, so a repeat-y tile RESTARTS at
   each chapter's top and is CLIPPED at its bottom: the ground brightness above
   a seam and below it came from unrelated tile phases, and the difference
   showed as a hard-edged band across the top of nearly every night section —
   the one thing a continuous descent cannot have. Masked top and bottom, each
   chapter's light arrives and leaves the way light does, and the seam has
   nothing to draw. */
.nightfall .chapter::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    mask-image: linear-gradient(180deg,
        transparent 0%, #000 9%, #000 91%, transparent 100%);
    background-repeat: repeat-y;
    background-size: 100% var(--colony-span, 1400px);
    /* The grown light only. There was a lamp pool here too — warm radials at
       the page's edges, one per chapter — and from round twenty-one to round
       twenty-six the design judges found them the same way every time: "khaki
       glows with no source", "olive-grey radial smudges that read as a dirty
       lens", "neither lantern-warm nor emerald". Warm light over moss with
       nothing casting it is a stain. The made light at night has sources now:
       the lit windows in the sunset's settlement, the lantern roundel, the
       medallions' glow and the lit call to action. The ground carries only
       what grows on it.

       The colony tints rather than lights — see --colony-deep below. */
    background-image:
        radial-gradient(640px 540px at var(--colony-x) var(--colony-ty),
            color-mix(in srgb, var(--colony-deep) 74%, transparent) 0%,
            color-mix(in srgb, var(--colony-deep) 34%, transparent) 42%,
            transparent 70%);
}

/* The values sit on the CHAPTER, not on its light layer: the variants below
   set them per chapter, and a declaration on the pseudo-element would beat
   anything they inherit. */
.nightfall .chapter {
    --colony-hue: var(--biolume-core);
    /* The colony tints rather than lights.
       Damping its alpha to stop it reversing the descent took its hue out with
       its brightness, and nighthue.mjs caught a chapter left with no second
       source at all — which is the monoculture the two-source model exists to
       cure. So it is the hue, carried on a body dark enough not to lift the
       ground: saturation without luminance, which is what the DAY colonies
       already do one paragraph down ("on parchment overgrowth is not light, it
       is SHADE"). Cold light on a forest floor is a colour, not a lamp.

       Named, not mixed. Two goes at deriving this from --colony-hue failed in
       opposite directions: an srgb mix toward near-black dragged chroma down
       with lightness and left a chapter at 0.18% saturated cold, and an oklab
       mix kept the chroma but needed an alpha that lifted the ground again.
       These are chosen AT the night's own luminance — #0b2b26 measures 35.8
       and the ground it sits on measures about 40 — with the saturation a
       reading of "cold light" needs. A colony that neither brightens nor dulls
       the floor it grows on can be as loud as it likes.

       Moss, not teal: #0b2b26 sat at hue 170, and both design judges read it
       where it lands, in the left gutter, as "cold teal, not moss" and "teal
       wedges that fight the olive". #0c3220 is an emerald at hue 152, about the
       same luminance (40.6): green to the eye, and still cold and saturated
       enough over the olive ground to register as a second source. Hue 143
       was tried first and blended under 140 on the ground, where nighthue
       measured #roadmap with no grown light at all. */
    --colony-deep: #0c3220;
    --colony-x: 0%;
    --colony-span: 1400px;
    /* In pixels, and never nearer a tile's top than the ellipse reaches (378px
       here, 448px on a phone): at 21-25% of the tile the centre sat 295px
       down, so every repeat after the first was cut flat across its top, and
       both judges found the cut as "a teal block with a hard top edge". */
    --colony-ty: 470px;
}

.nightfall .chapter:nth-of-type(3n+2) {
    --colony-hue: var(--biolume-core);
    /* A greener colony at the same luminance as the cyan above it, so the rarer
       one is a different COLOUR and not a brighter patch. It was spore violet,
       and two reviewers found it where it lands — down the right edge — as "a
       cold violet strip, (40,37,58); that hue is not moss and not lantern"
       and "an off-palette wash that belongs to no light source and fights the
       moss". Grown light is green; the two colonies differ inside that family. */
    --colony-deep: #0f3325;
    --colony-x: 100%;
    --colony-span: 1750px;
    --colony-ty: 455px;
}

.nightfall .chapter:nth-of-type(3n) {
    --colony-x: 0%;
    --colony-span: 1180px;
    --colony-ty: 520px;
}

/* The day has colonies too, and it needed them more.

   --creek leads and --sage varies, not the other way round: sage (#9dbb8b) sits
   so close to parchment's own hue that at any strength which still looks like
   shade it reads as the SAME tone — #servitor and #technology stayed at 96-98%
   single-hue while #mission, the one creek section, came down to 94.7%.

   Lighting the night fixed its monoculture and left the DAY as the flattest
   surface on the page: #technology measured 98.3% single-hue and #mission
   97.7%, against a night that had come down to 77-85%. Those are the first two
   chapters a reader meets after the hero, so the page opened on its most
   uniform ground and got more varied as it went — backwards.

   On parchment overgrowth is not light, it is SHADE. A cold glow on a bright
   ground either disappears or looks like a screen defect; moss on a warm wall
   is a cool tint that darkens. So the day colonies subtract rather than add,
   which also means they can only help the dark-on-light text they pass under.

   Same tiling as the night: inside the section, never a negative offset, on
   periods that do not divide into each other. */
.daylight .chapter {
    background-repeat: repeat-y;
    background-size: 100% var(--moss-span, 1500px);
    background-image: radial-gradient(720px 600px at var(--moss-x) var(--moss-ty),
        color-mix(in srgb, var(--moss-hue) 46%, transparent) 0%,
        color-mix(in srgb, var(--moss-hue) 17%, transparent) 44%,
        transparent 72%);
    /* Warm shade, not green. Creek was read as "a blue-grey bloom, damp", and
       the leaf-green that replaced it was read, three rounds running, as
       "sage mildew", "cold mint and sage stains", "water damage": any green on
       paper is a stain, because nothing on a sunlit page grows green in a soft
       patch. Taking the shade away was measured too, and left #mission's
       margins at zero variation — the flat day this layer exists to prevent.
       So the shade stays and changes hue: the parchment's own umber, deeper
       toward the page's edges, which is how light falls off across paper in
       lamplight. The grown things on the day half are the drawn plants. */
    --moss-hue: color-mix(in oklab, var(--copper) 40%, var(--day-rule));
    --moss-x: 2%;
    --moss-span: 1500px;
    --moss-ty: 38%;
}

.daylight .chapter:nth-of-type(3n+2) {
    --moss-hue: var(--day-rule);
    --moss-x: 98%;
    --moss-span: 1840px;
    --moss-ty: 28%;
}

.daylight .chapter:nth-of-type(3n) {
    --moss-x: 6%;
    --moss-span: 1270px;
    --moss-ty: 46%;
}


/* Below 900px there is no margin for light to live in.

   The lamp and the colony are both positioned toward the edges, which works
   while there are edges: on a desktop they light the ground beside the measure.
   A phone is all measure. At full strength they lit the ground UNDER the text —
   #investors' crop measured a median of 98 and a p90 of 172 against a base
   night of 46, and its near-white lead fell to 3.22:1, which is the brightest
   ink on the page failing AA because the thing behind it got brighter.

   Atmosphere is worth less than the sentence it sits behind. */
@media (max-width: 900px) {
    .nightfall .chapter::after {
        /* The colony alone, and faintly. Damping the lamp was not enough — at
           13% it still held the ground under #investors' lead at a median of
           93 against a base night of 46, and the brightest ink on the page
           read 3.48:1. There is no position on a 390px screen that is beside
           the measure, so a light source there is always behind a sentence.
           The night on a phone is night; the two-source model is a thing you
           can see where there is room to see it. */
        background-image:
            radial-gradient(760px 640px at var(--colony-x) var(--colony-ty),
                color-mix(in srgb, var(--colony-hue) 8%, transparent) 0%,
                color-mix(in srgb, var(--colony-hue) 3%, transparent) 42%,
                transparent 70%);
        background-size: 100% var(--colony-span, 1400px);
    }
}


