table {
  width: 100%;
}

/* Recipe tables: each row is a card, recipe title on top, pills wrapping below. */
table:has(.crate-chip),
table:has(.crate-chip) tbody {
  display: block;
}

table:has(.crate-chip) thead {
  display: none;
}

table:has(.crate-chip) tbody {
  padding-top: 10px;
}

table:has(.crate-chip) tr,
table:has(.crate-chip) tr:nth-child(2n) {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 0;
  margin: 0 0 24px; /* the extra space under each card leaves room for the next card's tab */
  padding: 12px 14px;
  border: 1px solid var(--table-border-color, var(--quote-border, #ccc));
  border-radius: 10px;
  background: var(--bg);
  transition: border-color 0.15s, box-shadow 0.15s;
}

table:has(.crate-chip) tr:hover {
  border-color: var(--links);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}

/* the whole card opens the recipe; pills stay clickable above the overlay */
table:has(.crate-chip) td:first-child a::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 10px;
}

table:has(.crate-chip) td .crate-chip {
  position: relative;
  z-index: 1;
}

table:has(.crate-chip) td,
table:has(.crate-chip) td:nth-child(n + 2) {
  display: flex;
  flex-wrap: wrap;
  width: auto;
  padding: 0 4px;
  border: 0;
  white-space: normal;
}

table:has(.crate-chip) td:first-child {
  display: block;
  flex-basis: 100%;
  font-size: 1.05em;
  font-weight: 500;
}

table:has(.crate-chip) td:nth-child(3) {
  margin-left: 8px;
}

table:has(.crate-chip) td .crate-chip {
  display: inline-flex;
}

/* Auto-sized comparison tables (not TOC tables) */
.comparison table {
  table-layout: auto;
}

.comparison table td:first-child {
  width: auto;
}

.comparison table td:nth-child(2) {
  width: auto;
}

.comparison table td,
.comparison table th {
  padding: 6px 12px;
  white-space: nowrap;
}

/* section sub-category labels (bold-only paragraphs in summary tables) */
p > strong:only-child {
  font-size: 1.1em;
}

/* underline hyperlinked inline code items */
a:hover > .hljs {
  text-decoration: underline;
}

/* color hyperlinked inline code items
   identically to normal links */
.rust a > .hljs,
.navy a > .hljs,
.coal a > .hljs,
.ayu a > .hljs {
  color: var(--links);
}

.light a > .hljs {
  color: var(--links);
}

/* pills: crate (name, copy, repository) and category */
.crate-chip {
  display: inline-flex;
  align-items: stretch;
  vertical-align: middle;
  margin: 2px 3px 2px 0;
  border: 1px solid var(--table-border-color, var(--quote-border, #ccc));
  border-radius: 999px;
  background: var(--quote-bg, #f5f5f5);
  font-family: "Source Code Pro", Consolas, monospace;
  font-size: 0.85em;
  line-height: 1.5;
  overflow: hidden;
  white-space: nowrap;
}

.crate-chip .crate-chip-name,
a.cat-chip {
  padding: 0 10px;
  color: var(--links);
  text-decoration: none;
}

.crate-chip a.crate-chip-name:hover,
a.cat-chip:hover {
  text-decoration: underline;
}

a.cat-chip {
  font-family: inherit;
  font-size: 0.8em;
  padding: 1px 10px;
}

/* mdBook colors links via `.content a:link` / `a:visited`, which would make
   visited and unvisited pills differ; match its specificity for both states. */
.content a.cat-chip:link,
.content a.cat-chip:visited {
  color: var(--fg);
}

.content .crate-chip a.crate-chip-repo:link,
.content .crate-chip a.crate-chip-playground:link,
.content .crate-chip a.crate-chip-repo:visited,
.content .crate-chip a.crate-chip-playground:visited {
  color: var(--icons, #747474);
}

.content .crate-chip a.crate-chip-repo:link:hover,
.content .crate-chip a.crate-chip-playground:link:hover,
.content .crate-chip a.crate-chip-repo:visited:hover,
.content .crate-chip a.crate-chip-playground:visited:hover {
  color: var(--icons-hover, #000);
}

a.cat-chip:hover {
  background: var(--theme-hover, rgba(128, 128, 128, 0.15));
}

.crate-chip-copy,
.crate-chip .crate-chip-playground,
.crate-chip .crate-chip-repo {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0 8px;
  border: 0;
  border-left: 1px solid var(--table-border-color, var(--quote-border, #ccc));
  background: transparent;
  color: var(--icons, #747474);
  font: inherit;
  cursor: pointer;
}

.crate-chip-copy:hover,
.crate-chip-copy:focus-visible,
.crate-chip .crate-chip-playground:hover,
.crate-chip .crate-chip-repo:hover {
  color: var(--icons-hover, #000);
  background: var(--theme-hover, rgba(128, 128, 128, 0.15));
}

.crate-chip.copied {
  border-color: #2e9b57;
}

.crate-chip.copied .crate-chip-copy {
  color: #2e9b57;
}

/* After "Copied", the button shows the Cargo.toml line that was copied. */
.crate-chip-copy code {
  max-width: 34ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0;
  background: transparent;
  color: inherit;
  font-size: 0.9em;
}

/* quick search: crate and topic matches above mdBook's full-text results */
#cookbook-quicksearch {
  margin: 0.75em auto 1em;
  padding: 0.25em 1em 0.75em;
  max-width: var(--content-max-width, 750px);
  border-bottom: 1px solid var(--table-border-color, var(--quote-border, #ccc));
}

#cookbook-quicksearch[hidden],
#cookbook-quicksearch li[hidden] {
  display: none;
}

#cookbook-quicksearch .qs-group {
  margin-top: 0.75em;
}

#cookbook-quicksearch .qs-title {
  font-size: 0.75em;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ck-muted);
}

#cookbook-quicksearch .qs-head,
#cookbook-quicksearch .qs-topic {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5em;
  margin-top: 0.35em;
}

#cookbook-quicksearch ul {
  margin: 0.1em 0 0.3em;
  padding: 0;
  list-style: none;
}

#cookbook-quicksearch li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1em;
  margin: 0.15em 0;
  padding-left: 0.25em;
}

#cookbook-quicksearch li .qs-muted {
  flex-shrink: 0;
  text-align: end;
}

#cookbook-quicksearch a.qs-recipe {
  color: var(--links);
  text-decoration: none;
}

#cookbook-quicksearch a.qs-recipe:hover {
  text-decoration: underline;
}

#cookbook-quicksearch .qs-muted {
  font-size: 0.85em;
  color: var(--ck-muted);
}

