/* ===== Theme Variables ===== */
:root {
  color-scheme: light;
  --bg: #f0f2f5;
  --paper: #ffffff;
  --ink: #1a1a2e;
  --muted: #5a5a7a;
  --line: #d4d8e0;
  --accent: #0f766e;
  --accent-hover: #0d9488;
  --code-bg: #f4f5f7;
  --code-ink: #1a1a2e;
  --toc-bg: #f8f9fb;
  --toc-border: #e2e6ec;
  --switch-bg: rgba(255, 255, 255, 0.92);
  --switch-border: rgba(0, 0, 0, 0.08);
  --active-bg: #1a1a2e;
  --active-ink: #ffffff;
  --table-head-bg: #f4f5f7;
  --table-stripe: #fafbfc;
  --figure-bg: #fafbfc;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 8px 30px rgba(0,0,0,0.04);
  --shadow-lg: 0 4px 24px rgba(0,0,0,0.08);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1117;
  --paper: #161b22;
  --ink: #e6edf3;
  --muted: #8b949e;
  --line: #30363d;
  --accent: #58d5c7;
  --accent-hover: #7ee8db;
  --code-bg: #1c2128;
  --code-ink: #e6edf3;
  --toc-bg: #1c2128;
  --toc-border: #30363d;
  --switch-bg: rgba(22, 27, 34, 0.92);
  --switch-border: rgba(255, 255, 255, 0.08);
  --active-bg: #e6edf3;
  --active-ink: #0d1117;
  --table-head-bg: #1c2128;
  --table-stripe: #1118;
  --figure-bg: #1c2128;
  --shadow: 0 1px 3px rgba(0,0,0,0.2), 0 8px 30px rgba(0,0,0,0.15);
  --shadow-lg: 0 4px 24px rgba(0,0,0,0.3);
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: 80px;
}

body {
  margin: 0;
  padding: 0;
  font-family: "Palatino Linotype", Palatino, "Book Antiqua", Georgia,
               "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB",
               "Noto Serif SC", serif;
  font-size: 17px;
  line-height: 1.75;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== Page Container ===== */
.page {
  max-width: 920px;
  margin: 0 auto;
  padding: 0 24px 80px;
}

.paper-body {
  background: var(--paper);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 48px 56px;
  margin-top: 16px;
}

/* ===== Top Controls ===== */
.top-controls {
  position: sticky;
  top: 12px;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  margin: 16px 0 0;
  background: var(--switch-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--switch-border);
  border-radius: 10px;
}

.top-links {
  display: flex;
  gap: 6px;
  align-items: center;
}

.top-links a {
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink) !important;
  text-decoration: none !important;
  transition: all 0.2s;
}

.top-links a:hover {
  background: var(--ink);
  color: var(--active-ink) !important;
  border-color: var(--ink);
}

.top-links .p2g-status {
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
}

.lang-switch {
  display: flex;
  gap: 2px;
  background: var(--toc-bg);
  border-radius: 7px;
  padding: 2px;
}

.lang-switch button {
  border: none;
  background: transparent;
  padding: 6px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  transition: all 0.2s;
}

.lang-switch button.active {
  background: var(--active-bg);
  color: var(--active-ink);
}

.lang-switch button:hover:not(.active) {
  color: var(--ink);
}

a.paper-switch,
a.paper-switch:link,
a.paper-switch:visited,
a.paper-switch:active {
  margin-right: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink) !important;
  text-decoration: none !important;
  transition: all 0.2s;
}

a.paper-switch:hover {
  background: var(--ink);
  color: var(--active-ink) !important;
  border-color: var(--ink);
  text-decoration: none !important;
}

.theme-toggle {
  border: none;
  background: transparent;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
  transition: color 0.2s;
}

.theme-toggle:hover {
  color: var(--ink);
}

/* ===== Language Panes ===== */
.lang-pane[hidden] {
  display: none !important;
}

/* ===== Typography ===== */
h1 {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
               "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 1.85em;
  font-weight: 700;
  line-height: 1.25;
  color: var(--ink);
  margin: 32px 0 20px;
  text-align: center;
}

h2 {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
               "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 1.35em;
  font-weight: 600;
  line-height: 1.35;
  margin: 40px 0 16px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
  color: var(--ink);
}

h2:first-of-type {
  border-top: none;
  padding-top: 0;
}

h3 {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
               "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 1.1em;
  font-weight: 600;
  margin: 28px 0 12px;
  color: var(--ink);
}

h4 {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
               "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 1em;
  font-weight: 600;
  margin: 20px 0 8px;
  color: var(--ink);
}

p {
  margin: 0 0 16px;
  text-align: justify;
}

a {
  color: var(--accent);
  text-decoration: none;
}

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

.section-link {
  color: var(--muted);
  opacity: 0;
  font-size: 0.85em;
  margin-right: 6px;
  transition: opacity 0.15s;
  text-decoration: none;
}

h2:hover .section-link,
h3:hover .section-link {
  opacity: 1;
}

/* ===== Author Block ===== */
.author-block {
  text-align: center;
  margin: 0 0 28px;
  font-size: 0.88em;
  line-height: 1.85;
  color: var(--ink);
}

.author-block .authors {
  margin-bottom: 8px;
}

.author-block .affiliations {
  font-size: 0.82em;
  color: var(--muted);
  line-height: 1.7;
}

.author-block .notes {
  font-size: 0.8em;
  color: var(--muted);
  margin-top: 6px;
}

.author-block sup {
  font-size: 0.7em;
}

