:root {
  --bg: #f7f7f5;
  --bg-raised: #ffffff;
  --fg: #1a1a1a;
  --fg-muted: #555;
  --border: #d8d4cc;
  --accent: #b8232a;
  --accent-hover: #7f1418;
  --link: #1d4e89;
  --link-hover: #b8232a;
  --header-h: 56px;
  --sidebar-w: 280px;
  /* Fluid max-width: fills the viewport on phones, caps at ~1200px on a
     typical 1080p/1440p monitor so long-form prose still has a readable
     line length. */
  --content-max: min(1200px, 94vw);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-2: 0 10px 30px rgba(0, 0, 0, 0.2);
  --radius: 6px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Helvetica,
    Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b1d;
    --bg-raised: #252528;
    --fg: #e7e7e4;
    --fg-muted: #a8a69e;
    --border: #3a3a3d;
    --accent: #ff6b6b;
    --accent-hover: #ff9b9b;
    --link: #8ab4f8;
    --link-hover: #ff6b6b;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 10px 30px rgba(0, 0, 0, 0.6);
  }
}

* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  line-height: 1.55;
}

body {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr auto;
  grid-template-areas:
    "header header"
    "sidebar main"
    "footer footer";
  min-height: 100vh;
}

.shell-skip {
  position: absolute;
  left: -9999px;
  top: auto;
}
.shell-skip:focus {
  left: 8px;
  top: 8px;
  z-index: 1000;
  background: var(--bg-raised);
  padding: 8px 12px;
  border: 2px solid var(--accent);
}

.shell-header {
  grid-area: header;
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-1);
  height: var(--header-h);
}

.shell-nav-toggle {
  background: none;
  border: 1px solid transparent;
  color: var(--fg);
  font-size: 22px;
  line-height: 1;
  padding: 6px 10px;
  cursor: pointer;
  border-radius: var(--radius);
  display: none;
}
.shell-nav-toggle:hover {
  border-color: var(--border);
}

.shell-home {
  color: var(--fg);
  text-decoration: none;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.shell-home strong {
  color: var(--accent);
  font-weight: 700;
}
.shell-home-sub {
  color: var(--fg-muted);
  font-weight: 500;
}

.shell-search {
  flex: 1;
  display: flex;
  justify-content: flex-end;
}
.shell-search input[type="search"] {
  appearance: none;
  width: min(420px, 60vw);
  font: inherit;
  padding: 8px 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  border-radius: var(--radius);
}
.shell-search input[type="search"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.shell-sidebar {
  grid-area: sidebar;
  position: sticky;
  top: var(--header-h);
  align-self: start;
  max-height: calc(100vh - var(--header-h));
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--bg-raised);
}

.shell-toc {
  font-size: 0.92rem;
}
.shell-toc-loading {
  color: var(--fg-muted);
  padding: 0 16px;
  font-style: italic;
}
.shell-toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.shell-toc .toc-section {
  border-bottom: 1px solid var(--border);
}
.shell-toc .toc-section-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  color: var(--fg);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  font: inherit;
  font-weight: 600;
}
.shell-toc .toc-section-header:hover {
  background: var(--bg);
  color: var(--accent);
}
.shell-toc .toc-caret {
  display: inline-block;
  width: 14px;
  color: var(--fg-muted);
  transition: transform 0.15s;
}
.shell-toc .toc-section.open .toc-caret {
  transform: rotate(90deg);
}
.shell-toc .toc-pages {
  max-height: 0;
  overflow: hidden;
}
.shell-toc .toc-section.open .toc-pages {
  max-height: none;
  padding: 0 0 8px;
}
.shell-toc .toc-pages a {
  display: block;
  padding: 4px 12px 4px 28px;
  color: var(--link);
  text-decoration: none;
  font-size: 0.88rem;
  line-height: 1.35;
  border-left: 3px solid transparent;
}
.shell-toc .toc-pages a:hover {
  background: var(--bg);
  color: var(--link-hover);
}
.shell-toc .toc-pages a.current {
  border-left-color: var(--accent);
  background: var(--bg);
  color: var(--accent);
  font-weight: 600;
}

