/* ─── Reset & Base ──────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #FDFAF5;
  --bg2:       #F5EEE3;
  --ink:       #1C1714;
  --ink2:      #3A3028;
  --muted:     #7A706A;
  --gold:      #7A5F35;
  --gold-lt:   #C4A87C;
  --border:    #DDD5C8;
  --nav-h:     72px;
  --max-w:     760px;
  --wide-w:    1100px;

  --font-head: 'Playfair Display', Georgia, serif;
  --font-body: 'Special Elite', 'Courier New', monospace;
  --font-type: 'Special Elite', 'Courier New', monospace;
}

/* MPA View Transitions — book page turn on navigation */
@view-transition {
  navigation: auto;
}

/* Old page: fold away to the left like turning a book page */
::view-transition-old(root) {
  animation: 420ms cubic-bezier(0.4, 0, 1, 0.6) both book-page-out;
  transform-origin: left center;
}
/* New page: unfold in from the right */
::view-transition-new(root) {
  animation: 420ms cubic-bezier(0, 0.4, 0.6, 1) 380ms both book-page-in;
  transform-origin: left center;
}

@keyframes book-page-out {
  0%   { transform: perspective(1400px) rotateY(0deg);    opacity: 1;   }
  60%  { transform: perspective(1400px) rotateY(-60deg);  opacity: 0.6; }
  100% { transform: perspective(1400px) rotateY(-90deg);  opacity: 0;   }
}
@keyframes book-page-in {
  0%   { transform: perspective(1400px) rotateY(90deg);   opacity: 0;   }
  40%  { transform: perspective(1400px) rotateY(60deg);   opacity: 0.6; }
  100% { transform: perspective(1400px) rotateY(0deg);    opacity: 1;   }
}

/* Nav is a shared element — stays put during transitions */
.site-nav {
  view-transition-name: nav;
}
::view-transition-old(nav),
::view-transition-new(nav) {
  animation: none;
  mix-blend-mode: normal;
}

/* Poetry canvas persists across pages — don't flip it */
::view-transition-old(poetry-bg),
::view-transition-new(poetry-bg) {
  animation: none;
  mix-blend-mode: normal;
}

/* Reduced motion: simple crossfade instead */
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root) {
    animation: 200ms ease both vt-fade-out;
    transform-origin: unset;
  }
  ::view-transition-new(root) {
    animation: 200ms ease both vt-fade-in;
    transform-origin: unset;
  }
}
@keyframes vt-fade-out { to   { opacity: 0; } }
@keyframes vt-fade-in  { from { opacity: 0; } }

html {
  scroll-behavior: smooth;
  font-size: 18px;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.75;
  overflow-x: hidden;
  min-height: 100vh;
}

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

h1, h2, h3, h4, h5 {
  font-family: var(--font-head);
  line-height: 1.2;
  font-weight: 700;
}

a {
  color: var(--gold);
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: opacity 0.2s;
}
a:hover { opacity: 0.7; }

img { display: block; max-width: 100%; }

/* ─── Skip Link ─────────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100%;
  left: 12px;
  background: var(--ink);
  color: white;
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 0.85rem;
  text-decoration: none;
  z-index: 9999;
}
.skip-link:focus { top: 12px; }

/* ─── Navigation ─────────────────────────────────────── */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(253, 250, 245, 0.94);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border-bottom: 1px solid var(--border);
  height: var(--nav-h);
  display: flex;
  align-items: center;
  padding: 0 48px;
}

.nav-inner {
  width: 100%;
  max-width: var(--wide-w);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-name {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: 0.02em;
  transition: opacity 0.2s;
}
.nav-name:hover { opacity: 0.6; }

.nav-links {
  display: flex;
  gap: 36px;
  list-style: none;
  align-items: center;
}

.nav-links a {
  color: var(--muted);
  text-decoration: none;
  font-family: var(--font-body);
  font-size: 0.88rem;
  letter-spacing: 0.03em;
  position: relative;
  padding-bottom: 2px;
  transition: color 0.2s;
}
.nav-links a::after {
  content: '';
  position: absolute;
  bottom: -2px; left: 0;
  width: 0; height: 1px;
  background: var(--gold);
  transition: width 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.nav-links a:hover,
.nav-links a[aria-current="page"] { color: var(--ink); opacity: 1; }
.nav-links a[aria-current="page"]::after,
.nav-links a:hover::after { width: 100%; }

.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--ink);
  line-height: 1;
}

