/* ============================================
   Editorial Typography System (Initium-inspired)
   ============================================ */

/* Use system font for ASCII punctuation to avoid CJK full-width spacing */
@font-face {
  font-family: 'Punctuation Fix';
  src: local('Georgia'), local('Times New Roman'), local('serif');
  unicode-range: U+0020-002F, U+003A-0040, U+005B-0060, U+007B-007E, U+2018-201F;
}

:root {
  /* Font Families */
  --font-display: 'Punctuation Fix', 'Noto Serif SC', Georgia, serif;
  --font-serif: 'Punctuation Fix', 'Noto Serif SC', Georgia, serif;
  --font-sans: 'Punctuation Fix', 'Noto Serif SC', Georgia, serif;
  --font-mono: 'IBM Plex Mono', 'SF Mono', 'Menlo', monospace;

  /* Type Scale (1.25 ratio) */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 2rem;
  --text-4xl: 2.5rem;

  /* Colors - Vibrant palette */
  --color-bg: #fafafa;
  --color-surface: #ffffff;
  --color-text: #222222;
  --color-text-secondary: #555555;
  --color-text-tertiary: #888888;
  --color-accent: #29a6c9;
  --color-accent-hover: #1e8ba8;
  --color-accent-2: #8b5cf6;
  --color-accent-3: #f59e0b;
  --color-gradient: linear-gradient(135deg, #29a6c9 0%, #8b5cf6 100%);
  --color-border: #e0e0e0;
  --color-border-light: #f0f0f0;
  --color-code-bg: #f5f5f5;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;

  /* Layout */
  --max-width: 1100px;
  --content-width: 720px;
  --narrow-width: 640px;
}

/* Dark mode - optimized for readability */
.dark {
  --color-bg: #161616;
  --color-surface: #1e1e1e;
  --color-text: #efefef;
  --color-text-secondary: #b8b8b8;
  --color-text-tertiary: #8a8a8a;
  --color-accent: #4cc9e8;
  --color-accent-hover: #6dd8f2;
  --color-accent-2: #b19afc;
  --color-accent-3: #fbbf24;
  --color-gradient: linear-gradient(135deg, #4cc9e8 0%, #b19afc 100%);
  --color-border: #3d3d3d;
  --color-border-light: #2d2d2d;
  --color-code-bg: #1c1c1c;
}

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

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

html {
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-y: scroll;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.7;
  color: var(--color-text);
  background-color: var(--color-bg);
  min-height: 100vh;
}

/* Screen reader only - visually hidden but SEO visible */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

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

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

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.animate-fade-in {
  animation: fadeIn 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.animate-fade-in-up {
  animation: fadeInUp 0.7s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.animate-slide-in {
  animation: slideIn 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* ============================================
   Reading Progress Bar
   ============================================ */

.reading-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: var(--color-gradient);
  transform: scaleX(0);
  transform-origin: left;
  z-index: 1000;
  will-change: transform;
  backface-visibility: hidden;
}

/* ============================================
   Site Header
   ============================================ */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}

.nav {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-4) var(--space-6);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav-title {
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  font-weight: 700;
  text-decoration: none;
  color: var(--color-text);
  letter-spacing: 0.05em;
  transition: color 0.3s ease;
}

.nav-title:hover {
  background: var(--color-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

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

.nav-links a {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  text-decoration: none;
  transition: color 0.2s;
}

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

/* Theme Toggle - Three-way Slider */
.theme-toggle {
  --theme-item: 30px;
  --theme-gap: 2px;
  --theme-pad: 3px;
}

.theme-toggle__track {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, var(--theme-item));
  gap: var(--theme-gap);
  padding: var(--theme-pad);
  border-radius: 100px;
  background: #f1f5f9;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

.dark .theme-toggle__track {
  background: linear-gradient(180deg, #0f0f0f 0%, #1a1a1a 100%);
  border: 1px solid transparent;
  border-top-color: #252525;
  border-bottom-color: #4a4a4a;
  border-left-color: #303030;
  border-right-color: #404040;
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.6),
    inset 0 -1px 1px rgba(255, 255, 255, 0.05),
    0 1px 2px rgba(255, 255, 255, 0.08);
}

.theme-toggle__indicator {
  position: absolute;
  top: var(--theme-pad);
  left: var(--theme-pad);
  width: var(--theme-item);
  height: var(--theme-item);
  border-radius: 50%;
  transform: translateX(calc(var(--theme-index, 0) * (var(--theme-item) + var(--theme-gap))));
  background: white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.1);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  will-change: transform;
  z-index: 0;
}

.dark .theme-toggle__indicator {
  background: linear-gradient(180deg, #454545 0%, #2a2a2a 100%);
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.5),
    0 1px 2px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.theme-toggle__btn {
  height: var(--theme-item);
  width: var(--theme-item);
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  position: relative;
  z-index: 1;
  transition: color 0.2s ease;
}

.theme-toggle__btn:hover {
  color: #64748b;
}

.dark .theme-toggle__btn {
  color: #606060;
}

.dark .theme-toggle__btn:hover {
  color: #909090;
}

.theme-toggle__btn.active {
  color: #334155;
}

.dark .theme-toggle__btn.active {
  color: #efefef;
}

.theme-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

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

.main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-12) var(--space-6);
}

/* ============================================
   Home Page - Initium-style Grid Layout
   ============================================ */

.home {
  min-height: 50vh;
}

.cards-section {
  max-width: var(--max-width);
  margin: 0 auto;
}

.section-header {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-10);
}

.section-title {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-tertiary);
  white-space: nowrap;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.section-line {
  flex: 1;
  height: 2px;
  background: var(--color-gradient);
  opacity: 0.3;
  border-radius: 1px;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-10) var(--space-12);
}

.card {
  background: transparent;
  transform: translateZ(0);
  will-change: transform;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.card:hover {
  transform: translateY(-6px) translateZ(0);
}

.card-link {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  height: 100%;
  padding: var(--space-4);
  border-radius: 12px;
  border: 1px solid transparent;
  transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.card-link:hover {
  background: var(--color-surface);
  border-color: var(--color-border);
  box-shadow: 0 8px 30px rgba(41, 166, 201, 0.1);
}

.dark .card-link:hover {
  box-shadow: 0 8px 30px rgba(61, 189, 224, 0.08);
}

.card-tag {
  align-self: flex-start;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-accent);
  background: rgba(41, 166, 201, 0.1);
  padding: var(--space-1) var(--space-3);
  border-radius: 4px;
  margin-bottom: var(--space-3);
  letter-spacing: 0.03em;
}


.card-title {
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: 1.4;
  color: var(--color-text);
  transition: color 0.2s;
  margin: 0 0 var(--space-3) 0;
}

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

.card-subtitle {
  font-size: var(--text-base);
  color: var(--color-text-secondary);
  line-height: 1.5;
  margin: 0 0 var(--space-3) 0;
}

.card-excerpt {
  font-size: var(--text-sm);
  color: var(--color-text-tertiary);
  line-height: 1.7;
  margin: 0 0 var(--space-4) 0;
  flex-grow: 1;
}

.card-date {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  margin-top: auto;
  letter-spacing: 0.02em;
}

/* Card with image - Initium style horizontal layout */
.card.has-image .card-link {
  flex-direction: row;
  gap: var(--space-5);
}

.card-image {
  flex-shrink: 0;
  width: 180px;
  height: 180px;
  border-radius: 4px;
  overflow: hidden;
}

.card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.card:hover .card-image img {
  transform: scale(1.05);
}

.card-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

/* Responsive: smaller image on tablet */
@media (max-width: 900px) {
  .card-image {
    width: 140px;
    height: 140px;
  }
}

/* Responsive: stack vertically on mobile */
@media (max-width: 640px) {
  .cards-grid {
    grid-template-columns: 1fr;
  }

  .card.has-image .card-link {
    flex-direction: column;
    gap: var(--space-4);
  }

  .card-image {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
  }
}

/* ============================================
   Article Page
   ============================================ */

.article-wrapper {
  position: relative;
}

.article {
  max-width: var(--content-width);
  margin: 0 auto;
}

/* Offset article to balance TOC on large screens */
@media (min-width: 1401px) {
  .article {
    margin-left: calc((100% - var(--content-width)) / 2 + 120px);
    margin-right: auto;
  }
}

/* Table of Contents */
.toc-sidebar {
  position: fixed;
  top: 100px;
  left: calc((100vw - var(--content-width)) / 2 - 280px);
  width: 240px;
  max-height: calc(100vh - 150px);
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding-bottom: var(--space-4);
}

.toc-sidebar::-webkit-scrollbar {
  display: none;
}

.toc-container {
  padding-right: var(--space-4);
}

.toc-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-tertiary);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 2px solid transparent;
  border-image: var(--color-gradient) 1;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.toc-title svg {
  flex-shrink: 0;
  opacity: 0.7;
}

.toc-nav {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.toc-link {
  display: block;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  text-decoration: none;
  padding: var(--space-2) var(--space-3);
  border-left: 2px solid var(--color-border-light);
  position: relative;
  transition: all 0.2s ease;
  line-height: 1.5;
}

.toc-link::before {
  content: '';
  position: absolute;
  left: -2px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--color-gradient);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.toc-link:hover {
  color: var(--color-text);
  background: var(--color-border-light);
}

.toc-link:hover::before {
  opacity: 0.5;
}

.toc-link.active {
  color: var(--color-accent);
  font-weight: 500;
  border-left-color: transparent;
}

.toc-link.active::before {
  opacity: 1;
}

.toc-h3 {
  padding-left: calc(var(--space-3) + 12px);
  font-size: var(--text-xs);
}

/* TOC completion message */
.toc-complete {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-4);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 500;
  color: #22c55e;
  background: rgba(34, 197, 94, 0.1);
  border-radius: 8px;
  opacity: 0;
  transform: translateY(10px) scale(0.95);
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}

.toc-complete.show {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.toc-complete svg {
  flex-shrink: 0;
  animation: toc-check-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s both;
}

@keyframes toc-check-pop {
  0% {
    transform: scale(0) rotate(-45deg);
    opacity: 0;
  }
  100% {
    transform: scale(1) rotate(0);
    opacity: 1;
  }
}

.dark .toc-complete {
  background: rgba(34, 197, 94, 0.15);
}

/* Hide TOC on smaller screens */
@media (max-width: 1400px) {
  .toc-sidebar {
    display: none;
  }
}

.article-header {
  margin-bottom: var(--space-10);
  padding-bottom: var(--space-8);
  border-bottom: 1px solid var(--color-border-light);
}

.article-meta-row {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.article-date {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--color-text-tertiary);
  letter-spacing: 0.02em;
}

.article-reading-time {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-tertiary);
}

.article-reading-time svg {
  opacity: 0.7;
}

/* Font size controls */
.font-size-controls {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-left: auto;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-1);
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--color-text-tertiary);
  transition: color 0.2s;
}

