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

:root {
  --bg: #f8f9fc;
  --surface: #ffffff;
  --text: #1a1a2e;
  --text-secondary: #2d2d44;
  --text-muted: #6b7280;
  --accent: #4361ee;
  --accent-hover: #3651d4;
  --accent-soft: rgba(67, 97, 238, 0.08);
  --border: #e5e7eb;
  --border-light: #f0f1f3;
  --inline-code-bg: #eef0f5;
  --inline-code-text: #2d336b;
  --code-bg: #1e1e2e;
  --code-text: #cdd6f4;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.06), 0 1px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.08);
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --max-width: 720px;
  --logo-brightness: 1;
  --table-hover: #f8f9fc;
  --blockquote-text: #3a3a5c;
  --transition-theme: background 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* ─── Dark Theme ─── */
[data-theme="dark"] {
  --bg: #0d0d1a;
  --surface: #16162a;
  --text: #e2e2f0;
  --text-secondary: #c4c4d8;
  --text-muted: #8888a0;
  --accent: #6b8aff;
  --accent-hover: #89a0ff;
  --accent-soft: rgba(107, 138, 255, 0.12);
  --border: #2a2a44;
  --border-light: #1f1f36;
  --inline-code-bg: #1f1f36;
  --inline-code-text: #c4c4d8;
  --code-bg: #0a0a14;
  --code-text: #cdd6f4;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.3), 0 1px 4px rgba(0,0,0,0.2);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.4);
  --logo-brightness: 1.4;
  --table-hover: #1a1a30;
  --blockquote-text: #b0b0cc;
}

html {
  font-size: 17px;
  background: var(--bg);
  transition: var(--transition-theme);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: var(--transition-theme);
}

/* ─── Layout ─── */
.wrapper {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
}

header {
  padding: 24px 0 0;
}

nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  transition: border-color 0.3s ease;
}

.logo {
  display: flex;
  align-items: center;
  text-decoration: none;
  transition: opacity 0.2s;
}
.logo:hover { opacity: 0.75; }
.logo img {
  display: block;
  filter: brightness(var(--logo-brightness));
  transition: filter 0.3s ease;
}

/* ─── Theme Toggle ─── */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  transition: background 0.2s, color 0.2s, transform 0.2s;
  flex-shrink: 0;
}
.theme-toggle:hover {
  background: var(--accent);
  color: #fff;
  transform: scale(1.05);
}
.theme-toggle:active {
  transform: scale(0.95);
}
.theme-toggle .icon-sun { display: inline; }
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: inline; }

.nav-links {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.nav-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: color 0.2s;
  position: relative;
}
.nav-links a::after {
  content: '';
  position: absolute;
  bottom: -3px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
  transition: width 0.2s ease;
}
.nav-links a:hover { color: var(--accent); }
.nav-links a:hover::after { width: 100%; }

/* ─── Main Content Card ─── */
main {
  margin-top: 32px;
}

article {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 40px;
  transition: var(--transition-theme);
}

/* ─── Post Header ─── */
.post-header { margin-bottom: 28px; }

.post-header h1 {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: -0.03em;
  color: var(--text);
  margin-bottom: 8px;
}

.post-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
}

.post-meta time { color: var(--text-muted); }

.post-meta .dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--border);
}

/* ─── Content Typography ─── */
.content { margin-bottom: 32px; }

.content h2 {
  font-size: 1.45rem;
  font-weight: 700;
  margin: 2rem 0 0.75rem;
  letter-spacing: -0.02em;
  color: var(--text);
  padding-bottom: 6px;
  border-bottom: 2px solid var(--border-light);
  transition: border-color 0.3s ease;
}

.content h3 {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 1.5rem 0 0.6rem;
  color: var(--text);
}

.content p { margin-bottom: 1.1rem; color: var(--text-secondary); }

.content a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s, color 0.2s;
}
.content a:hover {
  color: var(--accent-hover);
  border-bottom-color: var(--accent);
}

.content img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  margin: 1.5rem 0;
  box-shadow: var(--shadow-sm);
}

