/* ============================================================================
   Calvin van der Merwe — birding portfolio
   "Field-guide" identity: pale-lichen paper / deep-forest dark, russet accent.
   Light is the base palette; dark overrides follow. A [data-theme] on <html>
   (set by the toggle) wins over the system preference in both directions.
   ============================================================================ */

/* Netlify injects a free-tier "Powered by Netlify" badge (an iframe) into the
   served HTML; hide it. See note in deploy docs about the tier tradeoff. */
#nl-badge-frame, #netlify-badge, .netlify-badge { display: none !important; }

:root {
  /* Type */
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  /* Light — pale lichen paper, deep-forest ink */
  --paper: #e7e3d6;
  --paper-raised: #efece1;
  --ink: #1f2a22;
  --ink-soft: #56604f;
  --ink-faint: #8b9184;
  --line: rgba(31, 42, 34, 0.14);
  --line-strong: rgba(31, 42, 34, 0.28);
  --accent: #b4552f; /* russet */
  --accent-ink: #ffffff;
  --overlay: rgba(20, 28, 22, 0.66);
  --shadow: 0 18px 50px -20px rgba(20, 30, 22, 0.45);

  --wall-bg: #dcd8ca;
  --filler-tint: #bcc7a3; /* sage — multiplied over the grayscale out-of-bounds hexes */
  --tile-radius: 10px;
  --header-h: 82px;
  --filters-h: 62px;
  --footer-h: 52px;
  /* One shared horizontal gutter so header, filters and footer line up and
     breathe on wide screens instead of hugging the edges. */
  --page-pad: clamp(1.5rem, 3.5vw, 5.5rem);

  color-scheme: light;
}

:root[data-theme="dark"],
:root:not([data-theme="light"]) {
  /* falls back to light above unless the system asks for dark */
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #16211b;
    --paper-raised: #1d2b23;
    --ink: #e8e4d7;
    --ink-soft: #a9b1a3;
    --ink-faint: #6f776c;
    --line: rgba(232, 228, 215, 0.14);
    --line-strong: rgba(232, 228, 215, 0.28);
    --accent: #cc6a3f;
    --accent-ink: #14201a;
    --overlay: rgba(6, 12, 8, 0.72);
    --shadow: 0 18px 60px -18px rgba(0, 0, 0, 0.7);
    --wall-bg: #101913;
    --filler-tint: #2c6647; /* deep forest — tints the out-of-bounds hexes green */
    color-scheme: dark;
  }
}

/* Explicit dark toggle wins regardless of system setting */
:root[data-theme="dark"] {
  --paper: #16211b;
  --paper-raised: #1d2b23;
  --ink: #e8e4d7;
  --ink-soft: #a9b1a3;
  --ink-faint: #6f776c;
  --line: rgba(232, 228, 215, 0.14);
  --line-strong: rgba(232, 228, 215, 0.28);
  --accent: #cc6a3f;
  --accent-ink: #14201a;
  --overlay: rgba(6, 12, 8, 0.72);
  --shadow: 0 18px 60px -18px rgba(0, 0, 0, 0.7);
  --wall-bg: #101913;
  --filler-tint: #2c6647;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { height: 100%; }
/* body uses min-height (below), never a fixed height: the home wall fills one
   screen via flex, while a tall content page (a photo, About) can grow and
   scroll instead of overflowing under the footer. */

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* The home fills exactly one screen via flex (not vh math): header + filters +
   wall + footer, with the wall taking the leftover space. */
main#main { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

a { color: inherit; }

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 0.6rem 1rem;
  z-index: 100;
}
.skip-link:focus { left: 0; }

