/* Canis — novel book theme */

@import url("https://fonts.googleapis.com/css2?family=Literata:ital,opsz,wght@0,7..72,400;0,7..72,600;1,7..72,400&display=swap");

:root {
  --paper: #f4ecd8;
  --paper-shadow: #e8dcc4;
  --ink: #2c2416;
  --ink-muted: #5c4f3a;
  --accent: #6b5344;
  --page-width: 42rem;
  --flip-duration: 520ms;
  --font-serif: "Literata", Georgia, "Times New Roman", serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 18px;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-serif);
  color: var(--ink);
  background-color: var(--paper-shadow);
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(255, 252, 245, 0.6) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(180, 160, 130, 0.15) 0%, transparent 45%),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(120, 100, 70, 0.02) 2px,
      rgba(120, 100, 70, 0.02) 4px
    );
  line-height: 1.65;
}

.book-shell {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  padding: 2rem 1rem 3rem;
}

.book-shell--home {
  align-items: center;
}

.book-page {
  width: 100%;
  max-width: var(--page-width);
  background: var(--paper);
  padding: 2.5rem 2.75rem 2rem;
  border-radius: 2px;
  box-shadow:
    0 1px 2px rgba(44, 36, 22, 0.06),
    0 8px 24px rgba(44, 36, 22, 0.12),
    0 24px 48px rgba(44, 36, 22, 0.08);
  transform-style: preserve-3d;
  transform-origin: left center;
  transition: box-shadow 0.3s ease;
}

.book-page.is-flipping {
  pointer-events: none;
}

/* 3D page flip — forward = next chapter (page turns left) */
.book-page.page-flip-out-forward {
  animation: flipOutForward var(--flip-duration) ease-in-out forwards;
}

.book-page.page-flip-out-back {
  animation: flipOutBack var(--flip-duration) ease-in-out forwards;
}

.book-page.page-flip-in-forward {
  animation: flipInForward var(--flip-duration) ease-in-out forwards;
}

.book-page.page-flip-in-back {
  animation: flipInBack var(--flip-duration) ease-in-out forwards;
}

@keyframes flipOutForward {
  0% {
    transform: perspective(1400px) rotateY(0deg);
    opacity: 1;
  }
  100% {
    transform: perspective(1400px) rotateY(-88deg);
    opacity: 0.3;
  }
}

@keyframes flipOutBack {
  0% {
    transform: perspective(1400px) rotateY(0deg);
    opacity: 1;
  }
  100% {
    transform: perspective(1400px) rotateY(88deg);
    opacity: 0.3;
  }
}

@keyframes flipInForward {
  0% {
    transform: perspective(1400px) rotateY(88deg);
    opacity: 0.3;
  }
  100% {
    transform: perspective(1400px) rotateY(0deg);
    opacity: 1;
  }
}

@keyframes flipInBack {
  0% {
    transform: perspective(1400px) rotateY(-88deg);
    opacity: 0.3;
  }
  100% {
    transform: perspective(1400px) rotateY(0deg);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .book-page.page-flip-out-forward,
  .book-page.page-flip-out-back,
  .book-page.page-flip-in-forward,
  .book-page.page-flip-in-back {
    animation: none;
  }
}

/* Home / cover */
.book-cover {
  text-align: center;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid rgba(44, 36, 22, 0.12);
}

.book-title {
  margin: 0 0 0.5rem;
  font-size: 2.25rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.book-subtitle {
  margin: 0;
  font-size: 1rem;
  font-style: italic;
  color: var(--ink-muted);
}

.book-toc__heading {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-muted);
  margin: 0 0 1rem;
}

.book-toc__list {
  margin: 0;
  padding-left: 1.25rem;
}

.book-toc__list li {
  margin-bottom: 0.5rem;
}

.book-toc__list a {
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}

.book-toc__list a:hover {
  border-bottom-color: var(--accent);
}

.book-begin {
  text-align: center;
  margin-top: 2rem;
}

.book-begin__button {
  display: inline-block;
  padding: 0.65rem 1.5rem;
  font-family: var(--font-serif);
  font-size: 1rem;
  color: var(--paper);
  background: var(--ink);
  text-decoration: none;
  border-radius: 2px;
  transition: background 0.2s;
}

.book-begin__button:hover {
  background: var(--accent);
}

/* Chapter content */
.chapter-header {
  margin-bottom: 1.75rem;
}

.chapter-meta {
  margin: 0 0 0.25rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-muted);
}

.chapter-title {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.25;
}

.chapter-body p {
  margin: 0 0 1rem;
  text-align: justify;
  hyphens: auto;
}

.chapter-body > p:first-of-type::first-letter {
  float: left;
  font-size: 3.2rem;
  line-height: 0.85;
  padding: 0.08em 0.12em 0 0;
  font-weight: 600;
  color: var(--accent);
}

.chapter-body hr {
  border: none;
  text-align: center;
  margin: 2rem 0;
  color: var(--ink-muted);
}

.chapter-body hr::before {
  content: "§";
  font-size: 1rem;
  letter-spacing: 0.5em;
}

.chapter-body em {
  font-style: italic;
}

/* Chapter opener vignette (optional frontmatter) */
.chapter-vignette {
  margin: 0 0 1.75rem;
  text-align: center;
}

.chapter-body .chapter-vignette img {
  max-width: 72%;
  height: auto;
  border: 1px solid rgba(44, 36, 22, 0.12);
  border-radius: 1px;
}

/* Inline images in chapter body (excludes opener vignette) */
.chapter-body p img,
.chapter-body figure:not(.chapter-vignette) img {
  max-width: 100%;
  height: auto;
  display: block;
  margin-left: auto;
  margin-right: auto;
}

.chapter-body figure:not(.chapter-vignette) {
  margin: 1.5rem 0;
  text-align: center;
}

.chapter-body figcaption {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  font-style: italic;
  color: var(--ink-muted);
}

.chapter-body p:has(> img:only-child) {
  text-align: center;
}

/* Navigation */
.book-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid rgba(44, 36, 22, 0.1);
  font-size: 0.9rem;
}

.book-nav__link {
  color: var(--ink-muted);
  text-decoration: none;
  transition: color 0.2s;
}

.book-nav__link:hover:not(.book-nav__link--disabled) {
  color: var(--ink);
}

.book-nav__link--contents {
  flex-shrink: 0;
}

.book-nav__link--disabled {
  opacity: 0.35;
  cursor: default;
}

/* Loading state */
.book-page.is-loading {
  opacity: 0.85;
}
