/* The stylesheet of every page gherkin-glass writes. Colour and emphasis never
   carry meaning alone: every state is also said in words or in the markup. */

/* The colours are the themes' tokens, --ghg-*, which every page defines in
   its head, since the accent colours are set for each site. */

/* The content column stays in place whether a page scrolls or not. */
html {
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  background: var(--ghg-background);
  color: var(--ghg-text);
  font-family: system-ui, sans-serif;
  line-height: 1.5;
  /* A long word, such as a file's name or an address, breaks where it must,
     so that the page fits a narrow window. */
  overflow-wrap: anywhere;
}

main {
  max-width: 60rem;
  margin: 0 auto;
  padding: 0 1rem 1rem;
}

main > :first-child {
  margin-top: 1rem;
}

/* A link is underlined, so that colour is not all that tells it apart. */
a {
  color: var(--ghg-accent);
  text-decoration: underline;
}

:focus-visible {
  outline: 3px solid var(--ghg-accent);
  outline-offset: 2px;
}

h1, h2, h3, h4, h5 {
  line-height: 1.25;
  margin: 1.5rem 0 0.5rem;
}

/* The disclosure button reads as its heading, with a marker that shows its state. */
.ghg-toggle {
  all: inherit;
  margin: 0;
  cursor: pointer;
}

.ghg-toggle::before {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  margin-right: 0.5em;
  vertical-align: middle;
  border-style: solid;
  border-width: 0.4em 0 0.4em 0.6em;
  border-color: transparent transparent transparent currentColor;
  transition: transform 0.1s;
}

.ghg-toggle[aria-expanded="true"]::before {
  transform: rotate(90deg);
}

/* After `all: inherit`, which would take the heading's outline. */
.ghg-toggle:focus-visible {
  outline: 3px solid var(--ghg-accent);
  outline-offset: 2px;
}

/* Forced colours would make every border of the marker opaque, a box in either state. */
@media (forced-colors: active) {
  .ghg-toggle::before {
    forced-color-adjust: none;
    border-color: transparent transparent transparent ButtonText;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ghg-toggle::before {
    transition: none;
  }
}

.ghg-block {
  border-left: 1px solid var(--ghg-border);
  padding-left: 1rem;
}

.ghg-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  list-style: none;
  margin: 0.25rem 0;
  padding: 0;
  color: var(--ghg-muted);
}

.ghg-description p {
  margin: 0.5rem 0;
}

.ghg-steps {
  padding-left: 1.5rem;
}

/* Highlighting only colours text that already says what it is. */
.ghg-keyword {
  font-weight: bold;
  color: var(--ghg-keyword);
}

.ghg-parameter {
  color: var(--ghg-parameter);
}

.ghg-number {
  color: var(--ghg-number);
}

.ghg-placeholder {
  color: var(--ghg-placeholder);
}

/* A feature file's tables and a front page's alike. */
table {
  border-collapse: collapse;
  margin: 0.5rem 0;
}

th,
td {
  border: 1px solid var(--ghg-border);
  padding: 0.25rem 0.5rem;
  text-align: left;
  /* Not anywhere, which would let the table's layout break a word that fits
     whole: a cell breaks a word only when the word is wider than the window. */
  overflow-wrap: break-word;
}

/* On a narrower window, a code word in a cell, such as a configuration key,
   breaks so that its column leaves room for the others, and on a phone every
   word of a cell does. */
@media not all and (min-width: 48em) {
  th code,
  td code {
    overflow-wrap: anywhere;
  }
}

@media not all and (min-width: 24em) {
  th,
  td {
    overflow-wrap: anywhere;
  }
}

.ghg-doc-string {
  margin: 0.5rem 0;
}

/* An outline's examples are list items, not headings: each reads as a block's
   heading through its button, and keeps its bullet, which a screen reader
   names, so that the next examples block is not taken for one of the runs
   of the block before it. */
