/* pv-delta.css — "THE PRESERVED CITY" for figure.pm-delta-figure (#foundation).
   Companion to js/pv-delta.js. The stage is appended inside .pm-delta-code
   (the aria-hidden ink panel); the original static children stay in the DOM
   as the no-JS / forced-colors fallback and are hidden only while .pv4-live
   is set. No state controller exists for this figure: the scene is a
   self-running ~16.8 s loop on a virtual clock.

   Narrative: the selected repository is a block-city of modules (years of
   domain decisions, warm paper lamps, health ticks on the streets). A survey
   scan sweeps the city, finds the one dark gap, outlines it in rust, and all
   focused work happens ONLY there — scaffold strokes, sparks, the new block
   growing into place — while every preserved block stays lit. The new block
   seats, takes the city's rhythm, and keeps a thin rust "distinguishable
   contribution" outline. Rust is reserved for the delta; everything else is
   ink + paper. Type floor 13 px. */

.pm-delta-code.pv4-live { display: flex; }
.pm-delta-code.pv4-live > :not(.pv4-stage) { display: none; }

.pv4-stage {
    flex: 1;
    min-width: 0;
    position: relative;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    font-family: var(--pm-mono, 'Geist Mono', monospace);
}

/* ---------- header: codebase label + live status readout ---------- */

.pv4-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    min-width: 0;
    padding: .85rem 1rem;
    border-bottom: 1px solid var(--pm-line-dark, rgba(244,241,233,.16));
}

