/* =========================================================
   ratn.fyi — Book Site Stylesheet
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@400;500;600;700&family=EB+Garamond:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500&family=IM+Fell+English:ital@0;1&display=swap');

/* ----- Design Tokens ----- */
:root {
  --paper:     #eae5d9;
  --ink:       #171510;
  --muted-ink: #625b4e;
  --rule:      rgba(38, 31, 21, .42);
  --display:   "Cormorant Garamond", Georgia, serif;
  --reading:   "EB Garamond", Georgia, serif;
  --imprint:   "IM Fell English", Georgia, serif;
}

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

html {
  min-height: 100%;
  background: var(--paper);
  scroll-behavior: smooth;
}

/* ----- Body / Paper texture ----- */
body {
  min-height: 100svh;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    radial-gradient(ellipse at 20% 25%, rgba(255,255,255,.38), transparent 55%),
    radial-gradient(ellipse at 80% 70%, rgba(155,135,100,.09), transparent 60%),
    radial-gradient(ellipse at 50% 50%, transparent 45%, rgba(130,110,80,.08) 100%),
    repeating-linear-gradient(91deg, rgba(100,80,50,.012) 0, transparent 1px, transparent 3px);
  font-family: var(--reading);
  overflow-x: hidden;
}

/* Fine paper grain */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 20;
  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='.8' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: .15; mix-blend-mode: multiply;
}

/* Dust specks */
body::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 21;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 250 250' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23796c55'%3E%3Cellipse cx='22' cy='38' rx='.7' ry='1.1'/%3E%3Cellipse cx='91' cy='72' rx='1' ry='.6'/%3E%3Cellipse cx='180' cy='23' rx='.6' ry='1'/%3E%3Cellipse cx='211' cy='145' rx='.8' ry='.6'/%3E%3Cellipse cx='54' cy='191' rx='.7' ry='1'/%3E%3Cellipse cx='137' cy='221' rx='1' ry='.5'/%3E%3Cellipse cx='230' cy='82' rx='.6' ry='.8'/%3E%3Cellipse cx='110' cy='155' rx='.5' ry='1'/%3E%3C/g%3E%3C/svg%3E");
  opacity: .22;
}

button, a { color: inherit; }
button { font: inherit; }

/* ----- Stage / layout ----- */
/*
  Landscape orientation: stage fills the full viewport.
  Horizontal padding alone defines the margins — no inner
  width cap. Content breathes across the whole page.
*/
.stage {
  min-height: 100svh;
  display: grid; place-items: start center;
  /* 5vw ≈ 72px on 1440px, 48px on 960px, never below 28px */
  padding: clamp(36px, 5vh, 64px) clamp(28px, 5vw, 80px) clamp(36px, 5vh, 64px);
  position: relative; isolation: isolate;
}

/* ----- Book container ----- */
/*
  Full-width, no fixed height, no floating-rectangle decoration.
  The turn-sheet overlay still animates across the full width.
*/
.book {
  width: 100%;
  position: relative;
  display: flex; flex-direction: column;
  transform-style: preserve-3d;
}

/* ----- Page content area ----- */
/*
  No max-width cap — content fills the full width
  that the stage padding leaves available.
  Think landscape book, not portrait page.
*/
.page-content {
  width: 100%;
  animation: settle .55s ease both;
}

@keyframes settle {
  from { opacity: .25; transform: translateY(5px); }
  to   { opacity: 1;   transform: translateY(0); }
}

/* ----- Cover / masthead ----- */
.masthead { text-align: center; margin-bottom: 38px; }

.name {
  font-family: var(--display); font-weight: 700; text-transform: uppercase;
  /* Larger range now that we have the full canvas */
  font-size: clamp(4rem, 11vw, 8rem); line-height: .80;
  letter-spacing: -.055em; margin: 0 auto 24px;
}
.name span { display: block; }

.descriptor { font-family: var(--display); font-weight: 600; font-size: 1.35rem; }

.location {
  margin-top: 7px; color: var(--muted-ink);
  font: .92rem var(--imprint); letter-spacing: .06em;
}

.edition {
  margin-top: 11px; color: var(--muted-ink);
  font: .88rem var(--imprint); letter-spacing: .07em;
}

/* ----- Table of contents ----- */
/* On wide screens the TOC can be wider too */
.index-list { list-style: none; width: 100%; max-width: 680px; margin: 0 auto; }
.index-list li + li { margin-top: 15px; }

.index-link {
  display: flex; align-items: baseline; gap: 10px; text-decoration: none;
  font: 500 1.12rem var(--reading); text-transform: uppercase; letter-spacing: .015em;
  transition: opacity .2s ease;
}
.index-link:hover { opacity: .58; }
.index-link .label { white-space: nowrap; }
.index-link .sub-label {
  font-size: .82rem; text-transform: none; letter-spacing: 0;
  color: var(--muted-ink); font-style: italic; white-space: nowrap;
  font-family: var(--imprint);
}
.index-link .leader {
  flex: 1; min-width: 18px; height: .75em;
  background-image: radial-gradient(circle, currentColor .8px, transparent 1px);
  background-size: 8px 4px; background-repeat: repeat-x; background-position: left 78%;
  opacity: .78;
}
.index-link .number { font: 1rem var(--imprint); }

