@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,400&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --bg-color: #ffffff;
  --surface-color: #f9fafb;
  --ink-color: #111827;
  --text-muted: #4b5563;
  --text-light: #9ca3af;
  --border-color: #e5e7eb;
  --border-light: #f3f4f6;
  --accent-color: #111827;
  --accent-hover: #4b5563;
  
  --font-heading: 'DM Sans', sans-serif;
  --font-body: 'DM Sans', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
  
  --nav-height: 60px;
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: var(--nav-height);
  background-color: var(--bg-color);
  color: var(--ink-color);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

body { overflow-x: hidden; }

a {
  color: inherit;
  text-decoration: none;
  transition: color 0.2s ease;
}

button {
  font: inherit;
  cursor: pointer;
  background: none;
  border: none;
  color: inherit;
}

a:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 3px;
  border-radius: 2px;
}

.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

.skip-nav {
  position: absolute;
  top: -100px;
  left: 24px;
  background: var(--ink-color);
  color: var(--bg-color);
  padding: 12px 20px;
  border-radius: 6px;
  z-index: 9999;
  font-weight: 500;
  transition: top 0.2s ease;
}
.skip-nav:focus { top: 16px; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: color-mix(in srgb, var(--bg-color) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  height: var(--nav-height);
  display: flex;
  align-items: center;
}

.topbar-in {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.logo {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
  color: var(--ink-color);
}

.topnav {
  display: flex;
  align-items: center;
  gap: 24px;
}

.toplinks {
  display: flex;
  gap: 20px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
}
.toplinks a:hover, .toplinks a.active { color: var(--ink-color); }

.top-contact {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink-color);
  padding: 8px 12px;
  border-radius: 4px;
  transition: background 0.2s;
}
.top-contact:hover {
  background: var(--surface-color);
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 64px;
  align-items: start;
  padding: 64px 24px 100px;
}

/* TOC Sidebar */
.sidebar {
  position: sticky;
  top: calc(var(--nav-height) + 40px);
  max-height: calc(100vh - var(--nav-height) - 80px);
  display: flex;
  flex-direction: column;
}

.toc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink-color);
}

.dl-link {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}
.dl-link:hover { color: var(--ink-color); }
.dl-link svg { width: 14px; height: 14px; }

.toc {
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}
.toc::-webkit-scrollbar { width: 4px; }
.toc::-webkit-scrollbar-track { background: transparent; }
.toc::-webkit-scrollbar-thumb { background-color: var(--border-color); border-radius: 4px; }

.toc ol { list-style: none; }
.toc li { margin-bottom: 8px; }
.toc a {
  display: flex;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
  transition: color 0.2s;
}
.toc a:hover, .toc a.active { color: var(--ink-color); }
.toc a .tn { color: var(--text-light); min-width: 16px; }

.toc-toggle { display: none; }
.toc-label { display: none; }

/* Main Article */
#main-content {
  max-width: 720px;
  margin: 0 auto;
}

/* Paper Header */
.paper-header {
  text-align: center;
  margin-bottom: 64px;
}

.paper-header h1 {
  font-family: var(--font-heading);
  font-size: 2.25rem;
  line-height: 1.2;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink-color);
  margin-bottom: 16px;
}

.paper-header .subtitle {
  font-size: 1.25rem;
  color: var(--ink-color);
  margin-bottom: 24px;
  font-weight: 500;
}

.paper-meta {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.paper-meta p {
  margin: 4px 0;
}

.meta-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.meta-actions button, .meta-actions a {
  font-weight: 500;
  text-decoration: underline;
  text-decoration-color: transparent;
  transition: all 0.2s;
}
.meta-actions button:hover, .meta-actions a:hover {
  color: var(--ink-color);
  text-decoration-color: var(--border-color);
}

/* Abstract */
.paper-abstract {
  margin-bottom: 48px;
}

.paper-abstract h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--ink-color);
}

.paper-abstract p {
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--text-muted);
}

