:root {
  --color-primary: #667eea;
  --color-primary-dark: #5a67d8;
  --color-secondary: #764ba2;
  --color-accent: #f6ad55;
  --color-bg: #ffffff;
  --color-bg-secondary: #f7fafc;
  --color-text: #2d3748;
  --color-text-light: #718096;
  --color-border: #e2e8f0;
  --color-code-bg: #f7fafc;
  --color-code-text: #2d3748;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Fira Code', 'Courier New', monospace;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 20px rgba(0,0,0,0.15);
  --radius: 0.5rem;
  --max-width: 1200px;
  --article-width: 1100px;
}

.dark {
  --color-bg: #1a202c;
  --color-bg-secondary: #2d3748;
  --color-text: #e2e8f0;
  --color-text-light: #a0aec0;
  --color-border: #4a5568;
  --color-code-bg: #2d3748;
  --color-code-text: #e2e8f0;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--color-primary);
  color: white;
  padding: 8px;
  text-decoration: none;
  z-index: 100;
}

.skip-link:focus {
  top: 0;
}

.site-header {
  position: sticky;
  top: 0;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  z-index: 50;
  backdrop-filter: blur(10px);
  background-color: rgba(var(--color-bg), 0.9);
}

.site-nav {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1rem;
}

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

.site-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-primary);
  text-decoration: none;
}

.nav-menu {
  display: flex;
  list-style: none;
  gap: 2rem;
}

.nav-menu a {
  color: var(--color-text);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

.nav-menu a:hover {
  color: var(--color-primary);
}

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

.search-toggle,
.theme-toggle,
.menu-toggle {
  background: none;
  border: none;
  color: var(--color-text);
  cursor: pointer;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease;
}

.search-toggle:hover,
.theme-toggle:hover,
.menu-toggle:hover {
  color: var(--color-primary);
}

.menu-toggle {
  display: none;
}

.sun-icon,
.moon-icon {
  transition: opacity 0.3s ease;
}

.dark .sun-icon {
  display: none;
}

.dark .moon-icon {
  display: block;
}

.moon-icon {
  display: none;
}

.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--color-primary), var(--color-secondary));
  z-index: 100;
  transition: width 0.2s ease;
}

.search-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(5px);
  display: none;
  z-index: 90;
}

.search-overlay.active {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10vh;
}

.search-container {
  background: var(--color-bg);
  border-radius: var(--radius);
  padding: 2rem;
  width: 90%;
  max-width: 600px;
  box-shadow: var(--shadow-lg);
  position: relative;
}

.search-input {
  width: 100%;
  padding: 1rem;
  font-size: 1.125rem;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg);
  color: var(--color-text);
  margin-bottom: 1rem;
}

.search-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--color-text-light);
  cursor: pointer;
}

.search-results {
  max-height: 400px;
  overflow-y: auto;
}

.search-result {
  padding: 1rem;
  border-bottom: 1px solid var(--color-border);
  text-decoration: none;
  display: block;
  color: var(--color-text);
  transition: background-color 0.2s ease;
}

.search-result:hover {
  background: var(--color-bg-secondary);
}

.search-result-title {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.search-result-excerpt {
  color: var(--color-text-light);
  font-size: 0.875rem;
}

.main-content {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1rem;
  min-height: calc(100vh - 200px);
}

.post {
  max-width: var(--article-width);
  margin: 0 auto;
  position: relative;
}

.post-header {
  margin-bottom: 2rem;
}

.post-title {
  font-size: 2.5rem;
  line-height: 1.2;
  margin-bottom: 1rem;
  color: var(--color-text);
}

.post-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--color-text-light);
  font-size: 0.875rem;
}

.post-tags {
  display: flex;
  gap: 0.5rem;
}

.tag {
  background: var(--color-primary);
  color: white;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 500;
  transition: background-color 0.2s ease;
}

.tag:hover {
  background: var(--color-primary-dark);
}

.post-description {
  font-size: 1.25rem;
  color: var(--color-text-light);
  margin-top: 1rem;
}

/* Left Sidebar */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  width: 300px;
  background: var(--color-bg);
  border-right: 1px solid var(--color-border);
  z-index: 40;
  transform: translateX(0);
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  padding-top: 80px;
}

.sidebar.closed {
  width: 50px;
  background: var(--color-bg-secondary);
  border-right: 3px solid var(--color-primary);
  cursor: pointer; /* Indicate the bar is clickable */
}

.sidebar::before {
  content: '☰';
  position: absolute;
  font-size: 20px;
  color: var(--color-primary);
  pointer-events: none;
  transition: all 0.3s ease;
  z-index: 45; /* Above content */
}

