/* ================================================
   WEYWAY — TOC STYLES
   Contains styles for both TOC implementations:
   · Sidebar TOC (.post-toc / .sidebar-toc)
   · Bottom bar TOC (.mbar / .mdrawer)
   ================================================ */


/* ── SHARED ─────────────────────────────────────
   Strip global link pill from all TOC links.
   ────────────────────────────────────────────── */

.sidebar-toc a,
.sidebar-toc a:hover,
.mdscroll a,
.mdscroll a:hover {
  background: transparent;
  padding: 0;
  margin: 0;
  border-radius: 0;
}


/* ════════════════════════════════════════════════
   SIDEBAR TOC
   Desktop: sticky panel beside article content.
   Mobile (≤1200px): fixed slide-in drawer.
   ════════════════════════════════════════════════ */

.main-container {
  display: flex;
  gap: 0.1rem;
  align-items: flex-start;
}

.main-container article {
  flex: 1;
  min-width: 0;
}

@media (min-width: 1201px) {
  .post-toc {
    opacity: 0;
    transition: opacity 0.4s ease;
  }
}

.post-toc {
  max-width: 260px;
  min-width: 250px;
  position: sticky;
  top: 10%;
  align-self: flex-start;
  max-height: calc(90vh - 5rem);
  overflow-y: auto;
  overflow-x: hidden;
  margin-left: 1rem;
  margin-right: 1vw;
  padding: 0rem 1rem 1rem 0.75rem;
  scrollbar-width: none;
  -ms-overflow-style: none;
  scroll-padding-top: 15vh;
  background-color: var(--color-raised);
  border: none;
  border-radius: 8px;
  box-shadow: -4px 0 20px rgba(0,0,0,0.25);
}

.post-toc::-webkit-scrollbar {
  display: none;
}

/* "Contents" heading */
.post-toc > p,
.post-toc > h3,
.post-toc > h2,
.post-toc > h1,
.toc-title {
  font-size: 0.65rem !important;
  font-weight: 500 !important;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--logo-color) !important;
  margin-top: 0 !important;
  margin-bottom: 0.6rem;
  padding-top: 0 !important;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border-acc);
}

/* List resets */
.sidebar-toc,
.sidebar-toc ul,
.sidebar-toc li {
  margin: 0;
  padding: 0;
  list-style: none;
}

.sidebar-toc {
  margin-top: 0.5rem;
}

/* ── SIDEBAR TOC ITEMS ──────────────────────────
   Hover + active state on <li>, NOT <a>.
   Prevents text jumping on interaction.
   ────────────────────────────────────────────── */

.sidebar-toc li {
  margin-bottom: 0;
  border-left: 2px solid transparent;
  transition: border-color 0.15s;
}

.sidebar-toc li.active,
.sidebar-toc li:has(a.active) {
  border-left-color: var(--logo-color);
}

.sidebar-toc li a {
  display: block;
  text-decoration: none;
  border: none;
  background: none;
  line-height: 1.45;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.15s;
  font-weight: 400;
  border-radius: 3px;
}

.sidebar-toc li.h2 a { font-size: 0.86rem; color: var(--color-muted); padding: 0.27rem 0.5rem 0.27rem 0.5rem; }
.sidebar-toc li.h3 a { font-size: 0.81rem; color: var(--color-muted); padding: 0.27rem 0.5rem 0.27rem 1.1rem; }
.sidebar-toc li.h4 a { font-size: 0.77rem; color: var(--color-faint); padding: 0.27rem 0.5rem 0.27rem 1.8rem; }

.sidebar-toc li.h2:hover a,
.sidebar-toc li.h3:hover a { color: var(--text-color); }
.sidebar-toc li.h4:hover a  { color: var(--color-muted); }

.sidebar-toc li.active a,
.sidebar-toc li a.active {
  color: var(--logo-color) !important;
  background: var(--color-accent-dim);
}

.sidebar-toc li.h2 { padding-left: 0; }
.sidebar-toc li.h3 { padding-left: 0; }
.sidebar-toc li.h4 { padding-left: 0; }


/* ── SIDEBAR TOC MOBILE (≤1200px) ───────────────*/

#toggle-toc {
  display: none;
}

@media (max-width: 1200px) {
  .main-container {
    display: block;
  }

  .post-toc {
    display: block;
    position: fixed;
    min-width: unset;
    top: 15%;
    right: 0;
    width: 80vw;
    max-width: 300px;
    height: calc(100vh - 25%);
    background-color: var(--color-raised);
    border-left: 1px solid var(--color-border-acc);
    border-radius: 8px 0 0 8px;
    box-shadow: -4px 0 20px rgba(0,0,0,0.25);
    padding: 1rem 1rem 1rem 0.75rem;
    margin: 0;
    z-index: 1000;
    transform: translateX(100%);
    transition: transform 0.3s ease-in-out;
    overflow-y: auto;
  }

  .post-toc.active {
    transform: translateX(0);
  }

  #toggle-toc {
    display: block;
    position: fixed;
    top: 100px;
    right: 0;
    background-color: var(--headings-color);
    color: var(--page-bg);
    border: none;
    border-radius: 8px 0 0 8px;
    padding: 0.8rem 0.5rem;
    font-size: 0.7rem;
    cursor: pointer;
    box-shadow: -2px 0 8px rgba(0,0,0,0.2);
    z-index: 1001;
    letter-spacing: 0.06em;
    font-weight: 500;
    transition: background 0.18s;
  }

  #toggle-toc:hover {
    background-color: var(--logo-color);
  }
}


