/* =============================================================================
   Site stylesheet — Smart Stylish Clean
   Warm paper palette + teal accent. Fraunces + Manrope + JetBrains Mono.
   ============================================================================= */

/* ---------- Design tokens ---------- */
:root {
  /* Surfaces */
  --background: hsl(39 33% 96%);      /* #F7F5F2 */
  --foreground: hsl(20 14% 11%);      /* #1C1917 */
  --card:       hsl(0 0% 100%);
  --muted:      hsl(35 24% 91%);      /* #EFEBE6 */
  --muted-foreground: hsl(30 8% 52%); /* #8C857B */
  --accent:     hsl(35 17% 88%);      /* #E8E4DE */
  --border:     hsl(35 13% 84%);      /* #DCD7D0 */

  /* Brand */
  --primary:        hsl(177 84% 32%); /* #0D9488 */
  --primary-hover:  hsl(177 84% 28%);
  --primary-foreground: hsl(0 0% 100%);
  --ring:           hsl(177 84% 32%);

  /* Semantic */
  --warm:    hsl(23 86% 41%);
  --success: hsl(143 71% 29%);
  --info:    hsl(202 95% 32%);
  --destructive: hsl(345 83% 41%);

  /* Typography */
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-sans: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, monospace;

  /* Scale */
  --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: 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-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;

  --radius: 6px;
  --radius-lg: 12px;

  --max-width: 42rem;
  --max-width-wide: 64rem;

  --transition: 150ms ease-out;
}

@media (prefers-color-scheme: dark) {
  :root:not(.light) {
    --background: hsl(20 14% 11%);
    --foreground: hsl(60 9% 98%);
    --card:       hsl(20 9% 16%);
    --muted:      hsl(20 7% 14%);
    --muted-foreground: hsl(30 7% 55%);
    --accent:     hsl(20 7% 19%);
    --border:     hsl(20 7% 22%);

    --primary:        hsl(174 78% 44%);
    --primary-hover:  hsl(174 78% 52%);
    --ring:           hsl(174 78% 44%);

    --warm:    hsl(25 95% 61%);
    --success: hsl(142 69% 58%);
    --info:    hsl(199 92% 60%);
    --destructive: hsl(347 87% 60%);
  }
}

.dark {
  --background: hsl(20 14% 11%);
  --foreground: hsl(60 9% 98%);
  --card:       hsl(20 9% 16%);
  --muted:      hsl(20 7% 14%);
  --muted-foreground: hsl(30 7% 55%);
  --accent:     hsl(20 7% 19%);
  --border:     hsl(20 7% 22%);

  --primary:        hsl(174 78% 44%);
  --primary-hover:  hsl(174 78% 52%);
  --ring:           hsl(174 78% 44%);

  --warm:    hsl(25 95% 61%);
  --success: hsl(142 69% 58%);
  --info:    hsl(199 92% 60%);
  --destructive: hsl(347 87% 60%);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
img, svg { display: block; max-width: 100%; height: auto; }
input, button, textarea, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; padding: 0; }

/* ---------- Base typography ---------- */
body {
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "rlig" 1, "calt" 1;
  transition: background-color var(--transition), color var(--transition);
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.01em;
  color: var(--foreground);
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-3xl); margin-top: var(--space-12); margin-bottom: var(--space-4); }
h3 { font-size: var(--text-2xl); margin-top: var(--space-10); margin-bottom: var(--space-3); }
h4 { font-size: var(--text-xl); margin-top: var(--space-8); margin-bottom: var(--space-2); }

p { margin-block: var(--space-4); }

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover { color: var(--primary-hover); text-decoration: underline; text-underline-offset: 3px; }

:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
  border-radius: 2px;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin-block: var(--space-10);
}

strong { font-weight: 700; }
em { font-style: italic; }

small { font-size: var(--text-sm); color: var(--muted-foreground); }

/* ---------- Lists ---------- */
.prose ul, .prose ol {
  padding-left: 1.5rem;
  margin-block: var(--space-4);
}
.prose li { margin-block: var(--space-2); }
.prose li > ul, .prose li > ol { margin-block: var(--space-2); }

/* ---------- Code ---------- */
code, kbd, pre, samp {
  font-family: var(--font-mono);
  font-size: 0.925em;
}

:not(pre) > code {
  background: var(--muted);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.9em;
  border: 1px solid var(--border);
}

pre {
  background: var(--card);
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-6);
  overflow-x: auto;
  line-height: 1.5;
  margin-block: var(--space-6);
  font-size: 0.875rem;
}

pre code { background: transparent; padding: 0; border: 0; font-size: inherit; }

