:root {
  --bg: #f7f5f0;
  --bg-elev: #fffdf9;
  --bg-soft: #efece4;
  --bg-code: #20252a;
  --ink: #1f2328;
  --ink-soft: #4b5563;
  --muted: #7b817f;
  --line: #e2ddd2;
  --line-strong: #d1c9bb;
  --accent: #b45309;
  --accent-strong: #8f3f06;
  --accent-soft: #fff3e1;
  --teal: #0f766e;
  --teal-soft: #e6f4f1;
  --danger: #b42318;
  --shadow: 0 18px 48px rgba(31, 35, 40, 0.08);
  --shadow-soft: 0 8px 24px rgba(31, 35, 40, 0.06);
  --radius: 18px;
  --radius-sm: 11px;
  --font-ui: "Noto Sans CJK SC", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --font-reading: "Noto Serif CJK SC", "Noto Serif SC", "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-mono: "Maple Mono NF CN", "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --reader-scale: 1;
  --bar-height: 58px;
}

[data-theme="dark"] {
  --bg: #111315;
  --bg-elev: #171a1d;
  --bg-soft: #1d2125;
  --bg-code: #0c0e10;
  --ink: #e9e4d9;
  --ink-soft: #c4c0b6;
  --muted: #8f9397;
  --line: #2a2f34;
  --line-strong: #3a4046;
  --accent: #f0a45b;
  --accent-strong: #ffc78a;
  --accent-soft: #2a2018;
  --teal: #5eead4;
  --teal-soft: #12302d;
  --danger: #ff8a80;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
  --shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1100px 560px at 8% -12%, rgba(180, 83, 9, 0.07), transparent 62%),
    radial-gradient(900px 520px at 104% -4%, rgba(15, 118, 110, 0.055), transparent 58%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

[data-theme="dark"] body {
  background:
    radial-gradient(1100px 560px at 8% -12%, rgba(240, 164, 91, 0.08), transparent 62%),
    radial-gradient(900px 520px at 104% -4%, rgba(94, 234, 212, 0.045), transparent 58%),
    var(--bg);
}

::selection {
  background: var(--accent);
  color: #fff;
}

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

a:hover {
  color: var(--accent-strong);
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

img {
  max-width: 100%;
}

[hidden] {
  display: none !important;
}

body.lightbox-open {
  overflow: hidden;
}

.skip-link {
  position: fixed;
  left: 12px;
  top: -60px;
  z-index: 200;
  background: var(--ink);
  color: var(--bg);
  padding: 8px 14px;
  border-radius: 8px;
  transition: top 0.18s ease;
}

.skip-link:focus {
  top: 12px;
  color: var(--bg);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.shell {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 68px;
  padding: 10px max(24px, calc((100vw - 1180px) / 2));
  border-bottom: 1px solid transparent;
  background: rgba(247, 245, 240, 0.82);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
}

[data-theme="dark"] .topbar {
  background: rgba(17, 19, 21, 0.82);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev);
  color: var(--accent);
  box-shadow: var(--shadow-soft);
}

.brand-mark svg {
  width: 26px;
  height: 26px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-text strong {
  font-family: var(--font-reading);
  font-size: 19px;
  letter-spacing: -0.01em;
}

.brand-text small {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ghost-link,
.icon-button,
.text-button,
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  color: var(--ink-soft);
  padding: 7px 11px;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.ghost-link:hover,
.icon-button:hover,
.text-button:hover {
  border-color: var(--line-strong);
  background: var(--bg-elev);
  color: var(--ink);
}

.icon-button {
  width: 34px;
  height: 34px;
  padding: 0;
}

.icon {
  width: 17px;
  height: 17px;
}

[data-theme="light"] .icon-sun,
[data-theme="dark"] .icon-moon {
  display: none;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
}

.primary-button:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
}

/* ---------- hero ---------- */

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(260px, 0.7fr);
  gap: clamp(28px, 5vw, 72px);
  align-items: end;
  padding: clamp(46px, 7vw, 88px) 0 36px;
}

.hero h1 {
  margin: 0;
  font-family: var(--font-reading);
  font-size: clamp(46px, 7vw, 82px);
  font-weight: 700;
  line-height: 0.98;
  letter-spacing: -0.045em;
}

.hero h1::after {
  content: "";
  display: block;
  width: 64px;
  height: 4px;
  margin-top: 20px;
  border-radius: 99px;
  background: var(--accent);
}

.hero-lede {
  max-width: 620px;
  margin: 22px 0 0;
  color: var(--ink-soft);
  font-size: clamp(15px, 1.8vw, 18px);
  line-height: 1.8;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 26px;
  margin-top: 28px;
}

.stat {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.stat strong {
  font-family: var(--font-reading);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat span {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.02em;
}

.hero-note {
  position: relative;
  padding: 22px 22px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
  box-shadow: var(--shadow-soft);
}

.hero-note::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 24px;
  bottom: 24px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

.hero-note p {
  margin: 0;
  color: var(--ink-soft);
  font-family: var(--font-reading);
  font-size: 16px;
  line-height: 1.8;
}

.quote-mark {
  display: block;
  height: 22px;
  color: var(--accent);
  font-family: Georgia, serif;
  font-size: 42px;
  line-height: 0.9;
}

.hero-note-by {
  display: block;
  margin-top: 14px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* ---------- toolbar ---------- */

.toolbar {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 249, 0.72);
  box-shadow: var(--shadow-soft);
}

[data-theme="dark"] .toolbar {
  background: rgba(23, 26, 29, 0.72);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 14px;
  height: 52px;
  border: 1px solid var(--line-strong);
  border-radius: 13px;
  background: var(--bg-elev);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(180, 83, 9, 0.12);
}

.search-box svg {
  width: 20px;
  height: 20px;
  flex: none;
  color: var(--muted);
}

.search-box input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 15px;
}

.search-box input::placeholder {
  color: var(--muted);
}

.search-box kbd {
  flex: none;
  min-width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--bg-soft);
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 11px;
}

.toolbar-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-group:empty {
  display: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid transparent;
  border-radius: 99px;
  background: var(--bg-soft);
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.chip:hover {
  border-color: var(--line-strong);
  color: var(--ink);
}

.chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.chip .chip-count {
  color: var(--muted);
  font-weight: 500;
}

.chip.active .chip-count {
  color: var(--accent-strong);
  opacity: 0.7;
}

.sort-control {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.sort-control select {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-elev);
  padding: 5px 8px;
  color: var(--ink-soft);
  font-size: 12px;
  outline: none;
}

.result-count {
  margin: 12px 2px 0;
  color: var(--muted);
  font-size: 12px;
}

/* ---------- cards ---------- */

.paper-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 18px;
  padding: 26px 0 54px;
}

.paper-card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 280px;
  padding: 22px 22px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
  box-shadow: 0 2px 0 rgba(31, 35, 40, 0.02);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.paper-card::before {
  content: "";
  position: absolute;
  left: 22px;
  right: 22px;
  top: 0;
  height: 2px;
  border-radius: 0 0 2px 2px;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.paper-card:hover {
  transform: translateY(-3px);
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
}

.paper-card:hover::before {
  opacity: 1;
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.card-date {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.02em;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 99px;
  padding: 3px 9px;
  background: var(--bg-soft);
  color: var(--ink-soft);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.6;
}

.status-pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.8;
}

.status-unread {
  background: var(--bg-soft);
  color: var(--muted);
}

.status-reading {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.status-done {
  background: var(--teal-soft);
  color: var(--teal);
}

.status-archived {
  background: var(--bg-soft);
  color: var(--muted);
  opacity: 0.75;
}

.paper-card h2 {
  margin: 0;
  font-family: var(--font-reading);
  font-size: clamp(19px, 2.1vw, 23px);
  font-weight: 700;
  line-height: 1.32;
  letter-spacing: -0.015em;
}

.paper-card h2 a {
  color: var(--ink);
  text-decoration: none;
}

.paper-card h2 a::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
}

.paper-card h2 a:focus-visible {
  outline: none;
}

.paper-card h2 a:focus-visible::after {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.card-title-zh {
  margin: 6px 0 0;
  color: var(--muted);
  font-family: var(--font-reading);
  font-size: 13.5px;
  line-height: 1.65;
}

.card-authors {
  margin: 12px 0 0;
  color: var(--ink-soft);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.card-abstract {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 12px 0 0;
  color: var(--ink-soft);
  font-family: var(--font-reading);
  font-size: 13px;
  line-height: 1.75;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 14px;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--bg-soft);
  color: var(--ink-soft);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.6;
}

.tag::before {
  content: "#";
  margin-right: 2px;
  color: var(--accent);
  opacity: 0.7;
}

.card-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: auto;
  padding-top: 16px;
  color: var(--muted);
  font-size: 10.5px;
  border-top: 1px solid var(--line);
}

.card-foot .card-arrow {
  margin-left: auto;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.card-badges {
  display: inline-flex;
  gap: 4px;
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 17px;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.03em;
}

.badge.on {
  border-color: rgba(15, 118, 110, 0.28);
  background: var(--teal-soft);
  color: var(--teal);
}

/* ---------- empty / error ---------- */

.empty-state {
  margin: 26px 0 70px;
  padding: 54px 28px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  text-align: center;
  background: rgba(255, 253, 249, 0.5);
}

[data-theme="dark"] .empty-state {
  background: rgba(23, 26, 29, 0.5);
}

.empty-state h2 {
  margin: 0;
  font-family: var(--font-reading);
  font-size: 26px;
}

.empty-state p {
  max-width: 560px;
  margin: 10px auto 0;
  color: var(--muted);
  font-size: 14px;
}

.empty-state .primary-button {
  margin-top: 22px;
}

.error-state {
  border-color: rgba(180, 35, 24, 0.35);
}

.error-state code {
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--bg-soft);
  font-family: var(--font-mono);
  font-size: 0.9em;
}

/* ---------- footer ---------- */

.footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 0 40px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.02em;
}

.noscript {
  position: fixed;
  inset: auto 16px 16px;
  z-index: 100;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  text-align: center;
}

/* ---------- reader shell ---------- */

.page-reader {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.progress {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 80;
  width: 100%;
  height: 2px;
  background: transparent;
  pointer-events: none;
}

.progress span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #d97706);
  transition: width 0.08s linear;
}

.reader-bar {
  position: relative;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: var(--bar-height);
  padding: 9px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 245, 240, 0.9);
  backdrop-filter: blur(14px) saturate(1.15);
  -webkit-backdrop-filter: blur(14px) saturate(1.15);
  flex: none;
}

[data-theme="dark"] .reader-bar {
  background: rgba(17, 19, 21, 0.9);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: none;
  color: var(--ink-soft);
  font-size: 12.5px;
  font-weight: 600;
}

.back-link:hover {
  color: var(--accent);
}

.reader-bar-title {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  color: var(--muted);
  font-family: var(--font-reading);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-bar-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: none;
}

.view-tabs {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
}

.view-tab {
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  padding: 5px 10px;
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.5;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.view-tab:hover {
  color: var(--ink);
}

.view-tab[aria-selected="true"] {
  background: var(--bg-elev);
  color: var(--ink);
  box-shadow: 0 1px 5px rgba(31, 35, 40, 0.1);
}

.view-tab:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.sync-toggle {
  padding: 6px 9px;
  font-size: 11px;
}

.sync-toggle[aria-pressed="false"] {
  color: var(--muted);
  opacity: 0.7;
}

.sync-toggle[aria-pressed="true"] {
  border-color: rgba(180, 83, 9, 0.35);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

/* ---------- paper head ---------- */

.paper-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 28px;
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
  padding: 22px 0 18px;
  flex: none;
}

.paper-head-main {
  min-width: 0;
}

.paper-head h1 {
  margin: 0;
  font-family: var(--font-reading);
  font-size: clamp(22px, 2.8vw, 32px);
  font-weight: 700;
  line-height: 1.28;
  letter-spacing: -0.025em;
}

.paper-title-zh {
  margin: 7px 0 0;
  color: var(--muted);
  font-family: var(--font-reading);
  font-size: 14px;
  line-height: 1.65;
}

.paper-meta {
  margin: 9px 0 0;
  color: var(--ink-soft);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.paper-head .tags {
  margin-top: 11px;
}

.paper-head-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  flex: none;
}

.paper-links {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 5px;
}

.paper-links .text-button {
  padding: 5px 8px;
  font-size: 10.5px;
}

.reader-error {
  width: min(760px, calc(100% - 48px));
  margin: 40px auto;
  padding: 34px;
  border: 1px solid rgba(180, 35, 24, 0.35);
  border-radius: var(--radius);
  background: var(--bg-elev);
  text-align: center;
}

.reader-error h2 {
  margin: 0;
  font-family: var(--font-reading);
}

.reader-error p {
  color: var(--muted);
}

/* ---------- reader panes ---------- */

.reader-body {
  flex: 1;
  min-height: 0;
  display: flex;
}

.reader-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: grid;
  border-top: 1px solid var(--line);
  background: var(--line);
}

.reader-main.view-split {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1px;
}

.reader-main.view-en,
.reader-main.view-zh {
  grid-template-columns: minmax(0, 920px);
  justify-content: center;
}

.reader-main.view-pdf {
  grid-template-columns: minmax(0, 1fr);
}

.pane {
  position: relative;
  min-height: 0;
  overflow: auto;
  background: var(--bg);
  overscroll-behavior: contain;
}

.view-split .pane-en,
.view-split .pane-zh {
  border-right: 0;
}

.pane-head {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 245, 240, 0.9);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--muted);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

