/* ========== Theme tokens ========== */
:root {
  --bg: #2B2623;
  --text: #EDE9E3;
  --mute: #C9C3B8;
  --accent: #B6B1A8;

  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font-serif: Georgia, "Times New Roman", Times, serif;

  --h1-size: clamp(28px, 7vw, 72px);
  --h2-size: clamp(18px, 3.2vw, 28px);
  --body-size: clamp(17px, 1.6vw, 18px);
  --caption-size: clamp(12px, 1.2vw, 13px);

  --grid-gap: 16px;
  --row: 8px; /* base for masonry row height */

  --nav-w: 220px;
  --nav-pad: 22px;

  --link-underline-h: 0.1em;
  --title-follow-max: 18px; /* max offset for title follow */
}

.theme-light {
  --bg: #F5F1EB;
  --text: #201F1D;
  --mute: #8A847A;
  --accent: #8A847A;
}

/* Global reset-ish */
*,
*::before,
*::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: var(--font-serif);
  font-size: var(--body-size);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Focus styles for accessibility */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ========== Fixed vertical nav ========== */
.site-nav {
  position: fixed;
  z-index: 20;
  left: 0;
  top: 0;
  width: var(--nav-w);
  padding: calc(var(--nav-pad) + 4px) var(--nav-pad);
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none; /* allow hover through except active children */
}

.site-nav a, .site-nav button { pointer-events: auto; }

.site-title {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: var(--h1-size);
  line-height: 1;
  margin: 0 0 10px 0;
  transform: translate3d(0,0,0);
  will-change: transform;
}

.site-title a {
  text-decoration: none;
  color: var(--text);
}

.nav-links {
  list-style: none;
  margin: 0 0 12px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-links a {
  font-family: var(--font-mono);
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  letter-spacing: 0.02em;
}

/* Theme toggle glyph */
.theme-toggle {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--mute);
  background: transparent;
  color: var(--text);
  border-radius: 50%;
  cursor: pointer;
  transition: transform .15s ease;
}
.theme-toggle:hover { transform: translateY(-1px); }
.theme-toggle .glyph { font-size: 20px; line-height: 1; }

/* ========== Link highlighter animation ========== */
.link-highlight {
  position: relative;
  color: var(--text);
  text-decoration: none;
  transition: color .2s ease;
}
.link-highlight::before {
  content: "";
  position: absolute;
  inset: calc(100% - var(--link-underline-h)) 0 0 0;
  background: currentColor;
  transform: scaleY(1);
  transform-origin: bottom;
  transition: transform .25s cubic-bezier(.2,.7,.2,1);
}
.link-highlight:hover,
.link-highlight:focus-visible {
  color: var(--bg); /* invert text to page bg */
}
.link-highlight:hover::before,
.link-highlight:focus-visible::before {
  transform: scaleY(8); /* expand to highlight marker */
}

/* ========== Feed layout ========== */
.feed-wrap {
  position: relative;
  padding-left: calc(var(--nav-w) + 24px); /* keep grid clear of fixed nav */
  padding-right: 24px;
  padding-top: 24px;
}

/* Progressive fallback: no-overlap grid when JS fails.
   We switch to masonry (tiny rows + spans) only after JS runs. */
.feed {
  display: grid;
  grid-auto-flow: row dense; /* *row* ensures no weird absolute-like overlap */
  gap: var(--grid-gap);
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: auto; /* SAFE fallback — tall rows, never overlap */
}

/* A class JS adds once spans are computed */
.feed.masonry {
  grid-auto-rows: var(--row);
}

@media (max-width: 640px) {
  .feed-wrap { padding-left: 16px; padding-right: 16px; }
  .feed { grid-template-columns: 1fr; }
}
@media (min-width: 641px) and (max-width: 1024px) {
  .feed { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1025px) {
  .feed { grid-template-columns: repeat(4, 1fr); }
}

/* Cards */
.card {
  display: block; /* anchor wraps the whole card */
  color: inherit;
  text-decoration: none;
  border: 1px solid color-mix(in oklab, var(--mute), transparent 60%);
  background: color-mix(in oklab, var(--bg), var(--text) 1%);
  padding: 10px;
  transition: transform .18s ease;
  will-change: transform;
}
.card:hover { transform: translateY(-2px); }

.card article { display: block; }

.card h2 {
  font-family: var(--font-mono);
  font-size: var(--h2-size);
  margin: 8px 2px 2px;
  line-height: 1.2;
}

/* Images and captions */
.card figure { margin: 0; }
.card img {
  width: 100%;
  height: auto;
  display: block;
  transition: filter .25s ease;
}
.card:hover img { filter: invert(1); }
.card figure figcaption,
.caption {
  display: block;
  font-family: var(--font-mono);
  color: var(--mute);
  font-size: var(--caption-size);
  letter-spacing: 0.02em;
  margin-top: 6px;
}

/* Image-set grid */
.card-imageset .thumbs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.card-imageset .thumbs img {
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

/* Width utility classes (column spans) */
.w-narrow { grid-column: span 1; }
.w-medium { grid-column: span 2; }
.w-wide   { grid-column: span 3; }

/* Adjust spans for smaller breakpoints */
@media (max-width: 640px) {
  .w-narrow, .w-medium, .w-wide { grid-column: span 1; }
}
@media (min-width: 641px) and (max-width: 1024px) {
  .w-wide { grid-column: span 2; }
}

/* Footer */
.site-footer {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 40px 24px 60px;
  margin-left: calc(var(--nav-w) + 0px);
  border-top: 1px solid color-mix(in oklab, var(--mute), transparent 60%);
}
.site-footer a {
  color: var(--text);
  text-decoration: none;
}
.foot-right a + span { margin: 0 10px; }

/* Cursor FX canvas (only over feed area) */
.feed-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

/* Reduced motion: disable fancy bits */
@media (prefers-reduced-motion: reduce) {
  .theme-toggle { transition: none; }
  .card { transition: none; }
  .card img { transition: none; }
  .link-highlight::before { transition: none; }
}

/* Helpful little touches */
.mono { font-family: var(--font-mono); }