/* ============================================================
   Father Sanchez's Web Site of West Indian Natural History
   Design system — full redesign, no build step.
   ============================================================ */

:root {
  /* Palette — reverent, natural, Caribbean */
  --green:        #1f4d3a;
  --green-deep:   #163828;
  --green-soft:   #2f6a50;
  --maroon:       #5a1e1e;
  --maroon-soft:  #7a2e24;
  --gold:         #b8893b;
  --bg:           #faf7f0;
  --bg-raised:    #ffffff;
  --bg-sunken:    #f1ebde;
  --ink:          #2a2520;
  --ink-soft:     #5c544a;
  --line:         #e3dccd;
  --shadow:       0 1px 2px rgba(40,32,24,.06), 0 8px 24px rgba(40,32,24,.08);
  --shadow-lg:    0 12px 48px rgba(20,16,12,.28);

  --accent:       var(--maroon);
  --accent-hover: var(--maroon-soft);

  --sidebar-w:    clamp(15rem, 22vw, 19rem);
  --topbar-h:     3.75rem;
  --measure:      68ch;
  --radius:       12px;
  --radius-sm:    8px;

  --serif: "EB Garamond", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans:  "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  color-scheme: light;
}

[data-theme="dark"] {
  --green:        #6fbf97;
  --green-deep:   #0e1a14;
  --green-soft:   #8fd4b0;
  --maroon:       #e09b8c;
  --maroon-soft:  #eab3a6;
  --gold:         #d9ab63;
  --bg:           #14110d;
  --bg-raised:    #1d1913;
  --bg-sunken:    #100d09;
  --ink:          #ece4d6;
  --ink-soft:     #b3a892;
  --line:         #322b22;
  --shadow:       0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.45);
  --shadow-lg:    0 12px 48px rgba(0,0,0,.6);
  --accent:       var(--maroon);
  --accent-hover: var(--maroon-soft);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.05rem, 0.95rem + 0.4vw, 1.2rem);
  line-height: 1.7;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 0 clamp(1rem, 3vw, 2rem);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar__title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.15rem;
  letter-spacing: .01em;
  color: var(--green);
  text-decoration: none;
  line-height: 1.15;
}
.topbar__title small { display: block; font-size: .72rem; font-weight: 500; color: var(--ink-soft); font-family: var(--sans); letter-spacing: .04em; text-transform: uppercase; }
.topbar__spacer { flex: 1; }

.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.5rem; height: 2.5rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--bg-raised); color: var(--ink);
  cursor: pointer; font-size: 1.15rem; line-height: 1;
  transition: background .15s, border-color .15s, transform .1s;
}
.iconbtn:hover { border-color: var(--green); }
.iconbtn:active { transform: scale(.94); }
.navtoggle { display: none; }

/* ---------- Sidebar nav ---------- */
.sidebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  width: var(--sidebar-w);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 1.5rem 1rem 4rem;
  background: var(--bg-sunken);
  border-right: 1px solid var(--line);
  z-index: 30;
  overscroll-behavior: contain;
}
.nav-group { margin-bottom: 1.4rem; }
.nav-group__label {
  font-family: var(--sans);
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 0 .35rem .65rem;
}
.sidebar a {
  display: block;
  font-family: var(--sans);
  font-size: .9rem;
  line-height: 1.35;
  color: var(--ink-soft);
  text-decoration: none;
  padding: .4rem .65rem;
  border-radius: var(--radius-sm);
  transition: background .12s, color .12s;
}
.sidebar a:hover { background: color-mix(in srgb, var(--green) 10%, transparent); color: var(--ink); }
.sidebar a[aria-current="page"] {
  background: color-mix(in srgb, var(--green) 16%, transparent);
  color: var(--green);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--green);
}

/* ---------- Main content ---------- */
.content {
  margin-left: var(--sidebar-w);
  min-height: calc(100vh - var(--topbar-h));
}
.prose {
  max-width: var(--measure);
  margin: 0 auto;
  padding: clamp(1.5rem, 4vw, 3.5rem) clamp(1.1rem, 4vw, 2.5rem) 5rem;
}
.prose > .full,
.prose > figure { max-width: none; }

