.lucide {
  height: auto;
  width: 1em;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: var(--bs-spacer-2);
}

.navbar-brand .lucide {
  width: 1.5em;
}

.chapter-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--bs-spacer-2) var(--bs-spacer-5);
  padding: var(--bs-spacer-3) 0;
  border-block: 1px solid var(--bs-border-color);
  list-style: none;
}

.chapter-meta li {
  display: flex;
  align-items: center;
  gap: var(--bs-spacer-2);
}

/* Icon in a round chip tinted by the list's theme-* class. */
.chapter-meta .lucide {
  box-sizing: content-box;
  padding: .4em;
  border-radius: 50%;
  color: var(--bs-theme-fg);
  background: var(--bs-theme-bg-subtle);
}

.chapter-list .nav-link {
  --bs-nav-link-justify: start;
}

@media screen and (min-width: 768px) {
  .course-aside {
    min-width: 14rem;
  }
}

/* Element selector so it beats .btn-icon's cursor: pointer. */
button[data-sortable-handle] {
  cursor: grab;
}

button[data-sortable-handle]:active {
  cursor: grabbing;
}

/* Chapter sections, edited like a document: no frames, tools on hover/focus. */
.section-block {
  position: relative;
  padding-block: .25rem;
}

.section-gutter,
.section-tools {
  position: absolute;
  top: .25rem;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: .125rem;
  opacity: 0;
  transition: opacity .15s ease-in-out;
}

/* Vertically centred on the block; the add menu's wrapper is a flex box so both buttons line up. */
.section-gutter {
  top: 50%;
  right: 100%;
  padding-right: .25rem;
  transform: translateY(-50%);
}

.section-gutter > [id$="-add-after"] {
  display: flex;
}

/* Straddles the block's top-right corner, so it doesn't cover the content. */
.section-tools {
  top: 0;
  right: -1rem;
  transform: translateY(-50%);
  gap: .25rem;
  padding: .125rem .25rem;
  border-radius: var(--bs-radius-5);
  background-color: var(--bs-bg-body);
  box-shadow: 0 1px 3px rgb(0 0 0 / .12);
}

.section-block:hover > :is(.section-gutter, .section-tools),
.section-block:focus-within > :is(.section-gutter, .section-tools),
.section-block:has(.show) > :is(.section-gutter, .section-tools),
.section-block:has(.section-tools .invalid-feedback) > .section-tools {
  opacity: 1;
}

.section-type {
  padding-inline: .25rem;
  font-size: var(--bs-font-size-sm);
  color: var(--bs-fg-3);
}

.section-body textarea.form-ghost {
  min-height: 1.5em;
  padding: .25rem .5rem;
  resize: none;
  field-sizing: content;
}

.section-heading textarea.form-ghost {
  font-weight: 600;
  line-height: 1.25;
}

.section-heading-2 textarea.form-ghost { font-size: 1.75rem; }
.section-heading-3 textarea.form-ghost { font-size: 1.5rem; }
.section-heading-4 textarea.form-ghost { font-size: 1.25rem; }
.section-heading-5 textarea.form-ghost { font-size: 1.1rem; }
.section-heading-6 textarea.form-ghost { font-size: 1rem; }

.section-quote .section-body {
  margin-left: .5rem;
  border-left: 3px solid var(--bs-border-color);
}

.section-quote textarea.form-ghost {
  font-style: italic;
}

.section-callout .section-body {
  padding: .5rem;
  border-radius: var(--bs-radius-5);
  background-color: var(--bs-theme-bg-subtle, var(--bs-bg-2));
}

.section-code .section-body,
.section-mermaid .section-body {
  padding-block: .5rem;
  border-radius: var(--bs-radius-5);
}

/* Colour sample in a themed combobox item (the item carries the .theme-* class). */
.color-swatch {
  width: .875rem;
  height: .875rem;
  flex-shrink: 0;
  border: 1px solid var(--bs-theme-border, var(--bs-border-color));
  border-radius: 50%;
  background-color: var(--bs-theme-bg-subtle, var(--bs-bg-2));
}

/* Mermaid code / preview toggle: one icon per state. */
.mermaid-preview-toggle[aria-pressed="true"] .icon-when-code,
.mermaid-preview-toggle:not([aria-pressed="true"]) .icon-when-preview {
  display: none;
}

.mermaid-preview {
  padding: .5rem 1rem;
  overflow-x: auto;
  text-align: center;
  cursor: pointer;
}

.mermaid-preview-error {
  margin: 0;
  font-size: var(--bs-font-size-sm);
  color: var(--bs-danger-fg);
  text-align: start;
  white-space: pre-wrap;
}

/* Rendered chapter (ChapterRenderer): Shiki code blocks and Mermaid diagrams. */
.chapter-content pre {
  font-size: .875em;
}

.chapter-content pre.shiki {
  padding-block: 1rem;
  border-radius: var(--bs-radius-5);
  overflow-x: auto;
}

/* Full-width lines, padded themselves, so that their background reaches the edges. */
.chapter-content pre.shiki code {
  display: block;
  width: fit-content;
  min-width: 100%;
}

.chapter-content pre.shiki .line {
  display: inline-block;
  width: 100%;
  padding-inline: 1.5rem 1rem;
}

/* Shiki transformers: // [!code ++|--|highlight|error|warning|focus|word:xxx]
   Translucent with a solid edge, so that it shows on the light and dark Shiki backgrounds. */
.chapter-content pre.shiki .line.diff,
.chapter-content pre.shiki .line.highlighted {
  position: relative;
  --line-color: var(--bs-primary-fg);
  background-color: color-mix(in oklch, var(--line-color) 20%, transparent);
  box-shadow: inset 3px 0 var(--line-color);
}

