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

:root {
  /* Light Mode Colors */
  --bg-body: #f0eee6;            /* Ivory Medium */
  --text-primary: #1f1e1d;       /* Slate Dark */
  --text-muted: #5e5d59;         /* Slate Light */
  --border-color: #d1cfc5;       /* Cloud Light */
  --accent-color: #1f1e1d;       /* Monochrome */
  --link-hover-color: #5e5d59;
  --link-hover-bg: rgba(0, 100, 255, 0.26); /* Blue selection style */
  --code-bg: #e8e6dc;            /* Ivory Dark */
  --code-color: #1f1e1d;
  --blockquote-bg: #e8e6dc;      /* Ivory Dark */

  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-body: 'Lora', Georgia, Cambria, "Times New Roman", Times, serif;
  --font-mono: 'Space Mono', SFMono-Regular, Consolas, Monaco, monospace;

  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

:root.dark-mode {
  /* Dark Mode Colors (Inverted) */
  --bg-body: #1f1e1d;            /* Slate Dark */
  --text-primary: #f0eee6;       /* Ivory Medium */
  --text-muted: #b0aea5;         /* Cloud Medium */
  --border-color: #5e5d59;       /* Slate Light */
  --accent-color: #f0eee6;       /* Monochrome */
  --link-hover-color: #b0aea5;
  --link-hover-bg: rgba(0, 100, 255, 0.26);
  --code-bg: #3d3d3a;            /* Slate Medium */
  --code-color: #f0eee6;
  --blockquote-bg: #3d3d3a;      /* Slate Medium */
}


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

a, a:visited {
  color: inherit;
  text-decoration: none;
}

html {
  scroll-behavior: smooth;
  background-color: var(--bg-body);
}

body {
  background-color: var(--bg-body);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 19px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

/* Global Transitions for theme variables */
body,
.header,
.footer,
.article-content pre,
.article-content code,
.article-content blockquote,
.post-item,
.copy-code-button {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

@media (max-width: 768px) {
  body {
    font-size: 17px;
  }
}

/* Base Selection */
::selection {
  background-color: var(--link-hover-bg);
  color: inherit;
}

/* Page Frame Layout */
.container {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* Header Styles */
.header {
  position: relative;
  z-index: 100;
  padding: 2.25rem 0;
  margin-bottom: 3.5rem;
  background-color: var(--bg-body);
  transition: border-color var(--transition-fast);
}

@media (max-width: 768px) {
  .header {
    padding: 1.5rem 0;
    margin-bottom: 1.5rem;
  }
}

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand-link {
  text-decoration: none;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 1.8rem; /* Increased from 1.5rem */
  letter-spacing: -0.03em;
  transition: color var(--transition-fast);
}

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

.header-controls {
  display: flex;
  align-items: center;
  gap: 1.75rem;
}

.header-link {
  font-family: var(--font-ui);
  font-size: 0.95rem;
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 500;
  transition: color var(--transition-fast);
  position: relative;
  padding: 0.25rem 0;
}

.header-link::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background-color: var(--text-primary);
  transform: scaleX(0);
  transform-origin: right;
  transition: transform var(--transition-fast);
}

.header-link:hover::after, .header-link.active::after {
  transform: scaleX(1);
  transform-origin: left;
}

.header-link:hover, .header-link.active {
  color: var(--text-primary);
}

/* Minimalist Dark Mode Toggle (Sliding Switch) */
.toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
  display: inline-block;
  vertical-align: middle;
}

.toggle-checkbox {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-label {
  display: block;
  width: 100%;
  height: 100%;
  background-color: var(--border-color);
  border-radius: 99px;
  cursor: pointer;
  position: relative;
  transition: background-color var(--transition-fast);
}

.toggle-label::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  left: 2px;
  top: 2px;
  background-color: var(--text-primary);
  transition: transform var(--transition-fast), background-color var(--transition-fast);
}

/* Checked States (Dark Mode active) */
.toggle-checkbox:checked + .toggle-label {
  background-color: var(--text-primary);
}

.toggle-checkbox:checked + .toggle-label::before {
  transform: translateX(18px);
  background-color: var(--bg-body);
}


/* Home Intro */
.home-intro {
  margin-bottom: 1rem;
  font-size: 1.3rem;
  line-height: 1.6;
  color: var(--text-primary);
}

.home-intro a {
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 4px;
  transition: color var(--transition-fast);
}

.home-intro a:hover {
  color: var(--link-hover-color);
}

@media (max-width: 768px) {
  .home-intro {
    margin-bottom: 1rem;
    font-size: 1.15rem;
  }
}

/* Minimalist Section Titles */
.section-title {
  font-family: var(--font-ui);
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-top: 3rem;
  margin-bottom: 1.5rem;
  padding-bottom: 0.25rem;
}

/* Structured and Compact Article List */
.posts-list {
  margin-bottom: 3rem;
  display: flex;
  flex-direction: column;
}

.post-item {
  display: flex;
  align-items: baseline;
  padding: 0.45rem 0; /* Compact vertical padding */
  border-bottom: 1px dashed var(--border-color);
  font-family: var(--font-body);
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.post-item:last-of-type {
  border-bottom: none;
}

.post-date {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-muted);
  width: 105px; /* Fixed width to align titles perfectly */
  flex-shrink: 0;
  letter-spacing: -0.01em;
}

.post-title-wrapper {
  font-size: 1.15rem; /* Compact readable font size */
  font-weight: 400;
  margin: 0;
  line-height: 1.45;
}

.post-title-link,
.bullet-list-link {
  color: var(--text-primary);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

.post-item:hover .post-title-link,
.bullet-list-item:hover .bullet-list-link {
  color: var(--link-hover-color);
  border-bottom-color: var(--link-hover-color);
}

.post-item:hover .post-date {
  color: var(--text-primary);
}

.no-posts {
  font-size: 1rem;
  color: var(--text-muted);
  padding: 0.5rem 0;
  font-family: var(--font-ui);
}

@media (max-width: 768px) {
  .post-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
    padding: 0.6rem 0;
  }

  .post-date {
    width: auto;
    font-size: 0.75rem;
  }

  .post-title-wrapper {
    font-size: 1.1rem;
  }
}

/* Article Page Layout */
.article-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  position: relative;
  gap: 3rem;
  padding: 0;
}

/* Fallback two-column layout for medium screens (laptops/tablets) */
@media (min-width: 1024px) and (max-width: 1199px) {
  .article-grid {
    grid-template-columns: 220px minmax(0, 1fr);
    max-width: 960px;
    margin: 0 auto;
    padding: 0 1.5rem;
    gap: 2.5rem;
  }
  .article-container {
    padding: 0; /* Align directly to column grid bounds on medium screens */
  }
}

/* Premium three-column layout: centers the article container exactly on the viewport
   and places the sticky Table of Contents sidebar floating on the left column */
@media (min-width: 1200px) {
  .article-grid {
    grid-template-columns: 1fr 680px 1fr;
    max-width: 100%;
    margin: 0 auto;
    padding: 0 2rem;
    gap: 0;
  }

  .toc-sidebar {
    grid-column: 1;
    justify-self: end;
    width: 220px;
    margin-right: 4rem; /* Generous spacing between TOC and centered article */
    padding-right: 1rem;
  }

  .article-container {
    grid-column: 2;
    padding: 0 1.5rem; /* Aligns left margin perfectly with header brand container */
  }
}

.article-container {
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  padding: 0 1.5rem; /* Default padding for mobile centering consistency */
}

/* Table of Contents - Desktop Sidebar */
.toc-sidebar {
  display: none;
}

@media (min-width: 1024px) {
  .toc-sidebar {
    display: block;
    position: sticky;
    top: 2.5rem;
    align-self: start;
    max-height: calc(100vh - 5rem);
    overflow-y: auto;
    padding-right: 1.5rem;
  }
}

.toc-title {
  font-family: var(--font-ui);
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 1rem;
  font-weight: 600;
}

/* Formatting Hugo default TOC output */
#TableOfContents ul {
  list-style: none;
  padding-left: 0;
}

