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

/* Variables */
:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --color-bg: #ffffff;
  --color-bg-secondary: #f8f9fa;
  --color-text: #1a1a1a;
  --color-text-secondary: #6b7280;
  --color-text-tertiary: #9ca3af;
  --color-border: #e5e7eb;
  --color-link: #2563eb;
  --color-link-hover: #1d4ed8;
  --color-code-bg: #f3f4f6;
  --color-accent: #2563eb;
  --max-width: 720px;
  --header-height: 60px;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0f172a;
    --color-bg-secondary: #1e293b;
    --color-text: #f1f5f9;
    --color-text-secondary: #94a3b8;
    --color-text-tertiary: #64748b;
    --color-border: #334155;
    --color-code-bg: #1e293b;
    --color-link: #60a5fa;
    --color-link-hover: #93c5fd;
    --color-accent: #60a5fa;
  }
}

/* Base */
html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

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

/* Container */
.container {
  width: 100%;
  padding-left: 10.5%;
  max-width: calc(12.5% + 2500px);
  margin: 0 auto;
}

/* Header */
.header {
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 3rem;
}

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
}

.nav-logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -0.025em;
}

.nav-logo:hover {
  color: var(--color-link);
}

.nav-links {
  display: flex;
  gap: 2rem;
}

.nav-links a {
  color: var(--color-text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
}

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

.search-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-secondary);
  padding: 0.5rem;
  border-radius: 0.375rem;
  transition: background-color 0.2s ease;
}

.search-toggle:hover {
  background-color: var(--color-bg-secondary);
  color: var(--color-text);
}

/* Search */
.search-container {
  position: relative;
  margin-top: 1rem;
  display: none;
}

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

.search-input {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-family: var(--font-sans);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  background-color: var(--color-bg);
  color: var(--color-text);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 0.5rem;
  background-color: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
  max-height: 400px;
  overflow-y: auto;
  z-index: 100;
}

.search-result-item {
  padding: 1rem;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  transition: background-color 0.2s ease;
}

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

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

.search-result-title {
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 0.25rem;
}

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

/* Main */
.main {
  min-height: calc(100vh - 300px);
}

/* Hero */
.hero {
  padding: 4rem 0;
  text-align: center;
}

.hero-title {
  font-size: 3rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin-bottom: 1rem;
  line-height: 1.2;
}

.hero-subtitle {
  font-size: 1.25rem;
  color: var(--color-text-secondary);
  max-width: 500px;
  margin: 0 auto;
}

/* Post List */
.post-list {
  list-style: none;
}

.post-list-item {
  padding: 2rem 0;
  border-bottom: 1px solid var(--color-border);
}

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

.post-list-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.post-list-title a {
  color: var(--color-text);
}

.post-list-title a:hover {
  color: var(--color-link);
}

.post-list-meta {
  font-size: 0.875rem;
  color: var(--color-text-tertiary);
  margin-bottom: 0.75rem;
}

.post-list-excerpt {
  color: var(--color-text-secondary);
  line-height: 1.7;
}

/* Post Layout - Tufte-style (Content | Sidenotes in margin) */
.post {
  padding: 4rem 0;
}

.post-header {
  margin-bottom: 3rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--color-border);
}

.post-title {
  font-size: 2.2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 1rem;
  line-height: 1.2;
}

