:root {
  --bg: #14110e;
  --bg-2: #1b1713;
  --ink: #efe7da;
  --ink-2: #bdb09c;
  --ink-3: #8c8070;
  --gold: #c8a567;
  --gold-soft: rgba(200, 165, 103, 0.45);
  --print: #f4eee3;
  --display: "Cormorant Garamond", "Georgia", serif;
  --body: "EB Garamond", "Georgia", serif;
  --shadow-print:
    0 1px 2px rgba(0, 0, 0, 0.35),
    0 14px 30px -8px rgba(0, 0, 0, 0.6),
    0 34px 70px -24px rgba(0, 0, 0, 0.55);
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
html.lb-open, html.lb-open body { overflow: hidden; }

body {
  margin: 0;
  background-color: var(--bg);
  background-image:
    radial-gradient(1200px 800px at 50% -10%, rgba(120, 90, 50, 0.16), transparent 70%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 .9 0 0 0 0 .8 0 0 0 .05 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  color: var(--ink);
  font-family: var(--body);
  font-size: 18px;
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Floating light specks (drawn by js/particles.js), behind everything else. */
.particles {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100vh;
  height: 100lvh;
  z-index: -1;
  pointer-events: none;
}

img { display: block; max-width: 100%; }
button { font: inherit; color: inherit; }
a { color: inherit; }

:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }

/* ---------- Hero ---------- */

.hero {
  position: relative;
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 64px 16px 120px;
  overflow: hidden;
  isolation: isolate;
}

.hero-glow {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: radial-gradient(38vmax 34vmax at 50% 44%, rgba(214, 170, 102, 0.20), transparent 70%);
  pointer-events: none;
}

.hero-inner {
  position: relative;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  will-change: transform, opacity;
}

.eyebrow {
  margin: 0 0 22px;
  font-family: var(--body);
  font-size: 0.8rem;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--gold);
  padding-left: 0.34em; /* balance trailing letter-spacing */
}

.portrait {
  --pw: min(360px, 60vw, 40svh);
  width: var(--pw);
  padding: 0;
  border: 0;
  background: none;
  cursor: zoom-in;
  border-radius: 999px 999px 18px 18px;
  -webkit-tap-highlight-color: transparent;
}

.portrait-frame {
  display: block;
  padding: 9px;
  border: 1px solid var(--gold-soft);
  border-radius: 999px 999px 22px 22px;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.3),
    0 30px 80px -20px rgba(0, 0, 0, 0.8),
    0 0 120px -30px rgba(214, 170, 102, 0.35);
  transition: transform 0.6s cubic-bezier(.2, .7, .2, 1);
}

.portrait img {
  width: 100%;
  height: auto;
  border-radius: 999px 999px 14px 14px;
  background: #3c3a3e;
}

@media (hover: hover) {
  .portrait:hover .portrait-frame { transform: scale(1.015); }
}

.name {
  margin: 30px 0 0;
  font-family: var(--display);
  font-weight: 300;
  font-size: clamp(2.35rem, 6.4vw, 5.2rem);
  line-height: 1.04;
  letter-spacing: 0.01em;
  color: var(--ink);
  text-wrap: balance;
}

.dates {
  margin: 14px 0 0;
  font-style: italic;
  font-size: clamp(1.05rem, 2vw, 1.3rem);
  color: var(--ink-2);
  letter-spacing: 0.04em;
}

.tribute {
  margin: 10px 0 0;
  max-width: 42ch;
  font-family: var(--display);
  font-style: italic;
  font-size: clamp(1.15rem, 2.2vw, 1.5rem);
  color: var(--ink-2);
}

.dates:empty, .tribute:empty { display: none; }

.scroll-cue {
  position: absolute;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 3;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  font-size: 0.72rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--ink-3);
  padding-left: 0.3em;
}

.scroll-line {
  position: relative;
  width: 1px;
  height: 46px;
  overflow: hidden;
  background: rgba(239, 231, 218, 0.12);
}

.scroll-line::after {
  content: "";
  position: absolute;
  left: 0;
  top: -50%;
  width: 1px;
  height: 50%;
  background: var(--gold);
  animation: cue 2.4s cubic-bezier(.6, 0, .4, 1) infinite;
}

@keyframes cue {
  from { transform: translateY(0); }
  to { transform: translateY(300%); }
}

/* ---------- Floating photos around the portrait ---------- */

.floaters {
  position: absolute;
  inset: 0;
  z-index: 2;
}

.floater {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--w);
}