/* ----- Chapter heading ----- */
.page-heading { text-align: center; margin: 0 0 36px; }
.chapter-number {
  display: block; color: var(--muted-ink);
  font: .95rem var(--imprint); letter-spacing: .14em; margin-bottom: 11px;
}
h2 {
  /* Larger heading range for the wide canvas */
  font: 600 clamp(2.8rem, 6vw, 4.5rem)/.92 var(--display);
  letter-spacing: -.03em;
}
.chapter-epigraph {
  color: var(--muted-ink); font: italic 1.02rem/1.5 var(--reading);
  text-align: center; margin-top: 10px;
}

/* ----- Ornament divider ----- */
.ornament {
  text-align: center; margin: 21px 0 25px;
  color: var(--muted-ink); font: 1.1rem var(--imprint);
}

/* ----- Prose ----- */
.prose { font: 1.25rem/1.65 var(--reading); }
.prose p + p { margin-top: 18px; }

/*
  On wide screens, run long prose in two balanced columns.
  Each chapter page uses .prose directly — columns kick in
  only when there's genuinely room (> 740px content width).
*/
@supports (column-count: 2) {
  @media (min-width: 900px) {
    .prose.two-col {
      column-count: 2;
      column-gap: clamp(32px, 4vw, 64px);
      column-rule: 1px solid var(--rule);
    }
    .prose.two-col h3 {
      column-span: all; /* headings span both columns */
    }
    .prose.two-col .project + .project {
      break-before: avoid;
    }
  }
}

.prose h3 {
  font: 600 1.65rem/1.1 var(--display);
  margin: 30px 0 4px;
}
.prose .role-line {
  color: var(--muted-ink); font: italic .95rem var(--imprint);
  margin-bottom: 10px;
}
.prose ul { margin: 8px 0 0 22px; }
.prose li { padding-left: 3px; margin: 4px 0; }
.prose a {
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

/* ----- Project entries ----- */
.project + .project { margin-top: 32px; padding-top: 30px; border-top: 1px dotted var(--rule); }
.project-meta {
  color: var(--muted-ink); font: italic .92rem var(--imprint);
  margin-bottom: 10px;
}

/* Two-column project grid on wide screens */
@media (min-width: 860px) {
  .projects-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: clamp(24px, 3vw, 48px);
  }
  .projects-grid .project + .project {
    margin-top: 0; padding-top: 0; border-top: none;
  }
  .projects-grid .project {
    padding: 24px;
    border: 1px dotted var(--rule);
    border-radius: 2px;
  }
}

/* ----- Timeline (Chapter V) ----- */
.timeline { list-style: none; }
.timeline li {
  display: grid; grid-template-columns: 100px 1fr;
  gap: 14px; padding: 9px 0;
  border-bottom: 1px dotted var(--rule);
}
.timeline time { color: var(--muted-ink); font: .9rem var(--imprint); }
.timeline span  { font-size: 1.1rem; line-height: 1.45; }

/* ----- Links block ----- */
.link-row { margin-bottom: 10px; }
.link-row strong { font-family: var(--display); font-weight: 600; }

/* ----- Small / muted note ----- */
.small-note {
  color: var(--muted-ink);
  font: .95rem/1.45 var(--imprint);
  margin-top: 20px;
}
.small-note-inline {
  color: var(--muted-ink);
  font: italic .9rem var(--imprint);
}

/* ----- HR rule ----- */
.rule { border: none; border-top: 1px solid var(--rule); margin: 24px 0; }

/* ----- Page footer (navigation) ----- */
.page-footer {
  position: relative; margin-top: 32px;
  display: flex; justify-content: center; align-items: center; gap: 17px;
  color: var(--muted-ink); font: .88rem var(--imprint);
}
.page-footer button, .theme-toggle {
  border: 0; background: transparent; cursor: pointer; padding: 5px 7px;
  font: inherit; color: inherit;
}
.page-footer button:hover, .theme-toggle:hover { color: var(--ink); }
.page-footer .folio { min-width: 48px; text-align: center; }