.ghg-examples-list {
  margin: 0.5rem 0;
  padding-left: 1.25rem;
}

.ghg-examples-list > li {
  margin: 0.5rem 0;
}

/* The button inherits the item's rule and indent, which the item already draws. */
.ghg-examples-list > li > .ghg-toggle {
  display: block;
  border-left: 0;
  padding-left: 0;
  font-weight: bold;
}

/* The keyword the file writes, said once at the top of the block's content,
   in a note, smaller and in the muted colour, which keeps the themes'
   contrast; part of it is a button, drawn as a link, that opens the page's
   dialog about it. */
.ghg-keyword-note {
  font-size: 0.9rem;
  color: var(--ghg-muted);
}

/* A button lays out as one box, which starts a new line when it does not
   fit; its text keeps the sentence's alignment rather than a button's. */
.ghg-note-opener {
  text-align: inherit;
  font: inherit;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ghg-accent);
  text-decoration: underline;
  cursor: pointer;
}

/* A block with nothing to show keeps a block's rule, and its button, which
   opens nothing, looks disabled: no arrow, its text where the others' text
   starts, in normal weight rather than bold, so not by colour alone, and
   dimmed with the muted text colour, which keeps the themes' contrast. */
.ghg-examples-list > li:not(.ghg-block) {
  border-left: 1px solid var(--ghg-border);
  padding-left: 1rem;
}

.ghg-examples-list > li > .ghg-toggle[aria-disabled="true"] {
  color: var(--ghg-muted);
  font-weight: normal;
  cursor: not-allowed;
}

.ghg-toggle[aria-disabled="true"]::before {
  visibility: hidden;
}

pre {
  background: var(--ghg-surface);
  padding: 0.5rem;
  overflow-x: auto;
}

figcaption {
  color: var(--ghg-muted);
  font-family: monospace;
}

.ghg-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 1rem 0;
}

.ghg-controls button,
.ghg-from-disk button,
.ghg-dialog button {
  font: inherit;
  padding: 0.25rem 0.75rem;
  background: var(--ghg-surface);
  color: var(--ghg-text);
  border: 1px solid var(--ghg-border);
  border-radius: 0.25rem;
  cursor: pointer;
}

/* The breadcrumb's separators are drawn, not written, so that a screen reader
   says only the links, as the WAI-ARIA breadcrumb example does. */
.ghg-breadcrumb {
  max-width: 60rem;
  margin: 0 auto;
  padding: 1rem 1rem 0;
}

.ghg-breadcrumb ol {
  display: flex;
  flex-wrap: wrap;
  list-style: none;
  margin: 0;
  padding: 0;
}

.ghg-breadcrumb li:not(:last-child)::after {
  content: "";
  display: inline-block;
  height: 0.8em;
  margin: 0 0.5em;
  border-right: 0.1em solid currentColor;
  transform: rotate(15deg);
}

.ghg-breadcrumb [aria-current="page"] {
  font-weight: bold;
}

.ghg-features > li {
  margin: 0.25rem 0;
}

.ghg-feature > .ghg-toggle,
.ghg-count {
  display: inline;
  margin-left: 0.5em;
}

.ghg-count {
  color: var(--ghg-muted);
}

/* The skip link is out of sight until it has the focus. */
.ghg-skip {
  position: absolute;
  left: 0.5rem;
  top: -100rem;
  z-index: 1;
  padding: 0.5rem 1rem;
  background: var(--ghg-background);
  color: var(--ghg-accent);
}

.ghg-skip:focus {
  top: 0.5rem;
}

.ghg-from-disk,
.ghg-dialog {
  max-width: 36rem;
  padding: 1rem 1.5rem;
  border: 2px solid var(--ghg-border);
  background: var(--ghg-background);
  color: var(--ghg-text);
}

.ghg-from-disk::backdrop,
.ghg-dialog::backdrop {
  background: rgb(0 0 0 / 50%);
}

.ghg-from-disk-title {
  font-weight: bold;
}

