/* ===== CSS Variables (Dark Mode - Slate Gray) ===== */
:root {
  --bg-primary: #121214;
  --bg-secondary: #1c1c1f;
  --bg-tertiary: #27272a;
  --text-primary: #ebebed;
  --text-secondary: #a1a1a6;
  --text-muted: #71717a;
  --accent: #d4d4d8;
  --border: #3f3f46;
  --shadow: rgba(0, 0, 0, 0.4);
  --transition: 0.3s ease;

  /* Fonts */
  --font-title: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-body: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

a {
  color: var(--text-primary);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--text-secondary);
}

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

/* ===== Header ===== */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(18, 18, 20, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-content {
  max-width: 1800px;
  margin: 0 auto;
  padding: 1.25rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.site-title {
  font-family: var(--font-title);
  font-size: 1.25rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

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

.site-nav a {
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--text-secondary);
}

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

/* ===== Main Content ===== */
.site-content {
  max-width: 1800px;
  margin: 0 auto;
  padding: 6rem 2rem 4rem;
  min-height: calc(100vh - 80px);
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 2.5rem;
}

.tab-btn {
  padding: 0.6rem 1.5rem;
  font-size: 0.9rem;
  font-weight: 500;
  font-family: inherit;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 100px;
  cursor: pointer;
  transition: all var(--transition);
}

.tab-btn:hover {
  color: var(--text-secondary);
  border-color: var(--text-muted);
}

.tab-btn.active {
  background: var(--text-primary);
  color: var(--bg-primary);
  border-color: var(--text-primary);
}

/* ===== Masonry Grid (JS-controlled row-first ordering) ===== */
.project-grid {
  position: relative;
  width: 100%;
}

.project-item {
  position: absolute;
  width: calc(25% - 1.125rem); /* 4 columns with gap */
}

@media (max-width: 1400px) {
  .project-item {
    width: calc(33.333% - 1rem); /* 3 columns */
  }
}

@media (max-width: 1000px) {
  .project-item {
    width: calc(50% - 0.75rem); /* 2 columns */
  }
}

@media (max-width: 600px) {
  .project-item {
    width: 100%; /* 1 column */
  }
}

.project-item {
  background: var(--bg-secondary);
  border-radius: 8px;
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition);
}

.project-item:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 40px var(--shadow);
}

.project-item a {
  display: block;
}

.project-item img {
  width: 100%;
  height: auto;
  object-fit: cover;
  transition: opacity var(--transition);
}

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

.project-info {
  padding: 1.25rem;
}

.project-item h3 {
  font-family: var(--font-title);
  font-size: 1.1rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
  line-height: 1.4;
}

.project-item p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.project-date {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

/* ===== Project Page ===== */
.project-page {
  max-width: 800px;
  margin: 0 auto;
  padding-bottom: 4rem;
}

/* Project Title from Layout */
.project-title {
  font-family: var(--font-title);
  font-size: 3.5rem;
  font-weight: 400;
  margin-bottom: 0.5rem;
  letter-spacing: -0.01em;
  line-height: 1.15;
  color: var(--text-primary);
}

/* Project Date Header - right-aligned under title */
.project-date-header {
  text-align: right;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 3rem;
}

/* Hide duplicate h1 from markdown content (project pages only, not blog) */
.project-content.category-project > h1:first-child {
  display: none;
}

/* Center images in project content */
.project-content p:has(> img) {
  text-align: center;
}

/* PNG images with light gray background for transparency */
.project-content img[src$=".png"] {
  background-color: #e5e5e5;
  border-radius: 4px;
}

/* Hero Title */
.project-page h1 {
  font-family: var(--font-title);
  font-size: 3.5rem;
  font-weight: 400;
  margin-bottom: 3rem;
  letter-spacing: -0.01em;
  line-height: 1.15;
  color: var(--text-primary);
}

/* Section Headers */
.project-page h2 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  margin-top: 4rem;
  margin-bottom: 1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}

.project-page h3 {
  font-size: 1.1rem;
  font-weight: 500;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

/* Body Text */
.project-page p {
  font-size: 1.05rem;
  line-height: 1.85;
  margin-bottom: 1.5rem;
  color: var(--text-secondary);
}

/* Lead paragraph (first p after h1) */
.project-page h1 + p,
.project-page h1 + table + p {
  font-size: 1.25rem;
  line-height: 1.7;
  color: var(--text-primary);
  font-weight: 300;
}

/* Images - Natural size up to max-width */
.project-page img {
  max-width: 100%;
  width: auto;
  height: auto;
  margin: 2.5rem 0;
  border-radius: 8px;
  transition: transform 0.4s ease, box-shadow 0.4s ease;
}

.project-page img:hover {
  transform: scale(1.01);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

/* Consecutive images in same paragraph - inline side by side */
.project-page p img {
  display: inline-block;
  vertical-align: bottom;
  margin: 1rem 0.5rem 1rem 0;
}

.project-page p img:last-child {
  margin-right: 0;
}

/* Image Grid Gallery */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin: 1.5rem 0;
}

.image-grid img {
  width: 100%;
  height: auto;
  border-radius: 4px;
  background-color: #e5e5e5;
}

/* Image Carousel */
.image-carousel {
  position: relative;
  display: inline-block;
  max-width: 100%;
  margin: 2rem auto;
  overflow: hidden;
  border-radius: 8px;
}

.image-carousel-wrapper {
  display: flex;
  justify-content: center;
}

.carousel-track {
  display: flex;
  transition: transform 0.5s ease;
}

.carousel-track.is-animating {
  pointer-events: none;
}

.carousel-track img {
  flex-shrink: 0;
  border-radius: 8px;
  object-fit: contain;
  margin: 0 !important;
}

.carousel-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.5);
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.3s ease;
  z-index: 10;
}

