/* ==========================================================================
   Spector Memorial — design system (foundation)
   Tokens, base typography, layout, navigation, shared components.
   Feature stylesheets (content/gallery/tributes/guestbook.css) build on these.
   ========================================================================== */

/* ---------- 1. Tokens ---------- */
:root {
  /* Palette — light */
  --bg: #FAF7F2;          /* warm ivory */
  --bg-elev: #FFFDF9;     /* cards, raised surfaces */
  --bg-sunken: #F3EEE6;   /* notices, subtle wells */
  --ink: #2B2926;         /* body text */
  --ink-soft: #6B655C;    /* secondary text (≈5.5:1 on --bg) */
  --accent: #1E5C40;      /* deep green — links, controls (≈7.5:1 on --bg) */
  --accent-strong: #16452F;
  --on-accent: #FFFFFF;   /* text on accent fill */
  --border: #E5DFD5;      /* hairlines */
  --border-strong: #CFC6B8;
  --error: #9B2C2C;
  --focus: #1E5C40;
  --nav-bg: rgba(250, 247, 242, 0.86);
  --shadow: 0 1px 2px rgba(43, 41, 38, 0.04), 0 4px 16px rgba(43, 41, 38, 0.05);

  /* Typography */
  --font-display: "Playfair Display", Georgia, "Times New Roman", serif;
  --font-body: "Source Sans 3", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-text: "EB Garamond", Garamond, Georgia, "Times New Roman", serif;

  --step--1: clamp(0.94rem, 0.9rem + 0.15vw, 1rem);        /* ~15–16px small text */
  --step-0:  clamp(1.125rem, 1.08rem + 0.2vw, 1.25rem);    /* 18–20px base */
  --step-1:  clamp(1.3rem, 1.2rem + 0.45vw, 1.5rem);
  --step-2:  clamp(1.55rem, 1.35rem + 0.9vw, 2rem);
  --step-3:  clamp(1.9rem, 1.55rem + 1.5vw, 2.6rem);       /* max ~2.6rem */
  --step-hero: clamp(2.2rem, 1.6rem + 2.6vw, 3.4rem);      /* honoree's name only */

  --leading: 1.65;
  --leading-prose: 1.8;
  --measure: 68ch;

  /* Space & layout */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4.5rem;
  --space-section: clamp(3.5rem, 2.5rem + 5vw, 7rem);
  --container: 1100px;
  --gutter: clamp(1rem, 0.6rem + 2vw, 2rem);   /* ≥16px */
  --radius: 10px;
  --radius-sm: 6px;
  --nav-h: 3.5rem;
  --tap: 44px;

  /* Motion */
  --ease-out: cubic-bezier(0.22, 0.61, 0.36, 1);
  --dur-fade: 400ms;
  --dur-ui: 200ms;

  color-scheme: light dark;
}

/* Dark palette applies when the system prefers dark (unless the visitor
   forced light), or when the visitor forced dark via the footer toggle.
   The two blocks below MUST stay identical — keep them in sync. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    /* Palette — dark (same property names) */
    --bg: #1C1B19;          /* warm near-black */
    --bg-elev: #252321;
    --bg-sunken: #171614;
    --ink: #EDE8E0;         /* warm light text */
    --ink-soft: #B5AEA3;    /* ≈8:1 on --bg */
    --accent: #7CC4A0;      /* lightened green (≈9:1 on --bg) */
    --accent-strong: #9AD4B6;
    --on-accent: #10231A;   /* dark text on light accent fill */
    --border: #3A3733;
    --border-strong: #55504A;
    --error: #F2A3A3;
    --focus: #7CC4A0;
    --nav-bg: rgba(28, 27, 25, 0.84);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 4px 16px rgba(0, 0, 0, 0.2);
  }
}

:root[data-theme="dark"] {
  /* Palette — dark (same property names) */
  --bg: #1C1B19;          /* warm near-black */
  --bg-elev: #252321;
  --bg-sunken: #171614;
  --ink: #EDE8E0;         /* warm light text */
  --ink-soft: #B5AEA3;    /* ≈8:1 on --bg */
  --accent: #7CC4A0;      /* lightened green (≈9:1 on --bg) */
  --accent-strong: #9AD4B6;
  --on-accent: #10231A;   /* dark text on light accent fill */
  --border: #3A3733;
  --border-strong: #55504A;
  --error: #F2A3A3;
  --focus: #7CC4A0;
  --nav-bg: rgba(28, 27, 25, 0.84);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 4px 16px rgba(0, 0, 0, 0.2);
}

.theme-toggle {
  margin-top: var(--space-3, 0.75rem);
}

/* ---------- 2. Reset / base ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--nav-h) + var(--space-4));
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: var(--leading);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;             /* belt-and-braces against stray overflow at 360px;
                                   clip (not hidden) so body never becomes a scroll
                                   container, which breaks smooth scrollIntoView */
  overflow-wrap: break-word;
}

