/* ═══════════════════════════════════════════════
   Collapsible section cards (see javascripts/sections.js)
   ═══════════════════════════════════════════════ */

[data-md-color-scheme="slate"] {
  --sf-sec-grad-a: rgba(201, 168, 76, 0.17);
  --sf-sec-grad-b: rgba(201, 168, 76, 0.05);
  --sf-sec-border: rgba(201, 168, 76, 0.2);
  --sf-sec-border-hover: rgba(212, 186, 106, 0.5);
  --sf-sec-glow: rgba(201, 168, 76, 0.22);
  --sf-sec-chip: rgba(230, 225, 216, 0.08);
}

[data-md-color-scheme="default"] {
  --sf-sec-grad-a: rgba(138, 109, 31, 0.13);
  --sf-sec-grad-b: rgba(138, 109, 31, 0.035);
  --sf-sec-border: rgba(138, 109, 31, 0.22);
  --sf-sec-border-hover: rgba(138, 109, 31, 0.5);
  --sf-sec-glow: rgba(138, 109, 31, 0.18);
  --sf-sec-chip: rgba(26, 26, 26, 0.06);
}

/* ── Toolbar under the page title ──────────── */

.md-typeset .sf-sections-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.8rem;
  margin: -0.4rem 0 1.4rem;
}

.md-typeset .sf-sections-toolbar__count {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--md-default-fg-color--light);
}

.md-typeset .sf-sections-toolbar__btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.85rem 0.35rem 0.6rem;
  font: inherit;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--md-typeset-a-color);
  background: linear-gradient(100deg, var(--sf-sec-grad-a), var(--sf-sec-grad-b));
  border: 1px solid var(--sf-sec-border);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}

.md-typeset .sf-sections-toolbar__btn:hover {
  border-color: var(--sf-sec-border-hover);
  box-shadow: 0 4px 16px -8px var(--sf-sec-glow);
}

.md-typeset .sf-sections-toolbar__btn:active {
  transform: translateY(1px);
}

.md-typeset .sf-sections-toolbar__btn:focus-visible,
.md-typeset .sf-section__header:focus-visible {
  outline: 2px solid var(--sf-gold);
  outline-offset: 2px;
}

/* Two stacked chevrons: pointing together = collapse, apart = expand */
.md-typeset .sf-sections-toolbar__icon {
  display: inline-grid;
  width: 0.9rem;
  height: 0.9rem;
}

.md-typeset .sf-sections-toolbar__icon svg {
  grid-area: 1 / 1;
  width: 0.9rem;
  height: 0.9rem;
  fill: currentColor;
  transition: transform 0.3s ease;
}

.md-typeset .sf-sections-toolbar__btn[data-state="open"] .sf-sections-toolbar__icon svg:first-child {
  transform: translateY(0.18rem) rotate(180deg);
}
.md-typeset .sf-sections-toolbar__btn[data-state="open"] .sf-sections-toolbar__icon svg:last-child {
  transform: translateY(-0.18rem);
}
.md-typeset .sf-sections-toolbar__btn[data-state="closed"] .sf-sections-toolbar__icon svg:first-child {
  transform: translateY(-0.2rem) rotate(180deg);
}
.md-typeset .sf-sections-toolbar__btn[data-state="closed"] .sf-sections-toolbar__icon svg:last-child {
  transform: translateY(0.2rem);
}

/* ── Section card ──────────────────────────── */

/* Spacing lives BELOW an open section (its body's bottom padding), never
   above a header: collapsing or expanding a section then only moves what
   comes after it, and the header you clicked stays under the cursor.
   Closed cards stack at this small gap, so a collapsed page reads as an
   outline. */
.md-typeset .sf-section {
  margin: 0.75rem 0 0;
}

.md-typeset .sf-section--first {
  margin-top: 2rem;
}

.md-typeset .sf-section__header {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.7rem 0.8rem 0.7rem 1rem;
  background: linear-gradient(100deg, var(--sf-sec-grad-a) 0%, var(--sf-sec-grad-b) 55%, transparent 100%);
  border: 1px solid var(--sf-sec-border);
  border-radius: 0.7rem;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

/* The gold accent bar on the left edge */
.md-typeset .sf-section__header::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 0.55rem;
  bottom: 0.55rem;
  width: 3px;
  border-radius: 3px;
  background: linear-gradient(180deg, var(--sf-gold-light), var(--sf-gold-dark));
}

