.opening-map-document-branch-navigation button::after {
  content: attr(aria-label);
}

.opening-map-document-branch-navigation > [data-document-branch-controls],
.opening-map-document-branch-trigger { display: none; }

.opening-map-document-branch-navigation > button[hidden] { display: none; }

@media screen and (min-width: 821px) {
  .opening-map-document-branch-navigation > [data-document-branch-controls] {
    display: inline-flex;
    --branch-navigation-icon: url('/static/img/dots-vertical.svg');
  }
  .opening-map-repertoire-document-editor[data-document-branch-actions]
    .opening-map-repertoire-document-move[aria-current='step']:not([data-document-branch-move]) {
    margin-inline-end: calc(var(--document-branch-trigger-space) + var(--document-move-hanging-padding));
  }
  .opening-map-document-branch-trigger {
    position: fixed;
    z-index: 3;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--document-branch-trigger-size);
    height: var(--document-branch-trigger-size);
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--map-muted);
    cursor: pointer;
  }
  .opening-map-document-branch-trigger[hidden] { display: none; }
  .opening-map-document-branch-trigger::before {
    content: '';
    width: 80%;
    height: 80%;
    background: currentColor;
    mask: url('/static/img/dots-vertical.svg') center / contain no-repeat;
    -webkit-mask: url('/static/img/dots-vertical.svg') center / contain no-repeat;
  }
  .opening-map-document-branch-trigger:hover { color: var(--map-text); background: var(--map-control-hover); }
  .opening-map-document-branch-trigger:focus-visible { outline: var(--document-focus-outline, 1px solid var(--map-accent)); outline-offset: 2px; }
}

@media (min-width: 821px), print {
  /* Section roots are displayed by their heading; the authored atom retains
     its source insertion point without taking another notation row. */
  .opening-map-repertoire-document-editor [data-document-branch-move-source] {
    display: none;
  }

  /* Empty object boundaries expose a native text caret without adding a line
     or a column-break opportunity. Typing makes the same span ordinary flow. */
  .opening-map-repertoire-document-editor [data-document-object-caret]:empty {
    position: absolute;
    display: inline-block;
    width: 0;
    min-height: 1em;
    transform: var(--document-object-caret-shift, none);
  }

  .opening-map-document-branch-heading,
  .opening-map-document-branch-choices,
  .opening-map-document-branch-navigation {
    display: block;
    text-align: start;
    font-size: max(15px, 1em);
    line-height: 1.4;
    color: var(--map-text);
    break-inside: avoid;
    break-after: avoid;
  }

  .opening-map-document-branch-heading {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 0.3em;
    scroll-margin-block-start: 4em;
    margin-block-start: 1.25em;
    margin-block-end: 0.35em;
    font-weight: 700;
  }

  .opening-map-document-branch-heading::before {
    content: '';
    grid-column: 1;
    grid-row: 1;
  }

  .opening-map-document-branch-heading:has(> [data-document-branch-move]) {
    grid-template-columns: 1fr auto auto 1fr;
  }

  .opening-map-repertoire-document-editor .opening-map-document-branch-heading > [data-document-branch-move] {
    grid-column: 3;
    grid-row: 1;
    margin-inline: 0;
  }

  .opening-map-document-branch-choices,
  .opening-map-document-branch-navigation {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3em 1em;
    margin-block: 0.45em;
    font-size: 15px;
  }

  .opening-map-document-branch-choices {
    justify-content: center;
    align-items: center;
    margin-block: var(--document-font-size);
    font-weight: 400;
  }

  .opening-map-document-branch-navigation {
    grid-column: 4;
    grid-row: 1;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.2em;
    margin: 0 0 0 auto;
    clear: none;
  }

  .opening-map-document-branch-choices::before {
    content: '';
    flex: 0 0 1.2em;
    width: 1.2em;
    height: 1.2em;
    background: currentColor;
    -webkit-mask: url('/static/img/arrows-split.svg') center / contain no-repeat;
    mask: url('/static/img/arrows-split.svg') center / contain no-repeat;
  }

  .opening-map-document-branch-choices + .opening-map-document-branch-heading {
    margin-block-start: 0;
  }

  :is(.opening-map-document-branch-choices, .opening-map-document-branch-navigation) button {
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--map-muted);
    font: inherit;
    text-align: start;
    cursor: pointer;
    text-decoration: underline;
    text-decoration-color: var(--map-border);
    text-underline-offset: 0.2em;
  }

  .opening-map-document-branch-choices > [data-document-branch-choice] {
    padding: 0.15em 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--map-text);
    font: inherit;
    text-align: start;
    text-decoration: none;
    text-box-trim: trim-both;
    text-box-edge: cap alphabetic;
  }

  .opening-map-document-branch-navigation > button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.6em;
    height: 1.6em;
    text-decoration: none;
  }

  .opening-map-document-branch-navigation > button::after { display: none; }

  .opening-map-document-branch-navigation > button::before {
    content: '';
    width: 1.2em;
    height: 1.2em;
    background: currentColor;
    -webkit-mask: var(--branch-navigation-icon) center / contain no-repeat;
    mask: var(--branch-navigation-icon) center / contain no-repeat;
  }

  .opening-map-document-branch-navigation > [data-branch-navigation-action='previous'] {
    --branch-navigation-icon: url('/static/img/arrow-left.svg');
  }

  .opening-map-document-branch-navigation > [data-branch-navigation-action='fork'] {
    --branch-navigation-icon: url('/static/img/arrows-split.svg');
  }

  .opening-map-document-branch-navigation > [data-branch-navigation-action='next'] {
    --branch-navigation-icon: url('/static/img/arrow-right.svg');
  }

  :is(.opening-map-document-branch-choices, .opening-map-document-branch-navigation) button:hover {
    color: var(--map-text);
    text-decoration-color: currentColor;
  }

  .opening-map-document-branch-choices > button:hover {
    color: var(--map-accent);
  }

  :is(.opening-map-document-branch-choices, .opening-map-document-branch-navigation) button:focus-visible {
    outline: var(--document-focus-outline, 1px solid var(--map-accent));
    outline-offset: 3px;
  }

  .opening-map-document-branch-choices > button[aria-current='step'] {
    outline: 1px solid var(--map-accent);
    outline-offset: 3px;
  }

  .opening-map-document-branch-choices > button[aria-current='step']::selection {
    color: inherit;
    background: transparent;
  }

  /* Flowing analysis keeps one indentation level even for deep chess trees. */
  .opening-map-repertoire-document-editor[data-document-move-layout='paired']
    .opening-map-repertoire-document-variation .opening-map-repertoire-document-variation
    .opening-map-repertoire-document-variation {
    margin-inline-start: 0;
  }
  .opening-map-repertoire-document-editor[data-document-move-layout='paired']:not([data-document-atom-editing])
    .opening-map-repertoire-document-variation .opening-map-repertoire-document-variation
    .opening-map-repertoire-document-variation:not([data-document-variation-inline]):not([data-document-diagram-continuation-before]):not([data-document-diagram-continuation-after]) {
    margin-inline-start: calc(-1 * var(--document-variation-guide-inset));
  }
}

@media print {
  .opening-map-document-branch-navigation { display: none; }
}
