/* ============================================
   Luna Blog — Design System
   A minimal, typography-focused blog theme
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --font-serif: 'Lora', 'Georgia', serif;

  /* Font Sizes — Modular Scale (1.25) */
  --text-xs: 0.8rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;
  --text-5xl: 3rem;

  /* 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;

  /* Layout */
  --max-width: 720px;
  --content-padding: var(--space-6);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;

  /* Light Mode Colors */
  --bg-primary: #fafafa;
  --bg-secondary: #ffffff;
  --bg-code: #f4f4f5;
  --bg-code-block: #1e1e2e;
  --text-primary: #18181b;
  --text-secondary: #52525b;
  --text-tertiary: #a1a1aa;
  --accent: #0d9488;
  --accent-hover: #0f766e;
  --border: #e4e4e7;
  --border-light: #f4f4f5;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
}

/* Dark Mode — auto (system) or manual (toggle) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-primary: #0a0a0b;
    --bg-secondary: #141416;
    --bg-code: #1e1e24;
    --bg-code-block: #141416;
    --text-primary: #fafafa;
    --text-secondary: #a1a1aa;
    --text-tertiary: #52525b;
    --accent: #5eead4;
    --accent-hover: #99f6e4;
    --border: #27272a;
    --border-light: #1c1c1f;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  }
}

[data-theme="dark"] {
  --bg-primary: #0a0a0b;
  --bg-secondary: #141416;
  --bg-code: #1e1e24;
  --bg-code-block: #141416;
  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-tertiary: #52525b;
  --accent: #5eead4;
  --accent-hover: #99f6e4;
  --border: #27272a;
  --border-light: #1c1c1f;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

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

::selection {
  background-color: var(--accent);
  color: #fff;
}

/* --- Layout --- */
.container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--content-padding);
}

main {
  flex: 1;
  padding-top: var(--space-8);
  padding-bottom: var(--space-16);
}

/* --- Header / Navigation --- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--bg-primary);
  border-bottom: 1px solid var(--border-light);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.site-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
  text-decoration: none;
  letter-spacing: -0.02em;
  transition: color var(--transition-fast);
}

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

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

.site-nav a {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition-fast);
  position: relative;
}

.site-nav a::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 1.5px;
  background-color: var(--accent);
  transition: width var(--transition-base);
}

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

.site-nav a:hover::after {
  width: 100%;
}

/* --- Home Page — Hero --- */
.hero {
  padding: var(--space-16) 0 var(--space-12);
  text-align: center;
}

.hero h1 {
  font-size: var(--text-4xl);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--text-primary);
  margin-bottom: var(--space-4);
}

.hero p {
  font-size: var(--text-lg);
  color: var(--text-secondary);
  line-height: 1.6;
  max-width: 540px;
  margin-left: auto;
  margin-right: auto;
}

/* --- Post List --- */
.posts-section-title {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-tertiary);
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border-light);
}

.post-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.post-item {
  display: flex;
  align-items: baseline;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-radius: 8px;
  transition: background-color var(--transition-fast);
}

.post-item:hover {
  background-color: var(--bg-secondary);
}

