/* Modern Minimal Blog & Podcast Theme with Sidebars */

/* ========================================
   CSS Custom Properties for Theme Support
   ======================================== */
:root {
  --bg-color: #ffffff;
  --text-primary: #2d3748;
  --text-secondary: #718096;
  --primary-color: #3182ce;
  --border-color: #e2e8f0;
  --card-bg: #f7fafc;
  --hover-bg: #edf2f7;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
  --radius: 8px;
  --radius-lg: 12px;
  --font-system: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  --nav-height: 60px;
  /* Code & table theme vars */
  --code-bg: #f6f8fa;
  --code-text: #24292e;
  --code-border: #e1e4e8;
}

[data-theme="dark"] {
  --bg-color: #1a202c;
  --text-primary: #f7fafc;
  --text-secondary: #a0aec0;
  --primary-color: #63b3ed;
  --border-color: #2d3748;
  --card-bg: #2d3748;
  --hover-bg: #4a5568;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.3);
  --code-bg: #0d1117;
  --code-text: #c9d1d9;
  --code-border: #30363d;
}

/* ========================================
   Reset and Base Styles
   ======================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

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

/* ========================================
   Typography
   ======================================== */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.25rem; }

p {
  margin-bottom: 1rem;
  color: var(--text-primary);
}

a {
  color: var(--primary-color);
  text-decoration: none;
  transition: color 0.2s ease;
}

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

/* ========================================
   Navigation
   ======================================== */
.site-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background-color: var(--bg-color);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 1000;
  height: var(--nav-height);
  backdrop-filter: blur(10px);
}

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

.nav-links {
  display: flex;
  align-items: center;
  gap: 2rem;
}

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

.nav-links a:hover {
  color: var(--primary-color);
  text-decoration: none;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 0.5rem;
  cursor: pointer;
  font-size: 1.2rem;
  transition: all 0.2s ease;
}

.theme-toggle:hover {
  background-color: var(--hover-bg);
}

/* ========================================
   Main Layout
   ======================================== */
.main-content {
  /* Widen overall content area to reduce crowding */
  max-width: 1440px;
  margin: 0 auto;
  padding: 2rem;
  min-height: calc(100vh - var(--nav-height) - 100px);
}

/* Home Page with Sidebar */
.home-wrapper {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  /* Widen home container to reduce crowding */
  max-width: 1440px;
  margin: 0 auto;
}

.home-content {
  min-width: 0;
}

/* Hero Section - Full Width */
.hero {
  text-align: center;
  padding: 3rem 0;
  margin-bottom: 3rem;
  grid-column: 1 / -1; /* Span full width */
}

