/* APS Journal Style Overrides */

/* 1. Justified text alignment */
body {
  text-align: justify;
  -webkit-hyphens: auto;
  -moz-hyphens: auto;
  -ms-hyphens: auto;
  hyphens: auto;
}

.post p,
.post li,
.post blockquote {
  text-align: justify;
}

/* Drop cap styling */
.post .drop-cap {
  font-size: 5.8em;
  float: left;
  line-height: 1;
  margin: -0.09em 0.03em -0.1em -0.05em;
}

@media (max-width: 899px) {
  .post .drop-cap {
    font-size: 5.2em;
  }
}

/* 2. Two-column layout for article content */
@media (min-width: 900px) {
  .post-content {
    column-count: 2;
    column-gap: 2.5em;
    column-rule: 1px solid #e5e5e5;
  }

  /* Single-column mode (per-post override) */
  .post-content.single-column {
    column-count: 1;
  }

  /* Code blocks span both columns by default */
  .post-content .highlight,
  .post-content pre {
    column-span: all;
  }

  /* Wide figures/plots span both columns */
  .post-content figure.wide,
  .post-content .wide {
    column-span: all;
  }

  /* Inline figures stay in their column (default) */
  .post-content figure:not(.wide),
  .post-content .plot-container:not(.wide) {
    break-inside: avoid;
    max-width: 100%;
  }

  .post-content figure:not(.wide) img {
    max-width: 100%;
    width: 100%;
    height: auto;
    margin-left: 0;
    margin-right: 0;
  }

  /* Prevent orphaned elements at column breaks */
  .post-content p {
    orphans: 3;
    widows: 3;
  }

  /* Wider container to accommodate two columns */
  main,
  .post {
    max-width: 52em;
  }
}

/* 3. Numbered footnotes - APS superscript style */
.footnote-ref {
  font-size: 0.75em;
  vertical-align: super;
  line-height: 0;
  text-decoration: none;
}

/* Style the footnotes section at the bottom */
.footnotes {
  column-span: all;
  margin-top: 2em;
  padding-top: 1em;
  border-top: 1px solid #e5e5e5;
  font-size: 0.9em;
}

.footnotes ol {
  padding-left: 1.5em;
}

.footnotes li {
  margin-bottom: 0.5em;
}

/* Back-reference link in footnotes */
.footnotes .footnote-backref {
  font-size: 0.8em;
  text-decoration: none;
  margin-left: 0.3em;
}

/* 4. KaTeX equation styling */
.katex-display {
  margin: 1em 0;
  overflow: visible;
  padding: 0.2em 0;
}

/* Inline math styling */
.katex {
  font-size: 1.05em;
}

/* Plot container and caption styling */
.plot-container {
  display: block;
  width: 100%;
}

.plot-container.wide {
  display: block;
  width: 100%;
  text-align: center;
}

.plot-caption {
  display: block;
  text-align: center !important;
  font-size: 0.9em;
  font-style: italic;
  margin-top: 0.5em;
  margin-left: auto;
  margin-right: auto;
}

/* APS-style ruled tables */
.post-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.5em 0;
  font-size: 0.95em;
}

.post-content table thead {
  border-top: 2px solid currentColor;
  border-bottom: 1px solid currentColor;
}

.post-content table tbody {
  border-bottom: 2px solid currentColor;
}

.post-content table th,
.post-content table td {
  padding: 0.5em 0.75em;
  text-align: left;
}

.post-content table th {
  font-weight: bold;
}

.post-content table code {
  font-size: 0.9em;
}

/* Table container for wide/narrow control */
.table-container {
  display: block;
  width: 100%;
  margin: 1.5em 0;
}

.table-container table {
  margin: 0;
}

.table-caption {
  text-align: center !important;
  font-size: 0.9em;
  font-style: italic;
  margin-top: 0.5em;
}

@media (min-width: 900px) {
  .table-container.wide {
    column-span: all;
  }

  .table-container:not(.wide) {
    break-inside: avoid;
    max-width: 100%;
  }
}

/* Code container for wide/narrow control */
.code-container {
  display: block;
  width: 100%;
  margin: 1.5em 0;
}

.code-container .highlight,
.code-container pre {
  margin: 0;
}

.code-caption {
  text-align: center !important;
  font-size: 0.9em;
  font-style: italic;
  margin-top: 0.5em;
}

@media (min-width: 900px) {
  .code-container.wide {
    column-span: all;
  }

  .code-container:not(.wide) {
    break-inside: avoid;
    max-width: 100%;
  }

  /* Override default code block spanning */
  .post-content .code-container .highlight,
  .post-content .code-container pre {
    column-span: none;
  }
}

/* Code block horizontal scrolling */
.post-content pre,
.post-content .highlight pre {
  overflow-x: auto;
  max-width: 100%;
}

.post-content .highlight {
  overflow-x: auto;
  max-width: 100%;
}

/* Column break (single) */
.column-break {
  break-before: column;
}

