/* ==========================================================================
   Cheat Sheet Library theme
   Light/dark: follows the system setting; the toggle pins one theme by
   setting <html data-theme="light|dark">. Every colour token is written once,
   as light-dark(light, dark).
   ========================================================================== */

:root {
  color-scheme: light dark;

  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, 'Cascadia Code', 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
  --topbar-h: 3.5rem;
  --sidebar-w: 16.5rem;
  --toc-w: 13rem;
  --radius: 10px;
  --radius-sm: 6px;

  /* Colours: light-dark(light, dark) follows color-scheme, so the system setting
     and the toggle (which sets color-scheme, see below) both just work. */
  --bg: light-dark(#ffffff, #0e1015);
  --bg-soft: light-dark(#f8f9fb, #12151b);
  --surface: light-dark(#ffffff, #151922);
  --surface-2: light-dark(#f1f3f6, #1c212b);
  --border: light-dark(#e4e7ec, #262c38);
  --border-strong: light-dark(#d0d5dd, #353c4a);
  --text: light-dark(#1a1d23, #e7e9ee);
  --text-muted: light-dark(#555e6d, #a3abb8);
  --text-faint: light-dark(#5d6573, #8a93a2); /* light value passes WCAG AA on every light surface */
  --accent: light-dark(#4f46e5, #8b8dfb);
  --accent-hover: light-dark(#4338ca, #a5a7ff);
  --accent-soft: light-dark(#eef0ff, #23254a);
  --accent-text: light-dark(#3730a3, #c9caff);
  --code-bg: light-dark(#f3f4f7, #1b202a);
  --code-border: light-dark(#dfe3e9, #2c3341);
  --code-text: light-dark(#1f2937, #e5e7eb);
  --mark: light-dark(#fde68a, #6b5800);
  --row-hover: light-dark(#f9fafb, #161a22);
  --target: light-dark(#fff7d6, #2e2b13);
  --topbar-bg: light-dark(rgb(255 255 255 / 0.85), rgb(14 16 21 / 0.82));
  --shadow:
    0 1px 2px light-dark(rgb(16 24 40 / 0.05), rgb(0 0 0 / 0.4)),
    0 1px 3px light-dark(rgb(16 24 40 / 0.08), transparent);
  --shadow-lg: 0 24px 60px -12px light-dark(rgb(16 24 40 / 0.35), rgb(0 0 0 / 0.75));
}

/* The toggle pins one theme. */
:root[data-theme='dark'] {
  color-scheme: dark;
}
:root[data-theme='light'] {
  color-scheme: light;
}

/* Browsers without light-dark() (before 2024): system colours, which also follow
   light/dark. Plainer, but readable in both themes. */
@supports not (color: light-dark(#000, #fff)) {
  :root {
    --bg: Canvas;
    --bg-soft: Canvas;
    --surface: Canvas;
    --surface-2: ButtonFace;
    --border: GrayText;
    --border-strong: GrayText;
    --text: CanvasText;
    --text-muted: CanvasText;
    --text-faint: GrayText;
    --accent: LinkText;
    --accent-hover: LinkText;
    --accent-soft: ButtonFace;
    --accent-text: LinkText;
    --code-bg: ButtonFace;
    --code-border: GrayText;
    --code-text: CanvasText;
    --mark: Mark;
    --row-hover: ButtonFace;
    --target: Mark;
    --topbar-bg: Canvas;
    --shadow: none;
    --shadow-lg: 0 24px 60px -12px rgb(0 0 0 / 0.5);
  }
}

/* ---------- Base ---------- */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--topbar-h) + 1rem);
  accent-color: var(--accent);
}
html:has(.is-sheet) {
  scroll-padding-top: calc(var(--topbar-h) + 5rem);
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-underline-offset: 0.18em;
}
a:hover {
  color: var(--accent-hover);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

img,
svg {
  max-width: 100%;
}

button {
  font: inherit;
  color: inherit;
}

kbd {
  display: inline-block;
  min-width: 1.4em;
  padding: 0.05rem 0.4rem;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface);
  color: var(--text-muted);
  font: 500 0.72rem/1.4 var(--mono);
  text-align: center;
  white-space: nowrap;
}

.icon {
  width: 1.15rem;
  height: 1.15rem;
  flex: none;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0.5rem;
  z-index: 100;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}
.skip-link:focus {
  left: 1rem;
}

.is-hidden {
  display: none !important;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover {
  border-color: var(--accent);
  color: var(--accent-text);
}

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: var(--topbar-h);
  padding: 0 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--topbar-bg);
  backdrop-filter: saturate(1.8) blur(12px);
  -webkit-backdrop-filter: saturate(1.8) blur(12px);
  view-transition-name: topbar;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text);
  font-weight: 700;
  letter-spacing: -0.01em;
  text-decoration: none;
  white-space: nowrap;
}
.brand:hover {
  color: var(--text);
}
.logo {
  width: 1.75rem;
  height: 1.75rem;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  flex: none;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.search-trigger {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: min(22rem, 40vw);
  height: 2.25rem;
  margin-left: auto;
  padding: 0 0.45rem 0 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s;
}
.search-trigger:hover {
  border-color: var(--border-strong);
  color: var(--text);
}
.search-trigger-text {
  flex: 1;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Theme toggle shows the icon of the theme you can switch to. */
.icon-sun {
  display: none;
}
:root[data-theme='dark'] .icon-sun {
  display: block;
}
:root[data-theme='dark'] .icon-moon {
  display: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .icon-sun {
    display: block;
  }
  :root:not([data-theme='light']) .icon-moon {
    display: none;
  }
}

.menu-btn {
  display: none;
}

/* ---------- Layout ---------- */

.shell {
  flex: 1;
  width: 100%;
}
.shell.has-sidebar {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
}

.main {
  min-width: 0;
  padding: 1.5rem clamp(1rem, 4vw, 3rem) 4rem;
}
.is-home .main {
  max-width: 78rem;
  margin: 0 auto;
}

.page-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 3rem;
  max-width: 74rem;
}
.sheet {
  min-width: 0;
  max-width: 58rem;
}

/* ---------- Sidebar ---------- */

.sidebar {
  position: sticky;
  top: var(--topbar-h);
  height: calc(100dvh - var(--topbar-h));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1rem 0.75rem 3rem;
  border-right: 1px solid var(--border);
  background: var(--bg-soft);
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
  view-transition-name: sidebar;
}

.nav-home {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  padding: 0.4rem 0.55rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.85rem;
  text-decoration: none;
}
.nav-home:hover {
  background: var(--surface-2);
  color: var(--text);
}
.nav-home .icon {
  width: 1rem;
  height: 1rem;
}

.nav-group summary {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 600;
  list-style: none;
  cursor: pointer;
  user-select: none;
}
.nav-group summary::-webkit-details-marker {
  display: none;
}
.nav-group summary:hover {
  background: var(--surface-2);
}
.nav-group-title {
  flex: 1;
  min-width: 0;
}
.nav-count {
  color: var(--text-faint);
  font-size: 0.75rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.nav-group ul {
  margin: 0.15rem 0 0.6rem 1.2rem;
  padding: 0 0 0 0.6rem;
  border-left: 1px solid var(--border);
  list-style: none;
}
.nav-group a {
  display: block;
  padding: 0.26rem 0.6rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.875rem;
  text-decoration: none;
}
.nav-group a:hover {
  background: var(--surface-2);
  color: var(--text);
}
.nav-group a[aria-current='page'] {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}

.nav-backdrop {
  display: none;
}

/* Category icon: coloured per category via --hue */
.cat-icon {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  flex: none;
  border-radius: 9px;
  background: hsl(var(--hue) 85% 95%);
  background: light-dark(hsl(var(--hue) 85% 95%), hsl(var(--hue) 35% 18%));
  color: hsl(var(--hue) 65% 40%);
  color: light-dark(hsl(var(--hue) 65% 40%), hsl(var(--hue) 65% 74%));
}
.cat-icon.sm {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 6px;
}
.cat-icon.sm .icon {
  width: 0.95rem;
  height: 0.95rem;
}
.cat-icon.lg {
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 12px;
}
.cat-icon.lg .icon {
  width: 1.6rem;
  height: 1.6rem;
}

/* ---------- Sheet header ---------- */

.breadcrumb ol {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--text-faint);
  font-size: 0.85rem;
}
.breadcrumb li + li::before {
  content: '/';
  margin-right: 0.4rem;
  color: var(--border-strong);
}
.breadcrumb a {
  color: var(--text-muted);
  text-decoration: none;
}
.breadcrumb a:hover {
  color: var(--accent);
}

.sheet-header {
  display: flex;
  align-items: flex-start;
  gap: 1.1rem;
  margin: 1.1rem 0 1.25rem;
}
.sheet-header h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.75rem, 3vw, 2.3rem);
  line-height: 1.15;
  letter-spacing: -0.025em;
}
.lead {
  margin: 0;
  color: var(--text-muted);
  font-size: 1.05rem;
}
.lead code {
  font-size: 0.85em;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0.8rem 0 0;
  padding: 0;
  list-style: none;
}
.meta li {
  padding: 0.12rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* ---------- Filter bar ---------- */

.filter-bar {
  position: sticky;
  top: var(--topbar-h);
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  margin: 0 0 0.5rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.filter {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 0.55rem;
  min-width: 12rem;
  max-width: 28rem;
  height: 2.5rem;
  padding: 0 0.5rem 0 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-faint);
  cursor: text;
}
.filter:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.filter input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 0.95rem;
}
.filter:focus-within kbd {
  visibility: hidden;
}
.filter-status {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.no-results {
  margin: 2rem 0;
  padding: 2rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-muted);
  text-align: center;
}
.no-results p {
  margin: 0 0 1rem;
}

/* ---------- Content (rendered Markdown) ---------- */

.prose > section:first-child > h2:first-child,
.prose > h2:first-child {
  margin-top: 1.25rem;
}
.prose h2 {
  margin: 2.5rem 0 0.75rem;
  font-size: 1.3rem;
  line-height: 1.3;
  letter-spacing: -0.015em;
}
.prose h3 {
  margin: 1.75rem 0 0.5rem;
  font-size: 1.05rem;
}
.heading-anchor {
  margin-left: 0.35rem;
  color: var(--text-faint);
  font-weight: 400;
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.15s;
}
:is(h1, h2, h3):hover .heading-anchor,
.heading-anchor:focus-visible {
  opacity: 1;
}

.prose p,
.prose ul,
.prose ol {
  margin: 0.75rem 0;
}
.prose ul,
.prose ol {
  padding-left: 1.4rem;
}
.prose li {
  margin: 0.25rem 0;
}
.prose li::marker {
  color: var(--text-faint);
}
.prose .task-list {
  padding-left: 0.25rem;
  list-style: none;
}
.prose hr {
  margin: 2rem 0;
  border: 0;
  border-top: 1px solid var(--border);
}
.prose blockquote {
  margin: 1rem 0;
  padding: 0.1rem 1rem;
  border-left: 3px solid var(--border-strong);
  color: var(--text-muted);
}

.prose code {
  padding: 0.1em 0.38em;
  border: 1px solid var(--code-border);
  border-radius: 5px;
  background: var(--code-bg);
  color: var(--code-text);
  font-family: var(--mono);
  font-size: 0.84em;
  overflow-wrap: anywhere;
}

.code-block {
  position: relative;
  margin: 1rem 0;
}
.prose pre {
  margin: 1rem 0;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  background: var(--code-bg);
  font-size: 0.84rem;
  line-height: 1.6;
  scrollbar-width: thin;
}
.code-block pre {
  margin: 0;
}
.prose pre code {
  padding: 0;
  border: 0;
  background: none;
  font-size: inherit;
  overflow-wrap: normal;
}
.copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
.code-block:hover .copy-btn,
.copy-btn:focus-visible,
.copy-btn.copied {
  opacity: 1;
}
@media (hover: none) {
  .copy-btn {
    opacity: 1;
  }
}

/* Tables */
.table-wrap {
  margin: 0.75rem 0 1.25rem;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.prose th {
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}
.prose td {
  padding: 0.5rem 0.9rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.prose tbody tr:last-child td {
  border-bottom: 0;
}
.prose tbody tr:hover {
  background: var(--row-hover);
}
/* Two-column tables: give the key column a stable width. */
.prose table:has(th:nth-child(2):last-child) td:first-child {
  width: 42%;
}
.prose td {
  line-height: 1.75;
}
.prose td code {
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  border-color: var(--border-strong);
  border-bottom-width: 2px;
  background: var(--surface-2);
}
.prose td code.copyable {
  cursor: copy;
}
.prose td code.copyable:hover {
  border-color: var(--accent);
}
.prose tr:target {
  background: var(--target);
  box-shadow: inset 3px 0 0 var(--accent);
}

/* Expandable commands */
.cmd-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  max-width: 100%;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  color: inherit;
  font: inherit;
  line-height: inherit;
  text-align: left;
  cursor: pointer;
}
.cmd-toggle code {
  cursor: pointer;
}
.cmd-toggle:hover code,
.cmd-toggle[aria-expanded='true'] code {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-text);
}
.cmd-chevron {
  width: 0.95rem;
  height: 0.95rem;
  color: var(--text-faint);
  transition: transform 0.15s;
}
.cmd-toggle:hover .cmd-chevron {
  color: var(--accent);
}
.cmd-toggle[aria-expanded='true'] .cmd-chevron {
  color: var(--accent);
  transform: rotate(90deg);
}
.prose tr.is-open > td {
  border-bottom-color: transparent;
  background: var(--bg-soft);
}
.prose tr.cmd-details:hover {
  background: none;
}
.prose tr.cmd-details > td {
  width: auto !important;
  max-width: 0; /* the panel must never make the outer table wider */
  padding: 0 0.9rem 0.9rem;
  background: var(--bg-soft);
}
.cmd-panel {
  padding: 0.85rem 1rem 0.6rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface);
  line-height: 1.55;
}
.cmd-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}
.cmd-icon {
  width: 1.05rem;
  height: 1.05rem;
  color: var(--accent);
}
.prose code.cmd-name {
  font-size: 0.95rem;
  font-weight: 700;
}
.cmd-aliases {
  color: var(--text-faint);
  font-size: 0.8rem;
}
.cmd-actions {
  display: flex;
  gap: 0.35rem;
  margin-left: auto;
}
.btn-sm {
  padding: 0.15rem 0.6rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.78rem;
  cursor: pointer;
}
.btn-sm:hover {
  border-color: var(--accent);
  color: var(--accent-text);
}
.cmd-panel p {
  margin: 0.45rem 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.cmd-panel .table-wrap {
  margin: 0.6rem 0;
}
.prose .cmd-panel table {
  font-size: 0.86rem;
}
.prose .cmd-panel td {
  padding: 0.35rem 0.75rem;
  line-height: 1.5;
}
.prose .cmd-panel table td:first-child {
  width: 1% !important;
  white-space: nowrap;
}
.prose .cmd-panel th {
  padding: 0.4rem 0.75rem;
}
.cmd-panel pre {
  margin: 0.5rem 0;
}
.meta-hint {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  border-color: var(--accent) !important;
  background: var(--accent-soft) !important;
  color: var(--accent-text) !important;
}
.meta-hint .icon {
  width: 0.85rem;
  height: 0.85rem;
}

/* GitHub-style alerts */
.callout {
  --c: #3b82f6;
  margin: 1rem 0;
  padding: 0.75rem 1rem;
  border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
  border-left: 4px solid var(--c);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--c) 8%, transparent);
}
.callout-title {
  margin: 0 0 0.25rem !important;
  color: var(--c);
  font-weight: 600;
}
.callout > :last-child {
  margin-bottom: 0;
}
.callout-tip {
  --c: #10b981;
}
.callout-important {
  --c: #8b5cf6;
}
.callout-warning {
  --c: #f59e0b;
}
.callout-caution {
  --c: #ef4444;
}

.prose details {
  margin: 1rem 0;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

::highlight(filter) {
  background-color: var(--mark);
  color: inherit;
}

/* ---------- Table of contents ---------- */

.toc {
  display: none;
}
.toc-title {
  margin: 0 0 0.6rem;
  color: var(--text-faint);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}
.toc-nav {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  scroll-target-group: auto;
}
.toc-nav a {
  margin-left: -1px;
  padding: 0.28rem 0.8rem;
  border-left: 2px solid transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.4;
  text-decoration: none;
}
.toc-nav a:hover {
  color: var(--text);
}
/* Chrome 141 crashes when every target of a scroll-target-group is display:none
   (a filter with no results), so the spy is switched off while filtering. */
.is-filtering .toc-nav {
  scroll-target-group: none;
}
.toc-nav a:is(:target-current, .\:target-current) {
  border-left-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.toc-nav a.is-dim,
.toc-mobile a.is-dim {
  opacity: 0.35;
}

.toc-mobile {
  margin: 1rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  font-size: 0.9rem;
}
.toc-mobile summary {
  padding: 0.6rem 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.toc-mobile nav {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
  gap: 0.15rem 1rem;
  padding: 0 0.9rem 0.75rem;
}
.toc-mobile a {
  padding: 0.15rem 0;
  color: var(--text-muted);
  text-decoration: none;
}

/* ---------- Pager ---------- */

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 3rem;
}
.pager-link {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
}
.pager-link:hover {
  border-color: var(--accent);
  color: var(--text);
}
.pager-link.next {
  align-items: flex-end;
  text-align: right;
}
.pager-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-faint);
  font-size: 0.78rem;
}
.pager-label .icon {
  width: 0.9rem;
  height: 0.9rem;
}
.pager-title {
  font-weight: 600;
}

/* ---------- Cards ---------- */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 0.85rem;
}
.card {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  transition:
    border-color 0.15s,
    box-shadow 0.15s,
    transform 0.15s;
}
.card:hover {
  border-color: hsl(var(--hue) 60% 55%);
  box-shadow: var(--shadow);
  color: var(--text);
  transform: translateY(-1px);
}
.card-title {
  font-weight: 650;
}
.card-desc {
  display: -webkit-box;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}
.card-meta {
  margin-top: auto;
  padding-top: 0.35rem;
  color: var(--text-faint);
  font-size: 0.75rem;
}

/* ---------- Home ---------- */

.hero {
  padding: clamp(2.5rem, 7vw, 5rem) 0 2rem;
  text-align: center;
}
.hero h1 {
  margin: 0 0 0.9rem;
  font-size: clamp(2.2rem, 5.5vw, 3.6rem);
  line-height: 1.08;
  letter-spacing: -0.035em;
}
.hero .accent {
  color: var(--accent);
}
.hero > p {
  max-width: 36rem;
  margin: 0 auto 1.75rem;
  color: var(--text-muted);
  font-size: 1.1rem;
}
.eyebrow {
  margin: 0 0 0.5rem !important;
  color: var(--accent) !important;
  font-weight: 700;
  letter-spacing: 0.1em;
}
.hero-search {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: min(36rem, 100%);
  height: 3.25rem;
  margin: 0 auto;
  padding: 0 0.75rem 0 1.1rem;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text-faint);
  font-size: 1rem;
  cursor: pointer;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
.hero-search span {
  flex: 1;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hero-search:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.hero-search .icon {
  width: 1.3rem;
  height: 1.3rem;
  color: var(--accent);
}
.not-found .btn {
  margin-top: 1rem;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem 1.75rem;
  margin: 1.5rem 0 0;
  padding: 0;
  list-style: none;
  color: var(--text-muted);
  font-size: 0.92rem;
}
.stats strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.recent {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin: 0 0 1.5rem;
}
.recent[hidden] {
  display: none;
}
.recent-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-faint);
  font-size: 0.85rem;
}
.recent-list {
  display: contents;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  text-decoration: none;
  white-space: nowrap;
}
.chip .icon {
  width: 0.95rem;
  height: 0.95rem;
  color: hsl(var(--hue, 245) 65% 40%);
  color: light-dark(hsl(var(--hue, 245) 65% 40%), hsl(var(--hue, 245) 65% 74%));
}
.chip:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
}
.cat-nav .chip:is(:target-current, .\:target-current) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-text);
}

.cat-nav {
  position: sticky;
  top: var(--topbar-h);
  z-index: 5;
  display: flex;
  gap: 0.5rem;
  margin: 0 calc(clamp(1rem, 4vw, 3rem) * -1);
  padding: 0.7rem clamp(1rem, 4vw, 3rem);
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  scroll-target-group: auto;
  scrollbar-width: none;
}

.cat-section {
  margin: 2.75rem 0;
  scroll-margin-top: calc(var(--topbar-h) + 4rem);
}
.cat-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.cat-header h2 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.015em;
}
.cat-count {
  color: var(--text-faint);
  font-size: 0.85rem;
}
.cat-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-left: auto;
  font-size: 0.875rem;
  text-decoration: none;
}
.cat-link .icon {
  width: 1rem;
  height: 1rem;
}

/* ---------- Suggestions: calls to action + the form on /suggest/ ---------- */

.btn-primary {
  --on-accent: light-dark(#fff, #14153d); /* dark text on the light dark-mode accent */
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}
.btn-primary:hover {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
  color: var(--on-accent);
}
.btn-lg {
  padding: 0.75rem 1.25rem;
  font-size: 1rem;
}
.btn .icon {
  width: 1.05rem;
  height: 1.05rem;
}
.btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

/* Home: a line under the hero search, and a band after the categories */
.hero-suggest {
  margin: 1.5rem auto 0 !important;
  color: var(--text-muted);
  font-size: 0.95rem !important;
}
.hero-suggest a {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-left: 0.35rem;
  padding: 0.35rem 0.85rem;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
  text-decoration: none;
}
.hero-suggest a:hover {
  background: var(--accent);
  color: light-dark(#fff, #14153d);
}
.hero-suggest .icon {
  width: 1rem;
  height: 1rem;
}

.cta-band {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.25rem 1.5rem;
  margin: 3.5rem 0 1rem;
  padding: clamp(1.25rem, 4vw, 2rem);
  border: 1px solid var(--accent);
  border-radius: 14px;
  background: var(--accent-soft);
}
.cta-icon {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  flex: none;
  border-radius: 12px;
  background: var(--accent);
  color: light-dark(#fff, #14153d);
}
.cta-icon .icon {
  width: 1.5rem;
  height: 1.5rem;
}
.cta-text {
  flex: 1 1 20rem;
}
.cta-text h2 {
  margin: 0 0 0.35rem;
  font-size: 1.3rem;
  letter-spacing: -0.015em;
}
.cta-text p {
  margin: 0;
  color: var(--text-muted);
}

/* Sheet pages: a quiet line above the pager */
.suggest-cta {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  margin: 2.5rem 0 0;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.9rem;
}
.suggest-cta p {
  margin: 0;
}
.suggest-cta .icon {
  margin-top: 0.15rem;
  color: var(--text-faint);
}
.no-results-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}
.search-suggest {
  display: block;
  margin-top: 0.75rem;
  font-weight: 500;
}

/* The form */
.is-suggest .main {
  max-width: 46rem;
}
.suggest-form {
  display: grid;
  gap: 1.5rem;
  margin-top: 1.75rem;
}
.suggest-form[hidden],
.suggest:has(#sent:target) .suggest-form {
  display: none;
}
.field {
  display: grid;
  gap: 0.3rem;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.field > label,
.field > legend {
  padding: 0;
  font-weight: 600;
}
.field > legend {
  margin-bottom: 0.5rem;
}
.optional {
  color: var(--text-faint);
  font-weight: 400;
}
.hint {
  color: var(--text-muted);
  font-size: 0.875rem;
}
.suggest-form input:not([type='radio']),
.suggest-form textarea {
  width: 100%;
  min-height: 3rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
}
.suggest-form textarea {
  min-height: 9rem;
  resize: vertical;
}
.suggest-form input:focus-visible,
.suggest-form textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.choices {
  display: grid;
  gap: 0.5rem;
}
.choice {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
}
.choice:hover {
  border-color: var(--accent);
}
.choice:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.choice:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.choice input {
  width: 1.1rem;
  height: 1.1rem;
  margin: 0.2rem 0 0;
  flex: none;
}
.choice span {
  display: grid;
}
.choice small {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Errors appear only after you've left a field (or tried to send): :user-invalid */
.field-error {
  display: none;
  margin: 0.1rem 0 0;
  color: light-dark(#b42318, #ff8a80);
  font-size: 0.875rem;
  font-weight: 500;
}
.field-error::before {
  content: '⚠ ';
}
.field:has(:user-invalid) .field-error {
  display: block;
}
.suggest-form :is(input, textarea):user-invalid {
  border-color: light-dark(#b42318, #ff8a80);
}

.hp {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.form-status {
  min-height: 1.5em;
  margin: -0.5rem 0;
  color: var(--text-muted);
}
.form-status:empty {
  min-height: 0;
  margin: 0;
}
.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
}
.form-alt {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Result boxes: shown by app.js (.is-shown) or, without JavaScript, by the #sent / #error link */
.form-result {
  display: none;
  gap: 0.9rem;
  margin-top: 1.75rem;
  padding: 1.25rem 1.4rem;
  border-radius: 12px;
}
.form-result:is(:target, .is-shown) {
  display: flex;
}
.form-result:focus {
  outline: none;
}
.form-result p {
  margin: 0.35rem 0 0;
}
.form-result h2 {
  margin: 0;
  font-size: 1.2rem;
}
.form-sent {
  border: 1px solid light-dark(#a6e3bd, #1f6f43);
  background: light-dark(#ecfdf3, #0f2a1c);
}
.form-sent > .icon {
  width: 1.6rem;
  height: 1.6rem;
  color: light-dark(#067647, #6ce9a6);
}
.form-sent .btn {
  margin: 0.6rem 0.4rem 0 0;
}
.form-failed {
  border: 1px solid light-dark(#fda29b, #7a271a);
  background: light-dark(#fef3f2, #2b1210);
}

/* ---------- Text pages (/privacy/) ---------- */

.is-text .main {
  max-width: 46rem;
}
.text-page h1 {
  margin: 0.5rem 0 0.25rem;
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  letter-spacing: -0.02em;
}
.text-page-meta {
  margin: 0 0 1.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ---------- Footer ---------- */

.site-footer {
  padding: 1.5rem 1rem 2rem;
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 0.85rem;
  text-align: center;
}
.site-footer p {
  margin: 0.25rem 0;
}
.footer-legal {
  max-width: 44rem;
  margin: 0.75rem auto 0 !important;
  font-size: 0.78rem;
}

/* ---------- Search dialog ---------- */

.search {
  width: min(42rem, calc(100vw - 2rem));
  max-height: min(38rem, calc(100dvh - 4rem));
  margin: 8vh auto auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
.search[open] {
  display: flex;
  flex-direction: column;
}
.search::backdrop {
  background: rgb(10 12 18 / 0.55);
  backdrop-filter: blur(2px);
}
.search-head {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--accent);
}
.search-head .icon {
  width: 1.3rem;
  height: 1.3rem;
}
.search-head input {
  flex: 1;
  min-width: 0;
  height: 2rem;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 1.05rem;
}
.search-head input::-webkit-search-cancel-button {
  display: none;
}
.search-close {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  cursor: pointer;
}
.close-text {
  display: none;
  font-size: 0.95rem;
  font-weight: 500;
}
.search-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.search-results {
  margin: 0;
  padding: 0.4rem;
  list-style: none;
}
.search-results:empty {
  display: none;
}
.sr-label {
  padding: 0.6rem 0.75rem 0.3rem;
  color: var(--text-faint);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.sr-item a {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  column-gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
}
.sr-item[aria-selected='true'] a {
  background: var(--accent-soft);
}
.sr-icon {
  display: grid;
  grid-row: span 2;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 7px;
  background: hsl(var(--hue, 245) 85% 95%);
  background: light-dark(hsl(var(--hue, 245) 85% 95%), hsl(var(--hue, 245) 35% 18%));
  color: hsl(var(--hue, 245) 65% 40%);
  color: light-dark(hsl(var(--hue, 245) 65% 40%), hsl(var(--hue, 245) 65% 74%));
}
.sr-icon .icon {
  width: 1rem;
  height: 1rem;
}
.sr-main {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  min-width: 0;
}
.sr-key {
  flex: none;
  max-width: 60%;
  overflow: hidden;
  padding: 0 0.4rem;
  border: 1px solid var(--code-border);
  border-radius: 5px;
  background: var(--code-bg);
  font-family: var(--mono);
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sr-title {
  font-weight: 600;
}
.sr-val {
  overflow: hidden;
  font-size: 0.9rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sr-path {
  grid-column: 2;
  overflow: hidden;
  color: var(--text-faint);
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sr-item[aria-selected='true'] .sr-path {
  color: var(--accent-text);
}
.search mark {
  border-radius: 2px;
  background: var(--mark);
  color: inherit;
}
.search-empty {
  padding: 1.5rem 1.25rem;
  color: var(--text-muted);
  font-size: 0.92rem;
  text-align: center;
}
.search-empty:empty {
  display: none;
}
.search-suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.85rem;
}
.search-suggestions button {
  padding: 0.25rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-soft);
  font-size: 0.85rem;
  cursor: pointer;
}
.search-suggestions button:hover {
  border-color: var(--accent);
}
.search-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 0.55rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-faint);
  font-size: 0.75rem;
}
.search-count {
  margin-left: auto;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  z-index: 200;
  max-width: calc(100vw - 2rem);
  padding: 0.55rem 1rem;
  overflow: hidden;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.875rem;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 0.5rem);
  transition:
    opacity 0.2s,
    transform 0.2s;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Responsive ---------- */

@media (min-width: 900px) {
  .cat-nav {
    flex-wrap: wrap;
    justify-content: center;
    overflow: visible;
  }
}

@media (min-width: 1280px) {
  .page-grid {
    grid-template-columns: minmax(0, 1fr) var(--toc-w);
  }
  .toc {
    position: sticky;
    top: calc(var(--topbar-h) + 1.5rem);
    display: block;
    max-height: calc(100dvh - var(--topbar-h) - 3rem);
    overflow-y: auto;
    scrollbar-width: thin;
  }
  .toc-mobile {
    display: none;
  }
}

@media (max-width: 1023px) {
  .menu-btn {
    display: grid;
    margin-left: -0.4rem;
  }
  .shell.has-sidebar {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    bottom: 0;
    left: 0;
    z-index: 40;
    width: min(20rem, 85vw);
    height: auto;
    box-shadow: var(--shadow-lg);
    visibility: hidden;
    transform: translateX(-105%);
    transition:
      transform 0.22s ease,
      visibility 0s linear 0.22s;
    view-transition-name: none;
  }
  .nav-open .sidebar {
    visibility: visible;
    transform: none;
    transition: transform 0.22s ease;
  }
  .nav-backdrop:not([hidden]) {
    position: fixed;
    inset: var(--topbar-h) 0 0;
    z-index: 39;
    display: block;
    background: rgb(10 12 18 / 0.45);
  }
}

@media (max-width: 640px) {
  :root {
    --topbar-h: 3.25rem;
  }
  .brand span {
    display: none;
  }
  .search-trigger {
    width: auto;
    flex: 1;
  }
  .search-trigger kbd,
  .hero-search kbd,
  .filter kbd,
  .footer-keys,
  .search-foot {
    display: none;
  }
  .sheet-header {
    gap: 0.85rem;
  }
  .cat-icon.lg {
    width: 2.6rem;
    height: 2.6rem;
  }
  .filter {
    max-width: none;
  }
  .prose table:has(th:nth-child(2):last-child) td:first-child {
    width: 45%;
  }
  .prose th,
  .prose td {
    padding: 0.45rem 0.65rem;
  }
  .prose tr.cmd-details > td {
    padding: 0 0.4rem 0.6rem;
  }
  .cmd-panel {
    padding: 0.7rem 0.7rem 0.4rem;
  }
  .prose .cmd-panel table td:first-child {
    white-space: normal;
  }
  .prose .cmd-panel td:first-child code {
    white-space: nowrap;
    overflow-wrap: normal;
  }
  .close-text {
    display: inline;
  }
  .search-close kbd {
    display: none;
  }
  .sr-main {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
  }
  .sr-key {
    max-width: 100%;
  }
  .sr-val {
    max-width: 100%;
  }
  .sr-icon {
    grid-row: span 3;
  }
  .search {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }
  .pager {
    grid-template-columns: 1fr;
  }
  .pager-link.next {
    align-items: flex-start;
    text-align: left;
  }
  .cat-link {
    margin-left: 0;
    width: 100%;
  }
}

/* ---------- Motion ---------- */

@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-duration: 0.18s;
  }
  .prose tr:target {
    animation: flash 1.2s ease-out;
  }
  @keyframes flash {
    from {
      background: var(--mark);
    }
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
  .card:hover {
    transform: none;
  }
}

/* ---------- Print ---------- */

@media print {
  .topbar,
  .sidebar,
  .toc,
  .toc-mobile,
  .filter-bar,
  .pager,
  .site-footer,
  .heading-anchor,
  .copy-btn,
  .breadcrumb,
  .search,
  .toast {
    display: none !important;
  }
  .shell.has-sidebar {
    display: block;
  }
  body {
    background: #fff;
    color: #000;
    font-size: 10.5pt;
  }
  .table-wrap {
    overflow: visible;
    border-color: #ccc;
  }
  .prose tr,
  .prose pre {
    break-inside: avoid;
  }
  .prose h2 {
    break-after: avoid;
  }
}
