/* Base styles */
body {
  max-width: 800px;
  margin: auto;
  padding: 2em 1em;
  line-height: 1.7;
  font-size: 21px;
  color: #111;
  background-color: #fafafa;
}

/* Typography improvements */
h1, h2, h3, h4, h5, h6 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  line-height: 1.3;
  font-weight: 600;
}

h1 { font-size: 2.2em; }
h2 { font-size: 1.8em; }
h3 { font-size: 1.4em; }

p {
  margin: 1em 0;
  text-align: justify;
  hyphens: auto;
}

/* Links */
a {
  color: #0066cc;
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: #0052a3;
  text-decoration: underline;
}

/* Header and navigation */
.menu { 
  padding: 0;
  margin-bottom: 3em;
}

.menu li { 
  display: inline-block;
  margin: 0 1em;
}

.menu a {
  text-decoration: none;
  padding: 0.5em 0;
  color: #555;
  font-size: 0.95em;
  letter-spacing: 0.5px;
  text-transform: lowercase;
  transition: color 0.2s ease;
}

.menu a:hover {
  color: #0066cc;
  text-decoration: none;
}

/* Article metadata */
.article-meta {
  padding: 1em 0 1em;
  margin-bottom: 1em;
}

.article-meta h1 {
  margin: 0;
  font-size: 2.5em;
  line-height: 1.2;
  color: #1a1a1a;
}

.article-meta .author,
.article-meta .date {
  font-size: 0.95em;
  color: #444;
  font-weight: normal;
  margin: 0.3em 0;
}

.article-meta .date {
  font-style: italic;
}

.separator {
  color: #999;
  margin: 0 0.5em;
  font-size: 0.9em;
}

.reading-time {
  color: #444;
  font-size: 0.95em;
  cursor: help;
  position: relative;
  display: inline-block;
}

/* Custom tooltip for reading time */
.reading-time::after {
  content: "Estimate based on 270 words per minute, excluding math and code";
  position: absolute;
  bottom: 125%;
  left: 50%;
  transform: translateX(-50%);
  background-color: #333;
  color: #fff;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 0.85em;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 100;
}

/* Tooltip arrow */
.reading-time::before {
  content: "";
  position: absolute;
  bottom: 105%;
  left: 50%;
  transform: translateX(-50%);
  border-width: 5px;
  border-style: solid;
  border-color: #333 transparent transparent transparent;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 100;
}

/* Show tooltip on hover */
.reading-time:hover::after,
.reading-time:hover::before {
  opacity: 1;
}

/* Main content area */
main {
  hyphens: auto;
}

/* Drop cap only for posts */
.post main > p:first-of-type::first-letter {
  font-size: 3.2em;
  line-height: 0.8;
  float: left;
  margin: 0.05em 0.1em -0.1em 0;
  color: #444;
  font-weight: 600;
  text-transform: uppercase;
}

/* Improved code blocks */
.code-block-wrapper {
  margin: 1.5em 0;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  border: 1px solid #e5e7eb;
  background: #ffffff;
}

.code-header {
  background: #f8f9fa;
  padding: 0.5em 1em;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #e5e7eb;
}

.code-language {
  font-size: 0.75em;
  color: #6b7280;
  font-weight: 500;
  text-transform: lowercase;
  letter-spacing: 0.05em;
}

pre {
  background: #f9fafb;
  padding: 1.2em;
  overflow-x: auto;
  margin: 0;
  border: none;
  color: #1f2937;
  line-height: 1.6;
}

.highlight pre {
  background: transparent;
}

/* Ensure code elements inside pre don't have their own background */
pre code {
  background: transparent;
  padding: 0;
}

/* Let syntax highlighting colors show through - only override background */
.chroma {
  background: #f9fafb !important;
}

.copy-button {
  padding: 6px;
  font-size: 0;
  line-height: 0;
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: #4b5563;
  font-family: inherit;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  min-height: 28px;
}

.copy-button:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
  color: #1f2937;
}

.copy-button:focus,
.citation-copy-button:focus {
  outline: none;
  border-color: #0066cc;
}

.copy-button.copied:focus,
.citation-copy-button.copied:focus {
  border-color: #0066cc;
}

.copy-button.copied .copy-icon {
  filter: brightness(0) invert(1);
}

.copy-icon {
  width: 16px;
  height: 16px;
  display: block;
  opacity: 0.85;
  transition: opacity 0.2s ease;
}

.copy-button:hover .copy-icon,
.citation-copy-button:hover .copy-icon {
  opacity: 1;
}

