:root {
  color-scheme: light;
  --wine-950: #35141e;
  --wine-900: #4f1f2b;
  --wine-800: #692b3a;
  --rose-200: #dec3c0;
  --paper: #f6eee1;
  --paper-deep: #e9ddcc;
  --ink: #342a28;
  --muted-ink: #7d6f69;
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Baskerville, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  --page-shadow: 0 24px 54px rgb(67 43 34 / 16%), 0 3px 9px rgb(67 43 34 / 10%), 0 1px 1px rgb(255 255 255 / 70%);
  font-family: var(--serif);
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--wine-950);
  -webkit-text-size-adjust: 100%;
}

body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  overscroll-behavior: none;
}

button {
  color: inherit;
  font: inherit;
}

button:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 4px;
}

.app,
.cover-screen,
.reader {
  min-height: 100vh;
  min-height: 100dvh;
}

.cover-screen {
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: max(24px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 50% 12%, rgb(255 235 220 / 11%), transparent 36%),
    linear-gradient(155deg, #672937, var(--wine-950) 84%);
}

.cover-screen.is-leaving {
  animation: cover-out 420ms ease both;
}

.cover {
  position: relative;
  width: min(82vw, 360px);
  aspect-ratio: 0.69;
  overflow: hidden;
  border: 1px solid rgb(255 239 224 / 15%);
  border-radius: 3px 11px 11px 3px;
  background:
    radial-gradient(circle, rgb(255 244 232 / 3.5%) 0 0.7px, transparent 0.9px),
    radial-gradient(circle, rgb(10 0 3 / 4%) 0 0.55px, transparent 0.8px),
    linear-gradient(90deg, rgb(16 4 8 / 30%) 0, transparent 7%, transparent 94%, rgb(16 4 8 / 17%)),
    linear-gradient(145deg, #6a2b3a, var(--wine-950));
  background-position: 0 0, 8px 11px, 0 0, 0 0;
  background-size: 19px 23px, 27px 31px, auto, auto;
  box-shadow:
    -10px 20px 52px rgb(19 4 8 / 36%),
    3px 2px 0 rgb(30 7 13 / 25%),
    inset 0 0 48px rgb(255 224 210 / 4%);
}

.cover::before {
  position: absolute;
  inset: 0 auto 0 6%;
  width: 1px;
  content: "";
  background: rgb(255 244 230 / 13%);
  box-shadow: 2px 0 8px rgb(8 0 2 / 32%), -2px 0 5px rgb(255 237 221 / 3%);
}

.cover::after {
  position: absolute;
  inset: 10px;
  border: 1px solid rgb(234 213 197 / 17%);
  border-radius: 1px 8px 8px 1px;
  content: "";
  pointer-events: none;
}

.cover__content {
  position: relative;
  z-index: 1;
  display: flex;
  height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 13% 12% 10% 16%;
  color: #f5eadd;
  text-align: center;
}

.cover__eyebrow {
  margin: 0 0 clamp(26px, 6vh, 48px);
  color: var(--rose-200);
  font-family: var(--sans);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.cover h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2rem, 9.3vw, 3.25rem);
  font-weight: 400;
  letter-spacing: -0.025em;
  line-height: 1.06;
  text-shadow: 0 1px 1px rgb(21 4 9 / 18%);
}

.cover__ornament {
  display: flex;
  width: 58px;
  align-items: center;
  gap: 7px;
  margin: clamp(24px, 5vh, 38px) 0;
}

.cover__ornament::before,
.cover__ornament::after {
  height: 1px;
  flex: 1;
  content: "";
  background: rgb(222 195 192 / 82%);
}

.cover__ornament::after {
  width: 4px;
  height: 4px;
  flex: none;
  border-radius: 50%;
}

.cover__subtitle {
  max-width: 220px;
  margin: 0;
  color: #dbc6bf;
  font-size: clamp(0.9rem, 3.7vw, 1.05rem);
  font-style: italic;
  line-height: 1.55;
}

.start-button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 12px;
  margin-top: auto;
  border: 0;
  border-bottom: 1px solid rgb(245 234 221 / 28%);
  background: transparent;
  color: #f5eadd;
  cursor: pointer;
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  -webkit-tap-highlight-color: transparent;
}