[data-theme="dark"] .pane-head {
  background: rgba(17, 19, 21, 0.9);
}

.pane-hint {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: none;
}

.markdown {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding: 26px 30px 120px;
  color: var(--ink);
  font-family: var(--font-reading);
  font-size: calc(16.5px * var(--reader-scale));
  line-height: 1.86;
  overflow-wrap: break-word;
}

.markdown > :first-child {
  margin-top: 0;
}

.markdown h1,
.markdown h2,
.markdown h3,
.markdown h4 {
  position: relative;
  color: var(--ink);
  font-family: var(--font-reading);
  font-weight: 700;
  line-height: 1.34;
  letter-spacing: -0.02em;
  scroll-margin-top: 58px;
}

.markdown h1 {
  margin: 2em 0 0.8em;
  font-size: 1.7em;
}

.markdown h2 {
  margin: 2.1em 0 0.7em;
  padding-top: 0.9em;
  border-top: 1px solid var(--line);
  font-size: 1.38em;
}

.markdown h3 {
  margin: 1.7em 0 0.55em;
  font-size: 1.13em;
}

.markdown h4 {
  margin: 1.4em 0 0.4em;
  color: var(--ink-soft);
  font-size: 1em;
}

.markdown h1.doc-title {
  display: none;
}

.markdown p {
  margin: 0 0 1.05em;
}

