/* =========================================================================
   Riferimento API di nanos world — foglio di stile unico
   Tema chiaro/scuro con tre stati: chiaro, scuro, sistema.
   ========================================================================= */

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

:root {
  color-scheme: light;

  /* Superfici */
  --bg: #f7f8fa;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-sunken: #f1f3f7;
  --surface-hover: #eef1f6;
  --border: #dde2ea;
  --border-strong: #c3cbd8;

  /* Testo */
  --text: #131a24;
  --text-muted: #5a6879;
  --text-faint: #8b97a8;

  /* Accento: verde nanos */
  --accent: #0f8a6d;
  --accent-hover: #0c705a;
  --accent-text: #0a6350;
  --accent-soft: #e2f3ee;
  --accent-contrast: #ffffff;

  /* Semantica dei badge — coppie verificate per contrasto AA su testo piccolo */
  --server-bg: #fde8e0;
  --server-text: #8f3d18;
  --client-bg: #e2ecfd;
  --client-text: #1f4d94;
  --shared-bg: #e0f0e6;
  --shared-text: #1f6b41;
  --authority-bg: #efe6fb;
  --authority-text: #5b3a9b;
  --edge-bg: #fdf0d8;
  --edge-text: #855108;
  --removed-bg: #fbe3e3;
  --removed-text: #a02a2a;

  --fast: #199a63;
  --moderate: #b8860b;
  --slow: #c0562e;

  /* Codice — palette chiara ad alto contrasto */
  --code-bg: #fbfcfe;
  --code-border: #dde2ea;
  --code-text: #1c2430;
  --code-head-bg: #f1f3f7;
  --tok-kw: #9016a8;
  --tok-str: #9b2c1e;
  --tok-num: #0f6b4a;
  --tok-comment: #5f7285;
  --tok-type: #0d6e86;
  --tok-fn: #7a4c05;
  --tok-name: #1c2430;
  --tok-prop: #1b4f8a;
  --tok-op: #46536a;
  --tok-punct: #57647a;

  --shadow-sm: 0 1px 2px rgb(16 24 40 / 6%);
  --shadow-md: 0 4px 16px rgb(16 24 40 / 8%);
  --shadow-lg: 0 12px 40px rgb(16 24 40 / 14%);

  --radius: 10px;
  --radius-lg: 14px;

  --topbar-h: 60px;
  --sidebar-w: 268px;
  --toc-w: 216px;
  --content-max: 860px;

  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono",
    Menlo, Consolas, "Liberation Mono", monospace;
}

/* Tema scuro: applicato dal sistema, salvo scelta esplicita del chiaro. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --bg: #0d1117;
    --bg-elevated: #141b24;
    --surface: #161d27;
    --surface-sunken: #11171f;
    --surface-hover: #1d2631;
    --border: #262f3c;
    --border-strong: #3a4756;

    --text: #e6edf5;
    --text-muted: #9aa8b8;
    --text-faint: #6e7d8f;

    --accent: #2bb894;
    --accent-hover: #35cca6;
    --accent-text: #5fd7b6;
    --accent-soft: #10312a;
    --accent-contrast: #04140f;

    --server-bg: #3a1e13;
    --server-text: #f0a988;
    --client-bg: #142a4a;
    --client-text: #97bdf2;
    --shared-bg: #13301f;
    --shared-text: #86d3a4;
    --authority-bg: #2a1f45;
    --authority-text: #bda6ee;
    --edge-bg: #3a2c0d;
    --edge-text: #e6be6a;
    --removed-bg: #3d1a1a;
    --removed-text: #ee9a9a;

    --fast: #45c88c;
    --moderate: #d8ac4a;
    --slow: #e58a62;

    --code-bg: #0f151d;
    --code-border: #262f3c;
    --code-text: #d7e2ee;
    --code-head-bg: #161d27;
    --tok-kw: #d18ff5;
    --tok-str: #eb9a83;
    --tok-num: #7fd8a8;
    --tok-comment: #7e8fa3;
    --tok-type: #5cc9dd;
    --tok-fn: #e5c07b;
    --tok-name: #d7e2ee;
    --tok-prop: #86bdf5;
    --tok-op: #a9b6c8;
    --tok-punct: #93a1b3;

    --shadow-sm: 0 1px 2px rgb(0 0 0 / 40%);
    --shadow-md: 0 4px 16px rgb(0 0 0 / 45%);
    --shadow-lg: 0 12px 40px rgb(0 0 0 / 55%);
  }
}

/* Scelta esplicita dello scuro: deve vincere anche se il sistema è chiaro. */
:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0d1117;
  --bg-elevated: #141b24;
  --surface: #161d27;
  --surface-sunken: #11171f;
  --surface-hover: #1d2631;
  --border: #262f3c;
  --border-strong: #3a4756;

  --text: #e6edf5;
  --text-muted: #9aa8b8;
  --text-faint: #6e7d8f;

  --accent: #2bb894;
  --accent-hover: #35cca6;
  --accent-text: #5fd7b6;
  --accent-soft: #10312a;
  --accent-contrast: #04140f;

  --server-bg: #3a1e13;
  --server-text: #f0a988;
  --client-bg: #142a4a;
  --client-text: #97bdf2;
  --shared-bg: #13301f;
  --shared-text: #86d3a4;
  --authority-bg: #2a1f45;
  --authority-text: #bda6ee;
  --edge-bg: #3a2c0d;
  --edge-text: #e6be6a;
  --removed-bg: #3d1a1a;
  --removed-text: #ee9a9a;

  --fast: #45c88c;
  --moderate: #d8ac4a;
  --slow: #e58a62;

  --code-bg: #0f151d;
  --code-border: #262f3c;
  --code-text: #d7e2ee;
  --code-head-bg: #161d27;
  --tok-kw: #d18ff5;
  --tok-str: #eb9a83;
  --tok-num: #7fd8a8;
  --tok-comment: #7e8fa3;
  --tok-type: #5cc9dd;
  --tok-fn: #e5c07b;
  --tok-name: #d7e2ee;
  --tok-prop: #86bdf5;
  --tok-op: #a9b6c8;
  --tok-punct: #93a1b3;

  --shadow-sm: 0 1px 2px rgb(0 0 0 / 40%);
  --shadow-md: 0 4px 16px rgb(0 0 0 / 45%);
  --shadow-lg: 0 12px 40px rgb(0 0 0 / 55%);
}

