:root {
  --bg: #f3efe7;
  --panel: #1f2a28;
  --panel-accent: #d7b170;
  --panel-ink: #f7f2e8;
  --paper: #fffdf8;
  --ink: #1f1d1a;
  --muted: #6a645c;
  --border: rgba(31, 29, 26, 0.12);
  --soft-line: rgba(31, 29, 26, 0.08);
  --highlight: rgba(215, 177, 112, 0.22);
  --highlight-ink: #7a4f14;
  --shadow: 0 24px 60px rgba(24, 23, 20, 0.12);
  --ui-font: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --paper-font: "Noto Serif SC", "Source Han Serif SC", "Songti SC", serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at top, rgba(215, 177, 112, 0.2), transparent 32%),
    linear-gradient(180deg, #eee7da 0%, var(--bg) 100%);
  font-family: var(--paper-font);
}

.page-shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 24px;
  padding: 24px 24px 40px;
}

body.panel-hidden .page-shell {
  grid-template-columns: 1fr;
}

.floating-controls {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  max-width: min(92vw, 420px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.floating-controls.is-hidden-by-scroll {
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
}

.floating-button {
  padding: 10px 16px;
  border: 1px solid rgba(31, 29, 26, 0.14);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.92);
  color: #18211f;
  box-shadow: 0 10px 24px rgba(24, 23, 20, 0.1);
  cursor: pointer;
  font: 500 14px/1 var(--ui-font);
  backdrop-filter: blur(10px);
}

.floating-button.is-secondary {
  background: rgba(247, 242, 232, 0.86);
}

.floating-button.is-hidden {
  color: var(--muted);
  background: rgba(255, 253, 248, 0.72);
  box-shadow: 0 8px 18px rgba(24, 23, 20, 0.08);
}

.side-panel {
  position: sticky;
  top: 24px;
  align-self: start;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 16px;
  height: calc(100vh - 48px);
  max-height: calc(100vh - 48px);
  min-height: 0;
  overflow: hidden;
}

.panel-card {
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.meta-card {
  padding: 24px;
  color: var(--panel-ink);
  background: linear-gradient(180deg, #283734 0%, var(--panel) 100%);
}

.toc-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  height: 100%;
  border: 1px solid var(--border);
  background: rgba(255, 253, 248, 0.94);
  backdrop-filter: blur(8px);
  overflow: hidden;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--panel-accent);
  font: 600 12px/1.2 var(--ui-font);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.meta-card h1,
.toc-header h2 {
  margin: 0 0 10px;
  line-height: 1.1;
}

.meta-card h1 {
  font-size: 29px;
}

.toc-header h2 {
  font-size: 24px;
  color: #1b1a18;
}

.meta,
.hint,
.toc-state {
  margin: 0 0 10px;
  line-height: 1.7;
}

.meta {
  color: rgba(247, 242, 232, 0.84);
}

.hint,
.toc-state {
  color: var(--muted);
  font-family: var(--ui-font);
  font-size: 13px;
}

#refreshButton {
  margin: 12px 0 8px;
  padding: 12px 18px;
  border: 0;
  border-radius: 999px;
  color: #18211f;
  background: #f1d39c;
  cursor: pointer;
  font: 600 14px/1 var(--ui-font);
}

#refreshButton:disabled {
  cursor: wait;
  opacity: 0.75;
}

.source-files {
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px solid rgba(247, 242, 232, 0.18);
}

.source-files summary {
  cursor: pointer;
  font: 600 14px/1.4 var(--ui-font);
  color: #f3e4c0;
}

.source-file-list {
  margin: 12px 0 0;
  padding-left: 18px;
  max-height: 168px;
  overflow: auto;
  color: rgba(247, 242, 232, 0.84);
  font: 400 13px/1.7 var(--ui-font);
}

.toc-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--soft-line);
}

.toc-list {
  min-height: 0;
  padding: 10px 10px 14px 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.toc-link {
  display: block;
  margin: 2px 6px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 14px;
  color: var(--ink);
  text-decoration: none;
  font: 500 14px/1.45 var(--ui-font);
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease;
}

.toc-link:hover {
  border-color: rgba(215, 177, 112, 0.2);
  background: #f8f2e7;
}

.toc-link.active {
  border-color: rgba(215, 177, 112, 0.34);
  background: var(--highlight);
  color: var(--highlight-ink);
}

.toc-link[data-level="1"] {
  font-weight: 700;
}

.toc-link[data-level="2"] {
  padding-left: 22px;
}

.toc-link[data-level="3"] {
  padding-left: 34px;
  color: var(--muted);
  font-size: 13px;
}

.content-shell {
  min-width: 0;
}

.paper {
  max-width: 980px;
  margin: 0 auto;
  padding: 88px 72px 56px;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: var(--paper);
  box-shadow: var(--shadow);
  line-height: 1.95;
  font-size: 17px;
}

body.panel-hidden .paper {
  max-width: 1120px;
}

.paper :is(h1, h2, h3) {
  scroll-margin-top: 84px;
}

.paper h1,
.paper h2,
.paper h3,
.paper h4 {
  color: #18211f;
  line-height: 1.35;
}

.paper h1 {
  margin-top: 0;
  padding-bottom: 16px;
  border-bottom: 2px solid rgba(201, 165, 106, 0.4);
  font-size: 34px;
}

.paper h2 {
  margin-top: 40px;
  font-size: 28px;
}

.paper h3 {
  margin-top: 28px;
  font-size: 22px;
}

.paper p,
.paper li {
  word-break: break-word;
}

.paper p {
  text-indent: 2em;
}

.paper li p,
.paper blockquote p {
  text-indent: 0;
}

.paper ul,
.paper ol {
  padding-left: 1.6em;
}

.paper a {
  color: #7a4f14;
}

.paper blockquote {
  margin: 24px 0;
  padding: 12px 20px;
  border-left: 4px solid #c9a56a;
  color: #544d44;
  background: #fbf6ea;
}

.paper table {
  width: 100%;
  margin: 24px 0;
  border-collapse: collapse;
  overflow: hidden;
  font-size: 15px;
}

.paper img {
  max-width: 100%;
  height: auto;
}

.paper .thesis-figure {
  margin: 24px 0 10px;
  padding: 18px;
  border: 1px solid rgba(31, 29, 26, 0.1);
  border-radius: 20px;
  background: #fcfaf5;
}

.paper th,
.paper td {
  padding: 10px 12px;
  border: 1px solid rgba(31, 29, 26, 0.12);
  text-align: left;
}

.paper th {
  background: #f4ecdd;
}

.loading {
  color: var(--muted);
}

@media (max-width: 1100px) {
  .page-shell,
  body.panel-hidden .page-shell {
    grid-template-columns: 1fr;
  }

  .side-panel {
    position: static;
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .toc-list {
    max-height: 360px;
  }
}

@media (max-width: 720px) {
  /* 防止 iOS 横竖屏切换时自动缩放字号 */
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  .page-shell {
    padding: 16px 14px 28px;
  }

  .floating-controls {
    top: 12px;
    left: 12px;
    right: 12px;
    max-width: none;
  }

  .toc-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .paper {
    padding: 80px 22px 40px;
    font-size: 18px;
    line-height: 1.95;
    letter-spacing: 0.04em;
  }

  .paper h1 { font-size: 26px; }
  .paper h2 { font-size: 22px; }
  .paper h3 { font-size: 19px; }
}
