@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap");

/* ============================================================
   Shared tutorial styles
   Used by: system-design/systemdesign.html,
            agentic-system/agentic-ai.html,
            agentic-usecases/agetic-usecases.html
   ============================================================ */

:root {
  --paper: #f8f9fb;
  --card: #ffffff;
  --ink: #1a1a2e;
  --muted: #4a4a68;
  --line: #e5e7eb;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --code-bg: #f1f5f9;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
  --radius: 12px;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SFMono-Regular', 'Menlo', monospace;
  --body-size: clamp(15.5px, 1rem + 0.1vw, 16.5px);
  --body-leading: 1.72;
  --measure: 72ch;
  --sidebar-size: 0.875rem;
  --meta-size: 0.875rem;
  --small-size: 0.85rem;
  --table-size: 0.875rem;
  --code-size: 0.875rem;
  --topbar-bg: rgba(255, 255, 255, 0.92);
  --topbar-border: rgba(0, 0, 0, 0.08);
  --topbar-shadow: 0 1px 8px rgba(0, 0, 0, 0.06);
  --dropdown-bg: rgba(255, 255, 255, 0.97);
  --body-bg-start: #f8f9fb;
  --body-bg-mid: #ffffff;
  --body-bg-end: #f8f9fb;
  --pre-bg: #f8fafc;
  --thead-bg: #eff6ff;
  --btn-bg: rgba(255, 255, 255, 0.7);
  --btn-bg-hover: rgba(255, 255, 255, 0.95);
  --btn-border: rgba(0, 0, 0, 0.12);
  --btn-border-hover: rgba(37, 99, 235, 0.4);
  --item-hover-bg: rgba(37, 99, 235, 0.06);
  --item-active-bg: rgba(37, 99, 235, 0.1);
  --item-active-color: #1d4ed8;
  --divider: rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] {
  --paper: #0f1117;
  --card: #1a2032;
  --ink: #e8eaf6;
  --muted: #9ba3c0;
  --line: #2a3150;
  --accent: #60a5fa;
  --accent-soft: #1e3a5f;
  --code-bg: #1e293b;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);
  --topbar-bg: rgba(15, 17, 23, 0.96);
  --topbar-border: rgba(255, 255, 255, 0.07);
  --topbar-shadow: 0 1px 8px rgba(0, 0, 0, 0.4);
  --dropdown-bg: rgba(15, 17, 23, 0.99);
  --body-bg-start: #0f1117;
  --body-bg-mid: #161b27;
  --body-bg-end: #0f1117;
  --pre-bg: #161b27;
  --thead-bg: #1e3a5f;
  --btn-bg: rgba(255, 255, 255, 0.07);
  --btn-bg-hover: rgba(255, 255, 255, 0.13);
  --btn-border: rgba(255, 255, 255, 0.1);
  --btn-border-hover: rgba(255, 255, 255, 0.22);
  --item-hover-bg: rgba(96, 165, 250, 0.1);
  --item-active-bg: rgba(96, 165, 250, 0.16);
  --item-active-color: #93c5fd;
  --divider: rgba(255, 255, 255, 0.07);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background: linear-gradient(180deg, var(--body-bg-start) 0%, var(--body-bg-mid) 40%, var(--body-bg-end) 100%);
  font-family: var(--font-body);
  font-size: var(--body-size);
  line-height: var(--body-leading);
  letter-spacing: 0.002em;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  font-kerning: normal;
}

body.has-atlas-topbar {
  padding-top: 68px;
}

a {
  color: var(--accent);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.14em;
}

/* ============================================================
   Shared topbar
   ============================================================ */

.atlas-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--topbar-border);
  background: var(--topbar-bg);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  box-shadow: var(--topbar-shadow);
}

.atlas-topbar__left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.atlas-topbar__center {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-width: 0;
}

.atlas-topbar__right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex: 1;
}

