/* ==============================================================
 * code-collapse.css
 *
 * Collapse/expand control for long code blocks.
 * Written against jekyll-theme-chirpy 7.3.1.
 *
 * Chirpy renders every highlighted block as:
 *
 *   <div class="language-bash highlighter-rouge">
 *     <div class="code-header">
 *       <span data-label-text="Bash">...</span>   <- language label
 *       <span class="code-collapse-slot">...</span>  <- added by JS
 *       <button aria-label="copy">...</button>    <- theme's copy button
 *     </div>
 *     <div class="highlight"><code>...</code></div>
 *   </div>
 *
 * The markup comes from _includes/refactor-content.html in the theme;
 * the toggle is injected by assets/js/code-collapse.js.
 * ============================================================== */

/* ==============================================================
 * The toggle, sitting in the code header next to the copy button
 * ============================================================== */

.highlighter-rouge.cc-collapsible {
  position: relative;
}

/* The slot is positioned out of flow on purpose.
 *
 * .code-header is `display: flex; justify-content: space-between` with
 * three children (the ::before dots, the language label, the copy
 * button), and space-between is what centres the label. Adding a fourth
 * in-flow child redistributes that space and drags the label off-centre,
 * so a collapsed block would not match an uncollapsed one on the same
 * page. Taking the slot out of flow leaves the header's own layout
 * exactly as the theme wrote it.
 *
 * 2.25rem is $code-header-height, i.e. the width the theme gives the
 * copy button; parking the slot at that offset lands it immediately to
 * the left of the copy button. */
.highlighter-rouge .code-header {
  position: relative;
}

.highlighter-rouge .code-header .code-collapse-slot {
  position: absolute;
  top: 0;
  right: 2.25rem;
  height: 2.25rem;
  display: flex;
  align-items: center;
  line-height: 1;
}

/* The theme's label spans draw their text with a ::after; the slot
   must not inherit that. */
.highlighter-rouge .code-header .code-collapse-slot::after {
  content: none;
}

.highlighter-rouge .code-header .code-collapse-slot i {
  transition: transform 0.2s ease;
}

/* The button itself inherits the theme's `.code-header button` sizing,
   radius, colours and hover state. This only nudges the icon. */
.highlighter-rouge .code-header .code-collapse-btn i {
  font-size: 1rem;
}

/* Hide the toggle until the script has had a chance to wire it up, so
   a slow load never shows a button that does nothing. */
.highlighter-rouge:not(.cc-collapsible) .code-collapse-btn {
  visibility: hidden;
}

/* ==============================================================
 * The block
 * ============================================================== */

.highlighter-rouge.cc-collapsible .highlight {
  /* Down is never scrolled: collapsed is a short clip, expanded is the
     full height. Left/right stays scrollable when expanded so wide
     lines behave exactly as they did before. */
  overflow-y: hidden;
  overflow-x: hidden;
  transition: max-height 0.35s ease;
}

.highlighter-rouge.cc-collapsible:not(.cc-collapsed) .highlight {
  overflow-x: auto;
}

/* ==============================================================
 * Collapsed state: a fade at the bottom edge
 * ============================================================== */

.highlighter-rouge.cc-collapsed::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4rem;
  pointer-events: none;
  /* $radius-lg in the theme, applied so the fade follows the block's
     own bottom corners instead of squaring them off. */
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
  background: linear-gradient(to bottom, transparent, var(--highlight-bg-color));
}

/* Respect a reader who has asked for less motion. */
@media (prefers-reduced-motion: reduce) {
  .highlighter-rouge.cc-collapsible .highlight,
  .highlighter-rouge .code-header .code-collapse-slot i {
    transition: none;
  }
}

/* Printing should never hand someone a clipped listing. */
@media print {
  .highlighter-rouge.cc-collapsed .highlight {
    max-height: none !important;
    overflow: visible !important;
  }

  .highlighter-rouge.cc-collapsed::after {
    content: none;
  }
}