/* ── Header ─────────────────────────────────────────────────────────────── */
.site-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 0 var(--page-pad);
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand { text-decoration: none; display: flex; flex-direction: column; line-height: 1.2; gap: 6px; }
.brand-name { font-size: 1.25rem; letter-spacing: 0.2px; }
.brand-sub {
  font-family: var(--sans);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-faint);
  margin-top: 2px;
}
.site-nav { display: flex; align-items: center; gap: clamp(1.25rem, 2vw, 2.25rem); }
.site-nav a {
  font-family: var(--sans);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  text-decoration: none;
  color: var(--ink-soft);
  padding: 0.4rem 0;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.site-nav a:hover { color: var(--ink); border-bottom-color: var(--accent); }

.theme-toggle {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}
.theme-toggle-dot {
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: inset -4px -4px 0 0 var(--paper);
}
:root[data-theme="dark"] .theme-toggle-dot,
:root:not([data-theme="light"]) .theme-toggle-dot {
  /* handled by tokens; the inset shadow reads as a crescent moon in both modes */
}

/* ── Footer ─────────────────────────────────────────────────────────────── */
.site-footer {
  margin-top: auto;
  height: var(--footer-h);
  display: flex;
  align-items: center;
  padding: 0 var(--page-pad);
  border-top: 1px solid var(--line);
  color: var(--ink-faint);
  font-size: 0.78rem;
  font-family: var(--sans);
}
.site-footer p { margin: 0; }

/* ── Filters (floating, top-right of the grid; cascades down) ─────────────── */
.wall-filters {
  position: absolute;
  top: 14px; right: 14px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.filter-toggle {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-family: var(--sans); font-size: 0.85rem; color: var(--ink);
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line-strong);
  border-radius: 999px; padding: 0.45rem 0.9rem; cursor: pointer;
}
.filter-toggle:hover { border-color: var(--ink-soft); }
.filter-toggle .funnel { color: var(--accent); }
.filter-toggle .chev { color: var(--ink-faint); transition: transform 0.2s ease; }
.wall-filters.open .filter-toggle .chev { transform: rotate(180deg); }
/* The category options cascade straight down from the button as a small menu. */
.filter-chips {
  display: none;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  margin-top: 8px;
  padding: 7px;
  min-width: 170px;
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.wall-filters.open .filter-chips { display: flex; }
.filter-chips .filter { justify-content: flex-start; width: 100%; border-color: transparent; background: transparent; }
.filter-chips .filter:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); }
.filter {
  font-family: var(--sans);
  font-size: 0.82rem;
  letter-spacing: 0.03em;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 0.45rem 0.95rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}
.filter:hover { color: var(--ink); }
.filter .swatch {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--swatch, var(--accent));
}
.filter[aria-pressed="true"] {
  color: var(--accent-ink);
  background: var(--cat, var(--accent));
  border-color: transparent;
}
.filter[aria-pressed="true"] .swatch { background: var(--accent-ink); opacity: 0.9; }

/* ── Photo wall ─────────────────────────────────────────────────────────── */
.wall-viewport {
  position: relative;
  overflow: hidden;
  background: var(--wall-bg);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  flex: 1 1 auto; /* fill the leftover space after header/filters/footer */
  min-height: 320px;
  cursor: grab;
  touch-action: none;
  /* Dragging must not text/image-select the tiles (the blue highlight). */
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.wall-viewport.dragging { cursor: grabbing; }

/* Theatrical soft shading: a small shadow over the top, a larger one over the
   bottom. Overlays the honeycomb but never intercepts drags/clicks. */
.wall-viewport::before,
.wall-viewport::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  pointer-events: none;
  z-index: 5;
}
.wall-viewport::before {
  top: 0; height: 16%;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.3), transparent);
}
.wall-viewport::after {
  bottom: 0; height: 36%;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.62), transparent);
}

/* SVG hexagon mesh that renders the bulging honeycomb (shown once JS builds it). */
.wall-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: none; touch-action: none; }
.wall-viewport.svg-on .wall-svg { display: block; }
.wall-viewport.svg-on .wall-plane { display: none; }
/* Hide the no-JS fallback tiles before first paint when JS is on, so their
   images never enter the loading queue (the SVG wall handles images itself). */
html.js .wall-plane { display: none; }
.wall-svg image { cursor: pointer; }
/* Out-of-bounds filler hexes are grayscale; multiply a themed tint over them so
   the ring reads as part of the site (green in dark mode, sage in light) rather
   than dead grey. Per-cell opacity (set in wall.js) fades it by distance. */
.wall-svg .ftint { fill: var(--filler-tint); mix-blend-mode: multiply; }

