/* Recommended HTTP headers:
   Content-Type: text/css; charset=utf-8
   Cache-Control: public, max-age=31536000, immutable
   X-Content-Type-Options: nosniff
*/

@layer tokens, reset, base, layout, components, sections, motion;

/* --- Design Tokens --- */
@layer tokens {
  :root {
    --color-bg: #F8F4EF;
    --color-bg-alt: #EFE8DD;
    --color-surface: #FFFFFF;
    --color-text: #2A1F17;
    --color-text-muted: #7A6B5D;
    --color-accent: #8B6914;
    --color-accent-hover: #6D5310;
    --color-accent-soft: #C4A55A;
    --color-border: #D8CCBE;
    --color-placeholder-bg: #E8DED4;
    --color-placeholder-border: #C8BAA8;
    --color-quote-mark: #C49A6A;
    --color-shadow: rgba(42, 31, 23, 0.06);

    --font-display: 'Cormorant Garibaldi', 'Georgia', 'Times New Roman', serif;
    --font-body: 'Lora', 'Georgia', 'Times New Roman', serif;

    --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.8125rem);
    --text-sm: clamp(0.8125rem, 0.75rem + 0.3125vw, 0.9375rem);
    --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
    --text-lg: clamp(1.125rem, 1rem + 0.625vw, 1.375rem);
    --text-xl: clamp(1.5rem, 1.25rem + 1.25vw, 2rem);
    --text-2xl: clamp(2rem, 1.5rem + 2.5vw, 3rem);
    --text-3xl: clamp(2.5rem, 1.75rem + 3.75vw, 4.5rem);
    --text-hero: clamp(3rem, 2rem + 5vw, 6rem);

    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    --space-3xl: 4rem;
    --space-4xl: 6rem;
    --space-5xl: 8rem;

    --content-max: 72rem;
    --content-padding: clamp(1.25rem, 4vw, 2.5rem);
    --radius: 3px;
    --nav-height: 3rem;
  }

  @media (prefers-color-scheme: dark) {
    :root {
      --color-bg: #1A1410;
      --color-bg-alt: #211A14;
      --color-surface: #2A2218;
      --color-text: #E4DAD0;
      --color-text-muted: #A89888;
      --color-accent: #D4A84A;
      --color-accent-hover: #E0BA60;
      --color-accent-soft: #8B7A4A;
      --color-border: #3A2E24;
      --color-placeholder-bg: #2E2418;
      --color-placeholder-border: #4A3E32;
      --color-quote-mark: #A87A5A;
      --color-shadow: rgba(0, 0, 0, 0.25);
    }
  }
}

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

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    hanging-punctuation: first last;
  }

  body {
    min-height: 100svh;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

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

  button {
    font: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
  }

  p, h1, h2, h3, h4 {
    overflow-wrap: break-word;
  }

  ul, ol { list-style: none; }

  a {
    color: inherit;
    text-decoration-skip-ink: auto;
  }

  @media (prefers-reduced-motion: no-preference) {
    html { scroll-behavior: smooth; }
  }
}

/* --- Base Typography --- */
@layer base {
  body {
    font-family: var(--font-body);
    font-size: var(--text-base);
    color: var(--color-text);
    background-color: var(--color-bg);
  }

  h1, h2, h3 {
    font-family: var(--font-display);
    line-height: 1.15;
    text-wrap: balance;
  }

  h1 { font-weight: 400; }
  h2 { font-size: var(--text-2xl); font-weight: 400; letter-spacing: 0.01em; }
  h3 { font-size: var(--text-lg); font-weight: 600; line-height: 1.3; }

  blockquote {
    font-style: italic;
  }

  time {
    font-variant-numeric: tabular-nums;
  }

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

  :focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 3px;
    border-radius: var(--radius);
  }
}

