/* 
   Cream-themed Editorial Design System
   Inspired by the clean, serif typography layout.
*/

@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400..700;1,400..700&family=Plus+Jakarta+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* Color Palette */
  --bg-color: #FAF7F2;
  --sidebar-bg: #F5F1EA;
  --text-primary: #2B2B2B;
  --text-secondary: #6B665E;
  --text-muted: #8E887E;
  --border-color: #E6DFD5;
  --border-light: #ECE7DE;
  --accent-color: #4A5C4E; /* Dark Sage Green for subtle accents */
  --accent-hover: #3C4B3F;
  --code-bg: #F0EBE0;
  
  /* Font Stacks */
  --font-serif: 'Lora', Georgia, serif;
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Layout Variables */
  --sidebar-width: 320px;
  --header-height: 70px;
}

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

body {
  background-color: var(--bg-color);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
}

/* Sidebar Styling */
aside.sidebar {
  width: var(--sidebar-width);
  background-color: var(--sidebar-bg);
  border-right: 1px solid var(--border-color);
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 100;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

/* Custom scrollbars for sidebar */
aside.sidebar::-webkit-scrollbar {
  width: 6px;
}
aside.sidebar::-webkit-scrollbar-track {
  background: transparent;
}
aside.sidebar::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}
aside.sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Brand Logo */
.brand {
  display: flex;
  align-items: center;
  margin-bottom: 2rem;
  padding-left: 0.5rem;
}

.brand-logo {
  width: 38px;
  height: 38px;
  color: var(--text-primary);
}

/* Search Box */
.search-container {
  position: relative;
  margin-bottom: 1.5rem;
}

.search-input {
  width: 100%;
  padding: 0.7rem 1rem 0.7rem 2.5rem;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  background-color: var(--border-light);
  border: 1px solid transparent;
  border-radius: 20px;
  color: var(--text-primary);
  outline: none;
  transition: all 0.2s ease;
}

