:root {
  --primary: #4352c5;
  --primary-dark: #242a55;
  --text: #364153;
  /* On --bg, --bg-soft and --badge-bg: all at least 4.5:1 (WCAG AA). */
  --text-light: #596a84;
  --bg: #ffffff;
  --bg-soft: #f3f4f6;
  --mark: #fef3c7;
  --link: #4352c5;
  --border: #e5e7eb;
  --badge-bg: #eef0fb;
  --ok-bg: #dcfce7;
  --ok-text: #166534;
  --warn-bg: #fef3c7;
  --warn-text: #92400e;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 12px rgba(16, 24, 40, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #0a187f;
    --primary-dark: #00041c;
    --text: #e5e7eb;
    --text-light: #9ca3af;
    --bg: #000633;
    --bg-soft: #0b1152;
    --mark: #6b5b00;
    --link: #9fb0ff;
    --border: #1d2566;
    --badge-bg: #141c66;
    --ok-bg: #0f3d24;
    --ok-text: #86efac;
    --warn-bg: #4a3200;
    --warn-text: #fcd34d;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family:
    Inter,
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
}

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

.wrap {
  max-width: 1125px;
  margin: 0 auto;
  padding: 0 16px;
}

.narrow {
  max-width: 860px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* Header */
.top {
  background: var(--primary);
  color: #fff;
}

.top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 12px;
  padding-bottom: 12px;
}

.brand {
  color: #fff;
  font-weight: 700;
  font-size: 1.25rem;
  text-decoration: none;
}

.by {
  display: flex;
  align-items: center;
  gap: 10px;
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.85rem;
  text-decoration: none;
}

.by img {
  display: block;
}

/* Hero and search */
.hero {
  background: var(--primary);
  color: #fff;
  padding: 48px 0 40px;
  text-align: center;
}

.hero h1 {
  margin: 0 0 8px;
  font-size: clamp(2rem, 5vw, 3rem);
}

.lead {
  margin: 0 0 28px;
  font-size: 1.1rem;
  color: rgba(255, 255, 255, 0.9);
}

.search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg);
  border-radius: 16px;
  padding: 8px 8px 8px 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.search-icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  fill: none;
  stroke: var(--text-light);
  stroke-width: 2;
  stroke-linecap: round;
}

.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
  padding: 12px 8px;
  outline: none;
}

.search input::-webkit-search-cancel-button {
  display: none;
}

.search:focus-within {
  box-shadow:
    0 0 0 3px rgba(255, 255, 255, 0.45),
    0 10px 30px rgba(0, 0, 0, 0.2);
}

.clear {
  border: 0;
  background: transparent;
  color: var(--text-light);
  font: inherit;
  font-size: 0.9rem;
  padding: 8px 12px;
  cursor: pointer;
}

/* A thin bar along the bottom of the box while a search runs. */
.progress {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 30%;
  background: var(--primary);
  opacity: 0;
}

.search.loading .progress {
  opacity: 1;
  animation: progress 1s ease-in-out infinite;
}

@keyframes progress {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(340%);
  }
}

.examples {
  margin: 16px 0 0;
  font-size: 0.9rem;
  /* 4.5:1 against --primary (WCAG AA); 0.75 was 4.4. */
  color: rgba(255, 255, 255, 0.82);
}

.examples a {
  display: inline-block;
  margin: 4px 0 0 6px;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  text-decoration: none;
}

.examples a:hover {
  background: rgba(255, 255, 255, 0.24);
}

/* Results area */
/* Some height from the start, so results appearing and changing as the visitor
   types do not push the rest of the page around. */
.area {
  background: var(--bg-soft);
  padding: 24px 0 40px;
  min-height: 260px;
}

.intro {
  padding: 24px 0;
  text-align: center;
  color: var(--text-light);
}

.intro p {
  max-width: 56ch;
  margin: 0 auto;
}

.area.loading .results,
.area.loading .chips,
.area.loading .notice {
  opacity: 0.5;
  transition: opacity 0.2s 0.15s;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  min-height: 2rem;
}

.count {
  margin: 0;
  font-weight: 600;
  color: var(--text);
}

.count.error {
  color: #b42318;
}

.sort {
  font-size: 0.9rem;
  color: var(--text-light);
}

.sort select {
  margin-left: 6px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
}

.notice {
  margin: 4px 0 0;
  font-size: 0.9rem;
  color: var(--text-light);
}

.notice strong {
  color: var(--text);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 0;
}

