/* =========================================================
   AWS GenAI Developer Pro — Independent Study Guide
   Book Design System
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:opsz,wght@8..60,400;8..60,600;8..60,700&family=Inter+Tight:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;700&family=Caveat:wght@500;700&display=swap');

:root {
  /* Palette — independent publication, navy + amber */
  --ink:        #16202E;     /* deep navy, primary text & headings */
  --ink-soft:   #36465A;
  --ink-mute:   #6A7588;
  --rule:       #D9D3C4;     /* warm rule color */
  --rule-soft:  #ECE7DA;
  --paper:      #FAF7F0;     /* parchment page */
  --paper-deep: #F2EDE0;
  --amber:      #C97515;     /* burnt amber accent */
  --amber-soft: #FBE9CD;
  --amber-bg:   #FCF1DC;
  --terra:      #B0431F;     /* watch-out red */
  --terra-soft: #FBE2D6;
  --sky:        #2E5A86;     /* key concept navy */
  --sky-soft:   #E1ECF6;
  --sage:       #4F6B4A;     /* pro tip secondary */
  --sage-soft:  #E8EFE3;
  --code-bg:    #F1ECDF;
  --code-ink:   #2A3142;

  /* Type stack */
  --serif:  'Source Serif 4', 'Iowan Old Style', Georgia, serif;
  --sans:   'Inter Tight', -apple-system, system-ui, sans-serif;
  --mono:   'JetBrains Mono', 'SF Mono', Menlo, monospace;
  --hand:   'Caveat', 'Bradley Hand', cursive;

  /* Type scale */
  --fs-body:    18px;
  --lh-body:    1.62;
  --measure:    34rem;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  font-feature-settings: 'kern', 'liga', 'onum';
  -webkit-font-smoothing: antialiased;
}

/* ---------- Page shell ---------- */

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 4rem 2rem 6rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18rem;
  gap: 4rem;
  align-items: start;
}

.page--narrow {
  grid-template-columns: 1fr;
  max-width: 56rem;
}

.column {
  max-width: var(--measure);
  width: 100%;
}

.rail {
  position: sticky;
  top: 2rem;
  font-family: var(--sans);
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--ink-mute);
}

/* ---------- Chrome: sidebar nav + topbar (web only) ---------- */

.shell {
  display: grid;
  grid-template-columns: 18rem 1fr;
  min-height: 100vh;
  transition: grid-template-columns .22s ease;
}

.sidebar {
  background: var(--paper-deep);
  border-right: 1px solid var(--rule);
  padding: 2rem 1.5rem 4rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  font-family: var(--sans);
  font-size: 0.9rem;
  transition: padding .18s ease;
}

