/* ============================================================
   Aventurine — rounded squares on the budget page
   Load last. Scoped to body.tiles, so no other page changes.

   The page keeps the first site's type, colours and layout. This sheet
   only adds one motif to it, the lattice of rounded squares from the
   "Begin your ledger" call to action, and puts the hero and Download bands
   on the home page's charcoal, with the squares in light gray.

   Where it appears:
     the hero band       squares across the whole band, headline included
     the Download band   outlines framing the heading, filled squares
                         speckled across its top third, on charcoal

   The lattice is one empty element. Its ::before repeats one outlined
   square; its ::after draws the filled ones once, over a 12 x 6 block.
   Both are masks over a flat colour, anchored to the same corner, and the
   block is a whole number of --cell pitches, so the filled squares sit
   exactly on the outlined grid. A square is 44 of the 52px pitch, with a
   28% corner radius.
   ============================================================ */

.tiles {
  --av-ink:  #0E1A15;
  --av-deep: #13241D;    /* the dark surfaces */

  /* the squares' two colours: light gray, shared by the hero and Download bands */
  --tile-line: rgb(227 227 227 / .16);
  --tile-fill: rgb(227 227 227 / .26);

  --cell: 52px;
  --tile-outline: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 52 52'%3E%3Crect x='4.5' y='4.5' width='43' height='43' rx='12' fill='none' stroke='%23000' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E");
  --tile-on-low: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 624 312'%3E%3Cg%3E%3Crect x='576' y='56' width='44' height='44' rx='12'/%3E%3Crect x='472' y='108' width='44' height='44' rx='12'/%3E%3Crect x='264' y='160' width='44' height='44' rx='12'/%3E%3Crect x='576' y='160' width='44' height='44' rx='12'/%3E%3Crect x='368' y='212' width='44' height='44' rx='12'/%3E%3Crect x='524' y='212' width='44' height='44' rx='12'/%3E%3Crect x='108' y='264' width='44' height='44' rx='12'/%3E%3Crect x='472' y='264' width='44' height='44' rx='12'/%3E%3Crect x='576' y='264' width='44' height='44' rx='12'/%3E%3C/g%3E%3C/svg%3E");
  --tile-on-high: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 624 312'%3E%3Cg%3E%3Crect x='576' y='212' width='44' height='44' rx='12'/%3E%3Crect x='472' y='160' width='44' height='44' rx='12'/%3E%3Crect x='264' y='108' width='44' height='44' rx='12'/%3E%3Crect x='576' y='108' width='44' height='44' rx='12'/%3E%3Crect x='368' y='56' width='44' height='44' rx='12'/%3E%3Crect x='524' y='56' width='44' height='44' rx='12'/%3E%3Crect x='108' y='4' width='44' height='44' rx='12'/%3E%3Crect x='472' y='4' width='44' height='44' rx='12'/%3E%3Crect x='576' y='4' width='44' height='44' rx='12'/%3E%3C/g%3E%3C/svg%3E");
}

/* ---------- the lattice ----------
     --lat-w / --lat-h   how far across and down it reaches
     --lat-pos           the corner it grows from
     --lat-on            which filled pattern (low: near the bottom, high: near the top)
     --lat-line / --lat-fill   colours
   The element sits behind its section's content (z-index -1), so the
   section has to isolate; each one that carries a lattice does below. */