.post-meta {
  font-size: 0.9rem;
  color: var(--color-text-tertiary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.post-divider {
  color: var(--color-border);
}

/* Main article content - Tufte style */
.post-content {
  width: 65%;
  position: relative;
  font-size: 1.0625rem;
  line-height: 1.65;
  margin-left: 0px;
}

.post-content h1,
.post-content h2,
.post-content h3,
.post-content h4 {
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  font-weight: 600;
  line-height: 1.3;
  scroll-margin-top: 2rem;
}

.post-content h1 { font-size: 1.75rem; }
.post-content h2 { font-size: 1.4rem; }
.post-content h3 { font-size: 1.15rem; font-style: italic; }

.post-content p {
  margin-bottom: 1.2rem;
  text-align: justify;
}

.post-content a {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.post-content ul,
.post-content ol {
  margin-bottom: 1.4rem;
  padding-left: 6%;
}

.post-content li {
  margin-bottom: 0.5em;
}

.post-content blockquote {
  margin: 1.5rem 0;
  padding: 0.5rem 1rem;
  border-left: 3px solid var(--color-accent);
  font-size: 1rem;
  line-height: 1.6;
}

.post-content blockquote p:last-child {
  margin-bottom: 0;
}

.post-content code {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  background-color: var(--color-code-bg);
  padding: 0.15em 0.35em;
  border-radius: 3px;
}

.post-content pre {
  margin: 1.5rem 0;
  padding: 0.75rem 1rem;
  background-color: var(--color-code-bg);
  border-radius: 4px;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.5;
}

.post-content pre code {
  background: none;
  padding: 0;
  font-size: 0.85rem;
}

/* Code block with copy button */
.code-block-wrapper {
  position: relative;
}

.post-content pre {
  position: relative;
  padding-top: 2.5rem;
}

.copy-button {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.35rem 0.75rem;
  font-size: 0.75rem;
  font-family: var(--font-sans);
  font-weight: 500;
  color: var(--color-text-secondary);
  background-color: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 1;
}

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

.post-content img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  margin: 2rem 0;
}

.post-content hr {
  margin: 3rem 0;
  border: none;
  border-top: 1px solid var(--color-border);
}

/* Sidenotes / Footnotes - Tufte style float in margin */
.post-content aside.footnote {
  float: right;
  clear: right;
  width: 18vw;
  max-width: 240px;
  margin-right: -18vw;
  margin-left: 1rem;
  margin-top: 0;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--color-text-secondary);
  position: relative;
  break-inside: avoid-page;
}

.footnote-number {
  display: inline-block;
  width: 1.3rem;
  height: 1.3rem;
  line-height: 1.3rem;
  text-align: center;
  background-color: var(--color-accent);
  color: white;
  border-radius: 50%;
  font-size: 0.65rem;
  font-weight: 600;
  margin-right: 0.4rem;
  vertical-align: middle;
}

.post-content aside.footnote p {
  margin-bottom: 0.5rem;
  text-align: left;
  font-size: 0.95rem;
}

.post-content aside.footnote p:last-child {
  margin-bottom: 0;
}

.post-content aside.footnote img {
  max-width: 100%;
  height: auto;
  margin: 0.5rem 0;
  border-radius: 3px;
}

/* Inline footnote refs */
.post-content .footnote-ref {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-accent);
  vertical-align: super;
  line-height: 1;
  margin-left: 0.1em;
  text-decoration: none;
}

/* Sidebar Footnotes Container (for JS-moved footnotes) */
.post-sidebar {
  display: none;
}

/* Table of Contents - Inline at top of content */
.toc-inline {
  margin-bottom: 2rem;
  padding: 1rem 1.25rem;
  background-color: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: 6px;
}

.toc-inline-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-tertiary);
  margin-bottom: 0.75rem;
}

.toc-inline-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.toc-link {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  text-decoration: none;
  transition: color 0.2s ease;
  line-height: 1.4;
  display: block;
}

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

.toc-level-h1 { font-weight: 600; }
.toc-level-h2 { padding-left: 0; }
.toc-level-h3 { padding-left: 0.75rem; font-size: 0.75rem; }
.toc-level-h4 { padding-left: 1.5rem; font-size: 0.7rem; }

.footnote-content p {
  margin: 0;
}

/* Inline footnote refs in content */
.post-content .footnote-ref {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--color-accent);
  vertical-align: super;
  line-height: 1;
  margin-left: 0.1em;
  text-decoration: none;
}

/* Post Footer */
.post-footer {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--color-border);
}

.post-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 2rem;
}

.tag {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.25em 0.75em;
  background-color: var(--color-bg-secondary);
  color: var(--color-text-secondary);
  border-radius: 9999px;
  border: 1px solid var(--color-border);
}