.md-typeset .sf-section__header:hover {
  border-color: var(--sf-sec-border-hover);
  box-shadow: 0 8px 28px -16px var(--sf-sec-glow);
}

.md-typeset .sf-section__header h2 {
  flex: 1;
  margin: 0;
  font-size: 1.35em;
  line-height: 1.3;
}

/* The section number as a badge */
.md-typeset .sf-section__num {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.1rem;
  height: 2.1rem;
  font-size: 0.95rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #1a1a1a;
  background: linear-gradient(135deg, var(--sf-gold-light) 0%, var(--sf-gold) 55%, var(--sf-gold-dark) 100%);
  border-radius: 0.6rem;
  box-shadow: 0 3px 12px -4px var(--sf-sec-glow), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.md-typeset .sf-section__num--dot {
  width: 0.7rem;
  height: 0.7rem;
  margin: 0 0.7rem;
  border-radius: 50%;
}

/* "4 parts" — only while collapsed, as a hint of what is inside */
.md-typeset .sf-section__meta {
  flex: none;
  padding: 0.15rem 0.6rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--md-default-fg-color--light);
  background: var(--sf-sec-chip);
  border-radius: 999px;
  opacity: 0;
  transform: translateX(0.4rem);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}

.md-typeset .sf-section__meta:empty {
  display: none;
}

.md-typeset .sf-section.is-collapsed .sf-section__meta {
  opacity: 1;
  transform: none;
}

.md-typeset .sf-section__chevron {
  flex: none;
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  color: var(--md-default-fg-color--light);
  transition: background 0.2s ease, color 0.2s ease;
}

.md-typeset .sf-section__chevron svg {
  width: 1.3rem;
  height: 1.3rem;
  fill: currentColor;
  transition: transform 0.3s ease;
}

.md-typeset .sf-section__header:hover .sf-section__chevron {
  color: var(--md-typeset-a-color);
  background: var(--sf-sec-chip);
}

.md-typeset .sf-section.is-collapsed .sf-section__chevron svg {
  transform: rotate(-90deg);
}

/* ── Collapsible body ──────────────────────── */

/* grid-template-rows animates between 1fr and 0fr: a smooth height
   transition without measuring the content */
.md-typeset .sf-section__body {
  display: grid;
  /* minmax(0, 1fr): without it the column grows to the widest unbreakable
     content (a long code line) and the section spills out of the page */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.32s ease;
}

.md-typeset .sf-section.is-collapsed .sf-section__body {
  grid-template-rows: 0fr;
}

/* Clip vertically only, so wide code blocks and tables keep their own
   horizontal scrolling. No side indent: the content keeps the page's full
   writable width. */
.md-typeset .sf-section__inner {
  min-height: 0;
  min-width: 0;
  overflow-x: visible;
  overflow-y: clip;
  padding: 0.6rem 0 1.65rem;
  transition: opacity 0.25s ease, padding 0.32s ease;
}

/* Padding would survive a zero-height row; drop it while collapsed */
.md-typeset .sf-section.is-collapsed .sf-section__inner {
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
}

/* Sub-headings inside a card need less air than top-level ones */
.md-typeset .sf-section__inner > h3:first-child {
  margin-top: 0.8em;
}

/* Rules that only separated plain sections */
.md-typeset hr.sf-rule--absorbed,
.md-typeset .sf-section__inner > hr:last-child {
  display: none;
}

/* ── Small screens ─────────────────────────── */

@media screen and (max-width: 44.9375em) {
  .md-typeset .sf-section__header {
    gap: 0.65rem;
  }
  .md-typeset .sf-section__meta {
    display: none;
  }
}

/* ── Print: everything open, no controls ───── */

@media print {
  .md-typeset .sf-sections-toolbar,
  .md-typeset .sf-section__chevron,
  .md-typeset .sf-section__meta {
    display: none;
  }
  .md-typeset .sf-section__body,
  .md-typeset .sf-section.is-collapsed .sf-section__body {
    grid-template-rows: 1fr;
  }
  .md-typeset .sf-section.is-collapsed .sf-section__inner {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .md-typeset .sf-section__body,
  .md-typeset .sf-section__inner,
  .md-typeset .sf-section__chevron svg,
  .md-typeset .sf-section__meta,
  .md-typeset .sf-sections-toolbar__icon svg {
    transition: none;
  }
}