.markdown a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.markdown a:hover {
  color: var(--accent-strong);
}

.markdown strong {
  font-weight: 700;
}

.markdown ul,
.markdown ol {
  margin: 0 0 1.1em;
  padding-left: 1.45em;
}

.markdown li {
  margin: 0.25em 0;
}

.markdown li > p {
  margin-bottom: 0.4em;
}

.markdown blockquote {
  margin: 1.3em 0;
  padding: 0.85em 1.1em;
  border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0;
  background: var(--accent-soft);
  color: var(--ink-soft);
}

.markdown blockquote p:last-child {
  margin-bottom: 0;
}

.markdown hr {
  margin: 2.2em 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.markdown img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1.3em auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(31, 35, 40, 0.06);
  cursor: zoom-in;
}

.markdown img.img-error {
  min-height: 100px;
  border-style: dashed;
  background: var(--bg-soft);
  cursor: default;
}

.markdown code {
  padding: 0.12em 0.35em;
  border-radius: 4px;
  background: var(--bg-soft);
  font-family: var(--font-mono);
  font-size: 0.86em;
}

.markdown pre {
  position: relative;
  margin: 1.4em 0;
  padding: 16px 18px;
  border-radius: 12px;
  background: var(--bg-code);
  color: #e8e3d8;
  overflow: auto;
  line-height: 1.65;
}