.prose h1 {
  font-size: clamp(2rem, 1.4rem + 2.4vw, 3.1rem);
  line-height: 1.12;
  font-weight: 600;
  color: var(--green);
  margin: 0 0 1.5rem;
  letter-spacing: -.01em;
}
.prose h2 {
  font-size: clamp(1.5rem, 1.2rem + 1vw, 2rem);
  color: var(--maroon);
  margin: 2.5rem 0 .8rem;
  font-weight: 600;
}
.prose p { margin: 0 0 1.15rem; }
.prose i, .prose em { /* scientific names */ }

.prose blockquote {
  margin: 1.5rem 0 2rem;
  padding: .2rem 0 .2rem 1.4rem;
  border-left: 3px solid var(--gold);
  color: var(--green);
  font-style: italic;
  font-size: 1.08em;
}
.prose blockquote cite {
  display: block;
  margin-top: .5rem;
  font-style: normal;
  font-family: var(--sans);
  font-size: .82rem;
  font-weight: 600;
  letter-spacing: .03em;
  color: var(--ink-soft);
}
hr { border: none; border-top: 1px solid var(--line); margin: 3rem 0; }

/* ---------- Hero (homepage) ---------- */
.hero {
  position: relative;
  text-align: center;
  padding: clamp(3rem, 8vw, 6rem) 1.2rem clamp(2rem, 5vw, 3.5rem);
  background:
    radial-gradient(120% 120% at 50% -10%, color-mix(in srgb, var(--green) 14%, transparent), transparent 60%);
  border-bottom: 1px solid var(--line);
}
.hero h1 {
  font-size: clamp(2.2rem, 1.4rem + 4vw, 4rem);
  line-height: 1.08;
  font-weight: 600;
  color: var(--green);
  margin: 0 0 1rem;
}
.hero__epigraph {
  max-width: 44ch;
  margin: 1.5rem auto 0;
  font-style: italic;
  color: var(--maroon);
  font-size: clamp(1.05rem, 0.95rem + .6vw, 1.35rem);
  line-height: 1.6;
}
.hero__epigraph cite { display:block; margin-top:.6rem; font-style: normal; font-family: var(--sans); font-size:.8rem; font-weight:600; letter-spacing:.04em; color: var(--ink-soft); }

/* ---------- Galleries ---------- */
figure { margin: 0; }
.prose > figure { margin: 2.2rem 0; }

.gallery {
  margin: 2.4rem 0;
}
.gallery__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  gap: 1rem;
  align-items: start;
}
.gallery--single .gallery__grid {
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
}
.gallery a {
  display: block;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
  box-shadow: var(--shadow);
  line-height: 0;
  transition: transform .2s ease, box-shadow .2s ease;
}
.gallery a:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.gallery img { width: 100%; height: auto; }
.gallery--single img { object-fit: contain; max-height: 78vh; width: auto; margin: 0 auto; }
.gallery figcaption,
figure > figcaption {
  margin-top: .8rem;
  font-family: var(--sans);
  font-size: .85rem;
  line-height: 1.5;
  color: var(--ink-soft);
  text-align: center;
}
figcaption i, figcaption em { font-style: italic; }