.atlas-topbar__brand {
  color: var(--clay-deep, var(--accent, #7f3519));
  text-decoration: none;
  flex-shrink: 0;
  display: -webkit-inline-flex;
  display: inline-flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-align-items: flex-start;
  align-items: flex-start;
  gap: 4px;
}

.atlas-topbar__brand-title {
  font: 700 0.88rem/1 var(--font-ui, "Segoe UI", "Helvetica Neue", Arial, system-ui, sans-serif);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  white-space: nowrap;
}

.atlas-topbar__byline {
  font: 400 0.66rem/1 var(--font-ui, "Segoe UI", "Helvetica Neue", Arial, system-ui, sans-serif);
  letter-spacing: 0.03em;
  text-transform: none;
  color: var(--muted);
  opacity: 0.85;
  white-space: nowrap;
}

.atlas-topbar__nav-menu,
.atlas-topbar__menu {
  position: relative;
}

.atlas-topbar__nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: 160px;
  min-height: 34px;
  padding: 6px 12px 6px 14px;
  border: 1px solid var(--btn-border);
  border-radius: 999px;
  background: var(--btn-bg);
  color: var(--ink);
  font: 600 0.88rem/1 var(--font-ui, "Segoe UI", "Helvetica Neue", Arial, system-ui, sans-serif);
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, color 160ms ease;
  overflow: hidden;
}

.atlas-topbar__nav-btn > :not(svg) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.atlas-topbar__nav-btn:hover {
  transform: translateY(-1px);
  background: var(--btn-bg-hover);
  border-color: var(--btn-border-hover);
}

.atlas-topbar__nav-btn.is-active {
  background: linear-gradient(135deg, var(--clay, var(--accent, #a8502f)) 0%, var(--clay-deep, var(--accent, #7f3519)) 100%);
  border-color: transparent;
  color: #fff9f2;
  box-shadow: 0 8px 20px rgba(127, 53, 25, 0.22);
}

.atlas-topbar__nav-btn svg {
  flex-shrink: 0;
  opacity: 0.7;
  transition: transform 200ms ease;
}

.atlas-topbar__nav-btn[aria-expanded="true"] svg {
  transform: rotate(180deg);
}

.atlas-topbar__theme-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--btn-border);
  border-radius: 999px;
  background: var(--btn-bg);
  color: var(--ink);
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.atlas-topbar__theme-btn:hover {
  transform: translateY(-1px);
  background: var(--btn-bg-hover);
  border-color: var(--btn-border-hover);
}

.atlas-topbar__nav-dropdown,
.atlas-topbar__dropdown {
  position: absolute;
  top: calc(100% + 10px);
  min-width: 200px;
  padding: 6px;
  border: 1px solid var(--topbar-border);
  border-radius: 16px;
  background: var(--dropdown-bg);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: transform 160ms ease, opacity 160ms ease;
}

.atlas-topbar__nav-dropdown {
  left: 0;
  transform-origin: top left;
  transform: scale(0.94) translateY(-6px);
}

.atlas-topbar__dropdown {
  right: 0;
  min-width: 188px;
  transform-origin: top right;
  transform: scale(0.94) translateY(-6px);
}

.atlas-topbar__nav-dropdown.is-open,
.atlas-topbar__dropdown.is-open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.atlas-topbar__nav-item,
.atlas-topbar__dropdown-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 9px 14px;
  border-radius: 10px;
  color: var(--ink, #211915);
  font: 500 0.92rem/1.2 var(--font-ui, "Segoe UI", "Helvetica Neue", Arial, system-ui, sans-serif);
  text-decoration: none;
  transition: background 120ms ease, color 120ms ease;
}

.atlas-topbar__dropdown-item {
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.atlas-topbar__theme-btn .atlas-topbar__theme-icon,
.atlas-topbar__dropdown-item .atlas-topbar__theme-icon {
  flex-shrink: 0;
}

.atlas-topbar__dropdown-item .atlas-topbar__theme-icon {
  margin-right: 8px;
}

.atlas-topbar__nav-item:hover,
.atlas-topbar__dropdown-item:hover {
  background: var(--item-hover-bg);
  color: var(--item-active-color);
  text-decoration: none;
}

.atlas-topbar__nav-item.is-current,
.atlas-topbar__dropdown-item.is-active {
  background: var(--item-active-bg);
  color: var(--item-active-color);
  font-weight: 700;
}

.atlas-topbar__dropdown-divider {
  margin: 5px 8px;
  border: none;
  border-top: 1px solid var(--divider);
}

.atlas-topbar__chapter-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-right: 6px;
}

.atlas-topbar__chapter-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--btn-border);
  border-radius: 10px;
  background: var(--btn-bg);
  color: var(--ink);
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

.atlas-topbar__chapter-btn:hover:not(:disabled) {
  background: var(--btn-bg-hover);
  border-color: var(--btn-border-hover);
}

.atlas-topbar__chapter-btn:disabled {
  opacity: 0.32;
  cursor: default;
}

.atlas-topbar__menu-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--btn-border);
  border-radius: 10px;
  background: var(--btn-bg);
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease;
}

.atlas-topbar__menu-btn:hover,
.atlas-topbar__menu-btn[aria-expanded="true"] {
  background: var(--btn-bg-hover);
  border-color: var(--btn-border-hover);
}

