:root {
  /* Typography */
  --font-display: "neue-haas-grotesk-display", sans-serif;
  --font-body: "neue-haas-grotesk-text", sans-serif;
  --font-mono: ui-monospace, "SF Mono", monospace;

  /* Type Scale */
  --text-xs:    0.75rem;
  --text-sm:    0.875rem;
  --text-base:  1.0625rem;
  --text-lg:    1.25rem;
  --text-xl:    1.5rem;
  --text-2xl:   2rem;
  --text-3xl:   3rem;
  --text-4xl:   4rem;
  --text-5xl:   6rem;
  --text-6xl:   8rem;
  --text-hero:  clamp(3rem, 10vw, 6rem);

  /* Font Weights */
  --font-light:     300;
  --font-normal:    400;
  --font-medium:    500;
  --font-semibold:  600;
  --font-bold:      700;

  /* Line Heights */
  --leading-none:    1;
  --leading-tight:   1.1;
  --leading-snug:    1.3;
  --leading-normal:  1.6;

  /* Colors - Semantic (light theme defaults) */
  --color-bg:        #ffffff;
  --color-text:      #111111;
  --color-heading:   #111111;
  --color-muted:     #666666;
  --color-faint:     #999999;
  --color-border:    #e0e0e0;
  --color-accent:    #111111;
  --color-code-bg:   #f5f5f5;

  /* Spacing */
  --space-1:   0.25rem;
  --space-2:   0.5rem;
  --space-3:   0.75rem;
  --space-4:   1rem;
  --space-6:   1.5rem;
  --space-8:   2rem;
  --space-12:  3rem;
  --space-16:  4rem;
  --space-24:  6rem;
  --space-32:  8rem;

  /* Layout */
  --width-prose:   65ch;
  --width-content: 48rem;
  --width-wide:    72rem;
  --max-width:     90rem;
  --gutter:        clamp(1.5rem, 4vw, 4rem);
  --content-indent: 7.5rem;
  --header-offset: 10rem;

  /* Radii */
  --radius-sm: 3px;
  --radius-md: 4px;
}

/* ==========================================================================
   Dark Theme - Override semantic variables
   ========================================================================== */

.theme-dark {
  --color-bg:        #111111;
  --color-text:      #b0b0b0;
  --color-heading:   #e0e0e0;
  --color-muted:     #888888;
  --color-faint:     #666666;
  --color-border:    #333333;
  --color-accent:    #444444;
  --color-code-bg:   #222222;
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-size: 100%;
  -webkit-font-smoothing: antialiased;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--font-normal);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background: var(--color-bg);
  overflow-x: hidden;
}

::selection {
  background: var(--color-text);
  color: var(--color-bg);
}

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

/* ==========================================================================
   Typography
   ========================================================================== */

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: var(--font-bold);
  line-height: var(--leading-tight);
  color: var(--color-heading);
  margin: 0;
}

h1 {
  font-size: var(--text-hero);
  font-weight: var(--font-bold);
  line-height: var(--leading-none);
}

h2 {
  font-size: var(--text-3xl);
  margin-top: var(--space-16);
  margin-bottom: var(--space-6);
}

h3 {
  font-size: var(--text-xl);
  margin-top: var(--space-12);
  margin-bottom: var(--space-4);
}

h4 {
  font-size: var(--text-lg);
  margin-top: var(--space-12);
  margin-bottom: var(--space-4);
}

p {
  margin: 0 0 var(--space-6) 0;
}

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: opacity 0.2s;
}

a:hover {
  opacity: 0.6;
}

blockquote {
  margin: var(--space-12) 0;
  padding-left: var(--space-6);
  border-left: 2px solid var(--color-text);
  font-style: italic;
  font-size: var(--text-lg);
}

blockquote p:last-child {
  margin-bottom: 0;
}

code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--color-code-bg);
  padding: 0.2em 0.4em;
  border-radius: var(--radius-sm);
}

pre {
  background: var(--color-text);
  color: var(--color-bg);
  padding: var(--space-6);
  overflow-x: auto;
  border-radius: var(--radius-md);
  margin: var(--space-8) 0;
}

