:root {
  --bg: #f0f2f5;
  --panel: #ffffff;
  --panel-2: #f8faf9;
  --border: #e3e8ef;
  --text: #202124;
  --muted: #6b7280;
  --dim: #9aa3af;
  --zhu: #c23b22;
  --gold: #1a5c38;
  --accent: #1a5c38;
  --herb: #1a5c38;
  --herb-dark: #134d2e;
  --herb-light: #e8f3ec;
  --herb-mint: #f0f9f4;
  --font: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  background: var(--bg);
  overflow-x: hidden;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.65;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: max(0.7rem, env(safe-area-inset-top)) 1rem 0.7rem;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.link-back {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  height: 2rem;
  padding: 0 0.7rem 0 0.45rem;
  border-radius: 999px;
  border: 1px solid rgba(26, 92, 56, 0.28);
  background: #fff;
  color: var(--herb);
  text-decoration: none;
  font-size: 0.84rem;
  font-weight: 600;
  white-space: nowrap;
}
.link-back:hover { background: #f8fbf9; border-color: rgba(26, 92, 56, 0.45); }

.logo-title {
  flex: 1;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--herb);
}

.tool-row {
  width: 5.5rem;
  flex: none;
}

.page {
  max-width: 520px;
  margin: 0 auto;
  padding: 0.75rem 0.85rem 2rem;
  min-width: 0;
}

.seal-note {
  display: block;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 0.75rem;
  padding: 0.32rem 0.85rem;
  border: 0;
  border-radius: 999px;
  color: #1a5c38;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: #e8f3ec;
  text-align: center;
}

.search-wrap {
  display: block;
  position: relative;
  width: 100%;
  margin: 0 0 0.75rem;
}

.search-wrap::before {
  content: "";
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1rem;
  height: 1rem;
  pointer-events: none;
  opacity: 0.45;
  background: center / contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-3.5-3.5'/%3E%3C/svg%3E");
}

.herb-search {
  width: 100%;
  min-height: 44px;
  padding: 0 0.95rem 0 2.45rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  text-align: left;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.herb-search::placeholder { color: #9aa3af; }
.herb-search:focus {
  border-color: rgba(26, 92, 56, 0.45);
  box-shadow: 0 0 0 3px rgba(26, 92, 56, 0.1);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.cat-tabs {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.15rem;
  margin-bottom: 0.75rem;
  border-bottom: 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.cat-tabs::-webkit-scrollbar { display: none; }

.cat-tab {
  flex: none;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #6b7280;
  background: #fff;
  border: 1px solid #e3e8ef;
  border-radius: 999px;
  padding: 0.32rem 0.72rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.cat-tab:hover { color: var(--herb); border-color: #c5d9cc; }
.cat-tab[aria-selected="true"] {
  color: var(--herb);
  border-color: var(--herb);
  background: #fff;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: stretch;
  min-width: 0;
  width: 100%;
}

.herb-list-wrap {
  background: var(--panel);
  border: 1px solid rgba(227, 232, 239, 0.9);
  border-radius: 14px;
  box-shadow: 0 2px 16px rgba(26, 35, 50, 0.05);
  max-height: min(52vh, 420px);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.herb-list-head {
  padding: 0.62rem 0.85rem;
  border-bottom: 1px solid var(--border);
  color: #9aa3af;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: #fff;
}

.herb-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

.herb-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--text);
  background: transparent;
  border: 0;
  border-bottom: 1px solid #eef1f5;
  padding: 0.72rem 0.85rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.herb-item-main {
  flex: 1;
  min-width: 0;
}

.herb-item-name {
  display: block;
  font-size: 0.98rem;
  font-weight: 700;
  color: #1a5c38;
  line-height: 1.35;
}

.herb-item:hover { background: #f8faf9; }

.herb-item[aria-selected="true"] {
  background: var(--herb-mint);
  box-shadow: inset 4px 0 0 var(--herb);
}

.herb-item[aria-selected="true"] .herb-item-name {
  color: var(--herb-dark);
}

.herb-item-empty {
  color: var(--muted);
  font-weight: 500;
  cursor: default;
  pointer-events: none;
  display: block;
}

.herb-item-empty .herb-item-chevron { display: none; }

.herb-item-action {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.76rem;
  font-weight: 500;
  letter-spacing: 0;
  color: #9aa3af;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.herb-item-chevron {
  flex: 0 0 auto;
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 50%;
  background: #eef0f4;
  display: grid;
  place-items: center;
  color: #9aa3af;
  font-size: 1.05rem;
  line-height: 1;
}

.herb-item-chevron::before {
  content: "›";
  font-weight: 700;
  margin-left: 1px;
}

.herb-item[aria-selected="true"] .herb-item-chevron {
  background: #dceee4;
  color: #1a5c38;
}

.detail {
  border: 1px solid rgba(227, 232, 239, 0.9);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 2px 16px rgba(26, 35, 50, 0.05);
  min-height: 280px;
  padding: 1.05rem 1rem 1.15rem;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.detail-empty {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-align: center;
  padding: 3.5rem 1rem;
}

.detail-body.hidden,
.detail-empty.hidden,
.hidden { display: none !important; }

.detail-head {
  margin-bottom: 0.2rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px dashed #e3e8ef;
}

.detail-head h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #1a5c38;
  line-height: 1.3;
}

.meta-sub {
  margin-top: 0.35rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: #9aa3af;
  line-height: 1.5;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.meta-tag {
  display: inline-block;
  margin-top: 0.55rem;
  padding: 0.18rem 0.62rem;
  border-radius: 999px;
  color: #1a5c38;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--herb-light);
}

.detail-sections {
  display: flex;
  flex-direction: column;
}

.meta-block {
  margin: 0;
  padding: 0.85rem 0 0.75rem;
  border-bottom: 1px dashed #e3e8ef;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
}

.meta-block:last-child {
  border-bottom: 0;
  padding-bottom: 0.15rem;
}

.meta-block h2 {
  display: flex;
  align-items: center;
  gap: 0.42rem;
  margin: 0 0 0.45rem;
  padding: 0;
  border-radius: 0;
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #1a5c38;
  background: transparent;
}

.meta-block h2::before {
  content: "";
  flex: 0 0 auto;
  width: 3px;
  height: 0.88rem;
  border-radius: 2px;
  background: #1a5c38;
}

.meta-block--inline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem 1.5rem;
}

.meta-pair h2 {
  margin-bottom: 0.28rem;
}

.meta-pair p {
  margin: 0;
  font-size: 0.94rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.65;
}

.meta-content p,
.bullet-list {
  font-size: 0.94rem;
  font-weight: 500;
  color: #374151;
  line-height: 1.75;
}

.meta-prose {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.8;
  max-width: 100%;
}

.meta-bracket {
  color: #b45309;
  font-weight: 700;
  background: rgba(180, 83, 9, 0.08);
  padding: 0 0.12em;
  border-radius: 3px;
}

.meta-block.hidden {
  display: none !important;
}

.meta-fold {
  padding-top: 0.7rem;
}

.meta-fold-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.meta-fold-summary::-webkit-details-marker { display: none; }

.meta-fold-summary h2 {
  margin: 0;
}

.meta-fold-hint::after {
  content: "展开";
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--herb);
  letter-spacing: 0.04em;
}

.meta-fold[open] .meta-fold-hint::after {
  content: "收起";
}

.meta-fold .meta-content {
  margin-top: 0.45rem;
}

.bullet-list {
  list-style: none;
}

.bullet-list li {
  position: relative;
  padding: 0.1rem 0 0.1rem 0.85rem;
  margin: 0;
  border-radius: 0;
  background: transparent;
}

.bullet-list li::before {
  content: "·";
  position: absolute;
  left: 0.1rem;
  top: 0.06rem;
  color: var(--herb);
  font-weight: 700;
}

.meta-ref {
  margin-bottom: 0.75rem;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
}

.meta-ref:last-child { margin-bottom: 0; }

.meta-ref-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
  margin-bottom: 0.2rem;
}

.meta-ref-passage {
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.75;
}

.load-error {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid rgba(194, 59, 34, 0.35);
  border-radius: 10px;
  background: rgba(194, 59, 34, 0.06);
  color: var(--zhu);
  font-size: 0.9rem;
  font-weight: 600;
}

.page-foot {
  max-width: 520px;
  margin: 0 auto;
  padding: 0 0.85rem max(2rem, env(safe-area-inset-bottom));
  text-align: center;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  overflow-wrap: anywhere;
}

.page-foot-attr { margin-top: 0.28rem; }

.page-foot a {
  color: var(--herb);
  font-weight: 700;
  text-decoration: none;
}

.page-foot a:hover { text-decoration: underline; }

@media (min-width: 900px) {
  .page,
  .page-foot {
    max-width: 960px;
  }

  .workspace {
    display: grid;
    grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
    gap: 1rem;
    align-items: start;
  }

  .herb-list-wrap {
    max-height: min(70vh, 720px);
  }
}

@media (max-width: 820px) {
  body { font-size: 14.5px; }

  .top-bar {
    gap: 0.45rem;
    padding-left: 0.7rem;
    padding-right: 0.7rem;
  }

  .tool-row { width: 0.5rem; }

  .logo-title {
    font-size: 0.98rem;
    letter-spacing: 0.08em;
  }

  .link-back {
    font-size: 0.78rem;
    padding: 0 0.55rem 0 0.35rem;
  }

  .page { padding: 0.65rem 0.65rem 1.5rem; }

  .herb-list-wrap {
    max-height: 46vh;
  }

  .detail {
    padding: 0.95rem 0.85rem 1.05rem;
  }

  .detail-head h1 {
    font-size: 1.45rem;
  }

  .meta-block--inline {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.85rem;
  }

  .meta-content p,
  .bullet-list,
  .meta-prose {
    font-size: 0.92rem;
  }
}
