:root {
  --page-bg: #f4ead5;
  --page-bg-dark: #e8dcc4;
  --page-border: rgba(120, 90, 50, 0.25);
  --page-shadow: rgba(0, 0, 0, 0.35);
  --text-primary: #2c2416;
  --text-secondary: #5c4f3a;
  --accent: #8b6914;
  --flip-duration: 0.6s;
  --open-duration: 0.45s;
}

body {
  font-family: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color: var(--text-primary);
  background: #1a1510;
  overflow: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(60, 45, 30, 0.4) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 80%, rgba(40, 30, 20, 0.5) 0%, transparent 50%),
    #1a1510;
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 0;
  padding: 0.5rem;
  overflow: hidden;
  container-type: size;
  container-name: stage;
}

.book-wrapper {
  perspective: 2500px;
  perspective-origin: 50% 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
}

.book {
  position: relative;
  transform-style: preserve-3d;
  aspect-ratio: 1440 / 520;
  width: min(96cqw, 1440px, calc(100cqh * 1440 / 520));
  height: min(100cqh, 520px, calc(96cqw * 520 / 1440));
  max-width: 100%;
  max-height: 100%;
}

.book-board {
  position: absolute;
  left: 0;
  top: 0;
  width: 50%;
  height: 100%;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.04) 0%, transparent 40%),
    linear-gradient(180deg, #2a1f14 0%, #1a1510 50%, #120e0a 100%);
  border: 1px solid rgba(80, 60, 40, 0.5);
  border-right: none;
  box-shadow: inset -4px 0 12px rgba(0, 0, 0, 0.3);
  z-index: 1;
  transition: opacity 0.35s ease, background 0.35s ease;
}

.book:not(.book--show-board) .book-board {
  opacity: 0;
  pointer-events: none;
}

.book--open.book--show-board .book-board {
  background:
    linear-gradient(225deg, rgba(139, 105, 20, 0.05) 0%, transparent 50%),
    var(--page-bg-dark);
  border-color: var(--page-border);
  box-shadow: inset -2px 0 8px rgba(0, 0, 0, 0.06);
}

.book--open.book--show-board .book-board::after {
  content: none;
}

.book-cover {
  position: absolute;
  right: 0;
  top: 0;
  width: 50%;
  height: 100%;
  z-index: 150;
  background: var(--page-bg);
  border: 1px solid var(--page-border);
  border-left: none;
  box-shadow:
    inset 0 0 30px rgba(120, 90, 50, 0.08),
    2px 2px 12px var(--page-shadow);
  transform-origin: left center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transition:
    transform var(--open-duration) ease-in-out,
    opacity var(--open-duration) ease;
}

.book--closed .book-cover {
  transform: rotateY(0deg);
  opacity: 1;
  pointer-events: auto;
  cursor: pointer;
}

.book--opening .book-cover,
.book--open .book-cover {
  transform: rotateY(-105deg);
  opacity: 0;
  pointer-events: none;
}

.book--closing .book-cover {
  transform: rotateY(0deg);
  opacity: 1;
  transition:
    transform var(--open-duration) ease-in-out,
    opacity calc(var(--open-duration) * 0.6) ease;
}

.book--closed .pages {
  pointer-events: none;
}

.book-spine {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 10px;
  transform: translateX(-50%);
  background: linear-gradient(
    90deg,
    rgba(0, 0, 0, 0.35) 0%,
    rgba(60, 45, 30, 0.5) 35%,
    rgba(120, 90, 50, 0.15) 50%,
    rgba(60, 45, 30, 0.5) 65%,
    rgba(0, 0, 0, 0.35) 100%
  );
  z-index: 200;
  pointer-events: none;
}

.pages {
  position: relative;
  transform-style: preserve-3d;
  width: 100%;
  height: 100%;
  z-index: 2;
}

.page {
  position: absolute;
  top: 0;
  left: 50%;
  width: 50%;
  height: 100%;
  transform-style: preserve-3d;
  transform-origin: left center;
  transition: transform var(--flip-duration) ease-in-out;
  will-change: transform;
}

.book--closed-back::after {
  content: "";
  position: absolute;
  right: 0;
  top: 0;
  width: 50%;
  height: 100%;
  background:
    linear-gradient(225deg, rgba(255, 255, 255, 0.04) 0%, transparent 40%),
    linear-gradient(180deg, #2a1f14 0%, #1a1510 50%, #120e0a 100%);
  border: 1px solid rgba(80, 60, 40, 0.5);
  border-left: none;
  box-shadow: inset 4px 0 12px rgba(0, 0, 0, 0.3);
  z-index: 1;
}

.page.flipping .page-face--front {
  box-shadow:
    inset 0 0 30px rgba(120, 90, 50, 0.08),
    -8px 4px 20px rgba(0, 0, 0, 0.35);
}

.page.flipped {
  transform: rotateY(-180deg);
}

.page.flipping {
  z-index: 300 !important;
  pointer-events: none;
}

.page-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--page-bg);
  border: 1px solid var(--page-border);
  box-shadow:
    inset 0 0 30px rgba(120, 90, 50, 0.08),
    2px 2px 8px var(--page-shadow);
  overflow: hidden;
}