/* Sidebar toggle button (always rendered top-right of the rail) */
.sidebar-toggle {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 1.7rem;
  height: 1.7rem;
  background: var(--paper);
  border: 1.5px solid var(--ink);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0;
  cursor: pointer;
  border-radius: 2px;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.sidebar-toggle:hover { background: var(--amber); color: #fff; border-color: var(--amber); }
.shell[data-collapsed="true"] .sidebar-toggle {
  right: auto;
  left: 50%;
  transform: translateX(-50%);
}

/* Sidebar link icons — hidden in expanded mode, shown only when collapsed */
.sidebar a .nav-ic { display: none; }

/* Mini-TOC: chapter sections injected by JS under the active chapter link */
.sidebar .nav-sub {
  display: none;
  list-style: none;
  margin: 0.2rem 0 0.55rem 0.55rem;
  padding: 0;
  border-left: 1px dotted var(--rule);
}
.sidebar .nav-sub.is-active { display: block; }
.sidebar .nav-sub li { margin: 0; }
.sidebar .nav-sub a {
  font-size: 0.78rem;
  line-height: 1.35;
  padding: 0.2rem 0 0.2rem 0.75rem;
  color: var(--ink-mute);
  border-bottom: none;
  font-weight: 400;
}
.sidebar .nav-sub a:hover { color: var(--ink); border-bottom-color: transparent; }
.sidebar .nav-sub a.is-active {
  color: var(--amber);
  font-weight: 600;
  border-left: 2px solid var(--amber);
  margin-left: -2px;
  padding-left: 0.65rem;
}

/* Hide mini-TOC when sidebar is collapsed and in print */
.shell[data-collapsed="true"] .sidebar .nav-sub { display: none !important; }
@media print { .nav-sub { display: none !important; } }

/* ============== COLLAPSED STATE ============== */
.shell[data-collapsed="true"] { grid-template-columns: 4.6rem 1fr; }

.shell[data-collapsed="true"] .sidebar {
  padding: 3.4rem 0.4rem 3rem;
  text-align: center;
}

.shell[data-collapsed="true"] .sidebar .brand,
.shell[data-collapsed="true"] .sidebar > h4,
.shell[data-collapsed="true"] .sidebar summary,
.shell[data-collapsed="true"] .sidebar > div:last-of-type { display: none; }

/* Force any <details> visually open in collapsed mode */
.shell[data-collapsed="true"] .sidebar details { display: block; margin: 0; }
.shell[data-collapsed="true"] .sidebar details > a { display: flex; }

/* Boxed icon style (matches MCQ choice letter aesthetic) */
.shell[data-collapsed="true"] .sidebar a {
  width: 1.9rem;
  height: 1.9rem;
  margin: 0.32rem auto;
  padding: 0;
  border: 1.5px solid var(--ink);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  font-size: 0;
  color: var(--ink);
  text-decoration: none;
}
.shell[data-collapsed="true"] .sidebar a .nav-ic {
  display: inline-block;
  width: 16px;
  height: 16px;
  color: var(--ink);
  vertical-align: baseline;
}
.shell[data-collapsed="true"] .sidebar a .nav-t { display: none; }
.shell[data-collapsed="true"] .sidebar a:hover {
  background: var(--amber-bg);
  border-color: var(--amber);
}
.shell[data-collapsed="true"] .sidebar a:hover .nav-ic { color: var(--amber); }
.shell[data-collapsed="true"] .sidebar a.is-active {
  background: var(--ink);
  border-color: var(--ink);
}
.shell[data-collapsed="true"] .sidebar a.is-active .nav-ic { color: var(--paper); }
.shell[data-collapsed="true"] .sidebar a.upcoming {
  border-style: dashed;
  opacity: 0.45;
}

/* Group separators between <details> blocks in collapsed mode */
.shell[data-collapsed="true"] .sidebar details + details::before,
.shell[data-collapsed="true"] .sidebar h4 + details::before {
  content: '';
  display: block;
  width: 1.4rem;
  height: 1px;
  background: var(--rule);
  margin: 0.55rem auto 0.45rem;
}

.sidebar h4 {
  font-family: var(--sans);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.7rem;
  color: var(--amber);
  margin: 1.5rem 0 0.5rem;
}

.sidebar a {
  display: block;
  color: var(--ink-soft);
  text-decoration: none;
  padding: 0.3rem 0;
  border-bottom: 1px dotted transparent;
}
.sidebar a:hover { color: var(--ink); border-bottom-color: var(--rule); }
.sidebar a.is-active { color: var(--amber); font-weight: 600; }

.sidebar .brand {
  font-family: var(--sans);
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--ink);
  font-size: 0.95rem;
  line-height: 1.25;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 1rem;
}
.sidebar .brand .edition {
  display: block;
  font-size: 0.7rem;
  color: var(--ink-mute);
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-top: 0.3rem;
}

.sidebar details { margin: 0.4rem 0; }
.sidebar summary {
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  padding: 0.3rem 0;
  list-style: none;
}
.sidebar summary::-webkit-details-marker { display: none; }
.sidebar summary::before {
  content: '+';
  display: inline-block;
  width: 1.2em;
  color: var(--amber);
  font-weight: 700;
}
.sidebar details[open] summary::before { content: '−'; }
.sidebar details a { padding-left: 1.2em; font-size: 0.85rem; }

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

h1, h2, h3, h4, h5 {
  font-family: var(--sans);
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.015em;
  line-height: 1.15;
  margin-top: 2.2em;
}

h1 { font-size: 2.6rem; font-weight: 800; letter-spacing: -0.025em; }
h2 { font-size: 1.9rem; font-weight: 700; margin-top: 3rem; }
h3 { font-size: 1.35rem; font-weight: 700; margin-top: 2.4rem; color: var(--ink); }
h4 { font-size: 1.05rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--amber); margin-top: 2rem; }

p { margin: 0 0 1em; text-wrap: pretty; }
p + p { margin-top: 0; }

strong { color: var(--ink); font-weight: 700; }
em { font-style: italic; }

a { color: var(--amber); text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }

/* ---------- Chapter opener ---------- */

.chapter-opener {
  border-top: 8px solid var(--ink);
  padding-top: 2rem;
  margin-top: 4rem;
  break-before: page;
}