/* ------------------------------------------------------------------ base */

html {
  scroll-behavior: smooth;
  /* Le ancore non devono finire sotto la testata fissa. */
  scroll-padding-top: calc(var(--topbar-h) + 16px);
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15.5px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent-text);
  text-decoration-color: color-mix(in srgb, var(--accent-text) 35%, transparent);
  text-underline-offset: 2px;
}

a:hover {
  text-decoration-color: currentColor;
}

code,
pre,
kbd {
  font-family: var(--font-mono);
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: -100px;
  left: 12px;
  z-index: 100;
  padding: 10px 16px;
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: 0 0 var(--radius) var(--radius);
  font-weight: 600;
  text-decoration: none;
  transition: top 0.15s;
}

.skip-link:focus {
  top: 0;
}

.muted {
  color: var(--text-muted);
}

/* --------------------------------------------------------------- testata */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 100%;
  max-width: 1560px;
  margin: 0 auto;
  padding: 0 18px;
}

.menu-button {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.menu-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-text strong {
  font-size: 0.92rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.brand-text span {
  color: var(--text-faint);
  font-size: 0.72rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  flex-shrink: 0;
}

.topbar-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-decoration: none;
  white-space: nowrap;
}

.topbar-link:hover {
  color: var(--text);
}

.ext-icon {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.lang-switch {
  display: flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-sunken);
}

.lang-link {
  padding: 4px 9px;
  border-radius: 7px;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 550;
  text-decoration: none;
}

.lang-link:hover {
  background: var(--surface);
  color: var(--text);
}

.theme-switch {
  display: flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-sunken);
}

.theme-switch button {
  display: grid;
  place-items: center;
  width: 28px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--text-faint);
  cursor: pointer;
}

.theme-switch button svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-switch button:hover {
  color: var(--text);
}

.theme-switch button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--accent-text);
  box-shadow: var(--shadow-sm);
}

/* --------------------------------------------------------------- ricerca */

.search {
  position: relative;
  flex: 1;
  max-width: 460px;
  margin: 0 auto;
}

.search-icon {
  position: absolute;
  top: 50%;
  left: 11px;
  width: 16px;
  height: 16px;
  transform: translateY(-50%);
  fill: none;
  stroke: var(--text-faint);
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 38px;
  padding: 0 40px 0 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-sunken);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
}

.search-input::placeholder {
  color: var(--text-faint);
}

.search-input:focus {
  background: var(--surface);
  border-color: var(--accent);
  outline: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
  outline-offset: 0;
}

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