#TableOfContents ul ul {
  padding-left: 0.75rem;
  margin-top: 0.25rem;
}

#TableOfContents li {
  margin-bottom: 0.4rem;
  line-height: 1.3;
}

#TableOfContents a {
  font-family: var(--font-ui);
  font-size: 0.9rem; /* Slightly smaller for cleaner fit */
  color: var(--text-muted);
  text-decoration: none;
  transition: all var(--transition-fast);
  display: block;
  padding: 0.15rem 0;
  border-left: 2px solid transparent;
}

#TableOfContents a:hover {
  color: var(--text-primary);
}

#TableOfContents a.active {
  color: var(--text-primary);
  font-weight: 600;
  border-left-color: var(--text-primary);
  padding-left: 0.5rem;
  margin-left: -0.5rem;
}

/* Code Block Language Label */
.code-lang-label {
  position: absolute;
  top: 0.65rem;
  left: 1.25rem;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  user-select: none;
  pointer-events: none;
  opacity: 0.7;
}

.article-content pre.has-lang {
  padding-top: 2.3rem !important;
}

/* Copy Code Button */
.copy-code-button {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background-color: var(--code-bg);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 0.7rem;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  pointer-events: auto;
  transition: opacity var(--transition-fast), background-color var(--transition-fast);
}

