:root {
  --bg: #0f0e0c;
  --bg-elevated: #1a1815;
  --bg-card: #16140f;
  --text: #e8e3d8;
  --text-muted: #8a847a;
  --text-dim: #5a554d;
  --accent: #d4a574;
  --accent-glow: rgba(212, 165, 116, 0.15);
  --border: rgba(232, 227, 216, 0.08);
  --border-hover: rgba(212, 165, 116, 0.3);
  --serif: 'Fraunces', 'Noto Serif SC', Georgia, serif;
  --sans: 'Noto Serif SC', 'Fraunces', sans-serif;
  --mono: 'JetBrains Mono', monospace;
  --max-width: 720px;
  --transition: 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

[data-theme="light"] {
  --bg: #faf7f2;
  --bg-elevated: #f3ede3;
  --bg-card: #ffffff;
  --text: #2a2520;
  --text-muted: #6b6358;
  --text-dim: #a09890;
  --accent: #b8743a;
  --accent-glow: rgba(184, 116, 58, 0.1);
  --border: rgba(42, 37, 32, 0.1);
  --border-hover: rgba(184, 116, 58, 0.3);
}

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

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
  transition: background var(--transition), color var(--transition);
  overflow-x: hidden;
}

/* Grain texture overlay */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Cursor glow */
.cursor-glow {
  position: fixed;
  width: 400px;
  height: 400px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
  transform: translate(-50%, -50%);
  transition: opacity 0.3s;
  opacity: 0;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  background: rgba(250, 247, 242, 0.8);
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

[data-theme="dark"] .site-header {
  background: rgba(15, 14, 12, 0.7);
}

.nav {
  max-width: 960px;
  margin: 0 auto;
  padding: 18px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: -0.02em;
}

.logo-mark {
  color: var(--accent);
  font-size: 1.1rem;
  transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.logo:hover .logo-mark {
  transform: rotate(180deg);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 28px;
}

.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: color var(--transition);
  position: relative;
}

.nav-link::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 0;
  height: 1px;
  background: var(--accent);
  transition: width var(--transition);
}

.nav-link:hover { color: var(--text); }
.nav-link:hover::after { width: 100%; }
.nav-link.active { color: var(--text); }
.nav-link.active::after { width: 100%; }

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--border-hover);
}

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

/* Container */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 32px;
  position: relative;
  z-index: 1;
}

/* Hero */
.hero {
  padding: 100px 0 80px;
  text-align: center;
}

.hero-eyebrow {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--accent);
  letter-spacing: 0.05em;
  margin-bottom: 24px;
  opacity: 0;
  animation: fadeUp 0.8s 0.1s forwards;
}

.hero-title {
  font-family: var(--serif);
  font-size: clamp(2.5rem, 7vw, 4.5rem);
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: -0.03em;
  margin-bottom: 28px;
}

.hero-title .line {
  display: block;
  opacity: 0;
  animation: fadeUp 0.8s 0.3s forwards;
}

.hero-title .line:nth-child(2) {
  animation-delay: 0.5s;
}

.hero-title .italic {
  font-style: italic;
  font-weight: 300;
  color: var(--accent);
}

.hero-desc {
  font-size: 1.1rem;
  color: var(--text-muted);
  max-width: 480px;
  margin: 0 auto;
  opacity: 0;
  animation: fadeUp 0.8s 0.7s forwards;
}

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

/* Posts */
.posts {
  padding-bottom: 80px;
}

.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 40px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.section-title {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.section-count {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-dim);
}

.post-card {
  padding: 32px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}

.post-card::before {
  content: '';
  position: absolute;
  left: -16px;
  top: 50%;
  width: 4px;
  height: 0;
  background: var(--accent);
  border-radius: 2px;
  transform: translateY(-50%);
  transition: height var(--transition);
}

.post-card:hover::before { height: 60%; }

.post-card:hover .post-title { color: var(--accent); }
.post-card:hover .post-read { transform: translateX(8px); }

.post-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}

.post-date {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-dim);
}

.post-tag {
  font-size: 0.75rem;
  color: var(--accent);
  border: 1px solid var(--border-hover);
  padding: 2px 10px;
  border-radius: 20px;
}

.post-title {
  font-family: var(--serif);
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 12px;
  transition: color var(--transition);
}

.post-excerpt {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.7;
  margin-bottom: 16px;
}

.post-read {
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 500;
  display: inline-block;
  transition: transform var(--transition);
}

/* Newsletter */
.newsletter {
  margin: 80px 0;
  padding: 48px;
  background: var(--bg-elevated);
  border-radius: 20px;
  border: 1px solid var(--border);
  text-align: center;
  position: relative;
  overflow: hidden;
}

.newsletter::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -10%;
  width: 120%;
  height: 200%;
  background: radial-gradient(ellipse at center, var(--accent-glow) 0%, transparent 50%);
  pointer-events: none;
}

.newsletter-inner {
  position: relative;
}

