:root {
  --bg: #f4f3ef;
  --panel: #fffefa;
  --sidebar-bg: #f9f8f4;
  --line: #e4e1d9;
  --line-strong: #d5d0c5;
  --text: #242522;
  --muted: #74756f;
  --muted-strong: #595b55;
  --accent: #315f55;
  --accent-strong: #224a42;
  --accent-soft: #e7f0ec;
  --code-bg: #f2f1ed;
  --mark: #f3df9c;
  --shadow: 0 24px 70px rgba(54, 49, 39, .07);
  --sidebar: 304px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15.5px/1.68 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

a {
  color: var(--accent);
  text-decoration-thickness: .075em;
  text-underline-offset: .2em;
}

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

::selection {
  background: #d9e7e1;
}

:focus-visible {
  outline: 2px solid rgba(49, 95, 85, .52);
  outline-offset: 2px;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  width: var(--sidebar);
  overflow: auto;
  padding: 24px 18px 36px;
  border-right: 1px solid var(--line);
  background: var(--sidebar-bg);
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
  transition: transform .24s cubic-bezier(.4, 0, .2, 1);
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 4px 22px;
}

.brand {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 11px;
  min-width: 0;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid #cbdcd5;
  border-radius: 11px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: Georgia, serif;
  font-size: 17px;
  font-weight: 700;
}

.brand > span:last-child {
  display: grid;
  min-width: 0;
}

.brand strong {
  overflow: hidden;
  font-size: 14px;
  font-weight: 720;
  letter-spacing: -.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand small {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .055em;
  text-transform: uppercase;
}

.close-button {
  display: none;
}

.search-panel {
  margin-bottom: 13px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box > svg {
  position: absolute;
  left: 11px;
  width: 16px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.8;
  stroke-linecap: round;
  pointer-events: none;
}

.search-box input {
  width: 100%;
  min-width: 0;
  padding: 10px 34px 10px 35px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  background: rgba(255, 255, 255, .7);
  color: var(--text);
  font-size: 13px;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

.search-box input::placeholder {
  color: #96968f;
}

.search-box input:focus {
  border-color: #9cb8af;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(49, 95, 85, .08);
}

.search-clear {
  position: absolute;
  right: 6px;
  display: grid;
  width: 27px;
  height: 27px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.search-clear:hover {
  background: var(--code-bg);
  color: var(--text);
}

.search-status {
  min-height: 20px;
  padding: 6px 3px 0;
  color: var(--muted);
  font-size: 11px;
}

.search-status:empty {
  min-height: 0;
  padding: 0;
}

.search-results {
  display: grid;
  gap: 5px;
  margin-top: 6px;
}

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

.search-result {
  display: grid;
  gap: 3px;
  padding: 10px 11px;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
}

.search-result:hover {
  border-color: var(--line);
  background: #fff;
}

.search-result strong {
  font-size: 13px;
  line-height: 1.35;
}

.search-result small {
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result > span {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted-strong);
  font-size: 11px;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

mark {
  border-radius: 2px;
  background: var(--mark);
  color: inherit;
}

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

.nav-tree .nav-tree {
  margin: 2px 0 5px 10px;
  padding-left: 10px;
  border-left: 1px solid var(--line);
}

.nav-folder summary {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 8px;
  border-radius: 8px;
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.35;
  cursor: pointer;
  list-style: none;
  transition: background .14s ease, color .14s ease;
}

.nav-folder summary:hover {
  background: rgba(36, 37, 34, .045);
  color: var(--text);
}

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

.nav-folder summary::before {
  content: "›";
  display: inline-grid;
  flex: 0 0 15px;
  width: 15px;
  place-items: center;
  color: #92958d;
  font-size: 17px;
  font-weight: 400;
  line-height: 1;
  transition: transform .15s ease;
}

.nav-folder details[open] > summary::before {
  transform: rotate(90deg);
}

.nav-note a {
  display: block;
  margin: 1px 0;
  padding: 6px 9px;
  border-radius: 7px;
  color: #555851;
  font-size: 12.5px;
  line-height: 1.4;
  text-decoration: none;
  transition: background .14s ease, color .14s ease;
}

.nav-note a:hover {
  background: rgba(36, 37, 34, .045);
  color: var(--text);
}

.nav-note a.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 650;
}

.main {
  min-height: 100vh;
  margin-left: var(--sidebar);
  padding: 16px clamp(8px, 1.25vw, 20px) 28px;
  transition: margin-left .24s cubic-bezier(.4, 0, .2, 1), opacity .14s ease, transform .14s ease;
}

body.page-loading .main {
  opacity: .58;
  transform: translateY(3px);
  pointer-events: none;
}

.sidebar-toggle {
  position: fixed;
  top: 25px;
  left: calc(var(--sidebar) - 15px);
  z-index: 25;
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--panel);
  box-shadow: 0 5px 18px rgba(54, 49, 39, .1);
  color: var(--muted-strong);
  cursor: pointer;
  transition: left .24s cubic-bezier(.4, 0, .2, 1), border-color .15s ease, color .15s ease, box-shadow .15s ease;
}

.sidebar-toggle:hover {
  border-color: #a9bdb6;
  color: var(--accent);
  box-shadow: 0 6px 20px rgba(54, 49, 39, .15);
}

.sidebar-toggle span {
  display: block;
  font-family: Georgia, serif;
  font-size: 25px;
  line-height: 1;
  transform: translateY(-1px);
  transition: transform .24s cubic-bezier(.4, 0, .2, 1);
}

body.sidebar-collapsed .sidebar {
  transform: translateX(-100%);
}

body.sidebar-collapsed .main {
  margin-left: 0;
}

body.sidebar-collapsed .sidebar-toggle {
  left: 14px;
}

body.sidebar-collapsed .sidebar-toggle span {
  transform: rotate(180deg) translateY(1px);
}

.note {
  max-width: 1080px;
  margin: 0 auto;
  padding: 26px clamp(18px, 2vw, 30px) 36px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.note-header {
  margin-bottom: 23px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.breadcrumbs {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .045em;
  text-transform: uppercase;
}

.note h1 {
  max-width: 18ch;
  margin: 9px 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(29px, 4vw, 41px);
  font-weight: 650;
  line-height: 1.12;
  letter-spacing: -.025em;
  text-wrap: balance;
}

.note-content {
  color: #32332f;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16.5px;
  line-height: 1.72;
}

.note-content > :first-child {
  margin-top: 0;
}

.note-content > :last-child {
  margin-bottom: 0;
}

.note-content p,
.note-content ul,
.note-content ol {
  margin: 1em 0;
}

.note-content li + li {
  margin-top: .3em;
}

.note-content h2,
.note-content h3,
.note-content h4 {
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.24;
  letter-spacing: -.02em;
  text-wrap: balance;
}

.note-content h2 {
  margin: 2.2em 0 .65em;
  font-size: 25px;
  font-weight: 700;
}

.note-content h3 {
  margin: 1.9em 0 .55em;
  font-size: 19px;
  font-weight: 700;
}

.note-content h4 {
  margin: 1.65em 0 .45em;
  font-size: 16px;
  font-weight: 700;
}

.note-content blockquote {
  margin: 1.5em 0;
  padding: .15em 0 .15em 1.15em;
  border-left: 3px solid #a9c1b8;
  color: #5a5d56;
}

.note-content pre {
  overflow: auto;
  padding: 17px 18px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--code-bg);
  font-size: 13px;
  line-height: 1.58;
}

.note-content code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: .88em;
}

.note-content :not(pre) > code {
  padding: .14em .36em;
  border-radius: 5px;
  background: var(--code-bg);
}

.note-content img,
.note-content video,
.note-content iframe {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1.5em auto;
}

.note-content figure {
  max-width: 100%;
  margin: 1.5em auto;
  text-align: center;
}

.note-content figure > img {
  margin-top: 0;
  margin-bottom: .65em;
}

.note-content table {
  display: block;
  overflow: auto;
  width: max-content;
  max-width: 100%;
  margin: 1.5em auto;
  border-collapse: collapse;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
}

.note-content th,
.note-content td {
  padding: 9px 12px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.note-content th {
  background: var(--code-bg);
  font-weight: 700;
}

.note-content tbody tr:nth-child(even) {
  background: rgba(36, 37, 34, .018);
}

.note-content td mjx-container {
  margin: 0 !important;
}

.note-content hr {
  margin: 2.5em 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.math-display {
  max-width: 100%;
  margin: 1.6em 0;
  padding: .35em 0;
  overflow-x: auto;
  overflow-y: hidden;
  text-align: center;
}

.math-display mjx-container[display="true"] {
  margin: 0 !important;
}

.note-content .task-list-item {
  list-style: none;
}

.note-content input[type="checkbox"] {
  margin-right: .55em;
}

.functionplot-card {
  max-width: 100%;
  margin: 1.8em auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fbfbf8;
}

.functionplot-card svg {
  display: block;
  max-width: 100%;
  margin: 0 auto;
}

.functionplot-title {
  margin: 0 0 10px;
  color: var(--muted-strong);
  font-family: Inter, ui-sans-serif, sans-serif;
  font-size: 13px;
  font-weight: 700;
}

.functionplot-canvas {
  width: 100%;
  min-height: 420px;
  overflow: hidden;
}

.functionplot-error {
  padding: 12px;
  border-radius: 9px;
  background: #fff1f1;
  color: #8a3030;
  font: 13px/1.5 Inter, ui-sans-serif, sans-serif;
}

.mermaid-card {
  max-width: 100%;
  margin: 1.8em auto;
  padding: 18px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fbfbf8;
}

.mermaid-card .mermaid {
  display: grid;
  min-width: 420px;
  min-height: 80px;
  place-items: center;
  margin: 0;
  color: var(--muted-strong);
  font: 13px/1.5 "SFMono-Regular", Consolas, monospace;
  white-space: pre-wrap;
}

.mermaid-card .mermaid svg {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}

.mermaid-card .mermaid-error {
  place-items: start;
  color: #8a3030;
}

.menu-button,
.scrim {
  display: none;
}

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

@media (max-width: 900px) {
  .sidebar-toggle {
    display: none;
  }

  .menu-button {
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 30;
    display: grid;
    width: 42px;
    height: 42px;
    place-content: center;
    gap: 4px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(255, 254, 250, .94);
    box-shadow: 0 8px 24px rgba(40, 37, 31, .1);
  }

  .menu-button span {
    display: block;
    width: 17px;
    height: 1.5px;
    background: #3d3e3a;
  }

  .sidebar {
    width: min(330px, calc(100vw - 42px));
    transform: translateX(-102%);
    box-shadow: var(--shadow);
    transition: transform .2s ease;
  }

  body.menu-open .sidebar {
    transform: none;
  }

  body.sidebar-collapsed .sidebar {
    transform: translateX(-102%);
  }

  body.sidebar-collapsed.menu-open .sidebar {
    transform: none;
  }

  .close-button {
    display: grid;
    width: 32px;
    height: 32px;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font-size: 23px;
    cursor: pointer;
  }

  .scrim {
    position: fixed;
    inset: 0;
    z-index: 15;
    background: rgba(30, 30, 27, .28);
    backdrop-filter: blur(2px);
  }

  body.menu-open .scrim {
    display: block;
  }

  .main {
    margin-left: 0;
    padding: 62px 8px 28px;
  }

  .note {
    padding: 24px 14px 30px;
    border-radius: 12px;
  }

  .note h1 {
    font-size: clamp(27px, 9vw, 36px);
  }

  .note-content {
    font-size: 16px;
  }

  .functionplot-canvas {
    min-height: 340px;
  }
}

@media (max-width: 520px) {
  .main {
    padding-right: 0;
    padding-left: 0;
  }

  .note {
    border-right: 0;
    border-left: 0;
    border-radius: 0;
    box-shadow: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .sidebar,
  .main,
  .sidebar-toggle,
  .sidebar-toggle span {
    transition: none;
  }
}