pre code {
  background: none;
  padding: 0;
}

hr {
  border: none;
  height: 1px;
  background: var(--color-border);
  margin: var(--space-16) 0;
}

.theme-dark hr {
  background: var(--color-text);
}

/* ==========================================================================
   Header - Swiss Grid Style
   ========================================================================== */

.site-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: transparent;
  border-bottom: 1px solid var(--color-text);
}

.theme-dark .site-header {
  background: var(--color-bg);
  border-bottom-color: var(--color-border);
}

/* Light nav scheme (for dark backgrounds like hero) */
[data-nav-color="light"] .site-header {
  border-bottom-color: var(--color-bg);
}

[data-nav-color="light"] .site-logo {
  color: var(--color-bg);
  border-right-color: var(--color-bg);
}

[data-nav-color="light"] .nav-grid li {
  border-left-color: var(--color-bg);
}

[data-nav-color="light"] .nav-grid a {
  color: var(--color-bg);
}

.header-inner {
  display: grid;
  grid-template-columns: auto 1fr;
}

.site-logo {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: var(--font-bold);
  line-height: 1;
  text-decoration: none;
  color: var(--color-heading);
  background-color: transparent;
  padding: var(--space-3) var(--space-4);
  border-right: 1px solid var(--color-text);
}

.theme-dark .site-logo {
  border-right-color: var(--color-accent);
}

.site-logo:hover {
  opacity: 0.6;
}

.main-nav {
  display: flex;
  align-items: stretch;
  margin-left: auto;
}

.nav-grid {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-grid li {
  display: flex;
  border-left: 1px solid var(--color-text);
}

.theme-dark .nav-grid li {
  border-left-color: var(--color-border);
}

.nav-grid a {
  display: flex;
  align-items: center;
  width: 100%;
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-decoration: none;
  color: var(--color-text);
  background: transparent;
  transition: opacity 0.15s ease;
}

.nav-grid a:hover {
  opacity: 0.6;
}

.theme-dark .nav-grid a:hover {
  opacity: 1;
  color: var(--color-heading);
}

/* Header - Mobile */
@media (max-width: 768px) {
  .header-inner {
    grid-template-columns: 1fr;
  }

  .site-logo {
    font-size: var(--text-sm);
    padding: var(--space-3) var(--gutter);
    border-right: none;
    border-bottom: 1px solid var(--color-text);
  }

  .theme-dark .site-logo {
    border-bottom-color: var(--color-border);
  }

  .main-nav {
    margin-left: 0;
  }

  .nav-grid {
    flex-wrap: wrap;
    width: 100%;
  }

  .nav-grid li {
    flex: 1 1 50%;
    border-left: none;
    border-bottom: 1px solid var(--color-text);
  }

  .theme-dark .nav-grid li {
    border-bottom-color: var(--color-border);
  }

  .nav-grid li:nth-child(odd) {
    border-right: 1px solid var(--color-text);
  }

  .theme-dark .nav-grid li:nth-child(odd) {
    border-right-color: var(--color-border);
  }

  .nav-grid li:nth-last-child(-n+2) {
    border-bottom: none;
  }

  .nav-grid a {
    padding: var(--space-3) var(--gutter);
    font-size: var(--text-sm);
  }

  /* Light nav scheme for mobile */
  [data-nav-color="light"] .site-logo {
    border-bottom-color: var(--color-bg);
  }

  [data-nav-color="light"] .nav-grid li {
    border-bottom-color: var(--color-bg);
  }

  [data-nav-color="light"] .nav-grid li:nth-child(odd) {
    border-right-color: var(--color-bg);
  }
}

/* ==========================================================================
   Main Content
   ========================================================================== */

main {
  min-height: 100vh;
}

/* ==========================================================================
   Homepage - Photo Hero
   ========================================================================== */

.home-hero {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: flex-end;
  padding: var(--space-12) var(--content-indent);
  margin-bottom: var(--space-24);
  overflow: hidden;
}

.home-hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: var(--hero-image, url('/images/hero-bg-5.jpg'));
  background-size: cover;
  background-position: center;
  filter: grayscale(100%);
  z-index: -2;
}