/* Section break (double) - spans both columns */
.section-break {
  column-span: all;
  width: 100%;
  margin: 2em 0 1em;
}

.section-break-rule {
  border: none;
  border-top: 2px solid currentColor;
  margin: 0 0 1em;
  opacity: 0.4;
}

.section-break h2.section-break-title {
  text-align: center !important;
  margin: 0 !important;
  font-size: 2.2em !important;
  line-height: 1.2 !important;
  font-weight: 800;
}

/* Dark mode adjustments */
@media (prefers-color-scheme: dark) {
  .post-content {
    column-rule-color: #333;
  }

  .footnotes {
    border-top-color: #333;
  }
}

/* ============================================
   Table of Contents Sidebar
   ============================================ */

/* TOC Sidebar container */
.toc-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: 280px;
  background: #fafafa;
  border-right: 1px solid #e5e5e5;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  z-index: 1000;
  display: flex;
  flex-direction: column;
}

.toc-sidebar.open {
  transform: translateX(0);
}

/* TOC toggle button */
.toc-toggle {
  position: absolute;
  top: 50%;
  right: -40px;
  transform: translateY(-50%);
  width: 40px;
  height: 80px;
  background: #fafafa;
  border: 1px solid #e5e5e5;
  border-left: none;
  border-radius: 0 8px 8px 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease;
}

.toc-toggle:hover {
  background: #f0f0f0;
}

/* Toggle icon (hamburger-style lines) */
.toc-toggle-icon {
  display: block;
  width: 18px;
  height: 2px;
  background: #333;
  position: relative;
}

.toc-toggle-icon::before,
.toc-toggle-icon::after {
  content: '';
  display: block;
  width: 18px;
  height: 2px;
  background: #333;
  position: absolute;
  left: 0;
  transition: transform 0.2s ease;
}

.toc-toggle-icon::before {
  top: -6px;
}

.toc-toggle-icon::after {
  top: 6px;
}

/* Transform to X when open */
.toc-sidebar.open .toc-toggle-icon {
  background: transparent;
}

.toc-sidebar.open .toc-toggle-icon::before {
  transform: translateY(6px) rotate(45deg);
}

.toc-sidebar.open .toc-toggle-icon::after {
  transform: translateY(-6px) rotate(-45deg);
}

/* TOC content area */
.toc-content {
  padding: 2em 1.5em;
  overflow-y: auto;
  flex: 1;
  margin-top: 60px; /* Space for header */
}

.toc-title {
  font-size: 1.1em;
  font-weight: 700;
  margin: 0 0 1em 0;
  padding-bottom: 0.5em;
  border-bottom: 1px solid #e5e5e5;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Style the TOC nav */
.toc-content #toc-list {
  font-size: 0.9em;
  line-height: 1.6;
  text-align: left;
}

.toc-content #toc-list ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-content #toc-list > ul > li {
  margin-bottom: 0.75em;
}

.toc-content #toc-list li.toc-h3 {
  padding-left: 1em;
  margin-bottom: 0.4em;
}

.toc-content #toc-list li.toc-h4 {
  padding-left: 2em;
  margin-bottom: 0.3em;
  font-size: 0.9em;
}

.toc-content #toc-list a {
  color: #555;
  text-decoration: none;
  display: block;
  padding: 0.2em 0;
  transition: color 0.2s ease;
}

.toc-content #toc-list a:hover {
  color: #000;
}

/* Section numbers */
.toc-content #toc-list .toc-number {
  font-weight: 600;
  min-width: 2em;
  display: inline-block;
}

/* Active section highlighting */
.toc-content #toc-list a.active {
  color: #000;
  font-weight: 600;
}

.toc-content #toc-list a.active .toc-number {
  font-weight: 700;
}

/* Title link at top of TOC */
.toc-content #toc-list li.toc-title-link {
  margin-bottom: 1em;
  padding-bottom: 0.75em;
  border-bottom: 1px solid #e5e5e5;
}

.toc-content #toc-list li.toc-title-link a {
  font-weight: 400;
  font-style: italic;
}

/* Footnotes link at bottom of TOC */
.toc-content #toc-list li.toc-footnotes-link {
  margin-top: 1em;
  padding-top: 0.75em;
  border-top: 1px solid #e5e5e5;
}

.toc-content #toc-list li.toc-footnotes-link a {
  font-style: italic;
}

/* Main content shift when TOC is open */
body {
  transition: padding-left 0.3s ease;
}

body.toc-open {
  padding-left: 280px;
}

/* Hide TOC on small screens, show toggle only on larger screens */
@media (max-width: 1200px) {
  .toc-sidebar {
    display: none;
  }
}

