/* ============================================================
   TOKENS
   ============================================================ */
:root {
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --font-serif: 'Source Serif 4', Georgia, serif;
  --font-mono: 'Fira Mono', 'SFMono-Regular', Consolas, monospace;
  --sidebar-w: 220px;
  --bg:             #ffffff;
  --bg-soft:        #f8f8f8;
  --border:         #e5e5e5;
  --text:           #2d2d2d;
  --text-muted:     #717171;
  --text-light:     #999999;
  --link:           #4078c0;
  --link-hover:     #2a5ba0;
  --heading:        #1a1a1a;
  --nav-hover-bg:   #f0f0f0;
  --tag-bg:         #eef2f8;
  --tag-color:      #4078c0;
  --code-bg:        #f4f4f4;
  --sidebar-bg:     #f8f8f8;
  --sidebar-border: #e5e5e5;
  --accent:         #4078c0;
}
[data-theme="dark"] {
  --bg:             #1e1e1e;
  --bg-soft:        #252525;
  --border:         #3a3a3a;
  --text:           #c9c9c9;
  --text-muted:     #888888;
  --text-light:     #666666;
  --link:           #7eb6f6;
  --link-hover:     #a8cff8;
  --heading:        #e8e8e8;
  --nav-hover-bg:   #2d2d2d;
  --tag-bg:         #2a3447;
  --tag-color:      #7eb6f6;
  --code-bg:        #2a2a2a;
  --sidebar-bg:     #252525;
  --sidebar-border: #3a3a3a;
  --accent:         #7eb6f6;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s, color 0.2s;
}
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; }
img { max-width: 100%; display: block; }
.layout { display: flex; min-height: 100vh; }

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 50;
  transition: background 0.2s, border-color 0.2s;
}
.sidebar-inner {
  padding: 28px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  min-height: 100%;
}
.brand-link {
  display: block;
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 500;
  color: var(--heading) !important;
  text-decoration: none !important;
  margin-bottom: 4px;
  cursor: pointer;
}
.brand-link:hover { color: var(--accent) !important; }
.brand-sub { font-size: 0.75rem; color: var(--text-muted); line-height: 1.4; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: block;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 0.88rem;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--nav-hover-bg); color: var(--heading); text-decoration: none; }
.nav-item.active { color: var(--heading); font-weight: 500; }
.group-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-light);
  margin-bottom: 8px;
}
.sidebar-link {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 3px 0;
  text-decoration: none;
}
.sidebar-link:hover { color: var(--link); text-decoration: none; }
.sidebar-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.theme-btn, .lang-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 12px;
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: border-color 0.2s, color 0.2s;
  width: 100%;
  font-family: var(--font-sans);
}
.theme-btn:hover, .lang-btn:hover { border-color: var(--accent); color: var(--text); }

/* MOBILE HEADER */
.mobile-header {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--sidebar-border);
  z-index: 200;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}
.mobile-brand { font-family: var(--font-mono); font-size: 0.95rem; }
.mobile-actions { display: flex; gap: 6px; align-items: center; }
.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 0.85rem;
  cursor: pointer;
  line-height: 1;
  color: var(--text-muted);
}
.icon-btn:hover { border-color: var(--accent); }