/* ---------- Shared "photo print" ---------- */

.ph {
  display: block;
  padding: 0;
  border: 0;
  background: none;
  cursor: zoom-in;
  -webkit-tap-highlight-color: transparent;
}

.bob {
  display: block;
  animation: bob var(--dur, 8s) ease-in-out var(--delay, 0s) infinite alternate;
  animation-play-state: paused;
}

.ph.in-view .bob { animation-play-state: running; }

@keyframes bob {
  from { transform: translate3d(0, -6px, 0) rotate(-0.5deg); }
  to   { transform: translate3d(0, 6px, 0) rotate(0.5deg); }
}

.print {
  display: block;
  padding: 3.5%;
  background: var(--print);
  border-radius: 2px;
  box-shadow: var(--shadow-print);
  transform: rotate(var(--r, 0deg)) scale(0.9);
  opacity: 0;
  transition:
    opacity 0.9s ease,
    transform 0.9s cubic-bezier(.2, .7, .2, 1),
    box-shadow 0.5s ease;
}

.ph.shown .print {
  opacity: 1;
  transform: rotate(var(--r, 0deg)) scale(1);
}

.print img {
  width: 100%;
  height: auto;
  background: var(--c, #3a332b);
  opacity: 0;
  transition: opacity 0.6s ease;
}

.print img.loaded { opacity: 1; }

@media (hover: hover) {
  .ph:hover { z-index: 60 !important; }
  .ph.shown:hover .print {
    transform: rotate(0deg) scale(1.06);
    box-shadow:
      0 2px 4px rgba(0, 0, 0, 0.35),
      0 30px 60px -12px rgba(0, 0, 0, 0.75);
  }
}

.ph:focus-visible { outline: none; }
.ph:focus-visible .print { outline: 2px solid var(--gold); outline-offset: 5px; }

/* ---------- Services ---------- */

.services {
  position: relative;
  z-index: 5;
  max-width: 640px;
  margin: 0 auto;
  padding: 16vh 16px 0;
  text-align: center;
}

.service-card {
  position: relative;
  padding: 40px 28px 34px;
  border: 1px solid rgba(200, 165, 103, 0.28);
  border-radius: 4px;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(200, 165, 103, 0.08), transparent 70%),
    rgba(20, 17, 14, 0.72);
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.8);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.service-card::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid rgba(200, 165, 103, 0.12);
  border-radius: 2px;
  pointer-events: none;
}

.service-date {
  margin: 0;
  font-size: 0.82rem;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--gold);
  padding-left: 0.26em;
}

.service-name {
  margin: 18px 0 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(1.9rem, 5vw, 2.5rem);
  line-height: 1.15;
}

.service-time {
  margin: 8px 0 0;
  font-size: 1.2rem;
  color: var(--ink-2);
}

.service-place {
  margin: 28px 0 0;
  font-size: 0.9rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink);
  padding-left: 0.2em;
}

.service-address {
  margin: 10px 0 0;
  font-style: normal;
  font-size: 1.08rem;
  line-height: 1.55;
}

.service-address a {
  color: var(--ink-2);
  text-decoration: underline;
  text-decoration-color: rgba(200, 165, 103, 0.5);
  text-underline-offset: 4px;
}

.service-address a:hover { color: var(--ink); }

.service-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 30px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  padding: 12px 22px;
  border: 1px solid rgba(239, 231, 218, 0.2);
  border-radius: 999px;
  font-size: 0.8rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--ink);
  background: rgba(239, 231, 218, 0.03);
  transition: background 0.25s, border-color 0.25s, color 0.25s;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover { border-color: var(--gold-soft); background: rgba(200, 165, 103, 0.08); }

