/* The controls of the reader, and the book as pages. The words themselves
   are in styles.css; this file is what scripts add around them. */

/* ---------- Drawing on the book ---------- */

.js .window { position: relative; }
.ink { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.ink polyline { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.ink .fading { opacity: 0; transition: opacity 0.8s; }

/* With the pen in hand a sideways stroke draws. In a scroll, an up-and-down
   one still scrolls the page; as pages there is nothing to scroll. */
.stage.pen { cursor: crosshair; touch-action: pan-y pinch-zoom; }
.paged .stage.pen { touch-action: none; }
.stage.pen .book { user-select: none; -webkit-user-select: none; }
.stage.pen .mk { cursor: crosshair; }

/* ---------- The book as pages (html.paged) ---------- */

html.paged, html.paged body { height: 100%; overflow: hidden; }
html.paged body {
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh; height: 100dvh;
  overscroll-behavior: none;
}
html.paged:not(.ready) main { visibility: hidden; }

.paged .reader {
  position: relative; min-height: 0;
  margin: 0 env(safe-area-inset-right, 0px) 0 env(safe-area-inset-left, 0px);
}
.paged .stage {
  position: absolute; inset: 0;
  display: grid; justify-content: center;
  overflow: hidden;
  touch-action: pan-y pinch-zoom;
}
.paged .window { width: var(--window-w, 100vw); height: 100%; overflow: hidden; }
.paged .strip { position: absolute; inset: 0; }

.paged .book {
  position: absolute; left: 0; top: var(--top, 24px);
  width: 100%; height: var(--page-h, 70vh);
  margin: 0; padding: 0 var(--pad, 24px);
  column-width: var(--page-w, 300px);
  column-gap: calc(2 * var(--pad, 24px));
  column-fill: auto;
  outline: none;
}
.paged .book > section { max-width: none; }

/* One page at a time has room for one button under the opening words; the
   way to a file of your own is in the sentence above it. */
.paged .stage:not(.spread) .first-do a.btn { display: none; }

/* The page number sits under each page. */
.folio {
  position: absolute; bottom: 0;
  display: grid; place-items: center;
  width: var(--cell); height: 40px;
  font: 800 12px/1 var(--sans);
  letter-spacing: 0.08em; font-variant-numeric: tabular-nums;
}
.folios .folio:first-child { color: transparent; }

/* Two pages: a hard rule down the gutter, which a turning leaf swings round. */
.spread .window::after {
  content: "";
  position: absolute; left: 50%; top: var(--top); bottom: 40px; z-index: 2;
  width: 2px; margin-left: -1px;
  background: var(--ink);
}

.edge {
  position: absolute; top: 0; bottom: 40px; z-index: 3;
  display: grid; place-items: center;
  width: max(var(--pad, 24px), 22px);
  padding: 0; border: 0; background: none; color: var(--ink);
  opacity: 0.55;
  cursor: pointer;
  touch-action: none;
}
.edge.prev { left: 0; }
.edge.next { right: 0; }
.edge svg { width: 12px; height: 24px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: square; }
.edge:focus-visible { opacity: 1; }
.edge:disabled { visibility: hidden; }
html:not(.paged) .edge, html:not(.paged) .folios { display: none; }

/* ---------- A page turning (js/turn.js) ---------- */

/* For the third of a second a turn takes, pictures of the pages involved
   stand over the book, and one leaf swings round the spine. The tones on
   it are flat, like everything here: the leaf darkens as it turns away
   from the light, and the page under it is in its shade until it has gone.
   On the dark papers the tone is light instead, or it would not show. */
.turn {
  position: absolute; inset: 0; z-index: 1;
  perspective: 2600px; perspective-origin: 50% 42%;
  pointer-events: none;
}
.turn:empty { display: none; }
.face, .leaf, .cast { position: absolute; top: 0; bottom: 0; left: 0; width: var(--cell); }
.face { overflow: hidden; background: var(--paper); }
.face .folio { left: 0; }
.leaf { transform-style: preserve-3d; will-change: transform; }
.leaf .face {
  outline: 2px solid var(--ink); outline-offset: -2px;
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
}
.leaf .back { transform: rotateY(180deg); }
.shade { position: absolute; inset: 0; background: var(--tone); opacity: var(--shade, 0); }
.cast { background: var(--tone); opacity: 0; }

/* ---------- The band at the foot ---------- */

/* As pages it is a bar under the book: where you are, the controls for
   listening, and the dot. In a scroll (below) the bar itself is not there:
   the dot floats in the corner, a message is a note beside it, and the bar
   comes back only while the book is being read aloud. */
.band {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  height: var(--band);
  padding: 0 max(14px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(14px, env(safe-area-inset-left, 0px));
  border-top: var(--rule) solid var(--ink);
  background: var(--paper);
}
.where {
  flex: 1; min-width: 0; margin: 0;
  font: 800 12px/1.25 var(--sans);
  letter-spacing: 0.1em; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.where.said { font-weight: 600; font-size: 13px; letter-spacing: 0; text-transform: none; white-space: normal; }
.transport { display: flex; gap: 6px; }
.transport .btn { min-height: 40px; }

html:not(.paged) .band {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 18;
  border-top-color: transparent; background: none;
  pointer-events: none;
}
html:not(.paged) .band > * { pointer-events: auto; }
html:not(.paged) .where { display: none; }
html:not(.paged) .where.said {
  display: block; flex: 0 1 auto;
  padding: 10px 12px;
  background: var(--ink); color: var(--paper);
}
html:not(.paged).listening body { padding-bottom: var(--band); }
html:not(.paged).listening .band { border-top-color: var(--ink); background: var(--paper); pointer-events: auto; }
html:not(.paged).listening .where.said { position: absolute; left: 0; right: 0; bottom: 100%; }

/* The tool for scroll or pages, typeface, size and paper. A dot until it
   is pressed. */
.tool { position: relative; margin-left: auto; }
.dot { display: grid; place-items: center; width: 44px; height: 44px; margin-right: -12px; padding: 0; border: 0; background: none; cursor: pointer; }
.dot span { width: 16px; height: 16px; border-radius: 50%; background: var(--ink); outline: 3px solid var(--paper); }
.dot[aria-expanded="true"] span { background: var(--accent); }

.tool-panel {
  position: absolute; right: -2px; bottom: calc(100% + 8px); z-index: 25;
  width: min(300px, 100vw - 24px);
  padding: 12px 12px 2px;
  border: var(--rule) solid var(--ink);
  background: var(--paper);
}
.tool-panel fieldset { margin: 0 0 12px; padding: 0; border: 0; }
.tool-panel legend { margin-bottom: 6px; padding: 0; font-weight: 800; font-size: 11px; letter-spacing: 0.11em; text-transform: uppercase; }
.seg { display: flex; }
.seg > * { position: relative; flex: 1; margin-left: -2px; }
.seg > :first-child { margin-left: 0; }
.seg input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.seg label > span, .seg button, .seg output {
  display: grid; place-items: center;
  min-height: 44px;
  border: 2px solid var(--ink); border-radius: 0;
  background: var(--paper); color: var(--ink);
  font: 700 14px/1 var(--sans);
}
.seg button { cursor: pointer; }
.seg button:disabled { color: var(--soft); cursor: default; }
.seg input:checked + span { background: var(--ink); color: var(--paper); }
.seg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; z-index: 1; }
.a-small { font-size: 13px; }
.a-large { font-size: 21px; }

/* Each paper is shown in its own colours; the chosen one gets a bar. */
.papers .sw { position: relative; font-size: 12px; }
.papers .sw-paper, .papers input:checked + .sw-paper { background: #F6F2E9; color: #0B0B0B; }
.papers .sw-white, .papers input:checked + .sw-white { background: #FFFFFF; color: #0B0B0B; }
.papers .sw-dusk, .papers input:checked + .sw-dusk { background: #26272A; color: #E4E0D6; }
.papers .sw-black, .papers input:checked + .sw-black { background: #000000; color: #EFEBE2; }
.papers input:checked + .sw::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 7px; background: #27408B; }
.papers input:checked + .sw-dusk::after, .papers input:checked + .sw-black::after { background: #A3B8FF; }

/* ---------- Focus view (js/focus.js) ---------- */

/* A quiet canvas over the book with nothing on it but the sentence being
   said. Words said are in full ink, words to come are pale, and the word
   being said has the rule under it. */
.focus {
  position: fixed; z-index: 17;
  top: var(--bar); right: 0; bottom: var(--band); left: 0;
  display: grid; align-content: center; align-content: safe center;
  padding: 28px max(24px, 9vw);
  overflow-y: auto;
  background: var(--paper);
  cursor: pointer; touch-action: pan-y;
  -webkit-user-select: none; user-select: none;
}
.focus-where {
  margin: 0 0 1.4em;
  font: 800 11px/1.3 var(--sans);
  letter-spacing: 0.11em; text-transform: uppercase;
}
.focus-line {
  max-width: 24em; margin: 0;
  color: var(--quiet);
  font-family: var(--face); line-height: 1.24;
  text-wrap: pretty;
}
.focus-line.whole, .focus-line .said, .focus-line .now { color: var(--ink); }
.focus-line .now .word { text-decoration: underline var(--accent) 0.07em; text-underline-offset: 0.17em; }
@media (prefers-reduced-motion: no-preference) {
  .focus-line { animation: lift 0.26s ease-out; }
  .focus-line span { transition: color 0.12s linear; }
}
@keyframes lift { from { opacity: 0; transform: translateY(0.3em); } }
@media (min-width: 900px) {
  html.notes-open .focus { right: 400px; }
}

/* ---------- The notebook ---------- */

.notebook {
  position: fixed; z-index: 20;
  top: var(--bar); right: 0; bottom: var(--band);
  display: flex; flex-direction: column;
  width: min(400px, 100%);
  border-left: var(--rule) solid var(--ink);
  background: var(--paper);
}
html:not(.paged) .notebook { bottom: 0; }
html:not(.paged).listening .notebook { bottom: var(--band); }
.notebook-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  border-bottom: var(--rule) solid var(--ink);
}
.notebook h2 { margin: 0; font: 900 24px/1 var(--sans); letter-spacing: -0.035em; }
.notebook h2:focus { outline: none; }
.notebook-empty { margin: 0; padding: 16px 14px; font: 17px/1.45 var(--serif); }

.entries { flex: 1; margin: 0; padding: 0; overflow: auto; list-style: none; }
.entries li { display: flex; border-bottom: 2px solid var(--ink); }
.entry-go {
  flex: 1; min-width: 0;
  padding: 12px 14px 13px;
  border: 0; background: none; color: inherit;
  font: inherit; text-align: left;
  cursor: pointer;
}
.entry-kind { display: block; margin-bottom: 5px; font: 800 11px/1.3 var(--sans); letter-spacing: 0.11em; text-transform: uppercase; }
.entry-by { margin-left: 8px; padding: 1px 5px; border: 2px solid var(--agent); color: var(--agent); }
.entry-quote { display: block; font: 17px/1.4 var(--serif); }
.entry-note { display: block; margin-top: 7px; padding-left: 9px; border-left: 3px solid var(--agent); font: 14px/1.4 var(--sans); }
/* The page's own marks: a note in its hand, and whose it is in ink. */
.entry-by.page { border-color: var(--accent); color: var(--accent); }
.entry-note.hand { border-left-color: var(--accent); color: var(--accent); font: 17px/1.3 var(--hand); }
.entry-drop {
  min-width: 44px; padding: 0 14px;
  border: 0; border-left: 2px solid var(--ink); background: none; color: inherit;
  font: 800 11px/1 var(--sans); letter-spacing: 0.08em; text-transform: uppercase;
  cursor: pointer;
}

.notebook-foot { padding: 12px 14px 14px; border-top: var(--rule) solid var(--ink); }
.notebook-foot p { margin: 0; font-size: 12px; color: var(--soft); }
.notebook-foot .btn { width: 100%; margin-bottom: 10px; }

/* On a wide screen the notebook is a column beside the book, which is set
   again in the room that is left. On a narrow one it lies over the book. */
@media (min-width: 900px) {
  html.notes-open .reader { margin-right: calc(400px + env(safe-area-inset-right, 0px)); }
}

/* ---------- The bar for selected words ---------- */

.selbar { position: fixed; z-index: 30; display: flex; gap: 2px; padding: 2px; background: var(--paper); border: 2px solid var(--ink); }
.selbar.docked { left: 50%; bottom: calc(var(--band) + 10px); transform: translateX(-50%); }
html:not(.paged):not(.listening) .selbar.docked { bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
.selbar button {
  min-height: 44px; padding: 0 14px;
  border: 0; border-radius: 0;
  background: var(--ink); color: var(--paper);
  font: 800 13px/1 var(--sans); letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap;
  cursor: pointer;
}
.selbar button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }

/* ---------- Under a mouse ---------- */

/* Only where a pointer can hover: on a touch screen a hover sticks to the
   last thing tapped and makes it look pressed. */
@media (hover: hover) {
  .btn:hover, .entry-drop:hover, .contents a:hover { background: var(--ink); color: var(--paper); }
  .btn.solid:hover { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
  .btn:hover .count { background: var(--paper); color: var(--ink); }
  .contents a:hover::before { color: inherit; }
  .edge:hover { opacity: 1; }
  .dot:hover span { background: var(--accent); }
  .entry-go:hover .entry-quote { text-decoration: underline; }
  .selbar button:hover { background: var(--accent); color: var(--on-accent); }
}

/* ---------- Small screens and print ---------- */

@media (max-width: 480px) {
  .wide { display: none; }
  .narrow { display: inline; }
  .bar { gap: 8px; }
  .bar-tools { gap: 6px; }
  .bar .btn { padding: 0 9px; font-size: 12px; letter-spacing: 0.04em; }
  .notebook { border-left: 0; }
  .transport .btn { padding: 0 9px; font-size: 12px; letter-spacing: 0.04em; }
  html.listening .where:not(.said) { display: none; }
  html.listening .where.said { position: absolute; left: 0; right: 0; bottom: 100%; padding: 8px 14px; background: var(--ink); color: var(--paper); }
  /* In a scroll the dot sits in the margin, clear of the words. */
  html:not(.paged) .band { padding-right: 2px; }
  html:not(.paged) .dot { justify-items: end; margin-right: 0; padding-right: 2px; }
  html:not(.paged) .tool-panel { right: 8px; }
}
@media (max-width: 379px) {
  .wordmark { display: none; }
}

/* A phone on its side has little height: as pages, the chapter number sits
   beside its title, not above it. */
@media (max-height: 480px) {
  .paged .chapter:not(.plain) h2::before { display: inline; margin-right: 0.3em; font-size: 1em; }
}

@media print {
  .bar-tools, .band, .edge, .selbar, .notebook, .folios, .skip, .turn { display: none !important; }
  .bar { position: static; }
  html.paged, html.paged body { display: block; height: auto; overflow: visible; }
  .paged .reader, .paged .stage, .paged .window, .paged .strip, .paged .book { position: static; height: auto; overflow: visible; transform: none !important; columns: auto; }
}