.search-kbd {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text-faint);
  font-size: 0.72rem;
  line-height: 1.4;
  pointer-events: none;
}

.search-input:focus ~ .search-kbd {
  opacity: 0;
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 50;
  max-height: min(64vh, 520px);
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-lg);
  overscroll-behavior: contain;
}

.search-results[hidden] {
  display: none;
}

.search-result {
  display: block;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
}

.search-result:hover,
.search-result.is-active {
  background: var(--surface-hover);
}

.search-result.is-active {
  box-shadow: inset 2px 0 0 var(--accent);
}

.search-result-top {
  display: flex;
  align-items: baseline;
  gap: 7px;
  flex-wrap: wrap;
}

.search-result-name {
  font-family: var(--font-mono);
  font-size: 0.87rem;
  font-weight: 600;
}

.search-result-name mark {
  background: color-mix(in srgb, var(--accent) 26%, transparent);
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}

.search-result-owner {
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 0.76rem;
}

.search-result-desc {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 1px;
  color: var(--text-muted);
  font-size: 0.79rem;
}

.search-empty {
  padding: 22px 14px;
  color: var(--text-muted);
  font-size: 0.87rem;
  text-align: center;
}

.search-empty strong {
  color: var(--text);
  font-family: var(--font-mono);
}

.search-empty p {
  margin: 6px 0 0;
  color: var(--text-faint);
  font-size: 0.8rem;
}

.search-group-label {
  padding: 8px 10px 4px;
  color: var(--text-faint);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ---------------------------------------------------------------- telaio */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  gap: 30px;
  max-width: 1560px;
  margin: 0 auto;
  padding: 0 18px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: var(--topbar-h);
  max-height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px 4px 40px 0;
  scrollbar-width: thin;
}

.nav-section + .nav-section {
  margin-top: 20px;
}

.nav-title {
  margin: 0 0 6px;
  padding: 0 10px;
  color: var(--text-faint);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

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

.nav-link {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  border-radius: 7px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  text-decoration: none;
}

.nav-link:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.nav-link.is-active {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}

.nav-tag {
  padding: 0 5px;
  border-radius: 4px;
  background: var(--surface-sunken);
  color: var(--text-faint);
  font-family: var(--font-sans);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.nav-count {
  margin-left: auto;
  color: var(--text-faint);
  font-size: 0.72rem;
}

.sidebar-scrim {
  display: none;
}

.main {
  min-width: 0;
  max-width: var(--content-max);
  padding: 24px 0 72px;
}

.main:focus {
  outline: none;
}

.toc {
  position: sticky;
  top: var(--topbar-h);
  max-height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 26px 0 40px;
}

.toc-title {
  margin: 0 0 8px;
  color: var(--text-faint);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.toc-list {
  margin: 0;
  padding: 0;
  list-style: none;
  border-left: 2px solid var(--border);
}

.toc-list a {
  display: block;
  padding: 4px 0 4px 12px;
  margin-left: -2px;
  border-left: 2px solid transparent;
  color: var(--text-muted);
  font-size: 0.81rem;
  text-decoration: none;
}

.toc-list a:hover {
  color: var(--text);
}

.toc-list a.is-active {
  border-left-color: var(--accent);
  color: var(--accent-text);
  font-weight: 550;
}

/* -------------------------------------------------------------- briciole */

.breadcrumb {
  margin-bottom: 14px;
}

.breadcrumb ol {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.8rem;
}

.crumb + .crumb::before {
  content: "/";
  margin-right: 5px;
  color: var(--text-faint);
}

.crumb a {
  color: var(--text-muted);
  text-decoration: none;
}

.crumb a:hover {
  color: var(--accent-text);
  text-decoration: underline;
}

.crumb [aria-current="page"] {
  color: var(--text);
  font-weight: 550;
}

/* -------------------------------------------------------------- intestata */

.page-head {
  padding-bottom: 20px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.page-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 10px 0 12px;
  font-size: clamp(1.55rem, 1.1rem + 1.8vw, 2.1rem);
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.page-title code {
  font-size: inherit;
  font-weight: inherit;
}

.title-owner {
  color: var(--text-faint);
  font-weight: 500;
}

.title-sep {
  color: var(--text-faint);
}

.copy-link {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-faint);
  cursor: pointer;
}

.copy-link svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

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

.copy-link.is-done {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-text);
}

.page-stats {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin: 12px 0 0;
  color: var(--text-faint);
  font-size: 0.82rem;
}

.prose {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.65;
}

.prose-original {
  color: var(--text-muted);
  font-size: 0.92rem;
}

.original {
  margin: 8px 0 0;
}

.original summary {
  display: inline-block;
  color: var(--text-faint);
  font-size: 0.79rem;
  cursor: pointer;
  list-style: none;
}

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

.original summary::before {
  content: "▸ ";
}

.original[open] summary::before {
  content: "▾ ";
}

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

.original > .prose {
  padding: 10px 12px;
  margin-top: 6px;
  border-left: 2px solid var(--border-strong);
  background: var(--surface-sunken);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.untranslated-note {
  display: inline-block;
  margin: 6px 0 0;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--edge-bg);
  color: var(--edge-text);
  font-size: 0.72rem;
  font-weight: 600;
}

/* --------------------------------------------------------------- badge */

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-sunken);
  color: var(--text-muted);
  font-size: 0.73rem;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
  text-decoration: none;
}