.btn svg {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-primary {
  border-color: var(--gold);
  background: var(--gold);
  color: #1a140d;
  font-weight: 500;
}

.btn-primary:hover { background: #d8b77a; border-color: #d8b77a; color: #1a140d; }

.dignity { margin-top: 36px; }

.dignity-note {
  margin: 14px 0 0;
  font-family: var(--display);
  font-style: italic;
  font-size: 1.1rem;
  color: var(--ink-3);
}

.services.is-past #addToCalendar { display: none; }

/* ---------- Story (obituary) ---------- */

.story {
  position: relative;
  z-index: 5;
  max-width: 700px;
  margin: 0 auto;
  padding: 16vh 20px 2vh;
  text-align: center;
}

.story:has(.story-text:empty) { display: none; }

.section-title {
  margin: 0 0 36px;
  font-family: var(--display);
  font-weight: 300;
  font-style: italic;
  font-size: clamp(2.2rem, 5.5vw, 3.8rem);
  line-height: 1.1;
}

.story-text {
  text-align: left;
  font-size: 1.16rem;
  line-height: 1.8;
  color: var(--ink-2);
  hyphens: manual;
}

.story-text p { margin: 0 0 1.3em; }

.story-text p:first-child {
  font-size: 1.28rem;
  color: var(--ink);
}

.story-text p:first-child::first-letter {
  float: left;
  margin: 0.08em 0.1em 0 0;
  font-family: var(--display);
  font-size: 3.6em;
  line-height: 0.8;
  color: var(--gold);
}

.story-text p:last-child {
  margin-top: 2em;
  padding-top: 1.6em;
  border-top: 1px solid rgba(200, 165, 103, 0.2);
  font-style: italic;
}

/* ---------- Chapters & collage ---------- */

.chapter {
  position: relative;
  max-width: 1500px;
  margin: 0 auto;
  padding: 16vh 16px 6vh;
}

.chapter-head {
  position: relative;
  z-index: 70;
  text-align: center;
  margin-bottom: 8vh;
  pointer-events: none;
}

.chapter-num {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: -1;
  font-family: var(--display);
  font-weight: 300;
  font-size: clamp(9rem, 30vw, 22rem);
  line-height: 1;
  color: rgba(200, 165, 103, 0.06);
  transform: translate(-50%, -50%);
  will-change: transform;
  user-select: none;
}

.ornament {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--gold);
  margin-bottom: 18px;
}

.ornament::before, .ornament::after {
  content: "";
  width: 56px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-soft));
}

.ornament::after { transform: scaleX(-1); }

.ornament svg { width: 12px; height: 12px; fill: currentColor; }

.chapter-title {
  margin: 0;
  font-family: var(--display);
  font-weight: 300;
  font-style: italic;
  font-size: clamp(2.2rem, 5.5vw, 3.8rem);
  line-height: 1.1;
  text-wrap: balance;
}

.chapter-meta {
  margin: 12px 0 0;
  font-size: 0.78rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.collage {
  position: relative;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 20px;
}

.collage.is-laid { display: block; }

.collage.is-laid .ph {
  position: absolute;
  left: 0;
  top: 0;
}

/* ---------- Footer ---------- */

.footer {
  position: relative;
  padding: 18vh 20px calc(10vh + env(safe-area-inset-bottom));
  text-align: center;
  background: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.35));
}

.candle {
  position: relative;
  width: 40px;
  height: 110px;
  margin: 0 auto 30px;
}

.wax {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 18px;
  height: 58px;
  transform: translateX(-50%);
  border-radius: 3px 3px 2px 2px;
  background: linear-gradient(90deg, #cfc3ae, #f4eee3 45%, #d8ccb6);
  box-shadow: 0 0 40px 6px rgba(255, 190, 110, 0.12);
}

.wick {
  position: absolute;
  left: 50%;
  bottom: 57px;
  width: 2px;
  height: 8px;
  transform: translateX(-50%);
  background: #3a2c1e;
  border-radius: 1px;
}

.flame {
  position: absolute;
  left: 50%;
  bottom: 62px;
  width: 14px;
  height: 30px;
  margin-left: -7px;
  border-radius: 50% 50% 50% 50% / 64% 64% 36% 36%;
  background: radial-gradient(ellipse at 50% 78%, #fff8e6 0 18%, #ffd27a 38%, #f29a3a 70%, rgba(242, 154, 58, 0) 100%);
  box-shadow: 0 0 30px 12px rgba(255, 180, 90, 0.28), 0 0 90px 30px rgba(255, 160, 70, 0.12);
  transform-origin: 50% 90%;
  animation: flicker 3s ease-in-out infinite;
}

@keyframes flicker {
  0%, 100% { transform: scale(1, 1) rotate(-1deg); opacity: 1; }
  22% { transform: scale(0.96, 1.05) rotate(1.5deg); opacity: 0.95; }
  45% { transform: scale(1.03, 0.96) rotate(-2deg); opacity: 1; }
  70% { transform: scale(0.98, 1.04) rotate(1deg); opacity: 0.92; }
}

.footer-line {
  margin: 0;
  font-family: var(--display);
  font-style: italic;
  font-weight: 300;
  font-size: clamp(1.9rem, 4.5vw, 2.8rem);
}

.footer-name {
  margin: 10px 0 0;
  font-size: 0.8rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--gold);
  padding-left: 0.32em;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 26px;
  margin-top: 30px;
  font-size: 1rem;
}

.footer-links a {
  color: var(--ink-2);
  text-decoration: underline;
  text-decoration-color: rgba(200, 165, 103, 0.4);
  text-underline-offset: 4px;
}

.footer-links a:hover { color: var(--ink); }

.to-top {
  display: inline-block;
  margin-top: 36px;
  padding: 12px 22px;
  font-size: 0.78rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--ink-3);
  border: 1px solid rgba(239, 231, 218, 0.14);
  border-radius: 999px;
  transition: color 0.3s, border-color 0.3s;
}

