/* Keep the three-column book layout readable on wide displays. */
.bd-page-width {
  max-width: 100rem;
}

.bd-main .bd-content .bd-article-container {
  max-width: 68rem;
}

@media (min-width: 992px) {
  .bd-sidebar-primary {
    flex: 0 0 19rem;
    width: 19rem;
    max-width: 19rem;
  }
}

/* Grouped chapter navigation in the primary sidebar. */
.theory-sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.theory-sidebar-nav__home,
.theory-sidebar-nav__group summary,
.theory-sidebar-nav__group a {
  border-radius: 0.25rem;
  color: var(--pst-color-text-muted);
  text-decoration: none;
}

.theory-sidebar-nav__home {
  display: block;
  padding: 0.45rem 0.55rem;
  font-weight: 600;
}

.theory-sidebar-nav__title {
  margin: 1rem 0 0.3rem;
  color: var(--pst-color-text-base);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.theory-sidebar-nav__group {
  margin: 0;
}

.theory-sidebar-nav__group summary {
  position: relative;
  padding: 0.45rem 1.6rem 0.45rem 0.55rem;
  cursor: pointer;
  font-weight: 600;
  line-height: 1.3;
  list-style: none;
}

.theory-sidebar-nav__group summary::-webkit-details-marker {
  display: none;
}

.theory-sidebar-nav__group summary::after {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  content: "\203A";
  font-size: 1.1rem;
  line-height: 1;
  transform: rotate(90deg);
  transition: transform 120ms ease;
}

.theory-sidebar-nav__group[open] summary::after {
  transform: rotate(-90deg);
}

.theory-sidebar-nav__group ul {
  margin: 0.1rem 0 0.4rem;
  padding: 0 0 0 0.65rem;
  border-left: 1px solid var(--pst-color-border);
  list-style: none;
}

.theory-sidebar-nav__group li {
  margin: 0;
}

.theory-sidebar-nav__group a {
  display: block;
  padding: 0.35rem 0.5rem;
  line-height: 1.35;
}

.theory-sidebar-nav__home:hover,
.theory-sidebar-nav__group summary:hover,
.theory-sidebar-nav__group a:hover {
  color: var(--pst-color-link-hover);
  background: var(--pst-color-surface);
}

.theory-sidebar-nav__home.current,
.theory-sidebar-nav__group summary.current,
.theory-sidebar-nav__group a.current {
  color: var(--pst-color-primary);
  background: var(--pst-color-target);
}

.theory-sidebar-nav :focus-visible {
  outline: 2px solid var(--pst-color-accent);
  outline-offset: 1px;
}

/* Header dropdowns contain only the five major parts and stay in the viewport. */
.bd-header .theory-navbar .dropdown-menu {
  min-width: min(22rem, calc(100vw - 2rem));
  max-width: min(32rem, calc(100vw - 2rem));
  max-height: calc(100vh - var(--pst-header-height) - 1rem);
  overflow-x: hidden;
  overflow-y: auto;
}

.bd-header .theory-navbar .dropdown-item {
  height: auto;
  white-space: normal;
  line-height: 1.3;
}

.bd-header .theory-navbar .nav-item.current > .dropdown-toggle {
  color: var(--pst-color-primary);
  box-shadow: inset 0 -3px 0 var(--pst-color-primary);
}

/* The complete chapter list below replaces the header links in the mobile drawer. */
.sidebar-header-items .theory-navbar {
  display: none;
}

/* The header stays compact on intermediate widths; the left navigation remains visible. */
@media (min-width: 992px) and (max-width: 1279px) {
  .bd-header .theory-navbar {
    display: none;
  }
}

/* A concise, responsive guide map on the landing page. */
.theory-part-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(20rem, 100%), 1fr));
  gap: 1rem;
  margin-top: 2rem;
}

.theory-part-card {
  margin: 0;
  padding: 1rem 1.1rem;
  border: 1px solid var(--pst-color-border);
  border-radius: 0.4rem;
  background: var(--pst-color-on-background);
}

.theory-part-card > p:first-child {
  margin-top: 0;
  color: var(--pst-color-text-base);
  font-size: 1.1rem;
}

.theory-part-card > p:last-child {
  margin-bottom: 0;
}

/* Keep display equations at their natural typesetting size. Genuinely long
   equations should be split deliberately in the source rather than globally
   scrolled, wrapped, or scaled by the theme. */
.bd-content div.math,
.bd-content div.math mjx-container {
  overflow: visible;
}

.bd-content div.math mjx-container {
  min-width: 0;
}

/* Wide tables scroll locally instead of widening the whole page. */
.bd-content .table-wrapper {
  max-width: 100%;
  overflow-x: auto;
}