/* ----- Page-turn animation overlay ----- */
/*
  The turn-sheet simulates paper curling:
  · perspective() is applied per-element so the fold foreshortens naturally
  · The gradient layers a cast-shadow on the left, the paper body, and a
    warm curl-away tone on the right edge
  · A ::after pseudo-element adds a narrow highlight at the fold spine
*/
.turn-sheet {
  position: absolute; inset: 0; z-index: 5; pointer-events: none;
  transform-origin: left center;
  background: linear-gradient(
    to right,
    rgba(52, 38, 20, .28)  0%,
    rgba(52, 38, 20, .00)  3%,
    rgba(252,247,238, .97) 5.5%,
    #ede7d9                50%,
    rgba(200,185,160, .86) 100%
  );
  opacity: 0;
  border-radius: 0 1px 1px 0;
}
/* Fold-spine highlight — the bright crease where the page bends */
.turn-sheet::after {
  content: '';
  position: absolute; top: 0; bottom: 0;
  left: 5%; width: 2.5%;
  background: linear-gradient(
    to right,
    rgba(255,255,255, 0),
    rgba(255,255,255, .38),
    rgba(255,255,255, 0)
  );
  pointer-events: none;
}
.book.turning-forward .turn-sheet {
  animation: turn-forward .90s cubic-bezier(.36,.0,.18,1) both;
}
.book.turning-back .turn-sheet {
  transform-origin: right center;
  animation: turn-back .90s cubic-bezier(.36,.0,.18,1) both;
}
@keyframes turn-forward {
  0%   { opacity: 0;   transform: perspective(1100px) rotateY(0deg); }
  7%   { opacity: 1; }
  48%  {              transform: perspective(1100px) rotateY(-88deg); }
  100% { opacity: .05; transform: perspective(1100px) rotateY(-178deg); }
}
@keyframes turn-back {
  0%   { opacity: .05; transform: perspective(1100px) rotateY(-178deg); }
  7%   { opacity: 1; }
  52%  {              transform: perspective(1100px) rotateY(-88deg); }
  100% { opacity: 0;  transform: perspective(1100px) rotateY(0deg); }
}

/*
  Backward turn — mirror the gradient and fold-highlight.
  When going back the page peels from the LEFT edge, so:
  · the dark cast-shadow belongs on the RIGHT
  · the warm curl tone belongs on the LEFT
  · the fold-spine crease moves to the right side
*/
.book.turning-back .turn-sheet {
  background: linear-gradient(
    to left,
    rgba(52, 38, 20, .28)  0%,
    rgba(52, 38, 20, .00)  3%,
    rgba(252,247,238, .97) 5.5%,
    #ede7d9                50%,
    rgba(200,185,160, .86) 100%
  );
}
.book.turning-back .turn-sheet::after {
  left: auto;
  right: 5%;
}

/* ----- Theme toggle — fixed top-right corner ----- */
.theme-corner {
  position: fixed; top: 15px; right: 18px; z-index: 30;
  border: 0; background: transparent; cursor: pointer;
  color: var(--muted-ink); font-size: 1.2rem; line-height: 1;
  padding: 6px 8px;
  transition: color .2s ease, opacity .2s ease;
  opacity: .65;
  font-family: inherit;
}
.theme-corner:hover { color: var(--ink); opacity: 1; }

/* ----- Dark mode ----- */
body.ink-dark {
  --paper:     #29271f;
  --ink:       #e8dfcc;
  --muted-ink: #b4a991;
  --rule:      rgba(232,223,204,.35);
  background-color: var(--paper);
  background-image:
    radial-gradient(ellipse at 20% 25%, rgba(255,255,255,.035), transparent 55%),
    radial-gradient(ellipse at 80% 70%, rgba(0,0,0,.14), transparent 60%),
    repeating-linear-gradient(91deg, rgba(0,0,0,.025) 0, transparent 1px, transparent 3px);
}
/* no .book::before in dark mode either — edge decoration removed */
body.ink-dark .turn-sheet {
  background: linear-gradient(
    to right,
    rgba(0,0,0,.35)  0%,
    rgba(0,0,0,.00)  3%,
    rgba(55,51,41,.97) 5.5%,
    #302d24          50%,
    rgba(22,20,15,.88) 100%
  );
}
body.ink-dark .turn-sheet::after {
  background: linear-gradient(
    to right,
    rgba(255,255,255,0),
    rgba(255,255,255,.12),
    rgba(255,255,255,0)
  );
}
/* Dark-mode backward turn mirror */
body.ink-dark .book.turning-back .turn-sheet {
  background: linear-gradient(
    to left,
    rgba(0,0,0,.35)    0%,
    rgba(0,0,0,.00)    3%,
    rgba(55,51,41,.97) 5.5%,
    #302d24            50%,
    rgba(22,20,15,.88) 100%
  );
}


/* ----- Responsive ----- */
@media (max-width: 600px) {
  /* Mobile — compact, full-bleed */
  .stage    { padding: 22px 18px 20px; }
  .book     { padding-bottom: 44px; }
  .masthead { margin-bottom: 32px; }
  .index-link { font-size: 1.06rem; }
  .index-list li + li { margin-top: 17px; }
  .prose    { font-size: 1.16rem; }
  .timeline li { grid-template-columns: 80px 1fr; }
  .theme-corner { top: 12px; right: 14px; font-size: 1.1rem; }
}

@media (min-width: 601px) and (max-width: 1024px) {
  /* Tablet — slightly larger type */
  .prose { font-size: 1.19rem; }
}

/* ----- Reduced motion ----- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