.content blockquote {
  border-left: 4px solid var(--accent);
  padding: 1rem 1.25rem;
  margin: 1.25rem 0;
  background: var(--accent-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--blockquote-text);
  transition: background 0.3s ease, color 0.3s ease;
}

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

.content code {
  background: var(--inline-code-bg);
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.85em;
  font-weight: 500;
  font-family: "SFMono-Regular", "JetBrains Mono", Consolas, "Liberation Mono", Menlo, monospace;
  color: var(--inline-code-text);
  transition: background 0.3s ease, color 0.3s ease;
}

.content pre {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 1.25rem 1.5rem;
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: 1.25rem 0;
  font-size: 0.82rem;
  line-height: 1.65;
  box-shadow: inset 0 1px 4px rgba(0,0,0,0.3);
  position: relative;
}

.content pre code {
  background: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
  font-weight: 400;
}

.content ul, .content ol {
  margin: 0.5rem 0 1.25rem 1.5rem;
}

.content li { margin-bottom: 0.35rem; color: var(--text-secondary); }

.content li::marker { color: var(--accent); }

.content hr {
  border: none;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--border), transparent);
  margin: 2.5rem 0;
  transition: background 0.3s ease;
}

/* ─── Tables ─── */
.content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.25rem 0;
  font-size: 0.9rem;
}

.content th, .content td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  transition: border-color 0.3s ease;
}

.content th {
  background: var(--accent-soft);
  font-weight: 600;
  color: var(--text);
  transition: background 0.3s ease, color 0.3s ease;
}

.content tr:last-child td { border-bottom: none; }

.content tr:hover td { background: var(--table-hover); }

/* ─── Post Footer Navigation ─── */
.post-footer {
  padding-top: 24px;
  border-top: 1px solid var(--border);
  transition: border-color 0.3s ease;
}

.post-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.post-nav a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  transition: background 0.2s, color 0.2s;
}

.post-nav a:hover {
  background: var(--accent);
  color: #ffffff;
}

.post-nav-spacer { flex: 1; }

.post-nav span {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 8px 16px;
  opacity: 0.5;
}

/* ─── Recent Posts Section ─── */
.recent-posts {
  margin-top: 40px;
  padding-top: 0;
}

.recent-posts h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
  letter-spacing: -0.02em;
}

.recent-posts ul {
  list-style: none;
  padding: 0;
}

.recent-posts li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  margin-bottom: 4px;
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: var(--transition-theme), transform 0.2s;
}

.recent-posts li:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.recent-posts a {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  transition: color 0.2s;
}

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

.recent-posts time {
  color: var(--text-muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.recent-posts > p {
  margin-top: 16px;
  text-align: center;
}

.recent-posts > p a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  transition: background 0.2s, border-color 0.2s;
  display: inline-block;
}

.recent-posts > p a:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* ─── Archive Page ─── */
main h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 24px;
}

.archive-list {
  list-style: none;
  padding: 0;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  transition: var(--transition-theme);
}

.archive-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-light);
  transition: background 0.15s, border-color 0.3s ease;
}

.archive-list li:last-child { border-bottom: none; }

.archive-list li:hover { background: var(--accent-soft); }

.archive-list a {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 1rem;
  transition: color 0.2s;
}

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

.archive-list time {
  color: var(--text-muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

/* ─── Site Footer ─── */
.site-footer {
  margin-top: 48px;
  padding: 24px 0 40px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  border-top: 1px solid var(--border-light);
  transition: border-color 0.3s ease;
}

/* ─── Smooth scrollbar for dark mode ─── */
[data-theme="dark"] ::-webkit-scrollbar-track { background: var(--bg); }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ─── Responsive ─── */
@media (max-width: 640px) {
  html { font-size: 16px; }
  .wrapper { padding: 0 16px; }
  article { padding: 24px 20px; border-radius: var(--radius-md); }
  .post-header h1 { font-size: 1.6rem; }
  .recent-posts li { flex-direction: column; align-items: flex-start; gap: 4px; }
  .archive-list li { flex-direction: column; align-items: flex-start; gap: 4px; }
  .post-nav a { font-size: 0.85rem; padding: 6px 12px; }
}
