/* Reading: what both readers share: the paper, the bar, the pages, page turns, the page count and the reading panels */

/* Both readers sit on the page's own paper. On wide screens the bar, the
   page count and the margins take 150px of the height, the base chrome
   (--reader-chrome-base), which js/reading.js reads too; each reader sets
   its own on phones. */
.reader-view {
  --reader-chrome-base: 150px;
  --reader-extra-lines: 0;
  min-height: 100vh;
  background: var(--book-paper);
}

/* A text page's height over its width: 3:4 and the screen's whole extra
   lines of prose (--reader-extra-lines, which js/reading.js sets on the
   reader), each 4.09cqw × 1.58. */
.reader-view,
.reader-page-probe {
  --reader-page-ratio: calc(4 / 3 + 0.064622 * var(--reader-extra-lines));
}

.reader-shell {
  display: block;
  width: min(calc(100% - 40px), 1280px);
  margin: 0 auto;
  padding: 22px 0 65px;
}

.reader-stage {
  min-width: 0;
}

/* The bar on wide screens: one line, the reader's controls at its ends and
   the title between them. The controls are faint until the pointer or
   focus is in the bar, and even then --book-muted keeps 4.5:1 on the
   paper. */
.reader-bar {
  display: grid;
  min-height: 52px;
  grid-template-columns: minmax(max-content, 1fr) minmax(0, auto) minmax(max-content, 1fr);
  align-items: center;
  gap: 16px;
  padding: 4px 12px;
  color: var(--book-muted);
}

.reader-bar:hover,
.reader-bar:focus-within {
  color: var(--book-ink);
}

.reader-bar-start,
.reader-bar-end {
  display: flex;
  align-items: center;
  gap: 4px;
}

.reader-bar-start {
  grid-column: 1;
}

.reader-bar-end {
  grid-column: 3;
  justify-content: flex-end;
}

.reader-bar-title {
  min-width: 0;
  grid-column: 2;
  margin: 0;
  overflow: hidden;
  color: var(--book-muted);
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 850;
  letter-spacing: normal;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-bar-title span {
  font-weight: 700;
}

.reader-bar-button {
  display: inline-flex;
  min-width: 44px;
  height: 44px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 10px;
  border: 0;
  border-radius: 12px;
  color: inherit;
  background: transparent;
  font-size: 0.86rem;
  font-weight: 850;
  white-space: nowrap;
}

.reader-bar-button:hover:not(:disabled),
.reader-bar-button[aria-expanded="true"] {
  color: var(--book-ink);
  background: var(--book-tint);
}

.reader-bar-button:disabled {
  opacity: 0.55;
}

/* A round button in the phone bars and rows. */
.reader-icon-button {
  display: inline-grid;
  width: 44px;
  height: 44px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--book-line);
  border-radius: 50%;
  color: var(--book-ink);
  background: transparent;
}

.reader-icon-button:hover {
  border-color: var(--book-muted);
  background: var(--book-tint);
}

/* A reading panel's bar button, and on wide screens the panel hanging
   under it, over the page. On phones the panel is a book sheet with the
   same body. */
.reading-panel-control {
  position: relative;
  display: flex;
  flex: 0 0 auto;
}

/* Aa, in the book's face. A button that shows its text beside the icon,
   Download, has the bar's own (js/reading.js leaves this class off it). */
.reading-panel-button {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1;
}

.reading-panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 8px);
  right: 0;
  width: min(320px, calc(100vw - 32px));
  padding: 12px 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--ink);
  background: var(--paper);
  box-shadow: var(--shadow-lg);
  text-align: left;
}

/* Contents and Read in hang from the left of the bar, where their buttons
   are; Themes & Settings and Download from the right. */
.reading-panel-contents,
.reading-panel-language {
  right: auto;
  left: 0;
  width: min(360px, calc(100vw - 32px));
  max-height: min(70vh, 560px);
  overflow-y: auto;
}

.reading-panel-title {
  margin: 0 0 10px;
  padding: 2px 0 10px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--ink-soft);
  font-size: 0.88rem;
  font-weight: 850;
  letter-spacing: normal;
  text-align: center;
}

/* Themes & Settings: Smaller, the size and Larger in one capsule, then the
   two theme tiles. */