.citation-separator {
  margin-top: 3rem;
  margin-bottom: 1.5rem;
  border: 0;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.citation-block {
  margin-bottom: 2rem;
  padding: 1.2rem 1.3rem;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #fafafa;
  font-size: 0.95em;
}

.citation-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.citation-heading {
  font-size: 0.9em;
  color: #444;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.citation-formats {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.citation-format-btn {
  padding: 0.3rem 0.8rem;
  font-size: 0.85rem;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  background: #ffffff;
  cursor: pointer;
  color: #666;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.15s ease;
  pointer-events: auto;
  position: relative;
  z-index: 1;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  height: 32px;
  display: flex;
  align-items: center;
}

.citation-format-btn:active {
  transform: none;
}

.citation-format-btn:hover {
  background: #f3f4f6;
  border-color: rgba(0, 0, 0, 0.25);
  color: #333;
}

.citation-format-btn:focus {
  outline: 2px solid #666;
  outline-offset: 2px;
}

.citation-format-btn.active {
  background: #666;
  border-color: #666;
  color: #fff;
}

.citation-format-btn.active:hover {
  background: #555;
  border-color: #555;
}

.citation-body {
  margin-bottom: 1rem;
  position: relative;
  min-height: 3rem;
}

.citation-text {
  margin: 0;
  padding: 1rem;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.95em;
  line-height: 1.6;
  color: #1f2937;
  word-wrap: break-word;
  overflow-x: auto;
}

.citation-text em {
  font-style: italic;
  color: #1f2937;
}

.citation-text-bibtex {
  font-family: 'Latin Modern Mono', 'Courier New', monospace;
  white-space: pre-wrap;
  font-size: 0.9em;
}

.citation-copy-button {
  padding: 0;
  font-size: 0;
  line-height: 0;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  background: #ffffff;
  cursor: pointer;
  color: #444;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.15s ease;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.citation-copy-button:hover {
  background: #f3f4f6;
  border-color: rgba(0, 0, 0, 0.25);
  color: #1f2937;
}

.citation-copy-button:focus {
  outline: 2px solid #666;
  outline-offset: 2px;
}

.copy-button:focus {
  outline: 2px solid #666;
  outline-offset: 2px;
}

.citation-copy-button.copied {
  background: #0066cc;
  border-color: #0066cc;
  color: #fff;
}

.copy-button.copied {
  background: #0066cc;
  border-color: #0066cc;
  color: #fff;
}

.citation-copy-button.copied .copy-icon {
  filter: brightness(0) invert(1);
}


code {
  background: #f3f4f6;
  padding: 0.2em 0.4em;
  border-radius: 4px;
  font-size: 0.92em;
  color: #dc2626;
  font-weight: 500;
}

pre code { 
  background: none;
  padding: 0;
  color: inherit;
  font-weight: normal;
}

/* Blockquotes */
blockquote {
  margin: 1.5em 0;
  padding: 0.5em 1.5em;
  border-left: 4px solid #0066cc;
  background: #f8f8f8;
  font-style: italic;
  color: #555;
}

blockquote p {
  margin: 0.5em 0;
}

/* Images */
img, iframe, video {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 2em auto;
  border-radius: 4px;
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

/* Tables */
table {
  margin: 2em auto;
  border-collapse: collapse;
  width: 100%;
  font-size: 0.95em;
}

table thead th {
  background: #f5f5f5;
  border-bottom: 2px solid #ddd;
  padding: 0.8em;
  text-align: left;
  font-weight: 600;
}

th, td {
  padding: 0.8em;
  border-bottom: 1px solid #eee;
}

tbody tr:hover {
  background: #f9f9f9;
}

/* Lists */
ul, ol {
  margin: 1em 0;
  padding-left: 2em;
}

li {
  margin: 0.5em 0;
  line-height: 1.6;
}

/* Nested lists */
li ul, li ol {
  margin: 0.5em 0;
}

/* Math styling */
.math {
  overflow-x: auto;
  margin: 1em 0;
}

/* Inline math */
.math-inline {
  padding: 0 0.2em;
}

/* Display math */
.math-display {
  text-align: center;
  margin: 1.5em 0;
  padding: 1em;
  background: #f9f9f9;
  border-radius: 4px;
  overflow-x: auto;
}

/* Horizontal rules */
hr {
  border: none;
  border-top: 1px solid #e0e0e0;
  margin: 2em 0;
}

/* Categories and tags */
.categories, .tags {
  margin: 1.2em 0;
  font-size: 0.95em;
  color: #444;
}

/* Publication date below tags */
.publication-date {
  margin: 1.2em 0;
  font-size: 0.9em;
  color: #666;
  font-style: italic;
}

.categories a {
  color: #666;
  text-decoration: none;
  margin-right: 0.5em;
  transition: color 0.2s ease;
  font-size: 0.9em;
}

.tags a {
  color: #666;
  text-decoration: none;
  margin-right: 0.3em;
  font-size: 0.9em;
}

.categories a:hover {
  color: #0066cc;
  text-decoration: none;
}

.tags a:hover {
  color: #0066cc;
  text-decoration: none;
}

/* Footer */
footer {
  margin-top: 4em;
  padding-top: 2em;
  text-align: center;
  font-size: 0.9em;
  color: #666;
}

footer a {
  color: #666;
  text-decoration: none;
  transition: color 0.2s ease;
}

footer a:hover {
  color: #0066cc;
}

/* Centering */
.menu, .article-meta, footer {
  text-align: center;
}

/* Selection styling */
::selection {
  background: #0066cc;
  color: white;
}
/* Homepage styles */
.home h2 {
  margin-top: 2em;
  margin-bottom: 1em;
  font-size: 1.6em;
  color: #333;
}

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

.post-list li {
  margin-bottom: 1.5em;
  padding-bottom: 1.5em;
  border-bottom: 1px solid #f0f0f0;
}

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

.post-list .date {
  font-size: 0.9em;
  color: #555;
  display: block;
  margin-bottom: 0.3em;
}

.post-list h3 {
  margin: 0 0 0.3em 0;
  font-size: 1.3em;
}

.post-list h3 a {
  color: #333;
}

.post-list h3 a:hover {
  color: #0066cc;
  text-decoration: none;
}

.post-list .category {
  font-size: 0.85em;
  color: #666;
}

.post-list .category a {
  color: #666;
  text-decoration: none;
  font-weight: 500;
}

.post-list .category a:hover {
  color: #0066cc;
}

.post-list .post-description {
  margin: 0.5em 0;
  color: #666;
  font-size: 0.9em;
  font-style: italic;
  line-height: 1.5;
}

/* Category index */
.category-index {
  background: #f5f5f5;
  padding: 1.5em;
  border-radius: 8px;
  margin-bottom: 2em;
}

.category-index h3 {
  margin-top: 0;
  margin-bottom: 1em;
  font-size: 1.1em;
  color: #333;
}

.category-index ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 1.5em;
}

.category-index li {
  margin: 0;
}

.category-index a {
  color: #555;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

.category-index a:hover {
  color: #0066cc;
}

.category-index .count {
  color: #999;
  font-size: 0.9em;
  margin-left: 0.2em;
}

/* Category page styles */
.category-section {
  margin-bottom: 3em;
  scroll-margin-top: 1em;
}

.category-section h2 {
  margin-bottom: 1em;
  padding-bottom: 0.5em;
  border-bottom: 2px solid #e0e0e0;
  color: #333;
  font-size: 1.3em;
}

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

.category-post-list li {
  margin-bottom: 0.8em;
  font-size: 0.9em;
}

.category-post-list .date {
  color: #666;
  font-size: 0.85em;
  margin-right: 0.5em;
}

.category-post-list a {
  color: #333;
  text-decoration: none;
}

.category-post-list a:hover {
  color: #0066cc;
}

/* Tag cloud styles */
.tag-cloud {
  list-style: none;
  padding: 0;
  margin: 2em 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6em;
}

.tag-cloud li {
  margin: 0;
}

.tag-cloud a {
  display: inline-block;
  padding: 0.3em 0.6em;
  background: #f0f0f0;
  color: #444;
  text-decoration: none;
  border-radius: 15px;
  transition: all 0.2s ease;
  font-size: 0.95em;
}

.tag-cloud a:hover {
  background: #0066cc;
  color: white;
  transform: translateY(-2px);
}

.tag-cloud .count,
.terms .count {
  color: #999;
  font-size: 0.8em;
  margin-left: 0.2em;
}

/* Compact tag list */
.tag-list-compact {
  list-style: none;
  padding: 0;
  margin: 1.5em 0;
}

.tag-list-compact li {
  margin-bottom: 0.8em;
}

.tag-list-compact a {
  color: #555;
  text-decoration: none;
  font-size: 0.85em;
  display: inline-block;
  padding: 0.2em 0;
  transition: color 0.2s ease;
}

.tag-list-compact a:hover {
  color: #0066cc;
}

.tag-list-compact .count {
  color: #666;
  font-size: 0.8em;
  font-weight: 600;
  margin-left: 0.3em;
}

/* Categories expanded view */
.categories-expanded {
  margin: 2em 0;
}

.categories-expanded .category-section {
  margin-bottom: 3em;
  border-bottom: 1px solid #e0e0e0;
  padding-bottom: 2em;
}

.categories-expanded .category-section:last-child {
  border-bottom: none;
}

.categories-expanded h2 {
  font-size: 1.3em;
  margin-bottom: 1em;
  color: #333;
}

.categories-expanded h2 a {
  color: inherit;
  text-decoration: none;
  transition: color 0.2s ease;
}

.categories-expanded h2 a:hover {
  color: #0066cc;
}

.categories-expanded h2 .count {
  color: #666;
  font-size: 0.7em;
  font-weight: normal;
  margin-left: 0.5em;
}

/* Posts list under categories */
.categories-expanded .posts,
ul.posts {
  list-style: none;
  padding: 0;
  margin: 0;
}

.categories-expanded .posts li {
  margin-bottom: 0.8em;
  padding-left: 0;
  position: relative;
}

ul.posts li {
  margin-bottom: 0.8em;
  padding-left: 1.5em;
  position: relative;
}

ul.posts li::before {
  content: "—";
  position: absolute;
  left: 0;
  color: #ccc;
}

.categories-expanded .posts .date,
ul.posts .date {
  color: #999;
  font-size: 0.85em;
  margin-right: 1em;
  font-variant-numeric: tabular-nums;
}

.categories-expanded .posts a,
ul.posts a {
  color: #333;
  text-decoration: none;
  transition: color 0.2s ease;
}

.categories-expanded .posts a:hover,
ul.posts a:hover {
  color: #0066cc;
  text-decoration: underline;
}

/* Tag posts list */
.tag-posts-list {
  list-style: none;
  padding: 0;
  margin: 1.5em 0;
}

.tag-posts-list li {
  margin-bottom: 1em;
  padding-left: 1.5em;
  position: relative;
}

.tag-posts-list li::before {
  content: "›";
  position: absolute;
  left: 0;
  color: #999;
}

.tag-posts-list a {
  color: #333;
  text-decoration: none;
  font-weight: 500;
}

.tag-posts-list a:hover {
  color: #0066cc;
}

.tag-posts-list .post-description {
  color: #666;
  font-size: 0.9em;
  font-style: italic;
}

/* Meta info styling */
.meta-info {
  font-size: 0.9em;
  color: #666;
  margin: 0.5em 0;
}

.meta-info time,
.meta-info .author {
  display: inline-block;
  margin-right: 1em;
}

/* Responsive adjustments */
@media (max-width: 600px) {
  body {
    font-size: 19px;
    padding: 1em;
  }
  
  p {
    text-align: left;
  }
  
  .article-meta h1 {
    font-size: 2em;
  }
  
  .post main > p:first-of-type::first-letter {
    font-size: 2.5em;
  }
  
  .menu li {
    margin: 0 0.5em;
  }
  
  .tag-cloud {
    gap: 0.4em;
  }
  
  .tag-cloud a {
    font-size: 0.9em;
    padding: 0.25em 0.5em;
  }
  

  
  .tag-list-compact a {
    font-size: 0.8em;
  }
  
  .category-section h2 {
    font-size: 1.2em;
  }
  
  .category-index ul {
    gap: 1em;
  }
  
  .category-index {
    padding: 1em;
  }
  
  .citation-block {
    padding: 1rem;
  }
  
  .citation-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }
  
  .citation-formats {
    width: 100%;
    justify-content: flex-start;
  }
  
  .citation-format-btn {
    flex: 1;
    min-width: 0;
  }
  
  .citation-text {
    font-size: 0.8rem;
    padding: 0.85rem;
  }
}

/* Footnote tooltip */
.footnote-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 0.85em;
  line-height: 1.5;
  min-width: 150px;
  width: max-content;
  margin-bottom: 8px;
  z-index: 1000;
  box-shadow: 0 3px 12px rgba(0,0,0,0.25);
  white-space: normal;
  text-align: left;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

/* Dynamic width classes for different content lengths */
.footnote-tooltip.short {
  max-width: 300px;
}

.footnote-tooltip.medium {
  max-width: 400px;
}

.footnote-tooltip.long {
  max-width: 500px;
}

.footnote-tooltip.very-long {
  max-width: 700px;
}

.footnote-tooltip.show {
  opacity: 1;
  visibility: visible;
}

.footnote-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #333;
}

/* Light mode styles for footnote tooltip */
@media (prefers-color-scheme: light) {
  .footnote-tooltip {
    background: #f8f8f8;
    color: #333;
    border: 1px solid #ddd;
    box-shadow: 0 3px 12px rgba(0,0,0,0.1);
  }
  
  .footnote-tooltip::after {
    border-top-color: #f8f8f8;
  }
}

/* Ensure sup elements can contain positioned tooltips */
sup[id^="fnref:"] {
  position: relative;
}

/* Math in footnote tooltips */
.footnote-tooltip .MathJax {
  font-size: 0.9em;
}

.footnote-tooltip mjx-container {
  margin: 0 !important;
}

/* Responsive footnote tooltips */
@media (max-width: 600px) {
  .footnote-tooltip {
    max-width: calc(100vw - 40px);
    font-size: 0.8em;
    padding: 8px 10px;
  }
  
  .footnote-tooltip.short {
    max-width: 200px;
  }
  
  .footnote-tooltip.medium {
    max-width: 250px;
  }
  
  .footnote-tooltip.long,
  .footnote-tooltip.very-long {
    max-width: calc(100vw - 40px);
  }
}