.markdown pre code {
  padding: 0;
  background: transparent;
  color: inherit;
  font-size: 0.82em;
}

.code-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
  color: #d6d0c4;
  padding: 3px 7px;
  font-family: var(--font-ui);
  font-size: 9px;
  line-height: 1.5;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.markdown pre:hover .code-copy,
.code-copy:focus-visible {
  opacity: 1;
}

.code-copy:hover {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}

.table-wrap {
  margin: 1.4em 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-elev);
}

.markdown table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: 0.78em;
  line-height: 1.55;
}

.markdown th,
.markdown td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.markdown th {
  background: var(--bg-soft);
  color: var(--ink-soft);
  font-size: 0.92em;
  font-weight: 700;
  white-space: nowrap;
}

.markdown tr:last-child td {
  border-bottom: 0;
}

.markdown tr:nth-child(even) td {
  background: rgba(0, 0, 0, 0.012);
}

[data-theme="dark"] .markdown tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.018);
}

.heading-anchor {
  margin-left: 0.35em;
  color: var(--accent);
  font-family: var(--font-ui);
  font-size: 0.7em;
  font-weight: 500;
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.markdown h2:hover .heading-anchor,
.markdown h3:hover .heading-anchor,
.markdown h4:hover .heading-anchor,
.heading-anchor:focus-visible {
  opacity: 0.8;
}

.page-marker {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 2.4em 0 1.2em;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  line-height: 1;
  text-transform: uppercase;
  scroll-margin-top: 58px;
}

.page-marker::before,
.page-marker::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.page-marker span {
  flex: none;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--bg);
}