.tool-btn:hover {
  color: var(--color-accent);
}

.font-size-label {
  font-size: var(--text-sm);
  color: var(--color-text-tertiary);
  min-width: 1.5em;
  text-align: center;
}

/* Continue reading banner */
.continue-reading-banner {
  position: fixed;
  bottom: var(--space-6);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  font-size: var(--text-sm);
}

.continue-reading-banner button {
  padding: var(--space-2) var(--space-3);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: var(--text-sm);
  transition: all 0.2s;
}

#continue-reading {
  background: var(--color-accent);
  color: white;
}

#continue-reading:hover {
  background: var(--color-accent-hover);
}

#dismiss-banner {
  background: transparent;
  color: var(--color-text-tertiary);
  padding: var(--space-1) var(--space-2);
}

#dismiss-banner:hover {
  color: var(--color-text);
}

.article-title {
  font-family: 'Punctuation Fix', 'Noto Serif SC', Georgia, serif;
  font-size: var(--text-3xl);
  font-weight: 700;
  font-style: normal;
  line-height: 1.3;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-4);
  color: var(--color-text);
}

.article-subtitle {
  font-family: var(--font-sans);
  font-size: var(--text-lg);
  color: var(--color-text-secondary);
  line-height: 1.6;
  font-weight: 400;
}

