/* ============================================================
   Operating Systems: A Hands-On Approach — custom theme

   mdBook sets 1rem = 10px (`:root { font-size: 62.5% }`). Sizes
   below are therefore given in em, relative to the 18px body
   text, so that nothing falls back to a 10px base.

   Colors are tokens. The light values are the defaults; the dark
   themes (coal, navy, ayu) redefine them below.
   ============================================================ */

:root {
  --content-max-width: 840px;
  --code-font-size: 0.86em;

  --ink: #1d1d1f;
  --ink-soft: #3a3a3c;
  --muted: #5f6368;
  --accent: #0066cc;
  --accent-ink: #004f9e;
  --paper: #ffffff;
  --wash: #f5f5f7;
  --hairline: #d2d2d7;
  --code-bg: #f7f7fa;
  --sidebar-surface: #f5f5f7;

  --key: #f8fafc;
  --key-line: #e2e8f0;
  --key-ink: #1d4ed8;
  --note: #f8fafc;
  --note-line: #e2e8f0;
  --note-ink: #475569;
  --exp: #f8fafc;
  --exp-line: #e2e8f0;
  --exp-ink: #0f766e;
  --warn: #fffbf5;
  --warn-line: #eadbc8;
  --warn-ink: #b45309;
  --sum: #f8fafc;
  --sum-line: #e2e8f0;
  --sum-ink: #4338ca;

  /* Material Design 3 Tonal Table tokens (calm, neutral elevation) */
  --m3-surface: #ffffff;
  --m3-table-head-bg: #f1f5f9;
  --m3-table-head-ink: #0f172a;
  --m3-table-row-alt: #f8fafc;
  --m3-hairline: #e2e8f0;
  --table-border-color: #e2e8f0;
  --table-header-bg: #f1f5f9;
  --table-alternate-bg: #f8fafc;
}

/* 1. Night Owl (navy — rich deep midnight blue #011627) */
html.navy {
  --bg: #011627;
  --fg: #EDF2FA;
  --sidebar-bg: #01111D;
  --sidebar-fg: #9EB9CC;
  --sidebar-non-existant: #567085;
  --sidebar-active: #89D8D3;
  --sidebar-spacer: #122D42;
  --scrollbar: #1D3B53;
  --icons: #8AA7BC;
  --icons-hover: #89D8D3;
  --links: #89B4FA;
  --inline-code-color: #89D8D3;
  --theme-popup-bg: #071F33;
  --theme-popup-border: #1D3B53;
  --theme-hover: #0B2942;
  --quote-bg: #071D30;
  --quote-border: #89D8D3;

  --ink: #EDF2FA;
  --ink-soft: #D5DFEE;
  --muted: #C0CCDE;
  --accent: #89B4FA;
  --accent-ink: #B7D2FC;
  --paper: #011627;
  --wash: rgba(137, 180, 250, 0.065);
  --hairline: #173752;
  --code-bg: #051A2B;
  --sidebar-surface: #01111D;

  --key: rgba(137, 180, 250, 0.06);
  --key-line: #173752;
  --key-ink: #89B4FA;
  --note: rgba(226, 232, 240, 0.045);
  --note-line: #173752;
  --note-ink: #C0CCDE;
  --exp: rgba(137, 216, 211, 0.06);
  --exp-line: #173752;
  --exp-ink: #89D8D3;
  --warn: rgba(242, 201, 138, 0.06);
  --warn-line: #173752;
  --warn-ink: #F2C98A;
  --sum: rgba(200, 182, 255, 0.06);
  --sum-line: #173752;
  --sum-ink: #C8B6FF;

  --m3-surface: #051B2E;
  --m3-table-head-bg: #0B2942;
  --m3-table-head-ink: #D8E8FC;
  --m3-table-row-alt: #082035;
  --m3-hairline: #173752;
  --table-border-color: #173752;
  --table-header-bg: #0B2942;
  --table-alternate-bg: #082035;
}