/* When closed - center the icon in the thin bar */
.sidebar.closed::before {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* When open - position in top-right corner of sidebar */
.sidebar:not(.closed)::before {
  top: 100px; /* Below header area */
  right: 15px;
  cursor: pointer;
  background: var(--color-primary);
  color: white;
  padding: 10px;
  border-radius: 6px;
  border: 2px solid var(--color-primary);
  box-shadow: var(--shadow-md);
  font-weight: bold;
}

.sidebar:not(.closed):hover::before {
  background: var(--color-primary-dark);
  border-color: var(--color-primary-dark);
  transform: scale(1.05);
}

.sidebar.closed:hover {
  background: var(--color-primary-light);
  border-right: 3px solid var(--color-primary-dark);
}

.sidebar.closed .sidebar-content {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.sidebar-toggle {
  display: none; /* Hide toggle button, use bar click instead */
}

/* Pulse animation to make toggle more noticeable */
@keyframes pulse {
  0% {
    box-shadow: var(--shadow-lg), 0 0 0 0 rgba(102, 126, 234, 0.7);
  }
  70% {
    box-shadow: var(--shadow-lg), 0 0 0 10px rgba(102, 126, 234, 0);
  }
  100% {
    box-shadow: var(--shadow-lg), 0 0 0 0 rgba(102, 126, 234, 0);
  }
}


.sidebar-content {
  padding: 2rem;
  overflow-y: visible;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.sidebar-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--color-text);
  border-bottom: 2px solid var(--color-primary);
  padding-bottom: 0.5rem;
}

/* TOC Section */
.toc-section {
  flex-shrink: 0;
}

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

.toc-list li {
  margin-bottom: 0.75rem;
}

.toc-list a {
  color: var(--color-text-light);
  text-decoration: none;
  font-size: 0.875rem;
  transition: all 0.2s ease;
  display: block;
  padding: 0.5rem 0;
  border-left: 3px solid transparent;
  padding-left: 1rem;
  margin-left: -1rem;
  line-height: 1.4;
}

.toc-list a:hover {
  color: var(--color-primary);
  border-left-color: var(--color-primary);
  background: var(--color-bg-secondary);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.toc-list a.active {
  color: var(--color-primary);
  font-weight: 600;
  border-left-color: var(--color-primary);
  background: var(--color-bg-secondary);
}

/* Suggestions Section */
.suggestions-section {
  flex-shrink: 0;
  margin-top: 1rem;
}

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

.suggestion-item {
  margin-bottom: 1.5rem;
}

.suggestion-link {
  display: block;
  text-decoration: none;
  color: var(--color-text);
  padding: 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  transition: all 0.2s ease;
  background: var(--color-bg-secondary);
}

.suggestion-link:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-sm);
  transform: translateY(-2px);
}

.suggestion-title {
  display: block;
  font-weight: 600;
  font-size: 0.875rem;
  line-height: 1.3;
  margin-bottom: 0.5rem;
  color: var(--color-text);
}

.suggestion-meta {
  display: block;
  font-size: 0.75rem;
  color: var(--color-text-light);
  margin-bottom: 0.5rem;
}

.suggestion-tags {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.suggestion-tag {
  font-size: 0.625rem;
  background: var(--color-primary);
  color: white;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-weight: 500;
}

/* Page Styles */
.page {
  max-width: var(--article-width);
  margin: 0 auto;
  position: relative;
}

.page-header {
  margin-bottom: 2rem;
  text-align: center;
}

.page-title {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--color-text);
}

.page-content {
  font-size: 1.125rem;
  line-height: 1.8;
}

.page-content h1,
.page-content h2,
.page-content h3,
.page-content h4,
.page-content h5,
.page-content h6 {
  margin-top: 2rem;
  margin-bottom: 1rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--color-text);
}

.page-content h1 { font-size: 2rem; }
.page-content h2 { font-size: 1.75rem; }
.page-content h3 { font-size: 1.5rem; }
.page-content h4 { font-size: 1.25rem; }
.page-content h5 { font-size: 1.125rem; }
.page-content h6 { font-size: 1rem; }

.page-content p {
  margin-bottom: 1.5rem;
}

