/*
 * Tiny Liny
 *
 * The page is the whole design. Paper is a cool proof-sheet white, ink is
 * blue-black, and the companion is made of the same ink as the words. The
 * one colour, proofreader's blue pencil, is kept for the controls.
 *
 * --paper must be a flat colour. The companion hides a dot he has taken by
 * painting over it in exactly this colour.
 */

@font-face {
  font-family: "Literata";
  src: url("../fonts/literata-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: block;
}
@font-face {
  font-family: "Literata";
  src: url("../fonts/literata-latin-400-italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: block;
}

:root {
  --paper: #f3f5f2;
  --ink: #1b1e26;
  --pencil: #2450c4;
  --quiet: #676d7a;
  --rule: #d5d9d4;
  --panel: #fbfcfa;

  /* Set from JavaScript; these are only fallbacks. */
  --fs: 20px;
  --lh: 36px;

  --serif: "Literata", "Iowan Old Style", Georgia, serif;
  color-scheme: light dark;
}

/* The reader can choose the paper. With no choice made, it follows the device. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --paper: #14161a;
    --ink: #d6d9df;
    --pencil: #8eabff;
    --quiet: #8b909b;
    --rule: #2b2f36;
    --panel: #1b1e23;
  }
}
:root[data-theme="dark"] {
  --paper: #14161a;
  --ink: #d6d9df;
  --pencil: #8eabff;
  --quiet: #8b909b;
  --rule: #2b2f36;
  --panel: #1b1e23;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="sepia"] {
  --paper: #efe5cf;
  --ink: #33291b;
  --pencil: #8c4a1e;
  --quiet: #7b6b55;
  --rule: #d8cbae;
  --panel: #f6eedc;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
  overflow: hidden;            /* the page never scrolls; only the menu's lists do */
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:focus-visible, #page:focus-visible, input:focus-visible {
  outline: 2px solid var(--pencil);
  outline-offset: 3px;
}
[hidden] { display: none !important; }

/* ---------- frame ---------- */

#app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

#bar, #foot {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  /* Lined up with the text column (--col is set from JavaScript), never closer
     to the edge than 16px or the device's safe area. */
  padding: 0 max(16px, env(safe-area-inset-right), calc((100% - var(--col, 100%)) / 2))
           0 max(16px, env(safe-area-inset-left), calc((100% - var(--col, 100%)) / 2));
  font-size: 15px;
  line-height: 1;
  color: var(--quiet);
}
#bar { height: 46px; padding-top: env(safe-area-inset-top); box-sizing: content-box; }
#foot { height: 48px; padding-bottom: env(safe-area-inset-bottom); box-sizing: content-box; }

#open-menu { justify-self: start; padding: 10px 0; }
.on-shelf #open-menu, .on-shelf #foot > * { visibility: hidden; }
#open-menu:hover, #close-menu:hover, .quiet:hover { color: var(--ink); }

#running-head, #folio { margin: 0; line-height: 1.5; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#running-head { font-style: italic; }
#folio { font-variant-numeric: tabular-nums; }

#prev, #next { font-size: 30px; line-height: 1; width: 56px; height: 44px; color: var(--quiet); }
#prev { justify-self: start; text-align: left; }
#next { justify-self: end; text-align: right; }
#prev:hover, #next:hover { color: var(--ink); }
#prev:disabled, #next:disabled { opacity: .25; cursor: default; }

/* ---------- the page ---------- */

#stage { position: relative; overflow: hidden; }

#page {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  cursor: default;
}

#ink { position: absolute; left: 0; top: 0; pointer-events: none; }

/*
 * One chapter is laid out as a row of columns, one column per page, and the
 * row is slid sideways to turn the page. Left, top, width, height and the
 * column gap are set from JavaScript so every page holds whole lines.
 */
#flow {
  position: absolute;
  column-fill: auto;
  font-family: var(--serif);
  font-size: var(--fs);
  line-height: var(--lh);
  text-align: left;
  hyphens: manual;
  -webkit-hyphens: manual;
  /* The terrain map knows single letters, so letters must not be fused. */
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "clig" 0, "calt" 0;
  font-kerning: normal;
  font-synthesis: none;
  orphans: 2;
  widows: 2;
}