.post-item-date {
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  color: var(--text-tertiary);
  white-space: nowrap;
  min-width: 100px;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.post-item-title {
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--text-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

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

/* --- Article / Post Page --- */
.article-header {
  padding: var(--space-12) 0 var(--space-8);
  border-bottom: 1px solid var(--border-light);
  margin-bottom: var(--space-8);
}

.article-header h1 {
  font-size: var(--text-3xl);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.2;
  color: var(--text-primary);
  margin-bottom: var(--space-3);
}

.article-meta {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}

.article-meta time {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.article-meta .reading-time {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.article-meta .separator {
  color: var(--border);
}

/* --- Article Content (Prose) --- */
.prose {
  font-size: var(--text-base);
  line-height: 1.8;
  color: var(--text-primary);
}

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

.prose h2 {
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.3;
  margin-top: var(--space-12);
  margin-bottom: var(--space-4);
  color: var(--text-primary);
}

.prose h3 {
  font-size: var(--text-xl);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.4;
  margin-top: var(--space-10);
  margin-bottom: var(--space-3);
  color: var(--text-primary);
}

.prose h4 {
  font-size: var(--text-lg);
  font-weight: 600;
  margin-top: var(--space-8);
  margin-bottom: var(--space-2);
}

.prose p {
  color: var(--text-primary);
}

.prose a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  transition: color var(--transition-fast), text-decoration-color var(--transition-fast);
}

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

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

.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(--text-tertiary);
}

/* Blockquote */
.prose blockquote {
  border-left: 3px solid var(--accent);
  padding: var(--space-4) var(--space-6);
  background-color: var(--bg-secondary);
  border-radius: 0 8px 8px 0;
  color: var(--text-secondary);
  font-style: italic;
}

.prose blockquote p {
  color: var(--text-secondary);
}

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

/* Code Blocks */
.prose pre {
  background-color: var(--bg-code-block);
  border-radius: 12px;
  padding: var(--space-6);
  overflow-x: auto;
  font-size: var(--text-sm);
  line-height: 1.6;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}

.prose pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
  color: #d4d4d8;
}

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

/* Images */
.prose img {
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  margin: var(--space-4) 0;
}

/* Tables */
.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

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

.prose th {
  font-weight: 600;
  color: var(--text-primary);
}

.prose td {
  color: var(--text-secondary);
}

/* --- About Page --- */
.about-content {
  padding: var(--space-12) 0;
}

.about-content h1 {
  font-size: var(--text-3xl);
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: var(--space-8);
}

/* --- Footer --- */
.site-footer {
  border-top: 1px solid var(--border-light);
  padding: var(--space-8) 0;
}

.site-footer .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}

.footer-links {
  display: flex;
  gap: var(--space-5);
}

.footer-links a {
  color: var(--text-tertiary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.footer-links a:hover {
  color: var(--text-primary);
}

/* --- Back Link --- */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  text-decoration: none;
  transition: color var(--transition-fast);
  margin-bottom: var(--space-4);
}

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

.back-link svg {
  width: 16px;
  height: 16px;
}

/* --- 404 Page --- */
.not-found {
  text-align: center;
  padding: var(--space-20) 0;
}

.not-found h1 {
  font-size: var(--text-5xl);
  font-weight: 800;
  color: var(--text-tertiary);
  margin-bottom: var(--space-4);
}

.not-found p {
  color: var(--text-secondary);
  margin-bottom: var(--space-6);
}

.not-found a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* --- Theme Toggle --- */
.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  padding: var(--space-1);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: color var(--transition-fast), background-color var(--transition-fast);
}

.theme-toggle:hover {
  color: var(--text-primary);
  background-color: var(--bg-secondary);
}

/* Light mode: show moon, hide sun */
.icon-sun {
  display: none;
}

.icon-moon {
  display: block;
}

/* Dark mode: show sun, hide moon */
[data-theme="dark"] .icon-sun {
  display: block;
}

[data-theme="dark"] .icon-moon {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun {
    display: block;
  }

  :root:not([data-theme="light"]) .icon-moon {
    display: none;
  }
}

/* --- Responsive --- */
@media (max-width: 640px) {
  :root {
    --content-padding: var(--space-4);
  }

  .hero h1 {
    font-size: var(--text-3xl);
  }

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

  .post-item {
    flex-direction: column;
    gap: var(--space-1);
  }

  .post-item-date {
    min-width: auto;
  }

  .site-footer .container {
    flex-direction: column;
    gap: var(--space-4);
    text-align: center;
  }
}

/* --- Fade-in Animation --- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-in {
  animation: fadeInUp 0.5s ease forwards;
}

.post-item {
  animation: fadeInUp 0.4s ease forwards;
  opacity: 0;
}

.post-item:nth-child(1) {
  animation-delay: 0.05s;
}

.post-item:nth-child(2) {
  animation-delay: 0.1s;
}

.post-item:nth-child(3) {
  animation-delay: 0.15s;
}

.post-item:nth-child(4) {
  animation-delay: 0.2s;
}

.post-item:nth-child(5) {
  animation-delay: 0.25s;
}

.post-item:nth-child(6) {
  animation-delay: 0.3s;
}

.post-item:nth-child(7) {
  animation-delay: 0.35s;
}

.post-item:nth-child(8) {
  animation-delay: 0.4s;
}

.post-item:nth-child(9) {
  animation-delay: 0.45s;
}

.post-item:nth-child(10) {
  animation-delay: 0.5s;
}