.chapter-content pre.shiki .line.diff.add { --line-color: var(--bs-success-fg); }
.chapter-content pre.shiki .line.diff.remove { --line-color: var(--bs-danger-fg); opacity: .7; }
.chapter-content pre.shiki .line.highlighted.error { --line-color: var(--bs-danger-fg); }
.chapter-content pre.shiki .line.highlighted.warning { --line-color: var(--bs-warning-fg); }

.chapter-content pre.shiki .line.diff::before {
  position: absolute;
  left: .5rem;
  user-select: none;
}

.chapter-content pre.shiki .line.diff.add::before { content: "+"; color: var(--bs-success-fg); }
.chapter-content pre.shiki .line.diff.remove::before { content: "-"; color: var(--bs-danger-fg); }

.chapter-content pre.shiki .highlighted-word {
  padding: 0 .125rem;
  border: 1px solid var(--bs-primary-fg);
  border-radius: var(--bs-radius-2);
  background-color: color-mix(in oklch, var(--bs-primary-fg) 20%, transparent);
}

/* Lines out of focus fade, until the block is hovered. */
.chapter-content pre.shiki.has-focused .line:not(.focused) {
  opacity: .5;
  filter: blur(1px);
  transition: opacity .2s, filter .2s;
}

.chapter-content pre.shiki.has-focused:hover .line:not(.focused) {
  opacity: 1;
  filter: none;
}

/* Shiki writes light colours inline and dark ones in --shiki-dark variables; its <pre> is data-bs-theme="dark". */
.chapter-content .shiki[data-bs-theme="dark"],
[data-bs-theme="dark"] .chapter-content .shiki {
  background-color: var(--shiki-dark-bg) !important;
}

/* Colours only: the line backgrounds of the transformers stay. */
.chapter-content .shiki[data-bs-theme="dark"],
.chapter-content .shiki[data-bs-theme="dark"] span,
[data-bs-theme="dark"] .chapter-content .shiki,
[data-bs-theme="dark"] .chapter-content .shiki span {
  color: var(--shiki-dark) !important;
  font-style: var(--shiki-dark-font-style) !important;
  font-weight: var(--shiki-dark-font-weight) !important;
  text-decoration: var(--shiki-dark-text-decoration) !important;
}

/* Copy button of code blocks (code_copy_controller): on hover and keyboard focus, always on touch screens. */
.chapter-content .code-block {
  position: relative;
}

.chapter-content .code-copy {
  /* .btn-icon has no hover colour: without it, the dark page text colour is inherited on hover. */
  --bs-btn-hover-color: var(--bs-btn-color);
  position: absolute;
  top: .5rem;
  right: .5rem;
  opacity: 0;
  transition: opacity .15s;
}

.chapter-content .code-block:hover .code-copy,
.chapter-content .code-block:focus-within .code-copy {
  opacity: 1;
}

@media (hover: none) {
  .chapter-content .code-copy { opacity: 1; }
}

.chapter-content .code-copy.copied {
  color: var(--bs-success-fg);
}

.chapter-content .mermaid-diagram {
  margin-block: 1rem;
  overflow-x: auto;
  text-align: center;
}

/* Diagrams come in a light and a dark rendering (ChapterRenderer). The dark one shows with
   data-bs-theme="dark", or with a dark system preference unless the page is data-bs-theme="light". */
.chapter-content .mermaid-dark {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-bs-theme="light"]) .chapter-content .mermaid-light { display: none; }
  :root:not([data-bs-theme="light"]) .chapter-content .mermaid-dark { display: block; }
}

[data-bs-theme="dark"] .chapter-content .mermaid-light { display: none; }
[data-bs-theme="dark"] .chapter-content .mermaid-dark { display: block; }

/* Printing (and PDF export) of a page: only its content. Bootstrap 6 has no d-print-* utilities yet. */
/* 1.5cm in all: .75cm here, .75cm of container padding (print), which code blocks reach into. */
@page {
  size: A4;
  margin: 1.5cm .75cm;

  /* Page number, e.g. "1 / 3" (Chrome/Edge 131+; Firefox and Safari ignore @page margin boxes). */
  @bottom-center {
    content: counter(page) " / " counter(pages);
    font: 9pt sans-serif;
    color: #000;
  }
}

@media print {
  .d-print-none {
    display: none !important;
  }

  /* The content column spans the whole page, inside the @page margins. */
  main {
    margin-block: 0 !important;
  }

  .container {
    max-width: none;
    padding-inline: .75cm;
  }

  .row {
    margin-inline: 0;
  }

  .row > * {
    padding-inline: 0;
  }

  /* Keep the dark code blocks, annotated lines and diagram colours: browsers drop backgrounds by default. */
  .chapter-content pre.shiki,
  .chapter-content .mermaid-diagram {
    -webkit-print-color-adjust: exact; /* Safari */
    print-color-adjust: exact;
    break-inside: avoid;
  }

  /* No horizontal scroll on paper: long lines wrap. The block reaches a little into the page margins. */
  .chapter-content pre.shiki {
    margin-inline: -.75cm;
    overflow: visible;
    white-space: pre-wrap;
  }

  /* Light diagrams on paper, whatever the screen theme. */
  .chapter-content .mermaid-light { display: block !important; }
  .chapter-content .mermaid-dark { display: none !important; }

  .chapter-content pre.shiki.has-focused .line:not(.focused) {
    opacity: 1;
    filter: none;
  }
}