#flow p { margin: 0; text-indent: 1.4em; }
#flow .chapter-head + p,
#flow blockquote p,
#flow td p { text-indent: 0; }

#flow .chapter-head {
  break-inside: avoid;
  overflow: hidden;
  text-align: center;
}
#flow .chapter-head .numeral {
  margin: 0;
  text-indent: 0;
  color: var(--quiet);
  letter-spacing: .08em;
}
#flow .chapter-head h1 {
  margin: 0;
  font-size: 1.45em;
  font-weight: 400;
  line-height: calc(var(--lh) * 1.5);
  text-wrap: balance;
}

#flow blockquote { margin: var(--lh) 0 var(--lh) 1.5em; }
#flow blockquote.epigraph { font-style: italic; }
#flow cite { display: block; text-align: right; font-style: italic; }
#flow blockquote.epigraph cite { font-style: normal; }
#flow hr { border: 0; margin: 0; height: var(--lh); }
#flow ol, #flow ul { margin: var(--lh) 0; padding-left: 1.5em; }
#flow table { margin: var(--lh) 0; border-collapse: collapse; }
#flow td { padding: 0 1.2em 0 0; vertical-align: top; }
#flow p.sub { text-indent: 0; text-align: center; margin: var(--lh) 0 0; color: var(--quiet); letter-spacing: .08em; }
#flow p.sub + p { text-indent: 0; }
#flow b, #flow strong { font-weight: 400; font-variant-caps: all-small-caps; letter-spacing: .05em; }

/* ---------- the shelf ---------- */

#shelf {
  position: absolute;
  inset: 0;
  background: var(--paper);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px max(16px, calc((100% - 34rem) / 2)) 28px;
}
#shelf h1 { margin: 6px 0 2px; font-size: 30px; font-weight: 400; line-height: 1.2; }
#shelf .lede { margin: 0 0 14px; color: var(--quiet); font-style: italic; font-size: 17px; line-height: 1.5; }
#books { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
#books li { border-bottom: 1px solid var(--rule); }
#books button {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 16px;
  width: 100%;
  padding: 13px 4px 14px;
  text-align: left;
  line-height: 1.4;
}
#books button:hover .book-title { color: var(--pencil); }
.book-title { font-size: 20px; }
.book-place { align-self: baseline; color: var(--quiet); font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.book-author { grid-column: 1 / -1; color: var(--quiet); font-style: italic; font-size: 15px; }
.book-about { grid-column: 1 / -1; color: var(--quiet); font-size: 15px; }
.book-bar { grid-column: 1 / -1; height: 2px; margin-top: 7px; background: var(--rule); }
.book-bar i { display: block; height: 100%; background: var(--ink); }
#books .is-current .book-title { color: var(--pencil); }
#shelf-foot { margin: 16px 0 0; color: var(--quiet); font-size: 15px; line-height: 1.6; }
#shelf-foot p { margin: 0 0 6px; }
.linkish { color: var(--quiet); text-decoration: underline; text-underline-offset: 3px; font-size: 15px; padding: 6px 0; }
.linkish:hover { color: var(--ink); }
.code-form { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 0; }
.code-form input {
  font: inherit; font-size: 17px; letter-spacing: .08em; text-transform: uppercase;
  width: 9.5em; padding: 8px 10px; color: var(--ink); background: var(--panel);
  border: 1px solid var(--rule); border-radius: 8px;
}
.code-form button, .plain-button { padding: 8px 14px; border: 1px solid var(--rule); border-radius: 8px; font-size: 15px; }
.code-form button:hover, .plain-button:hover { border-color: var(--ink); }
#device-code { font-size: 22px; letter-spacing: .1em; font-variant-numeric: tabular-nums; }

/* ---------- end of chapter ---------- */

#doorstep {
  position: absolute;
  inset: 0;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  overflow-y: auto;
}