.chapter-opener .meta {
  display: flex;
  align-items: baseline;
  gap: 1.2rem;
  font-family: var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.75rem;
  color: var(--amber);
  font-weight: 700;
}
.chapter-opener .meta .num {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 4.5rem;
  line-height: 1;
  color: var(--ink);
  letter-spacing: -0.04em;
  font-feature-settings: 'lnum';
}

.chapter-opener h1 {
  font-size: 3rem;
  margin: 0.5rem 0 1rem;
  max-width: 24ch;
}

.chapter-opener .deck {
  font-family: var(--serif);
  font-size: 1.25rem;
  font-style: italic;
  color: var(--ink-soft);
  max-width: 38rem;
  line-height: 1.45;
  border-left: 3px solid var(--amber);
  padding-left: 1.2rem;
  margin: 1.5rem 0 2rem;
}

/* ---------- Drop cap ---------- */

.dropcap::first-letter {
  font-family: var(--sans);
  font-weight: 800;
  font-size: 4.5em;
  float: left;
  line-height: 0.85;
  margin: 0.05em 0.12em -0.05em 0;
  color: var(--amber);
}

/* ---------- Learning Objectives ---------- */

.objectives {
  background: var(--paper-deep);
  border: 1px solid var(--rule);
  border-left: 4px solid var(--ink);
  padding: 1.4rem 1.6rem;
  margin: 2rem 0 2.5rem;
}
.objectives h4 {
  margin: 0 0 0.6rem;
  color: var(--ink);
  font-size: 0.78rem;
}
.objectives ul {
  margin: 0;
  padding: 0;
  list-style: none;
}
.objectives li {
  padding: 0.3rem 0 0.3rem 1.6rem;
  position: relative;
  font-size: 0.98rem;
  line-height: 1.45;
}
.objectives li::before {
  content: '→';
  color: var(--amber);
  position: absolute;
  left: 0;
  font-weight: 700;
}

/* ---------- Callouts ---------- */

.callout {
  margin: 1.8rem 0;
  padding: 1.1rem 1.3rem 1.1rem 3.4rem;
  border-radius: 2px;
  position: relative;
  font-size: 0.95rem;
  line-height: 1.55;
}
.callout::before {
  position: absolute;
  left: 1.1rem;
  top: 1.1rem;
  font-family: var(--sans);
  font-weight: 800;
  font-size: 0.95rem;
  width: 1.6rem;
  height: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.callout .label {
  display: block;
  font-family: var(--sans);
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
}
.callout p:last-child { margin-bottom: 0; }

.callout--tip {
  background: var(--amber-bg);
  border-left: 4px solid var(--amber);
}
.callout--tip::before { content: '💡'; background: transparent; font-size: 1.1rem; }
.callout--tip .label { color: var(--amber); }

.callout--warn {
  background: var(--terra-soft);
  border-left: 4px solid var(--terra);
}
.callout--warn::before { content: '⚠'; color: var(--terra); background: transparent; font-size: 1.2rem; }
.callout--warn .label { color: var(--terra); }

.callout--key {
  background: var(--sky-soft);
  border-left: 4px solid var(--sky);
}
.callout--key::before { content: '📌'; background: transparent; font-size: 1.05rem; }
.callout--key .label { color: var(--sky); }

/* ---------- Side rail ---------- */

.rail .marginalia {
  font-family: var(--hand);
  font-size: 1.4rem;
  line-height: 1.25;
  color: var(--ink-soft);
  border-top: 1px solid var(--rule);
  padding: 1rem 0;
  margin-bottom: 1rem;
}
.rail .marginalia::before {
  content: '“';
  font-family: var(--hand);
  font-size: 2rem;
  color: var(--amber);
  display: block;
  line-height: 0.4;
  margin-bottom: 0.5rem;
}

.rail .ministat {
  font-family: var(--sans);
  display: flex;
  flex-direction: column;
  border-top: 2px solid var(--ink);
  padding: 0.6rem 0;
  margin-bottom: 1rem;
}
.rail .ministat .num {
  font-family: var(--sans);
  font-weight: 800;
  font-size: 2rem;
  color: var(--amber);
  line-height: 1;
  letter-spacing: -0.02em;
}
.rail .ministat .label {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.7rem;
  color: var(--ink-mute);
  margin-top: 0.35rem;
}

/* ---------- Lists ---------- */

ul, ol { padding-left: 1.4em; margin: 1em 0; }
li { margin: 0.35em 0; }

ol.decision {
  counter-reset: step;
  list-style: none;
  padding: 0;
  margin: 1.4em 0;
}
ol.decision li {
  counter-increment: step;
  padding: 0.6rem 0 0.6rem 3rem;
  position: relative;
  border-bottom: 1px dotted var(--rule);
}
ol.decision li::before {
  content: counter(step, decimal-leading-zero);
  position: absolute;
  left: 0;
  top: 0.6rem;
  font-family: var(--sans);
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--amber);
  letter-spacing: 0.05em;
}

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