/* Dark mode for TOC */
@media (prefers-color-scheme: dark) {
  .toc-sidebar {
    background: #1a1a1a;
    border-right-color: #333;
  }

  .toc-toggle {
    background: #1a1a1a;
    border-color: #333;
  }

  .toc-toggle:hover {
    background: #252525;
  }

  .toc-toggle-icon,
  .toc-toggle-icon::before,
  .toc-toggle-icon::after {
    background: #ccc;
  }

  .toc-sidebar.open .toc-toggle-icon {
    background: transparent;
  }

  .toc-title {
    border-bottom-color: #333;
  }

  .toc-content #toc-list a {
    color: #aaa;
  }

  .toc-content #toc-list a:hover,
  .toc-content #toc-list a.active {
    color: #fff;
  }
}

/* ============================================
   Manual theme toggle overrides
   ============================================ */

/* Core theme colors for manual dark mode */
html[data-theme="dark"] {
  background: #222;
}

html[data-theme="dark"],
html[data-theme="dark"] body {
  color: #bbb;
}

/* Core theme colors for manual light mode (override system dark preference) */
html[data-theme="light"] {
  background: #fff;
}

html[data-theme="light"],
html[data-theme="light"] body {
  color: #222;
}

/* Dark mode via data-theme attribute */
[data-theme="dark"] .post-content {
  column-rule-color: #333;
}

[data-theme="dark"] .footnotes {
  border-top-color: #333;
}

/* Light mode overrides (override system dark preference) */
[data-theme="light"] .post-content {
  column-rule-color: #e5e5e5;
}

[data-theme="light"] .footnotes {
  border-top-color: #e5e5e5;
}

[data-theme="dark"] .toc-sidebar {
  background: #1a1a1a;
  border-right-color: #333;
}

[data-theme="dark"] .toc-toggle {
  background: #1a1a1a;
  border-color: #333;
}

[data-theme="dark"] .toc-toggle:hover {
  background: #252525;
}

[data-theme="dark"] .toc-toggle-icon,
[data-theme="dark"] .toc-toggle-icon::before,
[data-theme="dark"] .toc-toggle-icon::after {
  background: #ccc;
}

[data-theme="dark"] .toc-sidebar.open .toc-toggle-icon {
  background: transparent;
}

[data-theme="dark"] .toc-title {
  border-bottom-color: #333;
}

[data-theme="dark"] .toc-content #toc-list a {
  color: #aaa;
}

[data-theme="dark"] .toc-content #toc-list a:hover,
[data-theme="dark"] .toc-content #toc-list a.active {
  color: #fff;
}

[data-theme="dark"] .toc-content #toc-list li.toc-title-link,
[data-theme="dark"] .toc-content #toc-list li.toc-footnotes-link {
  border-color: #333;
}

/* Light mode overrides for TOC (override system dark preference) */
[data-theme="light"] .toc-sidebar {
  background: #fafafa;
  border-right-color: #e5e5e5;
}

[data-theme="light"] .toc-toggle {
  background: #fafafa;
  border-color: #e5e5e5;
}

[data-theme="light"] .toc-toggle:hover {
  background: #f0f0f0;
}

[data-theme="light"] .toc-toggle-icon,
[data-theme="light"] .toc-toggle-icon::before,
[data-theme="light"] .toc-toggle-icon::after {
  background: #333;
}

[data-theme="light"] .toc-sidebar.open .toc-toggle-icon {
  background: transparent;
}

[data-theme="light"] .toc-title {
  border-bottom-color: #e5e5e5;
}

[data-theme="light"] .toc-content #toc-list a {
  color: #555;
}

[data-theme="light"] .toc-content #toc-list a:hover,
[data-theme="light"] .toc-content #toc-list a.active {
  color: #000;
}

[data-theme="light"] .toc-content #toc-list li.toc-title-link,
[data-theme="light"] .toc-content #toc-list li.toc-footnotes-link {
  border-color: #e5e5e5;
}

/* Image filter for manual dark mode */
[data-theme="dark"] img {
  filter: brightness(0.6) contrast(1.3);
}

/* Reset image filter for manual light mode (override system dark preference) */
[data-theme="light"] img {
  filter: none;
}

/* Preserve code block Monokai theme regardless of page theme */
.chroma,
.chroma pre,
.chroma code,
.chroma .lntable,
.chroma .lntd,
.chroma .lntd pre,
[data-theme="light"] .chroma,
[data-theme="light"] .chroma pre,
[data-theme="light"] .chroma code,
[data-theme="light"] .chroma .lntable,
[data-theme="light"] .chroma .lntd,
[data-theme="light"] .chroma .lntd pre,
[data-theme="dark"] .chroma,
[data-theme="dark"] .chroma pre,
[data-theme="dark"] .chroma code,
[data-theme="dark"] .chroma .lntable,
[data-theme="dark"] .chroma .lntd,
[data-theme="dark"] .chroma .lntd pre {
  background-color: #272822 !important;
  color: #f8f8f2;
}

.chroma .lntd,
.chroma .lntd pre,
[data-theme="light"] .chroma .lntd,
[data-theme="light"] .chroma .lntd pre,
[data-theme="dark"] .chroma .lntd,
[data-theme="dark"] .chroma .lntd pre {
  background: transparent !important;
}