/* ---------- Footer ---------- */
.site-footer {
  margin-left: var(--sidebar-w);
  padding: 2.5rem clamp(1.1rem, 4vw, 2.5rem) 3rem;
  border-top: 1px solid var(--line);
  background: var(--bg-sunken);
  font-family: var(--sans);
  font-size: .85rem;
  color: var(--ink-soft);
  text-align: center;
}
.site-footer p { margin: .3rem 0; }
.site-footer a { color: var(--green); font-weight: 500; }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  display: none;
  align-items: center; justify-content: center;
  background: rgba(10,8,6,.92);
  backdrop-filter: blur(4px);
  padding: clamp(.5rem, 3vw, 2rem);
}
.lightbox.open { display: flex; }
.lightbox__fig { margin: 0; max-width: 100%; max-height: 100%; display: flex; flex-direction: column; align-items: center; gap: .9rem; }
.lightbox__img {
  max-width: 100%;
  max-height: 82vh;
  width: auto; height: auto;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  background: #000;
}
.lightbox__cap {
  font-family: var(--sans); font-size: .9rem; line-height: 1.5;
  color: #f3ead9; text-align: center; max-width: 70ch;
}
.lightbox__cap i { font-style: italic; }
.lightbox__close, .lightbox__nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 3rem; height: 3rem; border-radius: 999px;
  border: 1px solid rgba(255,255,255,.25); background: rgba(0,0,0,.4);
  color: #fff; font-size: 1.5rem; cursor: pointer; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.lightbox__nav:hover, .lightbox__close:hover { background: rgba(255,255,255,.2); }
.lightbox__prev { left: clamp(.5rem, 2vw, 1.5rem); }
.lightbox__next { right: clamp(.5rem, 2vw, 1.5rem); }
.lightbox__close { top: clamp(.5rem,2vw,1.5rem); right: clamp(.5rem,2vw,1.5rem); transform: none; width:2.75rem; height:2.75rem; }
.lightbox__count { position: absolute; bottom: clamp(.5rem,2vw,1.2rem); left: 50%; transform: translateX(-50%); font-family: var(--sans); font-size:.8rem; color:#cdbfa8; }

/* ---------- Backdrop for mobile drawer ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 25;
  background: rgba(20,16,12,.45);
  opacity: 0; visibility: hidden; transition: opacity .2s;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .navtoggle { display: inline-flex; }
  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: var(--shadow-lg);
    width: min(20rem, 84vw);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .scrim { opacity: 1; visibility: visible; }
  .content, .site-footer { margin-left: 0; }
}

/* ---------- Skeleton / staged reveal ---------- */
/* `.skel` is added synchronously in each page's <head> before first paint,
   and only when JS is enabled — so the rules below never hide content for
   no-JS users or if site.js fails (a safety timeout strips `.skel`). */

/* Phase 1: hide text until phase 2 begins */
.skel .prose > :is(h1, h2, p, blockquote, figcaption, hr),
.skel .hero  > :is(h1, p) { opacity: 0; }

/* Phase 2: text fades in */
.skel.skel-text .prose > :is(h1, h2, p, blockquote, figcaption, hr),
.skel.skel-text .hero  > :is(h1, p) {
  opacity: 1;
  transition: opacity .5s ease;
}

/* Phase 1: image slots shimmer as placeholders (boxes already sized via width/height attrs).
   Scoped to a:has(img) so empty lightbox-only links (<a><br></a>) don't shimmer forever. */
.skel .gallery a:has(img):not(.is-loaded) {
  background:
    linear-gradient(90deg,
      color-mix(in srgb, var(--ink) 6%, transparent) 25%,
      color-mix(in srgb, var(--ink) 12%, transparent) 37%,
      color-mix(in srgb, var(--ink) 6%, transparent) 63%)
    var(--bg-sunken);
  background-size: 400% 100%;
  animation: skel-shimmer 1.4s ease infinite;
}
.skel .gallery a:not(.is-loaded) img { opacity: 0; }

/* Phase 3: real image fades in once loaded */
.skel .gallery a.is-loaded img { opacity: 1; transition: opacity .45s ease; }

@keyframes skel-shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
  /* Static tint instead of an animated shimmer */
  .skel .gallery a:has(img):not(.is-loaded) { animation: none; }
}

/* ---------- noscript fallback ---------- */
.noscript-nav {
  font-family: var(--sans); font-size: .9rem;
  padding: 1rem clamp(1.1rem,4vw,2.5rem);
  background: var(--bg-sunken); border-bottom: 1px solid var(--line);
}
.noscript-nav a { margin-right: 1rem; white-space: nowrap; }