/* --- Layout --- */
@layer layout {
  .content-wrap {
    max-width: var(--content-max);
    margin-inline: auto;
    padding-inline: var(--content-padding);
  }

  .card-grid {
    display: grid;
    gap: var(--space-xl);
    grid-template-columns: 1fr;
  }

  @media (min-width: 40rem) {
    .card-grid { grid-template-columns: repeat(2, 1fr); }
  }

  @media (min-width: 64rem) {
    .card-grid { grid-template-columns: repeat(3, 1fr); }
  }

  .tribute-section {
    padding-block: var(--space-4xl) var(--space-5xl);
    scroll-margin-top: var(--nav-height);
  }

  .tribute-section:nth-child(even) {
    background-color: var(--color-bg-alt);
  }
}

/* --- Components --- */
@layer components {

  /* Skip link */
  .skip-link {
    position: absolute;
    top: -100%;
    left: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    background: var(--color-surface);
    color: var(--color-accent);
    font-size: var(--text-sm);
    z-index: 100;
    border-radius: var(--radius);
  }

  .skip-link:focus {
    top: var(--space-md);
  }

  /* Section nav */
  .section-nav {
    position: sticky;
    top: 0;
    z-index: 50;
    background-color: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .section-nav::-webkit-scrollbar { display: none; }

  .section-nav ul {
    display: flex;
    justify-content: center;
    gap: var(--space-lg);
    padding: var(--space-sm) var(--content-padding);
    max-width: var(--content-max);
    margin-inline: auto;
    white-space: nowrap;
  }

  .section-nav a {
    display: block;
    padding: var(--space-xs) 0;
    font-size: var(--text-xs);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-text-muted);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: color 0.2s, border-color 0.2s;
  }

  .section-nav a:hover,
  .section-nav a:focus-visible {
    color: var(--color-accent);
    border-bottom-color: var(--color-accent);
  }

  /* Section header */
  .section-header {
    text-align: center;
    margin-bottom: var(--space-3xl);
  }

  .section-header::before {
    content: '';
    display: block;
    width: 2.5rem;
    height: 1px;
    background-color: var(--color-accent-soft);
    margin: 0 auto var(--space-xl);
  }

  .section-header p {
    margin-top: var(--space-sm);
    font-style: italic;
    color: var(--color-text-muted);
    font-size: var(--text-base);
  }

  /* Cards */
  .tribute-card {
    background-color: var(--color-surface);
    border-radius: var(--radius);
    padding: var(--space-xl);
    box-shadow: 0 1px 8px var(--color-shadow);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
  }

  .tribute-card h3 {
    color: var(--color-text);
  }

  .tribute-card .card-date {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    order: -1;
  }

  .tribute-card p {
    color: var(--color-text);
    line-height: 1.7;
  }

  .tribute-card blockquote {
    padding-left: var(--space-lg);
    border-left: 2px solid var(--color-accent-soft);
    color: var(--color-text);
  }

  .tribute-card .card-people {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    margin-top: auto;
    padding-top: var(--space-sm);
  }

  .tribute-card .card-people span {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    padding: 2px var(--space-sm);
    border: 1px solid var(--color-border);
    border-radius: 2px;
  }

  .tribute-card .card-photo {
    width: 100%;
    height: auto;
    border-radius: var(--radius);
    object-fit: cover;
  }

  /* Quote cards — special treatment */
  .tribute-quote {
    background: none;
    box-shadow: none;
    text-align: center;
    padding: var(--space-xl) var(--space-lg);
    position: relative;
  }

  .tribute-quote blockquote {
    border: none;
    padding: 0;
    font-style: normal;
  }

  .tribute-quote blockquote > p:first-child {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    font-weight: 400;
    font-style: italic;
    line-height: 1.4;
    color: var(--color-text);
  }

  .tribute-quote blockquote > p:first-child::before {
    content: '\201C';
    font-family: var(--font-display);
    font-size: 3em;
    line-height: 0;
    vertical-align: -0.35em;
    color: var(--color-quote-mark);
    margin-right: 0.05em;
  }

  .tribute-quote footer {
    margin-top: var(--space-md);
  }

  .tribute-quote cite {
    font-size: var(--text-sm);
    font-style: normal;
    color: var(--color-text-muted);
  }

  /* Mystery cards */
  .tribute-mystery {
    border-left: 2px solid var(--color-accent-soft);
  }

  /* Photo placeholder custom element */
  photo-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    aspect-ratio: 3 / 2;
    background-color: var(--color-placeholder-bg);
    border: 1px dashed var(--color-placeholder-border);
    border-radius: var(--radius);
    color: var(--color-text-muted);
    font-size: var(--text-sm);
    font-style: italic;
    padding: var(--space-lg);
    line-height: 1.4;
  }

  photo-placeholder[aspect="portrait"] { aspect-ratio: 3 / 4; }
  photo-placeholder[aspect="square"] { aspect-ratio: 1; }
  photo-placeholder[aspect="wide"] { aspect-ratio: 2 / 1; }

  /* Details / show-all */
  .section-more {
    margin-top: var(--space-md);
  }

  .section-more > summary {
    display: block;
    text-align: center;
    padding: var(--space-lg) var(--space-md);
    cursor: pointer;
    color: var(--color-accent);
    font-size: var(--text-sm);
    letter-spacing: 0.07em;
    text-transform: uppercase;
    transition: color 0.2s;
  }

  .section-more > summary:hover {
    color: var(--color-accent-hover);
  }

  .section-more > summary::marker,
  .section-more > summary::-webkit-details-marker {
    display: none;
  }

  .section-more > summary::after {
    content: ' \2193';
  }

  .section-more[open] > summary::after {
    content: ' \2191';
  }

  .section-more > .card-grid {
    margin-top: var(--space-md);
  }

  /* Visually hidden */
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}