.ghg-dialog-title {
  margin-top: 0;
  font-size: 1.25rem;
}

/* The reader's options, a bar across the top of the page. */
.ghg-options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.5rem;
  padding: 0.5rem 1rem;
  background: var(--ghg-surface);
  border-bottom: 1px solid var(--ghg-border);
}

.ghg-show-tree {
  accent-color: var(--ghg-accent);
}

/* The legend reads before its radio buttons, on their line. */
.ghg-theme {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 1rem;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: none;
}

.ghg-theme legend {
  float: left;
  padding: 0;
  margin-right: 0.25rem;
  font-weight: bold;
}

.ghg-tree-button {
  display: none;
  font: inherit;
  padding: 0.25rem 0.75rem;
  background: var(--ghg-background);
  color: var(--ghg-text);
  border: 1px solid var(--ghg-border);
  border-radius: 0.25rem;
  cursor: pointer;
}

.ghg-tree-button::before {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  margin-right: 0.5em;
  vertical-align: middle;
  border-style: solid;
  border-width: 0.4em 0 0.4em 0.6em;
  border-color: transparent transparent transparent currentColor;
  transition: transform 0.1s;
}

.ghg-tree-button[aria-expanded="true"]::before {
  transform: rotate(90deg);
}

@media (forced-colors: active) {
  .ghg-tree-button::before {
    forced-color-adjust: none;
    border-color: transparent transparent transparent ButtonText;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ghg-tree-button::before {
    transition: none;
  }
}

/* The search form and its results take the column of the breadcrumb and the content. */
.ghg-search {
  max-width: 60rem;
  margin: 0 auto;
  padding: 0.75rem 1rem 0;
}

.ghg-search-field {
  font: inherit;
  margin-left: 0.25rem;
  width: 20rem;
  max-width: 100%;
  box-sizing: border-box;
}

/* On the page of search results, the search box is in the content's column, under its heading. */
.ghg-search-heading + .ghg-search {
  max-width: none;
  margin: 0;
  padding: 0;
}

/* No margin while it is empty, until the reader searches, so that it takes no room. */
.ghg-search-status {
  margin: 0;
}

.ghg-search-status:not(:empty) {
  margin-top: 0.5rem;
}

/* The page of search results' own status, between its search box and its results. */
.ghg-results-status {
  margin: 1rem 0 0;
}

/* The link to the page of search results, on a line of its own under the field. */
.ghg-search-all:not([hidden]) {
  display: block;
  width: fit-content;
  margin-top: 0.5rem;
}

.ghg-search-results {
  margin: 0.5rem 0 0;
  padding: 0.25rem;
  list-style: none;
  background: var(--ghg-surface);
  border: 1px solid var(--ghg-border);
}

/* A line between results keeps those that wrap apart on a narrow window. */
.ghg-search-results li {
  padding: 0.25rem 0.5rem;
  cursor: pointer;
}

.ghg-search-results li:not(:last-child) {
  border-bottom: 1px solid var(--ghg-border);
}

/* The chosen result has its colours swapped and a ring inside its edge, so that colour is not
   all that tells it apart. The ring and the line under it take its text's colour, which stands
   out from its background as its text does, and the ring, inside the accent, does not look like
   the ring of the focus. */
.ghg-search-results li[aria-selected="true"] {
  color: var(--ghg-background);
  background: var(--ghg-accent);
  border-color: var(--ghg-background);
  outline: 2px solid var(--ghg-background);
  outline-offset: -0.25rem;
}

/* On the page of search results, a matched word is bold on a shaded background, not only
   coloured, and not underlined, so that it does not read as a link of its own. */
.ghg-search-groups mark {
  color: inherit;
  background: var(--ghg-surface);
  font-weight: bold;
}

.ghg-search-group > li {
  margin: 0.75rem 0;
}

.ghg-search-group p {
  margin: 0.25rem 0;
}

/* On a tag's page, a feature's heading shows its file's path smaller and muted;
   the words read the same. */
.ghg-tag-path {
  font-size: 0.8em;
  font-weight: normal;
  color: var(--ghg-muted);
}

.ghg-theme input {
  accent-color: var(--ghg-accent);
}

/* The folder tree beside the content, or above it on a window narrower than
   48em, the width script/src/policies/tree_state.ts's NARROW names too. */
.ghg-layout {
  display: flex;
  align-items: flex-start;
}

.ghg-tree {
  flex: 0 0 18rem;
  box-sizing: border-box;
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow: auto;
  padding: 1rem;
  border-right: 1px solid var(--ghg-border);
}

.ghg-tree[hidden] {
  display: none;
}

.ghg-page {
  flex: 1 1 auto;
  min-width: 0;
}

/* A narrow window shows the button in place of the checkbox. */
@media not all and (min-width: 48em) {
  /* Two classes, to win over .ghg-option's display below. */
  .ghg-option.ghg-tree-choice {
    display: none;
  }

  .ghg-tree-button {
    display: inline-block;
  }

  .ghg-search label {
    display: block;
  }

  .ghg-search-field {
    display: block;
    width: 100%;
    margin: 0.5rem 0 0;
  }

  .ghg-layout {
    display: block;
  }

  .ghg-tree {
    position: static;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--ghg-border);
  }
}