/* No-JS fallback: a plain wrapped gallery so tiles are visible without the canvas. */
.wall-plane {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: flex-start;
  gap: 12px;
  padding: 24px;
}
/* JS on: the plane becomes an absolutely-positioned, translate+scale canvas. */
.wall-plane.canvas {
  position: absolute;
  top: 0; left: 0;
  display: block;
  gap: 0;
  padding: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.tile {
  position: relative;
  width: 150px;
  height: 150px;
  /* Regular pointy-top hexagon (width = √3/2 · height) so cells tessellate. */
  clip-path: polygon(50% 0%, 93.3% 25%, 93.3% 75%, 50% 100%, 6.7% 75%, 6.7% 25%);
  overflow: hidden;
  background: var(--paper-raised);
  transform-origin: 0 0; /* JS transform places the tile absolutely */
  transition: none;
  cursor: pointer;
  border: 0;
  padding: 0;
}
/* Thin seam so touching cells read as a honeycomb. */
.tile::after { border-color: rgba(255, 255, 255, 0.14); }
/* JS on: tiles are positioned purely by their fisheye transform. */
.wall-plane.canvas .tile { position: absolute; left: 0; top: 0; }
.tile img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
}
.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: inherit;
}
.tile-cat {
  position: absolute;
  left: 50%; bottom: 11px;
  transform: translateX(-50%);
  width: 9px; height: 9px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35);
}

.wall-hint {
  position: absolute;
  left: 50%; bottom: 14px;
  transform: translateX(-50%);
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  background: color-mix(in srgb, var(--paper) 80%, transparent);
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  pointer-events: none;
  transition: opacity 0.4s ease;
  z-index: 300; /* above the fisheye-raised tiles */
}

/* Expand-in-place overlay: the honeycomb blurs + darkens behind the photo
   (a Lightroom-style backdrop). */
/* The mesh starts invisible and fades in once its photos have loaded, so the
   first paint is a calm ground rather than a half-built wall (see wall.js). */
.wall-svg { opacity: 0; transition: opacity 0.7s ease, filter 0.28s ease; }
.wall-svg.ready { opacity: 1; }
.wall-viewport.expanded .wall-svg { filter: blur(11px) brightness(0.42); }
.wall-viewport.expanded::before,
.wall-viewport.expanded::after { opacity: 0; }
.expand-frame {
  /* Fixed (not absolute) so the overlay spans the whole window, including the
     sticky header's band. When the centred image is taller than the viewport it
     overflows upward into that band; if the frame stopped at the viewport top,
     the header (z-index 50) would sit over the close button and eat its clicks. */
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: clamp(1rem, 4vw, 3rem);
  z-index: 1000; /* above the sticky header (50) and fisheye tiles (~200) */
}
.wall-viewport.expanded .expand-frame { display: grid; }
/* Frame hugs the image exactly (sizes to it), so there are never side bands —
   the caption is overlaid on the photo's lower edge instead of sitting beside it. */
