:root {
  --bg-chassis: #0f1115;
  --bg-deck: #171a21;
  --bg-faceplate: #1c2028;
  --bg-well: #0a0c10;
  --bg-elevated: #242934;
  --border-outer: #2c323d;
  --border-highlight: #3a4252;
  --text-primary: #e6eaf0;
  --text-secondary: #b4bcc8;
  --text-muted: #848e9c;
  --accent-burgundy: #962836;
  --accent-burgundy-bright: #d95362;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-cyan: #38bdf8;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 76px;
}

body {
  margin: 0;
  background-color: var(--bg-chassis);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15.5px;
  line-height: 1.65;
}

/* Top Hardware Studio Header Deck */
.top-deck {
  position: sticky;
  top: 0;
  z-index: 100;
  height: 60px;
  background: linear-gradient(180deg, #1f232c 0%, #15181f 100%);
  border-bottom: 1px solid var(--border-highlight);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  gap: 1rem;
}

.brand-cluster {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.brand-badge {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #f8fafc;
  background: linear-gradient(180deg, #962836 0%, #721c27 100%);
  border: 1px solid #b83848;
  padding: 0.28rem 0.55rem;
  border-radius: 4px;
  text-decoration: none;
  white-space: nowrap;
}

.brand-title {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.deck-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.search-trigger {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--bg-well);
  color: var(--text-muted);
  border: 1px solid var(--border-outer);
  border-radius: 5px;
  padding: 0.35rem 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  cursor: pointer;
  min-width: 230px;
  justify-content: space-between;
}

.search-trigger:hover {
  border-color: var(--accent-burgundy-bright);
  color: var(--text-primary);
}

.deck-btn {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  background: linear-gradient(180deg, #2c313c 0%, #20242d 100%);
  border: 1px solid var(--border-highlight);
  border-radius: 4px;
  padding: 0.36rem 0.75rem;
  text-decoration: none;
  white-space: nowrap;
}

.deck-btn:hover {
  background: linear-gradient(180deg, #353b48 0%, #272c37 100%);
  border-color: #50596b;
}

.deck-btn-primary {
  background: linear-gradient(180deg, #962836 0%, #721c27 100%);
  border-color: #b83848;
  color: #ffffff;
}

.deck-btn-primary:hover {
  background: linear-gradient(180deg, #ab3040 0%, #84212e 100%);
  border-color: #d95362;
}

/* Three-Column Studio Workspace */
.manual-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 240px;
  max-width: 1560px;
  margin: 0 auto;
  min-height: calc(100vh - 60px);
}

/* Left Chapter Sidebar */
.sidebar-nav {
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
  background-color: var(--bg-deck);
  border-right: 1px solid var(--border-outer);
  padding: 1.25rem 0.9rem 2rem;
}

.part-group {
  margin-bottom: 1.35rem;
}

.part-header {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0 0.5rem 0.4rem;
  border-bottom: 1px solid var(--border-outer);
  margin-bottom: 0.45rem;
}

.chapter-link {
  display: block;
  padding: 0.42rem 0.6rem;
  margin: 0.15rem 0;
  border-radius: 4px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  border: 1px solid transparent;
}

.chapter-link:hover {
  background-color: var(--bg-elevated);
  color: var(--text-primary);
}

.chapter-link.active {
  background: linear-gradient(180deg, #7a1f2b 0%, #5c1720 100%);
  border-color: #b83848;
  color: #ffffff;
  font-weight: 600;
}

.sidebar-subnav {
  list-style: none;
  padding-left: 0.85rem;
  margin: 0.25rem 0 0.5rem;
  border-left: 1px solid var(--border-outer);
}

.sidebar-subnav li a {
  display: block;
  padding: 0.22rem 0.45rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.8rem;
  line-height: 1.35;
  border-radius: 3px;
}

.sidebar-subnav li a:hover {
  color: var(--text-primary);
  background-color: rgba(255, 255, 255, 0.04);
}

/* Main Content Column */
.content-pane {
  padding: 2.25rem 3rem 4rem;
  max-width: 940px;
  width: 100%;
  margin: 0 auto;
}

.chapter-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-burgundy-bright);
  margin-bottom: 0.35rem;
}

.content-pane h1 {
  font-size: 2rem;
  line-height: 1.25;
  margin: 0 0 0.75rem;
  letter-spacing: -0.01em;
  color: #ffffff;
}

.chapter-lead {
  font-size: 1.05rem;
  color: var(--text-secondary);
  margin: 0 0 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-outer);
}

.content-pane h2 {
  font-size: 1.4rem;
  margin: 2.5rem 0 0.85rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border-outer);
  color: #f8fafc;
}

.content-pane h3 {
  font-size: 1.12rem;
  margin: 1.8rem 0 0.6rem;
  color: #e2e8f0;
}

.content-pane h4 {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  margin: 1.4rem 0 0.45rem;
  color: var(--accent-cyan);
}

.content-pane p {
  margin: 0 0 1.05rem;
  color: var(--text-primary);
}

.content-pane ul,
.content-pane ol {
  margin: 0 0 1.2rem;
  padding-left: 1.45rem;
}

.content-pane li {
  margin-bottom: 0.42rem;
}

.content-pane li > ul,
.content-pane li > ol {
  margin-top: 0.35rem;
  margin-bottom: 0.35rem;
}

.content-pane a {
  color: var(--accent-burgundy-bright);
  text-decoration: none;
  font-weight: 500;
}

.content-pane a:hover {
  text-decoration: underline;
}

.heading-anchor {
  opacity: 0;
  margin-left: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--text-muted);
  text-decoration: none;
}

h2:hover .heading-anchor,
h3:hover .heading-anchor {
  opacity: 1;
}

/* Inline Code & Tactile Keycaps */
code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background-color: var(--bg-well);
  border: 1px solid var(--border-outer);
  color: #f1f5f9;
  padding: 0.12rem 0.38rem;
  border-radius: 4px;
}

kbd.keycap {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.78em;
  font-weight: 700;
  line-height: 1.2;
  color: #f8fafc;
  background: linear-gradient(180deg, #323846 0%, #222630 100%);
  border: 1px solid #4a5366;
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0.14rem 0.42rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
}

/* Recessed Code / Signal-Flow Well */
pre.code-well {
  background-color: var(--bg-well);
  border: 1px solid var(--border-outer);
  border-radius: 6px;
  padding: 1rem 1.2rem;
  overflow-x: auto;
  margin: 0 0 1.35rem;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.6);
}

pre.code-well code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.84rem;
  line-height: 1.45;
  color: #d8dee9;
}