.shell-main {
  grid-area: main;
  padding: 16px 24px 48px;
  min-width: 0;
}
.shell-main:focus {
  outline: none;
}

.shell-breadcrumbs {
  font-size: 0.85rem;
  color: var(--fg-muted);
  margin: 0 auto 14px;
  max-width: var(--content-max);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  align-items: center;
}
.shell-breadcrumbs a {
  color: var(--link);
  text-decoration: none;
}
.shell-breadcrumbs a:hover {
  text-decoration: underline;
}
.shell-breadcrumbs .sep {
  color: var(--fg-muted);
}

.content {
  max-width: var(--content-max);
  margin: 0 auto;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow-1);
  overflow-wrap: break-word;
}

/* Factory content tends to use tables for layout of spec sheets. Preserve
   them but prevent them from blowing up the layout on narrow screens. */
.content table {
  max-width: 100%;
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 12px 0;
}
.content td,
.content th {
  padding: 6px 10px;
  vertical-align: top;
}
.content th {
  text-align: left;
  font-weight: 600;
}

/* Wiring-diagram pages have a single wrapper table around the SWF embed;
   don't inflate the embed's positioning with cell padding there. */
body[data-section="g5d09"] .content > table td,
body[data-section="g5d09"] .content > table th {
  padding: 0;
}
.content img {
  max-width: 100%;
  height: auto;
  cursor: zoom-in;
}
.content img.shell-no-zoom {
  cursor: default;
}
.content a {
  color: var(--link);
}
.content a:hover {
  color: var(--link-hover);
}
.content h1,
.content h2,
.content h3,
.content h4,
.content h5,
.content h6 {
  color: inherit;
}

.shell-pagenav {
  max-width: var(--content-max);
  margin: 20px auto 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: center;
}
.shell-pagenav a {
  color: var(--link);
  text-decoration: none;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  font-weight: 500;
}
.shell-pagenav a:hover {
  color: var(--link-hover);
  border-color: var(--accent);
}
.shell-pagenav .prev {
  justify-self: start;
}
.shell-pagenav .up {
  justify-self: center;
  color: var(--fg-muted);
  font-size: 0.88rem;
}
.shell-pagenav .next {
  justify-self: end;
}

.shell-footer {
  grid-area: footer;
  padding: 16px 24px;
  color: var(--fg-muted);
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
}
.shell-footer a {
  color: var(--link);
}

.shell-search-overlay[hidden] {
  display: none !important;
}
.shell-search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 10vh 16px;
}
.shell-search-modal {
  background: var(--bg-raised);
  width: min(680px, 100%);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}
.shell-search-box {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding: 6px 10px;
}
.shell-search-box input {
  flex: 1;
  font: inherit;
  font-size: 1.05rem;
  padding: 10px 4px;
  border: 0;
  background: transparent;
  color: var(--fg);
  outline: none;
}
.shell-search-close {
  background: none;
  border: none;
  color: var(--fg-muted);
  font-size: 26px;
  cursor: pointer;
  padding: 0 8px;
}
.shell-search-results {
  overflow-y: auto;
  padding: 8px 0;
}
.shell-search-empty,
.shell-search-hint {
  padding: 16px;
  color: var(--fg-muted);
  font-size: 0.92rem;
}
.shell-search-result {
  display: block;
  padding: 10px 16px;
  color: var(--fg);
  text-decoration: none;
  border-left: 3px solid transparent;
}
.shell-search-result:hover,
.shell-search-result.active {
  background: var(--bg);
  border-left-color: var(--accent);
}
.shell-search-result .title {
  display: block;
  font-weight: 600;
  color: var(--link);
}
.shell-search-result .excerpt {
  color: var(--fg-muted);
  font-size: 0.88rem;
  line-height: 1.4;
  margin-top: 2px;
}
.shell-search-result mark {
  background: rgba(184, 35, 42, 0.18);
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
}

