/* ==========================================================================
   Section menu (js/section-menu.js). Only pages that link this file get it.
   Computers (992px and up): a list on the left that stays in view.
   Phones and tablets: a slim bar across the top, shown only when the reader
   scrolls back up; tapping it slides the list in from the left.
   Colors and fonts come from the shared tokens in prophecy.css.
   ========================================================================== */
:where(:root) {   /* loads after settings.css: the saved panel settings must win over these */
  --type-section-bar-label: 11px;   /* phones: "In this article" on the bar */
  --type-section-bar: 15px;         /* phones: the section being read, on the bar */
  --type-section-close: 30px;       /* phones: the list's close button */
  --type-section-menu-sub: 14px;    /* the smaller entries under a section */
  --section-menu-fold: slide;       /* computers: how the list folds and opens (slide, fade, blind, wipe) */
}
.section-menu {
  --_fold: var(--section-menu-fold);   /* so picking the menu in the edit panel offers how it folds */
  font-family: var(--font-ui);
  font-size: var(--type-toc);
  line-height: 1.4;
  letter-spacing: 0;
  overflow-wrap: anywhere;
  hyphens: auto;
  overscroll-behavior: contain;
}
.section-menu[hidden] { display: none !important; }
.section-menu-title {
  margin: 0 0 10px;
  font-size: var(--type-kicker);
  font-weight: 700;
  letter-spacing: var(--type-tracking-kicker);
  text-transform: uppercase;
  color: var(--color-accent);
}
.section-menu-list { list-style: none; margin: 0; padding: 0; }
.section-menu-list li { margin: 0; min-width: 0; }
.section-menu-list a {
  --_fold: var(--section-menu-fold);
  display: block;
  padding: 7px 10px 7px 12px;
  border-left: 3px solid var(--color-rule);
  color: var(--color-ink);
  text-decoration: none;
  white-space: normal;
}
.section-menu-list .section-menu-h3 a { padding-left: 26px; font-size: var(--type-section-menu-sub); color: var(--color-muted); }
.section-menu-list .section-menu-group a { font-weight: 700; }   /* a group line from data-menu-group (js/section-menu.js) */
.section-menu-list a:hover { color: var(--color-accent); background: var(--color-tint); }
.section-menu-list a:focus-visible { outline: 2px solid var(--color-highlight); outline-offset: -2px; }
.section-menu-list .is-current a {
  border-left-color: var(--color-accent);
  background: var(--color-label-bg);
  color: var(--color-accent-dark);
  font-weight: 700;
}
.article-body h2[tabindex="-1"]:focus, .article-body h3[tabindex="-1"]:focus, .article-head[tabindex="-1"]:focus { outline: none; }

/* ---------- Phones and tablets: the bar across the top ---------- */
.section-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  margin: 0;
  padding: 6px 16px;
  border: 0;
  border-bottom: 1px solid var(--color-rule);
  background: var(--color-paper);
  color: var(--color-ink);
  font-family: var(--font-ui);
  text-align: left;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  /* Out of sight until the reader scrolls back up */
  transform: translateY(-110%);
  visibility: hidden;
  transition: transform 0.22s ease, visibility 0s 0.22s;
}
.section-bar.is-shown, .section-bar[aria-expanded="true"] {
  transform: none;
  visibility: visible;
  transition: transform 0.22s ease;
}
.section-bar:focus-visible { outline: 3px solid var(--color-highlight); outline-offset: -3px; }
.section-bar .section-menu-bars { flex: none; color: var(--color-accent-dark); }
.section-bar-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.section-bar-label {
  font-size: var(--type-section-bar-label);
  font-weight: 700;
  letter-spacing: var(--type-tracking-kicker);
  text-transform: uppercase;
  color: var(--color-accent);
}
.section-bar-now {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: var(--type-section-bar);
  font-weight: 600;
}
/* How far through the article */
.section-bar-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 3px;
  background: var(--color-accent);
  transform: scaleX(0);
  transform-origin: left;
}

.section-menu-bars, .section-menu-bars::before, .section-menu-bars::after {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 1px;
  background: currentColor;
}
.section-menu-bars { position: relative; }
.section-menu-bars::before, .section-menu-bars::after { content: ""; position: absolute; left: 0; }
.section-menu-bars::before { top: -6px; }
.section-menu-bars::after { top: 6px; }

.section-menu-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-menu-close {
  flex: none;
  width: 40px;
  height: 40px;
  margin: -8px -6px 0 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--color-ink);
  font: 400 var(--type-section-close)/1 var(--font-ui);
  cursor: pointer;
}
.section-menu-close:hover { background: var(--color-tint); }
.section-menu-close:focus-visible { outline: 2px solid var(--color-highlight); }
.section-menu-shade { display: none; }

@media (max-width: 991px) {
  /* The panel slides in from the left, over most of the screen; a dimmed
     strip of the page stays visible on the right. */
  .section-menu {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 70;
    width: min(85vw, 400px);
    overflow-y: auto;
    padding: 18px 16px 24px;
    background: var(--color-paper);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
    visibility: hidden;
    transform: translateX(-100%);
    transition: transform 0.25s ease, visibility 0s 0.25s;
  }
  .section-menu.is-open { visibility: visible; transform: none; transition: transform 0.25s ease; }
  .section-menu-shade {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 65;
    background: rgba(0, 0, 0, 0.4);
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.25s, visibility 0s 0.25s;
  }
  .section-menu-shade.is-open { visibility: visible; opacity: 1; transition: opacity 0.25s; }
  html.section-menu-open { overflow: hidden; }   /* the page behind stays still */
  .section-menu-list a { padding-block: 10px; }
}