.newsletter h3 {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.newsletter p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

.subscribe-form {
  display: flex;
  gap: 8px;
  max-width: 400px;
  margin: 0 auto;
}

.subscribe-form input {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 0.9rem;
  font-family: var(--sans);
  transition: border-color var(--transition);
}

.subscribe-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.subscribe-form button {
  padding: 12px 24px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.subscribe-form button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px var(--accent-glow);
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 32px 0;
  margin-top: 80px;
}

.footer-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.footer-text {
  font-size: 0.85rem;
  color: var(--text-dim);
}

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

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

.footer-links {
  display: flex;
  gap: 24px;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  transition: color var(--transition);
}

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

/* Article page */
.article-layout {
  display: flex;
  gap: 48px;
  max-width: 960px;
  margin: 0 auto;
  padding: 60px 0;
  align-items: flex-start;
}

.article {
  flex: 1;
  min-width: 0;
  max-width: var(--max-width);
}

/* Table of Contents */
.toc {
  position: sticky;
  top: 88px;
  width: 200px;
  flex-shrink: 0;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  padding-left: 16px;
  border-left: 1px solid var(--border);
}

.toc-title {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 16px;
}

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

.toc-item {
  margin-bottom: 8px;
}

.toc-link {
  display: block;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.82rem;
  line-height: 1.4;
  padding: 3px 0;
  border-left: 2px solid transparent;
  padding-left: 12px;
  margin-left: -14px;
  transition: all var(--transition);
}

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

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

.toc-link.level-3 {
  padding-left: 24px;
  margin-left: -14px;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.toc-link.level-3:hover {
  color: var(--accent);
}

.toc-link.level-3.active {
  color: var(--accent);
}

/* TOC toggle for mobile */
.toc-toggle {
  display: none;
}

@media (max-width: 900px) {
  .article-layout {
    flex-direction: column;
    gap: 0;
  }
  .toc {
    position: static;
    width: 100%;
    max-height: none;
    margin-bottom: 32px;
    padding-left: 0;
    border-left: none;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 16px 0;
  }
  .toc-title {
    cursor: pointer;
    margin-bottom: 0;
    position: relative;
  }
  .toc-title::after {
    content: '▸';
    position: absolute;
    right: 0;
    transition: transform var(--transition);
  }
  .toc.expanded .toc-title::after {
    transform: rotate(90deg);
  }
  .toc-list {
    display: none;
    margin-top: 12px;
  }
  .toc.expanded .toc-list {
    display: block;
  }
}

.article-header {
  margin-bottom: 48px;
  text-align: center;
}

.article-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 24px;
}

.article-title {
  font-family: var(--serif);
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 900;
  line-height: 1.2;
  letter-spacing: -0.03em;
  margin-bottom: 16px;
}

.article-subtitle {
  color: var(--text-muted);
  font-size: 1.05rem;
  font-style: italic;
}

.article-body {
  font-size: 1.05rem;
  line-height: 1.85;
}

.article-body h2 {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 700;
  margin: 48px 0 16px;
  letter-spacing: -0.02em;
}

.article-body h3 {
  font-family: var(--serif);
  font-size: 1.2rem;
  font-weight: 600;
  margin: 32px 0 12px;
}

.article-body p {
  margin-bottom: 24px;
  color: var(--text);
}

.article-body p strong {
  font-weight: 700;
  color: var(--text);
}

.article-body blockquote {
  border-left: 3px solid var(--accent);
  padding: 8px 0 8px 24px;
  margin: 32px 0;
  font-style: italic;
  color: var(--text-muted);
  font-family: var(--serif);
  font-size: 1.15rem;
}

.article-body code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--bg-elevated);
  padding: 2px 8px;
  border-radius: 4px;
  color: var(--accent);
}

.article-body pre {
  background: var(--bg-elevated);
  padding: 24px;
  border-radius: 12px;
  overflow-x: auto;
  margin: 32px 0;
  border: 1px solid var(--border);
}

.article-body pre code {
  background: none;
  padding: 0;
  color: var(--text);
  font-size: 0.9rem;
}

.article-body ul, .article-body ol {
  padding-left: 24px;
  margin-bottom: 24px;
}

.article-body li {
  margin-bottom: 8px;
}

.article-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  margin-bottom: 40px;
  transition: color var(--transition);
}

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

/* About page */
.about {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 80px 0;
}

.about h1 {
  font-family: var(--serif);
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 900;
  letter-spacing: -0.03em;
  margin-bottom: 32px;
}

.about p {
  font-size: 1.1rem;
  line-height: 1.85;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.about p strong {
  color: var(--text);
}

/* Responsive */
@media (max-width: 640px) {
  .nav { padding: 16px 20px; }
  .container { padding: 0 20px; }
  .footer-inner { padding: 0 20px; }
  .hero { padding: 60px 0 40px; }
  .newsletter { padding: 32px 20px; margin: 60px 0; }
  .subscribe-form { flex-direction: column; }
  .post-title { font-size: 1.3rem; }
  .nav-links { gap: 16px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
