/* ── Table of Contents ── */

.expanded {
  list-style: disclosure-open;
}
.expanded > ul {
  visibility: visible;
}
.collapsed {
  list-style: disclosure-closed;
}
.collapsed + ul {
  display: none;
}

.expanded:hover,
.collapsed:hover {
  cursor: pointer;
}

/* ── Layout wrapper: ToC + content side by side ── */
.toc-layout {
  display: flex;
  flex-direction: column;
  max-width: 750px;
  margin: 0 auto;
  padding: 30px 15px 0;
}

@media (max-width: 768px) {
  .toc-layout {
    max-width: 100%;
    padding: 30px 12px 0;
  }
}

.toc-layout-content {
  width: 100%;
  min-width: 0;
}

/* ── Default (small/medium): ToC is inline, collapsible ── */
.StickyToCContainer {
  max-height: 40vh;
  overflow-y: auto;
  margin-bottom: 20px;
  background: var(--dark-transparent);
  border: 1px solid color-mix(in srgb, var(--textColor) 8%, transparent);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 0.8em;
}

#ToC > h2 {
  font-family: 'Orbital', sans-serif;
  font-size: 10px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--textColor) 50%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--textColor) 10%, transparent);
  padding-bottom: 8px;
  margin-top: 0;
  margin-bottom: 12px;
}

#ToC ul {
  padding: 0;
  padding-left: 10px;
  margin: 0;
}

#ToC li {
  padding: 2px 0;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

#ToC a {
  color: color-mix(in srgb, var(--textColor) 65%, transparent);
  text-decoration: none;
  transition: color 0.15s ease;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

#ToC a:hover {
  color: var(--accentColor);
}

/* ── Wide screens: ToC becomes a sticky sidebar ── */
@media only screen and (min-width: 1200px) {
  .toc-layout {
    flex-direction: row;
    max-width: 1100px;
    gap: 0;
  }

  /* Container is the scroll wrapper. No overflow on #ToC itself. */
  .StickyToCContainer {
    position: -webkit-sticky;
    position: sticky;
    top: 50px;
    width: 200px;
    min-width: 200px;
    flex-shrink: 0;
    height: calc(100vh - 80px);
    max-height: none;
    overflow-y: scroll;
    overflow-x: hidden;
    background: none;
    border: none;
    border-radius: 0;
    /* Right padding = space between text and scrollbar + gap to content */
    padding: 0;
    margin-right: 20px;
    margin-bottom: 0;
    font-size: 0.8em;
    order: -1;
  }

  /* #ToC is just content, no scrolling */
  #ToC {
    height: auto;
    overflow: visible;
    padding-right: 8px;
  }

  .toc-layout-content {
    flex: 1;
    min-width: 0;
    max-width: 750px;
    border-left: 1px solid color-mix(in srgb, var(--textColor) 8%, transparent);
    padding-left: 30px;
  }

  #ToC > h2 {
    font-size: 9px;
    letter-spacing: 3px;
  }
}

@media (prefers-color-scheme: light) {
  .StickyToCContainer {
    background: rgba(255, 255, 255, 0.4);
  }

  @media only screen and (min-width: 1200px) {
    .StickyToCContainer {
      background: none;
    }
  }
}
