/* ---------------------------------------------------------------
   Reader controls — full-screen zoom for pictures, foldaway columns.

   Loaded as a plain stylesheet from public/ rather than through a Starlight
   component override. Overriding PageFrame or TwoColumnContent would mean
   copying their source and re-copying it at every upgrade; this file instead
   leans on three things Starlight documents or has kept stable since 0.19 —
   the `--sl-sidebar-width` and `--sl-content-width` variables, the
   `.sidebar-pane` element and the `.right-sidebar-container` element.

   The column widths are driven entirely by `--sl-sidebar-width`: Starlight
   derives the main frame's inline padding and the right column's width from
   it, so setting it to zero folds the left column and re-flows everything
   else without touching a single layout rule.
   --------------------------------------------------------------- */

/* --- the two collapse handles ----------------------------------- */

.rd-handle {
  position: fixed;
  top: 50%;
  z-index: calc(var(--sl-z-index-navbar, 10) + 1);
  display: none; /* switched on per breakpoint below */
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 3.5rem;
  margin: 0;
  padding: 0;
  transform: translateY(-50%);
  border: 1px solid var(--sl-color-hairline-shade, var(--sl-color-gray-5));
  border-radius: 0.5rem;
  background-color: var(--sl-color-bg-nav);
  color: var(--sl-color-gray-3);
  cursor: pointer;
  opacity: 0.45;
  transition:
    opacity 0.15s ease,
    color 0.15s ease;
}

.rd-handle:hover,
.rd-handle:focus-visible {
  opacity: 1;
  color: var(--sl-color-white);
}

.rd-handle svg {
  width: 1rem;
  height: 1rem;
}

/* The handle sits astride the column's border: the edge positions are
   measured in reader.js, because the right column's width is a calc() over
   three variables and a percentage of a box this element is not inside. */
.rd-handle-left {
  inset-inline-start: max(0.25rem, calc(var(--rd-left-edge, 0px) - 0.875rem));
}

.rd-handle-right {
  inset-inline-end: max(0.25rem, calc(var(--rd-right-edge, 0px) - 0.875rem));
}

/* Chevrons point at what the click does. */
html[data-reader-left="off"] .rd-handle-left svg,
html:not([data-reader-right="off"]) .rd-handle-right svg {
  transform: rotate(180deg);
}

/* Below Starlight's own breakpoints each column is already a drawer or a
   dropdown, so there is nothing to fold and the handle would only be in the
   way. */
@media (min-width: 50rem) {
  html[data-has-sidebar] .rd-handle-left {
    display: flex;
  }

  html[data-has-sidebar][data-reader-left="off"] {
    --sl-sidebar-width: 0rem;
  }

  html[data-reader-left="off"] .sidebar-pane {
    display: none;
  }
}

@media (min-width: 72rem) {
  html[data-has-toc] .rd-handle-right {
    display: flex;
  }

  html[data-reader-right="off"] .right-sidebar-container {
    display: none;
  }

  /* Starlight's own rule is [data-has-sidebar][data-has-toc] .main-pane, so
     this selector has to out-specify it rather than merely follow it. */
  html[data-has-sidebar][data-has-toc][data-reader-right="off"] .main-pane {
    width: 100%;
    --sl-content-margin-inline: auto;
  }

  /* A folded column is only worth folding if the page takes the space. */
  html[data-reader-left="off"],
  html[data-reader-right="off"] {
    --sl-content-width: 60rem;
  }

  html[data-reader-left="off"][data-reader-right="off"] {
    --sl-content-width: 72rem;
  }
}

/* --- pictures open full screen ---------------------------------- */

.sl-markdown-content img.rd-zoomable {
  cursor: zoom-in;
}

.sl-markdown-content img.rd-zoomable:focus-visible {
  outline: 2px solid var(--sl-color-text-accent);
  outline-offset: 3px;
}

.rd-viewer[hidden] {
  display: none;
}

.rd-viewer {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  /* Opaque, not a wash: at any alpha the page behind reads through a diagram
     drawn in thin lines and small type. */
  background-color: #0b0e14;
  /* The viewer is its own surface and does not follow the page theme: a
     diagram is drawn on white and reads against a dark backdrop either way. */
  color: #e6ecf3;
}

.rd-bar {
  display: flex;
  flex: none;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid rgb(255 255 255 / 0.12);
  font-size: var(--sl-text-xs, 0.8125rem);
}

.rd-level {
  min-width: 3.5rem;
  font-variant-numeric: tabular-nums;
  color: #97a4b2;
}

.rd-hint {
  flex: 1;
  overflow: hidden;
  color: #737f8b;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rd-bar button {
  min-width: 2rem;
  padding: 0.25rem 0.6rem;
  border: 1px solid rgb(255 255 255 / 0.18);
  border-radius: 0.375rem;
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: 1.6;
  cursor: pointer;
}

.rd-bar button:hover,
.rd-bar button:focus-visible {
  background-color: rgb(255 255 255 / 0.12);
}

.rd-stage {
  position: relative;
  flex: 1;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
}

.rd-stage.rd-dragging {
  cursor: grabbing;
}

.rd-stage img {
  position: absolute;
  top: 50%;
  left: 50%;
  max-width: none;
  max-height: none;
  transform-origin: center center;
  /* PlantUML and draw.io both emit a transparent background; without this a
     black-on-transparent diagram is invisible on the dark backdrop. */
  background-color: #ffffff;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
}

body.rd-locked {
  overflow: hidden;
}

/* On a phone the toolbar has to lose something, and it is the prose: the
   gestures it describes are the ones a touch screen already implies. */
@media (max-width: 34rem) {
  .rd-hint {
    display: none;
  }

  .rd-bar {
    gap: 0.375rem;
    padding: 0.5rem;
  }

  .rd-bar button {
    padding: 0.25rem 0.45rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rd-handle {
    transition: none;
  }
}
