/* ============================================================
   All About Math — RTD theme polish + navigation UX
   ============================================================ */

/* Content width: room for article + right TOC on wide screens */
.wy-nav-content {
  max-width: 1180px;
}

/* Readable body text */
.rst-content {
  font-size: 16px;
  line-height: 1.65;
}

/* Headings */
.rst-content h1,
.rst-content h2,
.rst-content h3 {
  font-weight: 600;
  letter-spacing: -0.01em;
  scroll-margin-top: 1rem;
}

/* Tables */
.rst-content table.docutils {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
}

.rst-content table.docutils th {
  background: #f0f4f8;
  font-weight: 600;
}

.rst-content table.docutils th,
.rst-content table.docutils td {
  padding: 0.5em 0.75em;
  border: 1px solid #d0d7de;
  vertical-align: top;
}

/* Math blocks */
.rst-content .arithmatex {
  overflow-x: auto;
}

.rst-content mjx-container[display="true"] {
  margin: 1em 0 !important;
  overflow-x: auto;
  overflow-y: hidden;
}

/* Admonitions / details (pymdownx) */
.rst-content .admonition,
.rst-content details {
  margin: 1em 0;
  padding: 0.75em 1em;
  border-left: 4px solid #2980b9;
  background: #f7f9fc;
  border-radius: 0 4px 4px 0;
}

.rst-content .admonition-title,
.rst-content summary {
  font-weight: 600;
  margin-bottom: 0.35em;
}

.rst-content details[open] summary {
  margin-bottom: 0.5em;
}

/* Code */
.rst-content code {
  font-size: 0.9em;
  padding: 0.1em 0.35em;
  border-radius: 3px;
  background: #f4f4f4;
}

.rst-content pre {
  border-radius: 4px;
}

/* Footer prev/next */
.rst-footer-buttons {
  margin-top: 2em;
}

/* ============================================================
   Two-column layout: article + right "On this page" TOC
   ============================================================ */

.aam-layout {
  display: block;
}

.aam-layout--with-toc {
  display: flex;
  align-items: flex-start;
  gap: 1.75rem;
}

.aam-main {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 48rem;
}

.aam-toc {
  flex: 0 0 14rem;
  width: 14rem;
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.5rem 0 0.5rem 1rem;
  border-left: 1px solid #d0d7de;
  font-size: 0.82rem;
  line-height: 1.4;
  align-self: flex-start;
}

.aam-toc__title {
  margin: 0 0 0.6rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #5c6b7a;
}

.aam-toc__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.aam-toc__list--nested {
  margin: 0.15rem 0 0.35rem;
  padding-left: 0.65rem;
  border-left: 1px solid #e4e9ef;
}

.aam-toc__item {
  margin: 0;
}

.aam-toc__link {
  display: block;
  padding: 0.22rem 0.35rem;
  color: #404040;
  text-decoration: none;
  border-radius: 3px;
  border-left: 2px solid transparent;
  margin-left: -2px;
}

.aam-toc__link:hover {
  color: #2980b9;
  background: #f0f6fb;
  text-decoration: none;
}

.aam-toc__link--active {
  color: #2980b9;
  font-weight: 600;
  border-left-color: #2980b9;
  background: #eef5fb;
}

.aam-toc__item--l2 .aam-toc__link {
  font-size: 0.95em;
  color: #555;
}

.aam-toc__item--l3 .aam-toc__link {
  font-size: 0.9em;
  color: #666;
}

/* ============================================================
   Left nav: denser, neater list items + collapsible domains
   ============================================================ */

/* Sidebar shell */
.wy-nav-side {
  font-size: 13px;
}

.wy-side-scroll {
  scrollbar-width: thin;
}

.wy-side-nav-search {
  padding: 0.65rem 0.75rem 0.55rem !important;
}

.wy-side-nav-search > a {
  font-size: 1.05rem !important;
  margin-bottom: 0.35rem !important;
  line-height: 1.25 !important;
}

.wy-side-nav-search input[type="text"] {
  border-radius: 4px !important;
  font-size: 12.5px !important;
  height: 2rem !important;
  line-height: 2rem !important;
  padding: 0 0.55rem !important;
  width: 100% !important;
  box-sizing: border-box;
}

