/* Fusion Bookstore — component styles.
   Layout: sticky topbar (mirrors velowiki's wiki-topbar) + filter rail
   + responsive card grid. Detail page reuses the same panel/card tokens. */

.bookstore-page { min-width: 0; background: var(--bg); }

.bs-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
  min-height: 64px;
  padding: .65rem clamp(1rem, 3vw, 3rem);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(16px);
}
.bs-brand {
  display: grid;
  gap: .05rem;
  min-height: 44px;
  align-content: center;
  color: var(--teal);
  font-family: Georgia, "Source Han Serif SC", serif;
}
.bs-brand span { color: var(--muted); font: 500 .66rem/1.2 ui-sans-serif, system-ui, sans-serif; }
.bs-brand strong { font-size: 1.08rem; }
.bs-toplinks { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.bs-toplinks a, .bs-toplinks button {
  min-height: 38px;
  padding: 0 .65rem;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.bs-toplinks a:hover, .bs-toplinks button:hover { background: #efede8; color: var(--ink); }
.bs-toplinks .bs-products-link:hover { color: var(--teal); }

.bs-shell {
  width: min(1360px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.5rem 0 4rem;
}

.bs-hero {
  display: grid;
  gap: 1rem;
  padding: clamp(1rem, 3vw, 2.5rem) 0 1.2rem;
  border-bottom: 1px solid var(--line);
}
.bs-hero p.bs-kicker {
  margin: 0 0 .45rem;
  color: var(--teal);
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.bs-hero h1 {
  margin: 0;
  max-width: 26ch;
  color: var(--ink);
  font-family: Georgia, "Source Han Serif SC", serif;
  letter-spacing: 0;
  font-size: clamp(2rem, 3.5vw, 3.25rem);
  line-height: 1.12;
}
.bs-hero p { max-width: 54rem; margin: 0; color: var(--muted); line-height: 1.7; }

.bs-search-field {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .55rem;
  align-items: stretch;
  max-width: 36rem;
}
.bs-search-field input {
  min-width: 0;
  min-height: 42px;
  padding: .55rem .7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
}
.bs-search-field button {
  min-height: 42px;
  padding: 0 .9rem;
  border: 1px solid var(--teal);
  border-radius: 6px;
  background: var(--teal);
  color: #fff;
  font-weight: 700;
}
.bs-search-field button:hover { background: #852721; border-color: #852721; }
.bs-search-scopes {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: .35rem .7rem;
  margin: -.15rem 0 0;
  padding: 0;
  border: 0;
  color: var(--muted);
  font-size: .74rem;
}
.bs-search-scopes legend { width: 100%; margin-bottom: .1rem; color: var(--muted); font-size: .72rem; font-weight: 700; }
.bs-search-scopes label { display: inline-flex; min-height: 24px; align-items: center; gap: .28rem; white-space: nowrap; }
.bs-search-scopes input[type="checkbox"] { min-height: 0; margin: 0; padding: 0; accent-color: var(--teal); }
.bs-search-scopes input[type="checkbox"]:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.bs-search-scope-status { grid-column: 1 / -1; margin: -.25rem 0 0; color: #852721; font-size: .76rem; font-weight: 700; }

.bs-stats-row {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
}
.bs-stat-pill {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .2rem .55rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: .74rem;
}
.bs-stat-pill strong { color: var(--ink); font-weight: 700; }

/* ---- subject hub ---- */

.bs-hub-hero { gap: .85rem; }
.bs-hub-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  align-items: center;
  color: var(--muted);
  font-size: .84rem;
}
.bs-hub-actions .bs-action { margin: 0; }
.bs-subject-guide { padding-top: clamp(1.5rem, 3vw, 2.5rem); }
.bs-section-heading, .bs-shelf-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
}
.bs-section-heading { padding-bottom: .9rem; border-bottom: 1px solid var(--line); }
.bs-section-heading .bs-kicker { margin: 0 0 .35rem; }
.bs-section-heading h2, .bs-shelf-heading h3 {
  margin: 0;
  color: var(--ink);
  font-family: Georgia, "Source Han Serif SC", serif;
}
.bs-section-heading h2 { font-size: clamp(1.35rem, 2vw, 1.75rem); }
.bs-text-link { color: var(--teal); font-size: .84rem; font-weight: 700; white-space: nowrap; }
.bs-text-link:hover { color: #852721; text-decoration: underline; }
.bs-action-secondary {
  border-color: var(--line);
  background: var(--panel);
  color: var(--teal);
}
.bs-action-secondary:hover { border-color: #852721; background: #852721; color: #fff; }
.bs-hub-status { margin: .8rem 0 0; color: var(--muted); font-size: .84rem; }
.bs-subject-groups { display: grid; gap: 1.25rem; margin-top: 1.1rem; }
.bs-subject-shelf {
  padding: clamp(1rem, 2vw, 1.35rem);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.bs-shelf-heading { margin-bottom: .85rem; }
.bs-shelf-heading h3 { font-size: 1.12rem; }
.bs-shelf-heading p { max-width: 50rem; margin: .32rem 0 0; color: var(--muted); font-size: .85rem; line-height: 1.6; }
.bs-shelf-grid { min-height: 0; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.bs-shelf-grid .bs-card { min-height: 12.75rem; }
.bs-term-guide { padding-top: clamp(1.5rem, 3vw, 2.5rem); }
.bs-term-chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.bs-term-chip {
  display: inline-flex;
  max-width: 100%;
  min-height: 34px;
  align-items: center;
  padding: .35rem .6rem;
  overflow: hidden;
  border: 1px solid #d7b9b2;
  border-radius: 999px;
  background: var(--teal-soft);
  color: var(--ink);
  font-size: .78rem;
  font-weight: 700;
  overflow-wrap: anywhere;
  text-overflow: ellipsis;
}
.bs-term-chip:hover, .bs-term-chip:focus-visible { border-color: #852721; background: #852721; color: #fff; }
.bs-term-popover {
  position: absolute;
  top: calc(100% + .4rem);
  right: 0;
  left: 0;
  z-index: 30;
  display: grid;
  gap: .7rem;
  padding: .85rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 28px rgba(44, 36, 29, .16);
}
.bs-search-field { position: relative; }
.bs-term-popover .bs-action { margin: 0; justify-self: start; }
.bs-term-popover-label, .bs-term-empty { margin: 0; color: var(--muted); font-size: .78rem; }
.bs-term-dialog {
  width: min(760px, calc(100% - 2rem));
  max-height: min(80vh, 760px);
  padding: clamp(1rem, 3vw, 1.5rem);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
}
.bs-term-dialog::backdrop { background: rgba(28, 24, 20, .48); }
.bs-term-dialog-heading { display: flex; align-items: start; justify-content: space-between; gap: 1rem; }
.bs-term-dialog-heading h2 { margin: 0; color: var(--ink); font-family: Georgia, "Source Han Serif SC", serif; }
.bs-term-dialog-heading .bs-kicker { margin: 0 0 .35rem; }
.bs-dialog-close {
  width: 38px;
  min-width: 38px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--teal);
  font-size: 1.35rem;
  line-height: 1;
}
.bs-dialog-close:hover { border-color: #852721; background: #852721; color: #fff; }
.bs-term-dialog-search { display: grid; gap: .35rem; margin-top: 1rem; color: var(--muted); font-size: .8rem; font-weight: 700; }
.bs-term-dialog-search input { min-height: 40px; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text); }
.bs-term-dialog-results { display: grid; gap: 1rem; margin-top: 1rem; }
.bs-term-domain { display: grid; gap: .5rem; padding-top: .9rem; border-top: 1px solid var(--line); }
.bs-term-domain h3 { margin: 0; color: var(--ink); font-family: Georgia, "Source Han Serif SC", serif; font-size: 1rem; }

/* ---- filter rail + card grid ---- */

.bs-layout {
  display: grid;
  grid-template-columns: minmax(220px, .85fr) minmax(0, 2.7fr);
  gap: clamp(1rem, 2.4vw, 2.4rem);
  margin-top: 1.5rem;
}

.bs-filter-rail {
  position: sticky;
  top: 5.25rem;
  align-self: start;
  display: grid;
  gap: 1rem;
  padding: 1.1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  max-height: calc(100vh - 6.5rem);
  overflow: auto;
}

.bs-filter-rail h2 {
  margin: 0;
  color: var(--ink);
  font-family: Georgia, "Source Han Serif SC", serif;
  font-size: 1rem;
}

.bs-filter-group {
  display: grid;
  gap: .45rem;
  padding-bottom: .9rem;
  border-bottom: 1px dashed var(--line);
}
.bs-filter-group:last-child { padding-bottom: 0; border-bottom: 0; }

.bs-filter-group > label {
  display: grid;
  gap: .35rem;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
}

.bs-filter-group fieldset {
  display: grid;
  gap: .3rem;
  margin: 0;
  padding: 0;
  border: 0;
}
.bs-filter-group legend {
  padding: 0 0 .35rem;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
}
.bs-check {
  display: flex;
  align-items: center;
  gap: .35rem;
  color: var(--text);
  font-size: .82rem;
  font-weight: 500;
}
.bs-check input { accent-color: var(--teal); }

.bs-year-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .35rem;
  align-items: center;
}
.bs-year-row input[type=range] { width: 100%; accent-color: var(--teal); }
.bs-year-row output {
  min-width: 3.6rem;
  text-align: right;
  color: var(--teal);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.bs-filter-actions {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
}
.bs-filter-actions button {
  flex: 1 1 auto;
  min-height: 38px;
  padding: 0 .55rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
}
.bs-filter-actions button.is-primary {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}
.bs-filter-actions button:hover { background: var(--teal-soft); color: var(--ink); }
.bs-filter-actions button.is-primary:hover { background: #852721; color: #fff; }

/* ---- card grid ---- */

.bs-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 1rem;
  align-content: start;
  min-height: 24rem;
}

.bs-empty {
  grid-column: 1 / -1;
  padding: 1.6rem;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-size: .9rem;
  text-align: center;
}

.bs-card {
  display: grid;
  min-width: 0;
  overflow: hidden;
  align-content: start;
  gap: .55rem;
  min-height: 13.5rem;
  padding: 1.05rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  transition: border-color .15s ease, transform .15s ease, background .15s ease;
  cursor: pointer;
  text-align: left;
}
.bs-card:hover {
  border-color: #caa8a1;
  background: var(--teal-soft);
  transform: translateY(-2px);
}
.bs-card:focus-visible {
  border-color: var(--teal);
  background: var(--teal-soft);
}
.bs-card-title {
  display: -webkit-box;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-family: Georgia, "Source Han Serif SC", serif;
  font-size: 1.12rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}
.bs-card-meta {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  gap: .35rem;
  color: var(--muted);
  font-size: .78rem;
}
.bs-card-meta span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bs-card-summary {
  display: -webkit-box;
  min-width: 0;
  max-width: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
  word-break: break-word;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}
.bs-card-body-hit {
  display: -webkit-box;
  min-width: 0;
  max-width: 100%;
  margin: .25rem 0 0;
  overflow: hidden;
  color: var(--teal);
  font-size: .8rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
  word-break: break-word;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.bs-card-body-hit::before {
  content: "📖 ";
}
.bs-search-highlight {
  padding: 0 .08em;
  border-radius: 2px;
  background: #f8e7a8;
  color: inherit;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
.bs-card-tags {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  gap: .3rem;
}
.bs-card-tags span {
  max-width: 100%;
  padding: .12rem .42rem;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: .7rem;
  overflow-wrap: anywhere;
  text-overflow: ellipsis;
}
.bs-card-status {
  display: flex;
  min-width: 0;
  gap: .35rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: .35rem;
  border-top: 1px dashed var(--line);
}
.bs-badge {
  display: inline-block;
  max-width: 100%;
  padding: .14rem .46rem;
  overflow: hidden;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 700;
  overflow-wrap: anywhere;
  text-overflow: ellipsis;
}
.bs-badge.is-text { background: #e6f3eb; color: var(--green); }
.bs-badge.is-scanned { background: #fdf1de; color: var(--amber); }
.bs-badge.is-unknown { background: #eeeae3; color: var(--soft); }
.bs-badge.is-djvu { background: #efe1f6; color: #5a2c80; }
.bs-badge.is-source {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-weight: 500;
}
.bs-badge.is-md { background: #e2eaf2; color: #1f4878; }

/* ---- detail page ---- */

.bs-detail-shell { padding-top: 1rem; }

.bs-detail-topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
  padding-bottom: 1.1rem;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.bs-detail-topbar .bs-back {
  min-height: 38px;
  padding: 0 .65rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--teal);
  font-size: .84rem;
  font-weight: 700;
}
.bs-detail-topbar .bs-back:hover { background: var(--teal-soft); border-color: var(--teal); }

.bs-detail-title h1 {
  margin: .35rem 0 .5rem;
  color: var(--ink);
  font-family: Georgia, "Source Han Serif SC", serif;
  font-size: clamp(1.8rem, 3.2vw, 2.6rem);
  line-height: 1.18;
}
.bs-detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  align-items: center;
}
.bs-detail-meta span { color: var(--muted); font-size: .82rem; }
.bs-detail-meta .bs-divider { color: var(--soft); }

.bs-detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(220px, 1fr);
  gap: clamp(1rem, 2.4vw, 2.4rem);
  margin-top: 1.5rem;
  align-items: start;
}

.bs-tabs {
  display: flex;
  gap: .35rem;
  flex-wrap: wrap;
  padding-bottom: .55rem;
  border-bottom: 1px solid var(--line);
}
.bs-tabs button {
  min-height: 38px;
  padding: 0 .7rem;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: .84rem;
  font-weight: 700;
}
.bs-tabs button[aria-selected="true"] {
  color: var(--ink);
  border-bottom-color: var(--teal);
}

.bs-tab-panel {
  margin-top: 1rem;
  padding: clamp(1rem, 2vw, 1.6rem);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  min-height: 18rem;
}

.bs-reader {
  max-height: 80vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.bs-reader h1, .bs-reader h2, .bs-reader h3, .bs-reader h4 {
  color: var(--ink);
  font-family: Georgia, "Source Han Serif SC", serif;
  margin-top: 1.6rem;
}
.bs-reader h1 { font-size: 1.5rem; }
.bs-reader h2 { font-size: 1.25rem; }
.bs-reader h3 { font-size: 1.1rem; color: var(--teal); }
.bs-reader p { line-height: 1.85; }
.bs-reader pre {
  overflow: auto;
  padding: .9rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #f7f6f3;
  font: .82rem/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.bs-reader :not(pre) > code {
  padding: .1rem .28rem;
  border-radius: 3px;
  background: #f0eee9;
  font: .84em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.bs-reader img { max-width: 100%; height: auto; margin: .8rem auto; border: 1px solid var(--line); border-radius: 4px; }
.bs-reader blockquote {
  margin: 1rem 0;
  padding: .25rem 0 .25rem 1rem;
  border-left: 2px solid var(--teal);
  color: var(--muted);
}
.bs-reader table {
  width: 100%;
  margin: 1rem 0;
  border-collapse: collapse;
  font-size: .85rem;
}
.bs-reader th, .bs-reader td {
  padding: .55rem;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  line-height: 1.55;
}
.bs-reader th { background: #f7f6f3; color: var(--ink); }
.bs-reader .katex-display { margin: .5rem 0 !important; overflow-x: auto; overflow-y: hidden; }

.bs-pdf-host {
  display: grid;
  gap: .65rem;
  min-height: 24rem;
}
.bs-pdf-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .55rem;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: .82rem;
}
.bs-pdf-toolbar button {
  min-height: 36px;
  padding: 0 .55rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel);
  color: var(--muted);
  font-size: .8rem;
  font-weight: 700;
}
.bs-pdf-toolbar button:hover { background: var(--teal-soft); color: var(--ink); }
.bs-pdf-toolbar input[type=number] {
  width: 4rem;
  min-height: 36px;
  padding: 0 .4rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel);
  color: var(--text);
  text-align: right;
}
.bs-pdf-canvas-wrap {
  display: grid;
  gap: .65rem;
  padding: .75rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7f6f3;
  overflow: auto;
  max-height: 80vh;
  justify-items: center;
}
.bs-pdf-canvas-wrap canvas {
  background: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .15);
  max-width: 100%;
}
.bs-pdf-empty {
  display: grid;
  gap: .55rem;
  padding: 1.2rem;
  border: 1px dashed var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: #fbfaf7;
}
.bs-pdf-empty a {
  color: var(--teal);
  font-weight: 700;
}

.bs-aside {
  display: grid;
  gap: 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.bs-aside section { display: grid; gap: .35rem; padding-bottom: .8rem; border-bottom: 1px solid var(--line); }
.bs-aside section:last-child { padding-bottom: 0; border-bottom: 0; }
.bs-aside h2 { margin: 0; color: var(--ink); font-family: Georgia, "Source Han Serif SC", serif; font-size: 1rem; }
.bs-aside dl { display: grid; grid-template-columns: max-content 1fr; gap: .25rem .6rem; margin: 0; color: var(--text); font-size: .82rem; }
.bs-aside dt { color: var(--muted); }
.bs-aside dd { margin: 0; }

.bs-status-banner {
  padding: .55rem .9rem;
  border-radius: 6px;
  font-size: .85rem;
}
.bs-status-banner.is-info { background: #e7eff7; color: #1d4f86; }
.bs-status-banner.is-warning { background: #fff6ee; color: #7d431b; border: 1px solid #e0b38d; }
.bs-status-banner.is-error { background: #fdecec; color: #7c1f1f; border: 1px solid #d99a9a; }

.bs-detail-status {
  margin: 1rem 0;
  min-height: 1.4rem;
  color: var(--muted);
  font-size: .84rem;
}

.bs-footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.2rem clamp(1rem, 3vw, 3rem);
  border-top: 1px solid var(--line);
  color: var(--soft);
  font-size: .78rem;
  flex-wrap: wrap;
}

[hidden] { display: none !important; }

.bs-provenance { margin: 0; color: var(--soft); font-size: .78rem; }
.bs-filter-heading, .bs-results-toolbar { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.bs-filter-heading span { color: var(--muted); font-size: .76rem; }
.bs-filter-toggle { display: none; }
.bs-results { min-width: 0; }
.bs-results-toolbar .bs-detail-status { margin: 0; }
.bs-sort { display: flex; align-items: center; gap: .4rem; color: var(--muted); font-size: .8rem; font-weight: 700; }
.bs-sort select { min-height: 36px; padding: 0 .45rem; border: 1px solid var(--line); border-radius: 5px; background: var(--panel); }
.bs-active-filters { display: flex; flex-wrap: wrap; gap: .4rem; margin: .6rem 0 1rem; min-height: 0; }
.bs-filter-chip { min-height: 30px; padding: 0 .55rem; border: 1px solid #d7b9b2; border-radius: 999px; background: var(--teal-soft); color: var(--ink); font-size: .74rem; }
.bs-load-more-wrap { display: flex; justify-content: center; padding: 1.25rem 0; }
.bs-load-more, .bs-action { min-height: 40px; padding: .55rem .85rem; border: 1px solid var(--teal); border-radius: 6px; background: var(--teal); color: #fff; font-weight: 700; }
.bs-action { display: inline-flex; width: fit-content; margin: .35rem .35rem .35rem 0; }
.bs-load-more:hover, .bs-action:hover { background: #852721; }
.bs-load-more:disabled { cursor: wait; opacity: .7; }
.bs-year-row { grid-template-columns: 1fr auto 1fr; }
.bs-year-row input { min-width: 0; min-height: 36px; padding: 0 .4rem; border: 1px solid var(--line); border-radius: 5px; background: var(--panel); }
.bs-tabs button:focus-visible { outline-offset: -1px; }

@media (max-width: 1000px) {
  .bs-layout { grid-template-columns: 1fr; }
  .bs-shelf-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bs-filter-toggle { display: block; width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--teal); font-weight: 700; }
  .bs-filter-rail { display: none; position: static; max-height: none; }
  .bs-filter-rail.is-open { display: grid; }
  .bs-detail-layout { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .bs-topbar { grid-template-columns: 1fr auto; }
  .bs-section-heading, .bs-shelf-heading { align-items: start; flex-direction: column; }
  .bs-shelf-grid { grid-template-columns: 1fr; }
  .bs-toplinks { grid-column: 1 / -1; justify-content: flex-start; }
  .bs-shell { width: min(100% - 1.25rem, 1360px); padding-top: 1rem; }
  .bs-detail-topbar { flex-direction: column; align-items: start; }
  .bs-card-grid { grid-template-columns: 1fr; }
}

/* ==== 分页 Markdown 阅读器（bookstore-reader.js）==== */
.bs-md-layout {
  display: block;
  min-height: 24rem;
}
.bs-md-toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  align-items: center;
  padding: .5rem .25rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.bs-md-title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: .8rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bs-md-toolbar button {
  min-height: 32px;
  padding: 0 .55rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel);
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
}
.bs-md-toolbar button:hover { background: var(--teal-soft); color: var(--ink); }
.bs-md-toolbar button[hidden] { display: none; }
.bs-md-progress { color: var(--muted); font-size: .78rem; }

.bs-md-grid {
  display: grid;
  grid-template-columns: minmax(0, 15rem) minmax(0, 1fr);
  gap: 1.2rem;
  padding: 1rem .25rem .5rem;
}
.bs-md-toc {
  position: sticky;
  top: 3.1rem;
  align-self: start;
  max-height: calc(100vh - 8rem);
  overflow-y: auto;
  padding-right: .3rem;
}
.bs-md-toc[hidden] { display: none; }
.bs-md-toc-list { margin: 0; padding: 0; list-style: none; }
.bs-md-toc-list li { margin: 0; }
.bs-md-toc-list a {
  display: block;
  padding: .3rem .5rem;
  border-left: 2px solid transparent;
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.45;
}
.bs-md-toc-list a:hover { color: var(--ink); background: var(--teal-soft); }
.bs-md-toc-list a.is-current { color: var(--ink); border-left-color: var(--teal); background: var(--teal-soft); }

.bs-md-page {
  font-size: var(--reader-font-size, 16px);
}
.bs-md-page-head {
  margin: .2rem 0 .6rem;
  padding: .15rem .5rem;
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--soft);
  font-size: .72rem;
}
.bs-md-page + .bs-md-page { margin-top: 1.4rem; }
.bs-chapter-heading {
  display: block;
  margin: 1.8rem 0 .7rem;
  padding-bottom: .3rem;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  font-family: Georgia, "Source Han Serif SC", serif;
  font-size: 1.15rem;
  font-weight: 700;
}
.bs-md-sentinel { height: 1px; }

/* 深色主题下的硬编码浅色修正 */
:root[data-theme="dark"] .bs-reader pre,
:root[data-theme="dark"] .bs-reader th,
:root[data-theme="dark"] .bs-pdf-canvas-wrap { background: #161a1f; }
:root[data-theme="dark"] .bs-reader :not(pre) > code { background: #2a313a; }
:root[data-theme="dark"] .bs-search-highlight { background: #8a5d12; color: #fff; }

@media (max-width: 900px) {
  .bs-md-grid { grid-template-columns: minmax(0, 1fr); }
  .bs-md-toc { position: static; max-height: none; }
}

/* ==== Phase B: 内容关联（bookstore-extra.js / bookstore-reader.js 术语链接）==== */

.bs-related { margin-top: 1.6rem; padding-top: .8rem; border-top: 1px solid var(--line); }
.bs-related h2 { margin: 0 0 .6rem; font-size: .95rem; color: var(--ink); }
.bs-related-grid { display: grid; gap: .5rem; }
.bs-mini-card {
  display: block;
  padding: .55rem .65rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}
.bs-mini-card:hover { border-color: var(--teal); background: var(--teal-soft); }
.bs-mini-card strong { display: block; font-size: .84rem; line-height: 1.45; color: var(--ink); }
.bs-mini-card span { color: var(--muted); font-size: .76rem; }

.bs-series { margin-top: 1.4rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.bs-series-badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 999px;
  background: var(--teal);
  color: #fff;
  font-size: .74rem;
  font-weight: 700;
}
.bs-series-note { margin: .5rem 0 .7rem; color: var(--muted); font-size: .78rem; line-height: 1.5; }
.bs-series-nav { display: flex; flex-wrap: wrap; gap: .35rem; }
.bs-series-link {
  padding: .25rem .55rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: .74rem;
}
.bs-series-link:hover { border-color: var(--teal); color: var(--ink); background: var(--teal-soft); }

.bs-term-link {
  border-bottom: 1px dotted var(--teal);
  color: inherit;
  cursor: pointer;
}
.bs-term-link:hover { color: var(--teal); background: var(--teal-soft); }

/* ==== Phase C: 搜索建议下拉（bookstore-suggest.js）==== */

.bs-suggest-wrap { position: relative; flex: 1 1 100%; }
.bs-suggest {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 30;
  max-height: 18rem;
  overflow-y: auto;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.bs-suggest-item {
  display: block;
  padding: .55rem .75rem;
  border-bottom: 1px solid var(--line);
}
.bs-suggest-item:last-child { border-bottom: 0; }
.bs-suggest-item strong { display: block; font-size: .86rem; line-height: 1.4; color: var(--ink); }
.bs-suggest-item span { color: var(--muted); font-size: .74rem; }
.bs-suggest-item.is-active { background: var(--teal-soft); }
.bs-suggest-item.is-active strong { color: var(--teal); }
:root[data-theme="dark"] .bs-suggest-item.is-active strong { color: var(--teal); }