.reading-size {
  display: grid;
  min-height: 52px;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--violet-faint);
}

.reading-size-step {
  min-height: 50px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  color: var(--ink);
  background: transparent;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
  line-height: 1;
}

.reading-size-step-larger {
  font-size: 1.6rem;
}

.reading-size-step:hover:not(:disabled) {
  background: var(--violet-pale);
}

.reading-size-step:disabled {
  color: var(--ink-soft);
  opacity: 0.45;
}

.reading-size-value {
  display: grid;
  min-width: 4.2em;
  place-items: center;
  border-inline: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 0.86rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.reading-themes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.reading-theme {
  display: grid;
  min-height: 92px;
  place-content: center;
  justify-items: center;
  gap: 4px;
  padding: 8px;
  border: 0;
  border-radius: 18px;
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: 0.86rem;
  font-weight: 800;
}

.reading-theme > span {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2rem;
  font-weight: 400;
  line-height: 1;
}

/* Each tile shows its theme's page in either theme, so these four colors
   stay the same in both. */
.reading-theme-light {
  color: #26234f;
  background: #fffdf8;
}

.reading-theme-dark {
  color: #f3ead9;
  background: #2a2623;
}

/* The pressed tile is always the theme on screen, so the ring is in its
   colors. */
.reading-theme[aria-pressed="true"] {
  box-shadow: inset 0 0 0 3px var(--violet);
}

/* Show moments, in the private reader: a row with the label and On or Off
   under it, the switch (css/components.css) at its end, then what it
   does. */
.reading-moment-marks {
  margin-top: 14px;
}

.reading-switch {
  position: relative;
  display: grid;
  min-height: 52px;
  grid-template-areas:
    "label track"
    "state track";
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0 12px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--violet-faint);
  cursor: pointer;
  font-weight: 800;
}

.reading-switch-label {
  grid-area: label;
}

.reading-moment-marks .reading-switch-track {
  grid-area: track;
  border-color: var(--ink-soft);
  background: var(--line);
}

.reading-switch-state {
  grid-area: state;
  color: var(--ink-soft);
  font-size: 0.86rem;
}

.reading-moment-marks-detail {
  margin: 8px 4px 0;
  color: var(--ink-soft);
  font-size: 0.82rem;
  line-height: 1.4;
}