.keywords {
  text-align: center;
  font-size: 0.88em;
  color: var(--muted);
  margin-bottom: 24px;
}

.keywords strong {
  color: var(--ink);
}

/* ===== Table of Contents ===== */
.toc {
  background: var(--toc-bg);
  border: 1px solid var(--toc-border);
  border-radius: 8px;
  padding: 20px 24px;
  margin: 28px 0 36px;
}

.toc-title {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 600;
  font-size: 0.95em;
  margin-bottom: 12px;
  color: var(--ink);
}

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

.toc li {
  margin: 0;
  line-height: 1.6;
}

.toc li a {
  color: var(--muted);
  font-size: 0.9em;
  text-decoration: none;
  display: block;
  padding: 2px 0;
  transition: color 0.15s;
}

.toc li a:hover {
  color: var(--accent);
}

.toc-l2 {
  padding-left: 0;
  font-weight: 500;
}

.toc-l2 a {
  color: var(--ink) !important;
}

.toc-l3 {
  padding-left: 20px;
}

/* ===== Figures ===== */
figure {
  margin: 28px 0;
  text-align: center;
}

figure img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  background: var(--figure-bg);
}

figcaption {
  font-size: 0.88em;
  color: var(--muted);
  margin-top: 10px;
  line-height: 1.55;
  text-align: left;
  padding: 0 12px;
}

figcaption strong {
  color: var(--ink);
}

.figure-placeholder {
  background: var(--figure-bg);
  border: 2px dashed var(--line);
  border-radius: 8px;
  padding: 48px 24px;
  color: var(--muted);
  font-size: 0.9em;
  font-style: italic;
}

/* ===== Tables ===== */
.table-wrap {
  overflow-x: auto;
  margin: 24px 0;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88em;
  line-height: 1.5;
}

thead th {
  background: var(--table-head-bg);
  font-weight: 600;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 2px solid var(--line);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.92em;
  white-space: nowrap;
}

tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}

tbody tr:nth-child(even) {
  background: var(--table-stripe);
}

.table-caption {
  font-size: 0.88em;
  color: var(--muted);
  margin-top: 8px;
  text-align: left;
}

.table-caption strong {
  color: var(--ink);
}

/* ===== References ===== */
.references {
  padding-left: 2.2em;
  font-size: 0.88em;
  line-height: 1.65;
}

.references li {
  margin-bottom: 6px;
  color: var(--muted);
}

.references li::marker {
  color: var(--muted);
}

/* ===== Contributions List ===== */
.contributions {
  padding-left: 0;
  list-style: none;
  margin: 12px 0;
}

.contributions li {
  margin-bottom: 10px;
  padding-left: 0;
}

.contributions li strong {
  color: var(--ink);
}

/* ===== Inline Code ===== */
code {
  font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: var(--code-bg);
  color: var(--code-ink);
  padding: 2px 6px;
  border-radius: 4px;
}

/* ===== Block Quotes / Callouts ===== */
blockquote {
  border-left: 3px solid var(--accent);
  margin: 20px 0;
  padding: 12px 20px;
  background: var(--toc-bg);
  border-radius: 0 6px 6px 0;
  color: var(--muted);
}

blockquote p {
  margin: 0;
}

/* ===== Section Placeholder ===== */
.placeholder {
  background: var(--toc-bg);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 32px 24px;
  text-align: center;
  color: var(--muted);
  font-style: italic;
  font-size: 0.92em;
  margin: 16px 0;
}

/* ===== External Links Bar ===== */
.external-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin: 0 0 24px;
}

.external-links a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.85em;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--muted);
  text-decoration: none;
  transition: all 0.2s;
}

.external-links a:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--toc-bg);
  text-decoration: none;
}

/* ===== Paper2GAL Button Status ===== */
.p2g-btn { position: relative; }

.p2g-status {
  margin-left: 6px;
  font-size: 0.85em;
  color: var(--accent);
  font-weight: 600;
}

/* ===== Collapsible Details ===== */
details {
  margin: 16px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

details summary {
  padding: 14px 20px;
  background: var(--toc-bg);
  cursor: pointer;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 600;
  font-size: 0.95em;
  color: var(--ink);
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

details summary::-webkit-details-marker { display: none; }

details summary::before {
  content: "▸";
  display: inline-block;
  transition: transform 0.2s;
  font-size: 0.85em;
  color: var(--muted);
}

details[open] summary::before {
  transform: rotate(90deg);
}

details summary:hover {
  background: var(--line);
}

details .details-content {
  padding: 16px 20px;
}

/* ===== KaTeX overrides ===== */
.katex { font-size: 1.05em; }

/* ===== Footer ===== */
.site-footer {
  text-align: center;
  padding: 32px 0;
  font-size: 0.82em;
  color: var(--muted);
}

/* ===== Responsive ===== */
@media (max-width: 720px) {
  body { font-size: 16px; }

  .paper-body {
    padding: 28px 20px;
    border-radius: 0;
  }

  .page {
    padding: 0 0 40px;
  }

  .top-controls {
    margin: 0;
    border-radius: 0;
    top: 0;
  }

  h1 { font-size: 1.45em; }
  h2 { font-size: 1.2em; }

  .toc { padding: 16px 18px; }

  .author-block { font-size: 0.82em; }
  .author-block .affiliations { font-size: 0.78em; }

  figure { margin: 20px -8px; }

  table { font-size: 0.82em; }
  thead th, tbody td { padding: 6px 8px; }
}

@media (max-width: 480px) {
  .lang-switch button {
    padding: 5px 12px;
    font-size: 13px;
  }

  h1 { font-size: 1.25em; }
}
