/* Extend Higan's existing tablet disclosure into the narrow desktop range.
   The theme's JS still owns rendering, dismissal and article anchors. */
@media (1024px <= width < 1280px) {
  #header-post #toc-desktop-panel {
    display: none !important;
  }

  #header-post #toc-icon-tablet {
    place-items: center;
    inline-size: 2.75rem;
    block-size: 2.75rem;
    margin: 0;
    border: 1px solid var(--color-primary);
    border-radius: .5rem;
    background: var(--color-base-100);
    color: var(--color-primary);
  }
}

/* Override Higan's important display utility in its own cascade layer. */
@layer utilities {
  @media (1024px <= width < 1280px) {
    body:has(#toc-tablet .toc-link) #header-post #toc-icon-tablet {
      display: grid !important;
    }
  }
}

/* Higan hides this panel with !important in its base layer at 1024px.
   Override there, and only after the native action reports expanded. */
@layer base {
  @media (1024px <= width < 1280px) {
    body:has(#header-post #toc-icon-tablet[aria-expanded="true"]) #toc-overlay-tablet:not([aria-hidden="true"]) {
      display: block !important;
    }
  }
}

/* This candidate has a 44rem centered reading column. Keep at least 3rem
   between the article and the TOC box, including when labels are long. */
@media (width >= 1280px) {
  #header-post #toc-desktop-panel {
    inline-size: fit-content;
    max-inline-size: min(20em, calc((100vw - 44rem) / 2 - 3rem));
  }

  #header-post #toc-desktop-panel .toc-text {
    overflow-wrap: anywhere;
  }
}