@media (hover: hover) {
  .copy-code-button {
    opacity: 0;
  }
  .article-content pre:hover .copy-code-button {
    opacity: 1;
  }
}

@media (hover: none) {
  .copy-code-button {
    opacity: 1;
  }
}

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

.copy-code-button.copied {
  background-color: rgba(46, 125, 50, 0.15);
  color: #2e7d32;
  border-color: #2e7d32;
}

:root.dark-mode .copy-code-button.copied {
  background-color: rgba(76, 175, 80, 0.2);
  color: #81c784;
  border-color: #81c784;
}

.copy-icon {
  flex-shrink: 0;
}

/* Mobile Inline TOC */
.mobile-toc {
  background-color: transparent;
  border: none;
  border-bottom: 1px solid var(--border-color);
  border-radius: 0;
  padding: 0.85rem 0;
  margin-bottom: 2.5rem;
  transition: border-color var(--transition-fast);
}

.mobile-toc:hover {
  border-color: var(--text-muted);
}

@media (min-width: 1024px) {
  .mobile-toc {
    display: none;
  }
}

.mobile-toc summary {
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
  user-select: none;
}

.mobile-toc summary::-webkit-details-marker {
  display: none;
}

.mobile-toc summary::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-top: 2px solid var(--text-muted);
  border-right: 2px solid var(--text-muted);
  transform: rotate(45deg);
  transition: transform var(--transition-fast) ease;
}

.mobile-toc[open] {
  padding-bottom: 1.25rem;
}

.mobile-toc[open] summary {
  border-bottom: 1px dashed var(--border-color);
  padding-bottom: 0.5rem;
  margin-bottom: 0.75rem;
}

.mobile-toc[open] summary::after {
  transform: rotate(135deg);
}

.mobile-toc #TableOfContents {
  margin-top: 0.75rem;
  padding-left: 0.25rem;
}

.mobile-toc #TableOfContents a {
  border-left: none;
  padding-left: 0;
  margin-left: 0;
  font-size: 0.95rem;
  padding: 0.3rem 0;
}

.mobile-toc #TableOfContents a.active {
  color: var(--text-primary);
  font-weight: 600;
  border-left: none;
  padding-left: 0;
  margin-left: 0;
}

