:root {
  --color-ink: #2c241c;
  --color-paper: #f6f0e6;
  --color-sheet: #fbf7f0;
  --color-rose: #9a3d4d;
  --color-on-rose: #fffaf4;
  --color-plum: #3c2744;
  --color-muted: #5e5148;
  --color-desk: #241528;
  --color-desk-light: #4c3456;
  --font-display: "Fraunces", "Iowan Old Style", Palatino, "Palatino Linotype", serif;
  --font-serif: "Source Serif 4", Palatino, "Palatino Linotype", "Book Antiqua", serif;
  --sheet-radius: 2px 14px 14px 2px;
  --ease-page: cubic-bezier(0.5, 0.02, 0.2, 1);
}

html {
  color-scheme: dark;
  overflow-x: clip;
}

body {
  margin: 0;
  min-height: 100dvh;
  overflow-x: clip;
  background: var(--color-desk);
  color: var(--color-ink);
  font-family: var(--font-serif);
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: #e7c4cb;
  color: var(--color-ink);
}

.desk {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  padding: 0.85rem 0.85rem 1.4rem;
  box-sizing: border-box;
  background:
    radial-gradient(900px 560px at 50% 38%, var(--color-desk-light) 0%, var(--color-desk) 62%, #140b16 100%);
  overscroll-behavior: none;
}

.running {
  width: min(40rem, 100%);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--color-paper);
  font-family: var(--font-display);
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0.78;
}

.book {
  position: relative;
  width: min(40rem, 100%);
  flex: 1 1 auto;
  min-height: 0;
  max-height: calc(100dvh - 8.25rem);
  display: flex;
  perspective: 1800px;
}

.stack,
.stack::before,
.stack::after {
  position: absolute;
  border-radius: var(--sheet-radius);
  background: #efe4d4;
}

.stack {
  inset: 14px 10px -8px 14px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
}

.stack::before,
.stack::after {
  content: "";
  inset: 0;
}

.stack::before {
  transform: rotate(1.25deg);
  background: #e7d8c6;
}

.stack::after {
  transform: rotate(-1deg) translateY(6px);
  background: #f3e7d6;
}

.sheet {
  position: relative;
  z-index: 1;
  flex: 1;
  width: 100%;
  min-height: 0;
  overflow: auto;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  padding: 1.55rem 1.35rem 1.15rem 1.7rem;
  border-radius: var(--sheet-radius);
  background-color: var(--color-sheet);
  background-image: radial-gradient(rgba(80, 48, 36, 0.045) 0.6px, transparent 0.65px);
  background-size: 6px 6px;
  color: var(--color-ink);
  box-shadow:
    0 22px 50px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  transform-origin: left center;
  transform-style: preserve-3d;
}

.sheet::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 18px;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(70, 36, 32, 0.16), transparent 80%);
}

.sheet.kind-cover {
  text-align: center;
  background-color: var(--color-plum);
  background-image:
    radial-gradient(420px 220px at 50% 0%, rgba(255, 250, 244, 0.08), transparent 70%),
    radial-gradient(rgba(255, 250, 244, 0.04) 0.6px, transparent 0.65px);
  color: var(--color-paper);
  padding-top: 1.7rem;
}

.sheet.kind-cover::before {
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.32), transparent 85%);
}

.ribbon {
  position: absolute;
  top: 0;
  right: 1.55rem;
  width: 14px;
  height: 72px;
  background: var(--color-rose);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 84%, 0 100%);
  box-shadow: 0 8px 12px rgba(0, 0, 0, 0.12);
}

.kicker {
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--color-muted);
}

.sheet.kind-cover .kicker {
  color: rgba(246, 240, 230, 0.72);
}

.rule {
  width: 3.25rem;
  height: 1px;
  margin: 0.85rem auto 0;
  background: currentColor;
  opacity: 0.4;
  border: 0;
}

.title {
  margin: 0.35rem 0 0.9rem;
  font-family: var(--font-display);
  font-weight: 560;
  font-style: italic;
  font-size: clamp(1.85rem, 5vw, 2.6rem);
  line-height: 1.12;
  letter-spacing: -0.02em;
}

.sheet.kind-cover .title {
  font-style: normal;
  font-weight: 620;
  font-size: clamp(3rem, 12vw, 4.8rem);
  line-height: 0.92;
  letter-spacing: -0.035em;
  margin: 0.35rem 0 0.4rem;
}

