/* =============================================================
   LAYOUT.CSS
   Layout primitives that appear on every page:
   site nav, hero variants, body column, footer.
   Component-level styles (article rows, tags, filters) live
   in components.css.
   ============================================================= */


/* -------------------------------------------------------------
   1. CONTAINER UTILITIES
   .container — full-bleed-aware wrapper, max 1152px, centred.
   .column    — narrow centred prose column, max 640px.
   ------------------------------------------------------------- */

.container {
  width: 100%;
  max-width: var(--max-container);
  margin-inline: auto;
  padding-inline: var(--space-6);
}

.column {
  width: 100%;
  max-width: var(--max-prose);
  margin-inline: auto;
  padding: var(--space-7) var(--space-6) var(--space-8);
}

@media (max-width: 640px) {
  .container { padding-inline: var(--space-4); }
  .column    { padding: var(--space-6) var(--space-4) var(--space-7); }
}


/* -------------------------------------------------------------
   2. SITE NAV
   Sticky top bar. Brand on the left; links + theme toggle on
   the right. Collapses to a hamburger panel under 720px.
   ------------------------------------------------------------- */

.site-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: color-mix(in srgb, var(--bg) 92%, transparent);
  /* The subtle blur keeps text legible when scrolling over a hero. */
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border-default);
  transition: background-color var(--t-default),
              border-color var(--t-default);
}

.site-nav__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  height: var(--nav-h);
  max-width: var(--max-container);
  margin-inline: auto;
  padding-inline: var(--space-6);
}

@media (max-width: 640px) {
  .site-nav__inner { padding-inline: var(--space-4); }
}

.site-nav__brand {
  font-family: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  font-size: 1.125rem;        /* 18px — matches wireframe */
  letter-spacing: -0.02em;
  color: var(--text-primary);
  white-space: nowrap;
}

/* Right-hand cluster (links + theme toggle). On desktop these
   sit inline; on mobile they collapse into a drop-down panel. */
.site-nav__menu {
  display: flex;
  align-items: center;
  gap: var(--space-6);
}

.site-nav__links {
  display: flex;
  align-items: center;
  gap: var(--space-6);
}

.site-nav__link {
  font-size: var(--fs-small);
  color: var(--text-secondary);
  letter-spacing: 0.005em;
  transition: color var(--t-fast);
}

.site-nav__link:hover,
.site-nav__link[aria-current="page"] {
  color: var(--text-primary);
}


/* --- Theme toggle button (icon swap handled by CSS, not JS) --- */
.theme-toggle {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  transition: color var(--t-fast), background-color var(--t-fast);
}

.theme-toggle:hover {
  color: var(--text-primary);
  background-color: var(--surface-muted);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

/* Show sun on dark theme (click to go light), moon on light theme.
   Both icons exist in the DOM; this just hides the inactive one. */
.theme-toggle__icon--sun  { display: none; }
.theme-toggle__icon--moon { display: block; }

[data-theme="dark"] .theme-toggle__icon--sun  { display: block; }
[data-theme="dark"] .theme-toggle__icon--moon { display: none; }

/* Also handle the auto-dark case (no data-theme attribute yet,
   user's OS is dark) — same icon swap as explicit dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle__icon--sun  { display: block; }
  :root:not([data-theme="light"]) .theme-toggle__icon--moon { display: none; }
}


/* --- Hamburger toggle — hidden on desktop ---------------- */
.site-nav__toggle {
  display: none;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-direction: column;
  color: var(--text-primary);
}

.site-nav__toggle-line {
  display: block;
  width: 20px;
  height: 1.5px;
  background-color: currentColor;
  transition: transform var(--t-default), opacity var(--t-fast);
  transform-origin: center;
}

/* Animate the three lines into an X when open. */
.site-nav__toggle[aria-expanded="true"] .site-nav__toggle-line:nth-child(1) {
  transform: translateY(5.5px) rotate(45deg);
}
.site-nav__toggle[aria-expanded="true"] .site-nav__toggle-line:nth-child(2) {
  opacity: 0;
}
.site-nav__toggle[aria-expanded="true"] .site-nav__toggle-line:nth-child(3) {
  transform: translateY(-5.5px) rotate(-45deg);
}


/* --- Mobile breakpoint: collapse menu into drop-down panel --- */
@media (max-width: 720px) {
  .site-nav__toggle {
    display: flex;
  }

  .site-nav__menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: var(--space-2) var(--space-4) var(--space-4);
    background-color: var(--bg);
    border-bottom: 1px solid var(--border-default);

    /* Hidden by default; .site-nav--open reveals. */
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transition: max-height var(--t-default),
                opacity var(--t-fast),
                visibility 0s linear var(--t-default);
  }

  .site-nav--open .site-nav__menu {
    max-height: 320px;
    opacity: 1;
    visibility: visible;
    transition: max-height var(--t-default),
                opacity var(--t-default),
                visibility 0s;
  }

  .site-nav__links {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    width: 100%;
  }

  .site-nav__link {
    display: block;
    padding: var(--space-3) 0;
    font-size: var(--fs-body);
    border-bottom: 1px solid var(--border-subtle);
  }

  .site-nav__menu .theme-toggle {
    align-self: flex-start;
    margin-top: var(--space-3);
    margin-left: -8px;   /* visually align icon with text above */
  }
}


