:root {
  color-scheme: light dark;
  --canvas: #f5f7f5;
  --surface: #ffffff;
  --surface-subtle: #f0f4f1;
  --surface-strong: #e5ece8;
  --ink: #17211c;
  --muted: #5c6962;
  --quiet: #78837d;
  --line: #d5ddd8;
  --line-strong: #b7c4bd;
  --accent: #176b52;
  --accent-strong: #0d503d;
  --accent-soft: #e5f3ed;
  --link: #0759b4;
  --warning: #95530a;
  --warning-soft: #fff4df;
  --focus: #a33cff;
  --shadow: 0 18px 60px rgb(22 40 31 / 14%);
  --font-ui: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-reading: var(--font-ui);
}

:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-palette="original"] {
  --canvas: #ffffff;
  --surface: #ffffff;
  --surface-subtle: #f5f5f5;
  --surface-strong: #d6d6d6;
  --ink: #1e1e1e;
  --muted: #6c6c6c;
  --quiet: #707070;
  --line: #eeeeee;
  --line-strong: #d6d6d6;
  --accent: #333333;
  --accent-strong: #1e1e1e;
  --accent-soft: #f5f5f5;
  --link: #0049a8;
  --warning: #8a4b08;
  --warning-soft: #fff3df;
  --focus: #175dcc;
  --shadow: 0 18px 60px rgb(0 0 0 / 14%);
}

:root[data-palette="washi"] {
  --canvas: #f7f0df;
  --surface: #fffaf0;
  --surface-subtle: #efe6d1;
  --surface-strong: #d8c8a8;
  --ink: #29251e;
  --muted: #675f52;
  --quiet: #786f61;
  --line: #d8cdb7;
  --line-strong: #bbaa89;
  --accent: #79543d;
  --accent-strong: #593a29;
  --accent-soft: #ead8c8;
  --link: #365b70;
  --warning: #945315;
  --warning-soft: #f4dfbd;
  --focus: #8c4f91;
  --shadow: 0 18px 60px rgb(65 48 24 / 17%);
}

:root[data-palette="sumi"] {
  --canvas: #f3f5f3;
  --surface: #fbfcfb;
  --surface-subtle: #e7ede9;
  --surface-strong: #cbd7d1;
  --ink: #1c2420;
  --muted: #5c6862;
  --quiet: #6b7771;
  --line: #cad4cf;
  --line-strong: #aabbb2;
  --accent: #45685b;
  --accent-strong: #2c5043;
  --accent-soft: #d8e6df;
  --link: #365f76;
  --warning: #8b541b;
  --warning-soft: #f7ead4;
  --focus: #765aa3;
  --shadow: 0 20px 62px rgb(33 50 42 / 16%);
}

:root[data-palette="aizome"] {
  --canvas: #f2f5f7;
  --surface: #fbfcfd;
  --surface-subtle: #e6ecf0;
  --surface-strong: #c7d4dc;
  --ink: #18232a;
  --muted: #596873;
  --quiet: #687985;
  --line: #c9d5dc;
  --line-strong: #a6bac6;
  --accent: #3e6479;
  --accent-strong: #294f65;
  --accent-soft: #d7e5ec;
  --link: #315f84;
  --warning: #8d531b;
  --warning-soft: #f6e8d2;
  --focus: #7357ad;
  --shadow: 0 20px 64px rgb(30 49 61 / 17%);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #111714;
  --surface: #18211d;
  --surface-subtle: #202b26;
  --surface-strong: #2b3932;
  --ink: #edf3ef;
  --muted: #a8b5ae;
  --quiet: #89978f;
  --line: #34433b;
  --line-strong: #4a5e54;
  --accent: #6cc8a7;
  --accent-strong: #91ddc2;
  --accent-soft: #173c30;
  --link: #91bdff;
  --warning: #ffc36b;
  --warning-soft: #3a2b16;
  --focus: #d5a2ff;
  --shadow: 0 22px 70px rgb(0 0 0 / 35%);
}

:root[data-theme="dark"][data-palette="original"] {
  --canvas: #1d1e20;
  --surface: #2e2e33;
  --surface-subtle: #2e2e33;
  --surface-strong: #414244;
  --ink: #dadadb;
  --muted: #9b9c9d;
  --quiet: #a4a5a6;
  --line: #333333;
  --line-strong: #535458;
  --accent: #c4c4c5;
  --accent-strong: #eeeeef;
  --accent-soft: #37383e;
  --link: #9dc3ff;
  --warning: #ffc06a;
  --warning-soft: #3a2a17;
  --focus: #bca1ff;
  --shadow: 0 22px 70px rgb(0 0 0 / 38%);
}