/* 2. Material Deep Ocean (coal — default dark #0F111A) */
html.coal {
  --bg: #0F111A;
  --fg: #EDF2FA;
  --sidebar-bg: #090B10;
  --sidebar-fg: #A1A9BC;
  --sidebar-non-existant: #5A627D;
  --sidebar-active: #89B4FA;
  --sidebar-spacer: #1B1F30;
  --scrollbar: #252C42;
  --icons: #8C9AB8;
  --icons-hover: #89D8D3;
  --links: #89B4FA;
  --inline-code-color: #89D8D3;
  --theme-popup-bg: #151926;
  --theme-popup-border: #252E45;
  --theme-hover: #1E273D;
  --quote-bg: #141926;
  --quote-border: #89B4FA;

  --ink: #EDF2FA;
  --ink-soft: #D5DFEE;
  --muted: #C0CCDE;
  --accent: #89B4FA;
  --accent-ink: #B7D2FC;
  --paper: #0F111A;
  --wash: rgba(137, 180, 250, 0.06);
  --hairline: #242E45;
  --code-bg: #141826;
  --sidebar-surface: #090B10;

  --key: rgba(137, 180, 250, 0.055);
  --key-line: #242E45;
  --key-ink: #89B4FA;
  --note: rgba(226, 232, 240, 0.04);
  --note-line: #242E45;
  --note-ink: #C0CCDE;
  --exp: rgba(137, 216, 211, 0.055);
  --exp-line: #242E45;
  --exp-ink: #89D8D3;
  --warn: rgba(242, 201, 138, 0.055);
  --warn-line: #242E45;
  --warn-ink: #F2C98A;
  --sum: rgba(200, 182, 255, 0.055);
  --sum-line: #242E45;
  --sum-ink: #C8B6FF;

  --m3-surface: #131724;
  --m3-table-head-bg: #18233A;
  --m3-table-head-ink: #D8E8FC;
  --m3-table-row-alt: #161B2A;
  --m3-hairline: #242E45;
  --table-border-color: #242E45;
  --table-header-bg: #18233A;
  --table-alternate-bg: #161B2A;
}

/* 3. Oceanic Next (ayu — calm deep teal-slate ocean #1B2B34) */
html.ayu {
  --bg: #1B2B34;
  --fg: #EDF2FA;
  --sidebar-bg: #142129;
  --sidebar-fg: #B0BDC7;
  --sidebar-non-existant: #6B7B87;
  --sidebar-active: #89D8D3;
  --sidebar-spacer: #263A45;
  --scrollbar: #344957;
  --icons: #97ACB8;
  --icons-hover: #89D8D3;
  --links: #89B4FA;
  --inline-code-color: #89D8D3;
  --theme-popup-bg: #20333E;
  --theme-popup-border: #344957;
  --theme-hover: #29414F;
  --quote-bg: #20333E;
  --quote-border: #89D8D3;

  --ink: #EDF2FA;
  --ink-soft: #D5DFEE;
  --muted: #C0CCDE;
  --accent: #89B4FA;
  --accent-ink: #B7D2FC;
  --paper: #1B2B34;
  --wash: rgba(137, 216, 211, 0.065);
  --hairline: #324C5C;
  --code-bg: #17262E;
  --sidebar-surface: #142129;

  --key: rgba(137, 180, 250, 0.06);
  --key-line: #324C5C;
  --key-ink: #89B4FA;
  --note: rgba(226, 232, 240, 0.045);
  --note-line: #324C5C;
  --note-ink: #C0CCDE;
  --exp: rgba(137, 216, 211, 0.06);
  --exp-line: #324C5C;
  --exp-ink: #89D8D3;
  --warn: rgba(242, 201, 138, 0.06);
  --warn-line: #324C5C;
  --warn-ink: #F2C98A;
  --sum: rgba(200, 182, 255, 0.06);
  --sum-line: #324C5C;
  --sum-ink: #C8B6FF;

  --m3-surface: #1E303A;
  --m3-table-head-bg: #27404E;
  --m3-table-head-ink: #D8E8FC;
  --m3-table-row-alt: #21343F;
  --m3-hairline: #324C5C;
  --table-border-color: #324C5C;
  --table-header-bg: #27404E;
  --table-alternate-bg: #21343F;
}

