/* ===== Reset & Variables ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #f4efe6;
  --text: #252019;
  --text-muted: #7a7265;
  --accent: #2a7d8e;
  --accent-hover: #1a5a68;
  --border: #d4cec4;
  --display: "Cormorant", serif;
  --body: "Literata", serif;
  --ui: "Karla", sans-serif;
  --col: 660px;
}

/* ===== Base ===== */
html {
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
  overflow-x: clip;
}

body {
  font-family: var(--body);
  color: var(--text);
  background: var(--bg);
  line-height: 1.78;
  min-height: 100vh;
  overflow-x: clip;
}

/* Paper grain texture */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.028;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

::selection {
  background: rgba(42, 125, 142, 0.18);
}

::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.25s ease;
}

a:hover {
  color: var(--accent-hover);
}

/* ===== Grid Layout =====
   main uses a 3-column grid: flex gutters + content column.
   Children snap to the content column by default; .full-bleed and .hero
   span all three columns. This prevents horizontal document overflow. */
main {
  display: grid;
  grid-template-columns:
    [full-start] 1fr
    [content-start] min(var(--col), 100% - 3rem) [content-end]
    1fr [full-end];
  row-gap: 0;
}

main > * {
  grid-column: content;
  min-width: 0;
}

main > .hero,
main > .full-bleed {
  grid-column: full;
  width: 100%;
}

/* ===== Navigation ===== */
.site-nav {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 2rem 2.5rem;
  max-width: 1200px;
  margin: 0 auto;
  animation: fadeDown 0.5s ease 0.2s both;
}

.nav-name {
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.35rem;
  color: var(--text);
  letter-spacing: 0.01em;
  transition: color 0.25s;
}

.nav-name:hover {
  color: var(--accent);
}

.nav-links {
  display: flex;
  gap: 2rem;
}

.nav-links a {
  font-family: var(--ui);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: lowercase;
  position: relative;
}

.nav-links a::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 1px;
  background: var(--accent);
  transition: width 0.3s ease;
}

.nav-links a:hover::after,
.nav-links a.active::after {
  width: 100%;
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--text);
}

/* Pages with a hero photo at the top: nav overlays the hero with light text */
.is-home .site-nav,
.is-post .site-nav {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
}

.is-home .nav-name,
.is-post .nav-name {
  color: rgba(255, 255, 255, 0.92);
}

.is-home .nav-name:hover,
.is-post .nav-name:hover {
  color: #fff;
}

.is-home .nav-links a,
.is-post .nav-links a {
  color: rgba(255, 255, 255, 0.7);
}

.is-home .nav-links a:hover,
.is-home .nav-links a.active,
.is-post .nav-links a:hover,
.is-post .nav-links a.active {
  color: rgba(255, 255, 255, 0.95);
}

.is-home .nav-links a::after,
.is-post .nav-links a::after {
  background: rgba(255, 255, 255, 0.8);
}

/* ===== Hero ===== */
.hero {
  position: relative;
  width: 100%;
  height: 72vh;
  min-height: 420px;
  max-height: 720px;
  overflow: hidden;
  margin-bottom: 3.5rem;
}

.hero-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 55%;
  animation: heroZoom 1.4s ease-out both;
}

.hero-gradient {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(
      to bottom,
      rgba(20, 18, 15, 0.38) 0%,
      rgba(20, 18, 15, 0.1) 30%,
      transparent 55%,
      rgba(20, 18, 15, 0.04) 80%,
      rgba(244, 239, 230, 0.85) 100%
    ),
    radial-gradient(
      ellipse at center,
      transparent 50%,
      rgba(20, 18, 15, 0.12) 100%
    );
  pointer-events: none;
}

/* ===== Bio ===== */
.bio {
  margin-bottom: 3.5rem;
  animation: fadeUp 0.6s ease 0.3s both;
}

.bio p {
  font-size: 1.05rem;
  line-height: 1.85;
}

.bio a {
  background-image: linear-gradient(var(--accent), var(--accent));
  background-position: 0% 100%;
  background-repeat: no-repeat;
  background-size: 0% 1px;
  transition: background-size 0.3s ease, color 0.25s ease;
  padding-bottom: 1px;
}

