:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #5f5e58;
  --border: #dedcd4;
  --accent: #1f5f8b;
  --accent-soft: #e5eef5;
  --rank: #8a4b08;
  --rank-soft: #fbeedd;
  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --surface: #201f1d;
    --text: #ecebe6;
    --muted: #a8a69e;
    --border: #3a3935;
    --accent: #7db7e0;
    --accent-soft: #1d3140;
    --rank: #f0b46a;
    --rank-soft: #3a2a17;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0 auto;
  max-width: 72rem;
  padding: 0 16px 2rem;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a {
  color: var(--accent);
}

header {
  /* Room for the GitHub corner. */
  padding-right: 56px;
}

header h1 {
  margin: 1.5rem 0 0.25rem;
  font-size: 1.6rem;
  line-height: 1.2;
}

header p {
  margin: 0.25rem 0 1rem;
  color: var(--muted);
  max-width: 48rem;
}

/* A triangle in the page's top right corner, holding the GitHub mark, that links to the repository. */
.github-corner {
  position: absolute;
  top: 0;
  right: 0;
  width: 72px;
  height: 72px;
  background: var(--text);
  color: var(--bg);
  clip-path: polygon(0 0, 100% 0, 100% 100%);
}

.github-corner:hover,
.github-corner:focus-visible {
  background: var(--accent);
}

.github-corner svg {
  position: absolute;
  top: 9px;
  right: 9px;
}

/* The search form and the summary of its results, which stay at the top of the window as the results scroll. */
#bar {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0 -16px;
  padding: 0.75rem 16px 0.25rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

#search {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#search input,
#search select {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
}

#search input {
  flex: 1 1 18rem;
  min-width: 0;
}

#search input:focus,
#search select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#search :disabled {
  opacity: 0.6;
}

#loading {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1.5rem 0;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

#loading[hidden] {
  display: none;
}

#loading.failed .spinner {
  display: none;
}

.loading-text {
  flex: 1;
  min-width: 0;
}

.loading-text p {
  margin: 0 0 0.5rem;
}

#loading progress {
  width: 100%;
  height: 0.5rem;
  accent-color: var(--accent);
}

.spinner {
  flex: none;
  width: 2rem;
  height: 2rem;
  border: 3px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 3s;
  }
}

#summary {
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

#panes {
  display: grid;
  gap: 1rem;
  margin-top: 0.75rem;
}

@media (min-width: 56rem) {
  #panes.has-detail {
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
    align-items: start;
  }

  #panes.has-detail #detail {
    order: 0;
    position: sticky;
    top: calc(var(--bar-height, 6rem) + 0.75rem);
    max-height: calc(100vh - var(--bar-height, 6rem) - 1.5rem);
    overflow-y: auto;
  }
}

#results {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

#results button {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  cursor: pointer;
}

#results button:hover,
#results button[aria-current="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.result-title {
  display: block;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.meta {
  color: var(--muted);
  font-size: 0.875rem;
}

.badge {
  display: inline-block;
  padding: 0 0.4rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
  vertical-align: 0.1em;
}

.badge.rank {
  background: var(--rank-soft);
  color: var(--rank);
}

/* In one column the detail comes before the results, and scrolls into view below the search bar. */
#detail {
  order: -1;
  scroll-margin-top: calc(var(--bar-height, 6rem) + 0.75rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

#detail h2 {
  margin: 0 0 0.25rem;
  font-size: 1.25rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

#detail section {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

#detail h3 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
}

#detail dl {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.15rem 0.75rem;
  margin: 0;
}

#detail dt {
  color: var(--muted);
}

#detail dd {
  margin: 0;
  overflow-wrap: anywhere;
}

#detail ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.close {
  float: right;
  font: inherit;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 0.25rem;
}