.paper-abstract .keywords {
  margin-top: 24px;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.paper-abstract .keywords strong {
  color: var(--ink-color);
  font-weight: 500;
}

/* Content Typography */
#main-content h2 {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  line-height: 1.3;
  font-weight: 600;
  color: var(--ink-color);
  margin: 48px 0 24px;
  scroll-margin-top: calc(var(--nav-height) + 40px);
}
#main-content h2:first-of-type { margin-top: 0; }

#main-content h3 {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--ink-color);
  margin: 32px 0 16px;
  scroll-margin-top: calc(var(--nav-height) + 40px);
}

#main-content .secnum {
  color: var(--text-light);
  margin-right: 8px;
  font-weight: 500;
}

#main-content p {
  margin-bottom: 20px;
  color: var(--text-muted);
}

#main-content a {
  color: var(--ink-color);
  text-decoration: underline;
  text-decoration-color: var(--border-color);
  text-underline-offset: 2px;
}
#main-content a:hover { text-decoration-color: var(--ink-color); }

#main-content a[href^="#ref-"] {
  font-size: 0.85em;
  color: var(--text-light);
  text-decoration: none;
  padding: 0 2px;
}
#main-content a[href^="#ref-"]:hover { color: var(--ink-color); }

#main-content ul, #main-content ol {
  margin: 0 0 24px 24px;
  color: var(--text-muted);
}
#main-content li { margin-bottom: 8px; }

#main-content strong {
  font-weight: 600;
  color: var(--ink-color);
}

#main-content blockquote, .note {
  margin: 32px 0;
  padding: 24px;
  background-color: var(--surface-color);
  border-left: 2px solid var(--border-color);
}
#main-content blockquote p, .note p { margin-bottom: 12px; }
#main-content blockquote p:last-child, .note p:last-child { margin-bottom: 0; }

.note-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-color);
  margin-bottom: 8px;
}

/* Tables */
.tbl-wrap {
  overflow-x: auto;
  margin: 32px 0;
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
}

.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  min-width: 600px;
}

.tbl caption {
  caption-side: bottom;
  padding: 16px 0;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.5;
  text-align: left;
}

.tbl th {
  color: var(--ink-color);
  font-weight: 600;
  text-align: left;
  padding: 12px 16px 12px 0;
  border-bottom: 1px solid var(--border-color);
}
.tbl th:last-child { padding-right: 0; }

.tbl td {
  padding: 12px 16px 12px 0;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-muted);
  vertical-align: top;
}
.tbl td:last-child { padding-right: 0; }
.tbl tr:last-child td { border-bottom: none; }

.tbl td.num {
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.restored-table tbody th[scope="row"] {
  border-bottom: 1px solid var(--border-light);
  color: var(--ink-color);
  font-weight: 500;
  padding: 12px 16px 12px 0;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}
.restored-table tbody tr:last-child th { border-bottom: none; }

/* Figures */
figure { margin: 40px 0; }
figure img {
  width: 100%;
  height: auto;
  display: block;
  border: 1px solid var(--border-color);
}
figcaption {
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}
figcaption strong { color: var(--ink-color); }

/* Badges */
.badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 4px;
  vertical-align: middle;
  margin-left: 6px;
  background: var(--surface-color);
  color: var(--ink-color);
  border: 1px solid var(--border-color);
}

/* Diagrams */
.diagram-box { margin: 32px 0; display: flex; flex-direction: column; gap: 16px; }
.box-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.box { 
  flex: 1; 
  border: 1px solid var(--border-color); 
  padding: 16px; 
  background: var(--bg-color); 
  font-size: 0.9rem; 
  color: var(--text-muted); 
  min-width: 200px;
}
.box strong { display: block; color: var(--ink-color); font-size: 0.95rem; margin-bottom: 4px; font-weight: 600; }
.box.highlight { border-color: var(--ink-color); }
.box.highlight strong { color: var(--ink-color); }
.arrow { color: var(--text-light); font-size: 1.2rem; }
.flow-diagram { flex-direction: row; align-items: center; justify-content: space-between; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 8px; }
.flow-diagram .box { flex: 1 1 0; min-width: 150px; }