/* ---------- Blockquote ---------- */
blockquote {
  border-left: 3px solid var(--primary);
  padding-left: var(--space-6);
  margin-block: var(--space-6);
  color: var(--muted-foreground);
  font-family: var(--font-display);
  font-style: italic;
  font-size: var(--text-lg);
}
blockquote p { margin-block: var(--space-2); }

/* ---------- Tables in prose ---------- */
.prose table {
  width: 100%;
  border-collapse: collapse;
  margin-block: var(--space-6);
  font-size: var(--text-sm);
}
.prose th, .prose td {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}
.prose th {
  font-weight: 600;
  background: var(--muted);
}

/* ---------- Images in prose ---------- */
.prose img {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-block: var(--space-6);
}

/* =============================================================================
   Layout
   ============================================================================= */
.site {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: var(--max-width);
  margin-inline: auto;
  padding-inline: var(--space-6);
}

.container-wide {
  width: 100%;
  max-width: var(--max-width-wide);
  margin-inline: auto;
  padding-inline: var(--space-6);
}

/* ---------- Header ---------- */
.site-header {
  padding-block: var(--space-6);
  border-bottom: 1px solid var(--border);
  background: var(--background);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
  background: color-mix(in srgb, var(--background) 85%, transparent);
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
  position: relative;
}

.site-brand {
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-3);
  color: var(--foreground);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-xl);
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.site-brand:hover { color: var(--foreground); text-decoration: none; }

.site-brand__title {
  display: inline-block;
  min-width: 0;
}

.site-brand__dot {
  width: 8px;
  height: 8px;
  background: var(--primary);
  border-radius: 50%;
  display: inline-block;
}

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

.nav-toggle {
  display: none;
  color: var(--muted-foreground);
  font-size: var(--text-sm);
  padding: var(--space-2);
  border-radius: var(--radius);
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), background-color var(--transition);
}

.nav-toggle:hover {
  color: var(--foreground);
  background: var(--accent);
}

.nav-toggle svg { width: 18px; height: 18px; }

.site-nav a {
  color: var(--muted-foreground);
  font-size: var(--text-sm);
  font-weight: 500;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  transition: color var(--transition), background-color var(--transition);
}

.site-nav a:hover {
  color: var(--foreground);
  background: var(--accent);
  text-decoration: none;
}

.site-nav a.active {
  color: var(--foreground);
}

.theme-toggle {
  color: var(--muted-foreground);
  font-size: var(--text-sm);
  padding: var(--space-2);
  border-radius: var(--radius);
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), background-color var(--transition);
}
.theme-toggle:hover {
  color: var(--foreground);
  background: var(--accent);
}
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
.dark .theme-toggle .icon-moon { display: none; }
.dark .theme-toggle .icon-sun { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not(.light) .theme-toggle .icon-moon { display: none; }
  :root:not(.light) .theme-toggle .icon-sun { display: block; }
}

/* ---------- Main ---------- */
.site-main {
  flex: 1;
  padding-block: var(--space-12) var(--space-20);
}

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding-block: var(--space-8);
  color: var(--muted-foreground);
  font-size: var(--text-sm);
}

.site-footer__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-4);
}

.site-footer a { color: var(--muted-foreground); }
.site-footer a:hover { color: var(--foreground); }

/* =============================================================================
   Home / post list
   ============================================================================= */
.hero {
  margin-bottom: var(--space-16);
}
.hero h1 {
  font-size: var(--text-5xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-4);
}
.hero p {
  font-size: var(--text-lg);
  color: var(--muted-foreground);
  max-width: 36rem;
}

.section-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted-foreground);
  margin-bottom: var(--space-6);
}

.post-list {
  display: flex;
  flex-direction: column;
}

.post-item {
  padding-block: var(--space-6);
  border-bottom: 1px solid var(--border);
}
.post-item:last-child { border-bottom: 0; }

.post-item__link {
  display: grid;
  grid-template-columns: 7rem 1fr;
  gap: var(--space-6);
  align-items: baseline;
  color: inherit;
}
.post-item__link:hover { color: inherit; text-decoration: none; }
.post-item__link:hover .post-item__title {
  color: var(--primary);
}

.post-item__date {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--muted-foreground);
  letter-spacing: 0.02em;
}

.post-item__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-xl);
  line-height: 1.3;
  margin-bottom: var(--space-1);
  transition: color var(--transition);
}

.post-item__teaser {
  color: var(--muted-foreground);
  font-size: var(--text-base);
  line-height: 1.5;
}

@media (max-width: 640px) {
  .post-item__link {
    grid-template-columns: 1fr;
    gap: var(--space-2);
  }
}