.article-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-5);
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 500;
  padding: var(--space-2) var(--space-4);
  background: rgba(41, 166, 201, 0.1);
  border: none;
  border-radius: 20px;
  color: var(--color-accent);
  text-decoration: none;
  letter-spacing: 0.03em;
  transform: translateZ(0);
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tag:hover {
  background: rgba(41, 166, 201, 0.15);
  color: var(--color-accent-hover);
  transform: translateY(-1px) translateZ(0);
  box-shadow: 0 0 12px rgba(41, 166, 201, 0.4), 0 0 24px rgba(41, 166, 201, 0.2);
}

.dark .tag:hover {
  background: rgba(61, 189, 224, 0.18);
  color: var(--color-accent);
  box-shadow: 0 0 12px rgba(61, 189, 224, 0.5), 0 0 24px rgba(61, 189, 224, 0.25);
}


/* ============================================
   Tag Page
   ============================================ */

.tag-page {
  max-width: var(--content-width);
  margin: 0 auto;
}

.tag-header {
  margin-bottom: var(--space-10);
  padding-bottom: var(--space-8);
  border-bottom: 1px solid var(--color-border);
  text-align: center;
}

.tag-title {
  font-family: var(--font-serif);
  font-size: var(--text-4xl);
  font-weight: 700;
  background: var(--color-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: var(--space-3);
}

.tag-count {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  letter-spacing: 0.05em;
}

.tag-page .posts-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

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

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

.tag-page .post-link {
  display: block;
  padding: var(--space-8) 0;
  text-decoration: none;
  transition: background 0.2s;
}

.tag-page .post-link:hover .post-title {
  color: var(--color-accent);
}

.tag-page .post-meta {
  margin-bottom: var(--space-2);
}

.tag-page .post-date {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  letter-spacing: 0.02em;
}

.tag-page .post-title {
  font-family: var(--font-serif);
  font-size: var(--text-2xl);
  font-weight: 600;
  line-height: 1.4;
  margin: 0 0 var(--space-2) 0;
  color: var(--color-text);
  transition: color 0.2s;
}

.tag-page .post-subtitle {
  font-size: var(--text-base);
  color: var(--color-text-secondary);
  margin: 0 0 var(--space-2) 0;
  line-height: 1.5;
}

.tag-page .post-excerpt {
  font-size: var(--text-sm);
  color: var(--color-text-tertiary);
  margin: 0;
  line-height: 1.7;
}

/* ============================================
   Prose (Article Content)
   ============================================ */

.prose {
  font-family: 'Punctuation Fix', 'Noto Serif SC', Georgia, serif;
  font-size: var(--text-base);
  line-height: 1.8;
  color: var(--color-text);
  max-width: var(--narrow-width);
}

.prose > * + * {
  margin-top: var(--space-6);
}

.prose h2 {
  font-family: var(--font-sans);
  font-size: var(--text-xl);
  font-weight: 700;
  margin-top: var(--space-12);
  margin-bottom: var(--space-4);
  color: var(--color-text);
}

.prose h3 {
  font-family: var(--font-sans);
  font-size: var(--text-lg);
  font-weight: 600;
  margin-top: var(--space-8);
  margin-bottom: var(--space-3);
}

.prose p {
  text-align: justify;
  text-justify: inter-ideograph;
}

.prose a {
  color: var(--color-accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}

.prose a:hover {
  border-bottom-color: var(--color-accent);
}

.prose strong {
  font-weight: 700;
}

.prose em {
  font-style: italic;
}

/* Lists */
.prose ul, .prose ol {
  padding-left: var(--space-6);
}

.prose li {
  margin-top: var(--space-2);
}

.prose li::marker {
  color: var(--color-text-tertiary);
}

/* Blockquotes */
.prose blockquote {
  position: relative;
  border-left: 3px solid var(--color-accent);
  padding: var(--space-4) var(--space-5);
  margin: var(--space-6) 0;
  background: var(--color-border-light);
  border-radius: 0 4px 4px 0;
  font-style: normal;
  color: var(--color-text-secondary);
}

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

.dark .prose blockquote {
  background: var(--color-surface);
  border-left-color: var(--color-accent);
}

/* Code */
.prose code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--color-code-bg);
  padding: 0.15em 0.4em;
  border-radius: 3px;
}