.shell-lightbox[hidden] {
  display: none !important;
}
.shell-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4vh 4vw;
}
.shell-lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  box-shadow: var(--shadow-2);
}
.shell-lightbox-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: #fff;
  font-size: 36px;
  cursor: pointer;
}

mark.shell-q {
  background: rgba(184, 35, 42, 0.25);
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
}

/* Embed mode: lets a diagram be loaded via ?embed=1 for a chrome-less view
   (useful for external embeds or direct SWF links). */
html.shell-embed,
body.shell-embed {
  background: #fff;
}
body.shell-embed {
  display: block !important;
  min-height: 0 !important;
}
body.shell-embed .shell-header,
body.shell-embed .shell-sidebar,
body.shell-embed .shell-footer,
body.shell-embed .shell-breadcrumbs,
body.shell-embed .shell-pagenav,
body.shell-embed .shell-skip,
body.shell-embed .diagram-refs,
body.shell-embed .conn-header {
  display: none !important;
}
body.shell-embed .shell-main {
  padding: 0 !important;
  margin: 0 !important;
  height: 100vh !important;
}
body.shell-embed .content {
  max-width: none !important;
  width: 100% !important;
  height: 100% !important;
  margin: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  padding: 0 !important;
  box-shadow: none !important;
  background: #fff !important;
  display: flex !important;
  align-items: stretch !important;
  justify-content: center !important;
}
body.shell-embed .content > * {
  width: 100%;
}
/* SWF fills the modal frame in embed mode. */
body.shell-embed .content object,
body.shell-embed .content embed,
body.shell-embed .content ruffle-object,
body.shell-embed .content ruffle-embed,
body.shell-embed .content ruffle-player {
  aspect-ratio: auto !important;
  width: 100% !important;
  height: 100vh !important;
  max-height: none !important;
  min-height: 0 !important;
}

/* Wiring-diagram pages: widen the content area so schematics render at a
   useful size, and style the recovered connector manifest. */
body[data-section="g5d09"] {
  --content-max: min(1600px, 96vw);
}
/* The factory Flash embed uses height="100%" on every ancestor, which
   collapses to 0 now that it lives inside .content instead of filling the
   viewport. Give the chain real dimensions. */
body[data-section="g5d09"] .content > table,
body[data-section="g5d09"] .content > table > tbody,
body[data-section="g5d09"] .content > table tr,
body[data-section="g5d09"] .content > table td {
  height: auto;
}
body[data-section="g5d09"] .content > table {
  display: table;
  overflow: visible;
  width: 100%;
}
body[data-section="g5d09"] .content object,
body[data-section="g5d09"] .content embed,
body[data-section="g5d09"] .content ruffle-object,
body[data-section="g5d09"] .content ruffle-embed,
body[data-section="g5d09"] .content ruffle-player {
  display: block !important;
  width: 100% !important;
  aspect-ratio: 4 / 3 !important;
  height: auto !important;
  max-height: 85vh !important;
  min-height: 420px !important;
  margin: 0 auto !important;
  background: #fff;
}
/* Ruffle's custom elements create a shadow DOM whose <canvas> fills the host.
   Make sure nothing inside also collapses. */
body[data-section="g5d09"] .content ruffle-embed > *,
body[data-section="g5d09"] .content ruffle-object > *,
body[data-section="g5d09"] .content ruffle-player > * {
  width: 100% !important;
  height: 100% !important;
}