.expand-inner {
  position: relative;
  width: fit-content;
  max-width: 94vw;
  max-height: 92vh;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
  animation: pop 0.22s ease-out;
}
@keyframes pop { from { transform: scale(0.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.expand-inner img { display: block; width: auto; height: auto; max-width: 94vw; max-height: 84vh; }
.expand-meta {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 3rem 1.5rem 1.25rem;
  background: linear-gradient(to top, rgba(8, 12, 9, 0.9), rgba(8, 12, 9, 0.5) 55%, transparent);
  color: #fff;
}
.expand-meta h2 { margin: 0 0 0.2rem; font-size: 1.5rem; color: #fff; }
.expand-meta .sub { font-family: var(--sans); font-size: 0.82rem; color: rgba(255, 255, 255, 0.82); letter-spacing: 0.02em; }
.expand-meta p { margin: 0.5rem 0 0; color: rgba(255, 255, 255, 0.85); }
.expand-actions { margin-top: 0.85rem; display: flex; gap: 1rem; align-items: center; }
.expand-actions a {
  font-family: var(--sans); font-size: 0.82rem; letter-spacing: 0.03em;
  text-decoration: none; color: #fff; border-bottom: 1px solid rgba(255, 255, 255, 0.5);
}
.expand-actions a:hover { border-bottom-color: #fff; }
.expand-close {
  position: absolute; top: 10px; right: 10px;
  width: 36px; height: 36px; border-radius: 50%;
  border: none; cursor: pointer;
  background: var(--overlay); color: #fff;
  font-size: 1.1rem; line-height: 1;
}

@media (prefers-reduced-motion: reduce) {
  .tile { transition: none; }
  .expand-inner { animation: none; }
  .wall-svg { transition: none; } /* reveal instantly; no idle auto-pan either */
}

/* ── Article / page content ─────────────────────────────────────────────── */
.prose { padding: clamp(1.5rem, 5vw, 3rem) clamp(1rem, 4vw, 2.5rem); max-width: 70ch; margin: 0 auto; }
.prose h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); line-height: 1.1; margin: 0 0 0.4rem; }
.prose .meta { font-family: var(--sans); font-size: 0.85rem; color: var(--ink-soft); letter-spacing: 0.02em; margin-bottom: 1.5rem; }
.prose img { border-radius: 12px; box-shadow: var(--shadow); margin: 1.5rem 0; }
.prose a { color: var(--accent); }

.pill {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-family: var(--sans); font-size: 0.78rem; letter-spacing: 0.04em;
  padding: 0.2rem 0.6rem; border-radius: 999px;
  background: color-mix(in srgb, var(--cat, var(--accent)) 16%, transparent);
  color: var(--ink);
}
.pill .swatch { width: 8px; height: 8px; border-radius: 50%; background: var(--cat, var(--accent)); }

/* Photo detail hero */
.photo-hero { max-width: 1100px; margin: 0 auto; padding: clamp(1rem, 4vw, 2rem); }
/* Landscapes fill the width; portraits are capped by height and centred, so
   a tall shot never dominates the page. */
.photo-hero img { display: block; margin: 0 auto; width: auto; max-width: 100%; max-height: 82vh; object-fit: contain; border-radius: 14px; box-shadow: var(--shadow); }
.photo-body { max-width: 62ch; margin: 1.5rem auto 0; }
.photo-body h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); margin: 0 0 0.3rem; }
.photo-body .meta { font-family: var(--sans); font-size: 0.85rem; color: var(--ink-soft); margin-bottom: 1rem; display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; }
.back-link { display: inline-block; margin: 1.5rem auto 0; font-family: var(--sans); font-size: 0.85rem; color: var(--accent); text-decoration: none; }
.back-link:hover { text-decoration: underline; }

/* About */
.about-grid { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: clamp(1.5rem, 4vw, 3rem); align-items: start; }
.about-portrait img { border-radius: 14px; box-shadow: var(--shadow); width: 100%; }
.stats { list-style: none; padding: 0; margin: 1.25rem 0 0; display: grid; gap: 0.6rem; }
.stats li { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--line); padding-bottom: 0.4rem; font-family: var(--sans); font-size: 0.9rem; }
.stats .k { color: var(--ink-soft); }
.gear { list-style: none; padding: 0; margin: 0.75rem 0 0; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.gear li { font-family: var(--mono); font-size: 0.78rem; border: 1px solid var(--line-strong); border-radius: 6px; padding: 0.2rem 0.5rem; color: var(--ink-soft); }
@media (max-width: 700px) { .about-grid { grid-template-columns: 1fr; } }

/* ── Phones ─────────────────────────────────────────────────────────────────
   The long brand name wraps on a narrow screen; let the header grow to fit it
   (instead of the fixed 82px band, which pushed the subtitle down over the
   wall) and shrink the type. Keep the wall hint to a single line. */
@media (max-width: 560px) {
  .site-header {
    height: auto;
    min-height: var(--header-h);
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
    gap: 1rem;
  }
  .brand { gap: 3px; }
  .brand-name { font-size: 1.05rem; line-height: 1.15; }
  .brand-sub { font-size: 0.62rem; letter-spacing: 0.14em; }
  .site-nav { gap: 1rem; }
  .site-nav a { font-size: 0.72rem; letter-spacing: 0.1em; }

  .wall-hint {
    font-size: 0.6rem;
    letter-spacing: 0.07em;
    white-space: nowrap;
    padding: 0.35rem 0.7rem;
  }
}

.empty-note { padding: 3rem clamp(1rem, 4vw, 2.5rem); color: var(--ink-soft); font-family: var(--sans); }