.prose pre {
  background: var(--color-code-bg);
  padding: var(--space-5);
  border-radius: 4px;
  overflow-x: auto;
  font-size: var(--text-sm);
  line-height: 1.6;
}

.prose pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

/* Images */
.prose img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  display: block;
  margin: var(--space-8) auto;
}

/* Video Embeds */
.prose .video-container {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; /* 16:9 aspect ratio */
  margin: var(--space-8) 0;
  border-radius: 4px;
  overflow: hidden;
}

.prose .video-container iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
}

.prose figure {
  margin: var(--space-10) 0;
  text-align: center;
}

.prose figcaption {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--color-text-tertiary);
  text-align: center;
  margin-top: var(--space-3);
}

/* Tables */
.prose table {
  width: 100%;
  border-collapse: collapse;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', 'PingFang SC', sans-serif;
  font-size: var(--text-sm);
  display: block;
  overflow-x: auto;
}

.prose th, .prose td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  text-align: left;
}

.prose th {
  font-weight: 600;
  background: var(--color-border-light);
}

/* Horizontal Rule */
.prose hr {
  border: none;
  height: 1px;
  background: var(--color-border);
  margin: var(--space-12) 0;
}

/* ============================================
   Math (KaTeX)
   ============================================ */

.prose .katex-display {
  margin: var(--space-6) 0;
  overflow-x: auto;
}