.chapter-progress {
  margin-bottom: 9px;
  color: var(--violet);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

/* The pages and the controls that turn them. On wide screens ‹ and › sit
   at the window's edges, centered on the pages. */
.reader-pages {
  position: relative;
}

.reader-turn {
  position: absolute;
  z-index: 2;
  top: 50%;
  display: grid;
  width: 44px;
  height: 88px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 12px;
  color: var(--book-muted);
  background: transparent;
  transform: translateY(-50%);
}

.reader-turn-previous {
  left: calc((100% - 100vw) / 2 + 12px);
}

.reader-turn-next {
  right: calc((100% - 100vw) / 2 + 12px);
}

.reader-turn:hover:not(:disabled) {
  color: var(--book-ink);
  background: var(--book-tint);
}

.reader-turn:disabled {
  opacity: 0.3;
}

.reader-turn .book-icon {
  width: 28px;
  height: 28px;
}

/* Two pages of the same width side by side: a single page keeps the left
   one. The width fits two pages and the arrows in the window, and a text
   page's height under the bars. */
.reader-spread,
.reader-count,
.reader-page-probe {
  display: grid;
  grid-template-columns: repeat(2, clamp(380px, min((100vw - 200px) / 2, (100dvh - var(--reader-chrome-base)) / var(--reader-page-ratio)), 600px));
  justify-content: center;
  column-gap: 24px;
}

.reader-spread {
  align-items: start;
}

/* The page count under the pages, and on wide screens the pages left in
   the chapter at its right end. */
.reader-count {
  align-items: center;
  margin: 0;
  padding-top: 14px;
  color: var(--book-muted);
  font-size: 0.8rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.reader-count-position {
  grid-row: 1;
  grid-column: 1 / -1;
  justify-self: center;
}

.reader-count-left {
  grid-row: 1;
  grid-column: 2;
  justify-self: end;
}

/* A page is the paper itself: no frame. */
.reader-book-page {
  position: relative;
  min-width: 0;
  background: var(--book-paper);
}

/* Hidden, for js/reading.js (measureReaderExtraLines): a page as wide as
   its width rule makes it with no extra lines and the base chrome, which a
   notice never raises, and the small viewport's height. */
.reader-page-probe {
  --reader-extra-lines: 0;
  --reader-chrome-height: var(--reader-chrome-base);
  height: 0;
  overflow: hidden;
  visibility: hidden;
}

.reader-viewport-probe {
  height: 100vh;
  height: 100svh;
}

/* A text page has the same layout at any size, so it holds the same lines
   of prose on every screen, and whole lines more on a taller one
   (js/pages.js). Sizes inside it are in cqw of its width: 1cqw is 3.9px on
   the 390px page of a 390x844 phone. As a size container its text no
   longer sets its width; its column does. It grows only if its text
   overflows. */
.reader-text-page {
  display: flex;
  flex-direction: column;
  aspect-ratio: 1 / var(--reader-page-ratio);
  container-type: inline-size;
}

/* The prose has the page but its margins: the room a running head and a
   footer once took is three more lines of it (READER_SCREEN_EXTRA_LINES).
   The page is the size container, so the padding is here, where cqw is the
   page's. */
.reader-text-page-body {
  flex: 1 1 auto;
  padding: 7.42cqw 7.42cqw 8.24cqw;
}

.reader-text-page .chapter-progress {
  margin-bottom: 1.92cqw;
  font-size: 2.9cqw;
}

.reader-text-page h2 {
  margin-bottom: 6.04cqw;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 7.82cqw;
  line-height: 1.08;
}

.reader-running-heading {
  padding-bottom: 3.02cqw;
  margin-bottom: 4.95cqw;
  border-bottom: 1px solid var(--book-heading-line);
}

.reader-running-heading span {
  display: block;
  margin-bottom: 0.82cqw;
  color: var(--violet);
  font-size: 2.73cqw;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.reader-running-heading h2 {
  margin-bottom: 0;
  color: var(--book-running-title);
  font-size: 4.75cqw;
  font-style: italic;
}

.reader-page-prose {
  color: var(--book-prose);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 4.09cqw;
  line-height: 1.58;
}

/* The text size scales the prose only (js/reading.js cuts the pages for
   it), so the page and its headings keep their sizes; the drop cap and the
   paragraph gap are in em and follow. */
.reader-view[data-text-size="90"] {
  --reader-text-size: 0.9;
}

.reader-view[data-text-size="115"] {
  --reader-text-size: 1.15;
}

.reader-view[data-text-size="130"] {
  --reader-text-size: 1.3;
}

.reader-view[data-text-size="150"] {
  --reader-text-size: 1.5;
}

.reader-view[data-text-size] .reader-page-prose {
  font-size: calc(4.09cqw * var(--reader-text-size));
}

.reader-page-prose p {
  margin-bottom: 0.92em;
}

.reader-page-prose p:last-child {
  margin-bottom: 0;
}

.reader-text-page.is-chapter-opener .reader-page-prose p:first-child::first-letter {
  float: left;
  margin: 0.08em 0.08em 0 0;
  color: var(--violet);
  font-size: 3.15em;
  font-weight: 700;
  line-height: 0.78;
}

/* Show moments (js/reader.js): a moment's number where its words start, a
   round badge centered in the page's left margin (the 7.42cqw of the page
   body's padding) beside the paragraph's first line, whose middle is 0.79
   of the prose size down (its line height is 1.58). Positioned from the
   paragraph, out of the flow, so the lines stay as the page was cut, and
   never selected with the prose. Calm, or amber like the moment card's
   mark when the moment changed since written or may no longer fit. */
.reader-page-prose .has-moment-mark {
  position: relative;
}

.moment-mark {
  position: absolute;
  top: calc(0.79 * 4.09cqw * var(--reader-text-size, 1) - 2.2cqw);
  left: -5.91cqw;
  display: grid;
  width: 4.4cqw;
  height: 4.4cqw;
  place-items: center;
  padding: 0;
  border: 1px solid var(--book-line);
  border-radius: 50%;
  color: var(--book-muted);
  background: var(--book-paper);
  font-family: var(--font-body);
  font-size: 2.3cqw;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
}

/* The tap area: 44px, centered on the badge. */
.moment-mark::before {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  content: "";
  transform: translate(-50%, -50%);
}

.moment-mark[data-state="changed"],
.moment-mark[data-state="doubt"] {
  border-color: var(--status-outdated-line);
  color: var(--book-status-outdated-ink);
  background: var(--gold-pale);
}

.moment-mark:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

/* A mark's menu on wide screens, a dropdown (css/components.css) in the
   mark's paragraph: under the mark at its left, or over the paragraph with
   is-up. In the app's face and size, not the prose's, and never selected
   with the prose. Its head: the moment's number over its state. */
.reader-page-prose .dropdown-menu {
  top: calc(0.79 * 4.09cqw * var(--reader-text-size, 1) + 2.2cqw + 4px);
  right: auto;
  left: -5.91cqw;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.25;
  user-select: none;
  -webkit-user-select: none;
}

.reader-page-prose .dropdown-menu.is-up {
  top: auto;
}

.moment-mark-menu-head {
  display: grid;
  justify-items: start;
  gap: 6px;
  padding: 8px 12px 8px;
}

.moment-mark-menu-head strong {
  font-size: 0.95rem;
  font-weight: 900;
}

/* Phones: the mark's state over its book sheet's rows. */
.moment-mark-sheet-state {
  margin: -2px 8px 10px;
}

.moment-mark-menu-head .moment-state,
.moment-mark-sheet-state .moment-state {
  margin-bottom: 0;
}

/* A picture keeps its 3:4 page, never cropped, centered beside a taller
   text page. */
.reader-illustration-page {
  align-self: center;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  color: #fff;
  background: #282650;
}

.reader-illustration-page > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reader-illustration-shade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to bottom, rgba(15, 14, 40, 0.24), transparent 28%),
    linear-gradient(to top, rgba(15, 14, 40, 0.72), transparent 42%);
}

.reader-illustration-label {
  position: absolute;
  z-index: 2;
  right: 27px;
  bottom: 27px;
  left: 27px;
  text-shadow: 0 2px 12px rgba(8, 7, 31, 0.75);
}

.reader-illustration-label p {
  margin-bottom: 4px;
  color: #ffe8a8;
  font-size: 0.65rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.reader-illustration-label h2 {
  margin-bottom: 0;
  color: #fff;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.4rem, 2.5vw, 2rem);
  line-height: 1.08;
}

@media (max-width: 1150px) {
  .reader-shell {
    width: min(calc(100% - 32px), 1080px);
  }
}

@media (max-width: 900px) {
  /* The page has no side gutter. */
  .reader-view .reader-shell {
    width: 100%;
  }

  /* A sideways swipe turns the page (js/reading.js); pinch zoom still works.
     So does a tap on its sides (reader-page-tap). iOS Safari sends no click
     for a tap on a plain element when the only listener is on the document
     (js/main.js), unless it has cursor: pointer; and it would flash a
     highlight over the whole page on every tap. */
  .reader-spread,
  .reader-page-probe {
    grid-template-columns: minmax(0, 600px);
  }

  .reader-spread {
    touch-action: pan-y pinch-zoom;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .reader-count {
    grid-template-columns: minmax(0, 1fr);
    padding-top: 10px;
  }

  /* No gutter: as wide as fits, or as a text page as tall as the height the
     reader's bars and rows leave (--reader-chrome-height, each reader's
     own), and centered. */
  .reader-book-page {
    width: min(100%, max(240px, calc((100dvh - var(--reader-chrome-height)) / var(--reader-page-ratio))));
    justify-self: center;
  }

  /* Previous page and Next page, for the keyboard: hidden until focused
     (css/base.css), then shown over the top of the page. */
  .reader-turn {
    top: 8px;
    width: auto;
    height: auto;
    min-height: 44px;
    padding: 0 16px;
    border-radius: 999px;
    color: var(--book-ink);
    background: var(--book-paper);
    box-shadow: var(--shadow-md);
    font-weight: 800;
    transform: none;
  }

  .reader-turn-previous {
    left: 8px;
  }

  .reader-turn-next {
    right: 8px;
  }
}
