/* ============================================
   CSS Custom Properties (light/dark themes)
   ============================================ */
:root,
[data-theme="light"] {
  --bg:          #ffffff;
  --bg-secondary: #f7f7f8;
  --border:      #e5e7eb;
  --text:        #1a1a1a;
  --text-muted:  #6b7280;
  --accent:      #2563eb;
  --accent-hover:#1d4ed8;
  --header-bg:   #ffffffee;
  --code-bg:     #f3f4f6;
  --code-text:   #1f2937;
  --shadow:      0 1px 3px rgba(0,0,0,0.08);
}

[data-theme="dark"] {
  --bg:          #0f1117;
  --bg-secondary: #1a1d27;
  --border:      #2d3748;
  --text:        #e2e8f0;
  --text-muted:  #94a3b8;
  --accent:      #60a5fa;
  --accent-hover:#93c5fd;
  --header-bg:   #0f1117ee;
  --code-bg:     #1e2433;
  --code-text:   #e2e8f0;
  --shadow:      0 1px 3px rgba(0,0,0,0.4);
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  transition: background 0.2s, color 0.2s;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

img { max-width: 100%; height: auto; display: block; }

/* ============================================
   Header / Nav
   ============================================ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--header-bg);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 3.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
  text-decoration: none;
}
.site-title:hover { color: var(--accent); text-decoration: none; }

.site-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.site-nav a {
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
}
.site-nav a:hover { color: var(--text); background: var(--bg-secondary); text-decoration: none; }
.site-nav a.active { color: var(--text); font-weight: 600; }

.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}
.theme-toggle:hover { color: var(--text); background: var(--bg-secondary); }

/* Mobile nav toggle */
.nav-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.4rem;
}
.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.2s;
}

@media (max-width: 600px) {
  .nav-toggle { display: flex; }
  .site-nav {
    display: none;
    position: absolute;
    top: 3.5rem;
    left: 0; right: 0;
    flex-direction: column;
    align-items: stretch;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 1rem 1rem;
    gap: 0;
  }
  .site-nav.open { display: flex; }
  .site-nav a { padding: 0.6rem 0.5rem; }
  .theme-toggle { align-self: flex-start; padding: 0.6rem 0.5rem; }
}

/* ============================================
   Main Content
   ============================================ */
.main-content {
  max-width: 860px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}

/* ============================================
   Bio Section (Home)
   ============================================ */
.bio-section {
  margin-bottom: 3.5rem;
  padding-bottom: 3rem;
  border-bottom: 1px solid var(--border);
}

.bio-inner {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
}

.bio-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid var(--border);
}

.bio-name {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 0.2rem;
}

.bio-tagline {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
  font-weight: 500;
}

.bio-blurb {
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.65;
  margin-bottom: 1rem;
}

.bio-links {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.bio-links a {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: color 0.15s, border-color 0.15s;
}
.bio-links a:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; }

@media (max-width: 500px) {
  .bio-inner { flex-direction: column; gap: 1.25rem; }
  .bio-avatar { width: 72px; height: 72px; }
}

/* ============================================
   Category Sections (Home)
   ============================================ */
.category-section {
  margin-bottom: 2.75rem;
}

.category-header {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.category-title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text);
}

