/* ==========================================================================
   Monochrome — Minimal Blog with Dark Mode, Syntax Highlighting & LaTeX
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,300..700;1,300..700&family=Newsreader:ital,opsz,wght@0,6..72,400..700;1,6..72,400..700&display=swap');

/* Color & Typography Tokens */
:root {
  --font-serif: 'Newsreader', 'Playfair Display', 'EB Garamond', 'Georgia', 'Times New Roman', serif;
  --font-mono: 'JetBrains Mono', 'IBM Plex Mono', 'Fira Code', 'SFMono-Regular', Menlo, Monaco, Consolas, 'Courier New', monospace;

  /* Light Theme */
  --bg: #ffffff;
  --fg: #0a0a0a;
  --muted: #666666;
  --border: #0a0a0a;
  --border-subtle: #d8d8d8;
  --inv-bg: #0a0a0a;
  --inv-fg: #ffffff;

  /* Code Block Palette (Light Mode - Clean & Colorful) */
  --code-bg: #f8f9fa;
  --code-header-bg: #f0f2f5;
  --code-border: #d0d7de;
  --code-fg: #24292f;
  --syntax-comment: #6e7781;
  --syntax-keyword: #cf222e;
  --syntax-string: #116329;
  --syntax-number: #0550ae;
  --syntax-func: #8250df;
  --syntax-class: #953800;
  --syntax-tag: #116329;
  --syntax-attr: #0550ae;
  --syntax-operator: #24292f;
}

[data-theme="dark"] {
  /* Dark Theme */
  --bg: #0c0d0e;
  --fg: #f0f0f0;
  --muted: #8c8c8c;
  --border: #f0f0f0;
  --border-subtle: #2b2e33;
  --inv-bg: #f0f0f0;
  --inv-fg: #0c0d0e;

  /* Code Block Palette (Dark Mode - Vibrant Neon / One Dark) */
  --code-bg: #14161a;
  --code-header-bg: #1a1e24;
  --code-border: #2c313a;
  --code-fg: #abb2bf;
  --syntax-comment: #7f848e;
  --syntax-keyword: #c678dd;
  --syntax-string: #98c379;
  --syntax-number: #d19a66;
  --syntax-func: #61afef;
  --syntax-class: #e5c07b;
  --syntax-tag: #e06c75;
  --syntax-attr: #d19a66;
  --syntax-operator: #56b6c2;
}

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

html {
  font-size: 16px;
  background-color: var(--bg);
  color: var(--fg);
  transition: background-color 0.15s ease, color 0.15s ease;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-mono);
  font-size: 0.9375rem; /* 15px */
  line-height: 1.7;
  color: var(--fg);
  background-color: var(--bg);
  min-height: 100vh;
}

/* Headings: Always Serif */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-serif);
  font-weight: 500;
  color: var(--fg);
  line-height: 1.25;
  letter-spacing: -0.015em;
}

/* Text, Controls & Everything Else: Always Monospace */
p, span, div, a, li, blockquote, code, pre, th, td, button {
  font-family: var(--font-mono);
}

