:root {
  --excipient-blue: #28657a;
  --excipient-blue-soft: #e8f3f6;
  --excipient-amber: #8a5a13;
  --excipient-amber-soft: #fbf3df;
}

.excipient-page .glow-container {
  display: none;
}

.excipient-sidebar {
  width: 310px;
}

@media (min-width: 769px) {
  .excipient-sidebar.collapsed {
    margin-left: -310px;
  }
}

.excipient-sidebar-header .logo-text h1 {
  margin: 0 0 4px;
  font-size: 1rem;
  letter-spacing: 0;
}

.excipient-sidebar-header .logo-text span {
  font-size: 0.7rem;
}

.excipient-filter {
  padding: 0 20px 16px;
}

.excipient-filter label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 700;
}

.excipient-filter select {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--panel-bg);
  color: var(--text-main);
  font: inherit;
  font-size: 0.8rem;
}

.excipient-category-trigger,
.excipient-category-sheet {
  display: none;
}

.excipient-directory {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 18px;
}

.excipient-directory-group + .excipient-directory-group {
  margin-top: 18px;
}

.excipient-directory-group h2 {
  margin: 0 8px 6px;
  color: var(--text-muted);
  font-size: 0.7rem;
  letter-spacing: 0;
}

.excipient-directory-item {
  width: 100%;
  min-height: 52px;
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--text-main);
  text-align: left;
  cursor: pointer;
}

.excipient-directory-item:hover,
.excipient-directory-item.is-active {
  background: var(--primary-light);
  border-left-color: var(--primary-color);
}

.directory-index {
  color: var(--text-muted);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
}

.excipient-directory-label {
  min-width: 0;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 8px;
}

.excipient-directory-item strong {
  font-size: 0.82rem;
  letter-spacing: 0;
}

.excipient-directory-item .excipient-directory-abbr {
  color: var(--primary-color);
  font-size: 0.78rem;
  font-weight: 800;
}

.search-icon svg {
  width: 16px;
  height: 16px;
}

.related-prescription-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.related-prescription-list a {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 7px 10px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--panel-bg);
  color: var(--primary-color);
  font-size: 0.75rem;
  font-weight: 700;
  text-decoration: none;
}

.related-prescription-list a[data-relationship="direct"]::before {
  content: "本方";
  margin-right: 6px;
  color: var(--text-muted);
  font-size: 0.62rem;
}

.related-prescription-list a:hover {
  border-color: var(--primary-color);
  background: var(--primary-light);
}

.directory-empty {
  margin: 16px 20px;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.excipient-sidebar-note {
  margin: 0 16px 16px;
  padding: 12px;
  border-left: 3px solid var(--primary-color);
  background: var(--primary-light);
}

.excipient-sidebar-note strong,
.excipient-sidebar-note span {
  display: block;
}

.excipient-sidebar-note strong {
  margin-bottom: 5px;
  font-size: 0.72rem;
}

.excipient-sidebar-note span {
  color: var(--text-muted);
  font-size: 0.68rem;
  line-height: 1.55;
}

.excipient-main {
  min-width: 0;
}

.excipient-top-bar .view-switch-btn {
  margin-right: 0;
}

.excipient-scroll {
  flex: 1;
  min-height: 0;
  height: auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.excipient-lesson {
  width: min(1020px, 100%);
  margin: 0 auto;
  padding: 34px 40px 72px;
}

.excipient-intro {
  padding-bottom: 28px;
  border-bottom: 2px solid var(--text-main);
}

.excipient-kicker {
  margin-bottom: 10px;
  color: var(--primary-color);
  font-size: 0.76rem;
  font-weight: 800;
}

.excipient-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
}

.excipient-title-row h1 {
  margin: 0 0 10px;
  font-size: 2rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.excipient-title-row p {
  max-width: 680px;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.7;
}

.excipient-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.excipient-badge {
  padding: 5px 8px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--panel-bg);
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 800;
  white-space: nowrap;
}

.excipient-badge.high {
  background: var(--excipient-amber-soft);
  border-color: #dfbd75;
  color: var(--excipient-amber);
}

.memory-line {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 14px;
  margin-top: 24px;
  padding: 16px 0;
  border-top: 1px solid var(--border-color);
}

.memory-line span {
  color: var(--primary-color);
  font-size: 0.72rem;
  font-weight: 800;
}

.memory-line strong {
  font-size: 0.92rem;
  line-height: 1.65;
}

.excipient-section {
  padding: 32px 0;
  border-bottom: 1px solid var(--border-color);
}

.excipient-section .section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.excipient-section .section-heading > div {
  display: flex;
  align-items: center;
  gap: 10px;
}

.excipient-section .section-number {
  color: var(--primary-color);
  font-size: 0.7rem;
  font-weight: 800;
}

.excipient-section h2 {
  font-size: 1.15rem;
  letter-spacing: 0;
}

.excipient-section .section-source {
  color: var(--text-muted);
  font-size: 0.7rem;
}

.context-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: 6px;
}