html.coal .content h1, html.navy .content h1, html.ayu .content h1 { color: #F4F8FF; }
html.coal .content h2, html.navy .content h2, html.ayu .content h2 { color: #D4E4FF; }
html.coal .content h3, html.navy .content h3, html.ayu .content h3 { color: #A9CBFF; }

.content img.plate {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 14px;
  margin: 0.6em 0 1.4em 0;
  box-shadow: none;
}

html.rust {
  --paper: var(--bg);
  --sidebar-surface: var(--sidebar-bg);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1.8rem;
  color: var(--ink);
  background: var(--paper);
}

.content main {
  line-height: 1.68;
}

/* ---------- Headings ---------- */

.content h1 {
  font-size: 2em;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin: 0 0 0.6em;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--hairline);
}

.content h2 {
  font-size: 1.45em;
  font-weight: 650;
  line-height: 1.3;
  letter-spacing: -0.01em;
  margin-top: 1.9em;
  margin-bottom: 0.5em;
}

.content h2 .md-sec-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  transform: translateY(-0.08em);
  margin-right: 0.38em;
  width: 1.12em;
  height: 1.12em;
  border-radius: 6px;
  background: var(--wash);
  color: var(--accent);
  border: 1px solid var(--hairline);
}

.content h2 .md-sec-icon svg {
  width: 0.72em;
  height: 0.72em;
  fill: currentColor;
}

.content h3 {
  font-size: 1.18em;
  font-weight: 600;
  line-height: 1.35;
  margin-top: 1.6em;
  margin-bottom: 0.45em;
}

/* Clean Material chevron list markers (only for remaining short reference/exercise lists) */
.content main ul {
  list-style: none;
  padding-left: 1.55em;
}

.content main ul > li {
  position: relative;
  margin: 0.5em 0;
}

.content main ul > li::before {
  content: "";
  position: absolute;
  left: -1.35em;
  top: 0.34em;
  width: 1em;
  height: 1em;
  background-color: var(--accent);
  opacity: 0.82;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z'/%3E%3C/svg%3E");
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
}

.content h1, .content h2, .content h3, .content h4 { color: var(--ink); }

/* ---------- Body text ---------- */

.content main p { margin: 0 0 1em; }

.content strong { color: var(--ink); }

.content a { color: var(--accent); text-decoration: none; }
.content a:hover { color: var(--accent-ink); text-decoration: underline; }
.content .header:link, .content .header:visited { color: var(--ink); }

.content blockquote {
  border-left: 3px solid var(--hairline);
  border-top: 0;
  border-bottom: 0;
  margin: 1.1em 0;
  padding: 0.4em 1em;
  color: var(--ink-soft);
  background: var(--wash);
  border-radius: 0 6px 6px 0;
}

/* ---------- Code ---------- */

.content pre {
  background: var(--code-bg);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 0;
  line-height: 1.55;
}

.content pre > code {
  display: block;
  padding: 0.95em 1.15em;
  overflow-x: auto;
}

.content code {
  font-family: "SF Mono", SFMono-Regular, ui-monospace, Menlo, Consolas,
    "Liberation Mono", monospace;
  font-size: var(--code-font-size);
}

.content :not(pre) > code {
  background: var(--wash);
  border-radius: 5px;
  padding: 0.12em 0.38em;
}

.content pre > code, .content pre > code.hljs { background: transparent; }

/* ---------- Figures ---------- */

.content img.cover {
  display: block;
  max-width: 560px;
  width: 100%;
  margin: 1em auto 1.8em;
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
}

.content figure {
  margin: 1.8em 0;
  text-align: center;
  page-break-inside: avoid;
}

.content figure img {
  display: block;
  width: 100%;
  max-width: 800px;
  height: auto;
  margin: 0 auto;
  border-radius: 16px;
}

.content figure figcaption {
  margin: 0.6em auto 0;
  font-size: 0.9em;
  color: var(--muted);
  max-width: 42em;
}

/* ---------- Material Design 3 Callout Cards with Icons & Elevation ---------- */

.callout {
  border-radius: 12px;
  border: 1px solid var(--note-line);
  border-left: 4px solid var(--note-ink);
  padding: 1.05em 1.25em 1em;
  margin: 1.5em 0;
  font-size: 0.96em;
  box-shadow: 0 2px 10px rgba(27, 36, 48, 0.07), 0 1px 2px rgba(27, 36, 48, 0.04);
  page-break-inside: avoid;
}

html.coal .callout,
html.navy .callout,
html.ayu .callout {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.34);
}

.callout p { margin: 0.45em 0; }
.callout p:first-child { margin-top: 0; }
.callout p:last-child { margin-bottom: 0; }

.callout .label {
  display: flex;
  align-items: center;
  gap: 0.5em;
  font-weight: 700;
  font-size: 0.8em;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 0.55em;
}