/* Links */
a {
  color: var(--fg);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

a:hover {
  text-decoration-thickness: 2px;
}

/* Layout Container */
.site-container {
  max-width: 760px;
  margin: 0 auto;
  padding: 40px 24px 64px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.site-header {
  margin-bottom: 48px;
}

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-bottom: 16px;
  flex-wrap: wrap;
  gap: 16px;
}

.site-brand {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  font-weight: 600;
  text-decoration: none;
  letter-spacing: -0.02em;
}

.site-brand:hover {
  text-decoration: underline;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Theme Toggle Button */
.theme-toggle {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 4px 10px;
  font-size: 0.8125rem;
  letter-spacing: 0.05em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-transform: uppercase;
}

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

.header-line, .footer-line {
  border-top: 1px solid var(--border);
  width: 100%;
}

/* Main Content Area */
.site-main {
  flex: 1;
}

/* Footer */
.site-footer {
  margin-top: 64px;
}

/* ==========================================================================
   View: Post List
   ========================================================================== */
.post-list-header {
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.post-count {
  font-size: 0.8125rem;
  color: var(--muted);
  letter-spacing: 0.05em;
}

.post-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.post-item {
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 32px;
}

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

.post-item-meta {
  font-size: 0.8125rem;
  color: var(--muted);
  margin-bottom: 8px;
  display: flex;
  gap: 12px;
}

.post-item-title {
  font-size: 1.4rem;
  margin-bottom: 8px;
}

.post-item-title a {
  text-decoration: none;
  color: var(--fg);
}

.post-item-title a:hover {
  text-decoration: underline;
}

.post-item-excerpt {
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.6;
}

.empty-state {
  padding: 48px 0;
  text-align: center;
  color: var(--muted);
}

/* ==========================================================================
   View: Single Post & Markdown Content
   ========================================================================== */
.post-view-header {
  margin-bottom: 32px;
}

.back-link {
  display: inline-block;
  font-size: 0.8125rem;
  text-decoration: none;
  margin-bottom: 24px;
}

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

.single-post-title {
  font-size: 2.25rem;
  font-weight: 600;
  margin-bottom: 12px;
  line-height: 1.25;
}

.single-post-meta {
  font-size: 0.8125rem;
  color: var(--muted);
  margin-bottom: 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.single-post-divider {
  border-top: 1px solid var(--border);
  margin-bottom: 32px;
}

/* Markdown Rendered Typography */
.markdown-body {
  line-height: 1.75;
}

.markdown-body h1 {
  font-size: 1.85rem;
  margin: 2.25rem 0 1rem;
}

.markdown-body h2 {
  font-size: 1.5rem;
  margin: 2.25rem 0 0.875rem;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-subtle);
}

.markdown-body h3 {
  font-size: 1.25rem;
  margin: 1.75rem 0 0.75rem;
}

.markdown-body h4, 
.markdown-body h5, 
.markdown-body h6 {
  font-size: 1.05rem;
  margin: 1.25rem 0 0.5rem;
}

.markdown-body p {
  margin-bottom: 1.25rem;
}

.markdown-body ul, 
.markdown-body ol {
  margin-bottom: 1.25rem;
  padding-left: 1.75rem;
}

.markdown-body li {
  margin-bottom: 0.375rem;
}

.markdown-body li > ul, 
.markdown-body li > ol {
  margin-top: 0.375rem;
  margin-bottom: 0.375rem;
}

.markdown-body blockquote {
  border-left: 2px solid var(--border);
  padding: 8px 0 8px 16px;
  margin: 1.5rem 0;
  font-style: italic;
  color: var(--fg);
}

.markdown-body blockquote p:last-child {
  margin-bottom: 0;
}

/* Inline Code */
.markdown-body code {
  font-size: 0.85em;
  padding: 0.15em 0.35em;
  background-color: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 2px;
  color: var(--code-fg);
}

/* ==========================================================================
   Colored Code Blocks & Syntax Highlighting
   ========================================================================== */
.code-block-wrapper {
  margin: 1.75rem 0;
  border: 1px solid var(--code-border);
  border-radius: 4px;
  overflow: hidden;
  background-color: var(--code-bg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background-color: var(--code-header-bg);
  border-bottom: 1px solid var(--code-border);
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  color: var(--muted);
  user-select: none;
}

.code-lang {
  text-transform: uppercase;
  font-weight: 600;
  font-size: 0.7rem;
}

.copy-code-btn {
  background: transparent;
  border: 1px solid var(--code-border);
  color: var(--fg);
  padding: 2px 8px;
  font-size: 0.7rem;
  text-transform: uppercase;
  cursor: pointer;
  letter-spacing: 0.05em;
  border-radius: 2px;
  transition: all 0.1s ease;
}

.copy-code-btn:hover {
  background-color: var(--inv-bg);
  color: var(--inv-fg);
}

.copy-code-btn.copied {
  background-color: var(--inv-bg);
  color: var(--inv-fg);
}

.markdown-body pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  background-color: var(--code-bg);
  line-height: 1.55;
  font-size: 0.875rem;
}

.markdown-body pre code {
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
  font-size: inherit;
  color: var(--code-fg);
  display: block;
}

/* Syntax Highlighting Tokens (Vibrant & Legible) */
.hljs-comment,
.hljs-quote {
  color: var(--syntax-comment);
  font-style: italic;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-doctag {
  color: var(--syntax-keyword);
  font-weight: 600;
}

.hljs-string,
.hljs-regexp,
.hljs-addition {
  color: var(--syntax-string);
}

.hljs-number,
.hljs-literal,
.hljs-attr,
.hljs-selector-attr,
.hljs-selector-class {
  color: var(--syntax-number);
}

.hljs-title,
.hljs-title.function_,
.hljs-section {
  color: var(--syntax-func);
  font-weight: 600;
}

.hljs-class .hljs-title,
.hljs-title.class_,
.hljs-type,
.hljs-built_in {
  color: var(--syntax-class);
}

.hljs-name,
.hljs-tag,
.hljs-deletion {
  color: var(--syntax-tag);
}

.hljs-variable,
.hljs-template-variable {
  color: var(--syntax-number);
}

.hljs-meta {
  color: var(--syntax-comment);
}

.hljs-operator,
.hljs-punctuation {
  color: var(--syntax-operator);
}

.hljs-subst {
  color: var(--code-fg);
}

/* ==========================================================================
   LaTeX Math Styling (KaTeX)
   ========================================================================== */
.katex {
  font-size: 1.05em;
  color: var(--fg);
}

.katex-display-wrapper {
  margin: 1.5rem 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 8px 0;
  text-align: center;
}

.katex-display {
  margin: 0 !important;
}

/* ==========================================================================
   Mermaid Diagrams
   ========================================================================== */
.mermaid {
  margin: 2rem 0;
  display: flex;
  justify-content: center;
  background-color: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 4px;
  padding: 1.5rem 1rem;
  overflow-x: auto;
}

.mermaid svg {
  max-width: 100%;
  height: auto;
}

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

.markdown-body th, 
.markdown-body td {
  border: 1px solid var(--border-subtle);
  padding: 8px 12px;
  text-align: left;
}

.markdown-body th {
  font-weight: 700;
  border-bottom: 2px solid var(--border);
  background-color: var(--code-header-bg);
}

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

/* Images */
.markdown-body img {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--border);
  margin: 1.5rem 0;
}

/* Checkboxes / Task lists */
.markdown-body input[type="checkbox"] {
  margin-right: 8px;
  accent-color: var(--fg);
}

/* Post Actions Footer */
.post-actions-footer {
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.8125rem;
}

/* Buttons */
.btn {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  letter-spacing: 0.05em;
  padding: 8px 16px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}

.btn:hover {
  background-color: var(--inv-bg);
  color: var(--inv-fg);
}

.btn-sm {
  padding: 4px 8px;
  font-size: 0.75rem;
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .site-container {
    padding: 24px 16px 48px;
  }

  .site-brand {
    font-size: 1.5rem;
  }

  .single-post-title {
    font-size: 1.75rem;
  }
}
