:root {
  --bg: #fafafa;
  --bg-secondary: #f4f4f5;
  --bg-card: #ffffff;
  --border: #d4d4d8;
  --border-soft: #e4e4e7;
  --text: #18181b;
  --text-secondary: #52525b;
  --text-muted: #71717a;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --accent-text: #1d4ed8;
  --code-bg: #f4f4f5;
  --code-text: #7c3aed;
  --shadow: rgba(0, 0, 0, 0.06);

  --radius: 0.75rem;
  --radius-sm: 0.5rem;
  --maxw: 52rem;

  /* Theme hooks consumed by the shared <command-palette> component.
     These reference our tokens above, so they follow light/dark automatically. */
  --surface: var(--bg-card);
  --surface-2: var(--bg-secondary);
  --text-dim: var(--text-muted);
  --accent-dim: var(--accent-soft);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #09090b;
    --bg-secondary: #18181b;
    --bg-card: #141416;
    --border: #3f3f46;
    --border-soft: #27272a;
    --text: #fafafa;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --accent: #60a5fa;
    --accent-soft: #1e3a5f;
    --accent-text: #93c5fd;
    --code-bg: #27272a;
    --code-text: #c4b5fd;
    --shadow: rgba(0, 0, 0, 0.4);
  }
}

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

[hidden] {
  display: none !important;
}

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.6;
  padding: 1rem;
  -webkit-text-size-adjust: 100%;
}

.container {
  width: 100%;
  max-width: var(--maxw);
  margin-inline: auto;
}

code {
  font-family: "Cascadia Code", "Fira Code", ui-monospace, "SF Mono",
    Menlo, monospace;
  font-size: 0.85em;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 0.1em 0.35em;
  border-radius: 0.3rem;
  word-break: break-word;
}

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

/* ---------------------------------------------------------- page header */
.page-head {
  padding: 1rem 0 0.5rem;
}

h1 {
  font-size: clamp(1.7rem, 5vw, 2.4rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

h1 .at {
  display: inline-grid;
  place-items: center;
  width: 1.6em;
  height: 1.6em;
  font-size: 0.7em;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  flex: none;
}

@media (prefers-color-scheme: dark) {
  h1 .at { color: #09090b; }
}

.tagline {
  margin-top: 0.75rem;
  color: var(--text-secondary);
  font-size: 1.02rem;
  max-width: 42rem;
}

/* ------------------------------------------------------------ explainer */
.explainer {
  margin: 1.5rem 0;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px var(--shadow);
  overflow: hidden;
}

.explainer > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  font-weight: 600;
  font-size: 1.05rem;
  user-select: none;
}

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

.explainer > summary:hover {
  color: var(--accent-text);
}

.explainer .chevron {
  flex: none;
  width: 0.7rem;
  height: 0.7rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.2s ease;
  margin-right: 0.25rem;
}

.explainer[open] .chevron {
  transform: rotate(-135deg);
}

.explainer-body {
  padding: 0 1.25rem 1.25rem;
  border-top: 1px solid var(--border-soft);
  padding-top: 1rem;
}

.explainer-body p {
  margin-bottom: 0.85rem;
  color: var(--text-secondary);
}

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

.explainer-body ol {
  margin: 0 0 0.85rem;
  padding-left: 1.3rem;
  display: grid;
  gap: 0.7rem;
}

.explainer-body li {
  color: var(--text-secondary);
}

.explainer-links {
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* ------------------------------------------------------------- controls */
.controls {
  margin-bottom: 0.75rem;
}

/* Search entry point — looks like a search field, opens the palette. */
.quick-jump {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.7rem 0.75rem;
  font: inherit;
  font-size: 1rem;
  text-align: left;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.quick-jump:hover,
.quick-jump:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.qj-icon {
  flex: none;
  width: 1.05rem;
  height: 1.05rem;
  background: currentColor;
  -webkit-mask: no-repeat center / contain
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='currentColor' d='M9.5 3a6.5 6.5 0 0 1 5.25 10.34l5.2 5.2-1.41 1.42-5.2-5.2A6.5 6.5 0 1 1 9.5 3m0 2a4.5 4.5 0 1 0 0 9 4.5 4.5 0 0 0 0-9'/%3E%3C/svg%3E");
  mask: no-repeat center / contain
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='currentColor' d='M9.5 3a6.5 6.5 0 0 1 5.25 10.34l5.2 5.2-1.41 1.42-5.2-5.2A6.5 6.5 0 1 1 9.5 3m0 2a4.5 4.5 0 1 0 0 9 4.5 4.5 0 0 0 0-9'/%3E%3C/svg%3E");
}

.quick-jump .qj-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quick-jump kbd {
  flex: none;
  font-family: inherit;
  font-size: 0.78rem;
  padding: 0.1rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 0.3rem;
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

/* Floating search button — a compact, opaque sticky affordance for mobile,
   where there's no keyboard shortcut. Hidden on larger screens. */
.search-fab {
  display: none;
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 20;
  width: 3.25rem;
  height: 3.25rem;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  place-items: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
}

@media (prefers-color-scheme: dark) {
  .search-fab { color: #09090b; }
}

.search-fab .qj-icon {
  width: 1.4rem;
  height: 1.4rem;
}

.count {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* ------------------------------------------------------------- glossary */
.cat-section {
  margin-bottom: 2rem;
  scroll-margin-top: 1rem;
}

.cat-head {
  margin-bottom: 0.75rem;
}

.cat-head h2 {
  font-size: 1.3rem;
  letter-spacing: -0.01em;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.cat-head .cat-count {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

.cat-head .cat-blurb {
  font-size: 0.92rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}

.term-list {
  display: grid;
  gap: 0.6rem;
}

.term-card {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: 0 1px 2px var(--shadow);
  scroll-margin-top: 1rem;
}

.term-card:target {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.term-top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.4rem 0.6rem;
  margin-bottom: 0.4rem;
}

.term-name {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.term-abbr {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border: 1px solid var(--border-soft);
  padding: 0.05rem 0.45rem;
  border-radius: 0.3rem;
}

.term-aka {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}

.term-def {
  color: var(--text-secondary);
  font-size: 0.97rem;
}

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

.xlink {
  color: var(--accent-text);
  text-decoration: none;
  border-bottom: 1px dashed color-mix(in srgb, var(--accent) 45%, transparent);
  cursor: pointer;
}

.xlink:hover {
  border-bottom-style: solid;
}

.term-ref {
  margin-top: 0.7rem;
}

.term-ref a {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--accent-text);
  text-decoration: none;
}

.term-ref a:hover {
  text-decoration: underline;
}

.term-ref a::after {
  content: "↗";
  font-size: 0.9em;
  opacity: 0.7;
}

/* --------------------------------------------------------------- footer */
.page-foot {
  margin-top: 2rem;
  padding: 1.5rem 0 1rem;
  border-top: 1px solid var(--border-soft);
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

/* --------------------------------------------------------------- mobile */
@media (max-width: 639px) {
  .search-fab {
    display: grid;
  }
}

/* ------------------------------------------------------------ desktop up */
@media (min-width: 640px) {
  body {
    padding: 2rem;
  }

  .term-list {
    gap: 0.75rem;
  }
}