/* ============================================
   Article Footer (Navigation)
   ============================================ */

.article-footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  margin-top: var(--space-16);
  padding-top: var(--space-8);
  border-top: 1px solid var(--color-border);
}

.nav-link {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  padding: var(--space-4);
  border: 1px solid var(--color-border-light);
  border-radius: 12px;
  transform: translateZ(0);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.nav-link:hover {
  border-color: var(--color-accent);
  background: rgba(41, 166, 201, 0.05);
  transform: translateY(-2px) translateZ(0);
  box-shadow: 0 4px 16px rgba(41, 166, 201, 0.12);
}

.dark .nav-link:hover {
  background: rgba(61, 189, 224, 0.08);
  box-shadow: 0 4px 16px rgba(61, 189, 224, 0.1);
}

.nav-link.next {
  text-align: right;
  grid-column: 2;
}

.nav-label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  margin-bottom: var(--space-1);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.nav-link .nav-title {
  font-family: var(--font-serif);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text);
  line-height: 1.4;
}

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

.site-footer {
  margin-top: var(--space-20);
}

.footer-content {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-8) var(--space-6);
  font-size: var(--text-sm);
  color: var(--color-text-tertiary);
  text-align: center;
}

/* ============================================
   Syntax Highlighting (Rouge)
   ============================================ */

