@font-face {
  font-family: "HuWenMingChao";
  src: url("https://mx.bdfz.net/data/fonts/HuWenMingChaoTi.woff2") format("woff2");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #f5efe3;
  --paper-soft: rgba(255, 253, 247, 0.68);
  --paper-strong: rgba(255, 253, 247, 0.94);
  --ink: #31444b;
  --ink-strong: #23363b;
  --muted: #6f8188;
  --line: rgba(86, 111, 118, 0.2);
  --line-strong: rgba(86, 111, 118, 0.34);
  --water: #5e8f84;
  --water-deep: #426d65;
  --petal: #d9a9b8;
  --sun: #dfbf70;
  --sky: #9fbdd1;
  --leaf: #abc591;
  --danger: #b65c4d;
  --shadow: 0 18px 44px rgba(54, 74, 81, 0.14);
  --font: "HuWenMingChao", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font);
  background:
    linear-gradient(120deg, rgba(245, 239, 227, 0.9), rgba(245, 239, 227, 0.78) 42%, rgba(238, 244, 238, 0.84)),
    url("background.jpg");
  background-size: auto, cover;
  background-attachment: fixed;
  line-height: 1.72;
}

body.viewer-open {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink);
  background: linear-gradient(180deg, rgba(255, 253, 247, 0.96), rgba(242, 235, 220, 0.82));
  cursor: pointer;
  transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

button:hover {
  border-color: rgba(66, 109, 101, 0.62);
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(54, 74, 81, 0.1);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
  box-shadow: none;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.9);
  color: var(--ink);
  outline: none;
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--water);
  box-shadow: 0 0 0 4px rgba(94, 143, 132, 0.16);
}

a {
  color: var(--water-deep);
  text-decoration-color: rgba(66, 109, 101, 0.35);
  text-underline-offset: 3px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(292px, 360px) minmax(0, 1fr);
  min-height: 100vh;
}

.lesson-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 14px;
  padding: 20px;
  border-right: 1px solid var(--line);
  background: rgba(255, 253, 247, 0.7);
  backdrop-filter: blur(16px);
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.brand-title {
  color: var(--water-deep);
  font-size: 2.2rem;
  line-height: 1;
  text-decoration: none;
}

#data-status {
  color: var(--muted);
  font-size: 0.88rem;
  white-space: nowrap;
}

.search-panel {
  display: grid;
  gap: 10px;
}

.search-panel label {
  color: var(--water-deep);
  font-size: 0.9rem;
}

#lesson-search {
  min-height: 42px;
  padding: 8px 11px;
}

.block-tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.block-tabs button {
  min-height: 34px;
  padding: 4px 6px;
  color: var(--muted);
  white-space: nowrap;
}

.block-tabs button.active {
  color: #fffaf1;
  border-color: rgba(66, 109, 101, 0.7);
  background: linear-gradient(180deg, rgba(94, 143, 132, 0.95), rgba(66, 109, 101, 0.95));
}

.lesson-list {
  display: grid;
  gap: 8px;
  overflow: auto;
  padding-right: 4px;
}

.lesson-item {
  width: 100%;
  display: grid;
  gap: 4px;
  padding: 10px;
  text-align: left;
  background: rgba(255, 253, 247, 0.66);
}

.lesson-item.active {
  border-color: rgba(66, 109, 101, 0.7);
  background: rgba(232, 242, 236, 0.86);
}

.lesson-item strong {
  display: block;
  font-size: 0.98rem;
  line-height: 1.35;
}

.lesson-item span {
  color: var(--muted);
  font-size: 0.82rem;
}

.lesson-main {
  min-width: 0;
  padding: 20px clamp(18px, 3vw, 38px) 34px;
}

.lesson-toolbar {
  max-width: 1180px;
  margin: 0 auto 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 64px;
  border-bottom: 1px solid var(--line);
}

.sidebar-toggle {
  display: none;
}

.lesson-heading {
  min-width: 0;
}

.lesson-heading h1 {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--ink-strong);
  font-size: clamp(1.8rem, 3vw, 3.1rem);
  line-height: 1.16;
  letter-spacing: 0;
}

.workspace {
  max-width: 1180px;
  margin: 0 auto;
  display: grid;
  gap: 16px;
}

.reading-pane {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 253, 247, 0.66);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.pane-tabs {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  gap: 4px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 247, 0.9);
  backdrop-filter: blur(12px);
  overflow-x: auto;
}

