:root {
  --bg-color: #ffffff;
  --text-color: #333333;
  --link-color: #0066cc;
  --header-bg: #f4f4f4;
}

.dark-mode {
  --bg-color: #1a1a1a;
  --text-color: #e0e0e0;
  --link-color: #66b3ff;
  --header-bg: #2d2d2d;
}

html,
body {
  height: 100%;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  line-height: 1.6;
  margin: 0;
  transition: background-color 0.3s, color 0.3s;
}

.container {
  max-width: 1300px;
  /* Increased from 1000px to fit TOC */
  margin: 0 auto;
  padding: 0 20px;
  width: 100%;
  box-sizing: border-box;
}

/* Header */
header {
  background: var(--header-bg);
  padding: 20px 0;
  border-bottom: 1px solid #ddd;
}

.header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  /* Allow wrapping on small screens */
}

.header-profile {
  display: flex;
  align-items: center;
  gap: 15px;
}

.header-info {
  display: flex;
  flex-direction: column;
}

.profile-img {
  width: 150px;
  height: 150px;
  object-fit: cover;
  border-radius: 50%;
}

header h1 {
  margin: 0;
  font-size: 2.2rem;
  /* Even larger */
  line-height: 1.2;
}

header h1 a {
  text-decoration: none;
  color: var(--text-color);
}

/* Search UI */
.search-toggle {
  font-size: 1.1rem;
  margin-right: 5px;
}

.search-container {
  width: 100%;
  padding: 10px 0;
  border-top: 1px solid #eee;
  margin-top: 10px;
}

#search-input {
  width: 100%;
  padding: 10px;
  font-size: 1rem;
  border: 1px solid #ddd;
  border-radius: 5px;
  box-sizing: border-box;
}

#search-results {
  list-style: none;
  padding: 0;
  margin-top: 10px;
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid #eee;
  display: none;
}

#search-results li {
  border-bottom: 1px solid #eee;
}

#search-results a {
  display: block;
  padding: 10px;
  text-decoration: none;
  color: var(--text-color);
}

#search-results a:hover {
  background: #f9f9f9;
}

.dark-mode #search-results a:hover {
  background: #333;
}

/* About Me */
.about-me {
  margin-bottom: 30px;
}

.about-me h2 {
  border-bottom: 2px solid var(--link-color);
  display: inline-block;
  margin-bottom: 20px;
}

.bio h3 {
  margin-top: 20px;
  font-size: 1.2rem;
}

.bio ul {
  padding-left: 20px;
}

/* Social Links */
.social-links {
  margin-top: 5px;
}

.social-links a {
  color: var(--text-color);
  margin-right: 10px;
  font-size: 1.1rem;
  transition: color 0.2s;
}

.social-links a:hover {
  color: var(--link-color);
}

.disabled-link {
  opacity: 0.5;
  cursor: default;
}

header nav {
  margin-left: auto;
  /* Push to the right */
  display: flex;
  align-items: center;
  z-index: 50;
  /* Ensure it's on top */
  position: relative;
}

header nav button {
  margin-left: 10px;
}

/* Buttons */
.nav-btn {
  cursor: pointer;
  padding: 5px 10px;
  background: none;
  border: none;
  /* Removed border */
  color: var(--text-color);
  font-size: 1.2rem;
  /* Larger icons */
  transition: color 0.2s;
}

.nav-btn:hover {
  color: var(--link-color);
}

/* About Me */
.about-me {
  margin-bottom: 150px;
  /* Greatly increased separation */
}

.about-me h2 {
  border-bottom: 2px solid var(--link-color);
  display: inline-block;
  margin-bottom: 25px;
  font-size: 1.8rem;
  /* Larger title */
}

.bio h3 {
  margin-top: 25px;
  font-size: 1.3rem;
  /* Larger subtitles */
  border-left: 4px solid var(--link-color);
  padding-left: 10px;
}

.bio ul {
  padding-left: 20px;
  margin-top: 10px;
}

/* Layout */
.layout-wrapper {
  display: flex;
  gap: 20px;
  /* Reduced gap significantly */
  margin-top: 40px;
  margin-bottom: 40px;
  align-items: flex-start;
  flex: 1 0 auto;
  /* Push footer down */
}

footer {
  flex-shrink: 0;
}

.sidebar {
  flex: 0 0 180px;
  /* Force narrow width */
  width: 180px;
  max-width: 180px;
  position: sticky;
  top: 20px;
  overflow: hidden;
  /* Ensure content doesn't stretch */
}

.content {
  flex: 1;
  width: calc(100% - 200px);
  /* Fallback */
  min-width: 0;
  /* Fix for flex item overflow */
  border-left: 1px solid #eee;
  /* The faint line requested */
  padding-left: 30px;
  /* Slightly more breathing room */
}