.frame {
  width: min(100%, 15.5rem);
  margin: 0 0 1rem;
  padding: 0.45rem 0.45rem 0.85rem;
  background: var(--color-on-rose);
  box-shadow: 0 12px 26px rgba(28, 10, 16, 0.16);
  transform: rotate(-1.4deg);
}

.sheet.kind-cover .frame {
  margin: 0.85rem auto 1rem;
  width: min(100%, 16.5rem);
}

.frame img {
  display: block;
  width: 100%;
  height: 12.5rem;
  object-fit: cover;
  object-position: center 18%;
}

.sheet.kind-cover .frame img {
  height: 13.5rem;
}

.frame figcaption {
  margin: 0.45rem 0 0;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 0.95rem;
  text-align: center;
  color: var(--color-rose);
}

.writing {
  flex: 1 1 auto;
}

.writing p {
  margin: 0 0 0.85rem;
  font-size: 1.08rem;
  line-height: 1.55;
  min-height: 1.2em;
}

.sheet.kind-cover .writing p {
  font-size: 1.02rem;
  line-height: 1.5;
  color: rgba(246, 240, 230, 0.92);
}

.caret {
  display: inline-block;
  width: 2px;
  height: 0.95em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--color-rose);
  animation: blink 1s steps(1) infinite;
}

.running,
.book,
.controls {
  position: relative;
  z-index: 1;
}