.atlas-topbar__menu-btn span {
  display: block;
  width: 16px;
  height: 2px;
  border-radius: 2px;
  background: var(--ink, #211915);
}

/* Show sun in dark mode, moon in light mode */
.atlas-topbar__theme-icon--sun { display: none; }
.atlas-topbar__theme-icon--moon { display: block; }

[data-theme="dark"] .atlas-topbar__theme-icon--sun { display: block; }
[data-theme="dark"] .atlas-topbar__theme-icon--moon { display: none; }

.has-atlas-topbar .sidebar {
  top: 92px;
  max-height: calc(100vh - 116px);
}

@media (max-width: 720px) {
  .atlas-topbar {
    padding: 10px 14px;
    gap: 8px;
    justify-content: space-between;
  }

  .atlas-topbar__left,
  .atlas-topbar__center,
  .atlas-topbar__right {
    flex: 0 1 auto;
  }

  .atlas-topbar__nav-btn {
    padding-left: 12px;
    padding-right: 10px;
  }

  .atlas-topbar__nav-dropdown {
    left: 50%;
    transform: translateX(-50%) scale(0.94) translateY(-6px);
    transform-origin: top center;
  }

  .atlas-topbar__nav-dropdown.is-open {
    transform: translateX(-50%) scale(1) translateY(0);
  }
}

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

a:hover {
  text-decoration-thickness: 0.12em;
}

.app-shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px 24px 64px;
}

.masthead {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.masthead__eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font: 700 0.8rem/1.25 var(--font-ui);
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.masthead__title {
  margin: 0;
  font: 700 clamp(1.2rem, 2vw, 1.45rem)/1.1 var(--font-display);
  letter-spacing: 0.02em;
}

.masthead__meta {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: var(--meta-size);
  line-height: 1.5;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--btn-border);
  border-radius: 999px;
  background: var(--btn-bg);
  color: var(--ink);
  padding: 12px 16px;
  font: 600 0.95rem/1.1 var(--font-ui);
  text-decoration: none;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.button:hover {
  transform: translateY(-1px);
  border-color: var(--btn-border-hover);
  background: var(--btn-bg-hover);
}

.layout {
  display: grid;
  grid-template-columns: minmax(260px, 300px) minmax(0, 1fr);
  gap: 0;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  overflow: hidden; /* fallback */
  overflow: clip;   /* clips for border-radius without creating a scroll container, so position:sticky works */
}

.sidebar {
  position: sticky;
  top: 24px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 20px 16px;
  border-right: 1px solid var(--line);
  background: var(--card);
}

.sidebar h2 {
  margin: 0 0 10px;
  font: 700 1rem/1.15 var(--font-ui);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.sidebar p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: var(--small-size);
  line-height: 1.62;
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 2px;
}

.toc-list li {
  margin: 0;
}

.toc-list a {
  display: block;
  padding: 5px 8px;
  font-size: var(--sidebar-size);
  border-radius: 12px;
  color: var(--ink);
  text-decoration: none;
  line-height: 1.5;
  transition: background 140ms ease, color 140ms ease;
}

.toc-list a:hover,
.toc-list a.is-active {
  background: var(--accent-soft);
  color: var(--item-active-color);
}

.document {
  min-width: 0;
}

.article {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 40px clamp(20px, 3vw, 48px);
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.article > :where(p, ul, ol, blockquote, table, .code-block, .diagram-figure, hr) {
  max-width: var(--measure);
}

.section + .section {
  margin-top: 34px;
}

.section-chapter {
  padding-top: 18px;
  border-top: 2px solid var(--line);
}

h1, h2, h3, h4 {
  color: var(--ink);
  line-height: 1.12;
  scroll-margin-top: 92px;
}

h1 a, h2 a, h3 a, h4 a {
  color: inherit;
  text-decoration: none;
}

h1 {
  margin: 0 0 20px;
  font: 700 clamp(2.5rem, 6vw, 3.8rem)/0.98 var(--font-display);
  letter-spacing: 0.01em;
}

h2 {
  margin: 0 0 16px;
  font: 700 clamp(1.55rem, 3vw, 2.05rem)/1.08 var(--font-display);
  letter-spacing: 0.02em;
}

h3 {
  margin: 26px 0 12px;
  font: 700 1.38rem/1.2 var(--font-display);
  letter-spacing: 0.01em;
}

h4 {
  margin: 18px 0 10px;
  font: 700 1.04rem/1.35 var(--font-ui);
  letter-spacing: 0.01em;
  color: var(--muted);
}

p, li {
  margin: 0 0 14px;
}

p {
  overflow-wrap: break-word;
  hyphens: auto;
}

ul, ol {
  margin: 0 0 18px 1.3rem;
  padding: 0;
}

li > ul,
li > ol {
  margin-top: 10px;
}

hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 24px 0;
}

blockquote {
  margin: 22px 0;
  padding: 18px 20px;
  border-left: 4px solid var(--accent);
  border-radius: 18px;
  background: var(--accent-soft);
  opacity: 0.9;
}

blockquote .section {
  margin: 0;
  padding: 0;
  border: 0;
}

code {
  padding: 0.12em 0.38em;
  border-radius: 0.4em;
  background: var(--code-bg);
  font: var(--code-size)/1.45 var(--font-mono);
}

.code-block {
  margin: 18px 0 22px;
}

.code-label {
  display: inline-flex;
  margin-bottom: 8px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font: 700 0.8rem/1.1 var(--font-ui);
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

pre {
  margin: 0;
  padding: 18px 18px 20px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--pre-bg);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  font: var(--code-size)/1.65 var(--font-mono);
}

pre code {
  padding: 0;
  border-radius: 0;
  background: transparent;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 18px 0 22px;
}

.diagram-figure {
  margin: 22px 0 24px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--card);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.diagram-figure img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 16px;
}

