/* styles/sections/lifecycle.css
 * "Code is one stage of seven" (frames: PDLC Loop). 1440 and 1920: a ruled table, a label
 * column of 152 and seven stage columns, three 112px rows (stages; coding agents, with the
 * frame's dot field and the fern "Writes code" island in Build; Brief, between 2px fern rules),
 * then the loop back to stage 1 drawn as the frames build it (3px fern rules from the middle of
 * stage 1 to the middle of stage 7, the exported arrowhead on top). 390: the stages as a list
 * with the exported loop line beside them. Padding is section-xl. */
@layer sections {
  .lifecycle-section {
    padding-block: var(--section-xl);
  }

  .lifecycle-section > .container {
    display: flex;
    flex-direction: column;
    gap: var(--space-32);
  }

  .lifecycle-section__intro {
    --intro-lede-pad: 0px;
    --intro-lede-size: 17px;
    --intro-lede-lh: 1.6;
  }

  .lifecycle-section__intro .section-intro__heading {
    text-wrap: wrap;
  }

  /* ---------- 390: list ---------- */
  .lifecycle-m {
    display: flex;
    flex-direction: column;
    gap: var(--space-20);
    margin: 0;
  }

  .lifecycle-m__stages {
    position: relative;
    padding-left: var(--space-24);
    box-shadow: inset 0 1.5px 0 var(--ink);
  }

  .lifecycle-m__loop {
    position: absolute;
    top: 0;
    left: 0;
  }

  .lifecycle-m__loop-arrow {
    position: absolute;
    top: 16px;
    left: 15px;
  }

  .lifecycle-m__list {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .lifecycle-m__stage {
    display: flex;
    align-items: baseline;
    gap: var(--space-12);
    height: 66px;
    padding: var(--space-12);
  }

  .lifecycle-m__stage + .lifecycle-m__stage {
    border-top: 1px solid var(--line);
  }

  .lifecycle-m__stage.is-current {
    height: 86px;
    background: var(--mist);
  }

  .lifecycle-m__num {
    flex: none;
    font-size: 12px;
    line-height: 1.6;
    color: var(--ink-55);
  }

  .lifecycle-m__body {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: var(--space-4);
    min-width: 0;
  }

  .lifecycle-m__name {
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 600;
    line-height: 1.15;
    letter-spacing: -0.2px;
  }

  .lifecycle-m__artifact {
    display: flex;
    align-items: center;
    gap: var(--space-8);
  }

  .lifecycle-m__id {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    color: var(--fern);
  }

  .lifecycle-m__title {
    flex: 1;
    min-width: 0;
    font-size: 14px;
    line-height: 1.2;
    /* Short label: balanced, so it does not end on one word (BRI-7805 J14) */
    --frame-wrap-style: balance;
    text-wrap-style: balance;
  }

  .lifecycle-m__source {
    font-size: 12px;
    line-height: 1.2;
    color: var(--ink-muted);
  }

  .lifecycle-m__note {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
    color: var(--fern);
  }

  /* ---------- 1440 and 1920: table ---------- */
  .lifecycle {
    --label-w: 152px;
    --col-w: calc((100% - var(--label-w)) / 7);
    margin: 0;
  }

  /* Below about 1100px of content the table and its loop scroll sideways instead of squeezing
     seven stages; js/stage-strip.js makes the region a tab stop only while it overflows. */
  .lifecycle__scroll {
    margin-right: calc(-1 * var(--page-gutter));
    padding-right: var(--page-gutter);
    overflow-x: auto;
    scrollbar-width: thin;
  }

  /* 147px stage columns: wide enough that no name or description wraps */
  .lifecycle__scroll > * {
    min-width: 1180px;
  }

  .lifecycle__table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
  }

  /* The frame's 1.5px ink top rule and the coding-agents rule lie inside their 112px rows */
  .lifecycle__table thead :is(th, td) {
    box-shadow: inset 0 1.5px 0 var(--ink);
  }

  .lifecycle__table th,
  .lifecycle__table td {
    height: 112px;
    padding: 0;
    vertical-align: middle;
    text-align: left;
    font-weight: 400;
  }

  .lifecycle__table :is(th, td) + :is(th, td) {
    border-left: 1px solid var(--line);
  }

  .lifecycle__table thead th:first-child {
    width: var(--label-w);
  }

  .lifecycle__label {
    padding-right: var(--space-16);
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.3px;
  }

  .lifecycle__table th.lifecycle__label {
    font-weight: 600;
  }

  .lifecycle__table th.lifecycle__label--muted {
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 400;
    letter-spacing: 0;
    color: var(--ink-muted);
  }

  .lifecycle__stage {
    padding: var(--space-16) var(--space-14);
  }

  /* The frame's stage cells are 112 high with 84 of content: it centers them 14 from the top */
  .lifecycle__table th.lifecycle__stage {
    padding: var(--space-14);
  }

  .lifecycle__numeral,
  .lifecycle__name,
  .lifecycle__desc {
    display: block;
  }

  /* The 1440 and 1920 frames both draw the step numeral at 32px */
  .lifecycle__numeral {
    font-family: var(--font-display);
    font-size: 32px;
  }

  .lifecycle__name {
    margin-top: var(--space-6);
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 600;
    line-height: 1.15;
    letter-spacing: -0.3px;
  }

  .lifecycle__stage.is-current .lifecycle__name {
    color: var(--fern);
  }

  .lifecycle__name,
  .lifecycle__desc {
    white-space: nowrap;
  }

  .lifecycle__desc {
    margin-top: var(--space-6);
    font-size: 14px;
    line-height: 1.2;
    color: var(--ink-muted);
  }

  .lifecycle__agents :is(th, td) {
    height: 112px;
    box-shadow: inset 0 1px 0 var(--line);
  }

  .lifecycle__dots {
    background: url("/assets/figures/home/lifecycle-dots.svg") 0 0 / 170px 112px no-repeat;
  }

  .lifecycle__table .lifecycle__island-cell {
    padding: 9px var(--space-10) var(--space-10);
  }

  .lifecycle__island {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: var(--space-4);
    height: 92px;
    padding: 0 var(--space-12);
    border-radius: 3px;
    background: var(--fern);
    color: var(--white);
  }

  .lifecycle__island-title {
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 600;
    line-height: 1.2;
  }

  .lifecycle__island-sub {
    font-size: 12px;
    line-height: 1.2;
    color: var(--white-80);
  }

  .lifecycle__brief :is(th, td) {
    border-top: 2px solid var(--fern);
    border-bottom: 2px solid var(--fern);
  }

  /* 112 with the collapsed 2px fern rules, as znE6M draws the row (rules inside) */
  .lifecycle__table .lifecycle__brief :is(th, td) {
    height: 111px;
  }

  .lifecycle__brief td {
    padding: 17px var(--space-10) 0 var(--space-14);
    vertical-align: top;
  }

  .lifecycle__id,
  .lifecycle__artifact,
  .lifecycle__source {
    display: block;
  }

  .lifecycle__id {
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    color: var(--fern);
  }

  .lifecycle__artifact {
    margin-top: var(--space-6);
    font-family: var(--font-display);
    font-size: 17px;
    font-weight: 500;
    line-height: 1.2;
    /* Short label: balanced, so it does not end on one word (BRI-7805 J14) */
    --frame-wrap-style: balance;
    text-wrap-style: balance;
  }

  .lifecycle__source {
    margin-top: var(--space-6);
    font-size: 13px;
    line-height: 1.2;
    color: var(--ink-muted);
  }

  .lifecycle__loop {
    height: 56px;
  }

  .lifecycle__loop-path {
    position: relative;
    display: block;
    height: 100%;
    margin-left: calc(var(--label-w) + var(--col-w) / 2 - 1.5px);
    margin-right: calc(var(--col-w) / 2 - 1.5px);
    border: 3px solid var(--fern);
    border-top: 0;
  }

  .lifecycle__loop-arrow {
    position: absolute;
    top: -11px;
    left: -13px;
  }

  .lifecycle__loop-label {
    position: absolute;
    top: 22px;
    left: 9px;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    line-height: 1.2;
    letter-spacing: 0.4px;
    color: var(--fern);
  }

  .lifecycle__caption {
    padding-top: var(--space-16);
  }

  @media (width >= 900px) {
    .lifecycle-section > .container {
      gap: var(--space-64);
    }

    .lifecycle-section__intro {
      --intro-heading-size: min(var(--t-display-sm-size), (100vw - 2 * var(--page-gutter)) * 0.05);
      --intro-heading-lh: var(--t-display-sm-lh);
      --intro-heading-ls: var(--t-display-sm-ls);
      --intro-heading-measure: 818px;
      --intro-lede-pad: var(--space-6);
      --intro-lede-size: 18px;
    }
  }

  @media (width >= 1680px) {
    .lifecycle-section {
      --container-max: 1440px;
    }

    .lifecycle-section__intro {
      --intro-heading-size: var(--t-h1-size);
      --intro-heading-lh: var(--t-h1-lh);
      --intro-heading-ls: var(--t-h1-ls);
      padding-inline: 80px;
    }
  }
}

/* The lifecycle caption sets its line at 19px with a 14px legend (the shared caption is 23 and 13) */
@layer artifacts {
  @media (width >= 900px) {
    .lifecycle__caption.figure-caption .figure-caption__label {
      line-height: 19px;
    }

    .lifecycle__caption.figure-caption {
      font-size: 14px;
      line-height: 19px;
    }
  }
}

/* Pencil sets every line on a whole pixel (88 x 0.95 = 84, 18 x 1.6 = 29, 17 x 1.6 = 27);
   these rounded line heights keep the page's text boxes the frames' size. */
@layer sections {
  .lifecycle-section__intro {
    --intro-heading-lh: round(nearest, 1.05em, 1px);
    --intro-lede-lh: round(nearest, 1.6em, 1px);
  }

  @media (width >= 900px) and (width < 1680px) {
    .lifecycle-section__intro {
      --intro-heading-lh: round(nearest, 0.95em, 1px);
    }
  }
}