code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--code-bg);
  color: var(--code-ink);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}
pre {
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.55;
  background: var(--code-bg);
  color: var(--code-ink);
  padding: 1.1rem 1.3rem;
  border-left: 3px solid var(--ink);
  overflow-x: auto;
  margin: 1.5rem 0;
}
pre code { background: transparent; padding: 0; }

/* ---------- Code comparison (side-by-side) ---------- */

.code-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1.5rem 0;
  font-family: var(--sans);
  position: relative;
}
.table-wrap { position: relative; margin: 1.4rem 0; overflow-x: auto; }
.table-wrap > table { margin: 0; }

/* Generic focus button (used on code-compare + tables) */
.focus-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 3;
  background: var(--paper);
  color: var(--ink-soft);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 0.25rem 0.55rem;
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s, background .15s, color .15s;
}
.code-compare:hover .focus-btn,
.table-wrap:hover .focus-btn,
.focus-btn:focus-visible { opacity: 1; }
.focus-btn:hover { background: var(--terra); color: #fff; border-color: var(--terra); }
@media print { .focus-btn { display: none !important; } }
.code-compare .cc-pane {
  border: 1px solid var(--rule);
  background: var(--code-bg);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.code-compare .cc-head {
  background: var(--ink);
  color: var(--paper);
  padding: 0.5rem 0.85rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
}
.code-compare .cc-head .cc-tag {
  font-size: 0.65rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--amber-soft);
  font-weight: 700;
}
.code-compare .cc-old .cc-head { background: #5a4a3a; }
.code-compare .cc-new .cc-head { background: var(--sage); }
.code-compare pre {
  margin: 0;
  background: var(--code-bg);
  border: none;
  padding: 0.85rem 1rem;
  font-size: 0.78rem;
  line-height: 1.55;
  overflow-x: auto;
  flex: 1;
}
.code-compare .cc-foot {
  border-top: 1px dotted var(--rule);
  padding: 0.55rem 0.85rem;
  font-family: var(--serif);
  font-size: 0.82rem;
  font-style: italic;
  color: var(--ink-soft);
}
.tok-k { color: #8a4a8a; font-weight: 600; }
.tok-s { color: #4F6B4A; }
.tok-c { color: var(--ink-mute); font-style: italic; }
.tok-n { color: #C97515; }
@media (max-width: 880px) { .code-compare { grid-template-columns: 1fr; } }

/* ---------- Tables ---------- */

.tbl {
  width: 100%;
  border-collapse: collapse;
  margin: 1.8rem 0;
  font-family: var(--sans);
  font-size: 0.92rem;
}
.tbl caption {
  caption-side: top;
  text-align: left;
  font-family: var(--sans);
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--amber);
  padding-bottom: 0.5rem;
}
.tbl thead th {
  background: var(--ink);
  color: var(--paper);
  text-align: left;
  padding: 0.7rem 0.9rem;
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
}
.tbl tbody td {
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
  line-height: 1.4;
}
.tbl tbody tr:nth-child(even) td { background: var(--paper-deep); }
.tbl tbody tr:hover td { background: var(--amber-bg); }

/* ---------- Review questions ---------- */

.review {
  border-top: 4px solid var(--ink);
  margin-top: 4rem;
  padding-top: 2rem;
}
.review h2 { margin-top: 0; }

.q {
  margin: 2rem 0;
  padding: 1.5rem 1.8rem;
  background: var(--paper-deep);
  border: 1px solid var(--rule);
}
.q .qnum {
  font-family: var(--sans);
  font-weight: 800;
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--amber);
  margin-bottom: 0.5rem;
}
.q .stem { font-size: 1.02rem; margin-bottom: 1rem; }
.q ol.choices {
  list-style: none;
  padding: 0;
  counter-reset: choice;
  margin: 0 0 1rem;
}
.q ol.choices li {
  counter-increment: choice;
  padding: 0.45rem 0 0.45rem 2rem;
  position: relative;
  font-size: 0.95rem;
  line-height: 1.5;
}
.q ol.choices li::before {
  content: counter(choice, upper-alpha);
  position: absolute;
  left: 0;
  top: 0.45rem;
  font-family: var(--sans);
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--amber);
  width: 1.5rem;
  height: 1.5rem;
  border: 1.5px solid var(--amber);
  display: flex;
  align-items: center;
  justify-content: center;
}
.q .reveal {
  margin-top: 1rem;
  border-top: 1px dotted var(--rule);
  padding-top: 1rem;
}
.q .reveal summary {
  cursor: pointer;
  font-family: var(--sans);
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--amber);
  list-style: none;
}
.q .reveal summary::after {
  content: ' ↓ reveal';
  color: var(--ink-mute);
  font-weight: 500;
}
.q .reveal[open] summary::after { content: ' ↑ hide'; }
.q .reveal .answer {
  margin-top: 0.9rem;
  padding: 0.9rem 1.1rem;
  background: var(--sage-soft);
  border-left: 3px solid var(--sage);
  font-size: 0.93rem;
  line-height: 1.5;
}
.q .reveal .answer strong { color: var(--sage); }

/* ---------- Diagram primitives ---------- */

.diagram {
  margin: 2rem 0;
  padding: 1.5rem;
  background: var(--paper-deep);
  border: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.85rem;
}
.diagram .dcaption {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--amber);
  font-weight: 700;
  margin-bottom: 0.8rem;
}
.diagram .dtitle {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
  margin-bottom: 1rem;
  letter-spacing: -0.01em;
}

