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

:root {
  --bg: #f5f5f0;
  --surface: #ffffff;
  --sidebar-bg: #f0ede8;
  --border: #ddd9d0;
  --text: #2c2c2c;
  --text-muted: #6b6b6b;
  --accent: #705dcf;
  --accent-hover: #5a47b0;
  --link: #705dcf;
  --link-hover: #5a47b0;
  --code-bg: #f0ede8;
  --code-text: #d63384;
  --pre-bg: #1e1e2e;
  --pre-text: #cdd6f4;
  --table-header: #ede9ff;
  --table-alt: #f9f8ff;
  --shadow: rgba(0,0,0,0.08);
  --sidebar-width: 280px;
  --header-height: 56px;
}

[data-theme="dark"] {
  --bg: #1e1e2e;
  --surface: #181825;
  --sidebar-bg: #11111b;
  --border: #313244;
  --text: #cdd6f4;
  --text-muted: #a6adc8;
  --accent: #cba6f7;
  --accent-hover: #b4befe;
  --link: #cba6f7;
  --link-hover: #b4befe;
  --code-bg: #313244;
  --code-text: #f38ba8;
  --pre-bg: #11111b;
  --pre-text: #cdd6f4;
  --table-header: #313244;
  --table-alt: #1e1e2e;
  --shadow: rgba(0,0,0,0.3);
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  transition: background 0.2s, color 0.2s;
}

/* ===== Layout ===== */
.layout { display: flex; min-height: 100vh; }

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 100;
  transition: transform 0.25s ease, background 0.2s;
}

.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-logo {
  width: 44px; height: 44px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
.sidebar-title:hover { color: var(--accent); }

.sidebar-nav { padding: 12px 0; flex: 1; }

.nav-category {
  margin-bottom: 2px;
}

.nav-category-btn {
  width: 100%;
  background: none;
  border: none;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: color 0.15s;
}
.nav-category-btn:hover { color: var(--text); }
.nav-category-btn .chevron {
  font-size: 0.65rem;
  transition: transform 0.2s;
  display: inline-block;
}
.nav-category-btn.open .chevron { transform: rotate(90deg); }

.nav-category-posts {
  display: none;
  flex-direction: column;
}
.nav-category-posts.open { display: flex; }

.nav-post-link {
  padding: 6px 16px 6px 28px;
  font-size: 0.875rem;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  border-left: 3px solid transparent;
  display: block;
}
.nav-post-link:hover {
  background: rgba(112,93,207,0.08);
  color: var(--accent);
}
.nav-post-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: rgba(112,93,207,0.1);
  font-weight: 600;
}

/* ===== Main ===== */
.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--header-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
  transition: background 0.2s;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }

.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--text);
  font-size: 1.2rem;
}

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

.theme-toggle {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, color 0.15s;
}
.theme-toggle:hover { background: var(--border); }

.content {
  max-width: 820px;
  margin: 0 auto;
  padding: 40px 32px 80px;
  width: 100%;
}

/* ===== Typography ===== */
.content h1 {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
  color: var(--text);
  line-height: 1.25;
}
.content h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-top: 2.5rem;
  margin-bottom: 0.75rem;
  color: var(--text);
  border-bottom: 2px solid var(--border);
  padding-bottom: 6px;
}
.content h3 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-top: 2rem;
  margin-bottom: 0.6rem;
  color: var(--text);
}
.content h4 {
  font-size: 1rem;
  font-weight: 700;
  margin-top: 1.5rem;
  margin-bottom: 0.4rem;
  color: var(--text);
}
.content p { margin-bottom: 1.1rem; }
.content a { color: var(--link); text-decoration: underline; }
.content a:hover { color: var(--link-hover); }
.content ul, .content ol { margin: 0 0 1.1rem 1.5rem; }
.content li { margin-bottom: 0.4rem; }
.content ul ul, .content ol ol, .content ul ol, .content ol ul {
  margin-top: 0.3rem; margin-bottom: 0.3rem;
}
.content strong { font-weight: 700; }
.content em { font-style: italic; }
.content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* Code */
.content code {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.875em;
  font-family: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
}
.content pre {
  background: var(--pre-bg);
  color: var(--pre-text);
  padding: 20px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 1.2rem 0;
  font-size: 0.875rem;
  line-height: 1.6;
  border: 1px solid rgba(255,255,255,0.05);
}
.content pre code {
  background: none;
  color: inherit;
  padding: 0;
  font-size: inherit;
}

/* Tables */
.content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.2rem 0;
  font-size: 0.9rem;
  overflow: hidden;
  border-radius: 8px;
  box-shadow: 0 1px 4px var(--shadow);
}
.content th {
  background: var(--table-header);
  color: var(--text);
  font-weight: 700;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 2px solid var(--border);
}
.content td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.content tr:last-child td { border-bottom: none; }
.content tr:nth-child(even) td { background: var(--table-alt); }

/* Blockquote */
.content blockquote {
  border-left: 4px solid var(--accent);
  background: rgba(112,93,207,0.05);
  padding: 12px 20px;
  margin: 1.2rem 0;
  border-radius: 0 8px 8px 0;
  color: var(--text-muted);
}

/* Video */
.video-wrapper {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  overflow: hidden;
  border-radius: 10px;
  margin: 1.5rem 0;
  box-shadow: 0 4px 20px var(--shadow);
}
.video-wrapper iframe {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border: none;
}

/* Post Meta */
.post-meta {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.post-tag {
  display: inline-block;
  background: rgba(112,93,207,0.12);
  color: var(--accent);
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 600;
  margin-right: 6px;
}

/* Social links */
.social-links { display: flex; flex-wrap: wrap; gap: 12px; margin: 1.2rem 0; }
.social-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  text-decoration: none;
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 500;
  transition: border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.social-link:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 2px 8px var(--shadow);
  text-decoration: none;
}

/* Overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 90;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.2);
  }
  .sidebar-overlay.open { display: block; }
  .main { margin-left: 0; }
  .hamburger { display: flex; }
  .content { padding: 24px 16px 60px; }
  .content h1 { font-size: 1.6rem; }
}

/* Prism overrides */
.token.keyword { color: #cba6f7; }
.token.string { color: #a6e3a1; }
.token.comment { color: #6c7086; font-style: italic; }
.token.number { color: #fab387; }
.token.function { color: #89b4fa; }
.token.operator { color: #89dceb; }
.token.punctuation { color: #cdd6f4; }