.search-input:focus {
  background-color: #FFF;
  border-color: var(--border-color);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.search-icon {
  position: absolute;
  left: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

/* Floating Search Results */
.search-results {
  position: absolute;
  top: 105%;
  left: 0;
  width: 100%;
  background-color: #FFF;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  max-height: 300px;
  overflow-y: auto;
  z-index: 200;
  display: none;
}

.search-results.active {
  display: block;
}

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

.search-result-item:last-child {
  border-bottom: none;
}

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

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

.search-result-snippet {
  color: var(--text-secondary);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sidebar Navigation Links */
.sidebar-menu {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.menu-group-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  padding-left: 0.5rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}

.menu-group-title::after {
  content: '▼';
  font-size: 0.6rem;
  transition: transform 0.2s ease;
}

.menu-group.collapsed .menu-group-title::after {
  transform: rotate(-90deg);
}

.menu-items {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.menu-group.collapsed .menu-items {
  display: none;
}

.menu-items a {
  display: block;
  padding: 0.4rem 0.5rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.menu-items a:hover {
  color: var(--text-primary);
  background-color: var(--border-light);
  padding-left: 0.75rem;
}

.menu-items li.active a {
  color: var(--text-primary);
  font-weight: 600;
  background-color: var(--border-light);
  padding-left: 0.75rem;
}

/* Visited History Section */
.history-section {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
}

.history-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  padding-left: 0.5rem;
}

.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.history-list a {
  display: block;
  padding: 0.3rem 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: 4px;
}

.history-list a:hover {
  color: var(--text-primary);
  background-color: var(--border-light);
}

.history-empty {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.5rem;
  line-height: 1.4;
  font-style: italic;
}

/* Footer links inside sidebar */
.sidebar-footer {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.8rem;
}

.footer-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-bottom: 0.8rem;
}

.footer-nav a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s ease;
}

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

.global-views {
  color: var(--text-muted);
}

/* Main Content Container */
main.content-area {
  margin-left: var(--sidebar-width);
  flex-grow: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Top Navigation Header */
header.top-header {
  height: var(--header-height);
  padding: 0 4rem;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  position: sticky;
  top: 0;
  background-color: rgba(250, 247, 242, 0.9);
  backdrop-filter: blur(8px);
  z-index: 90;
}

.auth-buttons {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.btn-login {
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: opacity 0.2s ease;
}

.btn-login:hover {
  opacity: 0.8;
}

.btn-signup {
  background-color: var(--text-primary);
  color: #FFF;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.5rem 1.2rem;
  border-radius: 20px;
  transition: background-color 0.2s ease;
}

.btn-signup:hover {
  background-color: var(--accent-color);
}

/* Mobile Hamburger Menu */
.mobile-nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  z-index: 110;
}

.mobile-nav-toggle svg {
  width: 24px;
  height: 24px;
  color: var(--text-primary);
}

/* Article Layout */
article.lecture-content {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 4rem 6rem 4rem;
  flex-grow: 1;
}

/* Category indicator */
.category-indicator {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* H1 Main Page Title */
.lecture-title {
  font-family: var(--font-serif);
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 1.2rem;
  color: var(--text-primary);
  text-wrap: balance;
}

/* Meta Line */
.lecture-meta {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 3.5rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1rem;
}

.lecture-meta .separator {
  color: var(--border-color);
}

.download-link {
  color: var(--text-primary);
  text-decoration: underline;
  cursor: pointer;
  font-weight: 500;
}

.download-link:hover {
  color: var(--accent-color);
}

/* Markdown Content Styling */
.markdown-body {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  line-height: 1.75;
  color: var(--text-primary);
}

/* Headings */
.markdown-body h2 {
  font-family: var(--font-serif);
  font-size: 1.7rem;
  font-weight: 600;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  color: var(--text-primary);
  text-wrap: balance;
}

.markdown-body h3 {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 600;
  margin-top: 2rem;
  margin-bottom: 0.8rem;
  color: var(--text-primary);
  text-wrap: balance;
}

.markdown-body p {
  margin-bottom: 1.5rem;
  text-wrap: pretty;
}

.markdown-body strong {
  font-weight: 700;
}

/* Horizontal Rules */
.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 3rem 0;
}

/* Lists */
.markdown-body ul, 
.markdown-body ol {
  margin-bottom: 1.5rem;
  padding-left: 2rem;
}

.markdown-body li {
  margin-bottom: 0.5rem;
  text-wrap: pretty;
}

/* Blockquotes */
.markdown-body blockquote {
  border-left: 4px solid var(--accent-color);
  padding-left: 1.5rem;
  margin: 1.5rem 0;
  font-style: italic;
  color: var(--text-secondary);
}

/* Inline Code */
.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background-color: var(--border-light);
  padding: 0.15em 0.35em;
  border-radius: 4px;
  color: var(--text-primary);
}

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

.markdown-body a:hover {
  color: var(--accent-hover);
  text-decoration: none;
}

/* Code Blocks */
.markdown-body pre {
  margin: 1.8rem 0;
  padding: 1rem 1.25rem;
  border-radius: 8px;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  background-color: var(--code-bg) !important;
}

.markdown-body pre code {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  background-color: transparent;
  padding: 0;
  border-radius: 0;
  color: var(--text-primary);
}

/* Override Prism Tomorrow theme colors to blend with our cream styling */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
  color: #8a8273;
  font-style: italic;
}

.token.punctuation {
  color: #5c554a;
}

.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted {
  color: #b55a30;
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
  color: #3b6b4c;
}

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
  color: #70583b;
}

.token.atrule,
.token.attr-value,
.token.keyword {
  color: #2b558c;
  font-weight: bold;
}

.token.function,
.token.class-name {
  color: #8c2b75;
}

.token.regex,
.token.important,
.token.variable {
  color: #825d10;
}

/* Tables */
.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 2rem 0;
  font-size: 0.95rem;
}

.markdown-body th {
  font-family: var(--font-sans);
  background-color: var(--sidebar-bg);
  font-weight: 700;
  border-bottom: 2px solid var(--border-color);
  text-align: left;
  padding: 0.75rem 1rem;
}

.markdown-body td {
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1rem;
  vertical-align: top;
}

.markdown-body tr:hover {
  background-color: rgba(245, 241, 234, 0.5);
}

/* Prev / Next Pagination Controls */
.pagination-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border-color);
  margin-top: 4rem;
  padding-top: 2rem;
  gap: 2rem;
}

.pag-btn {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: var(--text-secondary);
  max-width: 45%;
}