/* Boxy flow diagram */
.flow {
  display: flex;
  align-items: stretch;
  gap: 0;
  flex-wrap: wrap;
}
.flow .node {
  flex: 1 1 0;
  min-width: 8rem;
  background: var(--paper);
  border: 1.5px solid var(--ink);
  padding: 0.75rem 0.8rem;
  font-size: 0.85rem;
  line-height: 1.25;
  position: relative;
}
.flow .node .role {
  display: block;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--amber);
  font-weight: 700;
  margin-bottom: 0.3rem;
}
.flow .arrow {
  flex: 0 0 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  font-weight: 700;
}
.flow .arrow::before { content: '→'; font-size: 1.4rem; }

/* ---------- Manning-style figures (inline SVG) ---------- */

figure.fig {
  margin: 2.5rem 0;
  padding: 0;
  background: transparent;
  break-inside: avoid;
}
figure.fig .fig-frame {
  border: 1px solid var(--rule);
  background: #FFFDF7;
  padding: 1.25rem 1.25rem 0.5rem;
  position: relative;
}
figure.fig .fig-expand {
  position: absolute;
  top: 0.7rem;
  right: 0.7rem;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  border-radius: 3px;
  transition: background .15s, color .15s, border-color .15s;
  z-index: 2;
}
figure.fig .fig-expand:hover {
  background: var(--amber);
  color: #fff;
  border-color: var(--amber);
}

/* Focus overlay */
.fig-overlay {
  position: fixed;
  inset: 0;
  background: rgba(22, 32, 46, 0.78);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 2.5rem;
  animation: fig-fade-in .18s ease-out;
}
.fig-overlay-inner {
  background: var(--paper);
  border: 1px solid var(--rule);
  width: 100%;
  max-width: min(96vw, 1500px);
  max-height: 92vh;
  overflow: auto;
  padding: 1.5rem 1.5rem 1.25rem;
  position: relative;
  box-shadow: 0 30px 80px rgba(0,0,0,0.4);
}
.fig-overlay-close {
  position: absolute;
  top: 0.7rem;
  right: 0.7rem;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  border-radius: 3px;
  z-index: 2;
}
.fig-overlay-close:hover { background: var(--terra); color: #fff; border-color: var(--terra); }
.fig-overlay svg { width: 100%; height: auto; max-height: 78vh; }
.fig-overlay .fig-eyebrow,
.fig-overlay .fig-title,
.fig-overlay .fig-deck { /* inherit */ }
@keyframes fig-fade-in { from { opacity: 0 } to { opacity: 1 } }

@media print {
  figure.fig .fig-expand { display: none; }
  .fig-overlay { display: none !important; }
}
figure.fig .fig-eyebrow {
  font-family: var(--sans);
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--amber);
  font-weight: 700;
  margin-bottom: 0.3rem;
}
figure.fig .fig-title {
  font-family: var(--sans);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
  margin: 0 0 0.4rem;
  border-left: 3px solid var(--amber);
  padding-left: 0.7rem;
}
figure.fig .fig-deck {
  font-family: var(--serif);
  font-size: 0.92rem;
  font-style: italic;
  color: var(--ink-soft);
  margin: 0 0 0.9rem 0.85rem;
  max-width: 42rem;
  line-height: 1.45;
}
figure.fig svg {
  width: 100%;
  height: auto;
  display: block;
}
figure.fig figcaption {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-mute);
  margin-top: 0.7rem;
  padding-top: 0.5rem;
  border-top: 1px dotted var(--rule);
}
figure.fig figcaption strong {
  color: var(--ink);
  font-weight: 700;
}