.category-count {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.category-more {
  margin-left: auto;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.category-more:hover { text-decoration: underline; }

.post-list {
  list-style: none;
}

.post-item {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.post-item:last-child { border-bottom: none; }

.post-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  min-width: 130px;
}

.post-meta time {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.post-subcategory {
  font-size: 0.7rem;
  color: var(--text-muted);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  white-space: nowrap;
}

.post-title-link {
  font-size: 0.95rem;
  color: var(--text);
  text-decoration: none;
  line-height: 1.4;
  transition: color 0.15s;
}
.post-title-link:hover { color: var(--accent); text-decoration: none; }

@media (max-width: 500px) {
  .post-item { flex-direction: column; gap: 0.2rem; }
  .post-meta { min-width: unset; }
}

/* ============================================
   Post / Page
   ============================================ */
.post, .page {
  max-width: 720px;
  margin: 0 auto;
}

.post-header, .page-header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.post-breadcrumb {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.post-breadcrumb a { color: var(--text-muted); }
.post-breadcrumb a:hover { color: var(--accent); text-decoration: none; }
.breadcrumb-sep { opacity: 0.5; }

.post-title, .page-title {
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.25;
  margin-bottom: 0.75rem;
  color: var(--text);
}

.post-meta time {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.category-post-count {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* ============================================
   Post Body (markdown content)
   ============================================ */
.post-body {
  font-size: 1rem;
  line-height: 1.8;
}

.post-body h1,
.post-body h2,
.post-body h3,
.post-body h4,
.post-body h5 {
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: 2.25rem;
  margin-bottom: 0.75rem;
  color: var(--text);
  line-height: 1.3;
}
.post-body h1 { font-size: 1.6rem; }
.post-body h2 { font-size: 1.3rem; border-bottom: 1px solid var(--border); padding-bottom: 0.4rem; }
.post-body h3 { font-size: 1.1rem; }
.post-body h4 { font-size: 1rem; }

.post-body p { margin-bottom: 1.25rem; }

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

.post-body ul, .post-body ol {
  margin: 0 0 1.25rem 1.5rem;
}
.post-body li { margin-bottom: 0.3rem; }

.post-body blockquote {
  border-left: 3px solid var(--accent);
  margin: 1.5rem 0;
  padding: 0.85rem 1.25rem;
  background: var(--bg-secondary);
  border-radius: 0 6px 6px 0;
  color: var(--text-muted);
  font-style: normal;
}

.post-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

.post-body table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}
.post-body th, .post-body td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  text-align: left;
}
.post-body th {
  background: var(--bg-secondary);
  font-weight: 600;
}

/* Images in posts */
.post-body img {
  margin: 1.5rem auto;
  border-radius: 6px;
  box-shadow: var(--shadow);
  cursor: zoom-in;
}

.post-body .img-popup { display: block; width: fit-content; margin: 1.5rem auto; }

/* Flexible image sizing via markdown attributes */
.post-body img[width] { width: attr(width px); max-width: 100%; height: auto; }

/* ============================================
   Code Blocks
   ============================================ */
code {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.85em;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  border: 1px solid var(--border);
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  overflow-x: auto;
  margin: 1.5rem 0;
  line-height: 1.6;
}

pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.875rem;
}

/* Rouge line numbers */
.highlight .rouge-table {
  margin: 0;
  border: none;
}
.highlight .rouge-table td { border: none; padding: 0; }
.highlight .rouge-gutter { width: 2.5rem; padding-right: 1rem; color: var(--text-muted); user-select: none; }
.highlight .rouge-code { padding-left: 0.5rem; }
.highlight pre { margin: 0; border: none; padding: 0; background: none; }

/* ============================================
   Archives
   ============================================ */
.archive-year { margin-bottom: 2.5rem; }

.archive-year-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.archive-list { list-style: none; }

.archive-item {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.archive-item:last-child { border-bottom: none; }

.archive-item time {
  font-size: 0.8rem;
  color: var(--text-muted);
  min-width: 60px;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.archive-item a {
  color: var(--text);
  text-decoration: none;
  flex: 1;
}
.archive-item a:hover { color: var(--accent); text-decoration: none; }

.archive-cat {
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  flex-shrink: 0;
}

/* ============================================
   Post Navigation
   ============================================ */
.post-footer { margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--border); }

.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.post-nav-prev, .post-nav-next {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
  color: var(--text);
}
.post-nav-prev:hover, .post-nav-next:hover {
  border-color: var(--accent);
  background: var(--bg-secondary);
  text-decoration: none;
  color: var(--text);
}
.post-nav-next { text-align: right; grid-column: 2; }
.post-nav-prev:only-child { grid-column: 1; }

.nav-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.post-nav-next .nav-label { justify-content: flex-end; }

.nav-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--accent);
  line-height: 1.3;
}

@media (max-width: 500px) {
  .post-nav { grid-template-columns: 1fr; }
  .post-nav-next { grid-column: 1; text-align: left; }
  .post-nav-next .nav-label { justify-content: flex-start; }
}

/* ============================================
   Footer
   ============================================ */
.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 4rem;
  padding: 2rem 1.5rem;
}

.footer-inner {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.footer-links {
  display: flex;
  gap: 1rem;
}

.footer-links a {
  color: var(--text-muted);
  font-size: 1.1rem;
  transition: color 0.15s;
  text-decoration: none;
}
.footer-links a:hover { color: var(--accent); text-decoration: none; }

.footer-copy {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ============================================
   Magnific Popup overrides for dark mode
   ============================================ */
[data-theme="dark"] .mfp-bg { background: rgba(0,0,0,0.85); }
[data-theme="dark"] .mfp-arrow:before,
[data-theme="dark"] .mfp-arrow:after { border-top-color: #fff; border-bottom-color: #fff; }
[data-theme="dark"] button.mfp-close { color: #fff; }