img, svg, video { max-width: 100%; height: auto; display: block; }

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 500;
  line-height: 1.2;
  color: var(--ink);
  margin: 0 0 var(--space-4);
  text-wrap: balance;
}
h1 { font-size: var(--step-3); }
h2 { font-size: var(--step-3); }
h3 { font-size: var(--step-2); }
h4 { font-size: var(--step-1); }

p { margin: 0 0 var(--space-4); }
p:last-child { margin-bottom: 0; }

ul, ol { padding-left: 1.25em; margin: 0 0 var(--space-4); }
li + li { margin-top: var(--space-2); }

blockquote {
  margin: 0 0 var(--space-5);
  padding-left: var(--space-5);
  border-left: 2px solid var(--border-strong);
  font-family: var(--font-text);
  font-style: italic;
}

hr {
  border: 0;
  height: 1px;
  background: var(--border);
  margin: var(--space-7) auto;
  max-width: 8rem;
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  transition: color var(--dur-ui) ease;
}
a:hover { color: var(--accent-strong); text-decoration-thickness: 2px; }

small, .text-small { font-size: var(--step--1); }
.text-soft { color: var(--ink-soft); }

::selection { background: var(--accent); color: var(--on-accent); }

/* Visible focus everywhere */
:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
  border-radius: 3px;
}
main:focus-visible { outline: none; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- 3. Skip link ---------- */
.skip-link {
  position: absolute;
  left: var(--space-4);
  top: -100px;
  z-index: 200;
  padding: var(--space-3) var(--space-4);
  background: var(--accent);
  color: var(--on-accent);
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
}
.skip-link:focus,
.skip-link:focus-visible { top: var(--space-3); color: var(--on-accent); }

/* ---------- 4. Layout ---------- */
.container {
  width: 100%;
  max-width: calc(var(--container) + 2 * var(--gutter));
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.reading-column {
  max-width: var(--measure);
  margin-inline: auto;
}

.section {
  width: 100%;
  max-width: calc(var(--container) + 2 * var(--gutter));
  margin-inline: auto;
  padding: var(--space-section) var(--gutter);
  scroll-margin-top: var(--nav-h);
}
.section + .section { border-top: 1px solid var(--border); }

/* Section headings: centered, quiet, with a short hairline beneath */
.section > h2 {
  text-align: center;
  margin-bottom: var(--space-7);
}
.section > h2::after {
  content: "";
  display: block;
  width: 3rem;
  height: 1px;
  margin: var(--space-4) auto 0;
  background: var(--accent);
  opacity: 0.6;
}

/* Empty bodies (before feature modules render) look intentional, not broken */
.section-body:empty { min-height: 3rem; }

/* Hero */
.section--hero {
  min-height: calc(100vh - var(--nav-h));
  min-height: calc(100svh - var(--nav-h));
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-block: var(--space-7);
}
.section--hero > .section-body { width: 100%; }
.section--hero + .section { border-top: 0; }

/* ---------- 5. Navigation ---------- */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .site-nav {
    background: var(--nav-bg);
    -webkit-backdrop-filter: saturate(140%) blur(10px);
    backdrop-filter: saturate(140%) blur(10px);
  }
}

.site-nav__inner {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  min-height: var(--nav-h);
}

.site-nav__title {
  flex: none;
  font-family: var(--font-display);
  font-size: var(--step-0);
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.site-nav__title:hover { color: var(--ink); text-decoration: none; }

.site-nav nav { flex: 1 1 auto; min-width: 0; }

.site-nav__links {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-1);
  list-style: none;
  margin: 0;
  padding: 0;
}
.site-nav__links li { margin: 0; flex: none; }

.site-nav__link {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 var(--space-3);
  font-size: var(--step--1);
  color: var(--ink-soft);
  text-decoration: none;
  white-space: nowrap;
  border-radius: 999px;
  position: relative;
  transition: color var(--dur-ui) ease, background-color var(--dur-ui) ease;
}
.site-nav__link:hover { color: var(--ink); text-decoration: none; }
.site-nav__link.is-active { color: var(--accent); }
.site-nav__link.is-active::after {
  content: "";
  position: absolute;
  left: var(--space-3);
  right: var(--space-3);
  bottom: 8px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}

/* Mobile + tablet: horizontally scrollable row of chips, no hamburger */
@media (max-width: 900px) {
  .site-nav__title { display: none; }
  .site-nav__inner { padding-inline: 0; }
  .site-nav nav {
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    /* soft fade at the edges hints that the row scrolls */
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 var(--gutter), #000 calc(100% - var(--gutter)), transparent 100%);
    mask-image: linear-gradient(to right, transparent 0, #000 var(--gutter), #000 calc(100% - var(--gutter)), transparent 100%);
  }
  .site-nav nav::-webkit-scrollbar { display: none; }
  .site-nav__links {
    justify-content: flex-start;
    gap: var(--space-2);
    padding: var(--space-2) var(--gutter);
    width: max-content;
  }
  .site-nav__link {
    border: 1px solid var(--border);
    background: var(--bg-elev);
    padding: 0 var(--space-4);
  }
  .site-nav__link.is-active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
  }
  .site-nav__link.is-active::after { display: none; }
}

/* ---------- 6. Footer ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding-block: var(--space-7);
  text-align: center;
  color: var(--ink-soft);
  font-size: var(--step--1);
}

/* ---------- 7. Shared components ---------- */

/* Card — tribute and guestbook entries share this look */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-5);
  box-shadow: var(--shadow);
}
.card__name {
  font-family: var(--font-display);
  font-size: var(--step-1);
  font-weight: 500;
  margin: 0;
  line-height: 1.3;
}
.card__meta {
  color: var(--ink-soft);
  font-size: var(--step--1);
  margin: var(--space-1) 0 var(--space-4);
}
.card__text { white-space: pre-line; }

