/* The language picker at the top of each page, and what i18n.js needs to show a page in a language. */

/* A page in another language than English, until its texts are in it (i18n.js). */
html.i18n-pending body {
  visibility: hidden;
}

/*
 * TL;DR: A line ends where the page's language ends its lines, and a text of several lines does not end with a word
 * alone on its last line, where the browser can avoid that.
 * Details: A browser breaks Japanese and Korean after any letter, so a line ended inside a word, and a sentence with
 * one letter on a line of its own in a desktop's window (...してくださ / い。). Japanese is broken between its phrases
 * (word-break: auto-phrase, which does nothing in a language without them) and never before a long vowel mark or a
 * small letter (line-break: strict), and Korean between its words, which spaces separate (keep-all): each
 * language's own way of breaking a line, as the direction is for Arabic and Hebrew. In the other languages, the
 * steps of the download page ended with "info)." alone on a line on a phone: text-wrap: pretty asks a browser to
 * break the lines before the last one so that this does not happen. A browser that does not know one of these
 * breaks the lines as before. The landing page's centered sentences have lines of about the same length instead
 * (github-page-style.css).
 */
body {
  text-wrap: pretty;
  line-break: strict;
  word-break: auto-phrase;
}

body:lang(ko) {
  word-break: keep-all;
}

/* Where a line ends, the right, or the left in a page laid out from right to left: of the column that the landing page
   is, and of the block that the download page is. */
.language {
  position: relative;
  align-self: flex-end;
  text-align: end;
}

/*
 * The language picker: a button that shows the page's language, which opens a box under it, with a search field above
 * the list of languages, as the application's list has. The pages differ in their styles, and the download page has no
 * Bootstrap, so the picker is styled whole here.
 */
.language-picker {
  display: inline-block;
  text-align: start;
}

.language-picker[hidden] {
  display: none;
}

.language-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 4px 10px;
  border: 1px solid #ced4da;
  border-radius: 4px;
  background: #fff;
  color: #212529;
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
  cursor: pointer;
}

.language-button:hover {
  background: #f1f3f5;
}

.language-button:focus-visible {
  outline: 2px solid #0d6efd;
  outline-offset: 1px;
}

/* Said by a screen reader before the name of the language on the button, and not shown. */
.language-hidden-label {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* A globe before the name of the language, which says what the button is for in any language. */
.language-globe {
  flex: none;
  width: 18px;
  height: 18px;
  fill: #495057;
}

/* Points down while the box is closed, and up while it is open. */
.language-chevron {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: #343a40;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.language-button[aria-expanded="true"] .language-chevron {
  transform: rotate(180deg);
}

/*
 * The box, under the button and at the edge where its line ends, over the page's content.
 * TL;DR: 260 pixels wide, and wider where an entry needs it, up to the window's width.
 * Details: Each entry of the list is on one line where the window has room for it, as the choices of a field that
 * is as wide as its widest choice. The languages' names fit in 260 pixels; the first entry, "Use browser setting"
 * with the name of a language, is longer than that in some languages, and the box grows with it rather than take
 * another line for it. In a window narrower than that, the entry takes another line.
 */
.language-popup {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline-end: 0;
  z-index: 1000;
  box-sizing: border-box;
  width: max-content;
  min-width: 260px;
  max-width: calc(100vw - 20px);
  padding: 8px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
  color: #212529;
  font-size: 15px;
  line-height: 20px;
}


/* The search field and the magnifying glass in it. */
.language-search-field {
  position: relative;
  margin-bottom: 8px;
}

/*
 * A magnifying glass at the end of the search field, where a line ends, as search fields usually have, and as the
 * application's field and Photo Data Viewer's have it: 20 pixels, in the grey of the placeholder, 8 pixels from the
 * field's end. It is drawn over the field, whose text and clear button end before it, and a click on it goes to the
 * field under it.
 */
.language-search-icon {
  position: absolute;
  top: 6px;
  inset-inline-end: 8px;
  width: 20px;
  height: 20px;
  fill: #6c757d;
  pointer-events: none;
}

.language-search {
  display: block;
  box-sizing: border-box;
  width: 100%;
  height: 32px;
  margin: 0;
  padding: 6px 10px;
  padding-inline-end: 36px;
  border: 1px solid #ced4da;
  border-radius: 4px;
  background: #fff;
  color: inherit;
  font: inherit;
  appearance: none; /* Without the rounded corners that a browser gives a search field. */
}

.language-search::placeholder {
  color: #6c757d;
  opacity: 1;
}

.language-search:focus-visible {
  outline: 2px solid #0d6efd;
  outline-offset: -1px;
}

/*
 * The languages, which scroll.
 * TL;DR: Seven entries and a half, and a scrollbar that stays in view, so that the list is seen to go on.
 * Details: macOS and phones hide a scrollbar until the list is scrolled, so a box that ends between two entries would
 * look like the whole list. Half an entry at the box's edge shows in any browser that there are more. The scrollbar
 * styled here is drawn at all times, in the browsers that take these styles (Chrome, Edge and Safari).
 */
.language-options {
  position: relative; /* The entries' offsetTop is measured from here. */
  box-sizing: content-box; /* Seven entries and a half inside the border, on the page with Bootstrap as on the one without. */
  max-height: calc(7.5 * 32px);
  margin: 0;
  padding: 0;
  overflow-y: auto;
  /* The scrollbar's room is kept, so that the box is as wide as the widest entry beside it needs, and stays so
     while the search lists fewer entries. */
  scrollbar-gutter: stable;
  border: 1px solid #ced4da;
  border-radius: 4px;
  list-style: none;
}

.language-options::-webkit-scrollbar {
  width: 12px;
}

.language-options::-webkit-scrollbar-track {
  background: #f1f3f5;
}

/* The border leaves the thumb narrower than its track, and rounded at both ends. */
.language-options::-webkit-scrollbar-thumb {
  border: 2px solid #f1f3f5;
  border-radius: 6px;
  background: #8a8a8a;
}

.language-options::-webkit-scrollbar-thumb:hover {
  background: #6e6e6e;
}

.language-options[hidden] {
  display: none;
}

.language-option {
  display: flex;
  align-items: center;
  gap: 8px;
  box-sizing: border-box;
  min-height: 32px;
  padding: 6px 10px;
  cursor: pointer;
  user-select: none;
}

.language-option[hidden] {
  display: none;
}

.language-option:hover {
  background: #f1f3f5;
}

.language-option[aria-selected="true"] {
  background: #0d6efd;
  color: #fff;
}

/* The keyboard's focus, which the arrow keys move; Enter or Space chooses the entry under it. */
.language-option:focus-visible {
  outline: 2px solid #0d6efd;
  outline-offset: -2px;
}

.language-option[aria-selected="true"]:focus-visible {
  outline-color: #fff;
  outline-offset: -4px;
}

/* Said in the place of the list when the search finds no language. Without a text, it takes no room. */
.language-none {
  padding: 6px 10px;
  color: #6c757d;
}

.language-none:empty {
  padding: 0;
}
