/* Google Fonts Import */
@import url('https://fonts.googleapis.com/css2?family=Newsreader:ital,opsz,wght@0,6..72,200..800;1,6..72,200..800&display=swap');

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

/* Theme variables: Light mode (default) */
:root, html.light-mode {
  --bg: #ffffff;
  --text: #333333;
  --link: #007700;
  --link-hover: #1741a6;
  --muted: #666;
  --code-bg: #f8f9fa;
  --code-text: #c7254e;
  --pre-bg: #f8f9fa;
  --pre-shadow: 0 2px 8px 0 rgba(60,60,60,0.04);
  --inline-math-bg: #f8f9fa;
  --inline-math-text: #2d3a4a;
  --block-math-bg: #f8f9fa;
  --block-math-text: #2d3a4a;
  --weblog-tag: #555;
  --weblog-tag-hover: #333;
  --weblog-tag-bg: #f0f0f0;
  --weblog-tag-hover-bg: #e0e0e0;
  --upvote-arrow: #d1d1d1;
  --upvote-arrow-active: #4b4e50;
  --share: #555;
  --share-hover: #2563eb;
  --search-bg: #f8f9fa;
  --search-border: #ddd;
  --search-btn-bg: #007700;
  --search-btn-hover: #006600;
  --search-btn-text: white;
  --post-bg: #ffffff;
  --post-border: #eaeaea;
  --heading: #1a1a1a;
  --blockquote: #37352f;
}

/* Dark mode overrides */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --text: #e0e0e0;
    --link: #00cc00;
    --link-hover: #00ff00;
    --muted: #aaaaaa;
    --code-bg: #1e1e1e;
    --code-text: #00cc00;
    --pre-bg: #1e1e1e;
    --pre-shadow: 0 2px 8px 0 rgba(0,0,0,0.4);
    --inline-math-bg: #1e1e1e;
    --inline-math-text: #00cc00;
    --block-math-bg: #1e1e1e;
    --block-math-text: #00cc00;
    --weblog-tag: #00cc00;
    --weblog-tag-hover: #00ff00;
    --weblog-tag-bg: #1e1e1e;
    --weblog-tag-hover-bg: #2a2a2a;
    --search-bg: #1e1e1e;
    --search-border: #444;
    --search-btn-bg: #008800;
    --search-btn-hover: #00aa00;
    --search-btn-text: #fff;
    --post-bg: #1e1e1e;
    --post-border: #333;
    --upvote-arrow: #444;
    --upvote-arrow-active: #00ff00;
    --share: #00ff00;
    --share-hover: #00ff88;
    --heading: #f1f1f1;
    --blockquote: #00ff00;
  }
}

/* Explicit Dark Mode */
html.dark-mode {
    --bg: #121212;
    --text: #e0e0e0;
    --link: #00cc00;
    --link-hover: #00ff00;
    --muted: #aaaaaa;
    --code-bg: #1e1e1e;
    --code-text: #00cc00;
    --pre-bg: #1e1e1e;
    --pre-shadow: 0 2px 8px 0 rgba(0,0,0,0.4);
    --inline-math-bg: #1e1e1e;
    --inline-math-text: #00cc00;
    --block-math-bg: #1e1e1e;
    --block-math-text: #00cc00;
    --weblog-tag: #00cc00;
    --weblog-tag-hover: #00ff00;
    --weblog-tag-bg: #1e1e1e;
    --weblog-tag-hover-bg: #2a2a2a;
    --search-bg: #1e1e1e;
    --search-border: #444;
    --search-btn-bg: #008800;
    --search-btn-hover: #00aa00;
    --search-btn-text: #fff;
    --post-bg: #1e1e1e;
    --post-border: #333;
    --upvote-arrow: #444;
    --upvote-arrow-active: #00ff00;
    --share: #00ff00;
    --share-hover: #00ff88;
    --heading: #f1f1f1;
    --blockquote: #00ff00;
}

body {
  font-family: 'Newsreader', 'Times New Roman', Times, serif;
  font-size: 1.1em;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  position: relative;
}

main, .weblog-post {
  max-width: 800px;
  margin: 40px auto;
  background-color: var(--bg);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1), 0 1px 8px rgba(0, 0, 0, 0.06);
  padding: 40px;
  z-index: 1;
  position: relative;
  border-radius: 8px;
}

/* Responsive container */
@media (max-width: 600px) {
  body {
    padding: 1rem;
    font-size: 1em;
  }
  main, .weblog-post {
    padding: 20px;
    margin: 20px auto;
  }
}

/* Responsive image for blog posts */
img {
  max-width: 100% !important;
  height: auto !important;
  display: block; /* Helps prevent extra space below images */
  margin: 0 auto; /* Center align images by default */
}

/* Headings */
h1, h2, h3, h4, h5, h6, .page-title {
    margin: 1.5em 0 0.8em;
    line-height: 1.2;
    color: var(--heading);
}

h1 {
    font-size: 2.2rem;
    margin-top: 0;
    margin-bottom: 1rem;
}

h2 {
  font-size: 1.8rem;
  margin: 2rem 0 1rem 0;
}

h3, h4, h5, h6 {
  font-size: 1.4rem;
  margin: 1.8rem 0 0.8rem 0;
}

/* Links */
a {
    color: var(--link);
    text-decoration: none;
    transition: color 0.2s;
}

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

p {
  font-size: 1.1rem;
  margin: 0 0 1.2rem 0;
  text-align: left;
  line-height: 1.8;
}

