/*
 * ARCHON site overrides, loaded after every page's own styles.
 * They live in the build rather than in src/ so a fresh canvas export keeps them.
 * Inline styles from the canvas need !important to be overridden.
 */

/* Table layout fallback. The catalog pages' Synthesis tables use the same div-based table
   classes (.tx-tr rows, .tx-c2/.tx-c3/.tx-c4 column sets) as the rest of the site, but their
   CSS never included the layout rules, so each table's cells ran together as plain text.
   :where() keeps these rules at zero specificity, so any page that defines its own keeps them;
   the values match the ones the other 116 pages use. */
:where(.tx-scroll) {
  overflow-x: auto;
  max-width: 100%;
}
:where(.tx-tab) {
  min-width: 620px;
}
:where(.tx-tr) {
  display: grid;
  gap: 8px 20px;
  padding: 10px 0;
  font-size: 15px;
  line-height: 1.5;
}
:where(.tx-th) {
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  text-transform: uppercase;
}
:where(.tx-c2) {
  grid-template-columns: minmax(150px, 1fr) minmax(0, 2.4fr);
}
:where(.tx-c3) {
  grid-template-columns: minmax(140px, 1fr) minmax(0, 1.7fr) minmax(0, 1.7fr);
}
:where(.tx-c4) {
  grid-template-columns: minmax(120px, 1fr) minmax(0, 1.4fr) minmax(0, 1.4fr) minmax(0, 1.4fr);
}

/* Explorer and Blog lists. Their program buttons (.pbtn, .lbtn) keep a grid with a 62px first
   column for a program number the template no longer renders, so each name was squeezed into
   that 62px slot and cut off ("DOMINI…"). When the name block is the only child, let it span
   the row. Section names and subtitles wrap instead of being cut with an ellipsis. */
.pbtn > :only-child,
.lbtn > :only-child {
  grid-column: 1 / -1;
}
.fbtn .nm,
.pbtn .sb,
.lbtn .sb {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}
.fbtn {
  padding-top: 10px;
  padding-bottom: 10px;
  line-height: 1.3;
}
/* The Blog's section buttons have the same problem with a 40px code column: with only a name
   and a count, give the name the wide column. */
.fbtn:has(> :nth-child(2):last-child) {
  grid-template-columns: minmax(0, 1fr) auto;
}

/* Explorer and Blog: sections, a list, and a reader. In the docs column the reader did not fit
   beside the two lists, so it wrapped below them and opened 1,300–2,700px down the page. Stack
   the two lists in a left column, each scrolling inside a capped height, with the reader beside
   them; on narrower screens everything stacks, and the capped lists keep the reader close. */