.context-table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  background: var(--panel-bg);
}

.context-table th,
.context-table td {
  padding: 13px 15px;
  border-bottom: 1px solid var(--border-color);
  text-align: left;
  font-size: 0.82rem;
  line-height: 1.55;
}

.context-table th {
  background: var(--primary-light);
  color: var(--text-muted);
  font-size: 0.72rem;
}

.context-table tr:last-child td {
  border-bottom: 0;
}

.context-table td:nth-child(2) {
  color: var(--primary-color);
  font-weight: 800;
}

.mechanism-list {
  display: grid;
  gap: 10px;
  padding-left: 22px;
}

.mechanism-list li,
.trap-list li {
  color: var(--text-muted);
  font-size: 0.86rem;
  line-height: 1.7;
}

.confusion-list {
  border-top: 1px solid var(--border-color);
}

.confusion-row {
  display: grid;
  grid-template-columns: minmax(150px, 0.4fr) 1fr;
  gap: 20px;
  padding: 16px 4px;
  border-bottom: 1px solid var(--border-color);
}

.confusion-row button {
  justify-self: start;
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--panel-bg);
  color: var(--primary-color);
  font-weight: 800;
  cursor: pointer;
}

.confusion-row p {
  color: var(--text-muted);
  font-size: 0.84rem;
  line-height: 1.65;
}

.trap-list {
  display: grid;
  gap: 10px;
  padding-left: 20px;
}

.quiz-block {
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
}

.quiz-block summary {
  min-height: 58px;
  padding: 17px 36px 17px 4px;
  position: relative;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1.55;
}

.quiz-block summary::after {
  content: "+";
  position: absolute;
  right: 10px;
  color: var(--primary-color);
  font-size: 1.2rem;
}

.quiz-block[open] summary::after {
  content: "−";
}

.quiz-block div {
  padding: 0 30px 18px 4px;
  color: var(--text-muted);
  font-size: 0.86rem;
  line-height: 1.7;
}

.excipient-source-list {
  display: grid;
  gap: 10px;
  list-style: none;
}

.excipient-source-list li {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 12px;
  padding: 13px 0;
  border-top: 1px solid var(--border-color);
}

.source-type {
  align-self: start;
  padding: 5px 7px;
  border-radius: 4px;
  background: var(--primary-light);
  color: var(--primary-color);
  font-size: 0.66rem;
  font-weight: 800;
  text-align: center;
}

.excipient-source-list strong,
.excipient-source-list p {
  display: block;
}

.excipient-source-list strong {
  font-size: 0.84rem;
}

.excipient-source-list p {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 0.76rem;
  line-height: 1.55;
}

.source-boundary {
  margin-top: 14px;
  padding: 12px 14px;
  border-left: 4px solid var(--excipient-amber);
  background: var(--excipient-amber-soft);
  color: #694512;
  font-size: 0.76rem;
  line-height: 1.65;
}

body.dark-theme .excipient-badge.high,
body.dark-theme .source-boundary {
  background: #392a13;
  border-color: #6f5325;
  color: #f2c36b;
}

@supports (height: 100dvh) {
  .excipient-scroll {
    flex: 1;
    min-height: 0;
    height: auto;
  }
}