.diagram-refs {
  margin: 20px auto 0;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.92rem;
}
.diagram-refs h4 {
  margin: 0 0 6px;
  font-size: 0.95rem;
  color: var(--accent);
}
.diagram-refs-note {
  margin: 0 0 10px;
  color: var(--fg-muted);
  font-size: 0.82rem;
  font-style: italic;
}
.diagram-refs ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 4px 16px;
}
.diagram-refs li {
  padding: 2px 0;
  border-bottom: 1px dotted var(--border);
  line-height: 1.35;
}
.diagram-refs code {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--accent);
  background: none;
  padding: 0 4px 0 0;
  font-weight: 600;
}
.diagram-refs a code {
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}
.diagram-refs a:hover code {
  color: var(--accent-hover);
}

.conn-header {
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
}
.conn-header h2 {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 1.2rem;
}
.conn-header .conn-system {
  margin: 0;
  color: var(--fg-muted);
  font-size: 0.9rem;
}
.conn-header .conn-links {
  margin: 6px 0 0;
}
.conn-header a {
  color: var(--link);
}
.conn-header .conn-system-label {
  margin: 0 0 6px;
  color: var(--fg-muted);
  font-size: 0.88rem;
}
.conn-header ul.conn-systems {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 2px 16px;
  font-size: 0.88rem;
}
.conn-header ul.conn-systems li {
  padding: 2px 0;
  border-bottom: 1px dotted var(--border);
}
.conn-header ul.conn-systems code {
  font-family: var(--mono);
  color: var(--fg-muted);
  font-size: 0.8rem;
  margin-left: 6px;
}

.connector-grid {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 4px 16px;
}
.connector-grid li {
  padding: 3px 0;
  border-bottom: 1px dotted var(--border);
}
.connector-grid code {
  font-family: var(--mono);
  color: var(--accent);
  font-weight: 600;
  margin-right: 8px;
}
.connector-grid .muted {
  color: var(--fg-muted);
  font-size: 0.85rem;
}

.component-list {
  list-style: none;
  padding: 0;
  columns: 2;
  column-gap: 24px;
}
.component-list li {
  padding: 3px 0;
  break-inside: avoid;
  font-size: 0.9rem;
}
.component-list code {
  font-family: var(--mono);
  color: var(--accent);
  font-size: 0.8rem;
  margin-right: 6px;
}
@media (max-width: 720px) {
  .component-list {
    columns: 1;
  }
}

/* Ultra-wide monitors: give prose a bit more room but keep line-length
   sane so the reader isn't whipping their eyes across 2000px. */
@media (min-width: 1800px) {
  :root {
    --content-max: min(1400px, 78vw);
  }
  body[data-section="g5d09"] {
    --content-max: min(1800px, 88vw);
  }
}

@media (max-width: 900px) {
  body {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "main"
      "footer";
  }
  /* No fixed sidebar eating viewport → let content go edge-to-edge. */
  :root {
    --content-max: 100%;
  }
  body[data-section="g5d09"] {
    --content-max: 100%;
  }
  .shell-nav-toggle {
    display: inline-flex;
  }
  .shell-sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    width: min(320px, 85vw);
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow-2);
  }
  body.sidebar-open .shell-sidebar {
    transform: translateX(0);
  }
  body.sidebar-open::after {
    content: "";
    position: fixed;
    inset: var(--header-h) 0 0 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 55;
  }
  .shell-main {
    padding: 14px 14px 40px;
  }
  .content {
    padding: 14px 14px;
  }
}

@media (max-width: 540px) {
  :root {
    --header-h: 52px;
  }
  .shell-home-sub {
    display: none;
  }
  .shell-search input[type="search"] {
    width: 100%;
  }
  .content {
    padding: 12px 10px;
  }
  /* Neutralize factory text-indent on headings in narrow viewports. */
  .content h5,
  .content h6 {
    text-indent: 0;
  }
}

@media print {
  .shell-header,
  .shell-sidebar,
  .shell-footer,
  .shell-pagenav,
  .shell-breadcrumbs,
  .shell-search-overlay,
  .shell-lightbox {
    display: none !important;
  }
  body {
    display: block;
  }
  .content {
    max-width: none;
    border: 0;
    box-shadow: none;
    padding: 0;
  }
}