#no-script {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 24px;
  display: grid;
  place-items: center;
  text-align: center;
  font-size: 18px;
  line-height: 1.6;
}
#heap { display: block; }
#doorstep-count {
  margin: 0;
  min-height: 1.6em;
  font-size: 19px;
  line-height: 1.5;
  opacity: 0;
  transition: opacity 0.5s ease;
}
#doorstep-count.shown { opacity: 1; }
@media (prefers-reduced-motion: reduce) { #doorstep-count { transition: none; } }

#notice {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  margin: 0;
  padding: 9px 16px;
  max-width: calc(100% - 32px);
  background: var(--ink);
  color: var(--paper);
  font-size: 15px;
  line-height: 1.35;
  border-radius: 999px;
  text-align: center;
  pointer-events: none;
}
#notice.is-error { border-radius: 10px; pointer-events: auto; }

/* ---------- menu ---------- */

#scrim { position: fixed; inset: 0; background: rgb(10 12 18 / .32); }

#menu {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(23rem, 90vw);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--rule);
  padding: max(18px, env(safe-area-inset-top)) 20px max(14px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  font-size: 16px;
  line-height: 1.45;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.menu-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding-bottom: 14px; }
#menu-title { margin: 0; font-size: 24px; font-weight: 400; line-height: 1.2; }
#menu-author { margin: 2px 0 0; color: var(--quiet); font-style: italic; }
#close-menu { color: var(--quiet); font-size: 15px; padding: 6px 0; }

.menu-block { border-top: 1px solid var(--rule); padding: 13px 0; }
.menu-block h3 { margin: 0 0 3px; font-size: 16px; font-weight: 400; font-style: italic; color: var(--quiet); }
.menu-block p { margin: 0; }
.menu-row { display: flex; align-items: center; justify-content: space-between; }
.menu-row h3 { margin: 0; }
.aside { color: var(--quiet); font-size: 14px; }

.stepper { display: flex; gap: 8px; }
.stepper button { width: 52px; height: 38px; border: 1px solid var(--rule); border-radius: 8px; font-size: 16px; }
.stepper button:hover { border-color: var(--ink); }
.stepper button:disabled { opacity: .35; cursor: default; }

.choice { display: flex; gap: 6px; }
.choice button { padding: 7px 11px; border: 1px solid var(--rule); border-radius: 8px; font-size: 15px; }
.choice button:hover { border-color: var(--ink); }
.choice button[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: var(--paper); }
#to-shelf { margin-top: 4px; }

.check { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--pencil); }

.menu-block.grow { flex: 1 0 11rem; min-height: 11rem; display: flex; flex-direction: column; }
#chapters { list-style: none; margin: 4px -8px 0; padding: 0; overflow-y: auto; overscroll-behavior: contain; }
#chapters button {
  display: grid;
  grid-template-columns: 4.2em 1fr auto;
  gap: 8px;
  align-items: baseline;
  width: 100%;
  padding: 7px 8px;
  text-align: left;
  border-radius: 6px;
}
#chapters button:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); }
#chapters .num { color: var(--quiet); font-size: 14px; letter-spacing: .04em; }
#chapters .mark { color: var(--pencil); font-size: 14px; }
#chapters [aria-current="true"] { color: var(--pencil); }
#chapters [aria-current="true"] .num { color: inherit; }

@media (prefers-reduced-motion: no-preference) {
  #menu { animation: menu-in .16s ease-out; }
  @keyframes menu-in { from { transform: translateX(-14px); opacity: 0; } }
}

/* ---------- a phone on its side, or any very short window ---------- */

@media (max-height: 480px) {
  #bar { height: 34px; }
  #foot { height: 36px; }
  #prev, #next { height: 36px; font-size: 26px; }
  #doorstep { gap: 4px; padding: 6px 24px; }
  #doorstep-count { font-size: 17px; }
  #shelf { padding-top: 8px; }
  #shelf h1 { font-size: 24px; margin-top: 0; }
}