/* ─── Scroll-driven Animations ──────────────────────── */
@keyframes slide-up {
  from { opacity: 0; transform: translateY(36px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes slide-left {
  from { opacity: 0; transform: translateX(-28px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes slide-right {
  from { opacity: 0; transform: translateX(28px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes pop-in {
  from { opacity: 0; transform: scale(0.94); }
  to   { opacity: 1; transform: scale(1); }
}

/* CSS scroll-driven — no JS needed */
@supports (animation-timeline: view()) {
  .anim-up {
    animation: slide-up linear both;
    animation-timeline: view();
    animation-range: entry 0% entry 28%;
  }
  .anim-left {
    animation: slide-left linear both;
    animation-timeline: view();
    animation-range: entry 0% entry 28%;
  }
  .anim-right {
    animation: slide-right linear both;
    animation-timeline: view();
    animation-range: entry 0% entry 28%;
  }
  .anim-pop {
    animation: pop-in linear both;
    animation-timeline: view();
    animation-range: entry 0% entry 22%;
  }
}

/* Fallback: JS adds .is-visible and these kick in */
@supports not (animation-timeline: view()) {
  .anim-up, .anim-left, .anim-right, .anim-pop {
    opacity: 0;
    transition: opacity 0.7s ease, transform 0.7s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .anim-up     { transform: translateY(36px); }
  .anim-left   { transform: translateX(-28px); }
  .anim-right  { transform: translateX(28px); }
  .anim-pop    { transform: scale(0.94); }
  .anim-up.is-visible,
  .anim-left.is-visible,
  .anim-right.is-visible,
  .anim-pop.is-visible {
    opacity: 1;
    transform: none;
  }
}

/* Stagger delays for grid children */
.stagger-children > *:nth-child(1) { animation-delay: 0ms; }
.stagger-children > *:nth-child(2) { animation-delay: 80ms; }
.stagger-children > *:nth-child(3) { animation-delay: 160ms; }
.stagger-children > *:nth-child(4) { animation-delay: 240ms; }

/* ─── Hero Entrance Animations (load-triggered) ─────── */
@keyframes hero-word {
  from {
    opacity: 0;
    transform: translateY(28px) rotateX(12deg);
    filter: blur(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0) rotateX(0);
    filter: blur(0);
  }
}
@keyframes hero-fade {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

.hero-subtitle  { animation: hero-fade 0.6s ease both 0s; }
.hero-epigraph  { animation: hero-fade 0.7s ease both 1.9s; }
.hero-cta       { animation: hero-fade 0.6s ease both 2.2s; }
.hero-scroll    { animation: hero-fade 0.6s ease both 2.5s; }

/* ─── Typewriter cursor ─────────────────────────────── */
.type-cursor {
  display: inline-block;
  margin-left: 2px;
  animation: cursor-blink 0.75s step-end infinite;
  opacity: 1;
  transition: opacity 0.6s ease;
}
@keyframes cursor-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ─── Typewriter font — poem text ───────────────────── */
.poem-stanza,
.poem-text {
  font-family: var(--font-type);
  font-style: normal;
  font-size: 1rem;
  line-height: 2;
  color: var(--ink2);
  letter-spacing: 0.02em;
}

.section-label {
  font-family: var(--font-type);
  font-size: 0.7rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  display: block;
  margin-bottom: 16px;
}

/* ─── Stagger group (JS-driven) ─────────────────────── */
.stagger-item {
  opacity: 0;
  transform: translateY(28px);
  transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
.stagger-item.stagger-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ─── Ornamental Divider ────────────────────────────── */
.ornament {
  display: flex;
  align-items: center;
  gap: 20px;
  width: fit-content;
  margin: 0 auto;
}
.ornament::before,
.ornament::after {
  content: '';
  display: block;
  width: 80px;
  height: 1px;
  background: var(--gold-lt);
}
.ornament-glyph {
  color: var(--gold-lt);
  font-size: 1.1rem;
  line-height: 1;
}

/* ─── Buttons ───────────────────────────────────────── */
.btn {
  display: inline-block;
  padding: 13px 36px;
  background: var(--ink);
  color: white;
  text-decoration: none;
  font-family: var(--font-type);
  font-size: 0.82rem;
  letter-spacing: 0.1em;
  border: none;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  position: relative;
  overflow: hidden;
}
.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: white;
  opacity: 0;
  transition: opacity 0.15s;
}
.btn:hover {
  background: var(--ink2);
  opacity: 1;
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(28,23,20,0.2);
}
.btn:active { transform: translateY(0); box-shadow: none; }

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--border);
  padding: 12px 36px;
  display: inline-block;
  text-decoration: none;
  font-family: var(--font-type);
  font-size: 0.82rem;
  letter-spacing: 0.1em;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.btn-ghost:hover {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
  opacity: 1;
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(28,23,20,0.15);
}

/* ─── Page Header (inner pages) ─────────────────────── */
.page-header {
  padding: 80px 24px 60px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.page-header h1 {
  font-size: clamp(2.2rem, 5vw, 3.5rem);
  margin-bottom: 12px;
  animation: hero-word 0.8s cubic-bezier(0.16, 1, 0.3, 1) both 0.05s;
}
.page-header .section-label {
  animation: hero-fade 0.5s ease both 0s;
}
.page-header p {
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 480px;
  margin: 0 auto;
  animation: hero-fade 0.6s ease both 0.2s;
}

/* ─── Content Wrappers ──────────────────────────────── */
.content-wrap {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 24px;
}
.content-wrap-wide {
  max-width: var(--wide-w);
  margin: 0 auto;
  padding: 0 48px;
}

/* ─── Footer ─────────────────────────────────────────── */
.site-footer {
  background: var(--ink);
  color: rgba(255,255,255,0.55);
  text-align: center;
  padding: 48px 24px;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  margin-top: 100px;
}
.site-footer .footer-name {
  display: block;
  font-family: var(--font-head);
  font-size: 1.05rem;
  color: rgba(255,255,255,0.85);
  margin-bottom: 10px;
  letter-spacing: 0.08em;
  text-decoration: none;
}
.site-footer .footer-links {
  display: flex;
  justify-content: center;
  gap: 24px;
  list-style: none;
  margin-bottom: 24px;
}
.site-footer .footer-links a {
  color: rgba(255,255,255,0.45);
  text-decoration: none;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  transition: color 0.2s;
}
.site-footer .footer-links a:hover { color: rgba(255,255,255,0.85); opacity: 1; }
.site-footer .footer-copy { font-size: 0.72rem; }
.footer-social {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 20px;
}
.footer-social a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.5);
  text-decoration: none;
  transition: border-color 0.2s, color 0.2s;
}
.footer-social a:hover {
  border-color: rgba(255,255,255,0.6);
  color: rgba(255,255,255,0.9);
}

/* ─── Responsive — nav hamburger (8 items need more room) */
@media (max-width: 1100px) {
  .site-nav { padding: 0 20px; }

  .nav-links {
    display: none;
    position: fixed;
    top: var(--nav-h);
    left: 0; right: 0;
    background: rgba(253, 250, 245, 0.98);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    gap: 0;
    padding: 8px 0;
    z-index: 99;
    box-shadow: 0 12px 40px rgba(0,0,0,0.1);
    transform: translateY(-8px);
    opacity: 0;
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
  }
  .nav-links.open {
    display: flex;
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }
  .nav-links li { border-bottom: 1px solid var(--border); }
  .nav-links a { display: block; padding: 14px 24px; font-size: 1rem; }

  .nav-toggle { display: flex; align-items: center; }
}

/* ─── Responsive — general layout ───────────────────────── */
@media (max-width: 768px) {
  html { font-size: 16px; }
  .content-wrap-wide { padding: 0 20px; }
  .page-header { padding: 56px 20px 44px; }
  .site-footer { margin-top: 60px; }
}

/* ─── Poetry background canvas ──────────────────────── */
#poetry-bg {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 0;
  view-transition-name: poetry-bg;
}

main, .site-footer, .page-header, .filter-bar {
  position: relative;
  z-index: 1;
}

/* ─── Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  @view-transition { navigation: none; }
}