@media (max-width: 768px) {
  .container,
  .container-wide {
    padding-inline: var(--space-4);
  }

  .site-header {
    padding-block: var(--space-4);
  }

  .site-header__inner {
    gap: var(--space-3);
  }

  .site-brand {
    font-size: var(--text-lg);
    min-width: 0;
    flex: 1;
  }

  .site-brand__title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .nav-toggle {
    display: inline-flex;
    flex-shrink: 0;
  }

  .site-nav {
    display: none;
    position: absolute;
    top: calc(100% + var(--space-2));
    left: 0;
    right: 0;
    z-index: 20;
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-1);
    padding: var(--space-3);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: color-mix(in srgb, var(--card) 96%, transparent);
    box-shadow: 0 8px 24px color-mix(in srgb, var(--foreground) 12%, transparent);
  }

  .site-header.nav-open .site-nav {
    display: flex;
  }

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

  .theme-toggle {
    align-self: flex-start;
  }

  .site-main {
    padding-block: var(--space-8) var(--space-12);
  }

  h2 {
    margin-top: var(--space-8);
    margin-bottom: var(--space-3);
  }

  h3 {
    margin-top: var(--space-6);
    margin-bottom: var(--space-2);
  }

  h4 {
    margin-top: var(--space-4);
  }

  p {
    margin-block: var(--space-3);
  }

  pre,
  blockquote,
  .prose table,
  .prose img {
    margin-block: var(--space-4);
  }

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

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

  .hero p {
    font-size: var(--text-base);
  }

  .post-item {
    padding-block: var(--space-4);
  }

  .section-cta {
    margin-top: var(--space-10);
    padding: var(--space-6);
  }

  .post-header {
    margin-bottom: var(--space-8);
    padding-bottom: var(--space-6);
  }

  .post-header h1 {
    font-size: var(--text-3xl);
    margin-bottom: var(--space-3);
  }

  .post-footer {
    margin-top: var(--space-10);
    padding-top: var(--space-6);
  }

  .site-footer {
    padding-block: var(--space-6);
  }
}

/* ---------- Section nav (e.g. home → archive) ---------- */
.section-cta {
  margin-top: var(--space-16);
  padding: var(--space-8);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.section-cta h3 {
  margin-top: 0;
  margin-bottom: var(--space-2);
  font-size: var(--text-xl);
}
.section-cta p {
  color: var(--muted-foreground);
  margin-bottom: var(--space-4);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 500;
  border-radius: var(--radius);
  transition: background-color var(--transition), color var(--transition), border-color var(--transition);
  height: 2.25rem;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-foreground);
}
.btn-primary:hover {
  background: var(--primary-hover);
  color: var(--primary-foreground);
  text-decoration: none;
}

.btn-ghost {
  color: var(--foreground);
  background: transparent;
}
.btn-ghost:hover {
  background: var(--accent);
  color: var(--foreground);
  text-decoration: none;
}

.btn-outline {
  border-color: var(--border);
  background: var(--background);
  color: var(--foreground);
}
.btn-outline:hover {
  background: var(--accent);
  color: var(--foreground);
  text-decoration: none;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-2);
  font-size: var(--text-xs);
  font-weight: 500;
  border-radius: 999px;
  background: var(--muted);
  color: var(--muted-foreground);
  border: 1px solid var(--border);
  line-height: 1.4;
}

.badge--archive {
  background: color-mix(in srgb, var(--warm) 10%, transparent);
  color: var(--warm);
  border-color: color-mix(in srgb, var(--warm) 25%, transparent);
}

/* =============================================================================
   Post page
   ============================================================================= */
.post-header {
  margin-bottom: var(--space-12);
  padding-bottom: var(--space-8);
  border-bottom: 1px solid var(--border);
}

.post-header__meta {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--muted-foreground);
  margin-bottom: var(--space-4);
}

.post-header h1 {
  font-size: var(--text-4xl);
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-4);
}

.post-header__subtitle {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 400;
  color: var(--muted-foreground);
  font-style: italic;
}

.post-footer {
  margin-top: var(--space-16);
  padding-top: var(--space-8);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.post-footer__link {
  color: var(--muted-foreground);
  font-size: var(--text-sm);
}
.post-footer__link strong { color: var(--foreground); display: block; margin-top: 2px; }

/* =============================================================================
   Archive
   ============================================================================= */
.archive-notice {
  padding: var(--space-4) var(--space-6);
  background: color-mix(in srgb, var(--warm) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--warm) 20%, transparent);
  border-radius: var(--radius);
  color: var(--foreground);
  font-size: var(--text-sm);
  margin-bottom: var(--space-10);
}
.archive-notice strong { color: var(--warm); }

.archive-year {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 600;
  margin-top: var(--space-12);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}
.archive-year:first-of-type { margin-top: 0; }

/* =============================================================================
   Utilities
   ============================================================================= */
.text-muted { color: var(--muted-foreground); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }
.mb-4 { margin-bottom: var(--space-4); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
