/* The site's Mermaid diagrams, which javascripts/diagrams.js makes open full size: the size their labels are measured
   at, the diagrams' cursor and focus ring, and the dialog that shows one. A stylesheet in extra_css rather than a style
   the script adds, since instant navigation rebuilds the page's head from the next page's, keeping only what every page
   lists. */

/* Mermaid measures each label in a scratch copy of the diagram that it adds to the page's body, d<id> for the theme's
   id __mermaid_<n>, and sizes the boxes, and the room between them, to fit. The copy's own style sets its labels'
   16px; this sets it on the copy itself too, so a browser that hasn't applied that style yet measures them at 16px
   rather than at the body's smaller size, which once had Safari cut off the subgraphs' titles and run labels past their
   boxes. */
body > div[id^="d__mermaid_"] {
  font-size: 16px;
}

/* A diagram's boxes are neutral, the page's ground in a gray line, where the theme filled each with the accent's tint
   and outlined it in the accent, which marks a link, the current item, and focus, and fills no surface. A diagram marks
   its own product, the proxy and the agent, and the firewall's edge, with the classes diagrams.js outlines (product,
   firewall). A sequence diagram's boxes, the two sides of the firewall, are filled as the flowcharts' zones are. On the
   page, and enlarged; the diagram's shadow root inherits the variables. */
.md-typeset div.mermaid,
dialog.diagram-zoom {
  --md-mermaid-node-bg-color: var(--md-default-bg-color);
  --md-mermaid-node-fg-color: var(--md-default-fg-color--light);
  --md-mermaid-sequence-box-bg-color: var(--md-default-fg-color--lightest);

  /* The theme sets a sequence diagram's colors from the node colors where it declares them, on the page's root, so
     each takes the neutral value here too. */
  --md-mermaid-sequence-actor-border-color: var(--md-default-fg-color--light);
  --md-mermaid-sequence-actorman-line-color: var(--md-default-fg-color--light);
  --md-mermaid-sequence-label-bg-color: var(--md-default-bg-color);
  --md-mermaid-sequence-label-fg-color: var(--md-default-fg-color--light);
  --md-mermaid-sequence-loop-bg-color: var(--md-default-bg-color);
  --md-mermaid-sequence-loop-border-color: var(--md-default-fg-color--light);
  --md-mermaid-sequence-number-bg-color: var(--md-default-fg-color--light);
}

/* The diagram's box is as wide as the drawing (diagrams.js gives its width as --diagram-width), so its focus ring
   traces the drawing. It's centered on the reading text's measure, 27rem (extra.css), where centered in the column,
   which is wider, a diagram narrower than the text stood off to the right of the text it illustrates. One wider than
   the measure starts at the text's edge, as code and tables do, and on a phone, whose column is narrower than the
   measure, it's centered in the column. */
.md-typeset div.mermaid[role="button"] {
  max-width: var(--diagram-width, none);
  margin-right: auto;
  margin-left: max(0px, (min(27rem, 100%) - var(--diagram-width, 100%)) / 2);
  cursor: zoom-in;
}

.md-typeset div.mermaid[role="button"]:focus-visible {
  outline: 2px solid var(--md-accent-fg-color);
  outline-offset: 4px;
}

/* A diagram's description, its accDescr, which a screen reader reads with the diagram's button: hidden from view, as
   the diagram itself shows it. */
.md-typeset .diagram-desc {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  border: 0;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* The line under a diagram that says a tap enlarges it, set as a screenshot's caption is: only on a touch screen, which
   has no zoom-in cursor to say so. The button's name says so already, and a button's text isn't read apart from it, so
   a screen reader skips it. */
@media (hover: none) {
  .md-typeset div.mermaid[role="button"]::after {
    content: "Tap the diagram to see it full screen.";
    display: block;
    margin-top: 0.5em;
    text-align: center;
    color: var(--md-default-fg-color--light);
    font-size: 0.7rem;
  }
}

dialog.diagram-zoom {
  box-sizing: border-box;
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 48px 24px 24px;
  border: 0;
  background: var(--md-default-bg-color);
  color: var(--md-default-fg-color);
  cursor: zoom-out;
}

dialog.diagram-zoom::backdrop {
  background: var(--md-default-bg-color);
}

html:has(dialog.diagram-zoom[open]) {
  overflow: hidden;
}

dialog.diagram-zoom .diagram-zoom-view {
  width: 100%;
  height: 100%;
}

dialog.diagram-zoom button {
  position: fixed;
  top: 8px;
  right: 12px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--md-default-fg-color--light);
  font: 28px/36px sans-serif;
  cursor: pointer;
}

dialog.diagram-zoom button:hover {
  color: var(--md-default-fg-color);
  background: var(--md-default-fg-color--lightest);
}

dialog.diagram-zoom button:focus-visible {
  outline: 2px solid var(--md-accent-fg-color);
}