ul, ol {
  margin: 0.8rem 0 1.2rem 1.5rem;
  line-height: 1.8;
}

li {
  margin-bottom: 0.5rem;
}

blockquote {
  margin: 1.5rem 0;
  padding: 0.8rem 1.2rem;
  border-left: 4px solid var(--blockquote);
  background: var(--code-bg);
  color: var(--text);
  border-radius: 0 4px 4px 0;
}

figure {
  margin: 2rem 0;
  text-align: center;
  max-width: 100%;
}

/* Gallery container for horizontal images */
.gallery { /* #how to use in markdown: <div class="gallery"><figure>...</figure><figure>...</figure></div> */
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  justify-content: center;
  margin: 2rem 0;
  align-items: flex-start;
}

.gallery figure {
  margin: 0;
  flex: 1 1 300px; /* Flex-grow, flex-shrink, flex-basis (min-width before wrapping) */
  max-width: 100%;
}

figcaption, time, .pdf-relative-link-path, .page-description {
  margin-top: 0.8rem;
  font-size: 0.9em;
  color: var(--muted);
  font-style: italic;
}

/* Underline style */
.underline { /* #how to use in markdown: <span class="underline">your text</span> */
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 0.2em;
  text-decoration-color: var(--link);
}

/* Search bar */
.weblog-search-container {
  margin: 1.5rem 0;
}

.weblog-search-container form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  width: 100%;
}

#weblog-search {
  flex: 1;
  min-width: 0; /* Allows flex item to shrink below content size */
  padding: 0.6rem 1rem;
  font-size: 1rem;
  border: 1px solid var(--search-border);
  border-radius: 6px;
  background-color: var(--search-bg);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

#weblog-search:focus {
  outline: none;
  border-color: var(--link);
  box-shadow: 0 0 0 2px rgba(0, 119, 0, 0.2);
}

#weblog-search-btn {
  padding: 0.6rem 1.5rem;
  background-color: var(--search-btn-bg);
  color: var(--search-btn-text);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  transition: background-color 0.2s;
}

#weblog-search-btn:hover {
  background-color: var(--search-btn-hover);
}

@media (max-width: 600px) {
  #weblog-search-btn {
    padding: 0.6rem 1rem;
  }
}

/* Tags */
.weblog-tags {
  margin: 1.5rem 0;
  line-height: 2;
  font-size: 0.95rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.weblog-tag {
  display: inline-block;
  background: var(--weblog-tag-bg);
  color: var(--weblog-tag);
  border: none;
  border-radius: 4px;
  padding: 0.2rem 0.6rem;
  margin: 0;
  font-size: 0.85em;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.weblog-tag:hover, .weblog-tag.selected {
  background: var(--weblog-tag-hover-bg);
  color: var(--weblog-tag-hover);
  text-decoration: none;
}

.weblog-list {
  list-style: none;
  padding: 0;
  margin: 1.5rem 0;
}

.weblog-list li {
  margin: 0.5rem 0;
  padding: 0;
  background-color: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.weblog-list li:hover {
  transform: none;
  box-shadow: none;
}

.weblog-list li::before {
  content: "▪";
  font-size: 0.8em;
  margin-right: 0.6em;
  color: var(--text);
  flex-shrink: 0;
}

.weblog-list li a {
  font-weight: 500;
  color: var(--link);
  text-decoration: none;
  display: inline;
  margin-right: auto;
  padding-right: 1rem;
}

.weblog-date, .weblog-list .weblog-date {
  display: inline;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0;
  white-space: nowrap;
}


/* Code blocks */
pre, code {
  font-family: 'Fira Mono', 'Consolas', 'Menlo', 'Monaco', 'Liberation Mono', monospace;
  font-size: 1em;
}

pre {
  background: var(--pre-bg);
  border-radius: 6px;
  padding: 1.2em;
  margin: 1.5rem 0;
  overflow-x: auto;
  border: 1px solid var(--post-border);
  box-shadow: var(--pre-shadow);
  line-height: 1.6;
  font-size: 0.95em;
}

code, .code {
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: 4px;
  padding: 0.15em 0.4em;
  line-height: 1.8;
  letter-spacing: 0.03em;
  font-size: 1.03em;
  word-spacing: 0.10em;
}

pre code {
  background: none;
  color: inherit;
  padding: 0;
}

div.codehilite.codehilite-container {
    position: relative;
}

.code-toolbar {
    position: absolute;
    top: 0.5em;
    right: 0.5em;
    display: flex;
    gap: 0.8em;
    align-items: center;
    background-color: var(--code-bg);
    border: 1px solid var(--muted);
    padding: 4px 8px;
    border-radius: 5px;
    opacity: 0;
    z-index: 10;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.codehilite-container:hover .code-toolbar {
    opacity: 1;
}

.code-toolbar .language-name {
    font-size: 0.8em;
    color: var(--muted);
    font-family: 'Fira Mono', 'Consolas', 'Menlo', 'Monaco', 'Liberation Mono', monospace;
}

.code-toolbar .copy-btn, .code-toolbar .anchor-link {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 0;
    display: inline-flex;
    align-items: center;
}

.code-toolbar .copy-btn:hover, .code-toolbar .anchor-link:hover {
    color: var(--text);
}

.code-toolbar .anchor-link {
    text-decoration: none;
    font-size: 1.2em;
}

.code-toolbar svg {
    pointer-events: none;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-image: url('/raster.svg');
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center center;
    z-index: -2;
}

/* Remove background SVG for mobile devices */
@media (max-width: 768px) {
  body::before {
    display: none;
  }
}