.chip {
  font: inherit;
  font-size: 0.85rem;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

.chip:hover {
  border-color: var(--link);
}

.chip[aria-pressed="true"] {
  background: var(--link);
  border-color: var(--link);
  color: var(--bg);
}

/* The results: one list with dividers, the text on the left and the code
   and what to do with it in a column of its own on the right. */
.results {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.results:empty {
  display: none;
}

.row {
  display: grid;
  grid-template-columns: 1fr 12.5rem;
  gap: 8px 24px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.row:first-child {
  border-top: 0;
}

.row.tree {
  display: block;
}

.row-main {
  min-width: 0;
}

.desc {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 600;
  line-height: 1.45;
  color: var(--text);
  overflow-wrap: anywhere;
}

/* At most two lines; the parent's full title is on hover. */
.crumbs {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  margin-top: 4px;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--text-light);
}

.crumbs ol {
  display: inline;
  list-style: none;
  margin: 0;
  padding: 0;
}

.crumbs li {
  display: inline;
}

.crumbs li + li::before,
.crumbs ol:not(:empty) + .crumb-parent::before {
  content: "›";
  padding: 0 6px;
}

.crumb-code {
  border: 0;
  padding: 0;
  background: transparent;
  font: inherit;
  font-weight: 600;
  color: var(--text-light);
  white-space: nowrap;
  cursor: pointer;
}

.crumb-code:hover {
  color: var(--link);
  text-decoration: underline;
}

.row.tree > .crumbs {
  margin: 0 0 8px;
}

.row-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  text-align: right;
}

.row-code {
  display: flex;
  align-items: center;
  gap: 8px;
}

.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--link);
  white-space: nowrap;
}

.code.muted {
  color: var(--text-light);
  font-weight: 600;
}

.copy {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  padding: 3px 8px;
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}

.copy:hover {
  border-color: var(--link);
  color: var(--link);
}

.copy.copied {
  border-color: var(--ok-text);
  color: var(--ok-text);
}

.copy svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tag {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--text-light);
  white-space: nowrap;
  cursor: help;
}

.tag.ok {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.tag.warn {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.ext {
  font-size: 0.8rem;
  white-space: nowrap;
  text-decoration: none;
}

.ext:hover {
  text-decoration: underline;
}

.expand {
  margin-top: 6px;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--link);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.expand:hover {
  text-decoration: underline;
}

.row-children {
  grid-column: 1 / -1;
  margin-top: 4px;
  padding: 4px 12px;
  border-radius: 10px;
  background: var(--bg-soft);
}

.children-note {
  margin: 8px 0;
  font-size: 0.85rem;
  color: var(--text-light);
}

.link-button {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--link);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.link-button:hover {
  text-decoration: underline;
}

.link-button.small {
  font-size: 0.8rem;
}

/* A code search: the lines under the code as an indented list */
.tree-rows {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree-row {
  display: grid;
  grid-template-columns: 8.5em 1fr auto;
  align-items: baseline;
  gap: 4px 12px;
  padding: 7px 0;
  border-top: 1px solid var(--border);
  font-size: 0.95rem;
  line-height: 1.45;
}

.tree-row:first-child {
  border-top: 0;
}

.tree-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  color: var(--text-light);
  white-space: nowrap;
}

.tree-row.leaf .tree-code {
  color: var(--link);
  font-weight: 700;
}

.tree-text {
  padding-left: calc(var(--depth, 0) * 0.9rem);
  overflow-wrap: anywhere;
}

.tree-row.between .tree-text {
  color: var(--text-light);
  font-style: italic;
}

.tree-row.leaf .tree-text {
  font-weight: 500;
}

@media (max-width: 560px) {
  .row {
    grid-template-columns: 1fr;
    padding: 14px 14px;
  }

  .row-side {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    text-align: left;
  }

  .tree-row {
    grid-template-columns: 1fr auto;
  }

  .tree-code {
    grid-column: 1 / -1;
  }

  .tree-text {
    padding-left: calc(var(--depth, 0) * 0.5rem);
  }
}

/* No results */
.empty {
  margin-top: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 24px;
}

.empty h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
  color: var(--text);
}

.empty p {
  margin: 8px 0;
}

.empty ul {
  margin: 0;
  padding-left: 20px;
}

.empty .muted {
  margin-top: 16px;
  font-size: 0.9rem;
  color: var(--text-light);
}

.version {
  margin: 16px auto 0;
  font-size: 0.85rem;
  color: var(--text-light);
}

/* "Copied" message */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  background: var(--primary-dark);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  font-size: 0.9rem;
  transition:
    opacity 0.2s,
    transform 0.2s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

mark {
  background: var(--mark);
  color: inherit;
  border-radius: 2px;
}

/* Text */
.prose {
  padding: 40px 16px 64px;
}

.prose h2 {
  color: var(--link);
  font-size: 1.6rem;
  margin: 32px 0 8px;
}

.prose p,
.prose li {
  color: var(--text);
}

/* Footer */
.foot {
  background: var(--primary-dark);
  color: #fff;
  padding: 48px 0;
}

.foot-row {
  display: grid;
  gap: 32px;
  grid-template-columns: 1fr;
}

@media (min-width: 720px) {
  .foot-row {
    grid-template-columns: 2fr 1fr;
  }
}

.foot p {
  margin: 12px 0 0;
  color: rgba(255, 255, 255, 0.8);
}

.foot a {
  color: rgba(255, 255, 255, 0.85);
}

.foot nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.foot nav a {
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
}

.foot nav a:hover {
  color: #fff;
  text-decoration: underline;
}

/* --- Added with the code pages (Astro app) ------------------------------ */

/* Language switch next to the Kontakto logo */
.top-side {
  display: flex;
  align-items: center;
  gap: 20px;
}

.langs {
  position: relative;
}

.langs summary {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
  border-radius: 999px;
  color: #fff;
  cursor: pointer;
  list-style: none;
}

.langs summary::-webkit-details-marker {
  display: none;
}

.langs summary:hover,
.langs[open] summary {
  background: rgba(255, 255, 255, 0.12);
}

.langs svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.langs .globe {
  width: 22px;
  height: 22px;
  stroke-width: 1.75;
}

.langs .chevron {
  width: 14px;
  height: 14px;
  stroke-width: 1.75;
  opacity: 0.7;
}

.langs ul {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 10;
  width: 9rem;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}

.langs a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  font-size: 0.9rem;
  color: var(--text);
  text-decoration: none;
}