.pv4-hlabel {
    color: var(--pm-rust-light, #f09a78);
    font-size: .8125rem;
    font-weight: 600;
    letter-spacing: .07em;
    white-space: nowrap;
}

.pv4-status {
    display: flex;
    align-items: center;
    gap: .5rem;
    min-width: 0;
}

.pv4-stlamp {
    flex: 0 0 auto;
    width: .4rem;
    height: .4rem;
    border-radius: 50%;
    background: var(--pm-paper, #f4f1e9);
    box-shadow: 0 0 8px rgba(244, 241, 233, .35);
    transition: background-color .3s ease, box-shadow .3s ease;
}

.pv4-status.pv4-strust .pv4-stlamp {
    background: var(--pm-rust-light, #f09a78);
    box-shadow: 0 0 8px rgba(189, 67, 33, .55);
}

.pv4-sttext {
    color: #c8c2b7;
    font-size: .8125rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---------- the city ---------- */

.pv4-city {
    position: relative;
    min-width: 0;
    padding: 1rem;
    overflow: hidden;
    background-image: radial-gradient(rgba(244, 241, 233, .09) .8px, transparent .8px);
    background-size: 1.5rem 1.5rem;
}

.pv4-wires {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    pointer-events: none;
}

.pv4-street {
    fill: none;
    stroke: rgba(244, 241, 233, .10);
    stroke-width: 1;
}

.pv4-hdot { fill: var(--pm-paper, #f4f1e9); }

.pv4-scafline {
    fill: none;
    stroke: var(--pm-rust-light, #f09a78);
    stroke-width: 1.5;
    stroke-linecap: square;
}

.pv4-spark { fill: var(--pm-rust-light, #f09a78); }

.pv4-grid {
    position: relative;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-auto-rows: minmax(0, 1fr);
    gap: .65rem;
    height: 100%;
}

/* ---------- preserved blocks ---------- */

.pv4-blk {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: .2rem;
    min-height: 3.1rem;
    min-width: 0;
    padding: .5rem .6rem;
    border: 1px solid var(--pm-line-dark, rgba(244,241,233,.16));
    background: #24231f;
    /* keep long module names from propagating min-content width upward */
    contain: inline-size;
    transition: opacity .5s ease, box-shadow .22s ease, border-color .22s ease, filter .26s ease;
}

.pv4-s2 { grid-column: span 2; }

.pv4-bname {
    color: #e9e5da;
    font-size: .8125rem;
    font-weight: 600;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pv4-byr {
    color: #c8c2b7;
    font-size: .8125rem;
    font-weight: 500;
    line-height: 1;
}

.pv4-lamp {
    position: absolute;
    right: .55rem;
    bottom: .55rem;
    width: .35rem;
    height: .35rem;
    border-radius: 50%;
    background: var(--pm-paper, #f4f1e9);
    opacity: .55;
}

.pv4-ok {
    position: absolute;
    right: .5rem;
    top: .38rem;
    color: #e9e5da;
    font-size: .8125rem;
    font-weight: 600;
    line-height: 1;
    opacity: 0;
    transition: opacity .5s ease;
}

.pv4-blk.pv4-seen .pv4-ok { opacity: .38; }

.pv4-blk.pv4-seenflash { border-color: rgba(244, 241, 233, .55); }
.pv4-blk.pv4-seenflash .pv4-ok { opacity: .95; transition: opacity .1s ease; }

/* quiet health tick */
.pv4-blk.pv4-tick { box-shadow: 0 0 0 1px rgba(244, 241, 233, .16); }

/* survey focus: the city dims a breath but stays lit — preserved, untouched */
.pv4-stage.pv4-focus .pv4-blk { opacity: .78; }

/* rhythm ripple when the new block seats */
.pv4-blk.pv4-wave {
    box-shadow: 0 0 0 1px rgba(244, 241, 233, .4);
    filter: brightness(1.28);
    transition: box-shadow .12s ease, filter .12s ease, opacity .5s ease;
}

/* ---------- the gap → the delta ---------- */

.pv4-gap {
    position: relative;
    min-height: 3.1rem;
    min-width: 0;
    border: 1px dashed rgba(244, 241, 233, .15);
    background: rgba(12, 12, 11, .45);
    transition: border-color .45s ease, box-shadow .45s ease;
}

.pv4-gaplabel {
    position: absolute;
    top: .42rem;
    left: .55rem;
    color: var(--pm-rust-light, #f09a78);
    font-size: .8125rem;
    font-weight: 600;
    letter-spacing: .05em;
    line-height: 1;
    opacity: 0;
    transition: opacity .4s ease;
}

.pv4-gap.pv4-found {
    border-color: var(--pm-rust, #bd4321);
    box-shadow: 0 0 0 1px rgba(189, 67, 33, .32), inset 0 0 18px rgba(189, 67, 33, .16);
}

.pv4-gap.pv4-found .pv4-gaplabel { opacity: 1; }
.pv4-gap.pv4-forge .pv4-gaplabel { opacity: .45; }
.pv4-gap.pv4-nbseat .pv4-gaplabel { opacity: 0; }

/* once the block seats, the cell's own outline turns solid rust */
.pv4-gap.pv4-nbseat {
    border: 1px solid var(--pm-rust, #bd4321);
    box-shadow: none;
}

.pv4-newblk {
    position: absolute;
    inset: .3rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: .15rem;
    min-width: 0;
    overflow: hidden;
    padding: .3rem .55rem .35rem;
    border: 1px dashed var(--pm-rust-light, #f09a78);
    background: transparent;
    opacity: 0;
    transition: opacity .4s ease, background-color .4s ease, border-color .4s ease, box-shadow .4s ease;
}

.pv4-gap.pv4-nbwire .pv4-newblk { opacity: 1; }

.pv4-gap.pv4-nbseat .pv4-newblk {
    opacity: 1;
    border: 1px solid var(--pm-rust, #bd4321);
    background: #2a221d;
    /* the thin "distinguishable contribution" outline that remains */
    box-shadow: 0 0 0 1px rgba(189, 67, 33, .3);
}

.pv4-newblk .pv4-bname { color: #f0ece1; }

.pv4-ntag {
    align-self: flex-start;
    padding: .05rem .3rem;
    color: var(--pm-rust-light, #f09a78);
    border: 1px solid var(--pm-rust-dark, #8c3018);
    font-size: .8125rem;
    font-weight: 600;
    line-height: 1.2;
    transition: background-color .4s ease, color .4s ease;
}

.pv4-gap.pv4-nbseat .pv4-ntag {
    background: var(--pm-rust, #bd4321);
    border-color: var(--pm-rust, #bd4321);
    color: var(--pm-paper, #f4f1e9);
}

.pv4-newblk .pv4-lamp { opacity: 0; }

/* short gap cells (single-column pages, compact city): tag + name in a row */
.pv4-stage.pv4-nbrow .pv4-newblk {
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    gap: .5rem;
    padding: .2rem .5rem;
}

.pv4-stage.pv4-nbrow .pv4-ntag { align-self: center; }

/* ---------- survey scan ---------- */

.pv4-scan {
    position: absolute;
    top: .4rem;
    bottom: .4rem;
    left: 0;
    width: 1px;
    opacity: 0;
    pointer-events: none;
}

.pv4-scanline {
    position: absolute;
    inset: 0;
    width: 1px;
    background: linear-gradient(to bottom,
        rgba(244, 241, 233, 0),
        rgba(244, 241, 233, .85) 16%,
        rgba(244, 241, 233, .85) 84%,
        rgba(244, 241, 233, 0));
    box-shadow: 0 0 12px rgba(244, 241, 233, .3);
}

.pv4-scantag {
    position: absolute;
    top: 0;
    left: .45rem;
    padding: .06rem .38rem;
    border: 1px solid var(--pm-line-dark, rgba(244,241,233,.16));
    background: var(--pm-ink, #191917);
    color: #c8c2b7;
    font-size: .8125rem;
    font-weight: 600;
    letter-spacing: .06em;
    line-height: 1.4;
    white-space: nowrap;
}

.pv4-scan.pv4-scanflip .pv4-scantag { left: auto; right: .45rem; }

.pv4-scan.pv4-scanlock .pv4-scanline {
    background: linear-gradient(to bottom,
        rgba(240, 154, 120, 0),
        rgba(240, 154, 120, .95) 16%,
        rgba(240, 154, 120, .95) 84%,
        rgba(240, 154, 120, 0));
    box-shadow: 0 0 14px rgba(189, 67, 33, .55);
}

.pv4-scan.pv4-scanlock .pv4-scantag {
    color: var(--pm-rust-light, #f09a78);
    border-color: var(--pm-rust-dark, #8c3018);
}

/* ---------- target brackets around the gap ---------- */

.pv4-target {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s ease;
}

.pv4-target i {
    position: absolute;
    width: .7rem;
    height: .7rem;
    border: 2px solid var(--pm-rust-light, #f09a78);
    transition: transform .45s cubic-bezier(.2, .8, .2, 1);
}

.pv4-target i:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; transform: translate(-9px, -9px); }
.pv4-target i:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; transform: translate(9px, -9px); }
.pv4-target i:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; transform: translate(-9px, 9px); }
.pv4-target i:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; transform: translate(9px, 9px); }

.pv4-target.pv4-targeton { opacity: 1; }
.pv4-target.pv4-targeton i { transform: translate(0, 0); }

/* ---------- loop veil (masks the cycle reset) ---------- */

.pv4-veil {
    position: absolute;
    inset: 0;
    background: var(--pm-ink, #191917);
    opacity: 0;
    pointer-events: none;
}

/* ---------- delta line: the language of the argument ---------- */

.pv4-dline {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: .35rem .6rem;
    min-width: 0;
    padding: .72rem 1rem;
    border-top: 1px solid var(--pm-line-dark, rgba(244,241,233,.16));
}

.pv4-dmiss {
    color: var(--pm-rust-light, #f09a78);
    font-size: .8125rem;
    font-weight: 600;
    letter-spacing: .05em;
    white-space: nowrap;
    transition: text-shadow .35s ease;
}

.pv4-darrow {
    color: #c8c2b7;
    font-size: .8125rem;
    font-weight: 500;
    font-style: normal;
}

.pv4-dfocus {
    color: var(--pm-paper, #f4f1e9);
    font-family: var(--pm-sans, 'Geist', sans-serif);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -.01em;
    line-height: 1;
    white-space: nowrap;
}

.pv4-dnote {
    margin-left: auto;
    min-width: 0;
    color: #c8c2b7;
    font-size: .8125rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pv4-stage.pv4-dhot .pv4-dmiss { text-shadow: 0 0 10px rgba(240, 154, 120, .5); }

/* ---------- preserved footer ---------- */

.pv4-pres {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: .35rem 1rem;
    min-width: 0;
    padding: .72rem 1rem .85rem;
    border-top: 1px solid var(--pm-line-dark, rgba(244,241,233,.16));
}

.pv4-plabel {
    color: var(--pm-paper, #f4f1e9);
    font-size: .8125rem;
    font-weight: 600;
    letter-spacing: .06em;
    white-space: nowrap;
}

.pv4-pcount {
    color: #c8c2b7;
    font-size: .8125rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.pv4-pnote {
    margin-left: auto;
    min-width: 0;
    color: #c9c3b8;
    font-size: .8125rem;
    font-weight: 500;
    font-style: normal;
    text-align: right;
}

/* ---------- compact vertical composition (< 460 px) ---------- */

.pv4-stage.pv4-compact { grid-template-rows: auto auto auto auto; }

.pv4-stage.pv4-compact .pv4-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: minmax(3.2rem, auto);
    height: auto;
}

.pv4-stage.pv4-compact .pv4-head { flex-wrap: wrap; row-gap: .3rem; }
.pv4-stage.pv4-compact .pv4-dline { flex-wrap: wrap; }
.pv4-stage.pv4-compact .pv4-dnote { margin-left: 0; flex-basis: 100%; }
.pv4-stage.pv4-compact .pv4-pnote { margin-left: 0; text-align: left; }

/* ---------- reduced motion: instant swaps, no transitions ---------- */

@media (prefers-reduced-motion: reduce) {
    .pv4-stage, .pv4-stage * { transition: none !important; animation: none !important; }
}

/* ---------- forced colors: fall back to the original static panel ---------- */

@media (forced-colors: active) {
    .pm-delta-code.pv4-live { display: grid; }
    .pm-delta-code.pv4-live > .pv4-stage { display: none; }
    /* explicit display values (not `revert`, which would roll back past
       primae-v2.css's own grid rules and collapse the static panel) */
    .pm-delta-code.pv4-live > .pm-code-label { display: block; }
    .pm-delta-code.pv4-live > .pm-code-map,
    .pm-delta-code.pv4-live > .pm-code-delta,
    .pm-delta-code.pv4-live > .pm-code-preserved { display: grid; }
}
