/* =============================================================
   Comparison-diagram styles — shared by the landing page
   (#compare section) and the standalone compare.html.

   Colors reference the site's SEMANTIC variables (--surface,
   --text, --brand, --accent, --green, --info-bg, --border, …)
   so the diagram adapts to light/dark mode and matches the rest
   of the site instead of carrying its own fixed palette. The
   only diagram-local custom props are tints derived from those
   vars via color-mix.

   The diagram never scrolls horizontally: compare-diagram.js
   wraps the rows in a .diagram-stage and scales it to fit the
   frame width (see fitFrame()).

   Wrap the diagram markup in an element with class .cmp-scope.
   ============================================================= */
    .cmp-scope {
      /* derived tints (theme-aware) */
      --cmp-phase-fill:  color-mix(in srgb, var(--brand) 9%, var(--surface));
      --cmp-guard-fill:  color-mix(in srgb, var(--accent) 11%, var(--surface));
      --cmp-base-fill:   color-mix(in srgb, var(--green) 12%, var(--surface));
      --cmp-hover-fill:  color-mix(in srgb, var(--brand) 16%, var(--surface));
    }

    main.compare-main {
      padding: 4rem 0 6rem;
    }
    main.compare-main .compare-intro {
      max-width: 56rem;
      margin: 0 auto 3rem;
      text-align: center;
    }
    main.compare-main .compare-intro h1 {
      font-size: clamp(1.75rem, 2.4vw + 1rem, 2.6rem);
      line-height: 1.15;
      margin: 0 0 1rem;
      color: var(--brand);
    }
    main.compare-main .compare-intro p {
      font-size: 1.05rem;
      line-height: 1.55;
      color: var(--text-muted);
      margin: 0;
    }
    main.compare-main .compare-intro p em {
      background-color: var(--warn-bg);
      padding: 0 0.2em;
      font-style: normal;
      border-bottom: 1px dotted var(--accent);
    }

    /* ---------- diagram frame ---------- */
    .diagram-frame {
      max-width: 72rem;
      margin: 0 auto;
      padding: 1.5rem 1.25rem;
      background-color: var(--bg-alt);
      border: 1px solid var(--border);
      border-radius: 12px;
      overflow: hidden;            /* no horizontal scrollbar — JS scales to fit */
    }
    /* The stage holds the rows at their natural width; JS scales it to fill the
       frame width — up on wide viewports (bigger, more legible) and down on
       narrow ones (no horizontal scroll). Authored width:max-content so the
       natural size can be measured. */
    .diagram-stage {
      width: max-content;
      transform-origin: top left;
    }

    /* The three runtime rows share one column grid (via subgrid) so the common
       phase blocks — Read / Think / Act / Report — line up vertically across
       rows. Columns: label · Read · gap · Think · gap · Act · gap · Report ·
       annotation. A gap cell holds a guard where the runtime has one, or just
       an arrow where it doesn't — an empty gap reads as "no gate here." */
    .diagram-rows {
      display: grid;
      grid-template-columns: repeat(9, auto);
      column-gap: 0.4rem;
      row-gap: 1.25rem;
      align-items: center;
      width: max-content;
    }
    .diagram-row {
      display: grid;
      grid-column: 1 / -1;
      grid-template-columns: subgrid;
      align-items: center;
      justify-items: center;
    }

    .row-label {
      justify-self: end;
      font-weight: 700;
      color: var(--brand);
      font-size: 0.95rem;
      text-align: right;
      padding-right: 0.4rem;
      cursor: help;
      border-bottom: 1px dotted var(--border-strong);
    }
    .row-label.is-enclawed {
      color: var(--green);
      font-weight: 800;
    }

    .block {
      background-color: var(--cmp-phase-fill);
      border: 1px solid var(--brand);
      border-radius: 6px;
      padding: 0.5rem 0.7rem;
      font-size: 0.85rem;
      font-weight: 700;
      color: var(--text);
      cursor: help;
      transition: background-color 120ms, border-color 120ms, transform 120ms, box-shadow 120ms;
      white-space: nowrap;
      min-width: 4.5rem;
      text-align: center;
      font-family: "Inter", system-ui, sans-serif;
    }
    .block.is-phase {
      min-width: 5.5rem;
    }
    .block.is-guard {
      background-color: var(--cmp-guard-fill);
      border-color: var(--accent);
      color: var(--accent);
      font-size: 0.72rem;
      min-width: 4.5rem;
      padding: 0.35rem 0.5rem;
    }
    .block.is-base {
      background-color: var(--cmp-base-fill);
      border-color: var(--green);
      color: var(--green);
      font-size: 0.72rem;
      padding: 0.4rem 0.7rem;
      min-width: 9rem;
    }
    .block:hover, .block:focus-visible, .block.is-active {
      outline: none;
      background-color: var(--cmp-hover-fill);
      transform: translateY(-1px);
      box-shadow: var(--shadow);
    }
    .block.is-guard:hover, .block.is-guard:focus-visible, .block.is-guard.is-active {
      background-color: color-mix(in srgb, var(--accent) 20%, var(--surface));
    }
    .block.is-base:hover, .block.is-base:focus-visible, .block.is-base.is-active {
      background-color: color-mix(in srgb, var(--green) 20%, var(--surface));
    }

    .arrow {
      color: var(--text-muted);
      font-size: 1.2rem;
      font-weight: 700;
      user-select: none;
      pointer-events: none;
    }

    .annotation {
      justify-self: start;
      font-size: 0.82rem;
      font-style: italic;
      color: var(--accent);
      white-space: nowrap;
    }
    .annotation.is-good {
      color: var(--green);
    }

    /* ---------- foundation tier (audit + accreditor) ---------- */
    .diagram-foundation {
      display: flex;
      justify-content: center;
      gap: 1.5rem;
      margin-top: -0.5rem;
      padding-left: 9.5rem;
      flex-wrap: wrap;
    }
    .foundation-arm {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 0.3rem;
    }
    .foundation-arm::before {
      content: "▲";
      color: var(--text-faint);
      font-size: 0.9rem;
      opacity: 0.7;
    }

    /* ---------- the always-visible explanation panel ---------- */
    .explain-panel {
      max-width: 60rem;
      margin: 2rem auto 0;
      background-color: var(--surface);
      border: 1px solid var(--border);
      border-left: 4px solid var(--brand);
      border-radius: 8px;
      padding: 1.25rem 1.5rem;
      min-height: 8rem;
      transition: border-left-color 120ms;
    }
    .explain-panel.flavor-good {
      border-left-color: var(--green);
    }
    .explain-panel.flavor-warn {
      border-left-color: var(--accent);
    }
    .explain-panel-label {
      font-size: 0.78rem;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.08em;
      color: var(--text-muted);
      margin: 0 0 0.4rem;
    }
    .explain-panel-title {
      font-size: 1.15rem;
      font-weight: 700;
      margin: 0 0 0.6rem;
      color: var(--brand);
    }
    .explain-panel.flavor-good .explain-panel-title {
      color: var(--green);
    }
    .explain-panel.flavor-warn .explain-panel-title {
      color: var(--accent);
    }
    .explain-panel-body {
      font-size: 1rem;
      line-height: 1.55;
      color: var(--text);
      margin: 0;
    }
    .explain-panel-body .mono {
      font-family: "JetBrains Mono", ui-monospace, monospace;
      font-size: 0.92em;
      color: var(--text-muted);
    }
    .explain-panel-hint {
      font-size: 0.85rem;
      color: var(--text-faint);
      margin-top: 0.6rem;
      font-style: italic;
    }

    /* ---------- legend ---------- */
    /* Each item is a block-shaped sample + label, laid out so it reads as a
       miniature of the diagram blocks rather than a checkbox + caption. */
    .legend {
      display: flex;
      gap: 1rem 1.75rem;
      max-width: 60rem;
      margin: 1.5rem auto 0;
      flex-wrap: wrap;
      justify-content: center;
      font-size: 0.9rem;
      color: var(--text-muted);
    }
    .legend > span {
      display: inline-flex;
      align-items: center;
      gap: 0.5rem;
    }
    .legend-swatch {
      display: inline-block;
      width: 2.1rem;
      height: 1.05rem;
      vertical-align: middle;
      border-radius: 5px;
      border: 1.5px solid var(--brand);
      flex: 0 0 auto;
    }
    .legend-swatch.phase  { background-color: var(--cmp-phase-fill); border-color: var(--brand); }
    .legend-swatch.guard  { background-color: var(--cmp-guard-fill); border-color: var(--accent); }
    .legend-swatch.base   { background-color: var(--cmp-base-fill);  border-color: var(--green); }

    /* ---------- small screens ---------- */
    @media (max-width: 720px) {
      main.compare-main { padding-top: 2rem; }
      .diagram-frame { padding: 1rem 0.75rem; }
      .legend { font-size: 0.82rem; }
    }
