:root {
  color: #4a3528;
  background: #e4d5bd;
  font-family: Georgia, "Times New Roman", serif;
  font-synthesis: none;
  --page-width: 480;
  --page-height: 640;
  --ink: #3d2a20;
  --espresso: #2b1b16;
  --cocoa: #4a2e24;
  --camel: #9a7254;
  --cream: #efe3ce;
  --paper: #eee2cf;
  --gold: #c49d70;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background:
    linear-gradient(180deg, rgb(248 240 225 / 42%), rgb(193 164 127 / 18%)),
    url("assets/site-paper-bg.png") center / cover fixed no-repeat;
}

body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='grain'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.76' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23grain)' opacity='.12'/%3E%3C/svg%3E");
  content: "";
  mix-blend-mode: multiply;
  opacity: 0.16;
}

button {
  color: inherit;
  font: inherit;
}

.room {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 100dvh;
  padding: 24px clamp(16px, 3vw, 48px) 20px;
}

.book-header,
.controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  width: min(100%, 1180px);
  margin: 0 auto;
}

.book-header span {
  color: #765b45;
  font: 600 10px/1.2 Arial, sans-serif;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.book-header span:last-child {
  text-align: right;
}

.book-header h1 {
  margin: 0;
  color: #493326;
  font-size: 17px;
  font-weight: 400;
  letter-spacing: 0.04em;
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 20px 0;
  perspective: 1800px;
}

.stage::after {
  position: absolute;
  bottom: 7%;
  left: 50%;
  z-index: -1;
  width: min(82vw, 960px);
  height: 10%;
  border-radius: 50%;
  background: rgb(93 59 37 / 24%);
  content: "";
  filter: blur(30px);
  transform: translateX(-50%);
}

.book-rig {
  display: grid;
  place-items: center;
  width: min(100%, 960px);
  height: min(72dvh, 640px);
}

.book {
  position: relative;
  isolation: isolate;
  filter: drop-shadow(0 28px 30px rgb(76 48 30 / 26%));
}

.book:not(.stf__parent) {
  width: min(78vw, 480px);
  height: min(72dvh, 640px);
  aspect-ratio: 3 / 4;
}

.book-page {
  position: relative;
  overflow: hidden;
  display: none;
  background: var(--paper);
  color: var(--ink);
}

.book:not(.stf__parent) .book-page {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.book:not(.stf__parent) .book-page:first-child,
.book:not(.stf__parent) .book-page.fallback-visible {
  display: block;
}

.book:not(.stf__parent) .book-page.fallback-visible.cover,
.book:not(.stf__parent) .book-page.fallback-visible.title-page,
.book:not(.stf__parent) .book-page.fallback-visible.closing-page,
.book:not(.stf__parent) .book-page.fallback-visible.inside-cover,
.book:not(.stf__parent) .book-page.fallback-visible.back-cover {
  display: flex;
}

.book:not(.stf__parent) .book-page.fallback-visible {
  z-index: 2;
  opacity: 1;
  transform: none;
}

.book:not(.stf__parent) .book-page.fallback-enter,
.book:not(.stf__parent) .book-page.fallback-leave {
  display: block;
  z-index: 4;
  animation-duration: 560ms;
  animation-fill-mode: both;
  backface-visibility: hidden;
  transform-style: preserve-3d;
}

.book:not(.stf__parent) .book-page.fallback-enter {
  animation-name: fallback-enter-next;
  transform-origin: left center;
}

.book:not(.stf__parent) .book-page.fallback-leave {
  z-index: 3;
  animation-name: fallback-leave-next;
  transform-origin: left center;
}

.book:not(.stf__parent) .book-page.fallback-enter.fallback-back {
  animation-name: fallback-enter-back;
  transform-origin: right center;
}

.book:not(.stf__parent) .book-page.fallback-leave.fallback-back {
  animation-name: fallback-leave-back;
  transform-origin: right center;
}

@keyframes fallback-enter-next {
  from { opacity: 0; transform: rotateY(-82deg); }
  to { opacity: 1; transform: rotateY(0deg); }
}

@keyframes fallback-leave-next {
  from { opacity: 1; transform: rotateY(0deg); }
  to { opacity: 0; transform: rotateY(82deg); }
}

@keyframes fallback-enter-back {
  from { opacity: 0; transform: rotateY(82deg); }
  to { opacity: 1; transform: rotateY(0deg); }
}

@keyframes fallback-leave-back {
  from { opacity: 1; transform: rotateY(0deg); }
  to { opacity: 0; transform: rotateY(-82deg); }
}

.book-page.--left::before,
.book-page.--right::before {
  position: absolute;
  inset-block: 0;
  z-index: 3;
  width: clamp(14px, 4%, 28px);
  content: "";
  pointer-events: none;
}

.book-page.--left::before {
  right: 0;
  background: linear-gradient(to left, rgb(27 16 12 / 38%), rgb(27 16 12 / 11%) 42%, transparent);
}

.book-page.--right::before {
  left: 0;
  background: linear-gradient(to right, rgb(27 16 12 / 38%), rgb(27 16 12 / 11%) 42%, transparent);
}

.cover,
.back-cover {
  background:
    radial-gradient(circle at 52% 42%, rgb(144 97 67 / 22%), transparent 37%),
    linear-gradient(145deg, #3b251c, #1f1411 72%);
  color: var(--cream);
}

.cover {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 34px 34px 28px;
}

.cover--front {
  padding: 0;
  background: var(--paper);
}

.cover-topline,
.cover-footer {
  display: flex;
  justify-content: space-between;
  color: #c4a681;
  font: 600 9px/1.2 Arial, sans-serif;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.cover-center {
  margin-top: 22px;
}

.cover-mark {
  display: grid;
  width: 44px;
  height: 44px;
  margin: 0 0 70px;
  place-items: center;
  border: 1px solid rgb(236 220 193 / 65%);
  border-radius: 50%;
  color: #e9d5b2;
  font: 600 10px Arial, sans-serif;
  letter-spacing: 0.15em;
}

.kicker,
.folio,
.photo-label,
.page-number {
  font-family: Arial, sans-serif;
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.cover .kicker {
  margin: 0 0 14px;
  color: #c9a97e;
}

.cover h2 {
  margin: 0;
  color: #f1e2cb;
  font-size: 58px;
  font-weight: 400;
  line-height: 0.88;
  letter-spacing: -0.045em;
}

.cover-subtitle {
  margin: 20px 0 0;
  color: #c8a67b;
  font: 10px Arial, sans-serif;
  letter-spacing: 0.24em;
  text-transform: uppercase;
}

.title-page,
.closing-page {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 54px 46px;
  background:
    radial-gradient(circle at 88% 18%, rgb(177 125 84 / 22%), transparent 36%),
    linear-gradient(145deg, #e9dbc2, #c9b394);
}

.title-page__rule {
  width: 62px;
  height: 1px;
  margin-bottom: 28px;
  background: #8e6549;
}

.title-page .kicker,
.closing-page .kicker {
  margin: 0 0 15px;
  color: #7d5943;
}

.title-page h2,
.closing-page h2 {
  margin: 0;
  color: #3e2a20;
  font-size: 35px;
  font-weight: 400;
  line-height: 1.03;
  letter-spacing: -0.03em;
}

.title-page__note,
.closing-page__note {
  max-width: 250px;
  margin: 24px 0 0;
  color: #71533f;
  font: 12px/1.65 Arial, sans-serif;
}

.photo-page,
.art-page {
  background: var(--paper);
}

.photo-page img,
.art-page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.heart-page {
  background:
    linear-gradient(180deg, rgb(247 238 222 / 34%), rgb(236 217 190 / 18%)),
    url("assets/site-paper-bg.png") center / cover no-repeat;
  color: var(--ink);
}

.heart-page canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.heart-page__veil {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(to top, rgb(238 219 192 / 68%), transparent 30%),
    radial-gradient(circle at 50% 44%, transparent 20%, rgb(137 91 59 / 13%) 100%);
}

.heart-page__content {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 34px;
  pointer-events: none;
}

.heart-page__eyebrow,
.heart-page__hint,
.heart-page__folio {
  margin: 0;
  color: #79553c;
  font: 600 8px/1.3 Arial, sans-serif;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.heart-page h2 {
  margin: 14px 0 18px;
  color: #533426;
  font-size: 32px;
  font-weight: 400;
  line-height: 0.96;
  letter-spacing: -0.04em;
}

.heart-page__hint {
  color: rgb(91 62 43 / 74%);
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: none;
}

.heart-page__folio {
  position: absolute;
  right: 24px;
  bottom: 21px;
  color: #8c6549;
  font-size: 8px;
}

.photo-label {
  position: absolute;
  right: 20px;
  bottom: 19px;
  left: 20px;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  color: rgb(248 235 214 / 84%);
  font-size: 8px;
  text-shadow: 0 1px 8px rgb(0 0 0 / 30%);
}

.photo-label--light::before {
  position: absolute;
  right: 0;
  bottom: 18px;
  left: 0;
  height: 1px;
  background: rgb(248 235 214 / 42%);
  content: "";
}

.closing-page__ornament {
  margin-bottom: 55px;
  color: #9b6e4f;
  font-size: 20px;
}

.closing-page__note {
  max-width: 220px;
  margin-top: 26px;
}

.page-number {
  position: absolute;
  right: 24px;
  bottom: 21px;
  z-index: 3;
  margin: 0;
  color: #785640;
}

.inside-cover {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 32px;
  background:
    linear-gradient(145deg, rgb(255 244 221 / 35%), transparent 55%),
    #b9946f;
  color: #3b241a;
}

.inside-cover__type {
  margin: 0 0 36px;
  font: 600 9px Arial, sans-serif;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.inside-cover__line {
  margin: 0;
  font-size: 22px;
  line-height: 1.02;
}

.back-cover {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 34px;
}

.back-cover__rule {
  width: 50px;
  height: 1px;
  margin-bottom: 18px;
  background: #c7a274;
}

.back-cover p,
.back-cover span {
  margin: 0;
  color: #d8c1a1;
  font: 9px/1.4 Arial, sans-serif;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.back-cover span {
  margin-top: 6px;
  color: #977453;
  font-size: 8px;
}

.controls {
  grid-template-columns: 48px 1fr 48px;
  max-width: 440px;
}

.controls button {
  width: 44px;
  height: 38px;
  border: 1px solid rgb(88 59 39 / 34%);
  border-radius: 50%;
  background: rgb(247 239 224 / 68%);
  color: #4b3528;
  cursor: pointer;
  transition: background 180ms ease, border-color 180ms ease, transform 180ms ease;
}

.controls button:hover:not(:disabled) {
  border-color: rgb(88 59 39 / 72%);
  background: rgb(255 248 235 / 86%);
  transform: translateY(-1px);
}

.controls button:disabled {
  cursor: default;
  opacity: 0.28;
}

.status {
  display: grid;
  gap: 5px;
  text-align: center;
}

.status span {
  color: #4d372a;
  font: 600 10px Arial, sans-serif;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.status small {
  color: #725946;
  font: 9px Arial, sans-serif;
}

@media (max-width: 700px) {
  .room {
    padding: 18px 10px 14px;
  }

  .book-header {
    grid-template-columns: 1fr auto;
  }

  .book-header .header-quiet {
    display: none;
  }

  .book-header h1 {
    font-size: 15px;
  }

  .book-rig {
    height: min(72dvh, 640px);
  }

}

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

@media print {
  body {
    overflow: visible;
    background: white;
  }

  .book-header,
  .controls {
    display: none;
  }
}