.badge-server { background: var(--server-bg); color: var(--server-text); }
.badge-client { background: var(--client-bg); color: var(--client-text); }
.badge-shared { background: var(--shared-bg); color: var(--shared-text); }
.badge-authority { background: var(--authority-bg); color: var(--authority-text); }
.badge-edge { background: var(--edge-bg); color: var(--edge-text); }
.badge-removed { background: var(--removed-bg); color: var(--removed-text); }
.badge-base { background: var(--accent-soft); color: var(--accent-text); }

.badge-kind {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
}

.badge-inherited {
  background: transparent;
  border: 1px dashed var(--border-strong);
  color: var(--text-faint);
  font-weight: 500;
}

.badge-inherited:hover {
  border-color: var(--accent);
  color: var(--accent-text);
}

/* Il costo si legge a colpo d'occhio dai pallini, non solo dal colore:
   il colore da solo non basta per chi non lo distingue. */
.badge-efficiency {
  background: transparent;
  border: 1px solid var(--border);
}

.efficiency-dots {
  display: inline-block;
  width: 22px;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(
    to right,
    currentColor var(--fill, 33%),
    color-mix(in srgb, currentColor 22%, transparent) var(--fill, 33%)
  );
}

.badge-fast { color: var(--fast); --fill: 33%; }
.badge-moderate { color: var(--moderate); --fill: 66%; }
.badge-slow { color: var(--slow); --fill: 100%; }

/* ------------------------------------------------------------ gerarchia */

.hierarchy {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px;
  margin: 20px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-sunken);
}

.hierarchy-row {
  display: flex;
  gap: 10px;
  align-items: baseline;
  flex-wrap: wrap;
}