/* Buttons */
.btn,
.btn-quiet {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 var(--space-5);
  font: inherit;
  font-size: var(--step--1);
  font-weight: 600;
  line-height: 1.2;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  transition: background-color var(--dur-ui) ease, color var(--dur-ui) ease, border-color var(--dur-ui) ease;
}
.btn {
  background: var(--accent);
  color: var(--on-accent);
  border: 1px solid var(--accent);
}
.btn:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--on-accent); text-decoration: none; }

.btn-quiet {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border-strong);
}
.btn-quiet:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

.btn:disabled,
.btn-quiet:disabled,
.btn[aria-disabled="true"],
.btn-quiet[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }

/* Gentle notices (fallbacks, confirmations, backend unavailable) */
.notice {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: var(--space-4) var(--space-5);
  color: var(--ink);
}
.notice--error { border-left-color: var(--error); }

/* Respectful placeholder text (content not yet available) */
.placeholder {
  max-width: var(--measure);
  margin-inline: auto;
  text-align: center;
  font-family: var(--font-text);
  font-style: italic;
  font-size: var(--step-1);
  color: var(--ink-soft);
}

/* Forms */
.field { margin-bottom: var(--space-5); }
.field label,
.label {
  display: block;
  margin-bottom: var(--space-2);
  font-weight: 600;
  font-size: var(--step--1);
}
.field-hint {
  display: block;
  margin-top: var(--space-1);
  color: var(--ink-soft);
  font-size: var(--step--1);
}
input[type="text"],
input[type="email"],
input[type="search"],
input:not([type]),
textarea,
select {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: var(--space-3) var(--space-4);
  font: inherit;
  font-size: var(--step-0);   /* ≥16px avoids iOS zoom */
  color: var(--ink);
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color var(--dur-ui) ease, box-shadow var(--dur-ui) ease;
}
textarea { min-height: 9rem; resize: vertical; line-height: var(--leading); }
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--accent);
}
[aria-invalid="true"] { border-color: var(--error); }
.field-error {
  display: block;
  margin-top: var(--space-2);
  color: var(--error);
  font-size: var(--step--1);
}
.field-error:empty { display: none; }

/* Polite status region for form outcomes: <p class="form-status" aria-live="polite"></p>.
   Keep it in the DOM (never display:none) so screen readers announce updates. */
.form-status { margin-top: var(--space-4); }
.form-status:empty { margin: 0; }
.form-status--error { color: var(--error); }

/* ---------- 8. Motion: fade-in on first entry ---------- */
.fade-in {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity var(--dur-fade) var(--ease-out), transform var(--dur-fade) var(--ease-out);
}
.fade-in.is-visible {
  opacity: 1;
  transform: none;
}

/* ---------- 9. Back to top ---------- */
.back-to-top {
  position: fixed;
  right: var(--gutter);
  bottom: calc(var(--gutter) + env(safe-area-inset-bottom, 0px));
  z-index: 90;
  width: var(--tap);
  height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 1.2rem;
  line-height: 1;
  color: var(--accent);
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  box-shadow: var(--shadow);
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--dur-ui) ease, transform var(--dur-ui) ease;
}
.back-to-top[hidden] { display: none; }
.back-to-top.is-shown { opacity: 1; transform: none; }
.back-to-top:hover { border-color: var(--accent); }

/* ---------- 10. Reduced motion: everything static ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto !important; }
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
  .fade-in { opacity: 1; transform: none; }
}

/* ---------- 11. Print ---------- */
@media print {
  .site-nav, .back-to-top, .skip-link { display: none !important; }
  .fade-in { opacity: 1 !important; transform: none !important; }
  body { background: #fff; color: #000; }
}