.hearts {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.float-heart {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #c45668;
  transform: rotate(-45deg);
  opacity: 0.45;
  animation: drift 11s ease-in-out infinite;
}

.float-heart::before,
.float-heart::after {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  background: inherit;
  border-radius: 50%;
}

.float-heart::before {
  top: -6px;
  left: 0;
}

.float-heart::after {
  left: 6px;
  top: 0;
}

.float-heart:nth-child(1) { left: 8%; top: 18%; animation-delay: 0s; scale: 0.7; }
.float-heart:nth-child(2) { left: 18%; top: 72%; animation-delay: -2s; scale: 1.1; opacity: 0.3; }
.float-heart:nth-child(3) { left: 78%; top: 14%; animation-delay: -4s; scale: 0.85; }
.float-heart:nth-child(4) { left: 88%; top: 64%; animation-delay: -1s; scale: 1.25; opacity: 0.35; }
.float-heart:nth-child(5) { left: 46%; top: 8%; animation-delay: -6s; scale: 0.55; }
.float-heart:nth-child(6) { left: 6%; top: 46%; animation-delay: -3.5s; scale: 0.9; opacity: 0.28; }
.float-heart:nth-child(7) { left: 92%; top: 38%; animation-delay: -7s; scale: 0.65; }
.float-heart:nth-child(8) { left: 62%; top: 86%; animation-delay: -5s; scale: 0.8; opacity: 0.32; }

.mini-heart {
  position: relative;
  display: inline-block;
  width: 9px;
  height: 9px;
  margin: 0 0.35rem;
  background: var(--color-rose);
  transform: rotate(-45deg) translateY(-1px);
  vertical-align: middle;
}

.mini-heart::before,
.mini-heart::after {
  content: "";
  position: absolute;
  width: 9px;
  height: 9px;
  background: inherit;
  border-radius: 50%;
}

.mini-heart::before { top: -4.5px; left: 0; }
.mini-heart::after { left: 4.5px; top: 0; }

.sheet.kind-cover .mini-heart {
  background: #e7a0ab;
}

.folio {
  margin-top: auto;
  padding-top: 0.8rem;
  text-align: center;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 0.92rem;
  color: var(--color-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.seal {
  position: relative;
  width: 6.4rem;
  height: 6.4rem;
  margin: 0.15rem auto 0.85rem;
  display: grid;
  place-items: center;
  border: 0;
  color: var(--color-rose);
  font-family: var(--font-display);
  font-style: italic;
  font-size: 0.92rem;
}

.seal-heart {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.2;
}

.seal span {
  position: relative;
  transform: translateY(2px);
}

.blooms {
  position: absolute;
  left: 50%;
  bottom: 22%;
  width: 0;
  height: 0;
  z-index: 3;
  pointer-events: none;
}

.bloom {
  position: absolute;
  width: 14px;
  height: 14px;
  background: #c45668;
  transform: rotate(-45deg);
  animation: rise 1.15s ease-out forwards;
}

.bloom::before,
.bloom::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  background: inherit;
  border-radius: 50%;
}

.bloom::before { top: -7px; }
.bloom::after { left: 7px; }
.bloom:nth-child(1) { animation-delay: 0s; --dx: -36px; }
.bloom:nth-child(2) { animation-delay: 0.08s; --dx: 8px; scale: 0.75; }
.bloom:nth-child(3) { animation-delay: 0.04s; --dx: 42px; }
.bloom:nth-child(4) { animation-delay: 0.14s; --dx: -10px; scale: 0.6; }
.bloom:nth-child(5) { animation-delay: 0.1s; --dx: 22px; scale: 0.85; }

@keyframes drift {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -18px; }
}

@keyframes rise {
  0% { opacity: 0; transform: translate(0, 12px) rotate(-45deg) scale(0.4); }
  25% { opacity: 0.9; }
  100% { opacity: 0; transform: translate(var(--dx), -160px) rotate(-45deg) scale(1); }
}

.sheet.kind-cover .folio {
  color: rgba(246, 240, 230, 0.7);
}

.controls {
  width: min(40rem, 100%);
  display: grid;
  grid-template-columns: auto minmax(2rem, 1fr) auto;
  align-items: center;
  gap: 0.7rem;
}

.btn {
  min-height: 48px;
  padding: 0 0.9rem;
  border-radius: 999px;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  font-family: var(--font-display);
  font-size: clamp(0.92rem, 3.5vw, 1rem);
  letter-spacing: 0.01em;
  background: transparent;
  color: var(--color-paper);
  white-space: nowrap;
}

.btn svg {
  width: 1.1rem;
  height: 1.1rem;
  flex: none;
}

.btn-prev {
  border-color: rgba(246, 240, 230, 0.38);
}

.btn-next {
  background: var(--color-rose);
  color: var(--color-on-rose);
  border-color: var(--color-rose);
}

.btn-next.is-ready {
  box-shadow: 0 0 0 4px rgba(154, 61, 77, 0.28);
}

.btn:disabled {
  opacity: 0.38;
  cursor: default;
  box-shadow: none;
}

.btn:focus-visible {
  outline: 2px solid var(--color-paper);
  outline-offset: 3px;
}

.meter {
  height: 2px;
  width: 100%;
  background: rgba(246, 240, 230, 0.28);
}

.meter > span {
  display: block;
  height: 100%;
  width: var(--p, 0%);
  background: var(--color-rose);
  transition: width 420ms var(--ease-page);
}

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

.sheet.turn-next {
  animation: leaveNext 640ms var(--ease-page) forwards;
}

.sheet.turn-prev {
  transform-origin: right center;
  animation: leavePrev 640ms var(--ease-page) forwards;
}

.sheet.turn-in-next {
  animation: enterNext 460ms cubic-bezier(0.16, 0.84, 0.32, 1) both;
}

.sheet.turn-in-prev {
  transform-origin: right center;
  animation: enterPrev 460ms cubic-bezier(0.16, 0.84, 0.32, 1) both;
}

@keyframes leaveNext {
  0% { transform: rotateY(0deg); filter: brightness(1); }
  40% { filter: brightness(0.92); }
  100% { transform: rotateY(-78deg) translateX(-6%); opacity: 0; }
}

@keyframes enterNext {
  0% { transform: rotateY(62deg) translateX(5%); opacity: 0; }
  100% { transform: none; opacity: 1; }
}

@keyframes leavePrev {
  0% { transform: rotateY(0deg); }
  100% { transform: rotateY(78deg) translateX(6%); opacity: 0; }
}

@keyframes enterPrev {
  0% { transform: rotateY(-62deg) translateX(-5%); opacity: 0; }
  100% { transform: none; opacity: 1; }
}

@keyframes blink {
  50% { opacity: 0; }
}

@media (max-height: 760px) {
  .sheet.kind-cover .frame img,
  .frame img {
    height: 9.2rem;
  }

  .ribbon {
    height: 52px;
  }

  .writing p {
    font-size: 1rem;
  }
}

@media (min-width: 840px) {
  .desk {
    padding: 1.4rem 1.5rem 1.8rem;
  }

  .sheet {
    padding: 2.1rem 2.3rem 1.4rem 2.5rem;
  }

  .sheet.kind-cover {
    padding-top: 2.2rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .float-heart,
  .bloom,
  .sheet.turn-next,
  .sheet.turn-prev,
  .sheet.turn-in-next,
  .sheet.turn-in-prev,
  .caret,
  .meter > span {
    animation: none;
    transition: none;
  }
}