.hierarchy-label {
  flex-shrink: 0;
  color: var(--text-faint);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.hierarchy-chain,
.hierarchy-children {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.85rem;
}

.hierarchy-chain li + li::before {
  content: "→";
  margin-right: 5px;
  color: var(--text-faint);
}

.hierarchy-chain [aria-current="true"] code {
  color: var(--accent-text);
  font-weight: 650;
}

.hierarchy-children li a {
  display: inline-block;
  padding: 1px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  text-decoration: none;
}

.hierarchy-children li a:hover {
  border-color: var(--accent);
}

/* --------------------------------------------------------------- sezioni */

.section,
.member-section {
  margin: 32px 0;
  scroll-margin-top: calc(var(--topbar-h) + 16px);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 12px;
  font-size: 1.12rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.section-count {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-sunken);
  color: var(--text-faint);
  font-size: 0.73rem;
  font-weight: 600;
}

/* ----------------------------------------------------------- elenco membri */

.member-list {
  display: grid;
  gap: 6px;
  min-width: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.member-row {
  display: flex;
  align-items: center;
  gap: 12px;
  /* Senza questo il `min-width: auto` dei grid item fa allargare la riga
     fino alla descrizione più lunga, sfondando la colonna del contenuto. */
  min-width: 0;
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color 0.12s, background 0.12s;
}

.member-row:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.member-link {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex: 1;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

/* L'intera riga è cliccabile, ma il link resta un vero <a>:
   navigabile da tastiera e apribile in una nuova scheda. */
.member-link::after {
  content: "";
  position: absolute;
  inset: 0;
}

.member-row {
  position: relative;
}

.member-name {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 0.87rem;
  font-weight: 600;
  color: var(--accent-text);
}

.member-row:hover .member-name {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.member-desc {
  min-width: 0;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 0.83rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.member-row-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  flex-wrap: wrap;
  /* Sopra lo pseudo-elemento del link, così i badge restano cliccabili. */
  position: relative;
  z-index: 1;
}

.inherited-group {
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-sunken);
}

.inherited-group > summary {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 13px;
  cursor: pointer;
  font-size: 0.87rem;
  list-style: none;
}

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

.inherited-group > summary::before {
  content: "▸";
  color: var(--text-faint);
  font-size: 0.75rem;
}

.inherited-group[open] > summary::before {
  content: "▾";
}

.inherited-from {
  font-family: var(--font-mono);
  font-weight: 600;
}

.inherited-group .member-list {
  padding: 0 8px 8px;
}

/* --------------------------------------------------------------- codice */

.code-block {
  margin: 0 0 12px;
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  background: var(--code-bg);
  overflow: hidden;
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 8px 5px 12px;
  border-bottom: 1px solid var(--code-border);
  background: var(--code-head-bg);
}

.code-lang {
  color: var(--text-faint);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.code-copy {
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.code-copy:hover {
  border-color: var(--accent);
  color: var(--accent-text);
}

.code-copy.is-done {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-text);
}

.code-pre {
  margin: 0;
  padding: 13px 15px;
  overflow-x: auto;
  color: var(--code-text);
  font-size: 0.855rem;
  line-height: 1.62;
  tab-size: 2;
}

.tok-kw { color: var(--tok-kw); font-weight: 600; }
.tok-str { color: var(--tok-str); }
.tok-num { color: var(--tok-num); }
.tok-comment { color: var(--tok-comment); font-style: italic; }
.tok-type { color: var(--tok-type); }
.tok-fn { color: var(--tok-fn); }
.tok-name { color: var(--tok-name); }
.tok-prop { color: var(--tok-prop); }
.tok-op { color: var(--tok-op); }
.tok-punct { color: var(--tok-punct); }

.inline-code {
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-sunken);
  font-size: 0.87em;
  white-space: nowrap;
}

/* --------------------------------------------------------------- tabelle */

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.param-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}

.param-table th {
  padding: 9px 13px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-sunken);
  color: var(--text-muted);
  font-size: 0.73rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

.param-table td {
  padding: 10px 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.param-table tr:last-child td {
  border-bottom: 0;
}

.param-name {
  white-space: nowrap;
}

.param-flag {
  display: block;
  margin-top: 3px;
  color: var(--text-faint);
  font-size: 0.7rem;
  font-style: italic;
}

.param-desc {
  min-width: 220px;
}

.enum-value code {
  color: var(--tok-num);
}

.type {
  font-family: var(--font-mono);
  font-size: 0.83rem;
  white-space: nowrap;
}

.type-name {
  color: var(--tok-type);
}

.type-link {
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}

.type-link:hover {
  text-decoration-style: solid;
}

.callback,
.return-fields {
  margin-top: 8px;
  padding: 8px 10px;
  border-left: 2px solid var(--border-strong);
  background: var(--surface-sunken);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.callback-title,
.return-fields-title {
  display: block;
  margin-bottom: 4px;
  color: var(--text-faint);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.callback-args,
.return-fields ul {
  display: grid;
  gap: 4px;
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.82rem;
}

.callback-desc {
  color: var(--text-muted);
}

.return-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.return-item {
  display: flex;
  align-items: baseline;
  gap: 9px;
  flex-wrap: wrap;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.return-name {
  color: var(--text-muted);
}

.return-desc {
  flex: 1;
  min-width: 200px;
  color: var(--text-muted);
  font-size: 0.87rem;
}

/* ------------------------------------------------------------- paginazione */

.member-pager {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 36px 0 0;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.pager-link {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 46%;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}

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

.pager-next {
  margin-left: auto;
  flex-direction: row-reverse;
}

.pager-dir {
  color: var(--text-faint);
}

.pager-name {
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.button {
  display: inline-block;
  padding: 8px 16px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 0.87rem;
  font-weight: 600;
  text-decoration: none;
}

.button:hover {
  background: var(--accent-hover);
}

/* --------------------------------------------------------------- schede */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(248px, 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 15px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  transition: border-color 0.12s, transform 0.12s;
}

.card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.card-link {
  color: inherit;
  text-decoration: none;
}

.card-link::after {
  content: "";
  position: absolute;
  inset: 0;
}

.card-title {
  margin: 0 0 5px;
  font-size: 0.98rem;
  font-weight: 650;
}

.card-title code {
  color: var(--accent-text);
}

.card-desc {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0;
  color: var(--text-muted);
  font-size: 0.83rem;
}

.card-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin: 11px 0 0;
  color: var(--text-faint);
  font-size: 0.76rem;
}

/* ------------------------------------------------------------------ home */

.hero {
  padding: 28px 0 22px;
}

.hero-title {
  margin: 0 0 10px;
  font-size: clamp(1.8rem, 1.2rem + 2.6vw, 2.6rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.hero-lead {
  max-width: 62ch;
  margin: 0 0 12px;
  color: var(--text-muted);
  font-size: 1.05rem;
}

.hero-hint {
  margin: 0;
  color: var(--text-faint);
  font-size: 0.85rem;
}

.hero-hint kbd {
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface);
  font-size: 0.8em;
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 10px;
  margin: 0 0 30px;
  padding: 0;
  list-style: none;
}

.tile a {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: inherit;
  text-decoration: none;
}

.tile a:hover {
  border-color: var(--accent);
}

.tile-count {
  color: var(--accent-text);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.tile-label {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.build-stats {
  margin-top: 28px;
  font-size: 0.8rem;
}

.page-error {
  padding: 48px 0;
  text-align: center;
}

/* ---------------------------------------------------------------- piede */

.footer {
  margin-top: 40px;
  border-top: 1px solid var(--border);
  background: var(--surface-sunken);
}

.footer-inner {
  max-width: 1560px;
  margin: 0 auto;
  padding: 26px 18px 34px;
}

.footer-warning {
  max-width: 82ch;
  margin: 0 0 8px;
  font-size: 0.87rem;
}

.footer-note {
  max-width: 82ch;
  margin: 0 0 14px;
  color: var(--text-muted);
  font-size: 0.81rem;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin: 0 0 10px;
  padding: 0;
  list-style: none;
  font-size: 0.85rem;
}

.footer-meta {
  margin: 0;
  color: var(--text-faint);
  font-size: 0.78rem;
}

/* ------------------------------------------------------------- adattivo */

@media (max-width: 1240px) {
  .shell {
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  }
  .toc {
    display: none;
  }
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  .menu-button {
    display: inline-flex;
  }

  .brand-text {
    display: none;
  }

  /* Su schermo stretto la navigazione è un pannello che scorre da sinistra,
     invece di spingere il contenuto sotto un elenco di 69 voci. */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 60;
    width: min(84vw, 320px);
    max-height: none;
    padding: 18px 14px 40px;
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    visibility: hidden;
  }

  .sidebar.is-open {
    transform: translateX(0);
    visibility: visible;
  }

  .sidebar-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgb(0 0 0 / 45%);
  }

  .sidebar-scrim[hidden] {
    display: none;
  }

  .main {
    padding: 18px 0 56px;
  }

  .topbar-link {
    display: none;
  }

  .search {
    max-width: none;
  }

  .search-kbd {
    display: none;
  }
}

@media (max-width: 620px) {
  body {
    font-size: 15px;
  }

  .topbar-inner {
    padding: 0 12px;
    gap: 9px;
  }

  .shell,
  .footer-inner {
    padding-left: 12px;
    padding-right: 12px;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
  }

  .lang-switch {
    display: none;
  }

  /* La riga del membro passa su due livelli: il nome resta leggibile
     invece di essere schiacciato dai badge. */
  .member-row {
    flex-direction: column;
    align-items: stretch;
    gap: 7px;
  }

  .member-link {
    flex-direction: column;
    gap: 2px;
  }

  .member-desc {
    white-space: normal;
  }

  /* Su schermo stretto un badge lungo come "Ereditato da CharacterSimple"
     non ci sta su una riga: deve poter andare a capo invece di sfondare. */
  .badge {
    white-space: normal;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .member-pager {
    flex-direction: column;
  }

  .pager-link {
    max-width: none;
  }

  .pager-next {
    margin-left: 0;
  }

  .search-results {
    position: fixed;
    top: var(--topbar-h);
    left: 8px;
    right: 8px;
    max-height: calc(100vh - var(--topbar-h) - 16px);
  }
}

/* --------------------------------------------------------------- stampa */

@media print {
  .topbar,
  .sidebar,
  .toc,
  .member-pager,
  .footer-links,
  .code-copy,
  .copy-link,
  .skip-link {
    display: none !important;
  }

  .shell {
    grid-template-columns: 1fr;
  }

  body {
    background: #fff;
    color: #000;
  }

  a {
    color: #000;
  }

  /* In stampa il link perde il bersaglio: mostriamo l'indirizzo. */
  .prose a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 0.85em;
  }
}
