/* Page map (site/snippets/blocks/pagemap.php, the Single Location tier
   page's "What the 30 pages are"; public/assets/js/pagemap.js). The site's
   pages as a tree in the tier diagrams' style (blocks.css, "dg-"): lines at
   1.5px in the text's color at 0.55, round dots with a 1.5px ink outline
   (mint, peach, gold soft, butter, the hub in the page accent), the dashed
   boundary at 0.4 around a branch that holds another. Linked by the block
   itself (peanut_page_css), once per page. Every selector names a pagemap
   class. Tokens only. The shared hint is industry.css's.

   Geometry: --pm-x is the center of the site's dot and of each top branch's
   dot, so one rail runs through them; each branch's leaves hang on a rail of
   their own at --pm-step inside its leaves list. --pm-c on an item is the
   height from its top to its dot's center, where the rail stops on the last
   item. From 64rem, two to five branches stand side by side under a bus
   line (the Regional diagram's layout). */

@layer blocks {
  .pagemap__head {
    max-width: 44rem;
    margin-block-end: var(--space-5);
  }

  .pagemap__title {
    margin: 0;
  }

  .pagemap__intro {
    margin: var(--space-3) 0 0;
  }

  /* ---------- the hint and Open every branch (shown by the script) ---------- */
  .pagemap__bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-1) var(--space-3);
  }

  .pagemap.is-live .pagemap__bar {
    margin-block-end: var(--space-4);
  }

  .pagemap__bar [hidden] {
    display: none;
  }

  .pagemap__all {
    min-height: 2.75rem;
    margin: 0;
    padding: 0.5rem 0;
    background: none;
    border: 0;
    color: inherit;
    font: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.5;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.2em;
    cursor: pointer;
  }

  .pagemap__all:hover {
    text-decoration-thickness: 2px;
  }

  /* ---------- the tree ---------- */
  .pagemap__tree {
    --pm-line: 1.5px;
    --pm-x: 1.125rem;
    --pm-gap: 0.75rem;
    --pm-step: 0.375rem;
    --pm-col-gap: 2rem;
  }

  .pagemap__dot {
    --d: 0.75rem;
    position: relative;
    z-index: 1;
    flex: none;
    display: block;
    box-sizing: border-box;
    width: var(--d);
    height: var(--d);
    background: var(--color-brand);
    border: var(--pm-line, 1.5px) solid var(--color-ink);
    border-radius: 50%;
  }

  .pagemap__root {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem var(--pm-gap);
    min-height: 2.25rem;
    margin: 0;
  }

  .pagemap__root .pagemap__dot {
    --d: 2.25rem;
    background: var(--color-white);
  }

  .pagemap__rootname {
    font-size: 1.0625rem;
    font-weight: 600;
    line-height: 1.3;
  }

  .pagemap__tag {
    padding: 0.0625rem 0.5rem;
    background: var(--color-butter);
    border: var(--border);
    border-radius: var(--radius-sm);
    color: var(--color-ink);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: var(--tracking-caps);
    line-height: 1.6;
    text-transform: uppercase;
  }

  .pagemap__branches,
  .pagemap__leaves {
    position: relative;
    margin: 0;
    padding: 0;
    list-style: none;
  }

  /* a branch: --d its dot, --cx its dot's center from its left edge */
  .pagemap__branch {
    --d: 1.75rem;
    --cx: var(--pm-x);
    --pm-c: 1.625rem;
    position: relative;
    padding-block: 0.25rem 0.75rem;
  }

  .pagemap__branch--sub {
    --d: 1.25rem;
    --cx: var(--pm-step);
    padding-block-end: 0.25rem;
  }

  .pagemap__bhead,
  .pagemap__toggle {
    display: flex;
    align-items: center;
    gap: var(--pm-gap);
    min-height: 2.75rem;
    margin: 0;
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: normal;
  }

  .pagemap__bhead .pagemap__dot {
    --d: inherit;
    margin-inline-start: calc(var(--cx) - var(--d) / 2);
  }

  .pagemap__branch--sub > .pagemap__bhead {
    font-size: 0.9375rem;
  }

  .pagemap__toggle {
    padding: 0 0.25rem 0 0;
    background: none;
    border: 0;
    color: inherit;
    text-align: start;
    cursor: pointer;
  }

  .pagemap__toggle:hover .pagemap__name {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.2em;
  }

  /* the plus on a closed branch's dot, a minus once it is open */
  .pagemap__toggle .pagemap__dot::before,
  .pagemap__toggle .pagemap__dot::after {
    content: "";
    position: absolute;
    inset: 0;
    width: calc(var(--d) * 0.4);
    height: var(--pm-line);
    margin: auto;
    background: var(--color-ink);
  }

  .pagemap__toggle .pagemap__dot::after {
    transform: rotate(90deg);
  }

  .pagemap__toggle[aria-expanded="true"] .pagemap__dot::after {
    transform: rotate(90deg) scaleX(0);
  }

  /* the indent sits on the inner box, so the closed state's clip never cuts a nested dot */
  .pagemap__line,
  .pagemap__inner {
    padding-inline-start: calc(var(--cx) + var(--d) / 2 + var(--pm-gap));
  }

  .pagemap__line {
    max-width: 34rem;
    margin: 0;
    line-height: 1.5;
  }

  .pagemap__kids {
    margin-block-start: 0.5rem;
  }

  .pagemap__kids[data-closed] {
    display: none;
  }

  /* dot colors: the branch's own, the leaves mint, peach, gold in turn (as the diagrams' city pages) */
  .pagemap__branch--accent > .pagemap__bhead .pagemap__dot {
    background: var(--accent-mark, var(--accent));
  }

  .pagemap__branch--mint > .pagemap__bhead .pagemap__dot,
  .pagemap__leaf:nth-child(3n + 1) > .pagemap__dot {
    background: var(--color-brand);
  }

  .pagemap__branch--peach > .pagemap__bhead .pagemap__dot,
  .pagemap__leaf:nth-child(3n + 2) > .pagemap__dot {
    background: var(--color-accent-2);
  }

  .pagemap__branch--gold > .pagemap__bhead .pagemap__dot,
  .pagemap__leaf:nth-child(3n) > .pagemap__dot {
    background: var(--color-gold-soft);
  }

  .pagemap__branch--butter > .pagemap__bhead .pagemap__dot {
    background: var(--color-butter);
  }

  .pagemap__branch--white > .pagemap__bhead .pagemap__dot {
    background: var(--color-white);
  }

  /* a leaf: its dot on the leaves' rail, the name, an optional note under it */
  .pagemap__leaf {
    --pm-c: 1.0625rem;
    position: relative;
    padding: 0.3125rem 0 0.3125rem 1.375rem;
  }

  .pagemap__leaf > .pagemap__dot {
    position: absolute;
    inset-block-start: calc(var(--pm-c) - var(--d) / 2);
    inset-inline-start: calc(var(--pm-step) - var(--d) / 2);
  }

  .pagemap__leafname {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.5rem;
  }

  .pagemap__more {
    display: block;
    font-size: 0.8125rem;
    line-height: 1.45;
  }

  /* ---------- the lines ---------- */
  .pagemap__branches > li::before,
  .pagemap__leaves > li::before {
    content: "";
    position: absolute;
    inset-block: 0;
    inset-inline-start: calc(var(--pm-x) - var(--pm-line) / 2);
    width: var(--pm-line);
    background: currentColor;
    opacity: 0.55;
  }

  .pagemap__leaves > li::before {
    inset-inline-start: calc(var(--pm-step) - var(--pm-line) / 2);
  }

  .pagemap__branches > li:last-child::before,
  .pagemap__leaves > li:last-child::before {
    inset-block-end: auto;
    height: var(--pm-c);
  }

  /* the dashed boundary around a branch that holds another (the hub and its city pages) */
  .pagemap__branch--ring {
    --pm-c: 2.125rem;
    padding: 0.75rem 0.75rem 1rem 0;
    margin-block: 0.5rem;
  }

  .pagemap__branch--ring::after {
    content: "";
    position: absolute;
    inset: 0 0 0 -0.375rem;
    border: var(--pm-line) dashed currentColor;
    border-radius: var(--radius-sm);
    opacity: 0.4;
    pointer-events: none;
  }

  /* ---------- the line under the map: a dashed dot, a place with no office ---------- */
  .pagemap__note {
    display: flex;
    align-items: flex-start;
    gap: var(--pm-gap, 0.75rem);
    max-width: 44rem;
    margin: var(--space-4) 0 0;
    line-height: 1.7;
  }

  .pagemap__note .pagemap__dot {
    margin-block-start: calc((1.7em - var(--d)) / 2);
    background: transparent;
    border-style: dashed;
    border-color: currentColor;
  }

  /* ---------- wide screens: the branches side by side under a bus line ---------- */
  @media (min-width: 64rem) {
    .pagemap__branches--cols {
      display: grid;
      grid-template-columns: repeat(var(--pm-n), minmax(0, 1fr));
      align-items: start;
      column-gap: var(--pm-col-gap);
      padding-block-start: 2rem;
    }

    .pagemap__branches--2 {
      --pm-n: 2;
    }

    .pagemap__branches--3 {
      --pm-n: 3;
    }

    .pagemap__branches--4 {
      --pm-n: 4;
    }

    .pagemap__branches--5 {
      --pm-n: 5;
    }

    /* the bus: from the first column's dot to the last one's */
    .pagemap__branches--cols::before {
      content: "";
      position: absolute;
      inset-block-start: 0;
      inset-inline-start: calc(var(--pm-x) - var(--pm-line) / 2);
      inset-inline-end: calc((100% - (var(--pm-n) - 1) * var(--pm-col-gap)) / var(--pm-n) - var(--pm-x) - var(--pm-line) / 2);
      height: var(--pm-line);
      background: currentColor;
      opacity: 0.55;
    }

    /* each column's drop from the bus to its dot (the first one also meets the site's dot) */
    .pagemap__branches--cols > li::before,
    .pagemap__branches--cols > li:last-child::before {
      inset-block: -2rem auto;
      height: calc(2rem + var(--pm-c));
    }

    /* every column's dot on one line: the boundary grows upward instead */
    .pagemap__branches--cols > .pagemap__branch--ring {
      --pm-c: 1.625rem;
      margin-block: 0;
      padding-block-start: 0.25rem;
    }

    .pagemap__branches--cols > .pagemap__branch--ring::after {
      inset-block-start: -0.75rem;
    }
  }

  @media print {
    .pagemap__kids[data-closed] {
      display: block;
    }

    .pagemap__bar {
      display: none;
    }
  }
}

@layer motion {
  @media screen and (prefers-reduced-motion: no-preference) {
    html[data-fx~="diagrams"] .pagemap.is-live .pagemap__kids {
      display: grid;
      grid-template-rows: 1fr;
      opacity: 1;
      visibility: visible;
      transition: grid-template-rows 400ms var(--ease-out), opacity 300ms var(--ease-out), visibility 0s linear 0s;
    }

    html[data-fx~="diagrams"] .pagemap.is-live .pagemap__kids[data-closed] {
      grid-template-rows: 0fr;
      opacity: 0;
      visibility: hidden;
      transition: grid-template-rows 300ms var(--ease-out), opacity 200ms var(--ease-out), visibility 0s linear 300ms;
    }

    html[data-fx~="diagrams"] .pagemap.is-live .pagemap__inner {
      min-height: 0;
      overflow: hidden;
    }

    html[data-fx~="diagrams"] .pagemap.is-live .pagemap__toggle .pagemap__dot::after {
      transition: transform 250ms var(--ease-out);
    }
  }
}