.home-hero::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0.2) 50%, rgba(0,0,0,0) 100%);
  z-index: -1;
}

.home-hero-text {
  font-family: var(--font-display);
  font-size: var(--text-hero);
  font-weight: var(--font-light);
  line-height: var(--leading-none);
  max-width: 16ch;
  color: var(--color-bg);
}

/* Latest Posts */
.home-posts {
  padding: 0 var(--content-indent);
}

.home-posts-header {
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--color-muted);
  margin-bottom: var(--space-12);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.home-posts-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-16) var(--space-8);
}

.home-post-item {
  display: flex;
  flex-direction: column;
}

.home-post-title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  line-height: var(--leading-tight);
  margin: 0 0 var(--space-2) 0;
}

.home-post-title a {
  text-decoration: none;
}

.home-post-title a:hover {
  opacity: 0.6;
}

.home-post-date {
  font-size: var(--text-sm);
  color: var(--color-faint);
}

/* Homepage - Categories */
.home-categories {
  padding: 0 var(--content-indent);
  margin-top: var(--space-24);
}

.category-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-4) var(--space-8);
}

.category-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-border);
}

.category-item a {
  font-size: var(--text-lg);
  font-weight: var(--font-medium);
  text-decoration: none;
  text-transform: capitalize;
}

.category-item a:hover {
  opacity: 0.6;
}

.category-count {
  font-size: var(--text-sm);
  color: var(--color-faint);
}

@media (max-width: 768px) {
  .category-list {
    grid-template-columns: 1fr;
  }
}

/* ==========================================================================
   Single Post
   ========================================================================== */

.post-header {
  padding: var(--space-16) var(--content-indent) var(--space-8);
}

.post-title {
  font-size: var(--text-5xl);
  max-width: none;
  margin-bottom: var(--space-1);
}

.post-date {
  display: block;
  font-size: var(--text-sm);
  color: var(--color-faint);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.post-content {
  padding: 0 var(--content-indent);
}

/* Prose Width for Text */
.post-content > p,
.post-content > blockquote,
.post-content > ul,
.post-content > ol,
.post-content > h2,
.post-content > h3,
.post-content > pre {
  max-width: var(--width-prose);
}

/* YouTube Embeds - Prose Width */
.post-content iframe {
  max-width: var(--width-prose);
  width: 100%;
  aspect-ratio: 16 / 9;
  height: auto;
  margin: var(--space-8) 0;
}

/* Video Embeds - Prose Width */
.video-figure {
  max-width: var(--width-prose);
  margin: var(--space-8) 0;
}

.video-figure video {
  width: 100%;
  height: auto;
}

.video-figure figcaption {
  font-size: var(--text-sm);
  color: var(--color-muted);
  margin-top: var(--space-3);
}

/* Images - Break Out, Full Width */
.post-content img {
  width: 100%;
  max-width: none;
  margin: var(--space-16) 0;
}

.post-content figure {
  margin: var(--space-16) 0;
}

.post-content figure img {
  margin: 0;
}

.post-content figcaption {
  font-size: var(--text-sm);
  color: var(--color-muted);
  margin-top: var(--space-4);
  max-width: var(--width-prose);
}

/* Image Layouts */
.image-figure {
  margin: var(--space-12) 0;
}

.image-figure img {
  display: block;
  width: 100%;
  height: auto;
  margin: 0;
}

.image-figure figcaption {
  font-size: var(--text-sm);
  color: var(--color-muted);
  margin-top: var(--space-3);
}

/* Prose width (default) - 65ch */
.image-prose {
  max-width: var(--width-prose);
}

/* Half width - 50% of content area */
.image-half {
  width: 50%;
}

/* Wide - 75% of content area */
.image-wide {
  width: 75%;
}

/* Full width - 100% of content area */
.image-full {
  width: 100%;
}

/* ==========================================================================
   List Pages - Year Grouped
   ========================================================================== */

.list-header {
  padding: var(--space-16) var(--content-indent) 0 var(--content-indent);
  margin: 0 0 var(--space-12) 0;
}

.list-title {
  font-size: var(--text-4xl);
  font-weight: var(--font-bold);
}

.list-content {
  margin-top: var(--space-4);
  color: var(--color-muted);
  max-width: var(--width-prose);
}

.list-by-year {
  padding: 0 var(--content-indent);
}

.year-group {
  margin-bottom: var(--space-16);
}

.year-heading {
  font-size: var(--text-3xl);
  font-weight: var(--font-bold);
  margin: 0 0 var(--space-6) 0;
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-text);
}