.hero h1 {
  font-size: 3rem;
  margin-bottom: 1rem;
  background: linear-gradient(135deg, var(--primary-color), #805ad5);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-description {
  font-size: 1.25rem;
  color: var(--text-secondary);
  max-width: 600px;
  margin: 0 auto;
}

/* Hero with banner background - Optimized for AI Tech theme */
.hero.has-banner {
  position: relative;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  border-radius: var(--radius-lg);
  min-height: 400px;
  padding: 5rem 1rem;
  overflow: hidden;
  /* Enhanced for AI tech background */
  background-attachment: scroll;
}

.hero.has-banner::before {
  content: "";
  position: absolute;
  inset: 0;
  /* Lighter overlay to showcase the AI tech background */
  background: linear-gradient(
    135deg, 
    rgba(0,0,0,0.2) 0%, 
    rgba(0,0,0,0.3) 50%,
    rgba(0,0,0,0.2) 100%
  );
}

.hero.has-banner .hero-inner {
  position: relative;
  z-index: 1;
  max-width: 800px;
  margin: 0 auto;
}

.hero.has-banner h1 {
  color: #fff;
  -webkit-text-fill-color: initial;
  background: none;
  font-size: 3.5rem;
  font-weight: 800;
  margin-bottom: 1.5rem;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
  /* AI theme gradient text effect */
  background: linear-gradient(135deg, #64b5f6, #e1bee7, #81c784);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero.has-banner .hero-description {
  color: rgba(255,255,255,0.95);
  font-size: 1.4rem;
  font-weight: 400;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
  line-height: 1.6;
}

@media (min-width: 768px) {
  .hero.has-banner { 
    min-height: 480px; 
    padding: 6rem 2rem;
  }
  .hero.has-banner h1 {
    font-size: 4rem;
  }
}

@media (min-width: 1200px) {
  .hero.has-banner { 
    min-height: 520px;
    padding: 7rem 2rem;
  }
}

/* Content with Sidebar Layout */
.content-with-sidebar {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 2rem;
  align-items: start;
}

/* Article Page with Dual Sidebars */
.content-with-dual-sidebar {
  display: grid;
  /* Force 2:6:2 proportions (with minimums for sidebars) */
  grid-template-columns: minmax(200px, 20%) minmax(0, 60%) minmax(260px, 20%);
  gap: 2rem;
  max-width: 1440px;
  margin: 0 auto;
  padding: 2rem;
}

.main-article {
  /* Fill the middle grid track strictly by proportion */
  min-width: 0;
  width: 100%;
  max-width: none;
  margin: 0;
}

/* ========================================
   Sidebar Styles
   ======================================== */
.home-sidebar,
.post-sidebar {
  position: sticky;
  top: calc(var(--nav-height) + 20px);
  height: fit-content;
  max-height: calc(100vh - var(--nav-height) - 40px);
  overflow-y: auto;
  /* No z-index to avoid covering the main article */
}

.sidebar-widget {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

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

/* About Widget */
.about-content p {
  margin-bottom: 1rem;
  color: var(--text-secondary);
}

.contact-section {
  margin-top: 1rem;
}

.contact-section h4 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.qr-code {
  text-align: center;
  padding: 1rem;
  background: var(--bg-color);
  border-radius: var(--radius);
}

.qr-code img {
  max-width: 220px;
  height: auto;
  margin-bottom: 0.5rem;
}

.qr-code small {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.email-link {
  color: var(--primary-color);
  text-decoration: none;
  font-size: 0.95rem;
}

.email-link:hover {
  text-decoration: underline;
}

/* Recommendations Widget */
.recommendation-link {
  display: flex;
  align-items: center;
  padding: 0.75rem;
  background: var(--bg-color);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text-primary);
  transition: all 0.3s ease;
}

.recommendation-link:hover {
  background: var(--primary-color);
  color: white;
  transform: translateX(5px);
  text-decoration: none;
}

.link-icon {
  font-size: 1.2rem;
  margin-right: 0.5rem;
}

.link-text {
  flex: 1;
}

.link-arrow {
  opacity: 0.5;
}

/* Tags Widget */
.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tag-item {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background: var(--bg-color);
  color: var(--text-secondary);
  border-radius: 15px;
  text-decoration: none;
  font-size: 0.9rem;
  transition: all 0.3s ease;
}

.tag-item:hover {
  background: var(--primary-color);
  color: white;
  text-decoration: none;
}

/* Ad Widget */
.ad-container {
  text-align: center;
  padding: 1rem;
  background: var(--bg-color);
  border-radius: var(--radius);
}

.ad-container img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

/* Related Posts Widget */
.related-post {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border-color);
}

.related-post:last-child {
  border-bottom: none;
}

.related-post a {
  display: block;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.95rem;
  margin-bottom: 0.25rem;
}

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

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

/* ========================================
   Table of Contents
   ======================================== */
.toc {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.5rem;
  position: sticky;
  top: calc(var(--nav-height) + 20px);
  max-height: calc(100vh - var(--nav-height) - 40px);
  overflow-y: auto;
}

.toc-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-item {
  margin-bottom: 0.5rem;
}

.toc-h3 {
  padding-left: 1rem;
}

.toc-h4 {
  padding-left: 2rem;
}

.toc-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  display: block;
  padding: 0.25rem 0.5rem;
  border-left: 2px solid transparent;
  transition: all 0.3s ease;
}

.toc-link:hover {
  color: var(--primary-color);
  border-left-color: var(--primary-color);
  text-decoration: none;
}

.toc-link.active {
  color: var(--primary-color);
  font-weight: 600;
  border-left-color: var(--primary-color);
}

/* ========================================
   Content Styles
   ======================================== */
.recent-posts, .recent-episodes {
  margin-bottom: 3rem;
}

.recent-posts h2, .recent-episodes h2 {
  margin-bottom: 1.5rem;
  border-bottom: 2px solid var(--primary-color);
  padding-bottom: 0.5rem;
}

/* Post and Episode Cards */
.post-list, .episode-list {
  display: grid;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.post-card, .episode-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.post-card:hover, .episode-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.post-card h3 a, .episode-card h3 a {
  color: var(--text-primary);
  text-decoration: none;
}

.post-card h3 a:hover, .episode-card h3 a:hover {
  color: var(--primary-color);
}

.post-meta, .episode-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.post-excerpt {
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Tags in posts */
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tag {
  background-color: var(--hover-bg);
  color: var(--text-secondary);
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
}

/* Post/Episode Detail Pages */
.post, .episode {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.post-header, .episode-header {
  margin-bottom: 2rem;
  text-align: center;
}

.post-title, .episode-title {
  font-size: 2.5rem;
  margin-bottom: 1rem;
}

.post-content, .episode-content {
  font-size: 1.1rem;
  line-height: 1.8;
  margin: 2rem 0;
  /* Prevent long words/URLs from expanding the grid column */
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Ensure media never overflow the content column */
.post-content img,
.episode-content img,
.post-content video,
.episode-content video,
.post-content iframe,
.episode-content iframe {
  max-width: 100%;
  height: auto;
}

/* Make wide tables scrollable instead of overflowing */
.post-content table,
.episode-content table {
  display: block;
  width: 100%;
  overflow-x: auto;
}

.post-content h2, .post-content h3, .post-content h4,
.episode-content h2, .episode-content h3, .episode-content h4 {
  margin-top: 2rem;
  margin-bottom: 1rem;
}

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

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

.post-content code, .episode-content code {
  font-family: var(--font-mono);
  background-color: var(--code-bg);
  color: var(--code-text);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--code-border);
  font-size: 0.9em;
  /* Allow inline code to wrap rather than forcing overflow */
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.post-content pre, .episode-content pre {
  background-color: var(--code-bg);
  color: var(--code-text);
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--code-border);
  overflow-x: auto;
  margin: 1.25rem 0;
}

.post-content pre code, .episode-content pre code {
  background: none;
  padding: 0;
  /* Preserve code block formatting while allowing horizontal scroll */
  white-space: pre;
}

/* Rouge highlight wrapper */
.highlight {
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin: 1.25rem 0;
}

/* Minimal Rouge token colors (GitHub-like) */
.highlight .c, .highlight .c1, .highlight .cm, .highlight .cd { color: #6a737d; font-style: italic; } /* comments */
.highlight .k, .highlight .kd, .highlight .kn, .highlight .kp, .highlight .kr { color: #d73a49; } /* keywords */
.highlight .s, .highlight .sb, .highlight .sc, .highlight .s1, .highlight .s2, .highlight .se, .highlight .sh, .highlight .si, .highlight .sx, .highlight .sr, .highlight .ss { color: #22863a; } /* strings */
.highlight .m, .highlight .mi, .highlight .mf { color: #005cc5; } /* numbers */
.highlight .na, .highlight .nc, .highlight .nf, .highlight .nt { color: #6f42c1; } /* names/functions/tags */
.highlight .o, .highlight .ow { color: #d73a49; } /* operators */

/* Mermaid container tweaks */
.mermaid {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 1.5rem 0;
}

/* Table styling for readability */
.post-content table,
.episode-content table {
  display: block;
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
}

.post-content table table,
.episode-content table table { border: none; } /* nested tables */

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

.post-content thead th,
.episode-content thead th {
  background: var(--hover-bg);
  font-weight: 600;
}

.post-content tbody tr:nth-child(even),
.episode-content tbody tr:nth-child(even) {
  background: var(--card-bg);
}

.post-content tbody tr:last-child td,
.episode-content tbody tr:last-child td { border-bottom: none; }

/* Prevent long links/headings from stretching columns */
.post-content a, .episode-content a,
.post-content h1, .post-content h2, .post-content h3, .post-content h4,
.episode-content h1, .episode-content h2, .episode-content h3, .episode-content h4 {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Ensure table cell text wraps and does not expand the layout */
.post-content table td, .post-content table th,
.episode-content table td, .episode-content table th {
  word-break: break-word;
}

/* Sidebar content should wrap too to avoid pushing into main */
.post-sidebar, .home-sidebar, .toc {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Audio Player */
.episode-preview {
  width: 100%;
  margin-top: 1rem;
}

/* View All Button */
.view-all {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  background-color: var(--primary-color);
  color: white;
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 500;
  transition: background-color 0.2s ease;
}

.view-all:hover {
  background-color: #2c5aa0;
  text-decoration: none;
}

/* ========================================
   Footer
   ======================================== */
.site-footer {
  background-color: var(--card-bg);
  border-top: 1px solid var(--border-color);
  padding: 2rem;
  text-align: center;
  color: var(--text-secondary);
  margin-top: 3rem;
}

/* ========================================
   Responsive Design
   ======================================== */
@media (max-width: 1200px) {
  .content-with-dual-sidebar {
    grid-template-columns: 1fr 300px;
  }
  
  .toc {
    display: none;
  }
}

@media (max-width: 768px) {
  /* Navigation */
  .site-nav {
    padding: 0.75rem 1rem;
  }
  
  .nav-links {
    gap: 1rem;
  }
  
  .site-title {
    font-size: 1.2rem;
  }
  
  /* Layout */
  .main-content {
    padding: 1rem;
  }
  
  .content-with-sidebar,
  .content-with-dual-sidebar {
    grid-template-columns: 1fr;
  }
  
  /* Hide sidebars on mobile */
  .home-sidebar,
  .post-sidebar,
  .toc {
    display: none;
  }

  /* QR size on mobile when sidebar is visible in future */
  .qr-code img {
    max-width: 150px;
  }
  
  /* Mobile sidebar toggle (future feature) */
  .mobile-sidebar-toggle {
    display: block;
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 1.5rem;
    z-index: 999;
    box-shadow: var(--shadow-lg);
  }
  
  /* Hero adjustments */
  .hero h1 {
    font-size: 2rem;
  }
  
  .hero-description {
    font-size: 1rem;
  }
  
  /* Post/Episode adjustments */
  .post-title, .episode-title {
    font-size: 1.75rem;
  }
  
  .post, .episode {
    padding: 1rem;
  }
  
  .post-meta, .episode-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
}

@media (max-width: 480px) {
  /* Navigation */
  .site-nav {
    flex-direction: column;
    height: auto;
    padding: 0.5rem;
  }
  
  .nav-links {
    width: 100%;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 0.5rem;
  }
  
  .nav-links a {
    font-size: 0.9rem;
  }
  
  /* Content */
  .main-content {
    padding: 0.5rem;
  }
  
  .post-card, .episode-card {
    padding: 1rem;
  }
  
  h1 { font-size: 1.75rem; }
  h2 { font-size: 1.5rem; }
  h3 { font-size: 1.25rem; }
  h4 { font-size: 1.1rem; }
  
  .post-content, .episode-content {
    font-size: 1rem;
  }
}

/* ========================================
   Print Styles
   ======================================== */
@media print {
  .site-nav,
  .theme-toggle,
  .home-sidebar,
  .post-sidebar,
  .toc,
  .site-footer,
  audio {
    display: none;
  }
  
  body {
    background: white;
    color: black;
  }
  
  .main-content,
  .main-article {
    max-width: none;
    padding: 0;
  }
  
  .content-with-sidebar,
  .content-with-dual-sidebar {
    grid-template-columns: 1fr;
  }
}