/* Article Styling */
.article-header {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.article-title {
  font-family: var(--font-ui);
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.025em;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
}

.article-meta {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  color: var(--text-muted);
}

.article-content p {
  margin-bottom: 1.6rem;
  font-size: 1.1rem;
  line-height: 1.7;
  color: var(--text-primary);
}

.article-content h2 {
  font-family: var(--font-ui);
  font-size: 1.6rem;
  font-weight: 700;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.article-content h3 {
  font-family: var(--font-ui);
  font-size: 1.3rem;
  font-weight: 700;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  line-height: 1.3;
}

@media (max-width: 768px) {
  .article-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
  }

  .article-title {
    font-size: 1.4rem;
    line-height: 1.25;
  }

  .article-content h2 {
    font-size: 1.4rem;
    margin-top: 2rem;
  }

  .article-content h3 {
    font-size: 1.25rem;
    margin-top: 1.75rem;
  }
}

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

.article-content a {
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color var(--transition-fast);
}

.article-content a:hover {
  color: var(--link-hover-color);
}

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

.article-content li {
  margin-bottom: 0.5rem;
  font-size: 1.125rem;
}

/* Code & Formatting */
.article-content pre {
  background-color: var(--code-bg) !important;
  color: var(--code-color) !important;
  padding: 1.25rem;
  overflow-x: auto;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  margin: 1.5rem 0;
  font-family: var(--font-mono);
  font-size: 1rem; /* Increased to 1rem */
  position: relative; /* Added for absolute positioning of copy button */
}

.article-content code {
  font-family: var(--font-mono);
  font-size: 1rem; /* Increased to 1rem */
  background-color: var(--code-bg);
  color: var(--code-color);
  padding: 0.15rem 0.35rem;
  border-radius: 3px;
  border: 1px solid var(--border-color);
}

.article-content pre code {
  background-color: transparent;
  padding: 0;
  border-radius: 0;
  border: none;
  color: inherit;
}

/* Footer Back Links */
.article-footer {
  margin-top: 5rem;
  padding-top: 2rem;
  margin-bottom: 4rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.back-link,
.back-to-top {
  font-family: var(--font-ui);
  font-size: 1rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.back-link:hover,
.back-to-top:hover {
  color: var(--text-primary);
}

/* Simple Footer */
.footer {
  padding: 4rem 0;
  margin-top: 6rem;
  font-family: var(--font-ui);
  font-size: 0.95rem;
  color: var(--text-muted);
  text-align: center;
}

/* Hide TOC elements if they contain no headings (i.e. no anchor links) */
.toc-sidebar:not(:has(a)),
.mobile-toc:not(:has(a)) {
  display: none !important;
}

/* Adjust article layout grid if there is no TOC */
@media (min-width: 1024px) {
  .article-grid:not(:has(.toc-sidebar a)) {
    display: block;
    max-width: 680px;
    margin: 0 auto;
    padding: 0;
  }
}

/* Search Input Styling */
.search-wrapper {
  position: relative;
  width: 100%;
  margin-top: 1rem;
}

.search-input {
  width: 100%;
  padding: 0.6rem 0.5rem 0.6rem 2rem;
  background-color: transparent;
  border: none;
  border-bottom: 1px solid var(--border-color);
  font-family: var(--font-body); /* Using Lora serif for inputs for a publication feel */
  font-size: 1.25rem;
  color: var(--text-primary);
  outline: none;
  border-radius: 0; /* Minimalist sharp edges */
  transition: border-color var(--transition-fast);
}

.search-input::placeholder {
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 1.1rem;
  font-style: italic;
  opacity: 0.65;
}

.search-input:focus {
  border-bottom-color: var(--text-primary);
}

.search-icon {
  position: absolute;
  left: 0.25rem;
  top: 52%;
  transform: translateY(-50%);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  pointer-events: none;
  transition: color var(--transition-fast);
}

.search-input:focus + .search-icon {
  color: var(--text-primary);
}

/* --- Mobile Responsiveness Enhancements --- */

/* Responsive Images inside Article Content */
.article-content img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5rem auto;
  border-radius: 6px;
}

/* Responsive Tables inside Article Content */
.article-content table {
  display: block;
  width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-family: var(--font-ui);
  font-size: 0.95rem;
  -webkit-overflow-scrolling: touch;
}

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

.article-content th {
  background-color: var(--code-bg);
  color: var(--text-primary);
  font-weight: 600;
}

.article-content tr:nth-child(even) {
  background-color: rgba(0, 0, 0, 0.02);
}

:root.dark-mode .article-content tr:nth-child(even) {
  background-color: rgba(255, 255, 255, 0.02);
}

/* Responsive Block Equations (KaTeX) */
.article-content .katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  padding: 0.5rem 0;
  -webkit-overflow-scrolling: touch;
}

/* Wrap Inline Code blocks to prevent layout breakages */
.article-content :not(pre) > code {
  word-break: break-word;
  white-space: normal;
}

/* Extra Narrow Screen Sizing (e.g. 320px-375px viewports) */
@media (max-width: 480px) {
  .brand-link {
    font-size: 1.4rem;
  }
  .header-controls {
    gap: 0.85rem;
  }
  .container,
  .article-container {
    padding: 0 1rem;
  }
  .back-link,
  .back-to-top {
    font-size: 0.85rem;
    white-space: nowrap;
  }
}
