:root {
  --ink: #132028;
  --ink-soft: #3d525c;
  --paper: #f3f6f4;
  --panel: rgba(255, 255, 255, 0.78);
  --line: rgba(19, 32, 40, 0.12);
  --accent: #0f6e56;
  --accent-deep: #0a4d3c;
  --glow: rgba(15, 110, 86, 0.18);
  --sidebar-w: 280px;
  --header-h: 4.5rem;
  --font-display: "Instrument Serif", Georgia, serif;
  --font-body: "DM Sans", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(15, 110, 86, 0.14), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(40, 80, 110, 0.12), transparent 50%),
    linear-gradient(165deg, #e8eee9 0%, var(--paper) 40%, #e4ebe8 100%);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.bb-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.bb-header {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.85rem 1.5rem;
  backdrop-filter: blur(14px);
  background: rgba(243, 246, 244, 0.82);
  border-bottom: 1px solid var(--line);
  animation: bb-fade-down 0.55s ease-out both;
}

.bb-brand {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  gap: 0.35rem;
  line-height: 1.1;
}

.bb-brand-logo {
  display: block;
  height: 2.55rem;
  width: auto;
}

.bb-brand-sub {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
}

.bb-search {
  flex: 1;
  display: flex;
  gap: 0.5rem;
  max-width: 42rem;
}

.bb-search input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  padding: 0.7rem 0.95rem;
  font: inherit;
  font-size: 0.95rem;
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.bb-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--glow);
}

.bb-search button[type="submit"] {
  border: 0;
  border-radius: 0.55rem;
  padding: 0.7rem 1.1rem;
  font: inherit;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}

.bb-search button[type="submit"]:hover {
  background: var(--accent-deep);
}

.bb-search button[type="submit"]:active {
  transform: translateY(1px);
}

.bb-refresh {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.65rem;
  height: 2.65rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  background: #fff;
  color: var(--ink-soft);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s, transform 0.15s;
}

.bb-refresh:hover {
  color: var(--accent-deep);
  border-color: var(--accent);
  background: rgba(15, 110, 86, 0.06);
}

.bb-refresh:active {
  transform: translateY(1px);
}

.bb-refresh.is-busy {
  pointer-events: none;
  color: var(--accent);
}

.bb-refresh.is-busy .bb-refresh-icon {
  animation: bb-spin 0.7s linear infinite;
}

@keyframes bb-spin {
  to {
    transform: rotate(360deg);
  }
}

.bb-body {
  flex: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  align-items: start;
  min-height: calc(100vh - var(--header-h));
}

.bb-sidebar {
  position: sticky;
  top: var(--header-h);
  align-self: start;
  width: 100%;
  height: calc(100vh - var(--header-h));
  max-height: calc(100vh - var(--header-h));
  border-right: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(10px);
  overflow: auto;
  animation: bb-fade-in 0.6s ease-out 0.1s both;
}

.bb-sidebar-head {
  position: sticky;
  top: 0;
  padding: 0.85rem 1rem;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  background: rgba(243, 246, 244, 0.92);
  border-bottom: 1px solid var(--line);
}

.bb-topic-tree {
  padding: 0.4rem 0 1.5rem;
}

.bb-topic {
  border-bottom: 1px solid rgba(19, 32, 40, 0.06);
}

.bb-topic-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.7rem 1rem;
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: 600;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
}

.bb-topic-toggle:hover {
  background: rgba(15, 110, 86, 0.06);
}

.bb-topic-toggle .chev {
  width: 0.55rem;
  height: 0.55rem;
  border-right: 2px solid var(--ink-soft);
  border-bottom: 2px solid var(--ink-soft);
  transform: rotate(-45deg);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.bb-topic.is-open .chev {
  transform: rotate(45deg);
}

.bb-topic-docs {
  display: none;
  padding: 0 0.4rem 0.55rem 0.6rem;
}

.bb-topic.is-open .bb-topic-docs {
  display: block;
  animation: bb-slide 0.2s ease-out;
}

.bb-doc-link {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0.45rem 0.7rem;
  margin: 0.1rem 0;
  border-radius: 0.4rem;
  font: inherit;
  font-size: 0.88rem;
  color: var(--ink-soft);
  cursor: pointer;
}

.bb-doc-link:hover,
.bb-doc-link.is-active {
  color: var(--accent-deep);
  background: rgba(15, 110, 86, 0.1);
}

.bb-main {
  position: relative;
  min-width: 0;
  padding: 1.25rem 1.5rem 2rem;
  animation: bb-fade-in 0.65s ease-out 0.15s both;
}

.bb-empty {
  max-width: 28rem;
  margin: 12vh auto 0;
  text-align: center;
}

.bb-empty h1 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(2rem, 4vw, 2.75rem);
  margin: 0 0 0.6rem;
}

.bb-empty p,
.bb-muted {
  color: var(--ink-soft);
  margin: 0;
  line-height: 1.5;
}

.bb-viewer {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.bb-viewer-meta h2 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.85rem;
  margin: 0.15rem 0 0.35rem;
}

.bb-viewer-topic {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.bb-viewer-tags {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.88rem;
}

#pdf-frame {
  display: block;
  width: 100%;
  /* Roughly one letter page at current width, and never shorter than most of the viewport */
  aspect-ratio: 8.5 / 11;
  min-height: max(85vh, 36rem);
  height: auto;
  border: 1px solid var(--line);
  border-radius: 0.65rem;
  background: #fff;
  box-shadow: 0 18px 40px rgba(19, 32, 40, 0.06);
}

.bb-results-heading {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.6rem;
  margin: 0 0 0.85rem;
}

.bb-results-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.bb-result-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  padding: 0.85rem 1rem;
  background: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  font: inherit;
  transition: border-color 0.2s, transform 0.15s;
}

.bb-result-item:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.bb-result-item strong {
  display: block;
  margin-bottom: 0.2rem;
}

.bb-result-item .meta {
  font-size: 0.78rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.bb-result-item .snippet {
  margin: 0.35rem 0 0;
  color: var(--ink-soft);
  font-size: 0.88rem;
}

.is-hidden {
  display: none !important;
}

@keyframes bb-fade-down {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes bb-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes bb-slide {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 860px) {
  .bb-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .bb-body {
    grid-template-columns: 1fr;
  }

  .bb-sidebar {
    position: relative;
    top: auto;
    height: auto;
    max-height: 40vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  #pdf-frame {
    /* Taller than the viewport so page scroll reveals more PDF before the iframe scrolls */
    min-height: max(110vh, 32rem);
  }
}