#cookbook-quicksearch .qs-more {
  margin: 0 0 0.4em 0.25em;
  padding: 0;
  border: 0;
  background: none;
  color: var(--links);
  font: inherit;
  font-size: 0.85em;
  cursor: pointer;
}

#cookbook-quicksearch .qs-more:hover {
  text-decoration: underline;
}

/* Nobody is editing a Cargo.toml on a phone, so drop the copy button there. */
@media (max-width: 480px) {
  .crate-chip-copy {
    display: none;
  }
}

/* friendlier headings: lighter weight, a short accent underline on sections */
.content h1,
.content h2 {
  font-weight: 600;
  letter-spacing: -0.01em;
}

.content h1 {
  font-size: 2em;
  margin-top: 1.6em;
}

.content h1::after {
  content: "";
  display: block;
  width: 2.2em;
  height: 3px;
  margin-top: 0.3em;
  border-radius: 2px;
  background: var(--links);
}

.content h2 {
  font-size: 1.5em;
}

/* previous/next links say where they go */
.nav-label {
  display: flex;
  flex-direction: column;
  min-width: 0;
  font-size: 0.34em;
  line-height: 1.3;
}

.nav-kicker {
  font-size: 0.85em;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ck-muted);
}

.nav-title {
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* wide screens: the side strips get the label under the chevron */
.nav-chapters .nav-label {
  padding: 0 10px;
  margin-top: 0.4em;
  text-align: center;
}

/* narrower screens: bottom buttons with the title next to the arrow */
.mobile-nav-chapters {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  width: auto;
  max-width: 48%;
  padding: 8px 14px;
  border: 1px solid var(--table-border-color, var(--quote-border, #ccc));
  border-radius: 10px;
  background-color: var(--bg);
  font-size: 1.4em;
  text-align: start;
}

.mobile-nav-chapters .nav-label {
  font-size: 0.6em;
}

.mobile-nav-chapters.next {
  text-align: end;
}

.mobile-nav-chapters.next .nav-label {
  order: -1;
  align-items: flex-end;
}

/* home page: topic grid */
.section-grid ul {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 22px 10px; /* the extra row gap leaves room for the tabs */
  margin: 0;
  padding: 0;
  list-style: none;
}

.section-grid li {
  margin: 0;
}

.section-grid a {
  position: relative;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 2px;
  height: 100%;
  padding: 12px 14px;
  border: 1px solid var(--table-border-color, var(--quote-border, #ccc));
  border-radius: 10px;
  background: var(--bg);
  font-weight: 500;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.section-grid a:hover {
  border-color: var(--links);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  text-decoration: none;
}

/* Topic cards and recipe cards are index cards with a tab sticking out of their top edge. The tab
   slides along the edge with the card's place in the list (--tab-progress, 0 to 1, set by
   card-tabs.js). The tab's last pixel covers the card's top border so the two join. */
.section-grid a::before,
table:has(.crate-chip) tr::before {
  content: "";
  position: absolute;
  top: -10px;
  left: 16px;
  width: 38px;
  height: 11px;
  box-sizing: border-box;
  border: 1px solid var(--table-border-color, var(--quote-border, #ccc));
  border-bottom: 0;
  border-radius: 7px 7px 0 0;
  background: var(--bg);
  transition: border-color 0.15s;
}

.section-grid a::before,
table:has(.crate-chip) tr::before {
  left: calc(16px + var(--tab-progress, 0) * (100% - 70px));
}

.section-grid a:hover::before,
table:has(.crate-chip) tr:hover::before {
  border-color: var(--links);
}

.sg-count {
  display: block;
  padding-inline-start: 0.9em;
  font-size: 0.72em;
  font-weight: 400;
  color: var(--ck-muted);
}

kbd {
  padding: 0 5px;
  border: 1px solid var(--table-border-color, var(--quote-border, #ccc));
  border-radius: 4px;
  background: var(--quote-bg, #f5f5f5);
  font-family: inherit;
  font-size: 0.85em;
}

/* crate index page */
.ci-filter {
  box-sizing: border-box;
  width: 100%;
  margin: 0.5em 0 1em;
  padding: 10px 14px;
  border: 1px solid var(--table-border-color, var(--quote-border, #ccc));
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}

.ci-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.ci-card {
  padding: 12px 14px;
  border: 1px solid var(--table-border-color, var(--quote-border, #ccc));
  border-radius: 10px;
}

.ci-card[hidden] {
  display: none;
}

.ci-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5em;
}

.ci-head .qs-muted {
  font-size: 0.85em;
  color: var(--ck-muted);
}

.ci-card ul {
  margin: 0.5em 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.95em;
}

.ci-card li {
  margin: 0.2em 0;
}

/* snippet buttons (run, copy, ...): visible without hovering, easy to tap */
pre > .buttons {
  visibility: visible;
  opacity: 0.6;
  top: 6px;
  right: 6px;
}

pre:hover > .buttons,
pre > .buttons:focus-within {
  opacity: 1;
}

@media (pointer: coarse) {
  pre > .buttons {
    opacity: 0.9;
  }

  pre > .buttons button {
    min-width: 44px;
    min-height: 44px;
  }
}

/* search as a Cmd/Ctrl+K overlay */
#mdbook-search-wrapper:not(.hidden) {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 8vh 12px 0;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.45);
}

.cmdk-box {
  box-sizing: border-box;
  width: min(720px, 100%);
  max-height: 84vh;
  overflow-y: auto;
  padding: 4px 18px 16px;
  border: 1px solid var(--table-border-color, var(--quote-border, #ccc));
  border-radius: 14px;
  background: var(--bg);
  color: var(--fg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.ci-card li[hidden] {
  display: none;
}

.ci-more {
  margin: 0.4em 0 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--links);
  font: inherit;
  font-size: 0.9em;
  cursor: pointer;
}

.ci-more:hover {
  text-decoration: underline;
}

/* ---- accessibility (WCAG 2.2 AA) ---- */

/* Text that is quieter than body text but still readable. */
:root {
  --ck-muted: color-mix(in srgb, var(--fg) 80%, var(--bg));
}

/* mdBook's stock link and icon colors fall below 4.5:1 / 3:1 in these themes. */
.coal {
  --links: #3a99cb;
  --icons: #8a929a;
  --sidebar-active: #5f99cf;
}

.navy {
  --links: #3a99cb;
  --icons: #90919b;
  --sidebar-active: #469fce;
}

.ayu {
  --links: #009dd9;
  --icons: #90919b;
}

.rust {
  --links: #1d526e;
  --icons: #4c4d55;
}

.light {
  --icons: #6f6f6f;
}

/* Links inside running text must not rely on color alone. */
.content p a,
.content li a,
.content td a {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.content .section-grid a,
.content .ci-card a,
.content .ri-letters a,
.content .crate-chip a,
.content a.cat-chip,
.content table:has(.crate-chip) td:first-child a,
.content a.nav-chapters,
.content a.mobile-nav-chapters,
#cookbook-quicksearch a {
  text-decoration: none;
}

.content .section-grid a:hover,
.content .ci-card a:hover,
.content .crate-chip a:hover,
.content table:has(.crate-chip) td:first-child a:hover,
#cookbook-quicksearch a:hover {
  text-decoration: underline;
}

/* Header icons and sidebar links are too small to hit comfortably. */
.menu-bar .icon-button,
.right-buttons a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  min-height: 32px;
}

.sidebar .chapter li a {
  display: inline-block;
  min-height: 24px;
  line-height: 24px;
}

/* recipe index page */
.ri-letters {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 0.5em 0 1.5em;
}

.ri-letters a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  min-height: 32px;
  border: 1px solid var(--table-border-color, var(--quote-border, #ccc));
  border-radius: 8px;
  font-weight: 600;
}

.ri-letters a:hover {
  border-color: var(--links);
}

h2.ri-letter {
  margin-block: 1.2em 0.3em;
  font-size: 1.3em;
}

.ri-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.ri-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1em;
  margin: 0.2em 0;
}

.ri-section {
  flex-shrink: 0;
  font-size: 0.85em;
  color: var(--ck-muted);
}

/* stock colors below 4.5:1: search result count, and comments in Ayu code blocks */
#mdbook-searchresults-header {
  color: var(--ck-muted);
}

.ayu .hljs-comment {
  color: #8a95a1;
}

/* single links in lists are hit targets: give them 24px of height */
.content ul li > a {
  display: inline-block;
  min-height: 24px;
  line-height: 24px;
}

/* the list-link sizing above must not turn the topic cards into inline boxes */
.content .section-grid li > a {
  display: flex;
  line-height: normal;
}

/* dimmed search magnifier at the bottom of the page */
.bottom-search {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--fg);
  opacity: 0.55;
  cursor: pointer;
  transition: opacity 0.15s, background-color 0.15s;
}

.bottom-search:hover,
.bottom-search:focus-visible {
  opacity: 0.95;
  background-color: var(--theme-hover, rgba(128, 128, 128, 0.15));
}

.nav-wrapper {
  position: relative;
}

.bottom-search.in-nav {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.bottom-search-wide {
  display: flex;
  justify-content: center;
  margin: 50px 0 40px;
}

/* where mdBook shows the bottom nav row, the in-row magnifier is used instead */
@media (max-width: 1080px) {
  .bottom-search-wide {
    display: none;
  }
}

@media (max-width: 1380px) {
  #mdbook-sidebar-toggle-anchor:checked ~ .page-wrapper .bottom-search-wide {
    display: none;
  }
}

/* leave room for the magnifier between the previous and next links */
.mobile-nav-chapters {
  max-width: calc(50% - 36px);
}

/* Visible to screen readers only (live-region announcements). */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* A small 📦 after every link that goes to crates.io (category pills and links in the text). */
.content a[href^="https://crates.io"]::after,
.content a[href^="http://crates.io"]::after {
  content: "📦";
  content: "📦" / "";
  margin-left: calc(0.3em + 6px);
  position: relative;
  top: 2px;
  font-size: 0.8em;
  text-decoration: none;
  display: inline-block;
}