.pag-btn.next {
  text-align: right;
  align-items: flex-end;
}

.pag-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.pag-title {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  transition: color 0.2s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

.pag-btn:hover .pag-title {
  color: var(--accent-color);
}

/* Responsive Styles */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 280px;
  }
  header.top-header {
    padding: 0 2rem;
  }
  article.lecture-content {
    padding: 2rem 2rem 5rem 2rem;
  }
}

@media (max-width: 768px) {
  body {
    flex-direction: column;
  }
  
  aside.sidebar {
    width: 100%;
    height: auto;
    position: relative;
    max-height: 0;
    overflow: hidden;
    padding: 0;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    transition: max-height 0.35s ease, padding 0.35s ease;
  }
  
  aside.sidebar.mobile-active {
    max-height: 100vh;
    padding: 1.5rem;
    overflow-y: auto;
  }
  
  header.top-header {
    height: 60px;
    padding: 0 1.5rem;
    justify-content: space-between;
    position: relative;
    background-color: var(--sidebar-bg);
    border-bottom: 1px solid var(--border-color);
  }
  
  .mobile-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1rem;
  }
  
  .mobile-nav-toggle {
    display: block;
  }
  
  .auth-buttons {
    display: none; /* Hide on mobile to keep clean or move to sidebar */
  }
  
  main.content-area {
    margin-left: 0;
    width: 100%;
  }
  
  article.lecture-content {
    padding: 1.5rem 1.5rem 4rem 1.5rem;
  }
  
  .lecture-title {
    font-size: 2rem;
  }
  
  .lecture-meta {
    flex-wrap: wrap;
    margin-bottom: 2rem;
  }
  
  .pagination-container {
    flex-direction: column;
    gap: 1.5rem;
    margin-top: 3rem;
  }
  
  .pag-btn {
    max-width: 100%;
    width: 100%;
  }
  
  .pag-btn.next {
    text-align: left;
    align-items: flex-start;
  }
}

/* Print Styling - Highly optimized for book export */
@media print {
  aside.sidebar,
  header.top-header,
  .pagination-container,
  .mobile-nav-toggle {
    display: none !important;
  }
  
  body {
    background-color: #FFF !important;
    color: #000 !important;
    font-size: 12pt;
    line-height: 1.5;
  }
  
  main.content-area {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
  }
  
  article.lecture-content {
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
  }
  
  .lecture-meta {
    margin-bottom: 2rem !important;
    border-bottom: 1px solid #CCC !important;
  }
  
  .lecture-meta .download-link {
    display: none !important;
  }
  
  .markdown-body {
    font-size: 11pt !important;
  }
  
  .markdown-body pre {
    background-color: #F8F8F8 !important;
    border: 1px solid #DDD !important;
    page-break-inside: avoid;
  }
  
  .markdown-body table {
    page-break-inside: avoid;
  }
  
  .markdown-body tr {
    page-break-inside: avoid;
  }
  
  h1, h2, h3 {
    page-break-after: avoid;
  }
}

/* Copy Code Button styling */
.copy-code-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.3rem 0.6rem;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  background-color: var(--sidebar-bg);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
  z-index: 10;
}

div:hover > .copy-code-btn {
  opacity: 1;
}

.copy-code-btn:hover {
  color: var(--text-primary);
  background-color: var(--border-light);
  border-color: var(--text-muted);
}

.copy-code-btn.copied {
  color: #FFF;
  background-color: var(--accent-color);
  border-color: var(--accent-color);
}

@media print {
  .copy-code-btn {
    display: none !important;
  }
}

/* TOC Card Container */
.toc-container {
  background-color: var(--sidebar-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.5rem;
  margin: 1.5rem 0 2.5rem 0;
  max-width: 500px;
}
.toc-container h2 {
  font-family: var(--font-sans) !important;
  font-size: 1.1rem !important;
  font-weight: 700 !important;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0 !important;
  margin-bottom: 1rem !important;
  color: var(--text-secondary) !important;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
}
.toc-container ol {
  margin-bottom: 0 !important;
  padding-left: 1.2rem !important;
}
.toc-container li {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  margin-bottom: 0.4rem !important;
}
.toc-container li a {
  color: var(--accent-color);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}
.toc-container li a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