/* References */
ol.refs, ol.footnotes {
  margin: 0 0 24px 24px;
  font-size: 0.85rem;
  color: var(--text-muted);
}
ol.refs li, ol.footnotes li {
  margin-bottom: 12px;
  scroll-margin-top: calc(var(--nav-height) + 40px);
}
:target { scroll-margin-top: calc(var(--nav-height) + 40px); }
ol.refs li:target, ol.footnotes li:target {
  background-color: var(--surface-color);
  padding: 4px 8px;
  margin-left: -8px;
}
.fn-back {
  color: var(--text-light);
  margin-left: 6px;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border-color);
  padding: 48px 0;
  margin-top: 64px;
}
.fgrid {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 40px;
}
.fcol { display: flex; flex-direction: column; gap: 8px; }
.f-desc { color: var(--text-muted); font-size: 0.9rem; }
.flinks {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 24px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
}
.flinks a:hover { color: var(--ink-color); }
.legal { margin-top: 40px; font-size: 0.85rem; color: var(--text-light); }

/* Mobile */
@media (max-width: 800px) {
  .toplinks { display: none; }
  .layout {
    grid-template-columns: 1fr;
    gap: 32px;
    padding-top: 32px;
  }
  
  .sidebar {
    position: static;
    max-height: none;
    border: 1px solid var(--border-color);
    border-radius: 4px;
  }
  
  .toc-header {
    display: flex;
    padding: 16px;
    margin: 0;
    border-bottom: 1px solid var(--border-color);
  }
  
  .toc-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 16px;
    font-weight: 500;
    color: var(--ink-color);
    min-height: 52px;
  }
  
  .toc a { min-height: 44px; align-items: center; }
  .toc-toggle .caret { transition: transform 0.2s ease; color: var(--text-muted); }
  .toc.open .toc-toggle .caret { transform: rotate(180deg); }
  
  .toc-content {
    display: none;
    padding: 0 16px 16px;
  }
  .toc.open .toc-content { display: block; }
  
  .flow-diagram { flex-direction: column; align-items: stretch; }
  .arrow { text-align: center; transform: rotate(90deg); margin: 8px 0; }

  .restored-table { overflow-x: visible; border: none; }
  .restored-table .tbl { min-width: 0; font-size: 0.8rem; border-top: 1px solid var(--border-color); }
  .restored-table thead {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
  }
  .restored-table tbody, .restored-table tbody tr { display: block; }
  .restored-table tbody tr {
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
  }
  .restored-table tbody tr:last-child { border-bottom: 0; }
  .restored-table .tbl td, .restored-table .tbl tbody th[scope="row"] {
    display: grid;
    grid-template-columns: minmax(7rem, 0.35fr) minmax(0, 0.65fr);
    gap: 12px;
    padding: 4px 0;
    border-bottom: 0;
  }
  .restored-table .tbl td::before, .restored-table .tbl tbody th[scope="row"]::before {
    content: attr(data-label);
    color: var(--ink-color);
    font-weight: 500;
    font-size: 0.8rem;
    line-height: 1.4;
  }
  .restored-table .tbl caption { padding: 12px 0; overflow-wrap: anywhere; }
}

.toc li.sub { margin-left: 16px; }
.toc li.sub a { font-size: 0.8rem; }

#main-content h2#abstract {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0 0 16px 0;
  color: var(--ink-color);
}
#main-content h2#abstract + p,
#main-content h2#abstract + p + p {
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--text-muted);
}
#main-content p.keywords,
#main-content h2#abstract ~ p:nth-of-type(4) {
  margin-top: 24px;
  font-size: 0.9rem;
  color: var(--text-muted);
}
#main-content p.keywords strong,
#main-content h2#abstract ~ p:nth-of-type(4) strong {
  color: var(--ink-color);
  font-weight: 500;
}

/* Touch targets */
.btn {
  min-height: 44px;
}