.year-posts {
  list-style: none;
  margin: 0;
  padding: 0;
}

.year-post-item {
  border-bottom: 1px solid var(--color-border);
}

.year-post-item:last-child {
  border-bottom: none;
}

.year-post-link {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: var(--space-4) 0;
  text-decoration: none;
  transition: opacity 0.15s ease;
}

.year-post-link:hover {
  opacity: 0.6;
}

.year-post-title {
  font-size: var(--text-lg);
  font-weight: var(--font-medium);
}

.year-post-date {
  font-size: var(--text-sm);
  color: var(--color-faint);
  flex-shrink: 0;
  margin-left: var(--space-4);
}

@media (max-width: 768px) {
  .list-header {
    padding-top: var(--header-offset);
    padding-left: var(--gutter);
    padding-right: var(--gutter);
  }

  .list-by-year {
    padding: 0 var(--gutter);
  }

  .list-title {
    font-size: var(--text-3xl);
  }

  .year-heading {
    font-size: var(--text-2xl);
  }

  .year-post-title {
    font-size: var(--text-base);
  }
}

/* ==========================================================================
   Footer
   ========================================================================== */

.site-footer {
  margin-top: var(--space-32);
  background: var(--color-bg);
  border-top: 1px solid var(--color-text);
}

.theme-dark .site-footer {
  border-top-color: var(--color-border);
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
}

.footer-copyright {
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  color: var(--color-text);
}