/* ---------- Computers: pill + list on the left, article beside it ---------- */
.section-menu-pill { display: none; }
@media (min-width: 992px) {
  .section-bar, .section-menu-close, .section-menu-title { display: none; }
  /* Three columns: menu, article, and an equal empty one on the right, so
     the article sits in the middle of the screen. The article gets its full
     width first; the two sides share what is left (never under 200px). */
  main.has-section-menu {
    display: grid;
    grid-template-columns: minmax(200px, 1fr) minmax(0, calc(var(--layout-text-col) + var(--_gutter) * 2)) minmax(200px, 1fr);
    justify-content: center;
    column-gap: 56px;   /* space between the menu and the article */
    padding-inline: var(--_gutter);
  }
  main.has-section-menu::after { content: ""; grid-column: 3; grid-row: 1; }
  main.has-section-menu > article { min-width: 0; }
  /* The pill and the list under it float in view while the article scrolls */
  .section-menu {
    position: sticky;
    top: 24px;
    z-index: 1;   /* below .full-width videos, which cover it as they scroll past */
    align-self: start;
    justify-self: end;   /* stays 56px from the article however wide its column is */
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    max-width: 270px;
    min-width: 0;
    max-height: calc(100vh - 48px);
    margin-top: var(--_section);
  }
  .section-menu-top { flex: none; }
  .section-menu-pill {
    --_fold: var(--section-menu-fold);
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 12px;
    padding: 10px 16px 10px 14px;
    border: 0;
    border-radius: 999px;
    background: rgba(39, 92, 129, 0.12);   /* light, see-through blue (--color-accent at 12%) */
    color: var(--color-accent-dark);
    font: 700 var(--type-kicker)/1 var(--font-ui);
    letter-spacing: 2px;
    text-transform: none;
    box-shadow: 0 2px 8px rgba(0, 51, 102, 0.08);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s;
  }
  .section-menu-pill:hover { background: rgba(39, 92, 129, 0.2); box-shadow: 0 3px 12px rgba(0, 51, 102, 0.14); }
  .section-menu-pill:focus-visible { outline: 3px solid var(--color-highlight); outline-offset: 2px; }
  .section-menu-pill .section-menu-bars { width: 14px; margin-right: 8px; }   /* more room between the icon and the words */
  .section-menu-pill .section-menu-bars::before { top: -5px; }
  .section-menu-pill .section-menu-bars::after { top: 5px; }
  .section-menu-chevron {
    width: 7px;
    height: 7px;
    margin-left: 2px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: translateY(2px) rotate(-135deg);
    transition: transform 0.2s;
  }
  .section-menu.is-folded .section-menu-chevron { transform: translateY(-2px) rotate(45deg); }
  .section-menu-list {
    --_fold: var(--section-menu-fold);
    align-self: stretch;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 4px;
    /* How it folds and opens (Zev: not so abrupt) is the --section-menu-fold
       setting; js/section-menu.js puts it on the menu as a fold-* class.
       display waits for the movement (allow-discrete). */
    transition: opacity 0.2s ease, transform 0.2s ease, clip-path 0.2s ease, display 0.2s allow-discrete;
  }
  /* slide (the default): fades and slides up a little */
  .section-menu.is-folded .section-menu-list { display: none; opacity: 0; transform: translateY(-8px); }
  /* fade: fades only */
  .section-menu.fold-fade.is-folded .section-menu-list { transform: none; }
  /* blind: rolls up into the pill, the words going up with it */
  .section-menu.fold-blind .section-menu-list { transition-duration: 0.3s; clip-path: inset(0 0 0 0); }
  .section-menu.fold-blind.is-folded .section-menu-list { opacity: 1; transform: translateY(-100%); clip-path: inset(100% 0 0 0); }
  /* wipe: the words stay still and are covered from the bottom up */
  .section-menu.fold-wipe .section-menu-list { transition-duration: 0.25s; clip-path: inset(0 0 0 0); }
  .section-menu.fold-wipe.is-folded .section-menu-list { opacity: 1; transform: none; clip-path: inset(0 0 100% 0); }
  @starting-style {
    .section-menu:not(.is-folded) .section-menu-list { opacity: 0; transform: translateY(-8px); }
    .section-menu.fold-fade:not(.is-folded) .section-menu-list { transform: none; }
    .section-menu.fold-blind:not(.is-folded) .section-menu-list { opacity: 1; transform: translateY(-100%); clip-path: inset(100% 0 0 0); }
    .section-menu.fold-wipe:not(.is-folded) .section-menu-list { opacity: 1; transform: none; clip-path: inset(0 0 100% 0); }
  }
}
@media (prefers-reduced-motion: reduce) { .section-menu-list, .section-menu,.section-menu.is-open, .section-menu-shade, .section-menu-shade.is-open, .section-bar, .section-bar.is-shown { transition: none; } }
@media print { .section-menu, .section-bar { display: none !important; } main.has-section-menu { display: block; padding: 0; } }