/* ════════════════════════════════════════════════
   BOTTOM BAR TOC
   Fixed bar at the bottom of every post page.
   Left: TOC icon + current section label (opens drawer).
   Right: back-to-top button slot (occupied by theme button).
   ════════════════════════════════════════════════ */

.mbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 150;
  height: 48px;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border-acc);
  box-shadow: 0 -2px 12px rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: 0.75rem;
}

/* Handle pill — signals "this lifts up" */
.mbar-handle-wrap {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.mbar-handle {
  width: 36px;
  height: 4px;
  background: var(--color-border-acc);
  border-radius: 2px;
  margin-top: 5px;
}

/* Left side — icon + current section label */
.mbar-trigger {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.mbar-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  flex-shrink: 0;
  background: var(--color-pink-glow);
  border: 1px solid var(--color-border-acc);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  transition: background 0.15s;
}

.mbar-trigger:hover .mbar-icon {
  background: var(--color-accent-dim);
}

/* Animated icon frames — slide between hamburger and arrow */
.mbar-icon-frame {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.4s ease;
}

.mbar-icon-frame.show      { transform: translateY(0);     opacity: 1; }
.mbar-icon-frame.hide-up   { transform: translateY(-100%); opacity: 0; }
.mbar-icon-frame.hide-down { transform: translateY(100%);  opacity: 0; }

.mbar-section {
  font-size: 0.76rem;
  color: var(--logo-color);
  font-style: italic;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Right side — slot that the theme back-to-top button visually occupies */
.mbar-top-slot {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
}

/* ── PAGE BODY PADDING ──────────────────────────
   Prevents the bar from overlapping page content.
   ────────────────────────────────────────────── */

body:has(.mbar) {
  padding-bottom: 48px;
}


/* ── BACK TO TOP BUTTON ─────────────────────────
   Theme's #backToTop restyled to match the bar
   on post pages, and sits as a standalone floating
   button on all other pages.
   Needs !important on position, bottom, right,
   z-index, padding to beat the theme's style.css
   and its media query.
   ────────────────────────────────────────────── */

#backToTop.footer__bttop {
  position: fixed !important;
  bottom: 9px !important; /* centres in the 48px bar: (48 - 30) / 2 */
  right: 1rem !important;
  width: 30px !important;
  height: 30px !important;
  border-radius: 50% !important;
  border: 1px solid var(--color-border-acc) !important;
  background: var(--color-raised) !important;
  color: var(--color-muted);
  display: flex !important;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 151 !important;
  box-shadow: none !important;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  padding: 0 !important;
}

#backToTop.footer__bttop:hover {
  background: var(--color-pink-glow) !important;
  color: var(--logo-color);
  border-color: var(--color-border-acc) !important;
  opacity: 1;
}

/* On non-post pages — float above the page edge */
body:not(:has(.mbar)) #backToTop.footer__bttop {
  bottom: 1.25rem !important;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2) !important;
}


/* ════════════════════════════════════════════════
   TOC DRAWER
   Slides up from the bottom bar on trigger click.
   ════════════════════════════════════════════════ */

/* Overlay */
.moverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 149;
}

.moverlay.open {
  display: block;
}

/* Drawer panel */
.mdrawer {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 151;
  background: var(--color-surface);
  border-top: 1.5px solid var(--color-border-acc);
  border-radius: 16px 16px 0 0;
  padding-bottom: env(safe-area-inset-bottom, 1rem);
  box-shadow: 0 -8px 40px rgba(0,0,0,0.2);
  max-height: 70vh;
  overflow: hidden;
  flex-direction: column;
}

.mdrawer.open {
  display: flex;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Drawer header */
.mdhandle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.mdtitle {
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--logo-color);
}

.mdx {
  font-size: 1rem;
  color: var(--color-muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.mdx:hover {
  color: var(--logo-color);
  background: var(--color-pink-glow);
}

/* Drawer scroll area */
.mdscroll {
  overflow-y: auto;
  padding: 0.75rem 1rem 2rem;
  -webkit-overflow-scrolling: touch;
}

/* Drawer TOC items — slightly larger than sidebar */
.mdscroll .sidebar-toc li.h2 a { font-size: 0.85rem; }
.mdscroll .sidebar-toc li.h3 a { font-size: 0.78rem; }
.mdscroll .sidebar-toc li.h4 a { font-size: 0.72rem; }