.page-content a {
  color: var(--color-text);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.page-content a:hover {
  color: var(--color-text-light);
}

.page-content ul,
.page-content ol {
  margin-bottom: 1.5rem;
  padding-left: 2rem;
}

.page-content li {
  margin-bottom: 0.5rem;
}

.page-content strong {
  font-weight: 600;
  color: var(--color-text);
}

/* Adjust main content for sidebar - only when sidebar exists */
@media (min-width: 1024px) {
  .sidebar ~ .main-content {
    margin-left: 300px; /* Account for open sidebar by default */
    transition: margin-left 0.3s ease;
  }
  
  .sidebar.closed ~ .main-content {
    margin-left: 50px; /* Account for thin bar when closed */
  }
}

.post-content {
  font-size: 1.125rem;
  line-height: 1.8;
}

.post-content h1,
.post-content h2,
.post-content h3,
.post-content h4,
.post-content h5,
.post-content h6 {
  margin-top: 2rem;
  margin-bottom: 1rem;
  font-weight: 600;
  line-height: 1.3;
}

.post-content h1 { font-size: 2rem; }
.post-content h2 { font-size: 1.75rem; }
.post-content h3 { font-size: 1.5rem; }
.post-content h4 { font-size: 1.25rem; }
.post-content h5 { font-size: 1.125rem; }
.post-content h6 { font-size: 1rem; }

.post-content p {
  margin-bottom: 1.5rem;
}

.post-content a {
  color: var(--color-primary);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.post-content a:hover {
  color: var(--color-primary-dark);
}

.post-content ul,
.post-content ol {
  margin-bottom: 1.5rem;
  padding-left: 2rem;
}

.post-content li {
  margin-bottom: 0.5rem;
}

.post-content pre {
  background: var(--color-code-bg);
  padding: 1.5rem;
  border-radius: var(--radius);
  overflow-x: auto;
  margin-bottom: 1.5rem;
  border: 1px solid var(--color-border);
}

.post-content code {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  background: var(--color-code-bg);
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  color: var(--color-code-text);
}

.post-content pre code {
  background: none;
  padding: 0;
}

.post-content blockquote {
  border-left: 4px solid var(--color-primary);
  padding-left: 1.5rem;
  margin: 2rem 0;
  font-style: italic;
  color: var(--color-text-light);
}

/* Cover image styling */
.post-image {
  width: 100%;
  margin: 2rem 0;
  overflow: hidden;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.post-image picture {
  display: block;
  width: 100%;
}

.post-image img {
  width: 100%;
  height: auto;
  display: block;
  object-fit: cover;
  aspect-ratio: 16/9;
}

/* Responsive cover image adjustments */
@media (max-width: 480px) {
  .post-image {
    margin: 1rem 0;
    border-radius: calc(var(--radius) / 2);
  }
  
  .post-image img {
    aspect-ratio: 4/3;
  }
}

@media (min-width: 768px) {
  .post-image {
    margin: 3rem 0;
  }
}

@media (min-width: 1024px) {
  .post-image {
    max-width: 1200px;
    margin: 3rem auto;
  }
}

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

.post-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 2rem 0;
}

.post-content th,
.post-content td {
  padding: 0.75rem;
  border: 1px solid var(--color-border);
  text-align: left;
}

.post-content th {
  background: var(--color-bg-secondary);
  font-weight: 600;
}

.post-navigation {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--color-border);
}

.prev-post,
.next-post {
  text-decoration: none;
  color: var(--color-text);
  padding: 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  transition: all 0.2s ease;
}

.prev-post:hover,
.next-post:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
}

.next-post {
  text-align: right;
}

.nav-label {
  display: block;
  font-size: 0.875rem;
  color: var(--color-text-light);
  margin-bottom: 0.5rem;
}

.nav-title {
  display: block;
  font-weight: 600;
}

.site-footer {
  background: var(--color-bg-secondary);
  border-top: 1px solid var(--color-border);
  margin-top: 4rem;
}

.footer-container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 2rem;
}

.footer-content p {
  color: var(--color-text-light);
  font-size: 0.875rem;
}

.footer-content a {
  color: var(--color-primary);
  text-decoration: none;
}

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

.footer-links a {
  color: var(--color-text-light);
  text-decoration: none;
  font-size: 0.875rem;
  transition: color 0.2s ease;
}

.footer-links a:hover {
  color: var(--color-primary);
}

@media (max-width: 768px) {
  .nav-menu {
    position: fixed;
    top: 60px;
    left: -100%;
    width: 100%;
    height: calc(100vh - 60px);
    background: var(--color-bg);
    flex-direction: column;
    padding: 2rem;
    transition: left 0.3s ease;
    border-top: 1px solid var(--color-border);
  }

  .nav-menu.active {
    left: 0;
  }

  .menu-toggle {
    display: flex;
  }

  .post-title {
    font-size: 2rem;
  }

  .sidebar {
    width: 280px;
    padding-top: 70px;
  }
  
  .sidebar-toggle {
    left: 0.5rem;
    width: 44px;
    height: 44px;
  }
  
  .sidebar-content {
    padding: 1.5rem;
  }
  
  /* On mobile, always show thin bar, closed by default */
  .sidebar {
    width: 50px; /* Default to closed on mobile */
  }

  .sidebar:not(.closed) {
    width: 280px; /* Full width when open on mobile */
  }

  .main-content {
    margin-left: 50px !important; /* Always account for thin bar */
  }

  .post-navigation {
    grid-template-columns: 1fr;
  }

  .footer-container {
    flex-direction: column;
    text-align: center;
  }
}