.callout .label::before {
  content: "";
  display: inline-block;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  background-color: currentColor;
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}

.keyidea { background: var(--key); border-color: var(--key-line); border-left-color: var(--key-ink); }
.keyidea .label { color: var(--key-ink); }
.keyidea .label::before {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 21c0 .55.45 1 1 1h4c.55 0 1-.45 1-1v-1H9v1zm3-19C8.14 2 5 5.14 5 9c0 2.38 1.19 4.47 3 5.74V17c0 .55.45 1 1 1h6c.55 0 1-.45 1-1v-2.26c1.81-1.27 3-3.36 3-5.74 0-3.86-3.14-7-7-7z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 21c0 .55.45 1 1 1h4c.55 0 1-.45 1-1v-1H9v1zm3-19C8.14 2 5 5.14 5 9c0 2.38 1.19 4.47 3 5.74V17c0 .55.45 1 1 1h6c.55 0 1-.45 1-1v-2.26c1.81-1.27 3-3.36 3-5.74 0-3.86-3.14-7-7-7z'/%3E%3C/svg%3E");
}

.note { background: var(--note); border-color: var(--note-line); border-left-color: var(--note-ink); }
.note .label { color: var(--note-ink); }
.note .label::before {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z'/%3E%3C/svg%3E");
}

.experiment { background: var(--exp); border-color: var(--exp-line); border-left-color: var(--exp-ink); }
.experiment .label { color: var(--exp-ink); }
.experiment .label::before {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M19.8 18.4L14 10.67V6.5l1.35-1.69c.26-.33.03-.81-.39-.81H9.04c-.42 0-.65.48-.39.81L10 6.5v4.17L4.2 18.4c-.49.66-.02 1.6.8 1.6h14c.82 0 1.29-.94.8-1.6z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M19.8 18.4L14 10.67V6.5l1.35-1.69c.26-.33.03-.81-.39-.81H9.04c-.42 0-.65.48-.39.81L10 6.5v4.17L4.2 18.4c-.49.66-.02 1.6.8 1.6h14c.82 0 1.29-.94.8-1.6z'/%3E%3C/svg%3E");
}

.caution { background: var(--warn); border-color: var(--warn-line); border-left-color: var(--warn-ink); }
.caution .label { color: var(--warn-ink); }
.caution .label::before {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z'/%3E%3C/svg%3E");
}

.summary { background: var(--sum); border-color: var(--sum-line); border-left-color: var(--sum-ink); }
.summary .label { color: var(--sum-ink); }
.summary .label::before {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z'/%3E%3C/svg%3E");
}

.glance { background: var(--note); border-color: var(--note-line); }
.glance .label { color: var(--note-ink); }
.glance ul { margin: 0.2em 0 0; padding-left: 1.2em; }
.glance li { margin: 0.2em 0; }

/* ---------- Material Design 3 Tonal Data Tables (matching Distributed Systems) ---------- */

.content table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 1.5em 0;
  font-size: 0.91em;
  background: var(--m3-surface);
  border: 1px solid var(--m3-hairline);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(27, 36, 48, 0.05);
}

html.coal .content table,
html.navy .content table,
html.ayu .content table {
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.3);
}

.content table thead th {
  background: var(--m3-table-head-bg) !important;
  color: var(--m3-table-head-ink) !important;
  font-weight: 650;
  text-align: left;
  padding: 0.65em 0.9em;
  border: none;
  border-bottom: 1px solid var(--m3-hairline);
}

.content table td {
  padding: 0.62em 0.9em;
  border: none;
  border-bottom: 1px solid var(--m3-hairline);
  vertical-align: baseline;
  line-height: 1.55;
}

.content table td:first-child {
  font-variant-numeric: tabular-nums;
}

.content table tbody tr:last-child td {
  border-bottom: none;
}

.content table tbody tr:nth-child(2n) {
  background: var(--m3-table-row-alt) !important;
}

.content table tbody tr:nth-child(2n+1) {
  background: transparent !important;
}

/* ---------- Material Design Code Tabs (C++20 | Rust 2024 | Split) ---------- */

.md-code-tabs {
  margin: 1.5em 0;
  border: 1px solid var(--hairline);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 2px 10px rgba(27, 36, 48, 0.06);
  overflow: hidden;
}