:root[data-theme="dark"][data-palette="washi"] {
  --canvas: #1d1a16;
  --surface: #29241d;
  --surface-subtle: #383126;
  --surface-strong: #4a4031;
  --ink: #eee5d3;
  --muted: #b8ab96;
  --quiet: #9f937f;
  --line: #4b4133;
  --line-strong: #6d5e49;
  --accent: #d2a67e;
  --accent-strong: #edc49e;
  --accent-soft: #493327;
  --link: #a8cee0;
  --warning: #efb664;
  --warning-soft: #44301c;
  --focus: #d4a2db;
  --shadow: 0 22px 72px rgb(0 0 0 / 42%);
}

:root[data-theme="dark"][data-palette="sumi"] {
  --canvas: #111613;
  --surface: #1b231f;
  --surface-subtle: #28342f;
  --surface-strong: #36453e;
  --ink: #e7eee9;
  --muted: #a8b7af;
  --quiet: #8f9e96;
  --line: #34433c;
  --line-strong: #50645a;
  --accent: #87b8a3;
  --accent-strong: #a8d2c0;
  --accent-soft: #244238;
  --link: #9bc9e5;
  --warning: #edbb72;
  --warning-soft: #3d2f1d;
  --focus: #c4a5ed;
  --shadow: 0 22px 72px rgb(0 0 0 / 40%);
}

:root[data-theme="dark"][data-palette="aizome"] {
  --canvas: #11171d;
  --surface: #1b252d;
  --surface-subtle: #293842;
  --surface-strong: #384a56;
  --ink: #e5edf2;
  --muted: #a6b7c2;
  --quiet: #8d9faa;
  --line: #364854;
  --line-strong: #526a79;
  --accent: #82acc2;
  --accent-strong: #a9cde0;
  --accent-soft: #243e4d;
  --link: #9ec8f0;
  --warning: #efba70;
  --warning-soft: #3e2e1c;
  --focus: #bea6f2;
  --shadow: 0 22px 72px rgb(0 0 0 / 42%);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --canvas: #111714;
    --surface: #18211d;
    --surface-subtle: #202b26;
    --surface-strong: #2b3932;
    --ink: #edf3ef;
    --muted: #a8b5ae;
    --quiet: #89978f;
    --line: #34433b;
    --line-strong: #4a5e54;
    --accent: #6cc8a7;
    --accent-strong: #91ddc2;
    --accent-soft: #173c30;
    --link: #91bdff;
    --warning: #ffc36b;
    --warning-soft: #3a2b16;
    --focus: #d5a2ff;
    --shadow: 0 22px 70px rgb(0 0 0 / 35%);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
  animation: none !important;
  scroll-behavior: auto !important;
  transition: none !important;
}

html {
  background: var(--canvas);
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 17px;
  line-height: 1.62;
  text-rendering: optimizeLegibility;
}

body.search-open {
  overflow: hidden;
}

a {
  color: var(--link);
  text-underline-offset: 0.16em;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.5rem;
  left: 0.5rem;
  padding: 0.65rem 0.9rem;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: none;
}

.site-header {
  position: sticky;
  z-index: 30;
  top: 0;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem max(1rem, calc((100vw - 1120px) / 2));
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--canvas) 93%, transparent);
  backdrop-filter: blur(14px);
}

.site-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.62rem;
  color: var(--ink);
  font-weight: 760;
  letter-spacing: -0.015em;
  text-decoration: none;
}

.brand-mark {
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  border-radius: 0.5rem;
  background: var(--accent);
  color: var(--canvas);
  font-family: var(--font-reading);
  font-size: 1.25rem;
  font-weight: 800;
}

.site-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.header-action,
.hero-search,
.icon-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 0.62rem;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.header-action {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.72rem;
  font-size: 0.88rem;
  font-weight: 650;
}

.header-action:hover,
.hero-search:hover,
.icon-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-subtle);
}

.testing-trigger[aria-expanded="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.testing-panel {
  position: fixed;
  z-index: 60;
  top: 4.25rem;
  right: max(1rem, calc((100vw - 1120px) / 2));
  width: min(27rem, calc(100vw - 2rem));
  max-height: calc(100vh - 5.25rem);
  overflow-y: auto;
  padding: 1.1rem;
  border: 1px solid var(--line-strong);
  border-radius: 0.85rem;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.testing-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
}