/* Section captions (domain headers) */
.wy-menu-vertical p.caption {
  margin: 0.45rem 0 0.1rem !important;
  padding: 0.4rem 1.1rem 0.35rem 0.85rem !important;
  font-size: 11px !important;
  font-weight: 700 !important;
  letter-spacing: 0.05em !important;
  text-transform: uppercase !important;
  color: #b3b3b3 !important;
  line-height: 1.25 !important;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.wy-menu-vertical p.caption:first-child {
  border-top: none;
  margin-top: 0.15rem !important;
}

.wy-menu-vertical p.caption .caption-text {
  font-size: inherit;
  color: inherit;
}

.wy-menu-vertical p.caption.aam-nav-caption {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 1.6rem !important;
  transition: color 0.12s ease, background 0.12s ease;
}

.wy-menu-vertical p.caption.aam-nav-caption::after {
  content: "▸";
  position: absolute;
  right: 0.7rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.7rem;
  opacity: 0.7;
  transition: transform 0.15s ease;
}

.wy-menu-vertical p.caption.aam-nav-caption.aam-nav-open::after {
  transform: translateY(-50%) rotate(90deg);
}

.wy-menu-vertical p.caption.aam-nav-caption:hover {
  color: #ffffff !important;
  background: rgba(255, 255, 255, 0.04);
}

.wy-menu-vertical p.caption.aam-nav-caption.aam-nav-open {
  color: #e8e8e8 !important;
}

/* Nested lists under captions */
.wy-menu-vertical > ul {
  margin-bottom: 0.15rem !important;
}

.wy-menu-vertical ul {
  margin: 0 !important;
  padding: 0 !important;
}

.wy-menu-vertical li {
  margin: 0 !important;
  font-size: 12.5px !important;
  line-height: 1.25 !important;
}

/* Compact page links (all levels) */
.wy-menu-vertical a {
  font-size: 12.5px !important;
  line-height: 1.3 !important;
  padding: 0.28rem 0.75rem 0.28rem 1rem !important;
  color: #d5d5d5 !important;
  border-top: none !important;
  transition: background 0.1s ease, color 0.1s ease;
}

.wy-menu-vertical li.toctree-l1 > a {
  padding-top: 0.28rem !important;
  padding-bottom: 0.28rem !important;
  padding-left: 1rem !important;
}

.wy-menu-vertical li.toctree-l2 > a {
  padding: 0.24rem 0.7rem 0.24rem 1.35rem !important;
  font-size: 12px !important;
  color: #c4c4c4 !important;
}

.wy-menu-vertical li.toctree-l3 > a {
  padding: 0.22rem 0.65rem 0.22rem 1.7rem !important;
  font-size: 11.5px !important;
  color: #b8b8b8 !important;
}

.wy-menu-vertical li.toctree-l4 > a {
  padding: 0.2rem 0.6rem 0.2rem 2rem !important;
  font-size: 11.5px !important;
}

.wy-menu-vertical a:hover {
  background: #4e4a4a !important;
  color: #ffffff !important;
}

/* Current page / active branch */
.wy-menu-vertical li.current > a,
.wy-menu-vertical li.current > a:hover,
.wy-menu-vertical a.current {
  background: #2980b9 !important;
  color: #ffffff !important;
  font-weight: 600 !important;
  border-right: none !important;
}

.wy-menu-vertical li.current {
  background: transparent !important;
}

.wy-menu-vertical li.toctree-l1.current > ul,
.wy-menu-vertical li.toctree-l2.current > ul {
  background: rgba(0, 0, 0, 0.12);
}

/* Nested current children slightly quieter than active leaf */
.wy-menu-vertical li.current ul a {
  border-right: none !important;
}

.wy-menu-vertical ul.aam-nav-collapsed {
  display: none !important;
}

.wy-menu-vertical ul.aam-nav-open {
  display: block !important;
}

/* ============================================================
   Back to top + mobile Contents button
   ============================================================ */

.aam-back-top {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 100;
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  border-radius: 50%;
  background: #2980b9;
  color: #fff;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  transform: translateY(0.5rem);
}

.aam-back-top--visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.aam-back-top:hover {
  background: #1f6da0;
}

.aam-toc-toggle {
  display: none;
  position: fixed;
  right: 1.25rem;
  bottom: 4.25rem;
  z-index: 100;
  padding: 0.5rem 0.9rem;
  border: none;
  border-radius: 999px;
  background: #343131;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.aam-toc-toggle--open {
  background: #2980b9;
}

/* ============================================================
   Responsive: stack / drawer TOC on smaller screens
   ============================================================ */

@media (max-width: 1100px) {
  .aam-layout--with-toc {
    display: block;
  }

  .aam-main {
    max-width: none;
  }

  .aam-toc {
    display: none;
    position: fixed;
    right: 1rem;
    bottom: 5.5rem;
    top: auto;
    width: min(18rem, calc(100vw - 2rem));
    max-height: min(60vh, 28rem);
    background: #fff;
    border: 1px solid #d0d7de;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    padding: 0.75rem 1rem;
    z-index: 99;
  }

  .aam-toc.aam-toc--open {
    display: block;
  }

  .aam-toc-toggle {
    display: inline-flex;
    align-items: center;
  }
}

@media (max-width: 768px) {
  .wy-nav-content {
    max-width: none;
  }
}