.bio a:hover {
  background-size: 100% 1px;
  color: var(--accent-hover);
}

/* ===== Section Label ===== */
.section-label {
  font-family: var(--ui);
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.section-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ===== Writing List ===== */
.writing-list {
  list-style: none;
  margin-bottom: 4rem;
}

.writing-item {
  padding: 1.1rem 0 1.1rem 1.25rem;
  border-left: 2px solid transparent;
  transition: border-color 0.25s ease, background 0.25s ease;
  margin-bottom: 0.25rem;
}

.writing-item:hover {
  border-left-color: var(--accent);
  background: rgba(42, 125, 142, 0.03);
}

.writing-item-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 1rem;
  align-items: baseline;
}

.writing-item-title {
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--text);
  transition: color 0.25s;
  line-height: 1.3;
  min-width: 0;
}

.writing-item:hover .writing-item-title {
  color: var(--accent);
}

.writing-item-meta {
  font-family: var(--ui);
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.writing-item-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
  line-height: 1.6;
}

/* ===== Full Bleed Photo ===== */
.full-bleed {
  overflow: hidden;
}

.photo-break {
  height: 300px;
  margin: 3.5rem 0;
}

.photo-break img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 65%;
  filter: saturate(0.92);
}

/* ===== Post Page =====
   .post-hero rides on top of .hero (same height, gradient, nav overlay).
   It just nudges the focal point — most post heroes are mountain/sky
   compositions with a horizon below center. */
.post-hero {
  height: 60vh;
  min-height: 360px;
  max-height: 620px;
}

.post-hero .hero-img {
  object-position: center 50%;
}

.post-header {
  margin-bottom: 2.5rem;
  animation: fadeUp 0.5s ease 0.2s both;
}

.post-title {
  font-family: var(--body);
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin-bottom: 0.6rem;
}