/* --- Sections --- */
@layer sections {

  /* Hero */
  .hero {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 80svh;
    padding: var(--space-4xl) var(--content-padding);
    text-align: center;
    background-color: var(--color-bg);
  }

  .hero-content {
    max-width: 36rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xl);
  }

  .hero-dates {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    font-weight: 300;
    color: var(--color-text-muted);
    letter-spacing: 0.15em;
  }

  .hero h1 {
    font-size: var(--text-hero);
    letter-spacing: 0.02em;
    line-height: 1.05;
  }

  .hero photo-placeholder {
    width: min(16rem, 70vw);
    margin-block: var(--space-md);
  }

  .hero-portrait {
    width: min(16rem, 70vw);
    height: auto;
    border-radius: 50%;
    object-fit: cover;
    aspect-ratio: 1;
    margin-block: var(--space-md);
    box-shadow: 0 2px 20px var(--color-shadow);
  }

  .hero-quote {
    max-width: 28rem;
  }

  .hero-quote p {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    font-style: italic;
    color: var(--color-text-muted);
    line-height: 1.4;
  }

  .hero-rule {
    width: 2.5rem;
    height: 1px;
    background-color: var(--color-accent-soft);
    border: none;
  }

  /* Quote grid: 2 columns max for wider quote cards */
  #quotes .card-grid {
    grid-template-columns: 1fr;
  }

  @media (min-width: 48rem) {
    #quotes .card-grid {
      grid-template-columns: repeat(2, 1fr);
    }
  }

  /* Footer */
  .tribute-footer {
    text-align: center;
    padding: var(--space-5xl) var(--content-padding);
    background-color: var(--color-bg);
    border-top: 1px solid var(--color-border);
  }

  .tribute-footer .footer-name {
    font-family: var(--font-display);
    font-size: var(--text-2xl);
    font-weight: 400;
    margin-bottom: var(--space-sm);
  }

  .tribute-footer .footer-dates {
    font-size: var(--text-base);
    color: var(--color-text-muted);
    margin-bottom: var(--space-2xl);
  }

  .tribute-footer .footer-family,
  .tribute-footer .footer-legacy {
    font-size: var(--text-base);
    color: var(--color-text-muted);
    line-height: 1.8;
  }

  .tribute-footer .footer-closing {
    margin-top: var(--space-2xl);
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-style: italic;
    color: var(--color-text);
  }

  /* Site info / about */
  .site-info {
    padding: var(--space-3xl) var(--content-padding);
    background-color: var(--color-bg-alt);
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    line-height: 1.75;
  }

  .site-info h2 {
    font-size: var(--text-lg);
    color: var(--color-text);
    margin-bottom: var(--space-xl);
  }

  .site-info h3 {
    font-size: var(--text-base);
    color: var(--color-text);
    margin-top: var(--space-xl);
    margin-bottom: var(--space-sm);
  }

  .site-info p {
    margin-bottom: var(--space-md);
    max-width: 44rem;
  }

  .site-info .sources {
    margin-bottom: var(--space-lg);
  }

  .site-info .sources > summary {
    cursor: pointer;
    color: var(--color-accent);
    display: inline;
  }

  .site-info .sources > summary::marker,
  .site-info .sources > summary::-webkit-details-marker {
    display: none;
  }

  .site-info .sources > summary::after {
    content: ' \2193';
    font-size: 0.8em;
  }

  .site-info .sources[open] > summary::after {
    content: ' \2191';
    font-size: 0.8em;
  }

  .site-info .source-list {
    list-style: none;
    margin-top: var(--space-lg);
    padding-left: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
  }

  .site-info .source-list li {
    padding-left: var(--space-lg);
    border-left: 2px solid var(--color-border);
  }

  .site-info .source-list strong {
    color: var(--color-text);
    font-weight: 600;
  }

  .site-info .sources-grow {
    margin-top: var(--space-md);
    font-style: italic;
    font-size: var(--text-xs);
  }

  .site-info .site-example {
    padding-left: var(--space-lg);
    border-left: 2px solid var(--color-border);
    font-style: italic;
  }

  .site-info .site-credit {
    margin-top: var(--space-2xl);
    font-family: var(--font-display);
    font-size: var(--text-base);
    color: var(--color-text);
    font-style: italic;
  }
}