.footer-rss {
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  text-decoration: none;
  color: var(--color-text);
  padding: var(--space-2) var(--space-4);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.footer-rss:hover {
  background-color: var(--color-text);
  color: var(--color-bg);
  opacity: 1;
}

/* ==========================================================================
   Responsive - Global
   ========================================================================== */

@media (max-width: 768px) {
  :root {
    --text-hero: clamp(2.5rem, 12vw, 4rem);
  }

  .home-hero {
    padding: var(--space-12) var(--gutter);
  }

  .home-posts {
    padding: 0 var(--gutter);
  }

  .home-categories {
    padding: 0 var(--gutter);
  }

  .home-posts-list {
    grid-template-columns: 1fr;
    gap: var(--space-12);
  }

  .post-header {
    padding-top: var(--header-offset);
    padding-left: var(--gutter);
    padding-right: var(--gutter);
  }

  .post-content {
    padding: 0 var(--gutter);
  }

  .post-content img,
  .image-figure {
    max-width: 100%;
  }

  /* Wide and full images break out to viewport edges on mobile */
  .image-wide,
  .image-full {
    width: calc(100% + 2 * var(--gutter));
    margin-left: calc(-1 * var(--gutter));
    margin-right: calc(-1 * var(--gutter));
  }

  .post-title {
    font-size: var(--text-3xl);
    max-width: none;
  }

  .post-content h2 {
    font-size: var(--text-2xl);
  }

  .post-content h3 {
    font-size: var(--text-lg);
  }

  .post-content h4 {
    font-size: var(--text-base);
  }

  .post-list-item {
    grid-template-columns: 1fr;
    gap: var(--space-1);
  }
}

/* ==========================================================================
   Project Pages
   ========================================================================== */

.project-page {
  min-height: 100vh;
}

.project-header {
  padding: var(--space-16) var(--content-indent) var(--space-8);
}

.project-title {
  font-family: var(--font-display);
  font-size: var(--text-5xl);
  font-weight: var(--font-bold);
  line-height: var(--leading-tight);
}

.project-content {
  padding: 0 var(--content-indent);
}

.project-content > p,
.project-content > blockquote {
  max-width: var(--width-prose);
  margin-bottom: var(--space-6);
}

.project-content hr {
  max-width: var(--width-prose);
  margin: var(--space-12) 0;
}

@media (max-width: 768px) {
  .project-header {
    padding: var(--header-offset) var(--gutter) var(--space-8);
  }

  .project-title {
    font-size: var(--text-3xl);
  }

  .project-content {
    padding: 0 var(--gutter);
  }

  .project-content h2 {
    font-size: var(--text-2xl);
  }

  .project-content h3 {
    font-size: var(--text-lg);
  }

  .project-content h4 {
    font-size: var(--text-base);
  }

  /* Wide and full images break out to viewport edges on mobile */
  .project-content .image-wide,
  .project-content .image-full {
    width: calc(100% + 2 * var(--gutter));
    margin-left: calc(-1 * var(--gutter));
    margin-right: calc(-1 * var(--gutter));
  }
}

/* ==========================================================================
   Gallery - Masonry
   ========================================================================== */

.gallery-masonry {
  column-count: 3;
  column-gap: var(--space-4);
  margin: var(--space-12) 0;
}

.gallery-item {
  display: block;
  break-inside: avoid;
  margin-bottom: var(--space-4);
}

.gallery-item img {
  width: 100%;
  height: auto;
  display: block;
  transition: opacity 0.2s ease;
}

.gallery-item:hover img {
  opacity: 0.85;
}

@media (max-width: 1024px) {
  .gallery-masonry {
    column-count: 2;
  }
}

@media (max-width: 768px) {
  .gallery-masonry {
    column-count: 2;
    column-gap: var(--space-2);
  }

  .gallery-item {
    margin-bottom: var(--space-2);
  }
}

@media (max-width: 480px) {
  .gallery-masonry {
    column-count: 1;
  }
}

/* ==========================================================================
   Gallery - Flexible Rows
   ========================================================================== */

.gallery-row {
  display: flex;
  flex-wrap: nowrap;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.gallery-row .gallery-item {
  flex: 1 1 0;
  min-width: 0;
  margin-bottom: 0;
  overflow: hidden;
}

.gallery-row .gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Width modifiers - higher specificity to override flex default */
.gallery-row .photo-full {
  flex: 0 0 100%;
}

.gallery-row .photo-half {
  flex: 0 0 calc(50% - var(--space-2));
}

.gallery-row .photo-third {
  flex: 0 0 calc(33.333% - var(--space-3));
}

.gallery-row .photo-two-third {
  flex: 0 0 calc(66.666% - var(--space-2));
}

.gallery-row .photo-quarter {
  flex: 0 0 calc(25% - var(--space-3));
}

.gallery-row .photo-auto {
  flex: 1 1 0;
}

.gallery-row .photo-wide {
  flex: 0 0 100%;
  max-width: 900px;
  margin: 0 auto;
}

.gallery-row .photo-center {
  flex: 0 0 100%;
  max-width: 700px;
  margin: 0 auto;
}

@media (max-width: 768px) {
  .gallery-row {
    gap: var(--space-2);
  }

  .gallery-row .photo-half,
  .gallery-row .photo-third,
  .gallery-row .photo-two-third,
  .gallery-row .photo-quarter {
    flex: 0 0 calc(50% - var(--space-1));
  }

  .gallery-row .photo-wide,
  .gallery-row .photo-center {
    max-width: none;
  }
}

@media (max-width: 480px) {
  .gallery-row {
    flex-wrap: wrap;
  }

  .gallery-row .photo-half,
  .gallery-row .photo-third,
  .gallery-row .photo-two-third,
  .gallery-row .photo-quarter,
  .gallery-row .photo-auto,
  .gallery-row .gallery-item {
    flex: 0 0 100%;
  }
}

/* ==========================================================================
   Animations
   ========================================================================== */

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

main {
  animation: fadeUp 0.6s ease-out;
}

/* Smooth image loading */
.post-content img {
  opacity: 0;
  animation: fadeUp 0.5s ease-out forwards;
  animation-delay: 0.1s;
}