.post-date {
  font-family: var(--ui);
  font-size: 0.78rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.post-body {
  margin-bottom: 5rem;
  animation: fadeUp 0.5s ease 0.35s both;
}

.post-body p {
  margin-bottom: 1.5rem;
  font-size: 1rem;
}

.post-body h2 {
  font-family: var(--body);
  font-size: 1.6rem;
  font-weight: 700;
  margin-top: 3rem;
  margin-bottom: 0.75rem;
}

.post-body h3 {
  font-family: var(--body);
  font-size: 1.3rem;
  font-weight: 700;
  margin-top: 2.25rem;
  margin-bottom: 0.5rem;
}

.post-body blockquote {
  border-left: 2px solid var(--accent);
  padding-left: 1.5rem;
  margin: 2rem 0;
  color: var(--text-muted);
  font-style: italic;
}

.post-body a {
  background-image: linear-gradient(var(--border), var(--border));
  background-position: 0% 100%;
  background-repeat: no-repeat;
  background-size: 100% 1px;
  padding-bottom: 1px;
  transition: background-image 0.3s ease, color 0.25s;
}

.post-body a:hover {
  background-image: linear-gradient(var(--accent), var(--accent));
  color: var(--accent-hover);
}

.post-body img {
  max-width: 100%;
  border-radius: 2px;
  margin: 2rem 0;
}

.post-body code {
  background: rgba(42, 125, 142, 0.08);
  padding: 0.05em 0.35em;
  border-radius: 3px;
  font-size: 0.88em;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

.post-body pre {
  background: #2a2620;
  color: #e8e1d0;
  padding: 1.1rem 1.3rem;
  border-radius: 4px;
  overflow-x: auto;
  margin: 1.6rem 0;
  font-size: 0.82rem;
  line-height: 1.6;
}

.post-body pre code {
  background: transparent;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.post-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.8rem 0;
  font-family: var(--ui);
  font-size: 0.86rem;
}

.post-body table th,
.post-body table td {
  text-align: left;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.post-body table th {
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.72rem;
  border-bottom-width: 1.5px;
}

.post-body table tr:hover td {
  background: rgba(42, 125, 142, 0.025);
}

/* Wide figures (diagrams, large tables) break out of the 660px content
   column without breaking document width — relies on body { overflow-x: hidden; }.
   100% resolves to .post-body's width, so margin-inline becomes negative
   when the figure is wider, pulling it symmetrically into the gutters. */
.post-body figure {
  width: min(1100px, 100vw - 2rem);
  margin-inline: calc((100% - min(1100px, 100vw - 2rem)) / 2);
  margin-block: 2.75rem;
}

.post-body figure iframe {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fafaf6;
  display: block;
}

.post-body figure.pdf-embed iframe {
  height: 90vh;
  background: #fff;
}

.post-body figure figcaption {
  font-family: var(--ui);
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 0.65rem;
  text-align: center;
  letter-spacing: 0.02em;
  line-height: 1.5;
}

.katex-display {
  margin: 1.6rem 0 !important;
  overflow-x: auto;
  overflow-y: hidden;
}

/* ===== About Page ===== */
.about-title {
  font-family: var(--display);
  font-size: 2.4rem;
  font-weight: 600;
  margin-top: 1rem;
  margin-bottom: 2rem;
  letter-spacing: -0.01em;
}

.about-para {
  margin-bottom: 1.4rem;
  font-size: 1rem;
}

.about-para a,
.about-contact a {
  background-image: linear-gradient(var(--accent), var(--accent));
  background-position: 0% 100%;
  background-repeat: no-repeat;
  background-size: 0% 1px;
  padding-bottom: 1px;
  transition: background-size 0.3s ease, color 0.25s;
}

.about-para a:hover,
.about-contact a:hover {
  background-size: 100% 1px;
  color: var(--accent-hover);
}

.about-photos {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  grid-template-rows: 200px 200px;
  gap: 0.6rem;
  margin: 2.5rem 0 3rem;
}

.about-photos img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 2px;
}

.about-photos img:nth-child(1) {
  grid-row: 1 / 3;
}

.about-contact {
  margin-bottom: 4rem;
  font-size: 1rem;
}

/* ===== Footer ===== */
.site-footer {
  margin-top: auto;
}

.footer-strip {
  position: relative;
  height: 280px;
  overflow: hidden;
}

.footer-strip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 55%;
}

.footer-gradient {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    var(--bg) 0%,
    rgba(244, 239, 230, 0.55) 18%,
    transparent 50%
  );
  pointer-events: none;
}

/* ===== Animations ===== */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes heroZoom {
  from {
    opacity: 0;
    transform: scale(1.04);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Scroll reveal — only hides elements when JS is confirmed running,
   so no-JS users still see content. */
.js-ready .reveal {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.55s ease, transform 0.55s ease;
}

.js-ready .reveal.revealed {
  opacity: 1;
  transform: translateY(0);
}

.writing-list .reveal:nth-child(1) { transition-delay: 0s; }
.writing-list .reveal:nth-child(2) { transition-delay: 0.07s; }
.writing-list .reveal:nth-child(3) { transition-delay: 0.14s; }
.writing-list .reveal:nth-child(4) { transition-delay: 0.21s; }
.writing-list .reveal:nth-child(5) { transition-delay: 0.28s; }

/* ===== Responsive ===== */
@media (max-width: 720px) {
  html {
    font-size: 16px;
  }

  .site-nav {
    padding: 1.5rem 1.25rem;
  }

  main {
    grid-template-columns:
      [full-start] 1fr
      [content-start] min(var(--col), 100% - 2rem) [content-end]
      1fr [full-end];
  }

  .hero {
    height: 55vh;
    min-height: 300px;
  }

  .post-title,
  .about-title {
    font-size: 1.9rem;
  }

  .writing-item-header {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }

  .writing-item-title {
    font-size: 1.2rem;
  }

  .about-photos {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

  .about-photos img {
    height: 200px;
  }

  .about-photos img:nth-child(1) {
    grid-row: auto;
  }

  .post-hero {
    height: 260px;
  }

  .footer-strip {
    height: 200px;
  }
}
