/* Help (SV2-30a): the shell's dialog, made one column whose title stays at
   the top and whose buttons (Close help among them) stay at the foot, with
   the body scrolling between, on a phone upright or on its side. Loaded by
   ui/help/index.js when index.html has no link[data-sheet="help"]. */

.dialog.help {
  width: min(760px, calc(100vw - var(--s-5)));
  max-height: calc(100vh - var(--s-5));
  max-height: calc(100dvh - var(--s-5));
  padding: 0;
  overflow: hidden;
}

.dialog.help[open] {
  display: flex;
  flex-direction: column;
}

.dialog.help > .dialog__title {
  flex: none;
  padding: var(--s-3) var(--s-5);
  border-bottom: var(--border);
  overflow-wrap: anywhere;
}

.dialog.help > .dialog__body {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
}

.dialog.help > .dialog__buttons {
  flex: none;
  margin: 0;
  padding: var(--s-3) var(--s-5);
  border-top: var(--border);
}

.help__scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: var(--s-4) var(--s-5) var(--s-5);
  display: grid;
  gap: var(--s-4);
  align-content: start;
}

.help__scroll p,
.help__scroll h3,
.help__scroll h4 {
  margin: 0;
}

.help__scroll:focus-visible {
  outline-offset: -2px;
}

.help__lead {
  font-size: var(--t-md);
}