.page-marker:first-child {
  margin-top: 0;
}

.markdown .katex-display {
  margin: 1.2em 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 0;
}

.markdown .katex {
  font-size: 1.02em;
}

.math-scroll {
  display: inline-block;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  vertical-align: bottom;
  padding-bottom: 2px;
}

.math-scroll .katex {
  display: inline-block;
}

.missing-doc {
  max-width: 460px;
  margin: 80px auto;
  padding: 26px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.missing-doc strong {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
  font-family: var(--font-reading);
  font-size: 18px;
}

/* ---------- PDF pane ---------- */

.view-pdf .pane-pdf {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-soft);
}

.pdf-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.pdf-head a {
  font-size: 10px;
  letter-spacing: 0;
  text-transform: none;
}

#pdf-frame {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: 0;
  background: var(--bg-soft);
}

/* ---------- TOC ---------- */

.toc {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 70;
  width: min(360px, 92vw);
  display: flex;
  flex-direction: column;
  padding: 18px;
  border-left: 1px solid var(--line);
  background: var(--bg-elev);
  box-shadow: -24px 0 60px rgba(31, 35, 40, 0.12);
  transform: translateX(102%);
  visibility: hidden;
  transition: transform 0.24s ease, visibility 0.24s ease;
}

.toc.open {
  transform: translateX(0);
  visibility: visible;
}

/* On wide screens the table of contents is a docked sidebar, not a drawer. */
@media (min-width: 1160px) {
  .reader-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(260px, 22vw, 320px);
  }

  .reader-body.toc-hidden {
    grid-template-columns: minmax(0, 1fr);
  }

  .reader-body.toc-hidden .toc {
    display: none;
  }

  .toc {
    position: static;
    top: auto;
    right: auto;
    bottom: auto;
    width: auto;
    height: auto;
    transform: none;
    visibility: visible;
    border-top: 1px solid var(--line);
    box-shadow: none;
    transition: none;
  }

  .toc-backdrop {
    display: none !important;
  }
}

.toc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.toc-head strong {
  font-family: var(--font-reading);
  font-size: 18px;
}

.toc-head .icon-button {
  font-size: 18px;
}

.page-jump {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.page-jump select {
  max-width: 150px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg);
  padding: 5px 7px;
  color: var(--ink-soft);
  font-size: 11px;
}

.toc-list {
  flex: 1;
  overflow: auto;
  padding: 2px 2px 40px;
  overscroll-behavior: contain;
}

.toc-list a {
  display: block;
  padding: 5px 8px;
  border-left: 2px solid transparent;
  border-radius: 0 6px 6px 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.55;
  text-decoration: none;
}

.toc-list a:hover {
  background: var(--bg-soft);
  color: var(--ink);
}

.toc-list a.level-3 {
  padding-left: 20px;
  color: var(--muted);
  font-size: 11.5px;
}

.toc-list a.active {
  border-left-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
}

.toc-empty {
  padding: 18px 8px;
  color: var(--muted);
  font-size: 12px;
}

.toc-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(17, 19, 21, 0.35);
  backdrop-filter: blur(2px);
}

