:root {
  --paper-bg: #fdfcfa;
  --paper-text: #1a1a1a;
  --paper-muted: #555;
  --paper-link: #8b2500;
  --paper-accent: #c41e3a;
  --paper-border: #ddd;
  --paper-caption: #444;
  --paper-code-bg: #f5f5f0;
  --arxiv-red: #b31b1b;
  --arxiv-banner: #a41034;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html {
  scroll-behavior: smooth;
}

body {
  background: #e8e6e1;
  color: var(--paper-text);
  font-family: 'STIX Two Text', 'Crimson Pro', 'Times New Roman', serif;
  font-size: 11.5pt;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: rgba(179, 27, 27, 0.15);
}

.arxiv-banner {
  background: var(--arxiv-banner);
  color: white;
  padding: 6px 0;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.03em;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.paper-container {
  max-width: 820px;
  margin: 0 auto;
  background: var(--paper-bg);
  box-shadow: 0 0 40px rgba(0,0,0,0.1), 0 0 2px rgba(0,0,0,0.08);
  min-height: 100vh;
}

.paper-body {
  padding: 48px 64px;
}

@media (max-width: 860px) {
  .paper-body { padding: 32px 24px; }
}

/* Title block */
.paper-title {
  font-family: 'Crimson Pro', serif;
  font-size: 24pt;
  font-weight: 700;
  line-height: 1.2;
  color: var(--paper-text);
  text-align: center;
  margin-bottom: 16px;
}

.paper-authors {
  text-align: center;
  font-size: 12pt;
  margin-bottom: 4px;
  color: var(--paper-text);
}

.paper-affiliation {
  text-align: center;
  font-size: 10pt;
  color: var(--paper-muted);
  font-style: italic;
  margin-bottom: 4px;
}

.paper-date {
  text-align: center;
  font-size: 9.5pt;
  color: var(--paper-muted);
  margin-bottom: 28px;
}

/* Abstract */
.abstract-box {
  border: 1px solid var(--paper-border);
  padding: 20px 24px;
  margin-bottom: 32px;
  background: #fafaf7;
}

.abstract-title {
  font-weight: 700;
  font-size: 11pt;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.abstract-text {
  font-size: 10.5pt;
  line-height: 1.55;
  text-align: justify;
  hyphens: auto;
}

/* Sections */
.section-title {
  font-family: 'Crimson Pro', serif;
  font-size: 15pt;
  font-weight: 700;
  margin-top: 36px;
  margin-bottom: 12px;
  color: var(--paper-text);
  border-bottom: 1px solid #ddd;
  padding-bottom: 4px;
}

.subsection-title {
  font-family: 'Crimson Pro', serif;
  font-size: 12.5pt;
  font-weight: 600;
  margin-top: 24px;
  margin-bottom: 8px;
  color: var(--paper-text);
}

.body-text {
  text-align: justify;
  margin-bottom: 12px;
  line-height: 1.58;
  hyphens: auto;
}

.body-text.indent {
  text-indent: 1.5em;
}

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

.figure-container.full-width {
  margin: 32px -16px;
}

.figure-image {
  max-width: 100%;
  border: 1px solid #e0e0e0;
  border-radius: 2px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.figure-image.small {
  max-width: 55%;
}

.figure-image.medium {
  max-width: 75%;
}

.figure-grid {
  display: grid;
  gap: 12px;
  margin: 12px 0;
}

.figure-grid.two-col {
  grid-template-columns: 1fr 1fr;
}

.figure-grid.three-col {
  grid-template-columns: 1fr 1fr 1fr;
}

@media (max-width: 600px) {
  .figure-grid.two-col,
  .figure-grid.three-col {
    grid-template-columns: 1fr;
  }
}

.figure-caption {
  font-size: 9.5pt;
  color: var(--paper-caption);
  margin-top: 10px;
  line-height: 1.45;
  text-align: left;
  padding: 0 16px;
}

.figure-caption strong {
  color: var(--paper-text);
}

/* Tables */
.paper-table-container {
  margin: 20px 0;
  overflow-x: auto;
}

.paper-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10pt;
}

.paper-table th {
  border-top: 2px solid #333;
  border-bottom: 1px solid #333;
  padding: 6px 12px;
  font-weight: 600;
  text-align: left;
  font-size: 9.5pt;
}

.paper-table td {
  padding: 5px 12px;
  border-bottom: 1px solid #e5e5e5;
  font-size: 9.5pt;
}

.paper-table tr:last-child td {
  border-bottom: 2px solid #333;
}

.paper-table .num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9pt;
  text-align: right;
}

/* Equations */
.equation-block {
  margin: 18px 0;
  text-align: center;
  font-size: 12pt;
  position: relative;
}

.equation-number {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10pt;
  color: var(--paper-muted);
}

/* Code */
.code-block {
  background: var(--paper-code-bg);
  border: 1px solid #e0e0d8;
  border-radius: 3px;
  padding: 12px 16px;
  margin: 16px 0;
  font-family: 'JetBrains Mono', monospace;
  font-size: 8.5pt;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre;
}

/* Citations */
.citation {
  color: var(--arxiv-red);
  cursor: pointer;
  text-decoration: none;
}

.citation:hover {
  text-decoration: underline;
}

/* References */
.reference-item {
  font-size: 9.5pt;
  margin-bottom: 6px;
  padding-left: 2em;
  text-indent: -2em;
  line-height: 1.45;
}

.reference-item .ref-num {
  font-weight: 600;
  color: var(--arxiv-red);
}

/* Sidebar TOC */
.toc-sidebar {
  position: fixed;
  left: 0;
  top: 42px;
  width: 200px;
  max-height: calc(100vh - 42px);
  overflow-y: auto;
  padding: 16px 12px;
  font-size: 8.5pt;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(8px);
  border-right: 1px solid #ddd;
  z-index: 50;
  transition: transform 0.3s;
}

.toc-sidebar.hidden {
  transform: translateX(-100%);
}

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

.toc-item {
  display: block;
  padding: 3px 0;
  color: var(--paper-muted);
  text-decoration: none;
  cursor: pointer;
  transition: color 0.15s;
  font-family: 'Crimson Pro', serif;
}

.toc-item:hover, .toc-item.active {
  color: var(--arxiv-red);
}

.toc-item.sub {
  padding-left: 12px;
  font-size: 8pt;
}

/* Footnotes */
.footnote-ref {
  font-size: 8pt;
  vertical-align: super;
  color: var(--arxiv-red);
  cursor: pointer;
}

.footnote {
  font-size: 8.5pt;
  color: var(--paper-muted);
  border-top: 1px solid #ddd;
  padding-top: 8px;
  margin-top: 32px;
}

/* Keywords */
.keywords {
  font-size: 9.5pt;
  margin-top: 8px;
  color: var(--paper-muted);
}

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

/* Loading shimmer for images */
.img-loading {
  background: linear-gradient(90deg, #f0f0ec 25%, #e8e8e4 50%, #f0f0ec 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #aaa;
  font-size: 9pt;
  font-family: 'JetBrains Mono', monospace;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Interactive demo section */
.demo-embed {
  border: 2px solid #ddd;
  border-radius: 4px;
  overflow: hidden;
  margin: 20px 0;
  background: #0a0a0f;
}

.demo-embed canvas {
  display: block;
  width: 100%;
}

.demo-label {
  background: #f5f5f0;
  padding: 4px 12px;
  font-size: 8.5pt;
  font-family: 'JetBrains Mono', monospace;
  color: var(--paper-muted);
  border-top: 1px solid #ddd;
}

/* Margin notes */
.margin-note {
  font-size: 8pt;
  color: #888;
  font-style: italic;
  float: right;
  width: 140px;
  margin-right: -160px;
  margin-top: 4px;
  line-height: 1.3;
}

@media (max-width: 1100px) {
  .margin-note { display: none; }
}

/* Print */
@media print {
  .arxiv-banner, .toc-sidebar { display: none; }
  .paper-container { box-shadow: none; }
  body { background: white; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #e8e6e1; }
::-webkit-scrollbar-thumb { background: #bbb; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #999; }

/* Math inline */
.math-inline {
  font-family: 'STIX Two Text', serif;
  font-style: italic;
}

/* Highlight box */
.highlight-box {
  background: #fffbf0;
  border-left: 3px solid var(--arxiv-red);
  padding: 12px 16px;
  margin: 16px 0;
  font-size: 10pt;
}

/* Author ORCID */
.orcid-icon {
  display: inline-block;
  width: 14px;
  height: 14px;
  background: #a6ce39;
  border-radius: 50%;
  color: white;
  font-size: 9px;
  line-height: 14px;
  text-align: center;
  font-weight: bold;
  vertical-align: middle;
  margin-left: 2px;
}

/* Watermark */
.draft-watermark {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-35deg);
  font-size: 120px;
  font-weight: 900;
  color: rgba(179, 27, 27, 0.03);
  pointer-events: none;
  z-index: 0;
  font-family: 'Crimson Pro', serif;
  letter-spacing: 20px;
  white-space: nowrap;
}