/* ---------- Footer / page break ---------- */

.endmark {
  text-align: center;
  margin: 4rem 0 0;
  font-family: var(--sans);
  font-size: 0.7rem;
  letter-spacing: 0.3em;
  color: var(--ink-mute);
  text-transform: uppercase;
}
.endmark::before, .endmark::after {
  content: '◆';
  color: var(--amber);
  margin: 0 0.6em;
}

hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 3rem 0;
}

/* ---------- Cover ---------- */

.cover-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  background:
    radial-gradient(ellipse at top right, rgba(201,117,21,0.08), transparent 50%),
    radial-gradient(ellipse at bottom left, rgba(22,32,46,0.06), transparent 50%),
    var(--paper);
  break-after: page;
}

.cover-frame {
  max-width: 52rem;
  width: 100%;
  border: 1px solid var(--rule);
  background: var(--paper);
  padding: 4rem 4.5rem;
  position: relative;
}
.cover-frame::before, .cover-frame::after {
  content: '';
  position: absolute;
  width: 28px; height: 28px;
  border: 2px solid var(--amber);
}
.cover-frame::before { top: -6px; left: -6px; border-right: none; border-bottom: none; }
.cover-frame::after { bottom: -6px; right: -6px; border-left: none; border-top: none; }

.cover-eyebrow {
  display: flex;
  justify-content: space-between;
  font-family: var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
  color: var(--amber);
  font-weight: 700;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 1rem;
  margin-bottom: 3rem;
}

.cover-mark {
  margin: 0 auto 2.5rem;
  display: block;
  width: 160px;
}

.cover-title {
  font-family: var(--sans);
  font-weight: 800;
  font-size: 3.6rem;
  line-height: 1.05;
  letter-spacing: -0.03em;
  margin: 0 0 1rem;
  text-align: center;
  color: var(--ink);
}
.cover-title .amber { color: var(--amber); }

.cover-subtitle {
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.4rem;
  color: var(--ink-soft);
  margin-bottom: 3rem;
}

.cover-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  padding: 1.5rem 0;
  margin-bottom: 3rem;
}
.cover-meta-label {
  font-family: var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.7rem;
  color: var(--amber);
  font-weight: 700;
  margin-bottom: 0.4rem;
}
.cover-meta-value {
  font-size: 0.92rem;
  color: var(--ink-soft);
  line-height: 1.4;
}

.cover-foot {
  font-family: var(--sans);
  font-size: 0.72rem;
  color: var(--ink-mute);
  text-align: center;
  line-height: 1.5;
  font-style: italic;
}

/* ---------- Colophon ---------- */

.colophon {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
}
.colophon-label {
  font-family: var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.65rem;
  color: var(--amber);
  font-weight: 700;
}
.colophon-value {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin-top: 0.3rem;
}

/* ---------- TOC ---------- */

.toc-eyebrow {
  font-family: var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 0.78rem;
  color: var(--amber);
  font-weight: 700;
  margin-bottom: 0.6rem;
}
.toc-title {
  font-family: var(--sans);
  font-weight: 800;
  font-size: 4rem;
  letter-spacing: -0.03em;
  margin: 0 0 3rem;
}
.toc-block { margin-bottom: 2.5rem; }
.toc-part {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-top: 2px solid var(--ink);
  padding-top: 0.7rem;
  margin-bottom: 0.5rem;
}
.toc-tag {
  font-family: var(--sans);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--amber);
  background: var(--amber-bg);
  padding: 2px 8px;
  border-radius: 2px;
  margin-left: 0.6rem;
  vertical-align: middle;
}
.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.toc-list li {
  margin: 0;
}
.toc-list li a, .toc-list li > span:first-child {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  padding: 0.5rem 0;
  border-bottom: 1px dotted var(--rule-soft);
  text-decoration: none;
  color: var(--ink);
  font-size: 0.98rem;
}
.toc-list li a:hover { color: var(--amber); }
.toc-list li em {
  font-style: normal;
  font-family: var(--sans);
  font-weight: 700;
  color: var(--amber);
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  margin-right: 0.5rem;
  min-width: 1.5rem;
}
.toc-list .dots {
  flex: 1;
  border-bottom: 1px dotted var(--ink-mute);
  margin: 0 0.4rem 0.25rem;
}
.toc-list .pn {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--ink-mute);
  font-feature-settings: 'tnum';
}