.pane-tabs button {
  min-width: 74px;
  min-height: 34px;
  padding: 4px 12px;
}

.pane-tabs button.active {
  color: #fffaf1;
  border-color: rgba(66, 109, 101, 0.72);
  background: var(--water-deep);
}

.tab-panel {
  display: none;
  padding: clamp(16px, 3vw, 34px);
}

.tab-panel.active {
  display: block;
}

.forum-post {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 18px;
  padding: 22px 0;
  border-bottom: 1px solid var(--line);
}

.forum-post:first-child {
  padding-top: 4px;
}

.forum-post:last-child {
  border-bottom: 0;
}

.forum-post aside {
  position: sticky;
  top: 64px;
  align-self: start;
}

.post-number {
  color: var(--water-deep);
  font-size: 1.05rem;
}

.post-date {
  color: var(--muted);
  font-size: 0.78rem;
}

.cooked {
  min-width: 0;
  max-width: 900px;
  color: #26393f;
  font-size: clamp(1rem, 0.35vw + 0.95rem, 1.13rem);
  line-height: 1.92;
  overflow-wrap: anywhere;
}

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

.cooked > :last-child {
  margin-bottom: 0;
}

.cooked p {
  margin: 0.82em 0;
}

.cooked h1,
.cooked h2,
.cooked h3,
.cooked h4 {
  margin: 1.55em 0 0.6em;
  color: var(--ink-strong);
  line-height: 1.28;
  letter-spacing: 0;
}

.cooked h1 {
  font-size: 1.62rem;
}

.cooked h2 {
  font-size: 1.42rem;
}

.cooked h3 {
  font-size: 1.24rem;
}

.cooked h4 {
  font-size: 1.1rem;
}

.cooked img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  cursor: zoom-in;
}

.cooked .lightbox-wrapper {
  display: inline-grid;
  max-width: 100%;
  margin: 10px 0;
}

.cooked .lightbox {
  display: inline-grid;
  gap: 6px;
  color: inherit;
  text-decoration: none;
}

.cooked .lightbox .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.cooked .lightbox svg {
  display: none;
}

.cooked iframe,
.cooked video {
  max-width: 100%;
}

.cooked blockquote {
  margin: 1em 0;
  padding: 10px 14px;
  border-left: 3px solid var(--water);
  background: rgba(232, 242, 236, 0.62);
}

.cooked table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
}

.cooked td,
.cooked th {
  border: 1px solid var(--line);
  padding: 5px 8px;
}

.cooked sup a {
  padding: 0 2px;
  color: var(--danger);
  text-decoration: none;
}

.cooked .footnote-backref {
  display: none;
}

.cooked a.anchor {
  display: inline-block;
  width: 0;
  height: 0;
  overflow: hidden;
  text-decoration: none;
}

.footnotes-sep {
  margin: 24px 0 14px;
  border: 0;
  border-top: 1px solid var(--line-strong);
}

.footnotes-list {
  margin: 0;
  padding-left: 1.3em;
  color: var(--muted);
  font-size: 0.95rem;
}

.footnotes-list li {
  margin: 0.5em 0;
  padding-left: 0.2em;
}

.bbcode-color {
  color: var(--bbcode-color, var(--danger));
}

.anchor-focus {
  animation: anchorFlash 1300ms ease;
}

@keyframes anchorFlash {
  0%,
  100% {
    background: transparent;
  }
  18%,
  72% {
    background: rgba(223, 191, 112, 0.3);
  }
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.image-tile {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: rgba(255, 253, 247, 0.72);
}

.image-tile img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: contain;
  display: block;
  border-radius: 6px;
  background: rgba(255, 253, 247, 0.8);
  cursor: zoom-in;
}

.image-tile p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.resource-list {
  display: grid;
  gap: 12px;
}

.resource-item {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.68);
  overflow-wrap: anywhere;
}

.resource-link {
  display: grid;
  gap: 3px;
  text-decoration: none;
}

.resource-link strong {
  color: var(--ink-strong);
  font-weight: 600;
}

.resource-link span {
  color: var(--muted);
  font-size: 0.82rem;
}

.resource-embed,
.inline-embed {
  max-width: 900px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.72);
  overflow: hidden;
}

.inline-embed {
  margin: 10px 0 16px;
}

.video-embed {
  aspect-ratio: 16 / 9;
}

.video-embed iframe,
.document-embed iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.document-embed {
  height: min(72vh, 760px);
  min-height: 420px;
}