.start-button span {
  font-size: 1rem;
  transition: transform 180ms ease;
}

.start-button:is(:hover, :focus-visible) span {
  transform: translateX(3px);
}

.reader {
  display: grid;
  height: 100vh;
  height: 100dvh;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(10px, 2vh, 18px);
  overflow: hidden;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 50% 36%, rgb(255 255 255 / 66%), transparent 52%),
    linear-gradient(145deg, #eee7de, #e6ddd3 72%);
}

.reader[hidden],
.cover-screen[hidden] {
  display: none;
}

.reader.is-entering {
  animation: reader-in 440ms ease both;
}

.reader__header,
.reader__footer {
  display: flex;
  width: min(100%, 430px);
  align-items: center;
  justify-self: center;
}

.reader__header {
  min-height: 34px;
  justify-content: space-between;
}

.reader__header p {
  margin: 0;
  color: rgb(84 69 65 / 66%);
  font-size: 0.71rem;
  font-style: italic;
  letter-spacing: 0.02em;
}

.close-button,
.footer-arrow {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: rgb(84 69 65 / 60%);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.close-button {
  font-family: var(--sans);
  font-size: 1.4rem;
  font-weight: 200;
}

.book-stage {
  position: relative;
  display: grid;
  min-height: 0;
  place-items: center;
  perspective: 1450px;
  perspective-origin: 52% 48%;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.book {
  position: relative;
  width: min(calc(100vw - 32px), calc((100dvh - 142px) * 0.7), 430px);
  aspect-ratio: 0.7;
  transform-style: preserve-3d;
  filter: drop-shadow(0 1px 1px rgb(255 255 255 / 74%));
}

.book::after {
  position: absolute;
  z-index: -1;
  right: 4px;
  bottom: -6px;
  left: 4px;
  height: 9px;
  border-radius: 0 0 7px 7px;
  content: "";
  background: repeating-linear-gradient(to bottom, #d4c6b3 0 1px, #eee3d3 1px 2px);
  box-shadow: 0 6px 16px rgb(66 43 36 / 16%);
}

.page {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border: 1px solid rgb(113 88 70 / 11%);
  border-radius: 2px 7px 7px 2px;
  background:
    radial-gradient(circle, rgb(112 85 61 / 2.6%) 0 0.55px, transparent 0.8px),
    radial-gradient(circle, rgb(255 255 255 / 15%) 0 0.65px, transparent 0.9px),
    linear-gradient(90deg, rgb(95 67 48 / 7%), transparent 7%, transparent 92%, rgb(95 67 48 / 3.5%)),
    linear-gradient(155deg, rgb(255 255 255 / 16%), transparent 46%),
    var(--paper);
  background-position: 0 0, 9px 13px, 0 0, 0 0, 0 0;
  background-size: 21px 25px, 31px 37px, auto, auto, auto;
  box-shadow: var(--page-shadow), inset 0 0 54px rgb(137 100 69 / 4.5%);
}

.page--base,
.sheet-face--front {
  display: flex;
  flex-direction: column;
  padding: clamp(38px, 7vh, 68px) clamp(30px, 9vw, 58px) clamp(30px, 6vh, 52px);
}

.page__chapter {
  margin: 0 0 clamp(26px, 5vh, 44px);
  color: #9a756b;
  font-family: var(--sans);
  font-size: 0.61rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.page h2 {
  margin: 0 0 clamp(24px, 4vh, 36px);
  color: #302624;
  font-family: var(--serif);
  font-size: clamp(1.75rem, 7.6vw, 2.7rem);
  font-weight: 400;
  letter-spacing: -0.025em;
  line-height: 1.08;
}

.page__text {
  margin: 0;
  color: #514441;
  font-family: var(--serif);
  font-size: clamp(0.96rem, 3.95vw, 1.1rem);
  line-height: 1.62;
  text-wrap: pretty;
}

.page__text + .page__text {
  margin-top: 0.82em;
}

.page__folio {
  margin: auto 0 0;
  padding-top: 24px;
  color: rgb(116 96 89 / 56%);
  font-family: var(--serif);
  font-size: 0.68rem;
  text-align: center;
}

.page__note {
  max-width: 240px;
  margin: auto auto 0;
  padding-top: 28px;
  color: #968079;
  font-size: clamp(0.72rem, 3vw, 0.82rem);
  font-style: italic;
  line-height: 1.5;
  text-align: center;
}

.page--date {
  text-align: center;
}

.page--date .page__chapter {
  align-self: stretch;
  margin-bottom: 0;
  text-align: left;
}

.page--date h2 {
  max-width: 280px;
  margin: auto auto 26px;
  color: #3e2a2e;
  font-size: clamp(2.05rem, 8.6vw, 3.05rem);
  line-height: 1.12;
}

.page--date h2::after {
  display: block;
  width: 36px;
  height: 1px;
  margin: 24px auto 0;
  content: "";
  background: rgb(105 43 58 / 34%);
}

.page--date .page__body {
  max-width: 270px;
  margin: 0 auto auto;
}

.page--emphasis .page__chapter {
  margin-bottom: auto;
}

.page--emphasis h2 {
  margin: 0 0 clamp(28px, 5vh, 42px);
  color: #4e2530;
  font-size: clamp(3.05rem, 13.6vw, 4.7rem);
  letter-spacing: 0.11em;
  line-height: 1;
  text-align: center;
}

.page--emphasis .page__body {
  margin-bottom: auto;
}

.page--final h2 {
  margin-bottom: clamp(22px, 3.5vh, 30px);
}

.page--final .page__note::before {
  display: block;
  width: 30px;
  height: 1px;
  margin: 0 auto 16px;
  content: "";
  background: rgb(105 43 58 / 24%);
}

.page--compact {
  padding-top: clamp(36px, 5.5vh, 50px);
  padding-bottom: clamp(28px, 4vh, 38px);
}

.page--compact .page__chapter {
  margin-bottom: clamp(26px, 3.5vh, 34px);
}

.page--compact h2 {
  margin-bottom: clamp(20px, 3vh, 26px);
}

.page--compact .page__text {
  font-size: clamp(0.93rem, 3.78vw, 1.04rem);
  line-height: 1.58;
}

.turning-sheet {
  position: absolute;
  z-index: 2;
  inset: 0;
  transform-origin: left center;
  transform-style: preserve-3d;
  pointer-events: none;
}

.turning-sheet:is(.turn-forward, .turn-backward) {
  will-change: transform, filter;
}

.sheet-face {
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.sheet-face--front {
  transform: rotateY(0deg) translateZ(1px);
}

.sheet-face--back {
  transform: rotateY(180deg) translateZ(1px);
  background:
    radial-gradient(circle, rgb(112 85 61 / 2.4%) 0 0.55px, transparent 0.8px),
    linear-gradient(90deg, rgb(95 67 48 / 3%), transparent 88%, rgb(95 67 48 / 10%)),
    var(--paper-deep);
  background-size: 23px 27px, auto, auto;
}

.sheet-face::after {
  position: absolute;
  z-index: 3;
  inset: 0;
  border-radius: inherit;
  content: "";
  opacity: 0;
  pointer-events: none;
}

.turn-forward .sheet-face--front::after {
  background: linear-gradient(90deg, transparent 38%, rgb(69 45 36 / 18%) 100%);
  animation: fold-shade 650ms ease-in-out both;
}

.turn-backward .sheet-face--front::after {
  background: linear-gradient(270deg, transparent 38%, rgb(69 45 36 / 18%) 100%);
  animation: fold-shade 650ms ease-in-out both;
}

.turning-sheet.turn-forward {
  animation: turn-forward 650ms cubic-bezier(0.52, 0.04, 0.27, 0.98) both;
}

.turning-sheet.turn-backward {
  transform-origin: right center;
  animation: turn-backward 650ms cubic-bezier(0.52, 0.04, 0.27, 0.98) both;
}

.navigation-zone {
  position: absolute;
  z-index: 4;
  top: 0;
  bottom: 0;
  width: 50%;
  border: 0;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.navigation-zone--previous {
  left: 0;
}

.navigation-zone--next {
  right: 0;
}

.navigation-zone:focus-visible {
  outline-offset: -6px;
}

.navigation-zone:disabled,
.footer-arrow:disabled {
  cursor: default;
  opacity: 0.16;
}

.reader__footer {
  justify-content: space-between;
}

.footer-arrow {
  font-family: var(--sans);
  font-size: 0.88rem;
}

.footer-arrow:not(:disabled),
.close-button {
  opacity: 0.7;
}

.page-status {
  width: min(48vw, 180px);
  color: rgb(89 73 68 / 66%);
  font-family: var(--sans);
  text-align: center;
}

.page-status p {
  margin: 0 0 8px;
  font-size: 0.62rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.12em;
}

.progress {
  height: 1px;
  overflow: hidden;
  border-radius: 2px;
  background: rgb(79 31 43 / 10%);
}

.progress span {
  display: block;
  width: 33.333%;
  height: 100%;
  border-radius: inherit;
  background: rgb(105 43 58 / 72%);
  transition: width 320ms ease;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

@keyframes turn-forward {
  0% {
    transform: translateZ(0) rotateY(0deg) scaleX(1);
    filter: drop-shadow(0 10px 14px rgb(55 34 28 / 7%));
  }
  42% {
    transform: translateZ(7px) rotateY(-76deg) scaleX(0.992);
    filter: drop-shadow(20px 12px 18px rgb(55 34 28 / 23%));
  }
  58% {
    transform: translateZ(7px) rotateY(-108deg) scaleX(0.992);
    filter: drop-shadow(15px 10px 15px rgb(55 34 28 / 19%));
  }
  100% {
    transform: translateZ(0) rotateY(-180deg) scaleX(1);
    filter: drop-shadow(0 3px 4px rgb(55 34 28 / 3%));
  }
}

@keyframes turn-backward {
  0% {
    transform: translateZ(0) rotateY(0deg) scaleX(1);
    filter: drop-shadow(0 10px 14px rgb(55 34 28 / 7%));
  }
  42% {
    transform: translateZ(7px) rotateY(76deg) scaleX(0.992);
    filter: drop-shadow(-20px 12px 18px rgb(55 34 28 / 23%));
  }
  58% {
    transform: translateZ(7px) rotateY(108deg) scaleX(0.992);
    filter: drop-shadow(-15px 10px 15px rgb(55 34 28 / 19%));
  }
  100% {
    transform: translateZ(0) rotateY(180deg) scaleX(1);
    filter: drop-shadow(0 3px 4px rgb(55 34 28 / 3%));
  }
}

@keyframes fold-shade {
  0%,
  100% {
    opacity: 0;
  }
  46% {
    opacity: 0.72;
  }
}

@keyframes cover-out {
  to {
    opacity: 0;
    transform: scale(1.015);
  }
}

@keyframes reader-in {
  from {
    opacity: 0;
  }
}

@media (min-width: 600px) {
  .cover {
    width: min(72vw, 370px);
  }
}

@media (max-height: 620px) {
  .reader {
    gap: 6px;
    padding-top: max(6px, env(safe-area-inset-top));
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }

  .reader__header,
  .reader__footer {
    min-height: 30px;
  }

  .book {
    width: min(calc(100vw - 32px), calc((100dvh - 98px) * 0.7), 430px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }

  .cover-screen.is-leaving,
  .reader.is-entering {
    animation-duration: 140ms;
  }

  .turning-sheet.turn-forward,
  .turning-sheet.turn-backward {
    animation: page-fade 180ms ease both;
  }

  .turn-forward .sheet-face--front::after,
  .turn-backward .sheet-face--front::after {
    animation: none;
    opacity: 0;
  }

  .progress span,
  .start-button span {
    transition: none;
  }
}

@keyframes page-fade {
  0% {
    opacity: 1;
    transform: none;
  }
  50% {
    opacity: 0;
    transform: none;
  }
  100% {
    opacity: 0;
    transform: none;
  }
}
