*, *::before, *::after {
  box-sizing: border-box;
}

body {
  background-color: white;
  color: black;
  font-family: system-ui, sans-serif;
  margin: 0;
}
form {
  margin: 0;
  padding: 0;
}
h1 {
  font-size: 1.5rem;
  font-weight: bold;
}
h2 {
  font-size: 1.125rem;
  font-weight: bold;
}

.action {
  background-color: transparent;
  border: none;
  color: crimson;
  cursor: pointer;
  font-size: inherit;
  padding: 0 0.25rem;
}
.caption {
  font-size: 0.75rem;
  font-weight: bold;
}
.group {
  display: contents;
}
.h {
  align-items: baseline;
  display: flex;
  flex-flow: row nowrap;
  gap: 1rem;
}
.mono {
  --mono-font-width: 0.6rem;
  font-family: ui-monospace, Menlo, Monaco, "Courier New", monospace;
}
.stretch {
  flex: 1 1 auto;
}
.text {
  background-color: transparent;
  border: none;
  cursor: pointer;
  font: inherit;
}
.toggle [type="checkbox"] {
  appearance: none;
  position: absolute;
  pointer-events: none;
}
.toggle:has(:focus),
.toggle:focus {
  outline: solid;
}

#app {
  --word-length: 5;
  max-width: 100vw;
  min-height: 100svh;
  overflow-x: auto;
}

#header {
  align-items: center;
  background-color: #eee;
  border-bottom: solid 1px #aaa;
  padding: 0 1rem;
}

#word-length {
  color: cornflowerblue;
}

#dialog-toggle {
  color: #555;
  font-size: 2rem;
  line-height: 0.7;
  padding: 0.5rem;
  text-align: center;
}
#dialog-toggle:hover {
  color: inherit;
}

#main {
  align-items: start;
  display: flex;
  flex-flow: row wrap;
  gap: 1rem 3rem;
  padding: 1rem;
}

#result-count {
  text-align: right;
  width: 100%;
}

#histogram {
  --bin-full-size: 6rem;
  height: 7rem;
  width: 100%;
}
#histogram .bin:hover {
  border-top-color: hsl(from var(--bin-color) h s calc(l + 10) / 0.8);
  color: var(--bin-color);
}
.histogram {
  --bin-color: cornflowerblue;
  --bin-full-size: 6rem;
  --max: 1;
  --total: 1;
  align-items: end;
  gap: 1px;
}
.histogram .bin {
  --count: 0;
  border-top: 1px solid var(--bin-color);
  border-top-width: calc(var(--bin-full-size) * var(--count) / var(--max));
  cursor: pointer;
  flex: 1 1 auto;
  text-align: center;
  text-decoration: none;
  text-transform: uppercase;
  transition: border-top-width 0.3s ease-out;
}

#search {
  display: grid;
  gap: 0.25rem;
  grid-template-columns: repeat(var(--word-length), 2.25rem);
}
#search .caption {
  margin-top: 0.375rem;
}
#search .row {
  grid-column: 1 / -1;
}
#search [type="text"] {
  background-color: #eee;
  border: 2px solid #aaa;
  border-radius: 0.375rem;
  cursor: pointer;
  font-size: 1.125rem;
  height: 2.25rem;
  padding-left: 0.375rem;
  padding-right: 0.375rem;
  text-transform: uppercase;
}
#search [type="text"]:hover {
  filter: brightness(95%);
}

#matches input {
  text-align: center;
}
#matches input:not(:placeholder-shown) {
  background-color: limegreen;
}

#contains,
#not-contains {
  letter-spacing: 0.25rem;
}

#not-matches .toggle {
  background-color: #eee;
  border-radius: 0.375rem;
  color: silver;
  cursor: pointer;
  padding: 0.125rem;
  text-align: center;
  text-transform: uppercase;
}
#not-matches .toggle:has(:checked) {
  background-color: gold;
  color: black;
}
#not-matches .toggle:hover {
  filter: brightness(75%);
}

@keyframes spin {
  from {rotate: 270deg}
  to {rotate: -90deg}
}
#sort-order {
  transition: rotate 0.2s ease-out;
}
#sort-order:has(:checked),
#sort-order:active {
  rotate: -90deg;
}
.busy #sort-order {
  animation: spin 1.6s linear infinite;
  animation-delay: 0.15s;
}

#output {
  /* Column width = word length * (character width + letter spacing). */
  --cw: calc(var(--word-length) * (var(--mono-font-width) + 0.25rem));
  column-gap: 1rem;
  columns: var(--cw) auto;
  letter-spacing: 0.25rem;
  line-height: 1.5;
  list-style-type: none;
  margin: 0;
  /* Minimum width = 2 columns + 1 gap. */
  min-width: calc(2 * var(--cw) + 1rem);
  padding: 0;
  text-transform: uppercase;
}

#dialog {
  align-items: stretch;
  flex-flow: column nowrap;
  gap: .5rem;
  width: 80vw;
}
#dialog:open {
  display: flex;
}
#dialog button {
  align-self: end;
  padding: .25rem 1rem;
}