/* ---------- lightbox / toast / to top ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  grid-template-rows: 1fr auto;
  place-items: center;
  gap: 10px;
  padding: 28px;
  background: rgba(10, 12, 14, 0.9);
  backdrop-filter: blur(4px);
}

.lightbox img {
  max-width: min(94vw, 1500px);
  max-height: 84vh;
  border-radius: 8px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  object-fit: contain;
}

.lightbox p {
  max-width: 900px;
  margin: 0;
  color: #d8d2c6;
  font-size: 12px;
  text-align: center;
}

.lightbox-close {
  position: fixed;
  top: 16px;
  right: 18px;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 22px;
  line-height: 1;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.18);
}

.to-top {
  position: fixed;
  right: 20px;
  bottom: 22px;
  z-index: 50;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--bg-elev);
  color: var(--ink-soft);
  box-shadow: var(--shadow-soft);
}

.to-top:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 130;
  transform: translate(-50%, 8px);
  padding: 9px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--bg);
  font-size: 12px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- responsive ---------- */

@media (max-width: 1020px) {
  .hero {
    grid-template-columns: minmax(0, 1fr);
  }

  .hero-note {
    display: none;
  }

  .reader-bar-title {
    display: none;
  }

  .reader-bar-actions {
    margin-left: auto;
  }

  .paper-head {
    flex-direction: column;
    gap: 12px;
  }

  .paper-head-side {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    width: 100%;
  }
}

@media (max-width: 900px) {
  .page-reader,
  .reader-body {
    display: block;
    height: auto;
    overflow: visible;
  }

  .reader-bar {
    position: sticky;
    top: 0;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
  }

  .reader-bar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .view-tabs {
    order: 1;
  }

  .sync-toggle {
    order: 2;
  }

  .paper-head {
    width: calc(100% - 32px);
    padding: 18px 0 14px;
  }

  .sync-toggle {
    display: none;
  }

  .markdown h1,
  .markdown h2,
  .markdown h3,
  .markdown h4,
  .page-marker {
    scroll-margin-top: 108px;
  }

  .paper-head-side {
    flex-direction: column;
    align-items: flex-start;
  }

  .reader-main {
    display: block;
    border-top: 1px solid var(--line);
  }

  .view-split .pane,
  .view-en .pane,
  .view-zh .pane {
    overflow: visible;
  }

  .view-split .pane-en {
    border-bottom: 1px solid var(--line);
  }

  .pane-head {
    position: static;
  }

  .markdown {
    max-width: 100%;
    padding: 22px 18px 70px;
    font-size: calc(16px * var(--reader-scale));
  }

  .view-pdf .pane-pdf {
    height: calc(100vh - 190px);
  }

  .paper-links {
    justify-content: flex-start;
  }

  .to-top {
    right: 14px;
    bottom: 14px;
  }
}

@media (max-width: 620px) {
  .shell {
    width: calc(100% - 28px);
  }

  .topbar {
    padding: 8px 14px;
  }

  .brand-text strong {
    font-size: 17px;
  }

  .hero {
    padding-top: 38px;
  }

  .hero h1 {
    font-size: 52px;
  }

  .toolbar {
    padding: 12px;
  }

  .search-box {
    height: 46px;
  }

  .search-box kbd {
    display: none;
  }

  .toolbar-row {
    align-items: flex-start;
  }

  .sort-control {
    width: 100%;
    justify-content: flex-end;
    margin-top: 2px;
  }

  .paper-grid {
    grid-template-columns: 1fr;
  }

  .paper-card {
    min-height: 0;
  }

  .reader-bar-actions {
    gap: 4px;
  }

  .view-tab {
    padding: 5px 7px;
    font-size: 10.5px;
  }

  .sync-toggle {
    padding: 5px 7px;
    font-size: 10px;
  }

  .icon-button {
    width: 30px;
    height: 30px;
  }

  .paper-head h1 {
    font-size: 22px;
  }

  .paper-links .text-button {
    padding: 4px 6px;
    font-size: 10px;
  }

  .footer {
    flex-direction: column;
    gap: 6px;
  }
}

@media print {
  .topbar,
  .reader-bar,
  .paper-head-side,
  .pane-head,
  .toc,
  .to-top,
  .progress,
  .lightbox,
  .toast {
    display: none !important;
  }

  .page-reader {
    display: block;
    height: auto;
    overflow: visible;
  }

  .reader-main {
    display: block;
    border: 0;
  }

  .pane {
    overflow: visible;
  }

  .markdown {
    max-width: none;
    padding: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
  }
}