.ghg-treeview,
.ghg-treeview ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.ghg-treeview ul {
  padding-left: 1rem;
}

/* Every item's text starts at the same place, with a marker or without, and
   its wrapped lines line up with its first. */
.ghg-treeview [role="treeitem"] {
  display: block;
  padding: 0.125rem 0.25rem 0.125rem 1.75rem;
  text-decoration: none;
}

.ghg-treeview [role="treeitem"]:hover {
  text-decoration: underline;
}

.ghg-treeview [aria-current="page"] {
  font-weight: bold;
}

.ghg-marker {
  display: inline-block;
  /* At least 24 by 24 pixels, as WCAG 2.2's target size asks. */
  width: 1.5rem;
  min-height: 1.5rem;
  margin-left: -1.5rem;
  text-align: center;
  cursor: pointer;
}

.ghg-marker::before {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  vertical-align: middle;
  border-style: solid;
  border-width: 0.4em 0 0.4em 0.6em;
  border-color: transparent transparent transparent currentColor;
  transition: transform 0.1s;
}

[aria-expanded="true"] > .ghg-marker::before {
  transform: rotate(90deg);
}

@media (forced-colors: active) {
  .ghg-marker::before {
    forced-color-adjust: none;
    border-color: transparent transparent transparent LinkText;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ghg-marker::before {
    transition: none;
  }
}

.ghg-option {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

/* The backgrounds inside a scenario, set apart by a tint; their headings say where the steps come from. */
.ghg-background-in-scenario {
  margin: 0.5rem 0;
  padding: 0.25rem 0.75rem;
  background: var(--ghg-surface);
}

.ghg-background-in-scenario > :is(h3, h4) {
  margin: 0.25rem 0;
}

.ghg-background-in-scenario .ghg-steps {
  margin: 0.25rem 0;
}

/* A doc string keeps its box inside the tint. */
.ghg-background-in-scenario pre {
  background: var(--ghg-background);
}

/* The heading of a scenario's own steps, after its backgrounds, close to the steps it heads. */
.ghg-steps-heading {
  margin: 0.75rem 0 0.25rem;
}

.ghg-steps-heading + .ghg-steps {
  margin-top: 0.25rem;
}

/* The footer closes the content's column, set apart by a rule above its words. */
.ghg-footer {
  max-width: 60rem;
  margin: 2rem auto 0;
  padding: 0 1rem 1.5rem;
  color: var(--ghg-muted);
  font-size: 0.9rem;
}

.ghg-footer p {
  margin: 0;
  padding-top: 0.75rem;
  border-top: 1px solid var(--ghg-border);
}