.testing-heading .kind {
  margin-bottom: 0.18rem;
}

.testing-heading h2 {
  margin: 0;
  font-size: 1.18rem;
  letter-spacing: -0.02em;
}

.testing-heading .icon-button {
  width: 44px;
  height: 44px;
  margin: -0.35rem -0.35rem 0 0;
  font-size: 1.35rem;
}

.testing-intro {
  margin: 0.65rem 0 1rem;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.testing-fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.testing-fieldset legend {
  margin-bottom: 0.55rem;
  color: var(--quiet);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.palette-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.palette-option {
  min-width: 0;
  min-height: 62px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 0.62rem;
  background: var(--canvas);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.palette-option:hover {
  border-color: var(--line-strong);
  background: var(--surface-subtle);
}

.palette-option[aria-checked="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.palette-option strong,
.palette-option small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.palette-option strong {
  font-size: 0.82rem;
  line-height: 1.25;
}

.palette-option small {
  margin-top: 0.12rem;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.3;
}

.palette-swatch {
  width: 38px;
  height: 38px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--ink) 18%, transparent);
  border-radius: 50%;
  background: var(--swatch-a);
}

.palette-swatch i:first-child {
  background: var(--swatch-a);
}

.palette-swatch i:last-child {
  background: var(--swatch-b);
}

.palette-option[data-palette-value="current"] { --swatch-a: #f5f7f5; --swatch-b: #f0f4f1; }
.palette-option[data-palette-value="original"] { --swatch-a: #ffffff; --swatch-b: #f5f5f5; }
.palette-option[data-palette-value="washi"] { --swatch-a: #f7f0df; --swatch-b: #efe6d1; }
.palette-option[data-palette-value="sumi"] { --swatch-a: #f3f5f3; --swatch-b: #e7ede9; }
.palette-option[data-palette-value="aizome"] { --swatch-a: #f2f5f7; --swatch-b: #e6ecf0; }

:root[data-theme="dark"] .palette-option[data-palette-value="current"] { --swatch-a: #111714; --swatch-b: #202b26; }
:root[data-theme="dark"] .palette-option[data-palette-value="original"] { --swatch-a: #1d1e20; --swatch-b: #2e2e33; }
:root[data-theme="dark"] .palette-option[data-palette-value="washi"] { --swatch-a: #1d1a16; --swatch-b: #383126; }
:root[data-theme="dark"] .palette-option[data-palette-value="sumi"] { --swatch-a: #111613; --swatch-b: #28342f; }
:root[data-theme="dark"] .palette-option[data-palette-value="aizome"] { --swatch-a: #11171d; --swatch-b: #293842; }

kbd {
  padding: 0.12rem 0.35rem;
  border: 1px solid var(--line);
  border-bottom-color: var(--line-strong);
  border-radius: 0.3rem;
  background: var(--surface-subtle);
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 600;
}

.page-shell {
  width: min(calc(100% - 2rem), 1120px);
  margin: 0 auto;
  padding: 2.2rem 0 5rem;
}

.knowl-page {
  width: min(100%, 780px);
  margin: 0 auto;
}

.breadcrumb {
  width: min(100%, 780px);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 auto 1.5rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.breadcrumb a {
  color: var(--muted);
}

.page-header {
  margin-bottom: 1.8rem;
  padding: 0.6rem 0 1.8rem;
  border-bottom: 1px solid var(--line);
}

.page-header h1 {
  max-width: 18ch;
  margin: 0.12rem 0 0.75rem;
  font-family: var(--font-reading);
  font-size: clamp(2.35rem, 7vw, 4rem);
  font-weight: 720;
  letter-spacing: -0.045em;
  line-height: 1.02;
}

.kind,
.knowl-kind {
  color: var(--accent-strong);
  font-family: var(--font-ui);
  font-size: 0.73rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.kind {
  margin: 0 0 0.55rem;
}

.page-summary {
  max-width: 62ch;
  margin: 0;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: clamp(1.02rem, 2vw, 1.18rem);
  line-height: 1.55;
}

.core-section,
.section-body,
.knowl-body,
.knowl-inline-section {
  font-family: var(--font-reading);
  font-size: 1.06rem;
}

.core-section {
  padding: 0.2rem 0 2rem;
}

.core-heading {
  margin: 0 0 1rem;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 780;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.core-section p,
.section-body p {
  margin: 0 0 1rem;
}

.core-section li + li,
.section-body li + li,
.knowl-body li + li {
  margin-top: 0.42rem;
}

.knowl-section,
.relations {
  border-top: 1px solid var(--line);
}

.knowl-section > summary,
.index-section > summary {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  cursor: pointer;
  font-weight: 720;
  list-style: none;
}

.knowl-section > summary::-webkit-details-marker,
.index-section > summary::-webkit-details-marker {
  display: none;
}

.knowl-section > summary:hover,
.index-section > summary:hover {
  color: var(--accent-strong);
}

.section-state {
  color: var(--quiet);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.knowl-section[open] .section-state {
  font-size: 0;
}

.knowl-section[open] .section-state::after {
  content: "Close";
  font-size: 0.76rem;
}

.section-body {
  padding: 0.15rem 0 1.5rem;
}

.relations {
  padding: 1.5rem 0;
}

.relations h2 {
  font-family: var(--font-reading);
}

.relation-type {
  display: inline-block;
  margin-right: 0.35rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 760;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.semantic-block {
  margin: 1.2rem 0;
  padding: 1rem 1.1rem;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 0.45rem;
  background: var(--surface-subtle);
}

.semantic-block h3 {
  margin: 0 0 0.6rem;
  font-family: var(--font-ui);
  font-size: 0.9rem;
}

.callout {
  margin: 1.35rem 0;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--surface-subtle);
}

.callout-warning {
  border-color: color-mix(in srgb, var(--warning) 42%, var(--line));
  background: var(--warning-soft);
}

.callout-label {
  margin: 0 0 0.3rem !important;
  color: var(--warning);
  font-family: var(--font-ui);
  font-size: 0.74rem;
  font-weight: 820;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.callout > div > p:last-child {
  margin-bottom: 0;
}

.knowl {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 58%, transparent);
  text-decoration-style: dotted;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 0.16em;
  cursor: pointer;
}

.knowl:hover,
.knowl[aria-expanded="true"] {
  color: var(--accent-strong);
  text-decoration-style: solid;
}

.knowl[aria-expanded="true"] {
  font-weight: 700;
}

.missing-knowl {
  color: var(--warning);
}

.knowl-panel {
  --knowl-panel-background: var(--surface-subtle);
  content-visibility: auto;
  contain-intrinsic-size: auto 12rem;
  width: min(100%, 880px);
  margin: 0.4rem 0 0.65rem;
  border-left: 2px solid var(--accent);
  background: var(--knowl-panel-background);
}

.knowl-depth-odd {
  --knowl-panel-background: var(--canvas);
}

.knowl-content {
  position: relative;
}

.knowl-close,
.icon-button {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.knowl-close {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 0.25rem;
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1;
}

.knowl-close:hover {
  background: var(--surface-strong);
}

.knowl-body {
  padding: 0.55rem 0.75rem 0.35rem;
}

.knowl-body > :first-child,
.knowl-inline-section > :first-child {
  margin-top: 0;
}

.knowl-body > :last-child,
.knowl-inline-section > :last-child {
  margin-bottom: 0;
}

.knowl-controls {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  min-height: 32px;
  padding: 0 0.35rem 0.35rem 0.75rem;
}

.knowl-section-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2rem 0.65rem;
  margin-right: auto;
}

.section-chip {
  min-height: 32px;
  padding: 0.2rem 0;
  border: 0;
  border-bottom: 1px dotted currentColor;
  background: transparent;
  color: var(--link);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.section-chip:hover,
.section-chip[aria-expanded="true"] {
  color: var(--accent-strong);
}

.knowl-page-link {
  display: grid;
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 0.25rem;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 1rem;
  text-decoration: none;
}

.knowl-page-link:hover,
.knowl-page-link:focus-visible {
  background: var(--surface-strong);
  color: var(--link);
}

.knowl-inline-section {
  padding: 0.65rem 0.75rem 0.75rem;
  border-top: 1px solid var(--line);
  background: var(--knowl-panel-background);
}

.loading,
.error {
  padding: 1rem;
  color: var(--muted);
  font-family: var(--font-ui);
}

.definition-switcher {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 1rem 0;
}

.switcher-tab {
  min-height: 40px;
  padding: 0.42rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.42rem;
  background: var(--surface);
  cursor: pointer;
}

.switcher-tab.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.tfae-item,
.proof-step {
  margin: 0.7rem 0;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  background: var(--surface);
}

.proof-assertion {
  font-weight: 700;
}

.proof-justifications {
  display: flex;
  flex-wrap: wrap;
  gap: 0.42rem;
  margin-top: 0.55rem;
}

.justification,
.uses,
.proof-proves {
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 0.8rem;
}

.justification {
  padding: 0.22rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  background: var(--surface-subtle);
}

.uses {
  display: inline-block;
  margin-left: 0.35rem;
}

pre,
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

pre {
  max-width: 100%;
  overflow-x: auto;
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  background: var(--surface-subtle);
}

.diagram {
  max-width: 100%;
  margin: 1rem 0;
  overflow-x: auto;
  text-align: center;
  scrollbar-width: thin;
}

.diagram-frame {
  display: inline-block;
  max-width: 100%;
  isolation: isolate;
}

.diagram-svg .diagram-frame,
.diagram-image .diagram-frame {
  padding: 0.55rem;
  background: #ffffff;
  color: #111111;
}

:root[data-theme="dark"] .diagram-svg .diagram-frame,
:root[data-theme="dark"] .diagram-image .diagram-frame {
  background: var(--canvas);
  color: var(--ink);
}

:root[data-theme="dark"] .diagram-svg .diagram-frame svg,
:root[data-theme="dark"] .diagram-image .diagram-frame img {
  filter: invert(1) hue-rotate(180deg);
  mix-blend-mode: screen;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .diagram-svg .diagram-frame,
  :root:not([data-theme]) .diagram-image .diagram-frame {
    background: var(--canvas);
    color: var(--ink);
  }

  :root:not([data-theme]) .diagram-svg .diagram-frame svg,
  :root:not([data-theme]) .diagram-image .diagram-frame img {
    filter: invert(1) hue-rotate(180deg);
    mix-blend-mode: screen;
  }
}

.diagram svg,
.diagram img {
  display: block;
  min-width: min(100%, 12rem);
  max-width: 100%;
  height: auto;
}

.diagram figcaption {
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  text-align: left;
}

.diagram-source,
.diagram-error {
  padding: 0.8rem;
  border: 1px solid var(--line);
  background: var(--surface-subtle);
  text-align: left;
}

.math-inline {
  display: inline;
  max-width: 100%;
  overflow: visible;
  vertical-align: baseline;
}

.math-display,
mjx-container[display="true"] {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  padding: 0.25rem 0;
  text-align: center;
  scrollbar-width: thin;
}

.math-katex .katex-display {
  margin: 0.75em 0;
}

.math-katex .katex {
  white-space: nowrap;
}

.math-render-error {
  color: var(--warning);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.index-shell {
  max-width: 980px;
}

.index-hero {
  padding: 2rem 0 2.2rem;
}

.index-hero h1 {
  max-width: 14ch;
}

.hero-search {
  width: min(100%, 620px);
  min-height: 56px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.45rem;
  padding: 0.7rem 0.85rem;
  color: var(--muted);
  text-align: left;
  box-shadow: 0 5px 18px rgb(22 40 31 / 7%);
}

.index-intro {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin: 2rem 0 0.5rem;
}

.index-intro h2,
.index-intro p {
  margin: 0;
}

.index-intro p {
  color: var(--muted);
  font-size: 0.9rem;
}

.index-section {
  border-top: 1px solid var(--line);
}

.index-section > summary {
  min-height: 64px;
  font-family: var(--font-reading);
  font-size: 1.16rem;
}

.index-count {
  color: var(--quiet);
  font-family: var(--font-ui);
  font-size: 0.76rem;
  font-weight: 650;
}

.index-list {
  list-style: none;
  margin: 0;
  padding: 0 0 1rem;
}

.index-item {
  display: grid;
  grid-template-columns: minmax(13rem, 0.42fr) 1fr;
  gap: 1rem;
  padding: 0.58rem 0;
  border-top: 1px solid color-mix(in srgb, var(--line) 68%, transparent);
}

.index-knowl {
  align-self: start;
  font-family: var(--font-reading);
  font-weight: 720;
}

.index-item .summary {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.index-item .knowl-panel {
  grid-column: 1 / -1;
  margin-top: 0.35rem;
}

.home-content {
  width: min(calc(100% - 2rem), 780px);
  margin: 0 auto;
  padding: 3rem 0;
}

.search-dialog {
  position: fixed;
  z-index: 80;
  inset: 0;
  display: grid;
  place-items: start center;
  padding: min(10vh, 5rem) 1rem 1rem;
  background: rgb(8 15 12 / 62%);
}

.search-dialog[hidden],
[hidden],
.hidden {
  display: none !important;
}

.search-surface {
  width: min(100%, 700px);
  max-height: min(78vh, 760px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 0.8rem;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.search-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1rem 0.7rem;
}

.search-heading h2,
.search-heading p {
  margin: 0;
}

.search-heading h2 {
  font-family: var(--font-reading);
  font-size: 1.45rem;
}

.icon-button {
  width: 44px;
  height: 44px;
  font-size: 1.4rem;
}

.search-label {
  margin: 0 1rem 0.35rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 680;
}

.search-input {
  min-height: 54px;
  margin: 0 1rem;
  padding: 0.7rem 0.85rem;
  border: 2px solid var(--line-strong);
  border-radius: 0.55rem;
  background: var(--canvas);
  color: var(--ink);
  font-size: 1.05rem;
}

.search-status {
  margin: 0;
  padding: 0.65rem 1rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.search-results {
  min-height: 0;
  margin: 0;
  padding: 0 0.45rem 0.5rem;
  overflow-y: auto;
  list-style: none;
}

.search-result {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.12rem 0.75rem;
  padding: 0.66rem 0.7rem;
  border-top: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
}

.search-result:hover,
.search-result:focus-visible {
  border-radius: 0.42rem;
  background: var(--surface-subtle);
}

.search-result-meta {
  align-self: baseline;
  color: var(--quiet);
  font-size: 0.7rem;
  text-transform: capitalize;
}

.search-result-summary {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.38;
}

@media (max-width: 720px) {
  body {
    font-size: 16px;
  }

  .site-header {
    min-height: 54px;
    padding: 0.42rem 0.65rem;
  }

  .brand-mark {
    width: 1.8rem;
    height: 1.8rem;
  }

  .header-action {
    min-width: 44px;
    padding: 0.4rem 0.55rem;
  }

  .header-action kbd,
  #search-open > span:not(:first-child),
  .testing-trigger .testing-label,
  .theme-toggle .theme-label {
    display: none;
  }

  .testing-panel {
    top: 3.8rem;
    right: 0.5rem;
    width: calc(100vw - 1rem);
    max-height: calc(100vh - 4.3rem);
  }

  .page-shell {
    width: min(calc(100% - 1.25rem), 1120px);
    padding-top: 1.25rem;
  }

  .page-header h1 {
    max-width: none;
    font-size: clamp(2.15rem, 12vw, 3.2rem);
  }

  .core-section,
  .section-body,
  .knowl-body,
  .knowl-inline-section {
    font-size: 1rem;
  }

  .knowl-panel {
    width: calc(100vw - 1rem);
    margin-left: calc(50% - 50vw + 0.5rem);
    margin-right: calc(50% - 50vw + 0.5rem);
  }

  .knowl-panel .knowl-panel {
    width: auto;
    margin-right: 0;
    margin-left: 0;
  }

  .knowl-body,
  .knowl-inline-section {
    padding-right: 0.75rem;
    padding-left: 0.75rem;
  }

  .section-chip,
  .knowl-page-link,
  .knowl-close {
    min-height: 44px;
  }

  .knowl-page-link,
  .knowl-close {
    width: 44px;
  }

  .knowl-page-link {
    flex-basis: 44px;
  }

  .index-intro,
  .index-item {
    display: block;
  }

  .index-intro p {
    margin-top: 0.25rem;
  }

  .index-item .summary {
    display: block;
    margin-top: 0.15rem;
  }

  .search-dialog {
    align-items: end;
    padding: 0.5rem;
  }

  .search-surface {
    max-height: calc(100dvh - 1rem);
    border-radius: 0.75rem;
  }

  .proof-justifications {
    display: grid;
  }
}

@media (max-width: 520px) {
  .palette-options {
    grid-template-columns: 1fr;
  }
}

@media print {
  .site-header,
  .testing-panel,
  .search-dialog,
  .knowl-controls {
    display: none !important;
  }

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

  .page-shell {
    width: 100%;
    padding: 0;
  }

  .knowl-section:not([open]) > .section-body {
    display: block;
  }
}
