/* =========================================================
   E'SCAPE — shared design system
   Fonts by role:
     Fraunces        → expressive editorial display (soft/wonky axes)
     Instrument Sans → clean UI + body
     Reenie Beanie   → Ella's handwriting (annotations only)
     DM Mono         → labels, metadata, dates, edition numbers
   ========================================================= */

@view-transition { navigation: auto; }

:root {
  /* paper & ink */
  --paper: #f1e9db;
  --ivory: #faf6ee;
  --kraft: #c9a87c;
  --ink: #1e1a16;
  --ink-soft: #4b4137;
  --brown: #4a3527;
  --moss: #5d6a4b;
  --rose: #d8a7a0;
  --brick: #a9402d;
  --cobalt: #2c44e8;      /* rubber-stamp ink: the one loud accent */
  --safelight: #e3321b;
  --tape: rgba(236, 222, 186, .78);

  /* page-level (rooms override these) */
  --bg: var(--paper);
  --fg: var(--ink);
  --muted: var(--ink-soft);
  --accent: var(--cobalt);

  --f-display: "Fraunces", "Times New Roman", serif;
  --f-sans: "Instrument Sans", system-ui, sans-serif;
  --f-hand: "Reenie Beanie", "Bradley Hand", cursive;
  --f-mono: "DM Mono", ui-monospace, monospace;

  --ease: cubic-bezier(.2, .8, .2, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --gutter: clamp(16px, 4vw, 56px);

  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --fibres: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.012 .35' numOctaves='2' seed='4'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .27 0 0 0 0 .18 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E");
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 16px/1.6 var(--f-sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  transition: background-color .6s var(--ease), color .6s var(--ease);
}
img { display: block; max-width: 100%; }
a { color: inherit; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
::selection { background: var(--accent); color: var(--ivory); }
:focus-visible { outline: 2px dashed var(--accent); outline-offset: 4px; }

/* film grain over everything */
body::after {
  content: "";
  position: fixed; inset: -50%;
  background-image: var(--grain);
  opacity: .16;
  pointer-events: none;
  z-index: 9000;
  mix-blend-mode: multiply;
  animation: grain 1.2s steps(6) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); } 20% { transform: translate(-3%, 2%); }
  40% { transform: translate(2%, -4%); } 60% { transform: translate(-4%, -1%); }
  80% { transform: translate(3%, 3%); } 100% { transform: translate(0, 0); }
}

/* ---------- type roles ---------- */
.display {
  font-family: var(--f-display);
  font-variation-settings: "SOFT" 100, "WONK" 1, "opsz" 144;
  font-weight: 300;
  letter-spacing: -.035em;
  line-height: .88;
}
.display em { font-style: italic; font-weight: 300; }
.hand { font-family: var(--f-hand); font-weight: 400; line-height: 1.05; letter-spacing: .01em; }
.mono, .label {
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  line-height: 1.5;
}
.serif { font-family: var(--f-display); font-variation-settings: "opsz" 24, "SOFT" 50; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- paper objects ---------- */
.tape {
  position: absolute;
  width: 92px; height: 26px;
  background: var(--tape);
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
  mask: linear-gradient(90deg, transparent 0 2px, #000 2px calc(100% - 2px), transparent 0),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='92' height='26' preserveAspectRatio='none'%3E%3Cpath d='M0 2 L4 0 L8 3 L12 0 L16 2 L92 1 L88 4 L92 8 L89 13 L92 18 L88 22 L92 26 L4 25 L0 23 L3 19 L0 14 L4 9 L0 5Z'/%3E%3C/svg%3E") center / 100% 100%;
  mask-composite: intersect;
  z-index: 3;
  pointer-events: none;
}
.tape::after { content: ""; position: absolute; inset: 0; background-image: var(--fibres); opacity: .6; }
.pin {
  position: absolute; width: 14px; height: 14px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff8 0 2px, transparent 3px), var(--brick);
  box-shadow: 1px 3px 3px rgba(0,0,0,.35);
  z-index: 4; pointer-events: none;
}
.polaroid {
  background: var(--ivory);
  padding: 10px 10px 46px;
  box-shadow: 0 1px 1px rgba(0,0,0,.08), 0 10px 24px -8px rgba(40,25,10,.35);
  position: relative;
}
.polaroid img { width: 100%; aspect-ratio: 1; object-fit: cover; filter: saturate(.85) contrast(1.02) sepia(.08); }
.polaroid .cap { position: absolute; left: 14px; right: 10px; bottom: 8px; font-family: var(--f-hand); font-size: 24px; line-height: 1; }
.torn-top { mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='20' preserveAspectRatio='none'%3E%3Cpath d='M0 20 L0 8 L10 5 L22 9 L35 4 L48 8 L60 3 L74 7 L90 2 L103 8 L118 4 L131 9 L146 3 L160 7 L176 2 L190 8 L205 4 L220 9 L236 3 L250 7 L266 4 L281 9 L296 3 L310 8 L326 5 L340 9 L356 3 L371 8 L387 4 L400 7 L400 20Z'/%3E%3C/svg%3E") top / 100% 14px no-repeat, linear-gradient(#000, #000) 0 13px / 100% 100% no-repeat; }
.stamp {
  display: inline-block;
  font-family: var(--f-mono); font-weight: 500;
  font-size: 12px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--cobalt);
  border: 2px solid currentColor; border-radius: 4px;
  padding: 5px 9px 4px;
  mix-blend-mode: multiply;
  mask: var(--grain) 0 0 / 160px;
  -webkit-mask: var(--grain) 0 0 / 160px;
  opacity: .9;
}

/* ---------- shared chrome ---------- */
.chrome {
  position: fixed; inset: 0 0 auto 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 18px var(--gutter);
  z-index: 800;
  pointer-events: none;
}
.chrome > * { pointer-events: auto; }
.wordmark {
  font-family: var(--f-display);
  font-variation-settings: "SOFT" 100, "WONK" 1, "opsz" 144;
  font-size: 22px; font-weight: 500; letter-spacing: -.02em;
  text-decoration: none;
  display: inline-flex; align-items: baseline; gap: 2px;
}
.wordmark i { font-style: italic; font-weight: 300; color: var(--accent); }
.wordmark small { font-family: var(--f-hand); font-size: 18px; margin-left: 8px; color: var(--muted); font-weight: 400; letter-spacing: 0; }
.index-btn {
  font-family: var(--f-mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  display: inline-flex; align-items: center; gap: 10px;
  padding: 9px 14px 8px;
  background: var(--ivory); color: var(--ink);
  border-radius: 999px;
  box-shadow: 0 2px 0 rgba(0,0,0,.12);
  transition: transform .3s var(--ease);
}
.index-btn:hover { transform: rotate(-3deg) scale(1.04); }
.index-btn .dots { display: inline-grid; grid-template-columns: repeat(2, 4px); gap: 3px; }
.index-btn .dots span { width: 4px; height: 4px; border-radius: 50%; background: currentColor; }

/* index overlay — a handwritten contents card */
.index-overlay {
  position: fixed; inset: 0; z-index: 850;
  display: grid; place-items: center;
  background: rgba(20, 16, 12, .55);
  backdrop-filter: blur(6px);
  opacity: 0; visibility: hidden;
  transition: opacity .4s var(--ease), visibility 0s .4s;
  padding: 16px;
}
.index-overlay.open { opacity: 1; visibility: visible; transition: opacity .4s var(--ease); }
.index-card {
  position: relative;
  width: min(560px, 100%);
  background: var(--ivory) var(--fibres);
  color: var(--ink);
  padding: 40px clamp(20px, 5vw, 48px) 32px;
  box-shadow: 0 30px 60px -20px rgba(0,0,0,.5);
  transform: rotate(-1.5deg) translateY(30px) scale(.96);
  transition: transform .6s var(--ease-out);
  background-image:
    repeating-linear-gradient(transparent 0 33px, rgba(44,68,232,.16) 33px 34px),
    var(--fibres);
  background-position: 0 28px, 0 0;
}
.index-card::before { content: ""; position: absolute; top: 0; bottom: 0; left: 44px; width: 1px; background: rgba(169,64,45,.35); }
.index-overlay.open .index-card { transform: rotate(-1.5deg); }
.index-card .tape { top: -12px; left: 50%; transform: translateX(-50%) rotate(3deg); }
.index-card h2 { margin: 0 0 6px; font-family: var(--f-hand); font-size: 34px; font-weight: 400; line-height: 1; }
.index-card ol { list-style: none; margin: 0; padding: 0; counter-reset: i; }
.index-card li { counter-increment: i; }
.index-card a {
  display: flex; align-items: baseline; gap: 16px;
  text-decoration: none; padding: 0; height: 34px; line-height: 40px;
  font-family: var(--f-display); font-variation-settings: "SOFT" 100, "WONK" 1, "opsz" 72;
  font-size: 26px; font-weight: 350; letter-spacing: -.02em;
  transition: color .2s, transform .3s var(--ease);
}
.index-card a::before { content: "0" counter(i); font-family: var(--f-mono); font-size: 10px; letter-spacing: .1em; width: 20px; color: var(--muted); }
.index-card a span { margin-left: auto; font-family: var(--f-hand); font-size: 21px; color: var(--muted); }
.index-card a:hover { color: var(--cobalt); transform: translateX(6px); }
.index-card a[aria-current="page"] { text-decoration: line-through; text-decoration-color: var(--brick); text-decoration-thickness: 2px; }
.index-card .foot { margin-top: 22px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.index-close { position: absolute; top: 14px; right: 16px; font-family: var(--f-mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; }

/* cursor label (pointer: fine only) */
.cursor {
  position: fixed; left: 0; top: 0; z-index: 9100;
  pointer-events: none;
  width: 10px; height: 10px; margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: var(--fg);
  mix-blend-mode: difference;
  filter: invert(1);
  transition: width .35s var(--ease), height .35s var(--ease), margin .35s var(--ease), background .3s;
  display: grid; place-items: center;
  opacity: 0;
}
.cursor span {
  font-family: var(--f-mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--bg); opacity: 0; transition: opacity .2s; white-space: nowrap;
}
.cursor.has-label { width: 74px; height: 74px; margin: -37px 0 0 -37px; }
.cursor.has-label span { opacity: 1; }
@media (pointer: fine) { .cursor { opacity: 1; } }
@media (pointer: coarse) { .cursor { display: none; } }

/* scroll reveals */
.reveal { opacity: 0; transform: translateY(40px); transition: opacity 1s var(--ease-out), transform 1.2s var(--ease-out); }
.reveal.in { opacity: 1; transform: none; }
.reveal-img { clip-path: inset(100% 0 0 0); transition: clip-path 1.4s var(--ease-out); }
.reveal-img.in { clip-path: inset(0 0 0 0); }
/* handwriting that "writes" itself left to right */
.write { clip-path: inset(-20% 100% -20% 0); transition: clip-path 1.8s steps(28, end); }
.write.in { clip-path: inset(-20% -2% -20% 0); }

/* honest footnote */
.placeholder-note {
  font-family: var(--f-mono); font-size: 10px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); opacity: .8;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; }
  .reveal, .reveal-img, .write { opacity: 1; transform: none; clip-path: none; }
  @view-transition { navigation: none; }
}

::view-transition-old(root), ::view-transition-new(root) { animation-duration: .55s; animation-timing-function: var(--ease); }

/* rotated paper & glows may poke past the edge; never let them widen the page */
main { overflow-x: clip; }

/* ---------- the route: always-visible order of rooms ---------- */
.route { position: absolute; left: 50%; top: 16px; transform: translateX(-50%); }
.route ol { list-style: none; display: flex; align-items: center; margin: 0; padding: 4px; gap: 2px;
  background: rgba(250, 246, 238, .86); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-radius: 999px; box-shadow: 0 2px 0 rgba(0,0,0,.08), 0 8px 24px -14px rgba(0,0,0,.4); }
.route li { position: relative; display: flex; align-items: center; }
.route li + li::before { content: ""; width: 10px; height: 1px; background: rgba(30,26,22,.25); margin: 0 1px; }
.route a { display: flex; align-items: baseline; gap: 6px; padding: 7px 11px 6px; border-radius: 999px; text-decoration: none; color: #1e1a16; white-space: nowrap; transition: background .25s, color .25s; }
.route .rn { font-family: var(--f-mono); font-size: 9px; letter-spacing: .06em; color: #7a6f63; }
.route .rt { font-family: var(--f-sans); font-size: 13px; font-weight: 500; letter-spacing: -.01em; }
.route li.past .rt { color: #6d6358; }
.route a:hover { background: rgba(30,26,22,.07); }
.route a[aria-current="page"] { background: #1e1a16; color: #faf6ee; }
.route a[aria-current="page"] .rn { color: #d8a7a0; }
.index-btn .where { margin-left: 6px; padding-left: 10px; border-left: 1px solid rgba(30,26,22,.25); color: #6d6358; display: none; }

/* next stop, at the foot of a page */
.next-stop { padding: 60px var(--gutter) 70px; border-top: 1px solid color-mix(in srgb, var(--fg) 22%, transparent); display: grid; gap: 18px; justify-items: start; }
.next-stop a { display: grid; gap: 4px; text-decoration: none; color: var(--fg); }
.ns-k { color: var(--muted); }
.ns-t { font-family: var(--f-display); font-style: italic; font-weight: 300; font-variation-settings: "opsz" 144, "SOFT" 100, "WONK" 1;
  font-size: clamp(48px, 8vw, 120px); line-height: .95; letter-spacing: -.035em; }
.ns-arrow { display: inline-block; font-family: var(--f-sans); font-style: normal; font-weight: 300; transition: transform .4s var(--ease); }
.next-stop a:hover .ns-arrow { transform: translateX(16px); }
.next-stop a:hover .ns-t { color: var(--accent); }
.ns-s { font-size: 28px; color: var(--muted); }
.ns-index { color: var(--muted); border-bottom: 1px solid currentColor; padding-bottom: 2px; }

@media (max-width: 1180px) {
  .route { display: none; }
  .index-btn .where { display: inline; }
}
@media (max-width: 420px) { .wordmark small { display: none; } }