/* Sidebar */
.sidebar-section {
  margin-bottom: 20px;
  /* Reduced spacing */
}

.sidebar-section h3 {
  font-size: 1.1rem;
  border-bottom: 2px solid var(--link-color);
  padding-bottom: 5px;
  display: inline-block;
  margin-bottom: 10px;
  /* Reduced spacing */
}

.sidebar-section ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-section li {
  margin-bottom: 2px;
  /* Reduced spacing */
  line-height: 1.4;
  /* Tighter line height */
}

.sidebar-section a {
  color: var(--text-color);
  display: block;
  /* Required for ellipsis */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-section a:hover {
  color: var(--link-color);
}

.sidebar-aboutme h4 {
  margin: 10px 0 5px;
  font-size: 1rem;
  color: var(--link-color);
}

.sidebar-aboutme p {
  font-size: 0.9rem;
  margin: 0 0 10px;
}

.sidebar-aboutme ul {
  margin: 0;
  padding-left: 15px;
  font-size: 0.9rem;
}

.sidebar-aboutme li {
  margin-bottom: 2px;
}

/* Visitor Stats */
.visitor-stats li {
  font-size: 0.9em;
  color: var(--text-color);
  margin-bottom: 2px;
}

/* Nested Categories */
.category-name {
  font-weight: bold;
  display: block;
  margin-bottom: 2px;
  color: var(--text-color);
}

.category-post-list {
  padding-left: 15px !important;
  /* Removed border */
  margin-bottom: 5px !important;
  /* Reduced margin */
  margin-top: 0 !important;
}

.category-post-list li {
  margin-bottom: 0px;
  /* Minimal spacing */
  font-size: 0.95em;
  list-style: none;
  /* Remove default bullets */
}

.category-post-list li::before {
  content: "- ";
  margin-right: 5px;
  color: var(--text-color);
}

/* Common */
a {
  color: var(--link-color);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

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

ul.post-list li {
  margin-bottom: 15px;
  border-bottom: 1px solid #eee;
  padding-bottom: 10px;
}

ul.post-list span {
  color: #888;
  font-size: 0.9em;
}

img {
  max-width: 100%;
  border-radius: 8px;
}

/* Footer */
.site-footer {
  font-size: 0.85rem;
  color: #777;
}

/* Responsive */
@media (max-width: 768px) {
  .layout-wrapper {
    flex-direction: column-reverse;
    gap: 20px;
  }

  /* Default state for Sidebar on mobile (Hidden) */
  .sidebar {
    position: fixed;
    top: 0;
    left: -250px;
    /* Adjusted for narrower width? No keep mobile width standard or match */
    /* Hide off-screen */
    width: 250px;
    height: 100%;
    background-color: var(--bg-color);
    border-right: 1px solid #ddd;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
    padding: 20px;
    z-index: 1000;
    transition: left 0.3s ease;
    overflow-y: auto;
    margin-bottom: 0;
  }

  /* Active state for sidebar (Visible) */
  .sidebar.active {
    left: 0;
  }

  .profile-img {
    width: 70px;
    height: 70px;
  }

  header h1 {
    font-size: 1.3rem;
  }

  .container {
    padding: 0 15px;
  }

  .content {
    width: 100%;
    /* Use full width */
    padding-left: 0;
    /* Remove sidebar padding */
    border-left: none;
    /* Remove border */
  }
}

/* Menu Toggle Button */
.menu-toggle {
  display: none;
  /* Hidden on desktop */
}

@media (max-width: 768px) {
  .menu-toggle {
    display: inline-block;
    /* Visible on mobile */
    margin-right: 5px;
  }
}

/* Search UI Updates */
#search-input {
  background-color: transparent !important;
  color: var(--text-color);
  border: 1px solid #ddd;
}

#search-results {
  background-color: var(--bg-color);
  border: 1px solid #ddd;
}

/* Breadcrumbs */
.breadcrumbs {
  font-size: 0.9rem;
  color: #666;
  margin-bottom: 20px;
}

.breadcrumbs a {
  color: var(--link-color);
  text-decoration: none;
}

.breadcrumbs span {
  color: var(--text-color);
}



/* Nested Categories */
.main-category-list {
  list-style: none !important;
  padding: 0;
  margin: 0;
}

.sub-category-item {
  margin-bottom: 15px;
}

.sub-category-title {
  font-weight: bold;
  font-size: 1.0rem;
  color: var(--text-color);
  display: block;
  margin-bottom: 5px;
  /* Removed border and padding as requested */
}

.sub-category-list {
  list-style: none !important;
  padding-left: 20px;
  margin: 0;
}

.sub-category-list li {
  margin-bottom: 3px;
  font-size: 0.85rem;
}