.toc-pending .toc-part { color: var(--ink-mute); border-top-color: var(--rule); }
.toc-pending .toc-list li { color: var(--ink-mute); }
.toc-pending .toc-list li > span:first-child { color: var(--ink-mute); border-bottom-style: dotted; }

/* ---------- Part opener ---------- */

.part-opener {
  background: var(--ink);
  color: var(--paper);
  padding: 6rem 2rem;
  break-before: page;
  position: relative;
  overflow: hidden;
}
.part-opener::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle, rgba(201,117,21,0.18) 1px, transparent 1px);
  background-size: 24px 24px;
  opacity: 0.4;
  pointer-events: none;
}
.part-frame {
  max-width: 56rem;
  margin: 0 auto;
  position: relative;
}
.part-eyebrow {
  font-family: var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.3em;
  font-size: 0.85rem;
  color: var(--amber);
  font-weight: 700;
  margin-bottom: 0.5rem;
}
.part-num {
  font-family: var(--sans);
  font-weight: 800;
  font-size: 12rem;
  line-height: 0.85;
  letter-spacing: -0.06em;
  color: var(--paper);
  margin: 0;
  font-feature-settings: 'lnum';
}
.part-title {
  font-family: var(--sans);
  font-weight: 800;
  font-size: 3.4rem;
  line-height: 1.05;
  letter-spacing: -0.025em;
  margin: 1.5rem 0 1.5rem;
  color: var(--paper);
}
.part-deck {
  font-family: var(--serif);
  font-size: 1.15rem;
  line-height: 1.55;
  color: rgba(250,247,240,0.78);
  max-width: 42rem;
  margin: 0 0 3rem;
}
.part-stats {
  display: grid;
  grid-template-columns: repeat(4, auto);
  gap: 3rem;
  border-top: 1px solid rgba(250,247,240,0.2);
  border-bottom: 1px solid rgba(250,247,240,0.2);
  padding: 1.4rem 0;
  margin-bottom: 3rem;
}
.part-stat { display: flex; flex-direction: column; }
.part-stat .num {
  font-family: var(--sans);
  font-weight: 800;
  font-size: 2.4rem;
  color: var(--amber);
  letter-spacing: -0.02em;
  line-height: 1;
}
.part-stat .label {
  font-family: var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.7rem;
  color: rgba(250,247,240,0.6);
  margin-top: 0.4rem;
}

.part-toc {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.part-toc-row a {
  display: grid;
  grid-template-columns: 5rem 1fr 7rem;
  align-items: baseline;
  gap: 1rem;
  padding: 1rem 0;
  border-top: 1px solid rgba(250,247,240,0.15);
  text-decoration: none;
  color: var(--paper);
  font-family: var(--sans);
  transition: color 0.15s, padding 0.15s;
}
.part-toc-row:last-child a { border-bottom: 1px solid rgba(250,247,240,0.15); }
.part-toc-row a:hover { color: var(--amber); padding-left: 0.5rem; }
.part-toc-row a em {
  font-style: normal;
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--amber);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.part-toc-row a span {
  font-weight: 600;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}
.part-toc-row a b {
  font-weight: 500;
  font-size: 0.75rem;
  color: rgba(250,247,240,0.55);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  text-align: right;
  font-feature-settings: 'tnum';
}

/* ---------- Service spotlight card ---------- */

.spotlight {
  margin: 2rem 0;
  border: 1px solid var(--rule);
  background: var(--paper);
  display: grid;
  grid-template-columns: 9rem 1fr;
}
.spotlight .badge {
  background: var(--ink);
  color: var(--paper);
  padding: 1.1rem 1rem;
  font-family: var(--sans);
}
.spotlight .badge .kind {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--amber);
  font-weight: 700;
  margin-bottom: 0.4rem;
}
.spotlight .badge .name {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
}
.spotlight .body {
  padding: 1.1rem 1.3rem;
  font-size: 0.93rem;
  line-height: 1.5;
}
.spotlight .body p { margin: 0 0 0.5rem; }
.spotlight .body p:last-child { margin: 0; }
.spotlight .body .when {
  font-family: var(--sans);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--amber);
  font-weight: 700;
  margin-top: 0.7rem;
}

