/*
 * The table book's look: the founder's reference (docs/design/table-book-v9.html) section by
 * section, and the parts it did not need: the shelf's still picture that paints before three.js,
 * and the flat book for a browser without WebGL. Targets are 44 px or more; reduced motion stills
 * every transition and animation.
 */
:root {
  --paper: #f8f5ec; --page: #fffdf6; --ink: #203d34; --soft: #56695f; --rule: #d9d0b8; --gold: #b7975e; --ox: #8f2f2a; --leaf: #2c6450;
  --serif: "Fraunces", "Iowan Old Style", "Palatino Linotype", Georgia, serif; --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif; --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; overflow: hidden; background: #16231f; color: var(--ink); font: 400 16px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid #f2c14e; outline-offset: 3px; }
[hidden] { display: none !important; }

/* the table fills the window; everything else lies on it or floats over it */
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; transition: opacity .22s; }
#gl.cut { opacity: 0; }

.top { position: fixed; z-index: 6; inset: 0 0 auto 0; display: flex; align-items: center; gap: 10px; padding: 10px 14px; color: #f6efdc; pointer-events: none; }
.top > * { pointer-events: auto; }
.top img { width: 32px; height: 32px; border-radius: 50%; background: #fbf6e7; }
.top b { font: 500 18px/1 var(--serif); }
#crumb { margin-right: auto; padding-left: 10px; border-left: 1px solid rgb(246 239 220 / .35); font: 500 15px/1.2 var(--serif); opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { flex: none; white-space: nowrap; min-height: 44px; padding: 0 14px; border: 1px solid rgb(246 239 220 / .4); border-radius: 22px; background: rgb(18 30 26 / .55); color: #f6efdc; font: 500 14px/1 var(--sans); backdrop-filter: blur(6px); }
.pill[aria-pressed="true"] { background: #f6efdc; color: var(--ink); }
#about { position: relative; }
#about summary { list-style: none; display: grid; place-items: center; width: 44px; height: 44px; border: 1px solid rgb(246 239 220 / .4); border-radius: 50%; background: rgb(18 30 26 / .55); font: 600 15px/1 var(--serif); cursor: pointer; }
#about summary::-webkit-details-marker { display: none; }
#about div { position: absolute; right: 0; top: 52px; width: min(360px, 88vw); padding: 14px 16px; border-radius: 12px; background: var(--ink); color: #dbe6df; font-size: 13.5px; box-shadow: 0 20px 40px -18px #000; }
#about h2 { margin: 0 0 4px; font: 500 17px/1.2 var(--serif); color: #fff; }
#about p { margin: 0 0 10px; }
.log { padding: 8px 10px; min-height: 40px; border-radius: 6px; background: #17302a; font: 500 11.5px/1.6 var(--mono); color: #cfe0d6; white-space: pre-wrap; }

/* the shelf: two closed books on the table. Their names float under them. */
#shelfUI h1 { position: fixed; z-index: 4; left: 0; right: 0; top: 64px; margin: 0; padding: 0 16px; text-align: center; color: #f6efdc; font: 500 clamp(22px, 5.6vw, 36px)/1.1 var(--serif); letter-spacing: -.02em; text-shadow: 0 2px 18px #000a; }
.pick { position: fixed; z-index: 4; left: 0; top: 0; min-height: 48px; padding: 8px 16px; border: 1px solid rgb(246 239 220 / .45); border-radius: 26px; background: rgb(18 30 26 / .7); color: #f6efdc; text-align: center; font: 500 12px/1.3 var(--mono); backdrop-filter: blur(6px); translate: -50% 0; white-space: nowrap; }
.pick strong { display: block; font: 500 17px/1.2 var(--serif); }

/* the live sketch: a sheet of ruled paper lying on the left page, drawn in pencil. It is laid into the picture
   corner by corner, so it tilts with the book. */
#sketch { position: fixed; z-index: 2; left: 0; top: 0; transform-origin: 0 0; pointer-events: none; border-radius: 5px; background: #fffef8; background-image: linear-gradient(90deg, transparent 27px, #e9b3ad 27px 28.5px, transparent 28.5px), repeating-linear-gradient(#fffef8 0 21px, #d5e0ea 21px 22px); box-shadow: 0 0 0 1.5px #3b3a3655, 2px 5px 0 -1px #0002; transition: opacity .5s; }
#sketch.away { opacity: 0; }
#sketch { display: flex; flex-direction: column; }
#sketch h2 { flex: none; margin: 0; padding: 7px 12px 4px 38px; font: 500 15.5px/1.25 var(--serif); color: var(--ink); }
#sketch h2 small { margin-right: 7px; padding: 1px 7px; border-radius: 10px; background: var(--ox); color: #fbf6e7; font: 600 10px/1.5 var(--sans); vertical-align: 2px; }
.paper { display: block; flex: 1; min-height: 0; width: 100%; font-family: "Bradley Hand", "Segoe Print", "Marker Felt", "Chalkboard SE", "Comic Sans MS", cursive; }
.paper .pencil { fill: none; stroke: #3b3a36; stroke-width: 2.2; stroke-linecap: round; stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw .7s ease-out forwards; }
.paper .ink { opacity: 0; animation: ink .45s ease-out forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes ink { to { opacity: 1; } }
.paper.still .pencil:not(.fresh) { animation: none; stroke-dashoffset: 0; }
.paper.still .ink:not(.fresh) { animation: none; opacity: 1; }
.paper .pop { transform-box: fill-box; transform-origin: center; animation: ink .3s ease-out forwards, popin .45s cubic-bezier(.2,1.6,.4,1) backwards; }
@keyframes popin { from { transform: scale(.2); } }

/* what a dragon says: a balloon that floats over the speaker's head */
#balloon { position: fixed; z-index: 5; left: 0; top: 0; width: max-content; max-width: min(340px, calc(100vw - 20px)); padding: 9px 14px 11px; border-radius: 16px; background: #fffdf6; box-shadow: 0 0 0 2px var(--ink), 0 12px 26px -12px #000c; font: 400 16px/1.38 var(--serif); cursor: pointer; }
#balloon::after { content: ""; position: absolute; left: var(--tail, 40px); bottom: -9px; width: 16px; height: 16px; margin-left: -8px; background: inherit; box-shadow: 2px 2px 0 0 var(--ink); transform: rotate(45deg); }
#balloon b { display: block; font: 600 12px/1.4 var(--sans); color: var(--ox); }
#balloon[data-who="nell"] b { color: #b3261e; }
#balloon[data-who="pip"] b { color: #b85c0a; }
#balloon.pop { animation: pop .4s cubic-bezier(.2,.8,.2,1); }
@keyframes pop { from { scale: .9; opacity: .3; } }

/* the tools: paper tabs that hang under the front edge of the right page. The numbers sit at its right end. */
#dock { position: fixed; z-index: 4; left: 0; top: 0; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; width: max-content; max-width: calc(100vw - 16px); }
.tab { display: inline-flex; align-items: center; height: 46px; border-radius: 4px 4px 14px 14px; background: #fffdf6; box-shadow: 0 0 0 1.5px var(--ink), 0 8px 14px -8px #000c; overflow: hidden; }
.tab .lab { padding: 0 9px 0 12px; font: 600 12px/1 var(--sans); color: var(--soft); }
.tab button { min-width: 44px; height: 46px; padding: 0 12px; border: 0; border-left: 1px solid var(--rule); background: transparent; font: 600 15px/1 var(--sans); color: var(--ink); }
.tab button:first-child { border-left: 0; }
.tab button[aria-pressed="true"] { background: var(--ink); color: #fbf6e7; }
.tab output { min-width: 30px; padding-right: 8px; text-align: center; font: 500 15px/1 var(--mono); }
.go { height: 46px; padding: 0 20px; border: 0; border-radius: 4px 4px 14px 14px; background: var(--ink); color: #fbf6e7; font: 600 15px/1 var(--sans); box-shadow: 0 0 0 1.5px #0b1a15, 0 8px 14px -8px #000c; }
.go:disabled { opacity: .5; cursor: default; }
.round { width: 44px; height: 44px; border: 0; border-radius: 50%; background: rgb(18 30 26 / .6); color: #f6efdc; font: 600 16px/1 var(--serif); box-shadow: 0 0 0 1px rgb(246 239 220 / .45); backdrop-filter: blur(6px); }
/* A fixed width, so the tools do not shift under a finger when the status changes (the reference's did). */
#status { min-width: 25ch; text-align: center; margin: 0 0 0 4px; padding: 6px 12px; border-radius: 14px; background: rgb(18 30 26 / .6); color: #f6efdc; font: 500 13px/1.3 var(--mono); white-space: nowrap; backdrop-filter: blur(6px); }
.tools { display: contents; }
#dock { transition: opacity .35s; }
#dock.off { opacity: 0; pointer-events: none; }
#dock.turn .go:not(:disabled) { animation: turn 1.4s ease-in-out infinite; }
@keyframes turn { 50% { box-shadow: 0 0 0 7px rgb(242 193 78 / .55); } }
#keeps { position: fixed; z-index: 4; left: 50%; bottom: 10px; translate: -50% 0; width: min(620px, calc(100vw - 16px)); }
.keep { padding: 12px 14px; border-radius: 12px; background: #fffaf0; box-shadow: 0 0 0 1.5px var(--ink), 0 14px 30px -14px #000; }
.keep label { display: block; margin: 0 0 6px; font: 500 15px/1.35 var(--serif); }
.keep-row { display: flex; gap: 8px; align-items: stretch; }
.keep-row .go { flex: none; }
.keep input { flex: 1; min-width: 0; width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid var(--rule); border-radius: 8px; background: #fff; font: 400 16px/1 var(--serif); }
.keep .line { margin: 6px 0 0; font: italic 400 15px/1.4 var(--serif); color: var(--ox); }
@media (max-width: 560px) { .top b, #crumb { display: none; } .top img { margin-right: auto; } .top { gap: 8px; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
/* With no animation the pencil and ink must start drawn: the reference's sketch was blank under reduced motion. */
@media (prefers-reduced-motion: reduce) { .paper .pencil { stroke-dashoffset: 0; } .paper .ink { opacity: 1; } }

/* Before the 3D is ready, and without WebGL: the shelf is a still picture of the two covers on wood. */
body[data-mode="still"] #gl,
body[data-mode="flat"] #gl { display: none; }
body:not([data-mode="3d"]) { overflow: auto; background: #3a2a1d url("/primer/showcase/table-book/wood.webp") center / 480px repeat; }
body:not([data-mode="3d"]) #shelfUI h1 { position: static; padding: 76px 16px 0; }
/* Once the 3D table draws, the covers are its own books and the names float under them. */
body[data-mode="3d"] .shelf-still, body[data-mode="3d"] .still-book { display: contents; }
body[data-mode="3d"] .still-book img { display: none; }
body:not([data-mode="3d"]) .shelf-still { display: flex; flex-wrap: wrap; justify-content: center; gap: clamp(20px, 6vw, 72px); padding: 28px 16px 40px; }
.still-book { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.still-book img { display: block; width: min(300px, 40vw); min-width: 150px; height: auto; border-radius: 4px 10px 10px 4px; box-shadow: 0 0 0 6px #1c2c4c, 18px 22px 30px -12px #000c; }
.still-book[data-book="energy"] img { box-shadow: 0 0 0 6px #742a25, 18px 22px 30px -12px #000c; }
/* `?cover=1` (main.js coverOnly, the homepage's cards): one book, closed on its own mat, never the shelf of two. The mat
   (`.book-mat`) and the hardback (`.real-book`) are /primer/showcase/book-mats.css, the homepage's own (round 8). */
body[data-cover="ribbon"] .still-book[data-book="energy"], body[data-cover="energy"] .still-book[data-book="ribbon"] { display: none !important; }
body[data-cover]:not([data-mode="3d"]) .shelf-still { box-sizing: border-box; width: min(760px, calc(100vw - 32px)); aspect-ratio: 1200 / 816; align-items: center; margin: 24px auto 40px; padding: 4% 16px; }
body[data-cover]:not([data-mode="3d"]) .still-book .real-book { height: calc(min(760px, 100vw - 32px) * .42); aspect-ratio: 3 / 4; cursor: pointer; }
/* In 3D the book and its mat are the stage's own (stage.js `single`): the still mat's motif and the hardback go away. */
body[data-mode="3d"] .shelf-still.book-mat::after, body[data-mode="3d"] .still-book .real-book { display: none; }
body[data-cover]:not([data-mode="3d"]) .still-book .real-book img { width: 100%; min-width: 0; height: 100%; box-shadow: none; }
body:not([data-mode="3d"]) .pick { position: static; translate: none; transform: none !important; }
@media (max-width: 560px) { body:not([data-mode="3d"]) .shelf-still { flex-direction: column; align-items: center; } .still-book img { width: min(240px, 62vw); } }

/* The flat book: two paper pages side by side (stacked on a phone), the HTML lying on them. */
#flat { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0; width: min(1240px, calc(100vw - 24px)); margin: 72px auto 12px; padding: 14px; border-radius: 10px; background: var(--ink); box-shadow: 0 30px 50px -24px #000; }
#flat[hidden] { display: none; }
.flat-page { position: relative; min-height: 340px; padding: 14px; background: #fbf6e8; }
.flat-left { border-radius: 6px 0 0 6px; box-shadow: inset -12px 0 18px -14px #0006; display: flex; flex-direction: column; gap: 12px; }
.flat-right { border-radius: 0 6px 6px 0; box-shadow: inset 12px 0 18px -14px #0006; display: grid; place-items: center; }
.flat-world { width: 100%; height: auto; }
.flat-world .sails.spinning { transform-box: fill-box; animation: spin 1.2s linear infinite; }
@keyframes spin { to { rotate: 360deg; } }
body[data-mode="flat"] #sketch { position: relative; transform: none !important; width: 100% !important; height: auto !important; min-height: 230px; }
body[data-mode="flat"] #balloon { position: relative; transform: none !important; width: auto; max-width: 100%; }
body[data-mode="flat"] .paper { flex: none; height: auto; }
body[data-mode="flat"] #dock { position: relative; transform: none !important; margin: 0 auto 12px; }
body[data-mode="flat"] #dock.off { opacity: 1; pointer-events: auto; }
body[data-mode="flat"] #keeps { position: relative; left: auto; bottom: auto; translate: none; margin: 0 auto 16px; }
@media (max-width: 760px) { #flat { grid-template-columns: minmax(0, 1fr); } .flat-left, .flat-right { border-radius: 6px; } }
/* The picks wait for the table (main.js begin()): off and dimmed, and one line says why, until the stage or the flat book is ready. */
.pick:disabled { opacity: .55; cursor: progress; }
.shelf-wait { margin: 4px 0 0; text-align: center; font: 500 13px/1.3 var(--mono); color: #f6efdc; }
body[data-ready="true"] .shelf-wait, body[data-ready="failed"] .shelf-wait { display: none; }
/* Neither the table nor the flat book loaded (main.js begin()): say so, a Try again, and the two public books. */
.shelf-failed { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 8px auto 0; max-width: 34em; padding: 0 16px; text-align: center; font: 500 15px/1.45 var(--sans); color: #f6efdc; }
.shelf-failed[hidden] { display: none; }
.shelf-failed p { margin: 0; }
.shelf-failed a { display: inline-flex; align-items: center; min-height: 44px; color: #ffd98a; }
/* Inside the kids desk's Book (main.js `desk`): the desk's cream around the book, and none of this page's own chrome. */
body[data-desk] { background: #F6F1E7; }
body[data-desk] .top, body[data-desk] #shelfTitle, body[data-desk] .shelf-still { display: none; }