.to-top:hover { color: var(--ink); border-color: var(--gold-soft); }

.credit {
  max-width: 32em;
  margin: 56px auto 0;
  padding-top: 26px;
  border-top: 1px solid rgba(239, 231, 218, 0.08);
  font-size: 0.88rem;
  line-height: 1.7;
  color: var(--ink-3);
}

.credit a {
  color: var(--ink-2);
  text-decoration: underline;
  text-decoration-color: rgba(200, 165, 103, 0.4);
  text-underline-offset: 3px;
  white-space: nowrap;
}

.credit a:hover { color: var(--ink); }

/* ---------- Lightbox ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(12, 10, 8, 0.965);
  opacity: 0;
  transition: opacity 0.35s ease;
  touch-action: pinch-zoom;
  overscroll-behavior: contain;
  -webkit-user-select: none;
  user-select: none;
}

.lightbox[hidden] { display: none; }
.lightbox.open { opacity: 1; }

.lb-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(64px, env(safe-area-inset-top)) 96px calc(96px + env(safe-area-inset-bottom));
}

.lb-img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 2px;
  box-shadow: 0 30px 90px -20px rgba(0, 0, 0, 0.9);
  transition: opacity 0.3s ease, transform 0.35s cubic-bezier(.2, .7, .2, 1);
  -webkit-user-drag: none;
}

.lb-btn {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  padding: 0;
  border: 1px solid rgba(239, 231, 218, 0.16);
  border-radius: 50%;
  background: rgba(20, 17, 14, 0.6);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.lb-btn:hover { background: rgba(239, 231, 218, 0.1); border-color: var(--gold-soft); }

.lb-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.lb-close {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: 14px;
  z-index: 2;
}

.lb-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  pointer-events: none;
}

.lb-bar > * { pointer-events: auto; }

.lb-count {
  min-width: 7.5em;
  margin: 0;
  text-align: center;
  font-size: 0.85rem;
  letter-spacing: 0.2em;
  color: var(--ink-2);
}

.lb-count small {
  display: block;
  font-family: var(--display);
  font-style: italic;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  color: var(--ink-3);
}

@media (min-width: 900px) {
  .lb-prev, .lb-next {
    position: fixed;
    top: 50%;
    margin-top: -26px;
  }
  .lb-prev { left: 22px; }
  .lb-next { right: 22px; }
}

/* ---------- Phones & tall tablets ---------- */

@media (max-width: 760px), (max-aspect-ratio: 4/5) {
  .hero {
    display: block;
    padding: calc(40vw + env(safe-area-inset-top)) 16px 68vw;
  }

  /* Photos below the name sink out of view softly instead of being cut off. */
  .floaters {
    -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 64px), transparent);
    mask-image: linear-gradient(to bottom, #000 calc(100% - 64px), transparent);
  }

  .floater {
    left: var(--mx);
    top: var(--my, auto);
    bottom: var(--mb, auto);
    width: var(--mw);
  }

  .scroll-cue { display: none; }
}

@media (max-width: 760px) {
  body { font-size: 17px; }
  .services { padding-top: 12vh; }
  .service-card { padding: 34px 20px 26px; }
  .service-actions .btn { flex: 1 1 100%; }
  .btn-primary { width: 100%; letter-spacing: 0.1em; text-align: center; }
  .eyebrow { font-size: 0.72rem; margin-bottom: 18px; }
  .name { margin-top: 24px; }
  .chapter { padding-top: 12vh; }
  .chapter-head { margin-bottom: 6vh; }
  .lb-stage { padding: max(70px, env(safe-area-inset-top)) 8px calc(92px + env(safe-area-inset-bottom)); }
  .lb-close { right: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .bob, .flame, .scroll-line::after { animation: none; }
  .print, .print img, .lb-img, .portrait-frame { transition: none; }
}