.embed-image-button {
  width: 100%;
  display: block;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.embed-image-button:hover {
  transform: none;
  box-shadow: none;
}

.embed-image-button img {
  width: 100%;
  max-height: min(72vh, 760px);
  display: block;
  object-fit: contain;
  background: rgba(255, 253, 247, 0.82);
  cursor: zoom-in;
}

.interaction-stack {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.study-section {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 253, 247, 0.7);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 247, 0.72);
}

.section-head h2 {
  margin: 0;
  font-size: 1.08rem;
}

.section-head button {
  min-height: 30px;
  padding: 3px 10px;
}

.chat-log,
.discussion-log {
  display: grid;
  gap: 9px;
  max-height: 360px;
  overflow: auto;
  padding: 12px;
}

.message,
.discussion-comment {
  padding: 9px 10px;
  border-radius: 8px;
  background: rgba(245, 239, 227, 0.76);
  overflow-wrap: anywhere;
}

.message.user {
  background: rgba(232, 242, 236, 0.9);
}

.message .role,
.discussion-comment .comment-meta {
  color: var(--water-deep);
  font-size: 0.82rem;
}

.message p,
.discussion-comment p {
  margin: 4px 0 0;
  white-space: pre-wrap;
}

.chat-form,
.discussion-form {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.chat-form textarea,
.discussion-form textarea,
.discussion-form input {
  padding: 9px 10px;
}

.chat-form button,
.discussion-form button {
  min-height: 38px;
  color: #fffaf1;
  border-color: rgba(66, 109, 101, 0.72);
  background: linear-gradient(180deg, rgba(94, 143, 132, 0.96), rgba(66, 109, 101, 0.96));
}

#discussion-trap {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.empty {
  color: var(--muted);
  padding: 12px;
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 42px 18px 24px;
  background: rgba(31, 43, 47, 0.84);
}

.image-viewer.hidden {
  display: none;
}

.image-viewer img {
  max-width: min(96vw, 1280px);
  max-height: 84vh;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
  cursor: zoom-out;
}

.image-viewer p {
  margin: 10px 0 0;
  color: #fffaf1;
}

.viewer-close {
  position: fixed;
  top: 14px;
  right: 14px;
  width: 42px;
  height: 42px;
  color: #fffaf1;
  background: rgba(31, 43, 47, 0.72);
}

@media (max-width: 1080px) {
  .interaction-stack {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  body {
    background-attachment: scroll;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .lesson-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: min(88vw, 360px);
    transform: translateX(-105%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow);
  }

  body.sidebar-open .lesson-sidebar {
    transform: translateX(0);
  }

  .lesson-main {
    padding: 10px 10px 24px;
  }

  .lesson-toolbar {
    position: sticky;
    top: 0;
    z-index: 20;
    grid-template-columns: auto minmax(0, 1fr);
    min-height: 56px;
    margin-bottom: 10px;
    padding: 8px 0;
    background: rgba(245, 239, 227, 0.9);
    backdrop-filter: blur(12px);
  }

  .sidebar-toggle {
    min-width: 58px;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 10px;
  }

  .lesson-heading h1 {
    font-size: 1.35rem;
    line-height: 1.24;
  }

  .reading-pane,
  .study-section {
    border-radius: 8px;
  }

  .pane-tabs {
    top: 56px;
    padding: 8px;
  }

  .tab-panel {
    padding: 14px;
  }

  .forum-post {
    display: block;
    padding: 18px 0;
  }

  .forum-post aside {
    position: static;
    display: flex;
    gap: 8px;
    align-items: baseline;
    margin-bottom: 8px;
  }

  .post-number {
    font-size: 0.98rem;
  }

  .cooked {
    max-width: 100%;
    font-size: 1rem;
    line-height: 1.86;
  }

  .cooked h1 {
    font-size: 1.34rem;
  }

  .cooked h2 {
    font-size: 1.22rem;
  }

  .cooked h3,
  .cooked h4 {
    font-size: 1.08rem;
  }

  .image-grid {
    grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
    gap: 10px;
  }

  .document-embed {
    min-height: 360px;
    height: 62vh;
  }

  .chat-log,
  .discussion-log {
    max-height: 46vh;
  }
}

@media (max-width: 420px) {
  .block-tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .pane-tabs button {
    min-width: 64px;
    padding-inline: 8px;
  }

  .lesson-heading h1 {
    font-size: 1.18rem;
  }

  .image-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