.page-face--front {
  border-left: none;
}

.page-face--back {
  transform: rotateY(180deg);
  background: var(--page-bg-dark);
  border-right: none;
}

.page-num {
  position: absolute;
  bottom: 0.6rem;
  font-family: "Songti SC", "Noto Serif SC", serif;
  font-size: 0.65rem;
  color: var(--text-secondary);
  opacity: 0.55;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.page-face--front .page-num {
  right: 0.75rem;
}

.page-face--back .page-num {
  left: 0.75rem;
}

.page-content {
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
}

.page-content--cover {
  align-items: center;
  justify-content: center;
  text-align: center;
  background:
    linear-gradient(135deg, rgba(139, 105, 20, 0.08) 0%, transparent 50%),
    var(--page-bg);
}

.page-content--cover .cover-emblem {
  width: 80px;
  height: 80px;
  margin-bottom: 1.5rem;
  opacity: 0.7;
}

.page-content--cover h1 {
  font-family: "Songti SC", "Noto Serif SC", "STSong", serif;
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 600;
  letter-spacing: 0.15em;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.page-content--cover .cover-subtitle {
  font-size: clamp(0.85rem, 2.5vw, 1rem);
  color: var(--text-secondary);
  letter-spacing: 0.3em;
  margin-bottom: 2rem;
}

.page-content--cover .cover-hint {
  font-size: 0.8rem;
  color: var(--text-secondary);
  opacity: 0.7;
  margin-top: auto;
}

.page-content--endpaper {
  background: var(--page-bg-dark);
}

.page-content--image {
  padding: 1rem;
  align-items: center;
  justify-content: center;
}

.page-content--image .specimen-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 2px;
}

.page-content--image .specimen-label {
  position: absolute;
  bottom: 1rem;
  left: 1rem;
  right: 1rem;
  text-align: center;
  font-family: "Songti SC", "Noto Serif SC", serif;
  font-size: 0.85rem;
  color: var(--text-secondary);
  letter-spacing: 0.1em;
}

.page-content--story {
  padding: clamp(0.6rem, 1.5vw, 1rem);
  overflow: hidden;
  min-height: 0;
}

.page-content--story .story-header {
  flex-shrink: 0;
  margin-bottom: 0.35rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--page-border);
}

.page-content--story .story-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.4rem;
  margin-bottom: 0.2rem;
}

.page-content--story h2 {
  font-family: "Songti SC", "Noto Serif SC", serif;
  font-size: clamp(0.95rem, 2.5vw, 1.25rem);
  font-weight: 600;
  margin: 0;
  line-height: 1.25;
  flex: 1;
  min-width: 0;
}

.page-content--story .story-theme {
  flex-shrink: 0;
  font-size: 0.68rem;
  color: var(--accent);
  letter-spacing: 0.06em;
  padding: 0.12rem 0.4rem;
  border: 1px solid rgba(139, 105, 20, 0.3);
  border-radius: 2px;
  white-space: nowrap;
}

.page-content--story .story-meta {
  margin: 0;
  font-size: 0.68rem;
  line-height: 1.35;
  color: var(--text-secondary);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2rem 0.35rem;
}

.page-content--story .story-latin {
  font-style: italic;
}

.page-content--story .story-sep {
  opacity: 0.45;
}

.page-content--story .story-habitat {
  flex: 1;
  min-width: 0;
}

.page-content--story .story-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  font-size: clamp(0.78rem, 1.8vw, 0.9rem);
  line-height: 1.7;
  color: var(--text-primary);
  text-align: justify;
  padding-right: 0.15rem;
}

.page-content--story .story-body::-webkit-scrollbar {
  width: 4px;
}

.page-content--story .story-body::-webkit-scrollbar-thumb {
  background: rgba(120, 90, 50, 0.3);
  border-radius: 2px;
}

.page-content--back {
  align-items: center;
  justify-content: center;
  text-align: center;
  background:
    linear-gradient(225deg, rgba(139, 105, 20, 0.06) 0%, transparent 50%),
    var(--page-bg-dark);
}

.page-content--back p {
  font-family: "Songti SC", "Noto Serif SC", serif;
  font-size: 0.9rem;
  color: var(--text-secondary);
  letter-spacing: 0.2em;
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --flip-duration: 0.01s;
  }

  .page {
    transition: none;
  }
}
