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

:root {
  --sans: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --serif: 'Instrument Serif', 'Georgia', serif;
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --transition-color: 0.4s ease;
}

[data-theme="dark"] {
  --bg:          #111110;
  --bg-raised:   #191918;
  --bg-hover:    #1e1e1c;
  --border:      #2a2a28;
  --border-hover:#3a3a37;
  --text:        #eeeeec;
  --text-secondary: #b5b3ad;
  --text-muted:  #85837d;
  --accent:      #7352B5;
  --accent-dim:  rgba(115, 82, 181, 0.12);
  --code-bg:     #1a1a19;
}

[data-theme="light"] {
  --bg:          #fafaf8;
  --bg-raised:   #ffffff;
  --bg-hover:    #f0eeeb;
  --border:      #e0ddd7;
  --border-hover:#ccc9c1;
  --text:        #1a1a18;
  --text-secondary: #5a5850;
  --text-muted:  #8a877e;
  --accent:      #6344A3;
  --accent-dim:  rgba(99, 68, 163, 0.1);
  --code-bg:     #f4f3f0;
}

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

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  transition: background var(--transition-color), color var(--transition-color);
  opacity: 0;
  animation: pageIn 0.4s ease 0.05s forwards;
}

body.page-exit {
  animation: pageOut 0.25s ease forwards;
}

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

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

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

a { color: inherit; text-decoration: none; }

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ===== NAV ===== */
nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  transition: background var(--transition-color);
}

nav::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--border);
  transition: background var(--transition-color);
}

nav .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 24px;
}

.nav-logo {
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  transition: color 0.2s ease;
}

.sig {
  color: var(--accent);
  font-size: 0.7rem;
  display: inline-block;
  transition: color var(--transition-color), transform 0.4s var(--ease-out-expo), text-shadow 0.4s ease;
  line-height: 1;
  cursor: default;
}

.sig:hover {
  animation: sigPulse 1.6s ease-in-out infinite;
}

@keyframes sigPulse {
  0%, 100% { text-shadow: 0 0 4px var(--accent); }
  50%      { text-shadow: 0 0 16px var(--accent), 0 0 30px var(--accent); }
}

.nav-logo:hover .sig { animation: sigPulse 1.6s ease-in-out infinite; }

.theme-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  padding: 0;
}

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

.theme-toggle svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

/* ===== BACK LINK ===== */
.back-link {
  font-size: 0.82rem;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  transition: color 0.2s ease;
  margin-top: 48px;
}

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

/* ===== ARTICLE ===== */
.article-header {
  padding: 24px 0 40px;
}

.article-meta {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: color var(--transition-color);
}

.article-meta-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition-color);
}

.article-title {
  font-family: var(--serif);
  font-size: clamp(2rem, 5.5vw, 2.8rem);
  font-weight: 400;
  line-height: 1.12;
  letter-spacing: -0.02em;
  margin-bottom: 20px;
}

.article-subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.7;
  max-width: 520px;
  transition: color var(--transition-color);
}

/* ===== PROSE ===== */
.prose {
  padding-bottom: 80px;
}

.prose h2 {
  font-family: var(--serif);
  font-size: 1.6rem;
  font-weight: 400;
  letter-spacing: -0.01em;
  margin-top: 48px;
  margin-bottom: 16px;
  line-height: 1.2;
}

.prose h3 {
  font-family: var(--serif);
  font-size: 1.25rem;
  font-weight: 400;
  margin-top: 36px;
  margin-bottom: 12px;
  line-height: 1.3;
}

.prose p {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.8;
  margin-bottom: 20px;
  transition: color var(--transition-color);
}

.prose p strong {
  color: var(--text);
  font-weight: 500;
}

.prose p em {
  font-style: italic;
}

.prose a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 3px;
  transition: text-decoration-color 0.2s ease, color 0.2s ease;
}

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

.prose blockquote {
  border-left: 2px solid var(--accent);
  margin: 28px 0;
  padding: 4px 0 4px 20px;
}

.prose blockquote p {
  font-family: var(--serif);
  font-size: 1.05rem;
  font-style: italic;
  color: var(--text);
  line-height: 1.65;
  margin-bottom: 0;
}

.prose code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.78rem;
  background: var(--code-bg);
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 4px;
  transition: background var(--transition-color), color var(--transition-color);
}

.prose pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin: 24px 0;
  overflow-x: auto;
  transition: background var(--transition-color), border-color var(--transition-color);
}

.prose pre code {
  background: none;
  padding: 0;
  color: var(--text-secondary);
  font-size: 0.78rem;
  line-height: 1.7;
}

.prose ul, .prose ol {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.8;
  margin-bottom: 20px;
  padding-left: 24px;
  transition: color var(--transition-color);
}

.prose li {
  margin-bottom: 6px;
}

.prose li strong {
  color: var(--text);
  font-weight: 500;
}

.prose hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin: 40px 0;
  transition: background var(--transition-color);
}

/* ===== FOOTER ===== */
.article-footer {
  border-top: 1px solid var(--border);
  padding: 32px 0;
  transition: border-color var(--transition-color);
}

.article-footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.footer-back {
  font-size: 0.8rem;
  color: var(--text-muted);
  transition: color 0.2s ease;
}

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

/* ===== RESPONSIVE ===== */
@media (max-width: 560px) {
  .back-link { margin-top: 32px; }
  .article-header { padding: 16px 0 28px; }
  .article-title { font-size: 1.8rem; }
  .prose h2 { font-size: 1.35rem; margin-top: 36px; }
  .prose h3 { font-size: 1.1rem; margin-top: 28px; }
}
