:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --ink: #2b2622;
  --muted: #6f655c;
  --accent: #8a6a3d;
  --line: #e6ded2;
  --on-accent: #ffffff;
  color-scheme: light;
  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --sans: "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* Dark mode: follows the device unless the visitor picks a mode with the toggle. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1815; --surface: #25211d; --ink: #ece5db; --muted: #b3a797;
    --accent: #cfa96f; --line: #3a332c; --on-accent: #1b1815; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1815; --surface: #25211d; --ink: #ece5db; --muted: #b3a797;
  --accent: #cfa96f; --line: #3a332c; --on-accent: #1b1815; color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 64px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 18px/1.7 var(--sans);
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 10px 24px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font: 600 22px var(--serif); color: var(--ink); text-decoration: none; margin-right: auto; }
.topbar nav { display: flex; gap: 20px; }
.topbar nav a { color: var(--muted); text-decoration: none; font-size: 16px; }
.topbar nav a:hover { color: var(--accent); }
.lang { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.lang button {
  font: 600 14px var(--sans); color: var(--muted);
  background: none; border: 0; padding: 6px 14px; cursor: pointer;
}
.lang button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.theme-toggle {
  display: grid; place-items: center; width: 34px; height: 34px; padding: 0; cursor: pointer;
  background: none; color: var(--muted); border: 1px solid var(--line); border-radius: 50%;
}
.theme-toggle:hover { color: var(--accent); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }

/* Hero */
.hero {
  display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  gap: 56px; align-items: center;
  max-width: 1100px; margin: 0 auto; padding: 64px 24px 48px;
}
.hero-photo img {
  width: 100%; height: auto; aspect-ratio: 4 / 5; object-fit: cover; object-position: top;
  border-radius: 6px;
  box-shadow: 0 1px 2px rgb(0 0 0 / .08), 0 20px 40px -20px rgb(60 40 20 / .35);
}
.eyebrow { margin: 0; color: var(--accent); letter-spacing: .14em; text-transform: uppercase; font-size: 14px; font-weight: 600; }
h1 { font: 500 clamp(44px, 7vw, 76px)/1.05 var(--serif); margin: 12px 0 8px; }
.nickname { font: 500 20px var(--serif); color: var(--accent); letter-spacing: .02em; margin: 0 0 6px; }
.dates { font: italic 400 24px var(--serif); color: var(--muted); margin: 0 0 32px; }
blockquote { margin: 0; padding-left: 20px; border-left: 2px solid var(--accent); }
blockquote p { font: italic 400 24px/1.4 var(--serif); margin: 0 0 6px; }
cite { font-style: normal; color: var(--muted); font-size: 15px; }

/* Service */
.service { max-width: 1000px; margin: 0 auto; padding: 48px 24px; border-top: 1px solid var(--line); }
.events { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.event { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 20px; text-align: center; }
.event h3 { font: 600 26px/1.2 var(--serif); margin: 0 0 4px; }
.event .when { color: var(--accent); font-weight: 600; margin: 0 0 8px; }
.event p { margin: 0 0 12px; }
.event a, .arranged a { color: var(--accent); font-weight: 600; }
.flyer { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 32px; align-items: center; margin-top: 40px; }
.flyer img { width: 100%; height: auto; border-radius: 4px; box-shadow: 0 12px 30px -16px rgb(0 0 0 / .45); }
.flyer-text p { margin: 0 0 16px; }
.button { display: inline-block; background: var(--accent); color: var(--on-accent); text-decoration: none; font-weight: 600; padding: 10px 20px; border-radius: 999px; margin-bottom: 20px; }
.arranged { color: var(--muted); font-size: 16px; }

/* Life */
section h2 { font: 500 40px/1.2 var(--serif); text-align: center; margin: 0 0 8px; }
.life { max-width: 720px; margin: 0 auto; padding: 48px 24px 24px; border-top: 1px solid var(--line); }
.listen {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 16px;
  margin: 16px 0 32px; color: var(--muted); font-size: 16px;
}
.listen > span { align-self: flex-start; line-height: 54px; }  /* level with the player, not the badge */
.listen .player { display: flex; flex-direction: column; align-items: center; gap: 8px; width: min(100%, 360px); }
.listen audio { width: 100%; }
.powered { display: flex; align-items: center; justify-content: center; gap: 8px;
  color: var(--muted); font-size: 13px; text-decoration: none; }
.powered img { width: 110px; height: auto; }
.powered:hover span { color: var(--accent); }
.obituary p { margin: 0 0 1.2em; }
.obituary p:first-child::first-letter {
  float: left; font: 500 64px/0.85 var(--serif); color: var(--accent); padding: 6px 8px 0 0;
}

/* Photos */
.photos { max-width: 1200px; margin: 0 auto; padding: 48px 24px 64px; border-top: 1px solid var(--line); }
.sub { text-align: center; color: var(--muted); margin: 0 0 32px; }
/* Justified rows: photos read left to right in date order. Each tile grows in proportion to its
   aspect ratio (--r), so every photo in a row has the same height and nothing is cropped. */
.gallery { --row-h: 220px; display: flex; flex-wrap: wrap; gap: 10px; }
.gallery::after { content: ''; flex-grow: 1e4; }  /* keep the last row from stretching */
.gallery button {
  flex: var(--r) 1 calc(var(--r) * var(--row-h)); display: block; padding: 0; border: 0; background: var(--line);
  border-radius: 4px; overflow: hidden; cursor: zoom-in;
}
.gallery img { width: 100%; height: auto; transition: transform .3s ease, opacity .3s ease; }
.gallery button:hover img { transform: scale(1.03); }
.gallery button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.gallery .cap { display: block; padding: 6px 8px; font-size: 14px; color: var(--muted); background: var(--surface); text-align: left; }

/* Lightbox */
.lightbox {
  width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: rgb(20 16 12 / .95); color: #fff;
}
.lightbox[open] { display: flex; align-items: center; justify-content: center; }
.lightbox::backdrop { background: rgb(20 16 12 / .95); }
.lightbox figure { margin: 0; max-width: calc(100vw - 140px); text-align: center; }
.lightbox img { max-height: calc(100vh - 100px); width: auto; margin: 0 auto; border-radius: 3px; }
.lightbox figcaption { margin-top: 12px; font-size: 16px; color: #ddd; min-height: 1.5em; }
.lightbox button {
  position: absolute; background: rgb(255 255 255 / .1); color: #fff; border: 0; cursor: pointer;
  font: 32px/1 var(--sans); width: 48px; height: 48px; border-radius: 50%;
}
.lightbox button:hover { background: rgb(255 255 255 / .2); }
.lb-close { top: 16px; right: 16px; }
.lb-prev { left: 16px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 16px; top: 50%; transform: translateY(-50%); }

/* Guestbook */
.guestbook { max-width: 760px; margin: 0 auto; padding: 48px 24px 64px; border-top: 1px solid var(--line); }
.gb-form { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 24px; }
.gb-form label { display: flex; flex-direction: column; gap: 4px; font-size: 15px; font-weight: 600; color: var(--muted); }
.gb-form .full { grid-column: 1 / -1; }
.gb-form input, .gb-form textarea { font: 17px/1.5 var(--sans); color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 10px 12px; }
.gb-form input:focus, .gb-form textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.gb-form .trap { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.gb-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; }
.gb-actions .button { margin: 0; border: 0; cursor: pointer; font: 600 17px var(--sans); }
.gb-actions .button:disabled { opacity: .6; cursor: default; }
.gb-status { margin: 0; color: var(--muted); font-size: 16px; }
.gb-list { list-style: none; padding: 0; margin: 32px 0 0; }
.gb-list li { padding: 20px 0; border-bottom: 1px solid var(--line); }
.gb-list .who { font: 600 22px/1.3 var(--serif); }
.gb-list .meta { color: var(--muted); font-size: 15px; margin-bottom: 8px; }
.gb-list .msg { white-space: pre-line; margin: 0; }

footer { text-align: center; padding: 40px 24px 56px; border-top: 1px solid var(--line); }
footer p { font: italic 400 24px/1.4 var(--serif); color: var(--muted); max-width: 640px; margin: 0 auto; }

@media (max-width: 760px) {
  body { font-size: 17px; }
  .topbar { padding: 8px 16px; gap: 12px; }
  .topbar nav { display: none; }
  .hero { grid-template-columns: 1fr; gap: 28px; padding: 32px 16px; text-align: center; }
  .hero-photo { max-width: 340px; margin: 0 auto; }
  blockquote { border-left: 0; padding: 0; }
  .events, .flyer { grid-template-columns: 1fr; }
  .flyer { gap: 20px; text-align: center; }
  .flyer img { max-width: 360px; margin: 0 auto; }
  .gb-form { grid-template-columns: 1fr; padding: 16px; }
  .service, .life, .photos, .guestbook { padding-left: 16px; padding-right: 16px; }
  .gallery { --row-h: 120px; gap: 6px; }
  .listen > span { align-self: center; line-height: inherit; }
  .lightbox figure { max-width: 100vw; }
  .lb-prev, .lb-next { top: auto; bottom: 16px; transform: none; }
}
.gallery .cap[hidden] { display: none; }