/* Console Data Tables */
.table-wrap {
  overflow-x: auto;
  margin: 0 0 1.5rem;
  border: 1px solid var(--border-outer);
  border-radius: 6px;
  background-color: var(--bg-faceplate);
}

table.console-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

table.console-table th {
  background: linear-gradient(180deg, #252a34 0%, #1c2028 100%);
  color: #f8fafc;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border-highlight);
}

table.console-table td {
  padding: 0.58rem 0.85rem;
  border-bottom: 1px solid var(--border-outer);
  color: var(--text-primary);
  vertical-align: top;
}

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

table.console-table tr:nth-child(even) td {
  background-color: rgba(255, 255, 255, 0.015);
}

/* Studio Callout Boxes */
.callout {
  background-color: var(--bg-faceplate);
  border: 1px solid var(--border-outer);
  border-left: 4px solid var(--accent-cyan);
  border-radius: 6px;
  padding: 0.9rem 1.15rem;
  margin: 0 0 1.35rem;
}

.callout-tip {
  border-left-color: var(--accent-emerald);
}

.callout-important {
  border-left-color: var(--accent-burgundy-bright);
}

.callout-warning,
.callout-caution {
  border-left-color: var(--accent-amber);
}

.callout-header {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.35rem;
  color: #ffffff;
}

.callout p:last-child {
  margin-bottom: 0;
}

/* Studio Figures & Screenshots */
figure.studio-figure {
  margin: 1.5rem 0 1.85rem;
  background-color: var(--bg-well);
  border: 1px solid var(--border-highlight);
  border-radius: 7px;
  padding: 0.65rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

figure.studio-figure img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 4px;
  border: 1px solid var(--border-outer);
}

figure.studio-figure figcaption {
  margin-top: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-align: center;
}

.fig-num {
  color: var(--accent-burgundy-bright);
  font-weight: 700;
}

/* Right On-This-Page TOC */
.page-toc {
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
  padding: 1.5rem 1rem;
  border-left: 1px solid var(--border-outer);
  font-size: 0.8rem;
}

.page-toc-title {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}

.page-toc ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.page-toc li {
  margin-bottom: 0.35rem;
}

.page-toc li.toc-h3 {
  padding-left: 0.75rem;
}

.page-toc a {
  color: var(--text-muted);
  text-decoration: none;
  display: block;
  line-height: 1.35;
}

.page-toc a:hover {
  color: var(--text-primary);
}

/* Chapter Grid Cards on Landing Page */
.chapter-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.9rem;
  margin: 1.5rem 0 2.25rem;
}