/* MOBILE MENU - hidden by default, shown with .open class */
.mobile-menu {
  display: none;
  position: fixed;
  top: 52px; left: 0; right: 0;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  z-index: 190;
  padding: 10px 12px;
  flex-direction: column;
  gap: 2px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.mobile-menu.open { display: flex; }

/* CONTENT */
.content {
  margin-left: var(--sidebar-w);
  flex: 1;
  max-width: 760px;
  padding: 48px 48px 80px;
}

/* PAGES */
.page { display: none; }
.page.active { display: block; animation: fadeIn 0.2s ease both; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* INTRO */
.intro {
  margin-bottom: 44px;
  padding-bottom: 36px;
  border-bottom: 1px solid var(--border);
}
.intro-inner {
  display: flex;
  align-items: flex-start;
  gap: 32px;
}
.intro-text-block { flex: 1; }
.intro-text-block h1 {
  font-family: var(--font-serif);
  font-size: 1.9rem;
  font-weight: 400;
  color: var(--heading);
  margin-bottom: 14px;
}
.intro-text-block p {
  font-size: 1rem;
  color: var(--text);
  margin-bottom: 12px;
  max-width: 520px;
}
.intro-text-block p:last-child { margin-bottom: 0; }
.intro-photo-wrap { flex-shrink: 0; }
.intro-photo {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  border: 3px solid var(--border);
  object-fit: cover;
}

/* HOME SECTIONS */
.home-section {
  margin-bottom: 44px;
  padding-bottom: 36px;
  border-bottom: 1px solid var(--border);
}
.home-section:last-child { border-bottom: none; margin-bottom: 0; }
.home-section h2 {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  font-weight: 400;
  color: var(--heading);
  margin-bottom: 4px;
}
.section-sub { font-size: 0.88rem; color: var(--text-muted); margin-bottom: 16px; }

/* POST LIST */
.post-list { list-style: none; margin-bottom: 14px; }
.post-list li {
  display: flex;
  gap: 16px;
  align-items: baseline;
  padding: 5px 0;
  border-bottom: 1px dashed var(--border);
}
.post-list li:last-child { border-bottom: none; }
.post-date {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-light);
  white-space: nowrap;
  flex-shrink: 0;
}
.post-link {
  font-size: 0.93rem;
  color: var(--link);
  cursor: pointer;
  text-decoration: none;
}
.post-link:hover { text-decoration: underline; color: var(--link-hover); }
.text-link { font-size: 0.87rem; color: var(--link); cursor: pointer; text-decoration: none; }
.text-link:hover { text-decoration: underline; }

/* PAGE HEADINGS */
.page > h1 {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 400;
  color: var(--heading);
  margin-bottom: 8px;
}
.page-desc {
  font-size: 0.92rem;
  color: var(--text-muted);
  margin-bottom: 28px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 20px;
}

/* PROJECTS */
.project-year-group { margin-bottom: 32px; }
.project-year {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.project-item { padding: 12px 0; border-bottom: 1px dashed var(--border); }
.project-item:last-child { border-bottom: none; }
.project-name { font-size: 0.95rem; font-weight: 500; color: var(--heading); margin-bottom: 3px; }
.project-desc { font-size: 0.87rem; color: var(--text-muted); margin-bottom: 7px; }
.project-links { display: flex; gap: 12px; }
.project-links a { font-size: 0.8rem; color: var(--link); font-family: var(--font-mono); text-decoration: none; }
.project-links a:hover { text-decoration: underline; }

/* ABOUT */
.about-layout { display: flex; gap: 32px; align-items: flex-start; margin-top: 8px; }
.about-photo { width: 160px; height: 160px; border-radius: 50%; border: 3px solid var(--border); flex-shrink: 0; }

/* PROSE */
.prose h2 { font-family: var(--font-serif); font-size: 1.3rem; font-weight: 400; color: var(--heading); margin: 32px 0 12px; }
.prose p { font-size: 1rem; color: var(--text); margin-bottom: 18px; line-height: 1.8; }
.prose ul, .prose ol { padding-left: 24px; margin-bottom: 18px; }
.prose li { font-size: 1rem; color: var(--text); margin-bottom: 6px; line-height: 1.7; }
.prose a { color: var(--link); }
.prose a:hover { color: var(--link-hover); }
.prose strong { color: var(--heading); }
.prose blockquote { border-left: 3px solid var(--accent); margin: 24px 0; padding: 8px 20px; font-style: italic; color: var(--text-muted); }
.prose code { font-family: var(--font-mono); font-size: 0.85em; background: var(--code-bg); padding: 2px 6px; border-radius: 3px; color: var(--text); }
.prose pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 4px; padding: 16px; overflow-x: auto; margin: 20px 0; }
.prose pre code { background: none; padding: 0; font-size: 0.88rem; }
.prose hr { border: none; border-top: 1px solid var(--border); margin: 32px 0; }
.article-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; font-family: var(--font-mono); font-size: 0.78rem; color: var(--text-light); flex-wrap: wrap; }
.tag { background: var(--tag-bg); color: var(--tag-color); padding: 2px 8px; border-radius: 3px; }
.article-h1 { font-family: var(--font-serif); font-size: 1.8rem; font-weight: 400; color: var(--heading); margin-bottom: 28px; line-height: 1.3; border-bottom: 1px solid var(--border); padding-bottom: 20px; }
.back-link { display: inline-block; font-size: 0.85rem; color: var(--text-muted); cursor: pointer; margin-bottom: 28px; text-decoration: none; font-family: var(--font-mono); }
.back-link:hover { color: var(--link); text-decoration: none; }

/* RESPONSIVE */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .mobile-header { display: flex; }
  .content { margin-left: 0; padding: 70px 20px 60px; }
  .intro-inner { flex-direction: column-reverse; align-items: center; gap: 20px; }
  .intro-photo { width: 100px; height: 100px; }
  .intro-text-block h1 { font-size: 1.6rem; }
  .about-layout { flex-direction: column; align-items: center; }
  .about-photo { width: 120px; height: 120px; }
}
@media (max-width: 480px) {
  .post-list li { flex-direction: column; gap: 2px; }
  .post-date { font-size: 0.72rem; }
}

/* ── Loading spinner ──────────────────────────────────────────── */
.post-loading {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 48px 0;
}
.loading-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.3;
  animation: pulse 1.2s ease-in-out infinite;
}
.loading-dot:nth-child(2) { animation-delay: 0.2s; }
.loading-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse {
  0%, 100% { opacity: 0.2; transform: scale(0.8); }
  50%       { opacity: 1;   transform: scale(1);   }
}

/* ── Post error box ───────────────────────────────────────────── */
.post-error {
  border: 1px solid var(--border);
  border-left: 4px solid #c0392b;
  border-radius: 4px;
  padding: 20px 24px;
  background: var(--bg-soft);
  margin-top: 8px;
}
.post-error p { color: var(--text); margin: 0; line-height: 1.7; }
.post-error code {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  background: var(--code-bg);
  padding: 3px 7px;
  border-radius: 3px;
  display: inline-block;
  margin-top: 4px;
  word-break: break-all;
}
.post-error--warn { border-left-color: #e67e22; }