html.coal .md-code-tabs,
html.navy .md-code-tabs,
html.ayu .md-code-tabs {
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.32);
}

.md-code-tabs-bar {
  display: flex;
  align-items: stretch;
  gap: 4px;
  padding: 6px 10px 0;
  background: var(--wash);
  border-bottom: 1px solid var(--hairline);
}

.md-code-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px 9px;
  border: none;
  border-bottom: 3px solid transparent;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.84em;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.md-code-tab:hover {
  background: rgba(0, 102, 204, 0.06);
  color: var(--ink);
}

.md-code-tab.active {
  background: var(--paper);
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.md-code-tab-split {
  margin-left: auto;
}

.md-lang-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78em;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.md-lang-chip.cpp {
  background: #e6effd;
  color: #1a5fc4;
}

.md-lang-chip.rust {
  background: #fde8e4;
  color: #bf3620;
}

.md-lang-chip.split {
  background: #eef0f4;
  color: #3a3a3c;
}

html.coal .md-lang-chip.cpp,
html.navy .md-lang-chip.cpp,
html.ayu .md-lang-chip.cpp {
  background: rgba(90, 150, 255, 0.22);
  color: #9cc0fb;
}

html.coal .md-lang-chip.rust,
html.navy .md-lang-chip.rust,
html.ayu .md-lang-chip.rust {
  background: rgba(245, 130, 100, 0.22);
  color: #f59e8d;
}

html.coal .md-lang-chip.split,
html.navy .md-lang-chip.split,
html.ayu .md-lang-chip.split {
  background: rgba(255, 255, 255, 0.12);
  color: #d6dbe6;
}

.md-code-panels {
  display: block;
}

.md-code-panel {
  display: none;
  padding: 0.75em 0.9em 0.85em;
  min-width: 0;
}

.md-code-panel.active {
  display: block;
}

.md-code-panel > p {
  margin: 0.65em 0 0.4em;
  font-size: 0.9em;
}

.md-code-panel > p:first-child {
  margin-top: 0;
}

.md-code-panel pre {
  margin: 0.4em 0 0.7em;
  border-radius: 8px;
}

.md-code-panel pre:last-child {
  margin-bottom: 0;
}

/* Side-by-Side Split View (desktop) */
.md-code-tabs.is-split .md-code-panels {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.md-code-tabs.is-split .md-code-panel {
  display: block;
  padding: 0.75em 0.8em 0.85em;
}

.md-code-tabs.is-split .md-code-panel:first-child {
  border-right: 1px solid var(--hairline);
}

.md-code-tabs.is-split .md-code-panel pre > code {
  font-size: 0.78em;
  padding: 0.8em 0.9em;
}

@media (min-width: 1280px) {
  .md-code-tabs.is-split {
    width: calc(100% + 180px);
    max-width: 1060px;
    margin-left: -90px;
  }
}

@media (max-width: 960px) {
  .md-code-tab-split {
    display: none;
  }
  .md-code-tabs.is-split .md-code-panels {
    display: block;
  }
  .md-code-tabs.is-split .md-code-panel:first-child {
    border-right: none;
  }
}

/* ---------- Clickable Abbreviation Glossary Links & Tooltips ---------- */

.content a.md-abbr-link {
  color: inherit;
  border-bottom: 1.5px dotted var(--accent);
  text-decoration: none;
  border-radius: 2px;
  padding: 0 1px;
  transition: background-color 0.14s ease, color 0.14s ease;
}

.content a.md-abbr-link:hover {
  background: var(--key);
  color: var(--key-ink);
  text-decoration: none;
}

.content code > a.md-abbr-link.md-abbr-code {
  border-bottom: 1.5px dotted var(--accent);
  color: inherit;
}

/* ---------- Textbook Glossary Typography (Clean, Single-Column, Syntax-Highlighted) ---------- */

.md-glossary-term {
  padding: 1.15em 0 1.25em;
  border-bottom: 1px solid var(--hairline);
  scroll-margin-top: 76px;
}

.md-glossary-term:target {
  background: var(--wash);
  padding: 1.15em 1.1em 1.25em;
  margin: 0 -1.1em;
  border-radius: 8px;
  border-left: 3px solid var(--accent);
}

.md-glossary-term h3 {
  margin: 0 0 0.45em !important;
  font-size: 1.12em;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.55em;
}

.md-glossary-term .md-term-chip {
  font-family: "SF Mono", SFMono-Regular, ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.84em;
  font-weight: 700;
  color: var(--accent);
  background: var(--wash);
  border: 1px solid var(--hairline);
  padding: 2px 8px;
  border-radius: 5px;
}

.md-glossary-term .md-term-full {
  font-weight: 650;
  color: var(--ink);
}

.md-glossary-term p {
  margin: 0.35em 0 0.7em !important;
  color: var(--ink-soft);
}

.md-glossary-term pre {
  margin: 0.5em 0 0 !important;
}

/* ---------- Sidebar ---------- */

.sidebar {
  background: var(--sidebar-surface);
  border-right: 1px solid var(--hairline);
  font-size: 1.5rem;
}

.chapter li.part-title { color: var(--muted); font-weight: 600; }
.chapter li a:hover { color: var(--accent); }
.chapter li a.active { color: var(--accent); font-weight: 600; }

/* ---------- Wide screens: figures extend past the text column ---------- */

@media (min-width: 1280px) {
  .content figure img {
    width: calc(100% + 80px);
    max-width: 920px;
    margin-left: -40px;
  }
}

/* ---------- Small screens ---------- */

@media (max-width: 700px) {
  body { font-size: 1.7rem; }
  .content h1 { font-size: 1.7em; }
  .content h2 { font-size: 1.32em; }
  .callout { padding: 0.85em 1em; }

  /* Mobile-optimized Material code tabs: eliminate nested horizontal padding */
  .md-code-tabs {
    margin: 1.2em -12px;
    border-radius: 8px;
    border-left: none;
    border-right: none;
  }
  .md-code-tabs-bar {
    padding: 4px 6px 0;
    gap: 2px;
  }
  .md-code-tab {
    flex: 1;
    justify-content: center;
    padding: 8px 6px;
    font-size: 0.8em;
    gap: 5px;
  }
  .md-code-panel {
    padding: 0.55em 0 0;
  }
  .md-code-panel > p {
    padding: 0 12px;
    font-size: 0.85em;
  }
  .md-code-panel pre {
    border-left: none;
    border-right: none;
    border-radius: 0;
    margin: 0.35em 0 0.5em;
  }
  .md-code-panel pre > code {
    padding: 0.7em 12px;
    font-size: 0.78em;
  }

  /* A figure keeps a readable size and scrolls sideways. */
  .content figure { overflow-x: auto; }
  .content figure img { width: 680px; max-width: none; }
}

/* ---------- Print (used by the generated print.html and PDF) ---------- */

@media print {
  @page {
    size: Letter;
    margin: 10mm 12mm 12mm 12mm;
    background: #ffffff;
  }

  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  :root, html, body, html.coal, html.navy, html.ayu, html.rust, html.light {
    --bg: #ffffff !important;
    --fg: #1d1d1f !important;
    --ink: #1d1d1f !important;
    --ink-soft: #3a3a3c !important;
    --muted: #5f6368 !important;
    --accent: #0066cc !important;
    --accent-ink: #004f9e !important;
    --paper: #ffffff !important;
    --wash: #f5f5f7 !important;
    --hairline: #d2d2d7 !important;
    --code-bg: #f7f7fa !important;
    --m3-surface: #ffffff !important;
    --m3-table-head-bg: #f1f5f9 !important;
    --m3-table-head-ink: #0f172a !important;
    --m3-table-row-alt: #f8fafc !important;
    --m3-hairline: #e2e8f0 !important;
    background: #ffffff !important;
    background-color: #ffffff !important;
    color: #111111 !important;
  }

  html.coal .content h1, html.navy .content h1, html.ayu .content h1,
  html.coal .content h2, html.navy .content h2, html.ayu .content h2,
  html.coal .content h3, html.navy .content h3, html.ayu .content h3 {
    color: #111111 !important;
  }

  body {
    font-size: 10pt !important;
    line-height: 1.48 !important;
    color: #111111 !important;
    background: #ffffff !important;
  }

  #mdbook-content,
  .page-wrapper,
  .page,
  .content,
  .content main {
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .content main p {
    margin: 0 0 0.65em !important;
  }

  /* Headings */
  .content h1 {
    break-before: auto !important;
    font-size: 18pt !important;
    margin-top: 0 !important;
    margin-bottom: 0.5em !important;
    padding-bottom: 0.25em !important;
    border-bottom: 1.5px solid #d2d2d7 !important;
  }
  .content main > h1:first-child {
    break-before: auto !important;
  }

  h1, h2, h3, h4,
  .content h1, .content h2, .content h3, .content h4 {
    break-after: avoid !important;
    page-break-after: avoid !important;
  }

  .content h2 {
    font-size: 13.5pt !important;
    margin-top: 1.1em !important;
    margin-bottom: 0.35em !important;
    border-bottom: 1px solid #e5e5ea !important;
    padding-bottom: 0.15em !important;
  }

  .content h3 {
    font-size: 11.5pt !important;
    margin-top: 0.9em !important;
    margin-bottom: 0.25em !important;
  }

  .content h4 {
    font-size: 10.2pt !important;
    margin-top: 0.75em !important;
    margin-bottom: 0.2em !important;
  }

  /* Code blocks: allow natural flow across pages to eliminate huge empty gaps */
  pre,
  code,
  .content pre,
  .content pre > code {
    page-break-inside: auto !important;
    break-inside: auto !important;
  }

  .content code {
    font-size: 8.5pt !important;
  }

  .content pre {
    background: #f7f8fa !important;
    border: 1px solid #dcdfe4 !important;
    border-radius: 6px !important;
    margin: 0.75em 0 !important;
    padding: 0 !important;
  }

  .content pre > code {
    white-space: pre-wrap !important;
    overflow-wrap: anywhere !important;
    padding: 0.6em 0.8em !important;
    line-height: 1.38 !important;
  }

  /* Figures and Tables */
  .content img.cover {
    max-width: 78% !important;
    max-height: 220mm !important;
    width: auto !important;
    margin: 6mm auto 8mm !important;
    border-radius: 8px !important;
    box-shadow: none !important;
    page-break-after: always !important;
    break-after: page !important;
  }

  .content figure {
    margin: 1.2em 0 !important;
    page-break-inside: auto !important;
    break-inside: auto !important;
    overflow: visible !important;
  }

  .content figure img {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: auto !important;
    border-radius: 8px !important;
  }

  .content figure figcaption {
    font-size: 8.5pt !important;
    margin-top: 0.4em !important;
  }

  table,
  .content table {
    page-break-inside: auto !important;
    break-inside: auto !important;
    margin: 0.85em 0 !important;
    font-size: 8.8pt !important;
  }

  .content table th, .content table td {
    padding: 0.3em 0.55em !important;
  }

  /* Callouts */
  .callout {
    page-break-inside: auto !important;
    break-inside: auto !important;
    margin: 0.85em 0 !important;
    padding: 0.65em 0.9em !important;
    font-size: 9pt !important;
    border-radius: 6px !important;
  }

  .callout p {
    margin: 0.2em 0 !important;
  }

  /* High-Contrast Syntax Highlighting for Print */
  .content pre code span { font-weight: inherit !important; }
  .hljs-keyword, .hljs-selector-tag { color: #8959a8 !important; }
  .hljs-string, .hljs-symbol { color: #718c00 !important; }
  .hljs-title, .hljs-section, .hljs-function { color: #4271ae !important; }
  .hljs-comment, .hljs-quote { color: #8e908c !important; font-style: italic !important; }
  .hljs-number, .hljs-literal, .hljs-type { color: #f5871f !important; }
  .hljs-attr, .hljs-attribute { color: #c82829 !important; }
  .hljs-built_in, .hljs-params { color: #3e999f !important; }
  .hljs-meta { color: #e78c45 !important; }
  .hljs-addition { color: #22863a !important; background-color: #f0fff4 !important; }
  .hljs-deletion { color: #b31d28 !important; background-color: #ffeef0 !important; }
  .hljs-variable, .hljs-template-variable { color: #c82829 !important; }

  /* Hide UI chrome */
  .sidebar, .menu-bar, .nav-chapters, #mdbook-help-container,
  #mdbook-help-popup, .buttons, .fa, .md-code-tabs-bar { display: none !important; }

  .md-code-tabs {
    border: none !important;
    box-shadow: none !important;
    margin: 0.6em 0 !important;
    padding: 0 !important;
  }

  .md-code-panel {
    display: block !important;
    padding: 0 !important;
    margin: 0.5em 0 !important;
  }

  .content a.md-abbr-link {
    border-bottom: none !important;
    color: inherit !important;
  }
}