/* ---------- Print ---------- */

@page {
  size: letter;
  margin: 0.85in 0.75in;
}

@media print {
  body { background: white; font-size: 11pt; }
  .shell { display: block; }
  .sidebar, .topbar, .skip-print { display: none !important; }
  .page { display: block; padding: 0; max-width: none; margin: 0; }
  .rail { position: static; }
  .rail .marginalia, .rail .ministat {
    page-break-inside: avoid;
    margin: 1em 0;
  }
  h1, h2, h3 { page-break-after: avoid; }
  .chapter-opener { page-break-before: always; }
  .q .reveal { page-break-inside: avoid; }
  .q .reveal[open] { display: block; }
  .q .reveal summary { display: none; }
  .q .reveal .answer { margin-top: 0.5rem; }
  .callout, .objectives, .tbl, .diagram { page-break-inside: avoid; }
  pre { white-space: pre-wrap; }
  a { color: var(--ink); text-decoration: none; }
}

/* ---------- Abbreviations: hover tooltip on screen ---------- */
/* Prose uses Manning-style first-use expansion ("Full Term (ABBR)").    */
/* `<abbr>` remains on a few compact table cells where inline expansion  */
/* would wreck the layout — tooltip provides the definition on screen.   */

abbr[title] {
  border-bottom: 1px dotted var(--amber);
  text-decoration: none;
  cursor: help;
}

@media print {
  abbr[title] { border-bottom: none; }
}

/* ---------- Paged Media (Paged.js / Prince) ---------- */
/* CSS rules below are read by Paged.js when running                         */
/*   `mise run pdf` → npx pagedjs-cli editions/<sku>/index.html -o book.pdf  */
/* They set page numbers, running headers, recto chapter starts, and named  */
/* pages for cover / copyright / TOC so those don't carry page numbers.      */
/* Browser screen rendering ignores everything in this section.              */

@page {
  size: letter;
  margin: 0.85in 0.75in 0.95in 0.75in;

  @bottom-right {
    content: counter(page);
    font-family: 'Inter Tight', sans-serif;
    font-size: 9pt;
    color: #6A7588;
    margin-top: 0.3in;
  }

  @top-right {
    content: string(chapter-title);
    font-family: 'Inter Tight', sans-serif;
    font-size: 8.5pt;
    font-style: italic;
    color: #6A7588;
    letter-spacing: 0.02em;
    margin-bottom: 0.3in;
  }
}

@page :left {
  @bottom-right { content: none; }
  @bottom-left  { content: counter(page); font-family: 'Inter Tight', sans-serif; font-size: 9pt; color: #6A7588; margin-top: 0.3in; }
  @top-right    { content: none; }
  @top-left     {
    content: 'Production Generative AI on AWS';
    font-family: 'Inter Tight', sans-serif;
    font-size: 8.5pt;
    font-style: italic;
    color: #6A7588;
    letter-spacing: 0.02em;
    margin-bottom: 0.3in;
  }
}

/* Cover, copyright, ToC — no page numbers, no running header. */
@page :first, @page cover, @page front-matter {
  @bottom-left  { content: none; }
  @bottom-right { content: none; }
  @top-left     { content: none; }
  @top-right    { content: none; }
}

.cover-page         { page: cover; }
#copyright          { page: front-matter; }
#toc                { page: front-matter; }

/* Capture chapter title into the running header string. */
.chapter-opener h1  { string-set: chapter-title content(); }

/* Chapter openers start on a recto (right-hand) page — book convention. */
@media print {
  .chapter-opener        { break-before: right; }
  .part-opener           { break-before: right; }
  .cover-page            { break-after: right; }
  #copyright             { break-after: right; }
  #toc                   { break-after: right; }

  /* Typographic niceties for print only — orphans/widows + hyphenation. */
  p                      { orphans: 3; widows: 3; hyphens: auto; }
  h1, h2, h3, h4         { hyphens: manual; }
  pre, code, .mono       { hyphens: none; }

  /* Inline figures/tables/code-compares: avoid mid-page splits. */
  figure, .fig, .code-compare, .spotlight, .review .q { break-inside: avoid; }
}

/* ---------- Responsive ---------- */

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .page { grid-template-columns: 1fr; padding: 2rem 1.2rem 4rem; gap: 2rem; }
  .rail { position: static; }
}
