.notes-shell-page {
  --notes-shell-height: 46px;
}

.notes-shell-page main,
.notes-shell-page [id] {
  scroll-margin-top: calc(var(--notes-shell-height) + 12px);
}

.notes-sitebar {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: var(--notes-shell-height);
  padding: 8px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid rgba(31, 41, 55, 0.14);
  background: rgba(255, 255, 255, 0.92);
  color: #25313d;
  font: 700 14px/1.35 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.notes-sitebar a {
  color: inherit;
  text-decoration: none;
  border: 0;
}

.notes-sitebar a:hover {
  color: #a8492a;
  text-decoration: none;
  border: 0;
}

.notes-sitebar__brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  white-space: nowrap;
}

.notes-sitebar__mark {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: #c15f3c;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.42);
}

.notes-sitebar__links {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.notes-sitebar__link {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 10px;
  border: 1px solid rgba(31, 41, 55, 0.13) !important;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.62);
  color: #4f5d6a !important;
  white-space: nowrap;
}

.notes-sitebar__link:hover {
  border-color: rgba(193, 95, 60, 0.42) !important;
  background: rgba(247, 236, 228, 0.92);
  color: #a8492a !important;
}

.notes-shell-page .sidebar {
  top: var(--notes-shell-height);
  height: calc(100vh - var(--notes-shell-height));
}

.notes-shell-page .mobile-tools {
  top: var(--notes-shell-height);
}

/* Book styles switch to one column at 980px. Match that breakpoint and
   specificity so the shared desktop sidebar height cannot trap touch scrolling. */
@media screen and (max-width: 980px) {
  .notes-shell-page .sidebar {
    position: static;
    top: auto;
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .notes-shell-page .sidebar nav {
    max-height: 28vh;
    max-height: 28svh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .notes-shell-page .sidebar .brand {
    margin-bottom: 10px;
    padding-bottom: 10px;
  }

  .notes-shell-page .sidebar .brand-meta {
    display: none;
  }

  .notes-shell-page main.content {
    width: 100%;
    max-width: 100%;
  }

  /* Overflow scrolling does not apply to an inline box. Long inline formulas
     must become bounded inline blocks so they wrap/scroll within the text. */
  .notes-shell-page mjx-container[jax="CHTML"]:not([display="true"]) {
    display: inline-block;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    vertical-align: middle;
  }
}

.notes-shell-page {
  overflow-x: hidden;
}

.notes-shell-page *,
.notes-shell-page *::before,
.notes-shell-page *::after {
  max-width: 100%;
}

.notes-shell-page main,
.notes-shell-page section,
.notes-shell-page article,
.notes-shell-page header,
.notes-shell-page footer,
.notes-shell-page nav,
.notes-shell-page aside,
.notes-shell-page div,
.notes-shell-page figure,
.notes-shell-page figcaption,
.notes-shell-page p,
.notes-shell-page li,
.notes-shell-page blockquote,
.notes-shell-page pre,
.notes-shell-page code,
.notes-shell-page table,
.notes-shell-page th,
.notes-shell-page td,
.notes-shell-page svg,
.notes-shell-page img,
.notes-shell-page video,
.notes-shell-page canvas {
  min-width: 0;
}

.notes-shell-page img,
.notes-shell-page video,
.notes-shell-page svg,
.notes-shell-page canvas {
  height: auto;
}

.notes-shell-page p,
.notes-shell-page li,
.notes-shell-page blockquote,
.notes-shell-page figcaption,
.notes-shell-page td,
.notes-shell-page th,
.notes-shell-page a,
.notes-shell-page code,
.notes-shell-page .source-item,
.notes-shell-page .card,
.notes-shell-page .callout {
  overflow-wrap: anywhere;
}

.notes-shell-page pre,
.notes-shell-page .equation,
.notes-shell-page .math-display,
.notes-shell-page .formula,
.notes-shell-page .table-wrap,
.notes-shell-page .table-container,
.notes-shell-page .results-wrap,
.notes-shell-page .source-table-wrapper {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

.notes-shell-page pre code {
  white-space: pre;
  overflow-wrap: normal;
}

.notes-shell-page table {
  max-width: none;
}

@media (max-width: 720px) {
  .notes-sitebar {
    gap: 10px;
    padding: 8px 12px;
    font-size: 13px;
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .notes-sitebar__links {
    gap: 6px;
    flex-wrap: wrap;
  }

  .notes-sitebar__link {
    min-height: 28px;
    padding: 3px 8px;
  }

  .notes-shell-page .nav,
  .notes-shell-page .toc,
  .notes-shell-page .nav-links,
  .notes-shell-page .topbar,
  .notes-shell-page .source-list,
  .notes-shell-page .meta-strip,
  .notes-shell-page .tag-row {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .notes-shell-page header,
  .notes-shell-page main {
    width: calc(100% - 24px);
    max-width: calc(100% - 24px);
  }

  .notes-shell-page h1,
  .notes-shell-page h2,
  .notes-shell-page h3,
  .notes-shell-page .kicker,
  .notes-shell-page .meta {
    overflow-wrap: anywhere;
    word-break: break-word;
  }
}

@media print {
  .notes-sitebar {
    display: none;
  }

  .notes-shell-page .sidebar,
  .notes-shell-page .mobile-tools {
    top: 0;
    height: auto;
  }
}

/* ---------- Anthropic-inspired recolor for standalone notes ----------
   Every standalone note body references var(--accent) for its links,
   headings, cards, callouts and table headers. Overriding the custom
   properties (and the hard-coded body texture) here recolors all notes
   from teal to clay in one place, without editing each note file.
   --accent-2 (ochre/clay-brown) and the blue/green/red semantic colors
   are intentionally left untouched. */
.notes-shell-page {
  --accent: #c15f3c !important;
  --accent-soft: #f7ece4 !important;
  background:
    radial-gradient(circle at 12% 6%, rgba(193, 95, 60, 0.09), transparent 30%),
    radial-gradient(circle at 88% 0%, rgba(176, 119, 89, 0.09), transparent 32%),
    linear-gradient(90deg, rgba(193, 95, 60, 0.035) 1px, transparent 1px),
    linear-gradient(180deg, rgba(120, 105, 85, 0.028) 1px, transparent 1px),
    var(--paper, #f0ede4) !important;
  background-size: auto, auto, 44px 44px, 44px 44px, auto !important;
}
