/* ===== CSS Variables ===== */
:root,
[data-theme="light"] {
  --bg: #ffffff;
  --bg-secondary: #f8f8f8;
  --text: #333333;
  --text-secondary: #666666;
  --link: #b31b1b;
  --link-hover: #8b1515;
  --border: #e0e0e0;
  --code-bg: #f5f5f5;
  --code-border: #e0e0e0;
  --header-bg: #fafafa;
  --header-border: #ddd;
  --card-bg: #ffffff;
  --card-shadow: rgba(0,0,0,0.08);
  --blockquote-border: #b31b1b;
  --blockquote-bg: #fdf6f6;
  --table-stripe: #f9f9f9;
  --kbd-bg: #eee;
}

[data-theme="dark"] {
  --bg: #1e1e1e;
  --bg-secondary: #252526;
  --text: #d4d4d4;
  --text-secondary: #858585;
  --link: #569cd6;
  --link-hover: #9cdcfe;
  --border: #3c3c3c;
  --code-bg: #1e1e1e;
  --code-border: #3c3c3c;
  --header-bg: #252526;
  --header-border: #3c3c3c;
  --card-bg: #252526;
  --card-shadow: rgba(0,0,0,0.4);
  --blockquote-border: #569cd6;
  --blockquote-bg: #252526;
  --table-stripe: #2d2d2d;
  --kbd-bg: #333333;
}