.highlight .c, .highlight .c1, .highlight .cm { color: #6a737d; }
.highlight .k, .highlight .kd, .highlight .kn { color: #d73a49; }
.highlight .s, .highlight .s1, .highlight .s2 { color: #032f62; }
.highlight .n, .highlight .nf, .highlight .nc { color: #6f42c1; }
.highlight .mi, .highlight .mf { color: #005cc5; }
.highlight .o, .highlight .p { color: var(--color-text); }

.dark .highlight .c, .dark .highlight .c1, .dark .highlight .cm { color: #6a737d; }
.dark .highlight .k, .dark .highlight .kd, .dark .highlight .kn { color: #ff7b72; }
.dark .highlight .s, .dark .highlight .s1, .dark .highlight .s2 { color: #a5d6ff; }
.dark .highlight .n, .dark .highlight .nf, .dark .highlight .nc { color: #d2a8ff; }
.dark .highlight .mi, .dark .highlight .mf { color: #79c0ff; }

/* ============================================
   404 Error Page
   ============================================ */

.error-page {
  text-align: center;
  padding: var(--space-20) 0;
  max-width: var(--content-width);
  margin: 0 auto;
}

.error-code {
  font-family: var(--font-display);
  font-size: 6rem;
  font-weight: 700;
  color: var(--color-border);
  line-height: 1;
  margin-bottom: var(--space-4);
}

.error-message {
  font-family: var(--font-serif);
  font-size: var(--text-2xl);
  font-weight: 600;
  margin-bottom: var(--space-3);
}

.error-description {
  color: var(--color-text-secondary);
  margin-bottom: var(--space-8);
}

.error-link {
  display: inline-block;
  padding: var(--space-3) var(--space-6);
  background: var(--color-accent);
  color: white;
  text-decoration: none;
  border-radius: 4px;
  font-weight: 500;
  font-size: var(--text-sm);
  transition: background 0.2s;
}

.error-link:hover {
  background: var(--color-accent-hover);
}

/* ============================================
   Search Page
   ============================================ */

.search-page {
  max-width: var(--content-width);
  margin: 0 auto;
}

.search-container {
  margin-bottom: var(--space-10);
}

.search-input {
  width: 100%;
  padding: var(--space-4) var(--space-5);
  font-size: var(--text-lg);
  font-family: inherit;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus {
  border-color: var(--color-accent);
}

.search-input::placeholder {
  color: var(--color-text-tertiary);
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.search-hint,
.search-no-results {
  text-align: center;
  color: var(--color-text-tertiary);
  padding: var(--space-10);
}

.search-result-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-6) 0;
  border-bottom: 1px solid var(--color-border-light);
  text-decoration: none;
  transition: background 0.2s;
}

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

.search-result-date {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  letter-spacing: 0.02em;
}

.search-result-title {
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--color-text);
  transition: color 0.2s;
}

.search-result-subtitle {
  font-size: var(--text-base);
  color: var(--color-text-secondary);
}

/* ============================================
   Social Sharing
   ============================================ */

.share-section {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  margin-top: var(--space-10);
  padding-top: var(--space-6);
  border-top: 1px solid var(--color-border-light);
}

.share-label {
  font-size: var(--text-sm);
  color: var(--color-text-tertiary);
}

.share-buttons {
  display: flex;
  gap: var(--space-2);
}

.share-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  color: var(--color-text-secondary);
  text-decoration: none;
  background: var(--color-surface);
  cursor: pointer;
  transition: all 0.2s;
}

.share-btn:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.share-btn.copied {
  border-color: #22c55e;
  color: #22c55e;
}

/* ============================================
   Related Posts
   ============================================ */

.related-posts {
  margin-top: var(--space-10);
  padding-top: var(--space-8);
  border-top: 1px solid var(--color-border-light);
}

.related-title {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-tertiary);
  margin-bottom: var(--space-5);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.related-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.related-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--color-border-light);
  text-decoration: none;
  transition: background 0.2s;
}

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

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

.related-item-title {
  font-family: var(--font-serif);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text);
  transition: color 0.2s;
}

.related-item-subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

/* ============================================
   View Transitions
   ============================================ */

@view-transition {
  navigation: auto;
}

/* Title transition - smooth movement and scaling */
::view-transition-group(post-title-*) {
  animation-duration: 0.6s;
  animation-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1);
}

::view-transition-old(post-title-*),
::view-transition-new(post-title-*) {
  animation-duration: 0.6s;
  animation-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1);
  /* Prevent flickering by matching heights */
  height: 100%;
  width: 100%;
  object-fit: none;
}

/* Page navigation crossfade (default) */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.25s;
  animation-timing-function: ease-in-out;
}

::view-transition-old(root) {
  animation-name: fade-out;
}

::view-transition-new(root) {
  animation-name: fade-in;
}

@keyframes fade-out {
  to { opacity: 0; }
}

@keyframes fade-in {
  from { opacity: 0; }
}

/* Theme toggle circular expansion animation */
:root {
  --theme-toggle-x: 50vw;
  --theme-toggle-y: 0;
  --theme-toggle-radius: 100vmax;
}

html.theme-transitioning::view-transition-old(root) {
  animation: none;
  z-index: 1;
}

html.theme-transitioning::view-transition-new(root) {
  animation: theme-circle-expand 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 9999;
}

@keyframes theme-circle-expand {
  from {
    clip-path: circle(0 at var(--theme-toggle-x) var(--theme-toggle-y));
  }
  to {
    clip-path: circle(var(--theme-toggle-radius) at var(--theme-toggle-x) var(--theme-toggle-y));
  }
}

/* ============================================
   Icon Utilities (Heroicons)
   ============================================ */

/* Navigation Icons - Glossy Hover Effect */
.nav-link-icon {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  text-decoration: none;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--space-2);
  position: relative;
  transition: transform 0.25s, color 0.2s, background 0.2s;
}

.nav-link-icon:hover {
  color: var(--color-accent);
  background: rgba(41, 166, 201, 0.08);
  transform: translateY(-2px);
}

.dark .nav-link-icon:hover {
  background: rgba(61, 189, 224, 0.1);
}

.nav-link-icon:active {
  transform: translateY(0);
  transition: transform 0.1s;
}

.nav-link-icon svg {
  flex-shrink: 0;
  transition: transform 0.25s;
}

.nav-link-icon:hover svg {
  transform: scale(1.15) rotate(-5deg);
}

/* Shine effect on hover */
.nav-link-icon::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(
    120deg,
    transparent 0%,
    transparent 30%,
    rgba(255, 255, 255, 0.3) 50%,
    transparent 70%,
    transparent 100%
  );
  background-size: 200% 100%;
  background-position: 200% 0;
  opacity: 0;
  transition: opacity 0.3s, background-position 0.5s;
  pointer-events: none;
}