.carousel-btn:hover {
  background: rgba(0, 0, 0, 0.8);
}

.carousel-btn.prev {
  left: 10px;
}

.carousel-btn.next {
  right: 10px;
}

.carousel-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 1rem;
}

.carousel-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  border: none;
  cursor: pointer;
  transition: background 0.3s ease;
}

.carousel-dot.active {
  background: var(--text-primary);
}

/* Links */
.project-page a {
  color: var(--text-primary);
  text-decoration: none;
  background: linear-gradient(to right, var(--text-muted), var(--text-muted)) no-repeat;
  background-size: 100% 1px;
  background-position: 0 100%;
  transition: background-size var(--transition), color var(--transition);
}

.project-page a:hover {
  background-size: 100% 2px;
  color: var(--accent);
}

/* Back link exception */
.project-page .back-link {
  background: none;
}

/* Lists */
.project-page ul, .project-page ol {
  margin: 1.5rem 0 2rem 0;
  padding-left: 1.5rem;
  color: var(--text-secondary);
}

.project-page li {
  margin-bottom: 0.75rem;
  padding-left: 0.5rem;
  line-height: 1.7;
}

.project-page ul li::marker {
  color: var(--text-muted);
}

/* Blockquotes - Magazine callout style */
.project-page blockquote {
  margin: 2rem 0;
  padding: 1.5rem 2rem;
  background: var(--bg-secondary);
  border-left: 3px solid var(--text-muted);
  border-radius: 0 8px 8px 0;
}

.project-page blockquote p {
  margin-bottom: 0.75rem;
  font-size: 1rem;
  color: var(--text-secondary);
}

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

.project-page blockquote ul {
  margin: 0.5rem 0;
}

/* Emphasis */
.project-page em {
  font-style: italic;
  color: var(--text-secondary);
}

.project-page strong {
  font-weight: 600;
  color: var(--text-primary);
}

/* Horizontal Rule - subtle divider */
.project-page hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin: 3rem 0;
}

/* Image Gallery - Magazine/Masonry Style */
.image-gallery {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin: 2rem 0;
}

.image-gallery img {
  width: 100%;
  height: auto;
  margin: 0;
  border-radius: 8px;
  object-fit: cover;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.image-gallery img:hover {
  transform: scale(1.02);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

/* Full-width image in gallery */
.image-gallery .full-width,
.image-gallery img:only-child {
  grid-column: 1 / -1;
}

@media (max-width: 600px) {
  .image-gallery {
    grid-template-columns: 1fr;
  }
}

/* Side by side images (for GIFs etc.) */
.side-by-side-images {
  display: flex;
  gap: 1rem;
  margin: 2rem 0;
  justify-content: center;
  align-items: flex-start;
}

.side-by-side-images img {
  height: auto;
  border-radius: 8px;
  flex-shrink: 0;
}

@media (max-width: 600px) {
  .side-by-side-images {
    flex-direction: column;
    align-items: center;
  }
  .side-by-side-images img {
    max-width: 100%;
  }
}

/* Tables - clean minimal style */
.project-page table {
  width: 100%;
  margin: 1.5rem 0 2rem;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.project-page th,
.project-page td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

.project-page th {
  font-weight: 500;
  color: var(--text-primary);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
}

/* Navigation table (like [Instruction | How It Works]) */
.project-page > table:first-of-type {
  display: none;
}

/* Embedded Videos */
.project-page iframe {
  width: 100%;
  aspect-ratio: 16 / 9;
  margin: 2.5rem 0;
  border: none;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

/* Code blocks */
.project-page code {
  background: var(--bg-tertiary);
  padding: 0.2em 0.5em;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', monospace;
}

.project-page pre {
  background: var(--bg-secondary);
  padding: 1.5rem;
  border-radius: 8px;
  overflow-x: auto;
  margin: 2rem 0;
  border: 1px solid var(--border);
}

.project-page pre code {
  background: none;
  padding: 0;
}

/* Project metadata at end */
.project-page > p:last-of-type {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ===== Back Link ===== */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 2rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.back-link:hover {
  color: var(--text-primary);
}

.back-link::before {
  content: "\2190";
}

/* ===== Footer ===== */
.site-footer {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .header-content {
    padding: 1rem 1.5rem;
  }

  .site-content {
    padding: 5rem 1.25rem 3rem;
  }

  .project-page h1 {
    font-size: 2.25rem;
    margin-bottom: 2rem;
  }

  .project-page h2 {
    margin-top: 3rem;
  }

  .project-page p {
    font-size: 1rem;
  }

  .project-page h1 + p,
  .project-page h1 + table + p {
    font-size: 1.1rem;
  }

  .project-page blockquote {
    padding: 1rem 1.25rem;
    margin: 1.5rem 0;
  }

  .project-page img {
    margin: 1.5rem 0;
    border-radius: 6px;
  }

  .project-grid {
    column-gap: 1rem;
  }

  .project-item {
    margin-bottom: 1rem;
  }
}

/* ===== Selection ===== */
::selection {
  background: var(--accent);
  color: var(--bg-primary);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