/* -------------------------------------------------------------
   3. HERO
   Two variants:
     .hero--featured  — home page, taller, has eyebrow/title/sub
     .hero--page      — about / articles, shorter, heading only
   ------------------------------------------------------------- */

.hero {
  position: relative;
  width: 100%;
  overflow: hidden;
  background-color: var(--surface-muted);   /* fallback while image loads */
  isolation: isolate;                       /* contains the ::after overlay */
}

.hero--featured { height: var(--hero-feat-h); }
.hero--page     { height: var(--hero-page-h); }

/* The image fills the hero. Use <img> (not a CSS bg) so it loads
   eagerly with proper alt text, contributes to LCP, and is SEO-
   visible. Featured hero image should have fetchpriority="high". */
.hero__image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: -2;
}

/* Dark gradient overlay so light text stays readable on any image. */
.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--hero-overlay);
  z-index: -1;
  pointer-events: none;
}

/* The content slot — anchored bottom-left, padded, animated in. */
.hero__content {
  position: absolute;
  inset: auto 0 0 0;
  max-width: var(--max-container);
  margin-inline: auto;
  padding: var(--space-6);
  /* Subtle rise on first paint. Skipped if prefers-reduced-motion. */
  animation: hero-rise 540ms cubic-bezier(0.2, 0.7, 0.2, 1) 80ms backwards;
}

@media (max-width: 640px) {
  .hero__content { padding: var(--space-5) var(--space-4); }
}

@keyframes hero-rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* --- Hero text elements ---------------------------------- */

.hero__eyebrow {
  display: inline-block;
  font-size: var(--fs-eyebrow);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-on-hero-eyebrow);
  margin-bottom: var(--space-3);
}

.hero__title {
  font-family: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  font-size: var(--fs-display);
  font-weight: 400;
  color: var(--text-on-hero);
  line-height: 1.1;
  letter-spacing: -0.02em;
  max-width: 36rem;
  margin: 0 0 var(--space-3);
}

.hero__subtitle {
  font-size: var(--fs-body);
  color: var(--text-on-hero-muted);
  line-height: 1.55;
  max-width: 32rem;
  margin: 0;
}

/* Page hero heading — used on about + articles pages. */
.hero__heading {
  font-family: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  font-size: var(--fs-h1);
  font-weight: 400;
  color: var(--text-on-hero);
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 0;
}

/* Article hero: image flows in the document so the full image is
   visible at its natural aspect ratio. The z-index stack is rebuilt
   so the gradient overlay and text still sit above the image. */
.hero--article {
  height: auto;
}

.hero--article .hero__image {
  position: relative;
  inset: unset;
  width: 100%;
  height: auto;
  z-index: 1;
}

.hero--article::after {
  z-index: 2;
}

.hero--article .hero__content {
  z-index: 3;
}


/* When the entire featured hero is a link to its article. */
.hero-link {
  display: block;
  color: inherit;
  text-decoration: none;
  transition: transform var(--t-slow);
}

.hero-link:hover .hero__image {
  /* Subtle slow zoom on hover — keeps the editorial feel
     while signalling interactivity. */
  transform: scale(1.015);
  transition: transform 1200ms ease;
}

.hero-link .hero__image {
  transition: transform 600ms ease;
}


/* -------------------------------------------------------------
   4. SITE FOOTER
   Minimal: name + year + small links row. Lives below the main
   content on every page.
   ------------------------------------------------------------- */

.site-footer {
  border-top: 1px solid var(--border-default);
  margin-top: var(--space-8);
  padding: var(--space-6) 0;
  font-size: var(--fs-small);
  color: var(--text-tertiary);
}

.site-footer__inner {
  max-width: var(--max-container);
  margin-inline: auto;
  padding-inline: var(--space-6);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
}

@media (max-width: 640px) {
  .site-footer__inner { padding-inline: var(--space-4); }
}

.site-footer__links {
  display: flex;
  gap: var(--space-5);
}

.site-footer__link {
  color: var(--text-tertiary);
  transition: color var(--t-fast);
}

.site-footer__link:hover {
  color: var(--text-primary);
}


/* -------------------------------------------------------------
   5. PAGE WRAPPER
   Wraps everything between <header> and <footer>, used to push
   the footer to the bottom on short pages (sticky footer).
   ------------------------------------------------------------- */

html, body { height: 100%; }

body {
  display: flex;
  flex-direction: column;
}

.site-main {
  flex: 1 0 auto;
}

.site-footer {
  flex-shrink: 0;
}