.diagram-figure figcaption {
  margin-top: 12px;
  color: var(--muted);
  font-size: var(--meta-size);
  line-height: 1.5;
}

table {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  font-size: var(--table-size);
  line-height: 1.58;
}

th, td {
  padding: 10px 12px;
  border: 1px solid var(--line);
  vertical-align: top;
  text-align: left;
}

thead th {
  background: var(--thead-bg);
  font: 700 0.94rem/1.3 var(--font-ui);
  letter-spacing: 0.02em;
}

tbody tr:nth-child(even) td {
  background: var(--accent-soft);
}

.section-toc ol {
  columns: 2;
  column-gap: 28px;
}

.section-toc li {
  break-inside: avoid;
}

/* ── View switch & chapter controls ── */

.view-switch {
  display: inline-flex;
  border-radius: 999px;
  padding: 2px;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  gap: 4px;
}

.button--view {
  border-color: transparent;
  background: transparent;
  font-size: 0.92rem;
  padding: 10px 12px;
}

.button--view:hover {
  border-color: var(--btn-border-hover);
  background: var(--accent-soft);
}

.button--view.is-active {
  border-color: var(--btn-border);
  background: var(--accent-soft);
  color: var(--item-active-color);
}

.chapter-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 auto 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.chapter-controls[hidden] {
  display: none !important;
}

.chapter-controls__meta {
  margin: 0;
  font: 600 var(--small-size)/1.35 var(--font-ui);
  color: var(--muted);
  letter-spacing: 0.02em;
  text-align: center;
  flex: 1;
}

.chapter-controls__nav {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.chapter-controls__nav .button {
  flex: 1;
}

.chapter-controls .button {
  padding: 10px 14px;
  font-size: 0.9rem;
  white-space: nowrap;
}

.chapter-controls .button:disabled {
  opacity: 0.42;
  cursor: default;
  pointer-events: none;
  box-shadow: none;
}

.sidebar .chapter-controls {
  margin: 0 0 12px;
  padding: 10px;
  border-radius: 14px;
  box-shadow: none;
  background: var(--card);
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
}

.sidebar .chapter-controls__nav {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  order: 1;
}

.sidebar .chapter-controls .button {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  font-size: 0.82rem;
  white-space: nowrap;
  line-height: 1.2;
}

.sidebar .chapter-controls__meta {
  order: 0;
  font-size: 0.84rem;
  line-height: 1.25;
  font-weight: 700;
  padding: 2px 6px 0;
  overflow-wrap: anywhere;
}

.is-hidden-chapter {
  display: none !important;
}

/* ── Responsive ── */

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
    border-radius: 16px;
  }

  .sidebar {
    position: static;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 720px) {
  :root {
    --body-size: 16.5px;
    --body-leading: 1.74;
    --sidebar-size: 0.95rem;
    --meta-size: 0.93rem;
    --small-size: 0.9rem;
    --table-size: 0.94rem;
    --code-size: 0.9rem;
  }

  .app-shell {
    padding: 16px 10px 40px;
  }

  .masthead {
    flex-direction: column;
    align-items: start;
  }

  .layout {
    border-radius: 14px;
  }

  .article {
    padding: 24px 16px;
  }

  .section-toc ol {
    columns: 1;
  }

  .view-switch {
    width: 100%;
  }

  .button--view {
    flex: 1;
  }

  .chapter-controls {
    flex-wrap: wrap;
  }

  .chapter-controls__nav {
    width: 100%;
  }

  .chapter-controls .button {
    flex: 1;
  }

  .chapter-controls__meta {
    width: 100%;
    order: 3;
  }

  .sidebar .chapter-controls__meta {
    order: 0;
    width: auto;
  }
}

