@font-face {
  font-family: "Cormorant Garamond";
  src: url('assets/fonts/CormorantGaramond-Medium.woff2') format('woff2');
  font-weight: 500;
  font-display: swap;
}

.book-opening {
  position: absolute;
  z-index: 3;
  inset: 0 0 auto;
  aspect-ratio: var(--map-ratio, 1.75);
  isolation: isolate;
  --cover-gold: #e6ce99;
  --cover-latin: "Cormorant Garamond", Georgia, serif;
  --cover-font: var(--hand);
}

html[lang^='en'] .book-opening { --cover-font: var(--cover-latin); }

.opening-book {
  position: absolute;
  inset: 8% 12%;
}

.opening-pages {
  position: absolute;
  inset: 0;
  display: flex;
  perspective: max(900px, 160vw);
  perspective-origin: center;
  filter: drop-shadow(0 13px 18px #0008);
  pointer-events: none;
}

.opening-paper {
  width: 50%;
  background: #e9dbbb url('assets/open-novel-blank-v01.webp') 7% center / 216% 112% no-repeat;
}

.opening-paper-left {
  --fold-angle: 66deg;
  border-radius: 3px 0 0 4px;
  transform-origin: right center;
}

.opening-paper-right {
  --fold-angle: -66deg;
  border-radius: 0 3px 4px 0;
  background-position-x: 93%;
  transform-origin: left center;
}

.opening-front {
  /* The front is a portrait plate; only the opening spread follows the map. */
  position: fixed;
  top: calc(50svh + 24px);
  left: 50%;
  width: min(calc(100vw - 32px), calc((100svh - 140px) * 2 / 3));
  transform: translate(-50%, -50%);
  display: grid;
  justify-items: center;
  gap: 12px;
}

.opening-cover {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-radius: 2px 6px 6px 2px;
  padding: 9% 6% 0;
  overflow: hidden;
  border: 1px solid #62819d66;
  background:
    linear-gradient(90deg, #11212bdd 0, #11212b22 1.4%, #1c516f55 2.4%, #0e2636b0 3%, transparent 5.4%),
    repeating-linear-gradient(0deg, #a3c1c513 0 1px, transparent 1px 3px),
    repeating-linear-gradient(88deg, #0c203280 0 1px, transparent 1px 4px),
    radial-gradient(ellipse at 40% 24%, #274d64, #172f42 72%);
  box-shadow: inset -3px 0 #10263490, inset 0 -4px #0e202fb3, 3px 9px 24px #0009;
  color: var(--cover-gold);
}

.opening-cover::before {
  position: absolute;
  z-index: 1;
  inset: 4% 3% 5% 5%;
  border: 3px double #d7b279a6;
  border-radius: 1px 4px 4px 1px;
  content: '';
  pointer-events: none;
}

.opening-cover[data-illustrated] {
  padding-top: 9%;
}

.opening-cover[data-illustrated]::after {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, #091820b8, #09182083 24%, transparent 53%),
    linear-gradient(90deg, #081117ce, transparent 6%),
    var(--cover-art) center / contain no-repeat;
  content: '';
  pointer-events: none;
}

.opening-title, .opening-cover-subtitle {
  position: relative;
  z-index: 2;
  margin: 0;
  text-align: center;
  text-shadow: 0 1px #0d2635;
}

.opening-title {
  max-width: 80%;
  font-family: var(--cover-font);
  font-size: clamp(20px, 4.3vw, 60px);
  font-weight: 400;
  letter-spacing: .08em;
  line-height: 1.08;
  text-wrap: balance;
}

.opening-title:lang(zh) {
  max-width: 100%;
  font-size: clamp(16px, 17cqw, 60px);
  letter-spacing: .06em;
}

html[lang^='en'] .opening-title {
  font-size: clamp(18px, 10cqw, 50px);
  font-weight: 500;
  letter-spacing: .025em;
}

.opening-cover-subtitle {
  margin-top: 12px;
  color: #e6ce99e6;
  font-family: var(--cover-latin);
  font-weight: 500;
  font-size: clamp(11px, 3cqw, 15px);
  letter-spacing: .23em;
  line-height: 1.4;
}

.opening-start {
  display: grid;
  place-items: center;
  min-height: 44px;
  padding: 7px 20px;
  border: 1px solid #d7b279c9;
  border-radius: 2px;
  background: #0a2433ef;
  color: #ffedc6;
  font-family: var(--cover-font);
  font-size: clamp(16px, 1.5vw, 22px);
  line-height: 1;
  letter-spacing: .1em;
  width: max-content;
  max-width: 100%;
  text-align: center;
}

.opening-start:hover { background: #214b62; }
html[lang^='en'] .opening-start { font-weight: 500; }

.world-window:is([data-book-entry='loading'], [data-book-entry='closed'], [data-book-entry='starting'], [data-book-entry='turning'], [data-book-entry='spread']) .world-visual {
  opacity: 0;
}

.world-window:is([data-book-entry='revealing'], [data-book-entry='zooming']) .world-visual {
  position: relative;
  z-index: 4;
  pointer-events: none;
}

.world-window:is([data-book-entry='revealing'], [data-book-entry='zooming']) .world-visual::after {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 48%, #33200d55 50%, #fff2cc2b 50.7%, transparent 52%);
  content: '';
  pointer-events: none;
}

.world-window[data-book-entry]:not([data-book-entry='open']) .world-locations {
  opacity: 0;
  pointer-events: none;
}

.world-stage:has(.world-window[data-book-entry]:not([data-book-entry='open'])) .world-hint {
  visibility: hidden;
}

.world-stage:has(.world-window[data-book-entry]:not([data-book-entry='open']))::before,
.stage:has(.world-window[data-book-entry]:not([data-book-entry='open'])) .topbar .wordmark {
  opacity: 0;
}

[data-book-entry]:not([data-book-entry='closed']) .opening-start { visibility: hidden; }
[data-book-entry]:not([data-book-entry='closed']):not([data-book-entry='starting']) .opening-front { display: none; }
[data-book-entry='closed'] .opening-pages { opacity: 0; }
[data-book-entry='starting'] .opening-cover { animation: leave-cover .16s ease both; }
[data-book-entry='starting'] .opening-pages { animation: reveal-atlas .16s ease both; }
[data-book-entry='starting'] .opening-paper {
  transform: rotateY(var(--fold-angle));
  filter: brightness(.88);
}
[data-book-entry='turning'] .opening-paper { animation: unfold-paper 1.65s cubic-bezier(.32, .05, .22, 1) both; }
[data-book-entry='spread'] .opening-pages { animation: settle-paper .36s ease-out both; }
[data-book-entry='revealing'] .world-visual { animation: reveal-atlas .95s ease-in-out both; }
[data-book-entry='zooming'] .world-visual { animation: expand-atlas 1.15s cubic-bezier(.37, 0, .2, 1) both; }
[data-book-entry='zooming'] .world-visual::after,
[data-book-entry='zooming'] .opening-pages { animation: leave-paper 1.15s ease-out both; }
.world-stage:has([data-book-entry='zooming'])::before { animation: atlas-backdrop 1.15s ease-out both; }

@keyframes leave-cover {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes unfold-paper {
  from { transform: rotateY(var(--fold-angle)); filter: brightness(.88); }
  to { transform: rotateY(0deg); filter: brightness(1); }
}

@keyframes settle-paper {
  from { filter: drop-shadow(0 13px 18px #0009); }
  to { filter: drop-shadow(0 13px 18px #0008); }
}

@keyframes reveal-atlas {
  from { opacity: 0; }
  to { opacity: 1; }
}

[data-book-entry='revealing'] .world-visual {
  transform: translateY(var(--opening-offset, 0px)) scale(var(--atlas-page-scale, .64));
}

@keyframes expand-atlas {
  from { transform: translateY(var(--opening-offset, 0px)) scale(var(--atlas-page-scale, .64)); }
  to { transform: scale(1); }
}

@keyframes atlas-backdrop {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes leave-paper {
  0%, 18% { opacity: 1; }
  to { opacity: 0; }
}

@media (max-width: 600px) {
  .opening-book { inset: 3% 5%; }
  .opening-cover-subtitle { margin-top: 8px; letter-spacing: .14em; }
  .opening-start { font-size: 16px; letter-spacing: .06em; }
}

@media (max-width: 760px) and (orientation: portrait) {
  .world-stage:not(.indexed-atlas) .world-window {
    --opening-offset: max(0px, calc(44svh - 50vw / var(--map-ratio, 1.75) - 88px));
    --atlas-page-scale: .74;
  }
  .world-stage:not(.indexed-atlas) .opening-pages { translate: 0 var(--opening-offset, 0px); }
}

@media (prefers-reduced-motion: reduce) {
  [data-book-entry] :is(.opening-cover, .opening-pages, .opening-paper, .world-visual),
  [data-book-entry] .world-visual::after { animation: none; }
}