.nav-link-icon:hover::before {
  opacity: 1;
  background-position: -200% 0;
}

/* Card metadata with icons */
.card-tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.card-tag svg {
  flex-shrink: 0;
  opacity: 0.7;
}

.card-date {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.card-date svg {
  flex-shrink: 0;
  opacity: 0.6;
}

/* Article date with icon */
.article-date {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.article-date svg {
  flex-shrink: 0;
  opacity: 0.7;
}

/* Tags with icons */
.tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.tag svg {
  flex-shrink: 0;
  opacity: 0.7;
}

/* Navigation arrows */
.nav-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.nav-label svg {
  flex-shrink: 0;
  transition: transform 0.2s;
}

.nav-link.prev:hover .nav-label svg {
  transform: translateX(-3px);
}

.nav-link.next:hover .nav-label svg {
  transform: translateX(3px);
}

/* Tag page post date with icon */
.tag-page .post-date {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.tag-page .post-date svg {
  flex-shrink: 0;
  opacity: 0.6;
}

/* Hide nav text on very small screens */
@media (max-width: 480px) {
  .nav-link-icon span {
    display: none;
  }

  .nav-links {
    gap: var(--space-3);
  }
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 768px) {
  html {
    font-size: 16px;
  }

  .nav {
    padding: var(--space-3) var(--space-4);
  }

  .nav-links {
    gap: var(--space-4);
  }

  .main {
    padding: var(--space-8) var(--space-4);
  }

  /* cards-grid responsive handled in card-image section */
  .cards-grid {
    gap: var(--space-8);
    gap: var(--space-8);
  }

  .card-title {
    font-size: var(--text-lg);
  }

  .article-title {
    font-size: var(--text-2xl);
  }

  .article-footer {
    grid-template-columns: 1fr;
  }

  .nav-link.next {
    grid-column: 1;
    text-align: left;
  }

  .prose pre {
    margin-left: calc(-1 * var(--space-4));
    margin-right: calc(-1 * var(--space-4));
    border-radius: 0;
  }

  .error-code {
    font-size: 4rem;
  }

  .share-section {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
  }

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

/* ============================================
   Cookie Consent Banner (GDPR)
   ============================================ */

.cookie-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-bg);
  border-top: 1px solid var(--color-border);
  padding: var(--space-4) var(--space-6);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-6);
  z-index: 1000;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

.cookie-banner p {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.cookie-banner a {
  color: var(--color-accent);
  text-decoration: underline;
}

.cookie-buttons {
  display: flex;
  gap: var(--space-3);
  flex-shrink: 0;
}

.cookie-accept,
.cookie-reject {
  padding: var(--space-2) var(--space-4);
  border-radius: 4px;
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.cookie-accept {
  background: var(--color-accent);
  color: white;
  border: none;
}

.cookie-accept:hover {
  background: var(--color-accent-hover);
}

.cookie-reject {
  background: transparent;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

.cookie-reject:hover {
  background: var(--color-border-light);
}

@media (max-width: 768px) {
  .cookie-banner {
    flex-direction: column;
    text-align: center;
    gap: var(--space-4);
    padding: var(--space-4);
  }
}

/* ============================================
   Text Selection Menu
   ============================================ */

.selection-menu {
  position: fixed;
  display: none;
  align-items: center;
  gap: 2px;
  padding: 6px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  animation: selectionMenuFadeIn 0.15s ease;
}

.selection-menu.show {
  display: flex;
}

.selection-menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--color-text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.selection-menu-btn:hover {
  background: var(--color-border-light);
  color: var(--color-text);
}

.selection-menu-btn svg {
  flex-shrink: 0;
}

.selection-menu-divider {
  width: 1px;
  height: 24px;
  background: var(--color-border);
  margin: 0 4px;
}

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

/* Mobile adjustments */
@media (max-width: 640px) {
  .selection-menu-btn span {
    display: none;
  }

  .selection-menu-btn {
    padding: 10px;
  }
}