@media (max-width: 768px) {
  .excipient-sidebar {
    width: min(88vw, 340px);
  }

  .excipient-scroll {
    flex: 1;
    min-height: 0;
    height: auto;
  }

  .excipient-lesson {
    padding: 22px 16px calc(54px + env(safe-area-inset-bottom));
  }

  .excipient-title-row {
    display: grid;
  }

  .excipient-title-row h1 {
    font-size: 1.45rem;
  }

  .excipient-badges {
    justify-content: flex-start;
  }

  .memory-line {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .excipient-section {
    padding: 25px 0;
  }

  .confusion-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .excipient-filter {
    padding: 0 16px 14px;
  }

  .excipient-filter select {
    display: none;
  }

  .excipient-category-trigger {
    width: 100%;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 13px;
    border: 1px solid rgba(47, 107, 47, 0.16);
    border-radius: 16px;
    background: linear-gradient(135deg, rgba(248, 253, 247, 0.98), rgba(235, 247, 237, 0.96));
    color: var(--text-main);
    box-shadow: 0 10px 24px rgba(31, 54, 38, 0.10), inset 0 1px 0 rgba(255, 255, 255, 0.72);
    font: inherit;
    font-size: 0.9rem;
    font-weight: 750;
    text-align: left;
  }

  .excipient-category-trigger svg {
    width: 18px;
    height: 18px;
    color: var(--primary-color);
    flex: 0 0 auto;
  }
}

@media (max-width: 768px) {
  body.excipient-category-picker-open {
    overflow: hidden;
  }

  .excipient-category-sheet.is-open {
    position: fixed;
    inset: 0;
    z-index: 10000040;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0 14px calc(14px + env(safe-area-inset-bottom));
    background: rgba(24, 34, 27, 0.42);
    backdrop-filter: blur(7px);
    -webkit-backdrop-filter: blur(7px);
  }

  .excipient-category-panel {
    width: min(100%, 430px);
    max-height: min(74dvh, 620px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(47, 107, 47, 0.16);
    border-radius: 26px;
    background:
      radial-gradient(circle at 16% 0%, rgba(215, 238, 206, 0.72), transparent 32%),
      linear-gradient(180deg, rgba(253, 255, 251, 0.98), rgba(240, 249, 240, 0.98));
    box-shadow: 0 26px 64px rgba(15, 23, 42, 0.28);
  }

  .excipient-category-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 18px 12px;
    border-bottom: 1px solid rgba(47, 107, 47, 0.10);
  }

  .excipient-category-panel-header p {
    margin: 0 0 4px;
    color: var(--primary-color);
    font-size: 0.72rem;
    font-weight: 800;
  }

  .excipient-category-panel-header h2 {
    margin: 0;
    color: var(--text-main);
    font-size: 1.08rem;
    line-height: 1.25;
    letter-spacing: 0;
  }

  .excipient-category-close {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    border: 0;
    border-radius: 999px;
    background: rgba(47, 107, 47, 0.08);
    color: var(--primary-color);
  }

  .excipient-category-close svg {
    width: 18px;
    height: 18px;
  }

  .excipient-category-options {
    display: grid;
    gap: 8px;
    overflow-y: auto;
    padding: 10px 10px 14px;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }

  .excipient-category-option {
    min-height: 52px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 24px;
    align-items: center;
    gap: 12px;
    padding: 11px 13px;
    border: 1px solid rgba(47, 107, 47, 0.10);
    border-radius: 17px;
    background: rgba(255, 255, 255, 0.72);
    color: var(--text-main);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.68);
    font: inherit;
    font-size: 0.95rem;
    font-weight: 720;
    text-align: left;
  }

  .excipient-category-option::after {
    content: "";
    width: 20px;
    height: 20px;
    border: 2px solid rgba(47, 107, 47, 0.34);
    border-radius: 999px;
    box-sizing: border-box;
  }

  .excipient-category-option.is-selected {
    border-color: rgba(47, 107, 47, 0.28);
    background: rgba(232, 245, 233, 0.94);
    color: var(--primary-color);
  }

  .excipient-category-option.is-selected::after {
    border-color: var(--primary-color);
    background: radial-gradient(circle at center, var(--primary-color) 0 44%, transparent 48%);
  }

  body.dark-theme .excipient-category-trigger {
    border-color: rgba(199, 241, 194, 0.16);
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.92), rgba(25, 44, 32, 0.94));
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.30);
  }

  body.dark-theme .excipient-category-panel {
    border-color: rgba(199, 241, 194, 0.16);
    background:
      radial-gradient(circle at 16% 0%, rgba(64, 108, 70, 0.38), transparent 32%),
      linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(20, 35, 27, 0.98));
  }

  body.dark-theme .excipient-category-option {
    border-color: rgba(199, 241, 194, 0.12);
    background: rgba(15, 23, 42, 0.64);
  }

  body.dark-theme .excipient-category-option.is-selected {
    background: rgba(47, 107, 47, 0.34);
    color: #c7f1c2;
  }
}

@media (max-width: 430px) {
  .excipient-top-bar .top-bar-right {
    gap: 2px;
  }

  .excipient-top-bar .view-switch-btn,
  .excipient-top-bar .theme-btn {
    width: 42px;
    min-width: 42px;
    height: 42px;
  }

  .excipient-top-bar .current-chapter-info span {
    display: none;
  }

  .excipient-section .section-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .excipient-section .section-source {
    padding-left: 28px;
  }
}

/* 辅料双页展示布局 (Excipient Dual Column Grid Layout) */
.excipient-scroll.dual-column .excipient-lesson {
  width: min(1520px, calc(100% - 40px)) !important;
  max-width: 100% !important;
}

.excipient-scroll.dual-column .excipient-grid {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 24px 32px !important;
  align-items: start !important;
}

/* v240: keep the sidebar width consistent without changing excipient content spacing. */
.excipient-sidebar {
  width: var(--study-sidebar-width, 292px) !important;
  flex-basis: var(--study-sidebar-width, 292px) !important;
}

@media (min-width: 769px) {
  .excipient-sidebar.collapsed {
    margin-left: calc(-1 * var(--study-sidebar-width, 292px)) !important;
  }
}

@media (min-width: 769px) and (max-width: 1180px) {
  .excipient-sidebar {
    width: var(--study-sidebar-tablet-width, 246px) !important;
    flex-basis: var(--study-sidebar-tablet-width, 246px) !important;
  }

  .excipient-sidebar.collapsed {
    margin-left: calc(-1 * var(--study-sidebar-tablet-width, 246px)) !important;
  }
}

@media (max-width: 768px) {
  .excipient-sidebar {
    width: min(86vw, 320px) !important;
    flex-basis: auto !important;
  }
}