/* --- Motion --- */
@layer motion {
  @media (prefers-reduced-motion: no-preference) {
    .hero-content {
      animation: heroFadeIn 1.2s ease both;
    }

    .section-more[open] > .card-grid > * {
      animation: cardFadeIn 0.4s ease both;
    }

    .section-more[open] > .card-grid > :nth-child(1) { animation-delay: 0s; }
    .section-more[open] > .card-grid > :nth-child(2) { animation-delay: 0.06s; }
    .section-more[open] > .card-grid > :nth-child(3) { animation-delay: 0.12s; }
    .section-more[open] > .card-grid > :nth-child(4) { animation-delay: 0.18s; }
    .section-more[open] > .card-grid > :nth-child(5) { animation-delay: 0.24s; }
    .section-more[open] > .card-grid > :nth-child(6) { animation-delay: 0.3s; }
    .section-more[open] > .card-grid > :nth-child(7) { animation-delay: 0.36s; }

    @keyframes heroFadeIn {
      from { opacity: 0; transform: translateY(1rem); }
      to   { opacity: 1; transform: translateY(0); }
    }

    @keyframes cardFadeIn {
      from { opacity: 0; transform: translateY(0.5rem); }
      to   { opacity: 1; transform: translateY(0); }
    }

    .tribute-card {
      transition: box-shadow 0.2s ease;
    }

    .tribute-card:hover {
      box-shadow: 0 2px 16px var(--color-shadow);
    }
  }

  /* Content visibility for below-fold sections */
  .tribute-section {
    content-visibility: auto;
    contain-intrinsic-size: auto 600px;
  }
}