.chapter-card {
  background: linear-gradient(180deg, #21252f 0%, #181b22 100%);
  border: 1px solid var(--border-outer);
  border-radius: 6px;
  padding: 1rem 1.1rem;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.chapter-card:hover {
  border-color: var(--accent-burgundy-bright);
  transform: translateY(-1px);
}

.chapter-card-num {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--accent-burgundy-bright);
  text-transform: uppercase;
}

.chapter-card-title {
  font-size: 1rem;
  font-weight: 600;
  color: #ffffff;
}

.chapter-card-desc {
  font-size: 0.84rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

/* Prev / Next Chapter Footer Navigation */
.chapter-pager {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-outer);
}

.pager-card {
  flex: 1;
  background-color: var(--bg-faceplate);
  border: 1px solid var(--border-outer);
  border-radius: 6px;
  padding: 0.85rem 1.1rem;
  text-decoration: none;
}

.pager-card:hover {
  border-color: var(--accent-burgundy-bright);
}

.pager-card.next {
  text-align: right;
}

.pager-dir {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.pager-title {
  font-weight: 600;
  color: var(--text-primary);
}

/* Alphabetical Index Styling */
.index-letter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 1.5rem;
  padding: 0.65rem;
  background-color: var(--bg-faceplate);
  border: 1px solid var(--border-outer);
  border-radius: 6px;
}

.index-letter-pill {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.25rem 0.55rem;
  border-radius: 4px;
  background-color: var(--bg-well);
  border: 1px solid var(--border-outer);
  color: var(--text-primary);
  text-decoration: none;
}

.index-letter-pill:hover {
  border-color: var(--accent-burgundy-bright);
}

.index-term-list dt {
  font-weight: 600;
  color: #ffffff;
  margin-top: 0.65rem;
}

.index-term-list dd {
  margin-left: 1rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* Instant Search Modal */
.search-modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background-color: rgba(5, 7, 10, 0.78);
  align-items: flex-start;
  justify-content: center;
  padding: 5rem 1rem 2rem;
}

.search-modal-backdrop.open {
  display: flex;
}

.search-modal {
  width: 100%;
  max-width: 680px;
  background-color: var(--bg-faceplate);
  border: 1px solid var(--border-highlight);
  border-radius: 8px;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.7);
  overflow: hidden;
}

.search-input-bar {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-outer);
  background-color: var(--bg-well);
}

.search-input-bar input {
  width: 100%;
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  outline: none;
}

.search-results {
  max-height: 420px;
  overflow-y: auto;
  padding: 0.5rem;
}

.search-result-item {
  display: block;
  padding: 0.65rem 0.85rem;
  border-radius: 5px;
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.search-result-item:hover {
  background-color: var(--bg-elevated);
}

.search-result-title {
  font-weight: 600;
  color: #ffffff;
  font-size: 0.92rem;
}

.search-result-meta {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--accent-burgundy-bright);
  margin-bottom: 0.15rem;
}

.search-result-snippet {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

@media (max-width: 1180px) {
  .manual-layout {
    grid-template-columns: 260px minmax(0, 1fr);
  }
  .page-toc {
    display: none;
  }
}

@media (max-width: 820px) {
  .manual-layout {
    grid-template-columns: 1fr;
  }
  .sidebar-nav {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-outer);
  }
  .content-pane {
    padding: 1.5rem 1.25rem 3rem;
  }
  .search-trigger {
    min-width: auto;
  }
}

@media print {
  body {
    background: #ffffff;
    color: #111317;
    font-size: 10.5pt;
  }
  .top-deck,
  .sidebar-nav,
  .page-toc,
  .chapter-pager,
  .search-modal-backdrop {
    display: none !important;
  }
  .manual-layout {
    display: block;
  }
  .content-pane {
    max-width: 100%;
    padding: 0;
  }
  .content-pane h1,
  .content-pane h2,
  .content-pane h3,
  .content-pane h4,
  .content-pane p,
  .chapter-lead,
  table.console-table td {
    color: #111317;
  }
  .table-wrap,
  .callout,
  pre.code-well,
  figure.studio-figure {
    background: #f8fafc !important;
    border-color: #cbd5e1 !important;
    box-shadow: none !important;
    break-inside: avoid;
  }
  table.console-table th {
    background: #e2e8f0 !important;
    color: #0f172a !important;
    border-bottom-color: #94a3b8 !important;
  }
  table.console-table td {
    border-bottom-color: #cbd5e1 !important;
  }
  .callout-header {
    color: #0f172a !important;
  }
  pre.code-well code,
  code {
    background: #f1f5f9 !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
  }
  kbd.keycap {
    background: #e2e8f0 !important;
    color: #0f172a !important;
    border-color: #94a3b8 !important;
    box-shadow: none !important;
  }
  figure.studio-figure figcaption {
    color: #334155 !important;
  }
}
