/*
  Book 2's page art (r9). Only the Nightstorm page loads this. Pairs with book2-art.js.

  Left page:  the Phoenix, mirrored so his head is on the right and he looks at the title, standing in front of
              the mountains, above the back-cover text.
  Right page: the tentacles, under the links, rising from the foot of the page.

  Every drawing is ink on nothing: one ink colour whose transparency is the pencil's darkness (as the eye and
  the little dragon on Book 1 are made), so the page's own paper and grain show wherever the sheet was bare.
  Without script, and under reduced motion, all three are still images and the title is plain text.
  The one red on the page is the fire that burns the title in (book2-art.js); smoke and ash are grey.
*/

/* ---- Left page: the scene. Its box is 1000 x 668.5 units; the places below are shares of it and match
        qa/make_book2_art_r9.py, which cut the Phoenix's shape out of the mountains. ---- */
.phx {
  position: relative;
  width: 100%;
  aspect-ratio: 1000 / 668.5;
}
.phx__far,
.phx__bird {
  position: absolute;
  display: block;
}
.phx__far {                       /* the mountains: small, far and faint */
  left: 0;
  top: 37.97%;
  width: 64%;
  height: 56.04%;
  opacity: 0.42;
}
.phx__bird {
  left: 33%;
  top: 0;
  width: 67%;
  height: 100%;
}
.phx__far img,
.phx__bird img {
  display: block;
  width: 100%;
  height: 100%;
}
.phx__fx,
.tent__fx {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
/* While a canvas shows a drawing, its image stays in the page (and keeps its alt text) but is not painted. */
.b2-live > picture img { opacity: 0; }
/* The smoke from his nostrils: a small canvas over the top right of the scene. */
.phx__smoke {
  position: absolute;
  left: 62%;
  top: -4%;
  width: 44%;
  height: 84%;
  pointer-events: none;
  mix-blend-mode: multiply;        /* grey that lies in the paper; the grain stays in it */
}

/* ---- Right page: the tentacles, the last thing in the column, at the foot of the page. ---- */
.tent {
  position: relative;
  width: 78cqi;
  aspect-ratio: 1000 / 562;
}
.tent img {
  display: block;
  width: 100%;
  height: 100%;
}
/* The column fills the page: the words sit in the middle of the room above the tentacles, and the tentacles
   stand on the foot of the page. (Rows: room, the eight lines, room, the tentacles.) */
@media (min-width: 720px) {
  .bk--b2 .bk__words { align-items: stretch; padding-bottom: calc(var(--page-w) * 0.03); }
  .bk--b2 .words { grid-template-rows: 1fr repeat(8, auto) 1fr auto; }
  .bk--b2 .words > :nth-child(1) { grid-row: 2; }
  .bk--b2 .words > :nth-child(2) { grid-row: 3; }
  .bk--b2 .words > :nth-child(3) { grid-row: 4; }
  .bk--b2 .words > :nth-child(4) { grid-row: 5; }
  .bk--b2 .words > :nth-child(5) { grid-row: 6; }
  .bk--b2 .words > :nth-child(6) { grid-row: 7; }
  .bk--b2 .words > :nth-child(7) { grid-row: 8; }
  .bk--b2 .words > :nth-child(8) { grid-row: 9; }
  .bk--b2 .words > .tent { grid-row: 11; }
}
/* Narrow pages (a short or small window): a little smaller, so they never crowd the links. */
@container (max-width: 320px) {
  .tent { width: 70cqi; }
}
@media (max-width: 719.98px) {
  .tent { width: 84cqi; margin-top: 2cqi; }
  .bk--b2 .bk__words { padding-bottom: calc(var(--page-w) * 0.04); }
  /* On a phone this book's one page is taller than Book 1's (the tentacles stand under the links). While the
     closed book is tilted, a taller book reaches a little further down; this keeps it clear of the credit. */
  .bk.bk--b2 { margin-bottom: 26px; }
}

/* ---- The fire and the burning title: three small canvases, only while the title burns in. The script sizes each
        to the part of the spread it needs. The flame is multiplied into the paper (the red stains it and the
        grain stays in it). It is drawn OVER the title's letters while it plays (steer 12: no text box cuts into the
        fire; the words show again when it ends); with #burn-behind in the address it passes behind them. ---- */
.b2-fire,
.b2-ash,
.b2-char {
  position: absolute;
  pointer-events: none;
}
.b2-fire { mix-blend-mode: multiply; z-index: 2; }
.b2-ash { z-index: 3; }           /* sparks, cinders, ash and smoke: under the letters */
.b2-char { z-index: 4; }          /* the title's letters as they burn */
.b2-across .b2-fire { mix-blend-mode: normal; z-index: 5; }

/* =====================  The sequence on Book 2 (library.js runs it; nothing in it is changed)  =====================
   The book opens -> the Phoenix is still -> the quill writes the back-cover text -> the right page draws in,
   all but the title -> (e-on) the Phoenix breathes one burst of fire and the title burns into the paper. */
.bk--b2.bk-seq.w-on .words > :nth-child(9) { animation-delay: 0.9s; }
/* The title waits for the fire. */
.bk--b2.bk-seq:not(.e-on) .words > h1 { opacity: 0; animation: none; }
/* If the fire cannot run (no script yet, no WebGL, forced colours): the title simply fades in. */
.bk--b2.bk-seq.e-on .words > h1 { animation: dt-fade-in 1.2s 0.4s ease-out both; }
/* The fire runs or is waiting to be seen (book2-art.js adds b2-burn): the title is real text all the time, there
   but unpainted, and the canvas laid over it paints its letters as they burn. Afterwards (b2-done) it is itself. */
.bk.bk--b2.b2-burn .words > h1,
.bk.bk--b2.b2-done .words > h1 { opacity: 1; animation: none; }
.bk.bk--b2.b2-burn.b2-set h1 span { transition: color 0.28s linear; }
.bk.bk--b2.b2-burn:not(.b2-set) h1 span { color: transparent; }
/* Every letter is burned in and the paper has healed (b2-set): the burned letters give way to the text itself. */
.b2-char { transition: opacity 0.28s linear; }
.b2-set .b2-char { opacity: 0; }

/* ---- Touch: every link and button on this page can be hit in a square of at least 44 px. Nothing is drawn
        larger: the two text links stand a little further apart, and each target's own unseen margin is part of it. ---- */
.bk--b2 .swap-link,
.bk--b2 .home-link { position: relative; }
.bk--b2 .swap-link { margin-top: 4px; }
.bk--b2 .swap-link::after,
.bk--b2 .home-link::after { content: ""; position: absolute; inset: -10px 0; }
:root:has(.bk--b2) .bk-control,
:root:has(.bk--b2) .credit a { position: relative; }
:root:has(.bk--b2) .bk-control::after { content: ""; position: absolute; inset: -7px 0; }
:root:has(.bk--b2) .credit a::after { content: ""; position: absolute; inset: -10px 0; }

@media (prefers-reduced-motion: reduce) {
  .phx__fx, .tent__fx, .phx__smoke, .b2-fire, .b2-ash, .b2-char { display: none; }
  .b2-live > picture img { opacity: 1; }
}
