.notes-shell {
  width: min(100% - 2rem, 1160px);
  max-width: 1160px;
}

.notes-page .course-header {
  max-width: 820px;
}

.notes-page .course-header h1 {
  margin-top: 1.5rem;
}

.notes-downloads {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  margin-top: 1rem;
  font-size: 0.9rem;
}

.notes-layout {
  display: grid;
  grid-template-columns: minmax(0, 820px) minmax(160px, 1fr);
  align-items: start;
  gap: 3rem;
  margin-top: 1.8rem;
}

.notebook-content {
  min-width: 0;
  overflow-wrap: break-word;
}

.notebook-content h1,
.notebook-content h2,
.notebook-content h3,
.notebook-content h4 {
  margin: 2.1rem 0 0.8rem;
  line-height: 1.35;
  scroll-margin-top: 1.5rem;
}

.notebook-content h2 { font-size: 1.55rem; }
.notebook-content h3 { font-size: 1.25rem; }
.notebook-content h4 { font-size: 1.08rem; }
.notebook-content p { margin: 0 0 1rem; }
.notebook-content li { margin-block: 0.3rem; }

.notebook-content .anchor-link {
  margin-left: 0.35rem;
  font-weight: 400;
  font-size: 0.8em;
  text-decoration: none;
  opacity: 0;
}

.notebook-content :is(h1, h2, h3, h4):hover .anchor-link,
.notebook-content .anchor-link:focus-visible {
  opacity: 1;
}

.notebook-content .input_area {
  position: relative;
  margin: 1rem 0;
  padding: 1rem 1.15rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7f9fc;
}

.notebook-content pre {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.83rem;
  line-height: 1.6;
  tab-size: 4;
  white-space: pre;
  overflow: auto;
}

.notebook-content .highlight { background: transparent; }
.notebook-content .input_area pre { padding-right: 2.5rem; }
.notebook-content .output_area { margin: 0.75rem 0 1.5rem; overflow-x: auto; }
.notebook-content .output_stderr { color: #7d3b24; }
.notebook-content .output_subarea { max-width: 100%; }
.notebook-content img { max-width: 100%; height: auto; }
.notebook-content .output_png img { display: block; margin: 1rem auto; }
.notebook-content .output_svg svg { max-width: 100%; height: auto; }
.notebook-content :not(pre) > code { padding: 0.1em 0.3em; background: #f0f3f7; border-radius: 3px; font-size: 0.9em; }
.notebook-content mjx-container[display="true"] { overflow-x: auto; overflow-y: hidden; padding-block: 0.2rem; }

.notebook-content table {
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.88rem;
  text-align: left;
}

.notebook-content th,
.notebook-content td {
  padding: 0.45rem 0.7rem;
  border-bottom: 1px solid var(--line);
}

.notebook-content th { font-weight: 600; }
.notebook-content blockquote { margin-inline: 0; padding-left: 1.1rem; border-left: 3px solid var(--line); color: var(--muted); }
.notebook-content hr { margin: 2rem 0; border: 0; border-top: 1px solid var(--line); }

.copy-code {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--muted);
  font: inherit;
  font-size: 0.72rem;
  cursor: pointer;
}

.copy-code:focus-visible { outline: 3px solid #9eb6d4; outline-offset: 2px; }
.copy-code:hover { color: var(--ink); }

.notes-contents {
  position: sticky;
  top: 2rem;
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
  padding-left: 1rem;
  border-left: 1px solid var(--line);
  font-size: 0.8rem;
  line-height: 1.5;
}

.notes-contents h2 { font-size: 0.82rem; margin: 0 0 0.8rem; }
.notes-contents ul { list-style: none; padding: 0; margin: 0; }
.notes-contents li { margin-bottom: 0.65rem; }
.notes-contents a { color: var(--muted); text-decoration: none; }
.notes-contents a:hover { color: var(--link); text-decoration: underline; }

.notes-adjacent {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  max-width: 820px;
  margin-top: 3rem;
  padding-top: 1.3rem;
  border-top: 1px solid var(--line);
  font-size: 0.9rem;
}

.notes-page .site-footer { max-width: 820px; }
.skip-link { position: absolute; left: 1rem; top: -5rem; padding: 0.5rem; background: white; z-index: 2; }
.skip-link:focus { top: 0.5rem; }

@media (max-width: 1100px) {
  .notes-shell { max-width: 820px; }
  .notes-layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .notes-contents { display: none; }
}

@media (max-width: 640px) {
  .notes-shell { width: calc(100% - 1.25rem); }
  .notebook-content .input_area { padding: 0.8rem; }
  .notebook-content pre { font-size: 0.76rem; }
}

@media print {
  .notes-shell { width: 100%; max-width: none; padding: 0; }
  .notes-layout { display: block; }
  .notes-contents, .notes-downloads, .notes-adjacent, .copy-code, .anchor-link, .skip-link { display: none; }
  .notebook-content pre { white-space: pre-wrap; overflow-wrap: anywhere; }
  .notebook-content img { max-height: 20cm; object-fit: contain; }
  .notebook-content h2, .notebook-content h3 { break-after: avoid; }
}