.dx-main div:has(> article[aria-live="polite"]) {
  display: grid !important;
  grid-template-columns: minmax(230px, 290px) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  gap: 24px 28px !important;
  align-items: start;
}
.dx-main div:has(> article[aria-live="polite"]) > div {
  grid-column: 1;
  max-width: none !important;
  min-width: 0;
}
.dx-main div:has(> article[aria-live="polite"]) > article {
  grid-column: 2;
  grid-row: 1 / span 2;
  min-width: 0;
}
.dx-main div:has(> article[aria-live="polite"]) div:has(> .fbtn) {
  max-height: 340px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.dx-main div:has(> article[aria-live="polite"]) div:has(> .pbtn) {
  max-height: 520px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
@media (max-width: 1100px) {
  .dx-main div:has(> article[aria-live="polite"]) {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
  }
  .dx-main div:has(> article[aria-live="polite"]) > article {
    grid-column: 1;
    grid-row: auto;
  }
  .dx-main div:has(> article[aria-live="polite"]) div:has(> .fbtn) {
    max-height: 260px;
  }
  .dx-main div:has(> article[aria-live="polite"]) div:has(> .pbtn) {
    max-height: 360px;
  }
}

/* Home, "How the foundry works": the five stages were a 920px-wide strip in a column about
   700px wide, so it scrolled sideways and cut a stage off. Lay the stages out as a vertical
   list, with each activity label (Reconstruct, Test, Connect) beside the stages it covers. */
.dx-main [style*="min-width: 920px; display: grid; grid-template-columns: repeat(5"] {
  min-width: 0 !important;
  grid-template-columns: minmax(96px, 150px) minmax(0, 1fr) !important;
  gap: 0 28px !important;
}
.dx-main [style*="min-width: 920px; display: grid; grid-template-columns: repeat(5"] > :nth-child(-n+5) {
  grid-column: 2;
}
.dx-main [style*="min-width: 920px; display: grid; grid-template-columns: repeat(5"] > :nth-child(1) { grid-row: 1; }
.dx-main [style*="min-width: 920px; display: grid; grid-template-columns: repeat(5"] > :nth-child(2) { grid-row: 2; }
.dx-main [style*="min-width: 920px; display: grid; grid-template-columns: repeat(5"] > :nth-child(3) { grid-row: 3; }
.dx-main [style*="min-width: 920px; display: grid; grid-template-columns: repeat(5"] > :nth-child(4) { grid-row: 4; }
.dx-main [style*="min-width: 920px; display: grid; grid-template-columns: repeat(5"] > :nth-child(5) { grid-row: 5; }
.dx-main [style*="min-width: 920px; display: grid; grid-template-columns: repeat(5"] > :nth-child(6) {
  grid-column: 1 !important;
  grid-row: 1 / 3;
}
.dx-main [style*="min-width: 920px; display: grid; grid-template-columns: repeat(5"] > :nth-child(7) {
  grid-column: 1 !important;
  grid-row: 3 / 5;
}
.dx-main [style*="min-width: 920px; display: grid; grid-template-columns: repeat(5"] > :nth-child(8) {
  grid-column: 1 !important;
  grid-row: 5 / 6;
}
.dx-main [style*="min-width: 920px; display: grid; grid-template-columns: repeat(5"] > :nth-child(n+6) {
  margin-top: 0 !important;
  padding-top: 22px !important;
  border-top: 2px solid var(--ink-4) !important;
}

/* System-Field, "How a frame is made": a six-step row with a fixed 1080px minimum inside a
   narrower scroller, so the last step was always cut off. Show the steps as a grid instead
   (the arrow-line connectors between them are dropped). */
.dx-main ol[style*="min-width: 1080px"] {
  min-width: 0 !important;
  display: grid !important;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 28px 32px;
}
.dx-main ol[style*="min-width: 1080px"] > li[style*="flex: 0 0 28px"] {
  display: none !important;
}
@media (max-width: 900px) {
  .dx-main ol[style*="min-width: 1080px"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 480px) {
  .dx-main ol[style*="min-width: 1080px"] {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Older content kept inside the docs frame: its "paper" sections are drawn as dark panels
   with a 1px border (each page's own CSS), but the frame also strips every side padding from
   their inner .ax-wrap, so text sat flush against the panel's edges and the borders read as
   stray lines. Give the panel an inside margin. */
.dx-main section.ax-paper > .ax-wrap,
.dx-main section.ax-carbon > .ax-wrap {
  padding-left: 32px !important;
  padding-right: 32px !important;
}
@media (max-width: 600px) {
  .dx-main section.ax-paper > .ax-wrap,
  .dx-main section.ax-carbon > .ax-wrap {
    padding-left: 18px !important;
    padding-right: 18px !important;
  }
}

/* Tables that sit in their own sideways scroller carry a fixed minimum width (620–760px).
   In the docs column that minimum made the Integration table scroll and cut its last column
   mid-word. From tablet width up, let such tables fit their column; phones keep the scroller. */
@media (min-width: 700px) {
  .dx-main [style*="overflow-x: auto"] > table.ax-table[style*="min-width"] {
    min-width: 0 !important;
  }
}

/* Integration table: its merged "Integration check" cell uses body-size type, which ran to
   18 lines in its narrow column on tablets. Match the table's own size there. */
@media (max-width: 1300px) {
  .dx-main table.ax-table td[rowspan] .ax-body {
    font-size: 15px;
    line-height: 1.5;
  }
  .dx-main [style*="overflow-x: auto"] > table.ax-table th,
  .dx-main [style*="overflow-x: auto"] > table.ax-table td {
    padding-right: 10px;
  }
}

/* Long captions beside the entry pages' pictures, and body paragraphs in the older content
   that wrapped to the full column (the Blog's intro), ran about 110 characters to a line. */
.dx-main p.ax-hide-md,
.dx-main .dx-legacy-body p.ax-body {
  max-width: 70ch;
}

/* Site map, sections table: a fixed 760px minimum inside a narrower panel made it scroll
   sideways at every width. Its four columns fit without it (phones get a stacked layout below). */
.dx-main ol[style*="min-width: 760px"] {
  min-width: 0 !important;
}

/* Phones: rows that pair a fixed-minimum label column (160-280px) with text
   columns leave the text a sliver of the width, so long words push the page
   sideways. Stack them into one column. */
@media (max-width: 600px) {
  .dx-main [style*="grid-template-columns: minmax(1"],
  .dx-main [style*="grid-template-columns: minmax(2"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  /* Stacked ledgers: the label sits directly above its value, without a rule between. */
  .dx-main .ax-ledger[style*="grid-template-columns: minmax("] dt {
    padding-bottom: 0;
    border-bottom: 0;
  }

  /* Numbered rows (number, label, text): keep the number column and put the
     label and text under each other beside it. */
  .dx-main [style*="grid-template-columns: 30px minmax("] {
    grid-template-columns: 30px minmax(0, 1fr) !important;
  }
  .dx-main [style*="grid-template-columns: 44px minmax("] {
    grid-template-columns: 44px minmax(0, 1fr) !important;
  }
  .dx-main [style*="grid-template-columns: 72px minmax("] {
    grid-template-columns: 48px minmax(0, 1fr) !important;
    column-gap: 16px !important;
  }
  .dx-main [style*="grid-template-columns: 30px minmax("] > :nth-child(n+3),
  .dx-main [style*="grid-template-columns: 44px minmax("] > :nth-child(n+3),
  .dx-main [style*="grid-template-columns: 72px minmax("] > :nth-child(n+3) {
    grid-column: 2;
  }

  /* Site map, sections table (section, overview, program pages, foundry entries): a 760px-wide
     list that scrolled sideways on phones. Show each row as the section name, then its two
     links side by side, then its foundry entries; the column headings are not needed. */
  .dx-main ol[style*="min-width: 760px"] > li {
    grid-template-columns: max-content minmax(0, 1fr) !important;
    justify-content: start;
    gap: 6px 20px !important;
  }
  .dx-main ol[style*="min-width: 760px"] > li > :first-child,
  .dx-main ol[style*="min-width: 760px"] > li > :nth-child(4) {
    grid-column: 1 / -1;
  }
  .dx-main ol[style*="min-width: 760px"] > li.ax-micro {
    display: none !important;
  }

  /* Cards and rows that put text beside an auto-width side column (the Notes manifesto card):
     stack the side column under the text. */
  .dx-main [style*="grid-template-columns: minmax(0px, 1fr) auto"],
  .dx-main [style*="grid-template-columns: minmax(0, 1fr) auto"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  /* Tables without their own scroller: let headers wrap and drop fixed column widths. */
  .dx-main :not([style*="overflow"]) > table.ax-table th {
    white-space: normal;
  }
  .dx-main :not([style*="overflow"]) > table.ax-table th[style*="width"] {
    width: auto !important;
  }
  .dx-main :not([style*="overflow"]) > table.ax-table th,
  .dx-main :not([style*="overflow"]) > table.ax-table td {
    padding-right: 10px;
  }

  /* Wrapping flex cards with a wide basis may shrink below their content's minimum. */
  .dx-main [style*="flex: 1 1 "] {
    min-width: 0;
  }
}

/* Small phones (320-380px). */
@media (max-width: 380px) {
  /* Long single words in page titles ("Synchronization") need a slightly smaller size. */
  .dx-h1 {
    font-size: 30px;
    overflow-wrap: break-word;
  }

  /* System-Type spacing scale: the widest sample bar (192px) gets its own line,
     at true size, instead of overflowing its column. */
  .dx-main .srow > :nth-child(3) {
    grid-column: 1 / -1;
  }

  /* A table whose words cannot wrap any narrower scrolls inside itself, not the page. */
  .dx-main :not([style*="overflow"]) > table.ax-table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
  }
}

/* Research figures (rx-*). One kit for every new figure on the site: ASCII figures in a mono
   panel, and SVG diagrams and plots drawn with classes rather than presentation attributes, so
   the same markup works in static pages and in data-driven templates. Colors follow the docs
   palette: bone #ECE8E1, ash #A29B92 / #8A847B, rules #24221F / #3A3733, signal #FF6B1A. */
.rx-fig {
  margin: 30px 0 12px;
  max-width: 100%;
  min-width: 0;
}
.rx-cap {
  margin: 0 0 10px;
  max-width: 72ch;
  font: 400 12px/1.55 "Geist Mono", ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: .01em;
  color: #8A847B;
}
.rx-cap b {
  color: #ECE8E1;
  font-weight: 600;
}
.rx-note {
  margin: 10px 0 0;
  max-width: 70ch;
  font: 400 13px/1.55 "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  color: #8A847B;
}
.rx-ascii {
  margin: 0;
  padding: 18px 20px;
  overflow-x: auto;
  background: #141311;
  border: 1px solid #24221F;
  border-radius: 6px;
  color: #ECE8E1;
  font: 400 12.5px/1.25 "Geist Mono", ui-monospace, Menlo, Consolas, monospace;
  white-space: pre;
  tab-size: 4;
}
.rx-ascii .hl { color: #FF6B1A; }
.rx-ascii .dim { color: #8A847B; }
.rx-scroll {
  overflow-x: auto;
  background: #141311;
  border: 1px solid #24221F;
  border-radius: 6px;
}
.rx-svg {
  display: block;
  width: 100%;
  height: auto;
}
@media (max-width: 600px) {
  .rx-svg { min-width: 540px; }
}
.rx-svg text { font: 400 11px "Geist Mono", ui-monospace, Menlo, monospace; fill: #A29B92; }
.rx-svg text.tl { font: 600 12.5px "Instrument Sans", "Helvetica Neue", Arial, sans-serif; fill: #ECE8E1; }
.rx-svg text.tb { font: 400 12px "Instrument Sans", "Helvetica Neue", Arial, sans-serif; fill: #C2BBB2; }
.rx-svg text.ta { fill: #FF6B1A; }
.rx-svg text.tm { fill: #8A847B; }
.rx-svg .am { text-anchor: middle; }
.rx-svg .ae { text-anchor: end; }
.rx-svg .ax { fill: none; stroke: #3A3733; stroke-width: 1; }
.rx-svg .gd { fill: none; stroke: #24221F; stroke-width: 1; }
.rx-svg .ln { fill: none; stroke: #ECE8E1; stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.rx-svg .la { fill: none; stroke: #FF6B1A; stroke-width: 1.75; stroke-linejoin: round; stroke-linecap: round; }
.rx-svg .lm { fill: none; stroke: #8A847B; stroke-width: 1.25; stroke-linejoin: round; stroke-linecap: round; }
.rx-svg .ld { fill: none; stroke: #A29B92; stroke-width: 1.25; stroke-dasharray: 4 4; }
.rx-svg .lad { fill: none; stroke: #FF6B1A; stroke-width: 1.5; stroke-dasharray: 5 4; }
.rx-svg .bx { fill: #1D1B19; stroke: #3A3733; stroke-width: 1; }
.rx-svg .ba { fill: #1D1B19; stroke: #FF6B1A; stroke-width: 1.25; }
.rx-svg .bf { fill: #24221F; stroke: none; }
.rx-svg .sh { fill: #FF6B1A; fill-opacity: .16; stroke: none; }
.rx-svg .sm { fill: #ECE8E1; fill-opacity: .07; stroke: none; }
.rx-svg .dt { fill: #ECE8E1; stroke: none; }
.rx-svg .da { fill: #FF6B1A; stroke: none; }
.rx-svg .dm { fill: #8A847B; stroke: none; }
.rx-svg .ah { fill: #A29B92; stroke: none; }
.rx-svg .aa { fill: #FF6B1A; stroke: none; }

/* Section figures (the glyph diagrams on the older-style systems pages) sit inside a wrapping
   flex row; with no content width of their own they collapsed to zero and never showed.
   Give each one the full row. */
.dx-main .ax-wrap > figure.dx-fig {
  flex: 0 0 100%;
  width: 100%;
  min-width: 0;
}