.sub-category-list li a {
  color: #666;
  text-decoration: none;
  transition: color 0.2s;
}

.sub-category-list li a:hover {
  color: var(--link-color);
}

/* Latest Posts (No Bullets) */
.latest-post-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.latest-post-list li {
  margin-bottom: 2px;
  line-height: 1.4;
  font-size: 0.85rem;
  /* Matched to sub-categories */
}

/* Active Post in Footer List */
.post-list-active {
  font-weight: bold;
  background-color: #f9f9f9;
  padding: 5px;
  border-radius: 4px;
}

.dark-mode .post-list-active {
  background-color: #333;
  /* Dark mode highlight */
  color: #fff;
}

/* Code Blocks */
pre,
code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
}

/* Inline Code (e.g. `humble`) */
p code,
li code {
  background-color: #f1f1f1;
  padding: 2px 5px;
  border-radius: 4px;
  color: #c7254e;
  /* Reddish color for better visibility */
  font-size: 0.9em;
}

.dark-mode p code,
.dark-mode li code {
  background-color: #444;
  color: #ff8c8c;
}

/* Block Code (e.g. ```bash ... ```) */
pre {
  background-color: #f6f8fa;
  padding: 16px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 15px 0;
  line-height: 1.45;
  border: 1px solid #ddd;
}

.dark-mode pre {
  background-color: #1f1f1f;
  border-color: #444;
  color: #e0e0e0;
}

/* Ensure code inside pre doesn't inherit inline styles */
pre code {
  background-color: transparent !important;
  color: inherit !important;
  padding: 0 !important;
  font-size: 0.9rem;
}

/* Category Introduction Box */
.category-intro {
  background-color: #f9f9f9;
  padding: 20px;
  border-radius: 8px;
  border-left: 5px solid var(--link-color);
  margin-bottom: 30px;
  color: #555;
  font-size: 1.0em;
  line-height: 1.7;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.dark-mode .category-intro {
  background-color: #262626;
  color: #bbb;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}


/* Content Header Scroll Offset */
.content h2,
.content h3 {
  scroll-margin-top: 80px;
  /* Prevent header from being hidden behind sticky elements */
}

/* TOC Sidebar */
.toc-sidebar {
  width: 250px;
  flex: 0 0 250px;
  position: sticky;
  top: 80px;
  /* Adjusted for better vertical centering */
  margin-left: 20px;
  font-size: 0.9rem;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  /* Removed border-left from here, moving to container or specific track design */
}

.toc-container h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #999;
  margin-top: 0;
  margin-bottom: 15px;
  padding-bottom: 0;
  border-bottom: none;
  /* Removed underline */
  display: block;
  font-weight: 600;
}

.toc-container ul {
  list-style: none;
  padding: 0;
  margin: 0;
  position: relative;
}

/* Vertical Track Line */
.toc-container ul::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 2px;
  background-color: #eee;
}

.toc-container li {
  margin-bottom: 0;
  /* Removing generic margin */
  position: relative;
}

.toc-container a {
  color: #666;
  /* Softer text color */
  text-decoration: none;
  display: block;
  padding: 3px 0 3px 20px;
  /* indent text */
  transition: all 0.2s ease;
  border-left: 2px solid transparent;
  /* Prepare for active state */
  margin-left: 0;
  /* Align with track */
  font-size: 0.9em;
  line-height: 1.3;
}

.toc-container a:hover {
  color: var(--link-color);
  background-color: transparent;
  /* Clean hover */
}

.toc-container a.active {
  color: var(--link-color);
  font-weight: 600;
  border-left: 2px solid var(--link-color);
  /* The active indicator */
  background-color: #fafafa;
  /* Subtle highlight */
}

.dark-mode .toc-container a.active {
  background-color: #333;
}

/* Nested Headers Indentation */
.toc-h3 a {
  padding-left: 35px;
  /* Deeper indent for H3 */
  font-size: 0.85em;
}

/* Adjust active border for h3 to match the track line? 
   Actually, applying border-left to the 'a' generic works well if padding is handled correctly.
   Let's ensure the border coincides with the track line (left: 0).
*/
.toc-container a {
  /* To make border appear ON the track, we need to position it or move padding */
  /* Let's try overlapping the track */
  margin-left: 0;
}

/* Layout Adjustment for 3-Column */
.layout-wrapper.has-toc .content {
  /* Adjust width when TOC is present */
  width: calc(100% - 180px - 270px);
  /* Sidebar (180) + TOC (250+20 margin) */
  flex: 1;
}

@media (max-width: 1300px) {
  .toc-sidebar {
    display: none !important;
  }

  .layout-wrapper.has-toc .content {
    width: calc(100% - 200px);
    /* Revert to 2-column width */
  }
}