/*
 * The Fractions book's left page (fractions-book.js), typeset as the layout model (the table brief's
 * 0-layout-model-old-energy-page.png) and drawn as part of the book (BOOKS-V2-QUALITY.md, "Book design rules"): a framed
 * paper page, a small kicker, an italic heading, a few short lines, one red line of maths, one instruction; under a rule
 * the live numbers, a small number line and the tools in ink: the Fold tab drawn by hand, "Hang it here" a red ribbon,
 * "Ask for a hint" and "Show me an example" handwritten links. In the help state the top of the page is open, so the
 * dragons' table stands up there, and the maths is written by hand on a sheet below.
 *
 * The page's HTML is as wide as its top edge on the screen (fractions-book.js placeOverlays), so a size set here is the
 * least it is drawn; every size is relative to the page (`cq` units) and never under 16px. Three shapes: `tall` (a
 * tablet or a desktop: the pages stand taller than wide), `notepad` (a phone held upright: the page above the world) and
 * `short` (a phone on its side: the words on the left of the page, the tools on the right). Loaded after table-book.css.
 */
:root { --hand: "Bradley Hand", "Segoe Print", "Marker Felt", "Chalkboard SE", "Comic Sans MS", cursive; }
body { background: #2a1c12; }
body[data-mode="3d"] { background: #2a1c12; }

/* the desk's own small nav: the mark and the spread's name, no control; it keeps to its strip above the book */
.top { height: 46px; padding: 6px 12px; box-sizing: border-box; color: #f6efdc; }
.top img { width: 30px; height: 30px; }
.top b { margin-right: 8px; font-size: 17px; }
#crumb { margin-right: auto; font-size: 16px; }
/* inside the kids desk's Book (`&desk=1`): no nav of the page's own, the desk's cream round the book */
body[data-desk] { background: #F6F1E7; }
body[data-desk] .top { display: none; }
@media (max-width: 600px), (max-height: 520px) { .top b { display: none; } }
#wait { position: fixed; inset: 48% 0 auto; }

/* the page, laid corner by corner onto the left page of the book */
#page { position: fixed; z-index: 2; left: 0; top: 0; transform-origin: 0 0; color: var(--ink); font-family: var(--serif); container-type: size; }
#page[hidden] { display: none; }
#reading, #help { position: absolute; inset: 0; box-sizing: border-box; }
#reading { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 5cqh 8cqw 3.5cqh; background: #fcf8ee; box-shadow: inset 0 0 0 1.6cqw #fcf8ee, inset 0 0 0 calc(1.6cqw + 1px) #d9cfb8; border-radius: 3px; overflow: hidden; }
#reading[hidden], #help[hidden] { display: none; }
.kicker { margin: 0; font: italic 500 18px/1.2 var(--serif); letter-spacing: .04em; color: #8a7a52; }
#heading { margin: 1.4cqh 0 1cqh; font: italic 500 clamp(22px, 6.4cqw, 44px)/1.12 var(--serif); letter-spacing: -.01em; }
#lines p { margin: 0 0 .2em; font: 400 clamp(17px, 3.5cqw, 23px)/1.38 var(--serif); }
.equation { margin: 1.4cqh 0 .2cqh; font: italic 500 clamp(19px, 4.6cqw, 30px)/1.2 var(--serif); color: #8f2f2a; }
.instruction { margin: 1cqh 0 0; font: 400 clamp(17px, 3.1cqw, 20px)/1.38 var(--serif); color: var(--soft); }
#work { width: 100%; margin-top: auto; display: flex; flex-direction: column; align-items: center; }
#work hr { width: 88%; margin: 1.2cqh 0 .8cqh; border: 0; border-top: 1px solid var(--rule); }
.numbers { margin: 0; font: 700 clamp(17px, 3.2cqw, 21px)/1.3 var(--mono); color: var(--ink); letter-spacing: .02em; }
.paper.mini { width: 94%; height: clamp(40px, 9cqh, 76px); flex: none; }

/* the tools, in ink on the page */
.controls { display: flex; gap: 4cqw; align-items: center; justify-content: center; flex-wrap: wrap; margin: .6cqh 0 1cqh; }
.controls .tab { height: 48px; border-radius: 255px 14px 225px 14px / 14px 225px 14px 255px; background: transparent; box-shadow: none; border: 2px solid var(--ink); overflow: visible; }
.controls .tab .lab { padding: 0 6px 0 14px; font: 400 20px/1 var(--hand); color: var(--ink); }
.controls .tab output { min-width: 26px; padding: 0 4px; font: 400 24px/1 var(--hand); color: #8f2f2a; }
.controls .tab button { min-width: 44px; height: 44px; padding: 0 8px; border: 0; border-left: 1.5px dashed #9fb0a6; font: 400 26px/1 var(--hand); color: var(--ink); background: transparent; }
.controls .tab button:hover { background: #efe6cf; }
/* "Hang it here": a red ribbon laid across the page, its end cut in a swallowtail */
.ribbon { white-space: nowrap; height: 48px; min-width: 0; padding: 0 30px 0 18px; border: 0; border-radius: 0; background: #8f2f2a; color: #fbf3e2; font: italic 600 clamp(17px, 3.4cqw, 21px)/1 var(--serif); clip-path: polygon(0 0, 100% 0, calc(100% - 14px) 50%, 100% 100%, 0 100%); box-shadow: none; }
.ribbon:hover { background: #a2352f; }
.ribbon:disabled { background: #b9a9a0; }
.links { display: flex; gap: 6cqw; justify-content: center; flex-wrap: wrap; }
.link { min-height: 44px; padding: 0 4px; border: 0; background: none; font: 400 clamp(18px, 3.4cqw, 22px)/1 var(--hand); color: var(--leaf); text-decoration: underline wavy rgb(44 100 80 / .55) 1px; text-underline-offset: 6px; }
.link:hover { color: var(--ink); }
#after { width: 100%; margin-top: auto; display: flex; flex-direction: column; align-items: center; gap: 1.4cqh; }
#after .keep { width: 100%; box-sizing: border-box; box-shadow: none; border: 1.5px dashed var(--rule); background: transparent; }
#after .keep label { font: italic 400 17px/1.35 var(--serif); }
#after .keep input { font-size: 17px; }
#after .keep-row .ribbon, #after .keep-row button { font-size: 17px; }
#keepLine { font-size: 17px; }

/* the help state: the top of the page is the dragons' table (3D, seen through); the maths is written on a sheet below */
#help { display: flex; flex-direction: column; pointer-events: none; }
.stage-room { flex: 0 0 40%; }
.sheet { flex: 1; min-height: 0; display: flex; flex-direction: column; margin: 0 2.4cqw 2cqh; padding: 1.4cqh 4cqw .6cqh; border-radius: 6px; background: #fffef8; box-shadow: 0 0 0 1.5px #b9b19d, 0 6px 14px -8px #0006; pointer-events: auto; text-align: left; overflow: auto; }
.sheet h2 { margin: 0 0 4px; font: 600 clamp(17px, 3.6cqw, 22px)/1.25 var(--serif); }
#replay { margin: 0 0 4px; padding: 0; list-style: none; counter-reset: step; }
#replay li { counter-increment: step; position: relative; padding: 2px 0 2px 32px; font: 500 17px/1.35 var(--sans); }
#replay li::before { content: counter(step); position: absolute; left: 0; top: 2px; width: 24px; height: 24px; border-radius: 50%; background: #8f2f2a; color: #fff; display: grid; place-items: center; font: 700 17px/1 var(--sans); }
.said { margin: 2px 0; min-height: 1.4em; font: italic 400 clamp(17px, 3.3cqw, 21px)/1.38 var(--serif); color: var(--ink); }
.sheet .paper { flex: 1; min-height: 72px; width: 100%; }

/* a tall page (a tablet or a desktop): larger type, the words higher on the page */
#page[data-shape="tall"] #reading { padding-top: 7cqh; }
#page[data-shape="tall"] #heading { margin: 2.4cqh 0 2cqh; font-size: clamp(26px, 7.6cqw, 52px); }
#page[data-shape="tall"] #lines p { font-size: clamp(17px, 4.1cqw, 27px); }
#page[data-shape="tall"] .equation { margin-top: 2.6cqh; font-size: clamp(20px, 5.6cqw, 36px); }
#page[data-shape="tall"] .instruction { margin-top: 2cqh; font-size: clamp(17px, 3.6cqw, 23px); }

/* a phone held upright: the page above the world, the same order, a little closer together */
#page[data-shape="notepad"] #reading { padding: 2.6cqh 3.4cqw 1.2cqh; }
#page[data-shape="notepad"] .kicker { display: none; }
#page[data-shape="notepad"] #heading { margin: 0 0 .4cqh; font-size: 23px; }
#page[data-shape="notepad"] .equation { margin-top: .6cqh; }
#page[data-shape="notepad"] .instruction { margin-top: .4cqh; }
#page[data-shape="notepad"] #work hr { margin: .6cqh 0 0; }
#page[data-shape="notepad"] .paper.mini { height: 34px; }
#page[data-shape="notepad"] .controls { margin: 0 0 .2cqh; gap: 10px; flex-wrap: nowrap; }
#page[data-shape="notepad"] .controls .tab .lab { padding-left: 10px; }
#page[data-shape="notepad"] .controls .tab { height: 44px; }
#page[data-shape="notepad"] .controls .tab button { min-width: 38px; height: 40px; padding: 0 4px; }
#page[data-shape="notepad"] .ribbon { height: 44px; padding: 0 24px 0 12px; }
#page[data-shape="notepad"] .links { gap: 14px; flex-wrap: nowrap; }
#page[data-shape="notepad"] .link { min-height: 38px; font-size: 17px; white-space: nowrap; }
#page[data-shape="notepad"] .stage-room { flex-basis: 30%; }
#page[data-shape="notepad"] #heading { min-height: 38px; box-sizing: border-box; width: 100%; }

/* a phone on its side: the page is short, so the words stand on its left and the tools on its right */
#page[data-shape="short"] #reading { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: repeat(5, auto) 1fr; column-gap: 3cqw; align-content: start; padding: 3cqh 3cqw 2cqh; text-align: left; justify-items: start; }
#page[data-shape="short"] #reading > * { grid-column: 1; }
#page[data-shape="short"] #reading > #work, #page[data-shape="short"] #reading > #after { grid-column: 2; grid-row: 1 / -1; margin-top: 0; align-self: center; }
#page[data-shape="short"] .kicker { display: none; }
#page[data-shape="short"] #heading { margin: 0 0 .6cqh; font-size: 21px; }
#page[data-shape="short"] #lines p, #page[data-shape="short"] .instruction, #page[data-shape="short"] .numbers { font-size: 16.5px; }
#page[data-shape="short"] .equation { margin-top: .8cqh; font-size: 19px; }
#page[data-shape="short"] #work hr { display: none; }
#page[data-shape="short"] .numbers { text-align: center; }
#page[data-shape="short"] .paper.mini { height: 30px; }
#page[data-shape="short"] .controls { flex-direction: column; gap: 6px; margin: 0 0 2px; }
#page[data-shape="short"] .controls .tab { height: 42px; }
#page[data-shape="short"] .controls .tab .lab { padding-left: 8px; font-size: 18px; }
#page[data-shape="short"] .controls .tab button { min-width: 38px; height: 40px; padding: 0 4px; }
#page[data-shape="short"] .ribbon { height: 42px; padding: 0 24px 0 12px; font-size: 17px; }
#page[data-shape="short"] .links { flex-direction: column; gap: 0; }
#page[data-shape="short"] .link { min-height: 34px; font-size: 17px; }
#page[data-shape="short"] .stage-room { flex: 0 0 34%; }
#page[data-shape="short"] .sheet { margin: 0 2cqw 2cqh; padding: 1cqh 3cqw 0; }
#page[data-shape="short"] .sheet h2 { margin: 0; }
#page[data-shape="short"] .said { margin: 0; }

/* the world's names, over the right page: words only, never a control */
#tags { position: fixed; inset: 0; z-index: 3; pointer-events: none; }
.tag { position: absolute; left: 0; top: 0; padding: 3px 10px; border-radius: 13px; background: #203d34; color: #fbf6e8; font: 600 16px/1.2 var(--sans); white-space: nowrap; box-shadow: 0 4px 10px -6px #000; }
.tag[hidden] { display: none; }
.tag.post { padding: 1px 6px; border-radius: 6px; background: #fffdf6; color: var(--ink); box-shadow: 0 0 0 1.5px var(--ink); font: 700 16px/1.2 var(--sans); }
.tag.lantern { background: #8f2f2a; }
.tag.road { background: #fffdf6; color: var(--ink); box-shadow: 0 0 0 1.5px var(--ink); font: 400 18px/1.2 var(--hand); }
body[data-state="help"] .tag.post { opacity: .55; }
/* the ghost hand: its fingertip on the lantern, it drags a short way along the road and lifts, again and again */
.ghost { position: absolute; left: -14px; top: -4px; filter: drop-shadow(0 4px 6px #0007); animation: ghost 2.2s ease-in-out infinite; }
.ghost[hidden] { display: none; }
@keyframes ghost {
  0%, 12% { translate: 0 0; opacity: 0; }
  22% { translate: 0 0; opacity: 1; }
  72% { translate: var(--dx) var(--dy); opacity: 1; }
  88%, 100% { translate: var(--dx) var(--dy); opacity: 0; }
}

/* without WebGL: the two pages flat, the left page's HTML in its place */
body[data-mode="flat"] #page { position: relative; transform: none !important; width: 100% !important; height: auto !important; min-height: 520px; container-type: inline-size; }
body[data-mode="flat"] #reading, body[data-mode="flat"] #help { position: relative; min-height: 520px; }
body[data-mode="flat"] .stage-room { flex: 0 0 24px; }
@media (prefers-reduced-motion: reduce) { .ghost { animation: none; translate: calc(var(--dx) / 2) calc(var(--dy) / 2); } }
