:root {
  color-scheme: dark;
  --ink: #f5efe3;
  --muted: #9aa7b5;
  --accent: #58b7c0;
  --accent-warm: #d69a61;
  --paper: #070a0e;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-width: 300px;
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(88, 183, 192, .07), transparent 34rem),
    var(--paper);
  font: 15px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  border: 1px solid rgba(255, 255, 255, .22);
  color: var(--ink);
  background: rgba(7, 10, 14, .72);
  font: inherit;
  cursor: pointer;
}

button:hover:not(:disabled),
button:focus-visible {
  border-color: var(--accent);
  background: rgba(18, 31, 39, .92);
  outline: none;
}

button:disabled {
  cursor: default;
  opacity: .22;
}

.screen-reader-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.reader {
  min-height: 100vh;
  min-height: 100dvh;
  padding: 10px;
}

.reader-page {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(330px, .95fr);
  width: calc(100vw - 20px);
  height: calc(100vh - 20px);
  height: calc(100dvh - 20px);
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .13);
  background: var(--paper);
  box-shadow: 0 36px 90px rgba(0, 0, 0, .58), 0 0 0 1px rgba(255, 255, 255, .13);
}

.reader-page.landscape {
  grid-template-columns: minmax(0, 1.42fr) minmax(310px, .72fr);
}

.reader-image {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #030507;
}

.reader-image > img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0;
  place-self: center;
  object-fit: contain;
  object-position: center center;
  filter: saturate(.96) contrast(1.025) brightness(.94);
}

.reader-image.multi {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
}

.reader-image.multi > img {
  width: 100%;
  height: 100%;
  background: #030507;
}

.reader-image-hint {
  display: none;
}

.reader-copy {
  min-width: 0;
  height: 100%;
  overflow-y: auto;
  padding: clamp(24px, 3vw, 42px);
  border-left: 1px solid rgba(255, 255, 255, .12);
  color: var(--ink);
  background:
    radial-gradient(circle at 100% 0%, rgba(214, 154, 97, .09), transparent 21rem),
    #0d1218;
  scrollbar-color: rgba(214, 154, 97, .55) transparent;
  scrollbar-width: thin;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.reader-copy:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -3px;
}

.reader-chapter {
  margin: 0 0 12px;
  color: rgba(255, 247, 232, .78);
  font: 750 10px/1.2 system-ui, sans-serif;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.reader-prose {
  font: 500 18px/1.55 "Iowan Old Style", Baskerville, Georgia, serif;
  letter-spacing: .004em;
  text-wrap: pretty;
}

.reader-prose p {
  break-inside: avoid;
  margin: 0 0 .58em;
}

.reader-folio {
  position: absolute;
  right: 3.5%;
  bottom: 2.1%;
  color: rgba(214, 154, 97, .72);
  font: 700 9px/1 system-ui, sans-serif;
  letter-spacing: .14em;
  pointer-events: none;
}

.reader-controls button {
  position: fixed;
  bottom: 14px;
  z-index: 20;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  overflow: hidden;
  padding: 0;
  border-radius: 50%;
  color: transparent;
  font-size: 0;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .34);
  backdrop-filter: blur(8px);
}

.reader-controls button::before {
  color: rgba(255, 255, 255, .9);
  font: 500 25px/1 system-ui, sans-serif;
}

.reader-controls [data-reader-prev] {
  left: 14px;
}

.reader-controls [data-reader-prev]::before {
  content: "\2190";
}

.reader-controls [data-reader-next] {
  right: 14px;
}

.reader-controls [data-reader-next]::before {
  content: "\2192";
}

.reader-controls output {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 19;
  padding: 5px 9px;
  border: 1px solid rgba(255, 255, 255, .13);
  border-radius: 999px;
  color: rgba(255, 255, 255, .7);
  background: rgba(7, 10, 14, .62);
  font: 700 10px/1 system-ui, sans-serif;
  letter-spacing: .08em;
  transform: translateX(-50%);
  pointer-events: none;
  backdrop-filter: blur(8px);
}

noscript {
  display: block;
  max-width: 40rem;
  margin: 4rem auto;
  padding: 1.5rem;
  color: var(--ink);
  background: #0d1218;
}

@media (max-width: 820px) {
  .reader-page,
  .reader-page.landscape {
    display: block;
    width: calc(100vw - 20px);
    height: auto;
    min-height: 0;
  }

  .reader-image {
    width: 100%;
    height: min(58vh, 560px);
    height: min(58dvh, 560px);
    min-height: 300px;
    cursor: zoom-in;
  }

  .reader-image > img,
  .reader-image.multi > img {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: cover;
  }

  .reader-image-hint {
    position: absolute;
    right: 12px;
    bottom: 12px;
    z-index: 2;
    display: block;
    padding: 6px 9px;
    border: 1px solid rgba(255, 255, 255, .24);
    border-radius: 999px;
    color: rgba(255, 255, 255, .9);
    background: rgba(3, 5, 7, .72);
    font: 700 10px/1 system-ui, sans-serif;
    letter-spacing: .04em;
    pointer-events: none;
    backdrop-filter: blur(7px);
  }

  .reader-page.image-expanded {
    height: calc(100vh - 20px);
    height: calc(100dvh - 20px);
  }

  .reader-page.image-expanded .reader-image {
    height: 100%;
    min-height: 0;
    cursor: zoom-out;
  }

  .reader-page.image-expanded .reader-image > img,
  .reader-page.image-expanded .reader-image.multi > img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
  }

  .reader-page.image-expanded .reader-copy,
  .reader-page.image-expanded .reader-folio {
    display: none;
  }

  .reader-copy {
    height: min(52vh, 560px);
    height: min(52dvh, 560px);
    min-height: 320px;
    padding: clamp(24px, 6vw, 38px);
    border-top: 1px solid rgba(255, 255, 255, .12);
    border-left: 0;
  }

  .reader-folio {
    bottom: 14px;
  }
}

@media (max-width: 520px) {
  .reader-prose {
    font-size: 18px;
    line-height: 1.55;
  }
}

@media (prefers-reduced-motion: reduce) {
  .reader-copy {
    scroll-behavior: auto;
  }
}
