/* Hover preview popup for GitHub source links; see theme/source-peek.js. */

.source-peek {
  position: fixed;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  /* Wide enough for an 80-column source line at the size below. */
  max-width: min(64rem, 94vw);
  overflow: hidden;
  border: 1px solid var(--theme-popup-border, var(--table-border-color, #ccc));
  border-radius: 5px;
  background: var(--theme-popup-bg, var(--bg, #fff));
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
  /* 80% of the body text, and stays that way if the book's size changes. Not
     rem: mdBook roots the page at 62.5%, so 1rem is 10px and 0.8rem would be
     half the body text rather than four fifths of it. */
  font-size: 80%;
  line-height: 1.45;
}

.source-peek[hidden] {
  display: none;
}

/* The header is itself a link, retargeted to whichever line is centred. */
.source-peek-title {
  display: flex;
  flex: none;
  align-items: baseline;
  justify-content: space-between;
  gap: 1em;
  padding: 0.35em 0.6em;
  border-bottom: 1px solid
    var(--theme-popup-border, var(--table-border-color, #ccc));
  color: inherit;
  font-family: var(--mono-font, monospace);
  font-size: 0.9em;
  white-space: nowrap;
  text-decoration: none;
}

.source-peek-title:hover .source-peek-path,
.source-peek-title:hover .source-peek-meta {
  opacity: 1;
  text-decoration: underline;
}

.source-peek-path {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.85;
}

.source-peek-meta {
  flex: none;
  opacity: 0.55;
}

/* The scroll container for both columns. A snippet normally fits, so this only
   scrolls for a link whose own range is long, or when the viewport is short. */
.source-peek-body {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain; /* don't chain into the page and move the anchor */
}

.source-peek-gutter,
.source-peek-code {
  margin: 0;
  padding: 0.45em 0;
  background: none;
  font-family: var(--mono-font, monospace);
  font-size: inherit;
  line-height: inherit;
  white-space: pre;
  tab-size: 8;
}

.source-peek-gutter {
  flex: none;
  position: sticky;
  left: 0;
  z-index: 2; /* stays legible when the code is scrolled horizontally */
  padding-right: 0.5em;
  padding-left: 0.4em;
  border-right: 1px solid
    var(--theme-popup-border, var(--table-border-color, #ccc));
  background: var(--theme-popup-bg, var(--bg, #fff));
  text-align: right;
  user-select: none;
}

/* One anchor per number, so the browser's own link handling applies. The
   opacity lives on the line rather than the gutter because a child cannot
   undo an ancestor's opacity on hover. */
.source-peek-line {
  display: block;
  color: inherit;
  opacity: 0.4;
  text-decoration: none;
}

.source-peek-line.is-linked {
  opacity: 0.75;
}

.source-peek-line:hover,
.source-peek-line:focus {
  opacity: 1;
  text-decoration: underline;
}

/* Sized to the longest line so the bands span the full code width, not just
   the part currently in view. */
.source-peek-code-wrap {
  position: relative;
  flex: 1 0 auto;
  min-width: max-content;
}

.source-peek-code {
  position: relative;
  z-index: 1;
  width: 100%;
  padding-right: 0.7em;
  padding-left: 0.7em;
  overflow: visible;
}

/* Marks the lines the link actually pointed at. */
.source-peek-band {
  position: absolute;
  left: 0;
  z-index: 0;
  width: 100%;
  border-left: 2px solid rgba(93, 156, 236, 0.8);
  background: rgba(93, 156, 236, 0.15);
}

/* Marks the line whose number is under the pointer. */
.source-peek-hover {
  position: absolute;
  left: 0;
  z-index: 0;
  width: 100%;
  background: rgba(127, 127, 127, 0.16);
}

.source-peek-band[hidden],
.source-peek-hover[hidden] {
  display: none;
}

/* Touch-only pointers get no hover, and the tap would fight the link. */
@media (hover: none) {
  .source-peek {
    display: none;
  }
}
