/* ————————————————————————————————
   正阳 · 纸墨阅读
   温润纸色为底，墨色为文，朱砂为引。
   ———————————————————————————————— */

:root {
  color-scheme: light;
  --paper: #f6f1e6;
  --paper-raised: #fdfaf2;
  --paper-deep: #ece3d0;
  --ink: #2b251c;
  --ink-soft: #4d4435;
  --muted: #8d8171;
  --line: #ddd1bc;
  --line-soft: rgb(141 129 113 / 22%);
  --red: #9e3b2c;
  --red-dark: #7c2c20;
  --red-soft: rgb(158 59 44 / 7%);
  --shadow-soft:
    0 1px 2px rgb(43 37 28 / 5%),
    0 16px 36px -20px rgb(43 37 28 / 22%);
  --serif: "Songti SC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Noto Sans CJK SC", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(ellipse 55% 38% at 84% -6%, rgb(255 255 255 / 72%), transparent 62%),
    radial-gradient(ellipse 46% 34% at -4% 104%, rgb(158 59 44 / 5%), transparent 66%),
    var(--paper);
  background-attachment: fixed;
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.88;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

::selection {
  color: var(--ink);
  background: rgb(158 59 44 / 16%);
}

a {
  color: var(--red-dark);
  text-decoration-color: rgb(158 59 44 / 32%);
  text-underline-offset: 0.22em;
  transition: color 0.2s ease, text-decoration-color 0.2s ease;
}

a:hover {
  color: var(--red);
  text-decoration-color: currentColor;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
summary:focus-visible {
  border-radius: 0.3rem;
  outline: 2px solid var(--red);
  outline-offset: 3px;
}

/* —— 版面骨架 —— */

.site-header {
  position: sticky;
  z-index: 20;
  top: 0;
  background: rgb(246 241 230 / 92%);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.site-header-inner {
  display: flex;
  align-items: center;
  width: min(100%, 96rem);
  min-height: 4.75rem;
  margin: 0 auto;
  padding: 0 2rem;
}

.site-frame {
  display: grid;
  grid-template-columns: 18.5rem minmax(0, 1fr);
  min-height: calc(100vh - 4.75rem);
}

.site-frame--wide {
  display: block;
}

.course-sidebar {
  padding: 2rem 2.1rem;
  background: rgb(238 229 213 / 70%);
  border-right: 1px solid var(--line);
}

.course-menu > summary {
  display: none;
}

.course-menu > .note-nav {
  display: block;
}

/* 品牌印记：朱砂小印 + 站名 */
.site-brand {
  display: flex;
  align-items: center;
  gap: 0.95rem;
  margin: 0 auto 0 0;
  padding: 0;
  color: var(--ink);
  border: 0;
  text-decoration: none;
}

.brand-seal {
  display: grid;
  flex: none;
  place-items: center;
  width: 2.55rem;
  height: 2.55rem;
  color: #faf5ea;
  background: linear-gradient(155deg, #ab4231, #832c1f);
  border-radius: 0.32rem;
  box-shadow:
    inset 0 0 0 1px rgb(255 255 255 / 20%),
    0 5px 12px -5px rgb(124 44 32 / 60%);
  font-size: 0.84rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  line-height: 1.08;
  text-indent: 0.1em;
  writing-mode: vertical-rl;
}

.brand-name {
  font-size: 1.65rem;
  font-weight: 600;
  letter-spacing: 0.3em;
}

.primary-nav {
  display: flex;
  gap: 0.35rem;
  font-family: var(--sans);
}

.primary-nav a {
  min-height: 2.75rem;
  padding: 0.55rem 0.85rem;
  border-radius: 0.35rem;
  text-decoration: none;
}

.primary-nav a[aria-current="page"] {
  color: var(--red-dark);
  background: var(--red-soft);
}

.course-title {
  margin: 0 0 0.55rem;
  padding-bottom: 0.7rem;
  color: var(--muted);
  border-bottom: 1px solid var(--line-soft);
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.34em;
}

.note-modules {
  display: grid;
  gap: 0.15rem;
}

.note-module {
  border-bottom: 1px solid var(--line-soft);
}

.note-module summary {
  position: relative;
  display: flex;
  align-items: center;
  padding: 0.72rem 0.15rem;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.4;
  list-style: none;
  transition: color 0.2s ease;
}

.note-module summary::-webkit-details-marker {
  display: none;
}

.note-module summary::after {
  flex: none;
  width: 0.4rem;
  height: 0.4rem;
  margin: -0.15rem 0.3rem 0 auto;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  content: "";
  transform: rotate(-45deg);
  transition: transform 0.25s ease, border-color 0.2s ease;
}

.note-module summary:hover {
  color: var(--red-dark);
}

.note-module[open] summary {
  color: var(--red-dark);
}

.note-module[open] summary::after {
  margin-top: 0.15rem;
  border-color: var(--red);
  transform: rotate(45deg);
}

.note-nav ol {
  display: grid;
  gap: 0.3rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.note-module ol {
  gap: 0.1rem;
  padding: 0.15rem 0 0.85rem;
}

.note-nav a {
  display: block;
  padding: 0.56rem 0.75rem 0.56rem 1rem;
  color: var(--ink-soft);
  border: 1px solid transparent;
  border-left: 2px solid transparent;
  border-radius: 0.32rem;
  font-size: 0.92rem;
  line-height: 1.45;
  text-decoration: none;
  transition:
    background 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease;
}

.note-nav a:hover {
  color: var(--ink);
  background: rgb(255 253 248 / 72%);
}

.note-nav a[aria-current="page"] {
  color: var(--red-dark);
  background: var(--paper-raised);
  border-color: var(--line);
  border-left-color: var(--red);
  box-shadow: 0 2px 8px -4px rgb(43 37 28 / 18%);
  font-weight: 600;
}

/* —— 阅读区 —— */

.reading-pane {
  min-width: 0;
  padding: 6rem clamp(2.25rem, 6.5vw, 7.5rem) 7.5rem;
}

.article {
  width: min(100%, 44rem);
  margin: 0 auto;
}

.article h1 {
  margin: 0 0 3.1rem;
  font-size: clamp(2.55rem, 5vw, 4.1rem);
  font-weight: 600;
  letter-spacing: 0.045em;
  line-height: 1.18;
}

.article h1::after {
  display: block;
  width: 3.1rem;
  margin-top: 1.6rem;
  border-top: 2px solid var(--red);
  content: "";
}

.article h2 {
  margin: 5.2rem 0 1.6rem;
  padding-top: 1.7rem;
  border-top: 1px solid var(--line);
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  line-height: 1.35;
}

.article h2::before {
  display: inline-block;
  width: 0.42rem;
  height: 0.42rem;
  margin: 0 0.7rem 0.17rem 0;
  background: var(--red);
  content: "";
  transform: rotate(45deg);
}

.article h3 {
  margin: 2.9rem 0 0.95rem;
  font-size: 1.22rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  line-height: 1.45;
}

.article h4 {
  margin: 2rem 0 0.7rem;
}

.article p,
.article ul,
.article ol {
  margin-top: 0;
  margin-bottom: 1.3rem;
}

.article li + li {
  margin-top: 0.4rem;
}

.article li::marker {
  color: var(--muted);
}

.article strong {
  color: var(--ink);
  font-weight: 700;
}

.article blockquote {
  margin: 2.3rem 0;
  padding: 1.35rem 1.6rem;
  color: var(--ink-soft);
  background: rgb(255 253 248 / 72%);
  border: 1px solid var(--line);
  border-left: 3px solid var(--red);
  border-radius: 0.4rem;
}

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

.article hr {
  height: 1px;
  margin: 4rem 0;
  background: var(--line);
  border: 0;
}

.article table {
  display: block;
  width: 100%;
  margin: 2rem 0 2.5rem;
  overflow-x: auto;
  border-spacing: 0;
  border-collapse: collapse;
  font-size: 0.92rem;
  line-height: 1.65;
}

.article th,
.article td {
  min-width: 7.5rem;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.article thead th {
  border-top: 2px solid var(--ink);
  border-bottom: 1.5px solid var(--ink);
  font-weight: 650;
  white-space: nowrap;
}

.article tbody tr:last-child td {
  border-bottom: 2px solid var(--ink);
}

.article tbody tr {
  transition: background 0.2s ease;
}

.article tbody tr:hover {
  background: var(--red-soft);
}

.article code {
  padding: 0.14em 0.34em;
  background: var(--paper-deep);
  border-radius: 0.2rem;
  font-size: 0.88em;
}

/* —— 首页双入口 —— */

.reading-pane--wide {
  padding-inline: clamp(1.25rem, 5vw, 5rem);
}

.home-portals {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(18rem, 0.65fr);
  gap: 1.25rem;
  width: min(100%, 70rem);
  margin: 0 auto;
}

.home-portal {
  display: flex;
  min-height: 22rem;
  padding: 2.4rem;
  flex-direction: column;
  justify-content: flex-end;
  color: var(--ink);
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  box-shadow: 0 1px 2px rgb(43 37 28 / 4%);
  text-decoration: none;
  transition:
    border-color 0.25s ease,
    box-shadow 0.25s ease,
    transform 0.25s ease;
}

.home-portal--atlas {
  color: #fff8ee;
  background: linear-gradient(145deg, #3f362e, #7c3026);
  border-color: var(--red-dark);
}

.home-portal strong {
  display: block;
  margin: 0.3rem 0 0.6rem;
  font-size: clamp(1.8rem, 4vw, 3.2rem);
  line-height: 1.2;
}

.portal-kicker {
  font-family: var(--sans);
  font-size: 0.75rem;
  letter-spacing: 0.18em;
}

.home-portal:hover {
  color: var(--ink);
  border-color: #c6b49a;
  box-shadow: var(--shadow-soft);
  transform: translateY(-3px);
}

.home-portal--atlas:hover {
  color: #fff8ee;
  border-color: var(--red);
}

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

.course-note-list a {
  display: block;
  margin-bottom: 0.75rem;
  padding: 1rem 1.15rem;
  color: var(--ink);
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  text-decoration: none;
}

/* —— 图谱迁移提示页 —— */

.atlas-moved {
  max-width: 36rem;
  margin: 4rem auto;
  text-align: center;
}

/* —— 移动端 —— */

@media (max-width: 820px) {
  body {
    font-size: 16px;
  }

  .site-header-inner {
    flex-wrap: wrap;
    gap: 0.7rem;
    padding: 0.8rem 1rem;
  }

  .site-brand {
    white-space: nowrap;
  }

  .brand-seal {
    width: 2.3rem;
    height: 2.3rem;
    font-size: 0.78rem;
  }

  .brand-name {
    font-size: 1.45rem;
    letter-spacing: 0.18em;
  }

  .primary-nav {
    width: 100%;
    overflow-x: auto;
  }

  .primary-nav a {
    display: grid;
    flex: 1 0 auto;
    place-items: center;
    min-height: 2.75rem;
    white-space: nowrap;
  }

  .site-frame {
    display: block;
    min-height: 0;
  }

  .course-sidebar {
    padding: 0.75rem 1rem;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .course-menu > summary {
    display: flex;
    min-height: 2.75rem;
    align-items: center;
    cursor: pointer;
  }

  .course-menu:not([open]) > .note-nav {
    display: none;
  }

  .note-nav {
    overflow-x: visible;
  }

  .note-nav ol {
    display: grid;
    width: auto;
    gap: 0.15rem;
  }

  .note-module ol {
    padding-bottom: 0.7rem;
  }

  .note-nav a {
    padding: 0.55rem 0.7rem 0.55rem 0.9rem;
  }

  .reading-pane {
    padding: 3.4rem 1.35rem 5.5rem;
  }

  .article h1 {
    margin-bottom: 2.4rem;
    font-size: clamp(2.2rem, 11vw, 3.1rem);
  }

  .article h2 {
    margin-top: 4.2rem;
  }

  .home-portals {
    grid-template-columns: 1fr;
  }

  .home-portal {
    min-height: 14rem;
    padding: 1.5rem;
  }
}

/* —— 减少动态偏好 —— */

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

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