.langs a:hover {
  background: var(--bg-soft);
}

.langs a[aria-current="true"] {
  font-weight: 600;
}

.langs .check {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  stroke: var(--link);
  stroke-width: 2;
}

@media (max-width: 560px) {
  .top-side {
    gap: 10px;
  }

  .by span {
    display: none;
  }
}

/* A hit's text links to the code's page but reads as before. */
.desc-link {
  color: inherit;
  text-decoration: none;
}

.desc-link:hover {
  color: var(--link);
  text-decoration: underline;
}

a.tree-text {
  color: inherit;
  text-decoration: none;
}

a.tree-text:hover {
  color: var(--link);
  text-decoration: underline;
}

/* Server-rendered tree rows set their depth by class (the CSP allows no style attributes). */
.tree-row.d1 {
  --depth: 1;
}
.tree-row.d2 {
  --depth: 2;
}
.tree-row.d3 {
  --depth: 3;
}
.tree-row.d4 {
  --depth: 4;
}
.tree-row.d5 {
  --depth: 5;
}
.tree-row.d6 {
  --depth: 6;
}
.tree-row.d7 {
  --depth: 7;
}
.tree-row.d8 {
  --depth: 8;
}
.tree-row.d9 {
  --depth: 9;
}
.tree-row.d10 {
  --depth: 10;
}

.tree-row.current .tree-text {
  font-weight: 700;
  color: var(--text);
}

/* The search box on a code's page: the hero without its texts */
.hero.compact {
  padding: 20px 0 24px;
}

/* Chapter list on the home page and on chapter pages */
.browse {
  padding-top: 32px;
}

.browse h2 {
  color: var(--link);
  font-size: 1.6rem;
  margin: 0 0 12px;
}

.chapters {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr));
  gap: 0 24px;
  font-size: 0.9rem;
  line-height: 1.4;
}

.chapters a {
  display: flex;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
}

.chapters a:hover .ch-text {
  color: var(--link);
  text-decoration: underline;
}

.chapters a[aria-current="page"] {
  font-weight: 700;
}

.ch-code {
  flex-shrink: 0;
  width: 1.6rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 700;
  color: var(--link);
}

.ch-text {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* A code's page */
.code-area {
  min-height: 0;
  padding-top: 16px;
}

.page-crumbs ol {
  display: flex;
  flex-wrap: wrap;
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  font-size: 0.85rem;
  color: var(--text-light);
}

.page-crumbs li + li::before {
  content: "›";
  padding: 0 6px;
}

.page-crumbs a {
  color: var(--text-light);
  font-weight: 600;
  text-decoration: none;
}

.page-crumbs a:hover {
  color: var(--link);
  text-decoration: underline;
}

.code-card,
.panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 20px 24px;
}

.panel {
  margin-top: 16px;
  padding: 16px 20px 8px;
}

.kicker {
  margin: 0 0 2px;
  font-size: 0.9rem;
  color: var(--text-light);
}

.code-card h1 {
  margin: 0 0 12px;
  font-size: clamp(1.35rem, 3.2vw, 1.75rem);
  line-height: 1.3;
  color: var(--text);
  overflow-wrap: anywhere;
}

.code-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.code-line .code {
  font-size: 1.35rem;
}

.status-text {
  margin: 10px 0 0;
  font-size: 0.9rem;
  color: var(--text-light);
}

.code-links {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  margin: 8px 0 0;
}

.code-links .ext {
  font-size: 0.9rem;
  white-space: normal;
}

.panel h2 {
  margin: 0 0 4px;
  font-size: 1.05rem;
  color: var(--text);
}

.panel-count {
  margin-left: 4px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-light);
}

.panel-foot {
  margin: 4px 0 8px;
  font-size: 0.85rem;
}

.panel .chapters {
  margin: 4px 0 12px;
}

@media (max-width: 560px) {
  .code-card,
  .panel {
    padding: 16px 14px;
  }
}