/* ===== Transitions ===== */
html {
  transition: background-color 0.3s ease, color 0.3s ease;
}
*, *::before, *::after {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* ===== Reset & Base ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Linux Libertine', 'Georgia', 'Times New Roman', serif;
  font-size: 17px;
  line-height: 1.75;
  color: var(--text);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ===== Header ===== */
.site-header {
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 8px 24px;
  min-height: 56px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.site-title {
  font-family: 'Arial', 'Helvetica Neue', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}
.site-title:hover {
  color: var(--link);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.github-link {
  font-family: 'Arial', sans-serif;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-decoration: none;
}
.github-link:hover {
  color: var(--link);
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  min-width: 36px;
  text-align: center;
}
.theme-toggle:hover {
  border-color: var(--link);
}

/* ===== Container ===== */
.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* Paper pages: shift right to make room for left TOC */
@media (min-width: 1201px) {
  .paper-content {
    position: relative;
  }
}

/* ===== Index Page ===== */
.index-header {
  text-align: center;
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 2px solid var(--border);
}

.index-header h1 {
  font-family: 'Arial', 'Helvetica Neue', sans-serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.index-header p {
  color: var(--text-secondary);
  font-size: 1.05rem;
}

.index-header .subtitle {
  font-size: 0.9rem;
  margin-top: 0.3rem;
}

.paper-count {
  font-size: 0.85em;
  font-weight: 400;
  color: var(--text-secondary);
}

.empty-hint {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-style: italic;
  padding: 0.5rem 1rem;
}

.category-section {
  margin-bottom: 2rem;
}

.category-title {
  font-family: 'Arial', 'Helvetica Neue', sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.8rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.category-title .cat-icon {
  margin-right: 0.4rem;
}

.category-subtitle {
  font-size: 0.88rem;
  color: var(--text-muted, #888);
  margin-top: -0.4rem;
  margin-bottom: 0.8rem;
  font-style: italic;
}

.subcategory-section {
  margin-bottom: 1.2rem;
}

.subcategory-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
  padding-left: 0.8rem;
  border-left: 3px solid var(--accent, #4a9eff);
}

.toc-sublist {
  list-style: none;
  padding-left: 1rem;
  margin-top: 0.2rem;
}

.toc-link-sub {
  font-size: 0.8rem;
  color: var(--text-muted, #888);
  padding: 0.1rem 0.4rem;
}

.paper-list {
  list-style: none;
  padding: 0;
}

.paper-list li {
  margin-bottom: 0.4rem;
}

.paper-card {
  display: block;
  padding: 0.7rem 1rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  color: var(--text);
  font-size: 0.95rem;
}

.paper-card:hover {
  border-color: var(--link);
  box-shadow: 0 2px 8px var(--card-shadow);
  color: var(--link);
}

.paper-card .paper-title {
  font-weight: 600;
}

/* ===== Paper Layout with TOC ===== */
.paper-layout {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
}

.paper-body {
  flex: 1;
  min-width: 0;
}

/* ===== TOC Sidebar ===== */
.toc-sidebar {
  width: 220px;
  flex-shrink: 0;
  position: sticky;
  top: 70px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  order: -1;
  margin-left: -260px;
}

.toc-wrapper {
  padding: 0.8rem 0;
}

.toc-title {
  font-family: 'Arial', 'Helvetica Neue', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 0.6rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

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

.toc-item {
  margin-bottom: 0.15rem;
}

.toc-item.toc-h3 {
  padding-left: 0.8rem;
}

.toc-link {
  display: block;
  padding: 0.25rem 0.5rem;
  font-family: 'Arial', sans-serif;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 2px solid transparent;
  border-radius: 0 3px 3px 0;
  transition: all 0.15s ease;
}

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

.toc-link.active {
  color: var(--link);
  border-left-color: var(--link);
  font-weight: 600;
  background: var(--bg-secondary);
}

/* ===== Right Sidebar (quick actions) ===== */
.right-sidebar {
  width: 140px;
  flex-shrink: 0;
  position: sticky;
  top: 70px;
  margin-right: -170px;
  align-self: flex-start;
}

.right-sidebar-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.8rem 0;
}

.right-sidebar-link {
  display: block;
  padding: 0.35rem 0.5rem;
  font-family: 'Arial', sans-serif;
  font-size: 0.78rem;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 4px;
  transition: all 0.15s ease;
  border-left: 2px solid transparent;
}

.right-sidebar-link:hover {
  color: var(--link);
  background: var(--bg-secondary);
  border-left-color: var(--link);
}

@media (max-width: 1200px) {
  .right-sidebar {
    display: none;
  }
}

/* TOC scrollbar */
.toc-sidebar::-webkit-scrollbar {
  width: 3px;
}
.toc-sidebar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* Show TOC only on wide screens */
@media (max-width: 1200px) {
  .toc-sidebar {
    display: none;
  }
  .paper-layout {
    display: block;
  }
}

/* Wider container for paper pages to accommodate TOC */
.paper-content .paper-layout {
  max-width: none;
}

/* ===== Index Layout with TOC ===== */
.index-layout {
  display: block;
  position: relative;
}

.index-main {
  min-width: 0;
}

.index-layout .toc-sidebar {
  position: sticky;
  top: 70px;
  float: left;
  width: 220px;
  margin-left: -260px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}

@media (max-width: 1200px) {
  .index-layout .toc-sidebar {
    display: none;
  }
}

/* ===== Breadcrumb ===== */
.breadcrumb {
  font-family: 'Arial', sans-serif;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--border);
}

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

.breadcrumb .sep {
  margin: 0 0.5rem;
  color: var(--text-secondary);
}

/* ===== Paper Content ===== */
.paper-body h1,
.paper-body h2,
.paper-body h3,
.paper-body h4,
.paper-body h5,
.paper-body h6 {
  scroll-margin-top: 80px;
}

.paper-body h1 {
  font-family: 'Arial', 'Helvetica Neue', sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1rem;
  line-height: 1.3;
}

.paper-body h2 {
  font-family: 'Arial', 'Helvetica Neue', sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 2rem;
  margin-bottom: 0.8rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
}

.paper-body h3 {
  font-family: 'Arial', 'Helvetica Neue', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 1.5rem;
  margin-bottom: 0.6rem;
}

.paper-body h4, .paper-body h5, .paper-body h6 {
  font-family: 'Arial', 'Helvetica Neue', sans-serif;
  font-weight: 700;
  color: var(--text);
  margin-top: 1.2rem;
  margin-bottom: 0.4rem;
}

.paper-body p {
  margin-bottom: 1rem;
}

.paper-body a {
  color: var(--link);
  text-decoration: none;
}
.paper-body a:hover {
  text-decoration: underline;
  color: var(--link-hover);
}

/* Lists */
.paper-body ul, .paper-body ol {
  margin-bottom: 1rem;
  padding-left: 1.8rem;
}
.paper-body li {
  margin-bottom: 0.3rem;
}

/* Blockquotes */
.paper-body blockquote {
  border-left: 3px solid var(--blockquote-border);
  background: var(--blockquote-bg);
  padding: 0.8rem 1.2rem;
  margin: 1rem 0;
  border-radius: 0 6px 6px 0;
  color: var(--text-secondary);
}
.paper-body blockquote p {
  margin-bottom: 0.3rem;
}

/* Code */
.paper-body code {
  font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.15em 0.4em;
  border-radius: 3px;
  border: 1px solid var(--code-border);
}

.paper-body pre {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 6px;
  padding: 1rem 1.2rem;
  overflow-x: auto;
  margin: 1rem 0;
  line-height: 1.5;
}

.paper-body pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.85em;
}

/* Tables */
.paper-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.92em;
}

.paper-body th, .paper-body td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.8rem;
  text-align: left;
}

.paper-body th {
  background: var(--bg-secondary);
  font-family: 'Arial', sans-serif;
  font-weight: 700;
}

.paper-body tr:nth-child(even) {
  background: var(--table-stripe);
}

/* Images */
.paper-body img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  margin: 1rem 0;
}

/* HR */
.paper-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* KaTeX overrides */
.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.5rem 0;
}

/* ===== Paper Nav ===== */
.paper-nav {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.back-link {
  font-family: 'Arial', sans-serif;
  font-size: 0.9rem;
  color: var(--link);
  text-decoration: none;
}
.back-link:hover {
  text-decoration: underline;
}

.prev-link, .next-link {
  font-family: 'Arial', sans-serif;
  font-size: 0.9rem;
  color: var(--link);
  text-decoration: none;
}
.prev-link:hover, .next-link:hover {
  text-decoration: underline;
}

/* ===== Footer ===== */
.site-footer {
  padding: 24px 0 20px;
  border-top: 1px solid var(--border);
  margin-top: 1rem;
}

.footer-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 24px;
  text-align: center;
  font-family: 'Arial', sans-serif;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ===== Language Toggle ===== */
.lang-toggle {
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
  transition: border-color 0.3s ease, background 0.3s ease, color 0.3s ease;
  line-height: 1;
  user-select: none;
  min-width: 36px;
  text-align: center;
}
.lang-toggle:hover {
  background: var(--link);
  color: #fff;
  border-color: var(--link);
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
  .container {
    padding: 1rem;
  }
  .paper-body h1 {
    font-size: 1.4rem;
  }
  .paper-body h2 {
    font-size: 1.15rem;
  }
  .index-header h1 {
    font-size: 1.5rem;
  }
  .header-inner {
    padding: 0.6rem 1rem;
  }
  .site-title {
    flex: 1;
    min-width: 0;
    white-space: normal;
    word-break: break-word;
    line-height: 1.3;
  }
}

/* ===========================
   Rouge Syntax Highlighting — Single Box (table mode)
   =========================== */
.paper-body .highlighter-rouge {
  margin: 1.2rem 0;
}

/* ===== Code blocks (rouge colors + custom per-line layout) ===== */
.paper-body .highlighter-rouge {
  margin: 1.2rem 0;
}

.paper-body .code-block {
  background: #ffffff !important;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.6rem 0;
  font-family: 'SF Mono', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.875rem;
  line-height: 1.5;
  white-space: pre;
}

[data-theme="dark"] .paper-body .code-block {
  background: #1e1e1e !important;
  border-color: #3c3c3c;
}

@media (prefers-color-scheme: dark) {
  .paper-body .code-block {
    background: #1e1e1e;
    border-color: #3c3c3c;
  }
}

.paper-body .code-row {
  display: flex;
  align-items: baseline;
  /* Row never wraps: gutter + code stay on one visual line */
  flex-wrap: nowrap;
  min-width: max-content;
}

.paper-body .code-ln {
  flex: 0 0 3rem;
  width: 3rem;
  text-align: right;
  padding-right: 0.75rem;
  color: #999;
  user-select: none;
  font-size: inherit;
  line-height: inherit;
  /* Keep gutter fixed and opaque even when code scrolls left */
  position: sticky;
  left: 0;
  background: #ffffff;
  z-index: 1;
}

.paper-body .code-cell {
  flex: 1;
  padding-right: 1.5rem;
  white-space: pre;
  word-break: normal;
  font-size: inherit;
  line-height: inherit;
}

/* Dark mode (code-ln) */
[data-theme="dark"] .paper-body .code-ln {
  color: #555;
  background: #1e1e1e;
}

/* ===========================
   Rouge syntax colors — dark mode (Dracula)
   =========================== */
[data-theme="dark"] .highlight .k,  [data-theme="dark"] .highlight .kd { color: #ff79c6; }
[data-theme="dark"] .highlight .nb, [data-theme="dark"] .highlight .nc { color: #bd93f9; }
[data-theme="dark"] .highlight .no, [data-theme="dark"] .highlight .nv { color: #50fa7b; }
[data-theme="dark"] .highlight .s,  [data-theme="dark"] .highlight .s1, [data-theme="dark"] .highlight .s2 { color: #f1fa8c; }
[data-theme="dark"] .highlight .c,  [data-theme="dark"] .highlight .cm, [data-theme="dark"] .highlight .co { color: #6272a4; font-style: italic; }
[data-theme="dark"] .highlight .o,  [data-theme="dark"] .highlight .ow { color: #ff79c6; }
[data-theme="dark"] .highlight .mi, [data-theme="dark"] .highlight .mf { color: #bd93f9; }
[data-theme="dark"] .highlight .nf, [data-theme="dark"] .highlight .fm { color: #50fa7b; }
[data-theme="dark"] .highlight .ne { color: #ffb86c; }
[data-theme="dark"] .highlight .nt { color: #ff79c6; }
[data-theme="dark"] .highlight .vc, [data-theme="dark"] .highlight .vi, [data-theme="dark"] .highlight .vm { color: #50fa7b; }
[data-theme="dark"] .highlight .sr, [data-theme="dark"] .highlight .ss, [data-theme="dark"] .highlight .se, [data-theme="dark"] .highlight .sc { color: #f1fa8c; }
[data-theme="dark"] .highlight .err { color: #ff5555; }
[data-theme="dark"] .highlight .p,  [data-theme="dark"] .highlight .n  { color: #f8f8f2; }

/* Rouge syntax colors — light mode (GitHub) */
:root:not([data-theme="dark"]) .highlight .k,  :root:not([data-theme="dark"]) .highlight .kd { color: #cf222e; }
:root:not([data-theme="dark"]) .highlight .nb, :root:not([data-theme="dark"]) .highlight .nc { color: #8250df; }
:root:not([data-theme="dark"]) .highlight .no, :root:not([data-theme="dark"]) .highlight .nv { color: #953800; }
:root:not([data-theme="dark"]) .highlight .s,  :root:not([data-theme="dark"]) .highlight .s1, :root:not([data-theme="dark"]) .highlight .s2 { color: #0a3069; }
:root:not([data-theme="dark"]) .highlight .c,  :root:not([data-theme="dark"]) .highlight .cm, :root:not([data-theme="dark"]) .highlight .co { color: #6e7781; font-style: italic; }
:root:not([data-theme="dark"]) .highlight .o  { color: #cf222e; }
:root:not([data-theme="dark"]) .highlight .mi, :root:not([data-theme="dark"]) .highlight .mf { color: #8250df; }
:root:not([data-theme="dark"]) .highlight .nf, :root:not([data-theme="dark"]) .highlight .fm { color: #8250df; }
:root:not([data-theme="dark"]) .highlight .ne { color: #953800; }
:root:not([data-theme="dark"]) .highlight .nt { color: #116329; }
:root:not([data-theme="dark"]) .highlight .vc, :root:not([data-theme="dark"]) .highlight .vi, :root:not([data-theme="dark"]) .highlight .vm { color: #953800; }
:root:not([data-theme="dark"]) .highlight .sr, :root:not([data-theme="dark"]) .highlight .ss, :root:not([data-theme="dark"]) .highlight .se, :root:not([data-theme="dark"]) .highlight .sc { color: #0a3069; }
:root:not([data-theme="dark"]) .highlight .err { color: #cf222e; }
:root:not([data-theme="dark"]) .highlight .p,  :root:not([data-theme="dark"]) .highlight .n  { color: #24292f; }