.post-navigation {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.nav-link {
  padding: 0.75rem 1rem;
  background-color: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.nav-link:hover {
  background-color: var(--color-border);
  color: var(--color-text);
}

/* Comments */
.comments-section {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--color-border);
}

.comments-section h2 {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
}

/* Archive */
.archive-header {
  margin-bottom: 3rem;
}

.archive-title {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.archive-subtitle {
  color: var(--color-text-secondary);
}

.archive-list {
  list-style: none;
}

.archive-section {
  margin-bottom: 3rem;
}

.archive-section:last-child {
  margin-bottom: 0;
}

.archive-dir-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: capitalize;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border);
}

.archive-list-item {
  display: flex;
  align-items: baseline;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--color-border);
}

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

.archive-date {
  font-size: 0.875rem;
  color: var(--color-text-tertiary);
  font-family: var(--font-mono);
  min-width: 100px;
}

.archive-title {
  font-size: 1rem;
  font-weight: 500;
}

.archive-title a {
  color: var(--color-text);
}

.archive-title a:hover {
  color: var(--color-link);
}

/* About */
.about {
  padding: 2rem 0;
}

.about h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 2rem;
}

.about-content {
  font-size: 1.125rem;
  line-height: 1.8;
}

.about-content p {
  margin-bottom: 1.5em;
}

/* Footer */
.footer {
  margin-top: 4rem;
  padding: 2rem 0;
  border-top: 1px solid var(--color-border);
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.875rem;
  color: var(--color-text-secondary);
}

.footer-links {
  display: flex;
  gap: 1.5rem;
}

.footer-links a {
  color: var(--color-text-secondary);
}

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

/* Responsive - Tufte style */
@media (max-width: 1200px) {
  .post-content aside.footnote {
    width: 20vw;
    margin-right: -20vw;
  }
}

@media (max-width: 1000px) {
  .container {
    padding-left: 5%;
    max-width: calc(5% + 1200px);
  }

  .post-content {
    width: 65%;
  }

  .post-content aside.footnote {
    width: 28vw;
    margin-right: -28vw;
  }

  .post-toc {
    width: 150px;
  }
}

@media (max-width: 760px) {
  .container {
    padding-left: 0;
    padding-right: 0;
  }

  .post-content {
    width: 90%;
    margin: 0 auto;
    float: none;
  }

  .post-content aside.footnote {
    float: none;
    width: 100%;
    max-width: 100%;
    margin: 1.5rem 0;
    margin-left: 0;
    padding: 1rem;
    background-color: var(--color-bg-secondary);
    border-radius: 4px;
    border: 1px solid var(--color-border);
    font-size: 0.95rem;
  }

  .post-toc {
    position: static;
    float: none;
    width: 100%;
    max-height: none;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--color-border);
  }

  .post-toc .toc-nav {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .post-title {
    font-size: 1.8rem;
  }

  .post-content {
    font-size: 1.1rem;
    line-height: 1.7;
  }

  .post-content h1 { font-size: 1.7rem; }
  .post-content h2 { font-size: 1.4rem; }
  .post-content h3 { font-size: 1.2rem; }
}

@media (max-width: 640px) {
  .nav-links {
    gap: 1rem;
  }

  .hero-title {
    font-size: 2rem;
  }

  .hero-subtitle {
    font-size: 1rem;
  }

  .post-navigation {
    flex-direction: column;
  }

  .footer-content {
    flex-direction: column;
    gap: 1rem;
    text-align: center;
  }
}

/* Page transitions */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.main {
  animation: fadeIn 0.3s ease;
}

/* Lightbox */
#lightbox {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.9);
  z-index: 9999;
  justify-content: center;
  align-items: center;
  cursor: zoom-out;
}

#lightbox.active {
  display: flex;
}

.lightbox-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
}

.lightbox-img {
  max-width: 100%;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 4px;
}

.lightbox-close {
  position: absolute;
  top: -2rem;
  right: 0;
  background: none;
  border: none;
  color: white;
  font-size: 2rem;
  cursor: pointer;
  padding: 0.5rem;
  line-height: 1;
  opacity: 0.8;
  transition: opacity 0.2s;
}

.lightbox-close:hover {
  opacity: 1;
}