.help__jump ul {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-1) var(--s-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.help__jump .btn {
  justify-content: flex-start;
  padding-inline: var(--s-2);
  text-align: left;
}

.help__part {
  display: grid;
  gap: var(--s-3);
  padding-top: var(--s-4);
  border-top: var(--border);
}

.help__title {
  font-size: var(--t-lg);
  line-height: var(--lh-lg);
  font-weight: var(--w-semibold);
  scroll-margin-top: var(--s-3);
}

.help__name {
  font-size: var(--t-md);
  font-weight: var(--w-semibold);
}

.help__here {
  color: var(--ink-2);
  font-weight: var(--w-medium);
}

.help__sections,
.help__device ul {
  display: grid;
  gap: var(--s-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.help__device ul {
  gap: var(--s-2);
  padding-left: var(--s-5);
  list-style: disc;
}

.help__section,
.help__device,
.help__numbers {
  display: grid;
  gap: var(--s-2);
}

.help__section[data-here="true"] {
  padding: var(--s-3);
  border-radius: var(--r-1);
  background: var(--accent-soft);
}

.help__more {
  color: var(--ink-2);
}

.help kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 var(--s-1);
  border: var(--border-width) solid var(--line-strong);
  border-radius: var(--r-1);
  font: inherit;
  font-variant-numeric: tabular-nums;
  text-align: center;
  white-space: nowrap;
}

.help__table {
  border: var(--border);
  border-radius: var(--r-1);
  overflow-x: auto;
}

.help__groups,
.help__words {
  display: grid;
  grid-template-columns: minmax(7rem, max-content) 1fr;
  gap: var(--s-2) var(--s-4);
  margin: 0;
}

.help__groups dt,
.help__words dt {
  font-weight: var(--w-semibold);
}

.help__groups dd,
.help__words dd {
  margin: 0;
}

@media (max-width: 640px) {
  .dialog.help > .dialog__title,
  .dialog.help > .dialog__buttons {
    padding: var(--s-2) var(--s-4);
  }

  .help__scroll {
    padding: var(--s-3) var(--s-4) var(--s-4);
  }

  .help__search {
    padding: var(--s-2) var(--s-4);
  }

  .help__back {
    padding-inline: var(--s-2);
  }

  /* a shortcut is its keys and what it does on one line, where it works
     under them, so nothing scrolls sideways at 390 px */
  .help__table tr {
    display: grid;
    grid-template-columns: minmax(5.5rem, 9rem) 1fr;
    border-top: var(--border);
  }

  /* a long chord (Shift+Arrows, Shift+Page Up, …) wraps inside its column
     instead of running past the table's edge */
  .help__table kbd {
    white-space: normal;
    overflow-wrap: anywhere;
    text-align: left;
  }

  .help__table td {
    min-width: 0;
  }

  .help__table thead tr {
    border-top: 0;
  }

  .help__table td {
    border-top: 0;
  }

  .help__table td:nth-child(3),
  .help__table th:nth-child(3) {
    grid-column: 2;
    padding-top: 0;
    color: var(--ink-2);
  }

  .help__groups,
  .help__words {
    grid-template-columns: 1fr;
    gap: 0 0;
  }

  .help__groups dd,
  .help__words dd {
    margin-bottom: var(--s-3);
  }
}

/* ---------- Search help (DESIGN 16.10, 16.12 item 7) ---------- */

.help__search {
  flex: none;
  display: grid;
  gap: var(--s-1);
  padding: var(--s-3) var(--s-5) var(--s-2);
  border-bottom: var(--border);
  background: var(--card);
}

.help__label {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0 var(--s-3);
}

.help__label label {
  font-weight: var(--w-semibold);
}

.help__hint {
  color: var(--ink-2);
  font-size: var(--t-sm);
}

.help__row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.help__field {
  flex: 1 1 12rem;
  min-width: 0;
  height: 44px;
  font-size: var(--t-md);
}

.help__back,
.help__clear {
  flex: none;
  min-height: 44px;
}

.help__clear {
  min-width: 44px;
  padding-inline: 0;
}

.help__back[hidden],
.help__clear[hidden] {
  display: none;
}

.help__count,
.help__none {
  color: var(--ink-2);
}

.help__results {
  display: grid;
  gap: var(--s-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.help__result {
  display: grid;
  gap: var(--s-1);
  width: 100%;
  min-height: 44px;
  padding: var(--s-2) var(--s-3);
  border: var(--border);
  border-radius: var(--r-1);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  text-align: left;
  scroll-margin: var(--s-3);
}

.help__result:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.help__result-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0 var(--s-3);
  align-items: baseline;
}

.help__result-title {
  font-size: var(--t-md);
  font-weight: var(--w-semibold);
}

.help__result-section {
  color: var(--note);
  font-size: var(--t-sm);
}

/* the paragraph's first words, when other results share the title */
.help__result-lead {
  color: var(--note);
  font-size: var(--t-sm);
  font-style: italic;
  overflow-wrap: anywhere;
}

.help__result-text {
  overflow-wrap: anywhere;
}

.help mark {
  padding: 0 1px;
  border-radius: 2px;
  background: var(--mark-bg);
  color: var(--mark-ink);
}

/* where a result opened */
.help [data-landed] {
  border-radius: var(--r-1);
  background: var(--accent-soft);
  box-shadow: -4px 0 0 var(--accent-soft);
}

/* A phone on its side: the head and foot take as little height as they can. */
@media (max-height: 500px) {
  /* Under 500 px of height only the search field stays pinned: the dialog
     itself scrolls, so the title goes up with the text, the field sticks to
     the top and Close help sticks to the foot. */
  .dialog.help {
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .dialog.help[open] {
    display: block;
  }

  .dialog.help > .dialog__title {
    padding-block: var(--s-2);
    font-size: var(--t-md);
  }

  .dialog.help > .dialog__body {
    display: block;
  }

  .help__search {
    position: sticky;
    top: 0;
    z-index: 1;
    padding-block: var(--s-1);
  }

  .help__hint {
    display: none;
  }

  .help__scroll {
    overflow: visible;
  }

  .dialog.help > .dialog__buttons {
    position: sticky;
    bottom: 0;
    z-index: 1;
    padding-block: var(--s-2);
    background: var(--card);
  }
}

@media (pointer: coarse) {
  .help .table__sort {
    min-height: 44px;
  }
}