/* ── Print ── */

@page {
  size: A4;
  margin: 18mm 18mm 20mm;
}

@media print {
  :root {
    --ink: #111;
    --muted: #444;
    --line: #cfcfcf;
    --accent: #555;
    --accent-soft: transparent;
    --code-bg: #f0f0f0;
    --pre-bg: #f5f5f5;
    --thead-bg: #ebebeb;
    --card: #fff;
    --paper: #fff;
    --shadow: none;
  }

  *,
  *::before,
  *::after {
    background: transparent !important;
    box-shadow: none !important;
    text-shadow: none !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  body {
    background: #fff !important;
    color: #111;
    font-family: "Palatino Linotype", "Book Antiqua", Georgia, serif;
    font-size: 11.5pt;
    line-height: 1.62;
  }

  tbody tr:nth-child(even) td { background: #f7f7f7 !important; }

  .app-shell {
    max-width: none;
    padding: 0;
  }

  .site-nav,
  .masthead,
  .sidebar,
  .chapter-controls,
  .view-switch,
  .actions {
    display: none !important;
  }

  .article {
    max-width: none;
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .layout,
  .document {
    display: block;
    border: 0;
    border-radius: 0;
  }

  .section + .section {
    margin-top: 18px;
  }

  h1, h2, h3, h4 {
    font-family: "Segoe UI", "Helvetica Neue", Arial, system-ui, sans-serif;
    color: #111;
    break-after: avoid;
    page-break-after: avoid;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  h1 {
    font-size: 22pt;
    line-height: 1.05;
  }

  h2 {
    font-size: 15pt;
    line-height: 1.16;
  }

  h3 {
    font-size: 12pt;
    line-height: 1.26;
  }

  h4 {
    font-size: 10.5pt;
    line-height: 1.32;
    color: #444;
  }

  /* Each chapter section starts on a new page */
  .section-chapter {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
    break-before: page;
    page-break-before: always;
  }

  .section-chapter:first-of-type {
    break-before: auto;
    page-break-before: auto;
  }

  /* Chapter headings break before but never orphan at the bottom of a page */
  h2[id^="chapter-"] {
    break-before: page;
    page-break-before: always;
    break-after: avoid;
    page-break-after: avoid;
    padding-top: 0;
  }

  /* Element immediately after a heading cannot be the first thing on a new page */
  h1 + *, h2 + *, h3 + *, h4 + * {
    break-before: avoid;
    page-break-before: avoid;
  }

  p, li {
    orphans: 3;
    widows: 3;
  }

  a {
    color: inherit;
    text-decoration: none;
  }

  blockquote,
  pre,
  .code-block,
  .diagram-figure,
  figure,
  img,
  svg,
  tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  pre {
    overflow: visible;
    white-space: pre-wrap;
    word-break: break-word;
    background: #f5f5f5 !important;
    border: 1px solid #ddd;
    font-family: "SFMono-Regular", Menlo, Monaco, "Courier New", monospace;
    font-size: 9pt;
    line-height: 1.5;
    border-radius: 0;
  }

  code {
    font-family: "SFMono-Regular", Menlo, Monaco, "Courier New", monospace;
    font-size: 0.88em;
    background: #f0f0f0 !important;
    border-radius: 0;
  }

  table {
    font-family: "Source Serif 4", Georgia, "Times New Roman", serif;
    font-size: 10pt;
  }

  thead th {
    font-family: "Segoe UI", "Helvetica Neue", Arial, system-ui, sans-serif;
    background: #ebebeb !important;
    color: #111;
  }

  thead {
    display: table-header-group;
  }

  tfoot {
    display: table-footer-group;
  }

  th, td {
    padding: 7px 8px;
  }

  .code-label {
    border: 1px solid #000;
    background: transparent !important;
    color: #000;
  }

  blockquote {
    border-left: 3px solid #888;
    padding: 10px 16px;
    margin: 14px 0;
    color: #333;
    font-style: italic;
    border-radius: 0;
  }

  .section-toc ol {
    columns: 1;
  }
}

.site-footer {
  text-align: center;
  padding: 0.4rem 1rem;
  font-size: 0.75rem;
  color: var(--muted);
  border-top: 1px solid var(--line);
  margin-top: 0;
}

.site-footer a {
  color: var(--clay);
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}