.tiles .lattice {
  position: absolute;
  z-index: -1;
  top: 0;
  right: 0;
  width: var(--lat-w, 64%);
  height: var(--lat-h, 100%);
  pointer-events: none;
  -webkit-mask-image: linear-gradient(to left, #000 25%, transparent);
          mask-image: linear-gradient(to left, #000 25%, transparent);
}
.tiles .lattice::before,
.tiles .lattice::after {
  content: "";
  position: absolute;
  inset: 0;
  -webkit-mask-position: var(--lat-pos, right bottom);
          mask-position: var(--lat-pos, right bottom);
}
.tiles .lattice::before {
  background: var(--lat-line, var(--tile-line));
  -webkit-mask-image: var(--tile-outline);
          mask-image: var(--tile-outline);
  -webkit-mask-size: var(--cell) var(--cell);
          mask-size: var(--cell) var(--cell);
}
.tiles .lattice::after {
  background: var(--lat-fill, var(--tile-fill));
  -webkit-mask-image: var(--lat-on, var(--tile-on-low));
          mask-image: var(--lat-on, var(--tile-on-low));
  -webkit-mask-size: calc(var(--cell) * 12) calc(var(--cell) * 6);
          mask-size: calc(var(--cell) * 12) calc(var(--cell) * 6);
  -webkit-mask-repeat: no-repeat;
          mask-repeat: no-repeat;
}
.tiles .lattice--high { --lat-on: var(--tile-on-high); --lat-pos: right top }
.tiles .lattice--quiet { --lat-line: rgb(207 224 212 / .1); --lat-fill: rgb(143 181 160 / .18) }

/* a corner cluster, fading down as well as across */
.tiles .lattice--head {
  --lat-w: 52%;
  --lat-h: 340px;
  -webkit-mask-image: linear-gradient(to left, #000 25%, transparent), linear-gradient(to bottom, #000 45%, transparent);
          mask-image: linear-gradient(to left, #000 25%, transparent), linear-gradient(to bottom, #000 45%, transparent);
  -webkit-mask-composite: source-in;
          mask-composite: intersect;
}

/* ---------- the hero band ----------
   The band is the header's ::before, which stops --overhang short of the
   bottom; the lattice covers the same area, unmasked, so the squares run
   behind the headline too. The ground is the home page's flat charcoal. */
.tiles .ledger-hero::before { background: var(--surface-inverse) }
.tiles .ledger-hero > .lattice {
  --lat-w: 100%;
  --lat-h: calc(100% - var(--overhang));
  -webkit-mask-image: none;
          mask-image: none;
}

/* The hero's squares are larger, and they light up in a wave. Every square
   keeps its outline (the lattice's ::before, as in the Download band); the wave
   fills it. Each lit square is an <i> placed on a grid: --k is its column counted from the
   centre (negative is left), --r its row from the top. The grid is centred
   rather than anchored to the right edge, so a square keeps its place at any
   window width.

   One wave takes --wave to repeat. A square's delay is its place along the
   wave's path (left to right and a little downward: .32s per column, .22s per
   row) plus its own --j, a jitter of about half a second either way, so the
   front is ragged rather than a clean line. --p is how bright it peaks, and
   a few positions carry no square. The wave spends about half the cycle
   crossing the band and the rest quiet. Only opacity animates; the delay
   starts 6s back, so the wave is already crossing when the page loads. */
.tiles .lattice--hero {
  --cell: clamp(48px, 4.9vw, 68px);
  --lat-pos: center top;
  --wave: 11s;
  --lat-line: var(--tile-fill);
  overflow: hidden;
}
/* outlines only: the fills come from the wave, not from a static pattern */
.tiles .lattice--hero::after { display: none }
.tiles .lattice--hero > i {
  position: absolute;
  display: block;
  width: calc(var(--cell) * 44 / 52);
  aspect-ratio: 1;
  top: calc(var(--r) * var(--cell) + var(--cell) * 4 / 52);
  left: calc(50% + var(--k) * var(--cell) - var(--cell) * 22 / 52);
  border-radius: 28%;
  background: var(--tile-fill);
  opacity: 0;
  animation: lattice-lit var(--wave) ease-in-out
    calc((var(--k) + 7) * .32s + var(--r) * .22s + var(--j) - 6s) infinite;
}
@keyframes lattice-lit {
  0%   { opacity: 0 }
  7%   { opacity: var(--p, 1) }
  18%  { opacity: 0 }
  100% { opacity: 0 }
}

/* ---------- the hero band's depth ----------
   The band stops --overhang short of the bottom (hero-ledger.css). Nothing
   straddles its edge on this page, so the overhang is zero and the band is
   the whole header; the padding under the copy keeps the button off the edge. */
.tiles .ledger-hero {
  --overhang: 0px;
  padding-bottom: clamp(4.5rem, 10vh, 6.5rem);
}

/* ---------- the Download band: charcoal and light gray ----------
   The hero's charcoal ground and light gray squares, and a light gray panel
   in charcoal ink. The colours are set as
   local tokens so .dark's own rules (its text is var(--surface)) pick them up. */
.tiles section.dark {
  --dl-charcoal: var(--surface-inverse);   /* the home page's charcoal */
  --dl-light:    #E3E3E3;
  --surface: var(--dl-light);
  --text: var(--dl-charcoal);
  --text-muted: #55575A;
  --panel-raised: #EFEFEF;
  --border: color-mix(in srgb, var(--dl-charcoal) 16%, transparent);
  --accent: var(--dl-charcoal);
  position: relative;
  isolation: isolate;
  overflow: hidden;
  background: var(--dl-charcoal);
}
.tiles section.dark h2 { color: var(--dl-light) }
/* The panel's usual ground is translucent white, which over the charcoal
   turns murky, and its row titles carry no colour of their own, so they would
   take the band's light text. A solid light gray ground and charcoal ink keep
   it the panel it is elsewhere, and the build logos keep their neutral field. */
.tiles section.dark .list-panel { background: var(--surface); color: var(--text) }
.tiles section.dark .tile:active { background: #D6D6D6 }
.tiles section.dark .tile-go { color: var(--dl-charcoal) }
/* faded out before the panel */
.tiles section.dark > .lattice {
  --lat-w: 100%;
  --lat-h: 100%;
  -webkit-mask-image: linear-gradient(to bottom, #000 40%, transparent 68%);
          mask-image: linear-gradient(to bottom, #000 40%, transparent 68%);
  -webkit-mask-composite: initial;
          mask-composite: initial;
}
/* The outlines stay clear in the middle for the heading: a second mask layer,
   intersected with the outline. */
.tiles section.dark > .lattice::before {
  -webkit-mask-image: var(--tile-outline), radial-gradient(ellipse 48% 60% at 50% 38%, transparent 36%, #000 100%);
          mask-image: var(--tile-outline), radial-gradient(ellipse 48% 60% at 50% 38%, transparent 36%, #000 100%);
  -webkit-mask-size: var(--cell) var(--cell), 100% 100%;
          mask-size: var(--cell) var(--cell), 100% 100%;
  -webkit-mask-repeat: repeat, no-repeat;
          mask-repeat: repeat, no-repeat;
  -webkit-mask-position: var(--lat-pos, right bottom), 0 0;
          mask-position: var(--lat-pos, right bottom), 0 0;
  -webkit-mask-composite: source-in;
          mask-composite: intersect;
}
/* The filled squares are a sparse speckle across the whole top third, heading
   included. --tile-speckle is a 32 x 8 block, tiled both ways from the same
   corner as the outlines (it is a whole number of --cell pitches, so the fills
   stay on the grid). The box is a third of the band's height rounded down to
   whole rows, so no square is cut in half at its lower edge. */
.tiles section.dark > .lattice::after {
  --tile-speckle: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1664 416'%3E%3Cg%3E%3Crect x='212' y='4' width='44' height='44' rx='12'/%3E%3Crect x='784' y='4' width='44' height='44' rx='12'/%3E%3Crect x='992' y='4' width='44' height='44' rx='12'/%3E%3Crect x='1356' y='4' width='44' height='44' rx='12'/%3E%3Crect x='576' y='56' width='44' height='44' rx='12'/%3E%3Crect x='888' y='56' width='44' height='44' rx='12'/%3E%3Crect x='1616' y='56' width='44' height='44' rx='12'/%3E%3Crect x='1200' y='160' width='44' height='44' rx='12'/%3E%3Crect x='1304' y='160' width='44' height='44' rx='12'/%3E%3Crect x='108' y='212' width='44' height='44' rx='12'/%3E%3Crect x='472' y='212' width='44' height='44' rx='12'/%3E%3Crect x='1096' y='212' width='44' height='44' rx='12'/%3E%3Crect x='1616' y='212' width='44' height='44' rx='12'/%3E%3Crect x='264' y='264' width='44' height='44' rx='12'/%3E%3Crect x='576' y='264' width='44' height='44' rx='12'/%3E%3Crect x='836' y='264' width='44' height='44' rx='12'/%3E%3Crect x='1148' y='316' width='44' height='44' rx='12'/%3E%3Crect x='1564' y='316' width='44' height='44' rx='12'/%3E%3C/g%3E%3C/svg%3E");
  bottom: auto;
  height: 33.333%;
  height: round(down, 33.333%, var(--cell));
  -webkit-mask-image: var(--tile-speckle);
          mask-image: var(--tile-speckle);
  -webkit-mask-size: calc(var(--cell) * 32) calc(var(--cell) * 8);
          mask-size: calc(var(--cell) * 32) calc(var(--cell) * 8);
  -webkit-mask-repeat: repeat;
          mask-repeat: repeat;
}

/* ---------- narrow screens, reduced motion ---------- */
@media (max-width: 700px) {
  .tiles { --cell: 44px }
  .tiles .lattice--hero { --cell: 42px }
  .tiles .lattice { opacity: .6 }
  .tiles section.dark > .lattice {
    -webkit-mask-image: linear-gradient(to bottom, #000 15%, transparent 60%);
            mask-image: linear-gradient(to bottom, #000 15%, transparent 60%);
  }
}

/* held still: no wave, a scattering of squares left dimly lit */
@media (prefers-reduced-motion: reduce) {
  .tiles .lattice--hero > i { animation: none }
  .tiles .lattice--hero > i:nth-child(5n + 1) { opacity: .3 }
}
