/**
 * Score card — the product's central output surface.
 *
 * Composite-led single card: composite hero → numeric scale → one-line
 * trait rows → shared detail panel. Progressive disclosure via click on
 * any row (composite included); the panel swaps content rather than
 * expanding inline.
 *
 * Governed by ADR 021 §7. Tier colors pull from the global palette
 * (`--tier-*` tokens in base.html); this file carries no hex values
 * except the few rgba tints that bake tier hues into zone backgrounds.
 *
 * Selectors use the `sc-` prefix so this component does not collide
 * with anything else on a host page.
 */

/* ---- Outer wrapper (multiple cards, e.g. compare view) --------
   Acts as a size container so the card reflows based on its own
   width, not the viewport. That way a card rendered in a narrow
   column (a docs figure, a sidebar, a compare grid) collapses to
   the two-row layout even on a wide screen. */
.sc-cards {
    display: flex; flex-direction: column; gap: 1.6em;
    container: sc-cards / inline-size;
}

/* ---- Card chassis --------------------------------------------- */
.sc-card {
    background: var(--bg);
    border: 1px solid var(--rule);
    border-left: 4px solid var(--emphasis);
    /* No vertical padding on the card; children own the top/bottom edges so
       an active tint extends cleanly up to the card's top edge (composite)
       and down to the detail-area divider (last row). */
    padding: 0 1.8rem;
    position: relative;
    font-family: var(--font-body);
    /* Subtle full-width separators. */
    --sc-rule: rgba(20, 17, 12, 0.06);
    /* Warm-neutral active row tint — stays off-cobalt so it never competes
       with the brand-mark color; cobalt is reserved for the triangle marker. */
    --sc-active-bg: rgba(20, 17, 12, 0.05);
}

/* ---- Result header (optional) --------------------------------- */
.sc-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 0.6em;
}
.sc-title {
    font-family: var(--font-mono);
    font-size: 0.72em; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.14em;
    color: var(--dim);
}
.sc-clear {
    background: none; border: none; color: var(--dim);
    font-family: var(--font-mono); font-size: 0.72em;
    letter-spacing: 0.08em; text-transform: uppercase;
    cursor: pointer; padding: 0.2em 0.4em;
    transition: color 0.15s;
}
.sc-clear:hover { color: var(--fg); }

/* ---- Composite hero ------------------------------------------- */
.sc-composite {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 1.4em;
    align-items: center;
    /* Full-width active background; content stays inset. No divider below —
       composite flows directly into the scale legend and first row. */
    margin: 0 -1.8rem;
    padding: 1em 1.8rem 1.1em;
    position: relative;
    cursor: pointer;
    transition: background 0.12s;
}
.sc-composite.active { background: var(--sc-active-bg); }
.sc-composite.active::after {
    content: "";
    position: absolute;
    left: 0.4em; top: 50%;
    transform: translateY(-50%);
    width: 0; height: 0;
    border-left: 6px solid var(--emphasis);
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
}
.sc-comp-left {
    display: flex; flex-direction: column; gap: 0.15em;
    min-width: 0;
}
.sc-comp-label {
    font-family: var(--font-mono);
    font-size: 0.68em;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--dim);
}
.sc-comp-val {
    font-family: var(--font-display);
    font-size: 3.6em;
    font-weight: 700;
    color: var(--fg);
    letter-spacing: -0.035em;
    line-height: 0.95;
}
.sc-comp-mid {
    min-width: 0;
    display: flex; flex-direction: column; gap: 0.4em;
}
/* Composite track: plain axis, no tier zones, but carries tick marks at
   the computed composite breaks (--b1/--b2/--b3 set inline by the
   renderer). The marker shows where the composite sits; the ticks show
   where it would need to reach to clear Developing / Solid / Strong. */
.sc-comp-track {
    position: relative;
    height: 8px;
    background: var(--bg-deep);
    border: 1px solid var(--rule);
}
.sc-comp-track::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(to right, transparent calc(var(--b1, 50%) - 0.3%), var(--rule) calc(var(--b1, 50%) - 0.3%), var(--rule) calc(var(--b1, 50%) + 0.3%), transparent calc(var(--b1, 50%) + 0.3%)),
        linear-gradient(to right, transparent calc(var(--b2, 65%) - 0.3%), var(--rule) calc(var(--b2, 65%) - 0.3%), var(--rule) calc(var(--b2, 65%) + 0.3%), transparent calc(var(--b2, 65%) + 0.3%)),
        linear-gradient(to right, transparent calc(var(--b3, 80%) - 0.3%), var(--rule) calc(var(--b3, 80%) - 0.3%), var(--rule) calc(var(--b3, 80%) + 0.3%), transparent calc(var(--b3, 80%) + 0.3%));
    opacity: 0.7;
    pointer-events: none;
}
/* Composite tier + headroom readout — sits under the composite track.
   Tier label uses composite-breaks-derived class; headroom note is muted. */
.sc-comp-tier {
    font-family: var(--font-mono);
    font-size: 0.78em;
    letter-spacing: 0.04em;
}
.sc-comp-tier .sc-comp-tier-label {
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.14em;
}
.sc-comp-tier .sc-comp-tier-label.tier-hi   { color: var(--tier-hi); }
.sc-comp-tier .sc-comp-tier-label.tier-good { color: var(--tier-good); }
.sc-comp-tier .sc-comp-tier-label.tier-mid  { color: var(--tier-mid); }
.sc-comp-tier .sc-comp-tier-label.tier-weak { color: var(--tier-weak); }
.sc-comp-tier .sc-comp-tier-head { color: var(--dim); margin-left: 0.5em; }
.sc-comp-tier .sc-comp-tier-head .tier-hi   { color: var(--tier-hi); }
.sc-comp-tier .sc-comp-tier-head .tier-good { color: var(--tier-good); }
.sc-comp-tier .sc-comp-tier-head .tier-mid  { color: var(--tier-mid); }
.sc-comp-tier .sc-comp-tier-head .tier-weak { color: var(--tier-weak); }

/* Composite-breaks readout in the detail panel — shows the aggregated
   thresholds so readers can see where the scale ticks come from. */
.sc-detail .sc-comp-breaks {
    font-family: var(--font-mono);
    font-size: 0.78em;
    color: var(--dim);
    letter-spacing: 0.02em;
    margin-top: 0.3em;
}
.sc-comp-conf {
    font-family: var(--font-mono);
    color: var(--dim);
    letter-spacing: -1px;
    font-size: 1.05em;
    align-self: start;
    cursor: help;
}

/* ---- Shared marker (track tick + diamond foot) ---------------- */
.sc-marker {
    position: absolute;
    top: -4px; bottom: -4px;
    width: 2px;
    z-index: 2;
}
.sc-marker.tier-hi   { background: var(--tier-hi); }
.sc-marker.tier-good { background: var(--tier-good); }
.sc-marker.tier-mid  { background: var(--tier-mid); }
.sc-marker.tier-weak { background: var(--tier-weak); }
.sc-marker.ink       { background: var(--emphasis); }
.sc-marker::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translate(-50%, 1px) rotate(45deg);
    width: 6px; height: 6px;
    background: inherit;
}

/* ---- Numeric scale legend ------------------------------------- */
/* Uses the SAME grid template as trait rows so tick marks at 50/65/80
   align exactly with the score markers in each row's track. */
.sc-scale {
    display: grid;
    grid-template-columns: 9.5rem 1fr 2.8rem 6.5rem 2rem;
    gap: 0.9rem;
    /* Zero vertical margin; vertical breathing room is absorbed by
       composite's padding-bottom above and row padding below, so there is
       no neutral gap between an active composite/row and this legend. */
    margin: 0 -1.8rem;
    padding: 0.35em 1.8rem;
    font-family: var(--font-mono);
    font-size: 0.62em;
    color: var(--dim);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    opacity: 0.7;
}
.sc-scale-axis {
    grid-column: 2;
    position: relative;
    height: 1em;
}
.sc-scale-axis .sc-tick {
    position: absolute;
    top: 0;
    transform: translateX(-50%);
}
.sc-scale-axis .sc-tick.pin-left  { transform: translateX(0); }
.sc-scale-axis .sc-tick.pin-right { transform: translateX(-100%); }

/* ---- Trait rows ----------------------------------------------- */
.sc-rows-wrap { position: relative; }
.sc-row {
    display: grid;
    grid-template-columns: 9.5rem 1fr 2.8rem 6.5rem 2rem;
    gap: 0.9rem;
    align-items: center;
    margin: 0 -1.8rem;
    padding: 0.5em 1.8rem;
    font-family: var(--font-mono);
    font-size: 0.88em;
    border-bottom: 1px solid var(--sc-rule);
    position: relative;
    cursor: pointer;
    transition: background 0.12s;
}
.sc-row:last-of-type { border-bottom: none; }
.sc-row.active { background: var(--sc-active-bg); }
.sc-row.active::after {
    content: "";
    position: absolute;
    left: 0.4em; top: 50%;
    transform: translateY(-50%);
    width: 0; height: 0;
    border-left: 6px solid var(--emphasis);
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
}
/* Belt-and-suspenders: keep cell widths fixed so column 4's tier label
   never shoves the scale out of alignment when it says "DEVELOPING". */
.sc-row > * { min-width: 0; }

.sc-name {
    color: var(--fg);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
}
/* Per-trait track zones. The renderer sets --b1/--b2/--b3 inline from each
   trait's actual detail.breaks (developing/solid/strong). Defaults match the
   shared scale legend (50/65/80) when breaks are missing. */
.sc-track {
    position: relative;
    height: 10px;
    --b1: 50%;
    --b2: 65%;
    --b3: 80%;
    background:
        linear-gradient(to right,
            rgba(154, 145, 128, 0.16) 0 var(--b1),
            rgba(193, 115, 56, 0.10) var(--b1) var(--b2),
            rgba(46, 107, 66, 0.14) var(--b2) var(--b3),
            rgba(30, 58, 138, 0.22) var(--b3) 100%);
    border: 1px solid var(--rule);
}
.sc-track::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(to right, transparent calc(var(--b1) - 0.3%), var(--rule) calc(var(--b1) - 0.3%), var(--rule) calc(var(--b1) + 0.3%), transparent calc(var(--b1) + 0.3%)),
        linear-gradient(to right, transparent calc(var(--b2) - 0.3%), var(--rule) calc(var(--b2) - 0.3%), var(--rule) calc(var(--b2) + 0.3%), transparent calc(var(--b2) + 0.3%)),
        linear-gradient(to right, transparent calc(var(--b3) - 0.3%), var(--rule) calc(var(--b3) - 0.3%), var(--rule) calc(var(--b3) + 0.3%), transparent calc(var(--b3) + 0.3%));
    opacity: 0.6;
    pointer-events: none;
}
.sc-val {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 1.25em;
    font-weight: 700;
    letter-spacing: -0.01em;
    text-align: right;
    line-height: 1;
}
.sc-val.tier-hi   { color: var(--tier-hi); }
.sc-val.tier-good { color: var(--tier-good); }
.sc-val.tier-mid  { color: var(--tier-mid); }
.sc-val.tier-weak { color: var(--tier-weak); }

.sc-tier {
    font-family: var(--font-mono);
    font-size: 0.7em;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 700;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sc-tier.tier-hi   { color: var(--tier-hi); }
.sc-tier.tier-good { color: var(--tier-good); }
.sc-tier.tier-mid  { color: var(--tier-mid); }
.sc-tier.tier-weak { color: var(--tier-weak); }

.sc-conf {
    font-family: var(--font-mono);
    color: var(--dim);
    letter-spacing: -1px;
    font-size: 0.95em;
    text-align: right;
    cursor: help;
}

/* ---- Shared detail panel -------------------------------------- */
.sc-detail-area {
    /* No margin-top — detail-area sits flush against the last row's
       bottom edge so an active last-row tint touches the divider with
       no neutral gap in between. The border-top is the "kept" divider. */
    margin: 0 -1.8rem;
    padding: 0.9em 1.8rem 1em;
    border-top: 1px solid var(--sc-rule);
    min-height: 6.6em;
    position: relative;
}
/* Persistent hint glyph — links to the score-card docs. Bottom-right so
   it doesn't collide with the polarity labels at the top of trait details.
   Square chassis per ADR 021 §4a. Selector is doubled-up (.sc-detail-area
   .sc-info-hint) to beat `.pane-content a`, which otherwise forces the
   bottom border to transparent and repaints it accent-colored on hover. */
.sc-detail-area .sc-info-hint {
    position: absolute;
    bottom: 0.6em;
    right: 0.9em;
    width: 1.35em;
    height: 1.35em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 0.72em;
    font-weight: 700;
    color: var(--dim);
    background: var(--bg);
    border: 1px solid var(--rule);
    text-decoration: none;
    user-select: none;
    opacity: 0.6;
    transition: opacity 0.15s, color 0.15s, border-color 0.15s;
}
.sc-detail-area .sc-info-hint:hover {
    opacity: 1;
    color: var(--fg);
    border-color: var(--border);
}
.sc-detail {
    display: none;
    font-family: var(--font-body);
    font-size: 0.92em;
    color: var(--fg-soft);
    line-height: 1.55;
}
.sc-detail.active { display: block; }
.sc-detail .sc-polarity {
    display: flex;
    justify-content: space-between;
    font-family: var(--font-mono);
    font-size: 0.72em;
    color: var(--dim);
    letter-spacing: 0.08em;
    margin-bottom: 0.45em;
    text-transform: uppercase;
}
.sc-detail .sc-polarity .sc-neg::before { content: "\25C2 "; opacity: 0.7; margin-right: 0.2em; }
.sc-detail .sc-polarity .sc-pos::after  { content: " \25B8"; opacity: 0.7; margin-left: 0.2em; }
.sc-detail .sc-desc {
    font-family: var(--font-math);
    font-style: italic;
    font-size: 1em;
    color: var(--fg-soft);
    line-height: 1.55;
    margin-bottom: 0.45em;
}
.sc-detail .sc-meta {
    font-family: var(--font-mono);
    font-size: 0.78em;
    color: var(--dim);
    letter-spacing: 0.02em;
}
.sc-detail .sc-meta .sc-h-label {
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.9em;
    color: var(--dim);
    opacity: 0.7;
    margin-right: 0.5em;
}
.sc-detail .sc-meta .tier-hi   { color: var(--tier-hi); }
.sc-detail .sc-meta .tier-good { color: var(--tier-good); }
.sc-detail .sc-meta .tier-mid  { color: var(--tier-mid); }
.sc-detail .sc-meta .tier-weak { color: var(--tier-weak); }

/* Discovery signal — only present for traits found by PCA/LDA discovery */
.sc-detail .sc-disc {
    font-family: var(--font-mono);
    font-size: 0.78em;
    color: var(--fg-soft);
    letter-spacing: 0.02em;
    margin-bottom: 0.35em;
    cursor: help;
}
.sc-detail .sc-disc .sc-h-label {
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.9em;
    color: var(--dim);
    opacity: 0.7;
    margin-right: 0.5em;
}
.sc-detail .sc-disc-value {
    color: var(--emphasis);
    font-variant-numeric: tabular-nums;
}
.sc-detail .sc-disc-value .dim {
    color: var(--dim);
    opacity: 0.7;
    font-weight: 400;
}

/* ---- Mobile: two-row trait layout, full-width bar --------------
   The 5-column row collapses on narrow viewports. Top row holds
   metadata (name + score + tier + conf); bar spans the full width
   below. No information is hidden; the bar just gets a row of its
   own when there's no room to share. */
@container sc-cards (max-width: 640px) {
    .sc-card { padding: 0 1em; }
    .sc-composite {
        grid-template-columns: 1fr auto;
        gap: 0.6em 1em;
        margin: 0 -1em;
        padding: 0.8em 1em 1em;
    }
    .sc-composite .sc-comp-mid { grid-column: 1 / -1; }
    .sc-comp-conf { align-self: start; }

    .sc-scale, .sc-row {
        margin: 0 -1em;
        padding: 0.55em 1em;
        grid-template-columns: 1fr auto auto auto;
        grid-template-areas:
            "name val tier conf"
            "bar  bar bar  bar";
        column-gap: 0.6em;
        row-gap: 0.4em;
    }
    .sc-name  { grid-area: name; font-size: 0.92em; }
    .sc-track { grid-area: bar; height: 12px; }
    .sc-val   { grid-area: val; }
    .sc-tier  { grid-area: tier; }
    .sc-conf  { grid-area: conf; }

    .sc-scale {
        padding-top: 0.3em;
        padding-bottom: 0.1em;
        font-size: 0.6em;
    }
    .sc-scale-axis {
        grid-area: bar;
        grid-column: auto;
    }
    .sc-scale > span:empty { display: none; }

    .sc-detail-area {
        margin: 0 -1em;
        padding: 0.7em 1em 0.7em;
    }

    .sc-row.active::after,
    .sc-composite.active::after {
        left: 0.05em;
        border-left-width: 5px;
    }
}

/* ---- Hero-mode modifier ---------------------------------------
   The hero uses an ambient, non-interactive, visually quiet card.
   Strips everything that is redundant at ambient-viewing speed:
   - no chassis border, surface, or left-rim (the hero carries its
     own visual register)
   - no zone gradients or break ticks in the tracks
   - no per-row tier labels or confidence dots (color + score already
     communicate the tier; ambient cycling doesn't need a second cue)
   - no click affordance
   Rows and composite start hidden; `.visible` fades them in with the
   staggered rhythm the demo is built around. */
.sc-card-hero {
    border: none;
    background: transparent;
    padding: 0;
}
.sc-card-hero .sc-composite,
.sc-card-hero .sc-row {
    cursor: default;
    opacity: 0;
    transform: translateY(3px);
    transition: opacity 0.4s ease-out, transform 0.4s ease-out;
}
.sc-card-hero .sc-composite.visible,
.sc-card-hero .sc-row.visible {
    opacity: 1;
    transform: translateY(0);
}
.sc-card-hero .sc-composite:hover,
.sc-card-hero .sc-row:hover,
.sc-card-hero .sc-composite.active,
.sc-card-hero .sc-row.active {
    background: transparent;
}
.sc-card-hero .sc-composite.active::after,
.sc-card-hero .sc-row.active::after {
    display: none;
}

/* Composite hero — big number, small tier label, simple track. No
   break ticks, no readout line with headroom. The hero communicates
   "here's the verdict"; detail belongs on other surfaces. */
.sc-card-hero .sc-composite {
    grid-template-columns: auto 1fr;
    gap: 1.2em;
    align-items: center;
    margin: 0;
    padding: 0 0 0.9em;
    border-bottom: 1px solid var(--rule);
    margin-bottom: 0.5em;
}
.sc-card-hero .sc-comp-val { font-size: 2.6em; line-height: 0.95; }
.sc-card-hero .sc-comp-label { font-size: 0.64em; }
.sc-card-hero .sc-comp-mid { gap: 0.3em; }
.sc-card-hero .sc-comp-track {
    height: 4px;
    background: var(--rule);
    border: none;
    border-radius: 0;
    overflow: hidden;
}
.sc-card-hero .sc-comp-track::before { display: none; }
.sc-card-hero .sc-comp-tier-head { display: none; }
.sc-card-hero .sc-comp-conf { display: none; }
/* Composite marker in hero mode is also a full fill — same treatment
   as the trait rows so the hero composes from one geometric primitive. */
.sc-card-hero .sc-comp-track .sc-marker {
    position: absolute;
    top: 0; bottom: 0;
    left: 0 !important;
    width: var(--pos, 0%);
    border-radius: 0;
    pointer-events: none;
    background: var(--emphasis);
}
.sc-card-hero .sc-comp-track .sc-marker::after { display: none; }

/* Trait rows — three columns: name · plain track · score. The track
   is a single neutral rail with a tier-colored fill up to the score.
   No zones, no ticks, no tier label, no confidence dots: the score's
   own color is the tier signal at this register.

   Single-line layout: name · bar · val all inline. Explicitly reset
   grid-template-areas (the narrow-card container query above paints a
   2-row "name val / bar" stack, which reads ambiguously — which bar
   belongs to which row?). Here the bar lives between its name and its
   score, the reader's eye travels name → bar (scoring in flight) → val
   (the verdict).

   `!important` on the grid-* props is load-bearing: specificity-wise
   this rule already beats the narrow-card container query above
   (0,2,0 vs 0,1,0), but iOS Safari 16.0–16.1 had a bug where @container
   rules could trump external selectors of higher specificity in
   certain cases. Marking these !important makes the hero single-line
   layout bulletproof across that browser-version window. */
.sc-card-hero .sc-row {
    grid-template-columns: 9.5rem 1fr 2.4rem !important;
    grid-template-areas: "name bar val" !important;
    gap: 1em;
    padding: 0.32em 0;
    margin: 0;
    border-bottom: none;
    font-size: 0.88em;
    align-items: center;
    row-gap: 0;
}
.sc-card-hero .sc-name  { grid-area: name !important; }
.sc-card-hero .sc-track { grid-area: bar !important; height: 4px; }
.sc-card-hero .sc-val   { grid-area: val !important; }
.sc-card-hero .sc-row .sc-tier,
.sc-card-hero .sc-row .sc-conf { display: none; }
.sc-card-hero .sc-track {
    height: 3px;
    background: var(--rule);
    border: none;
    border-radius: 0;
    overflow: hidden;
}
.sc-card-hero .sc-track::before { display: none; }
/* Convert the point-marker into a filled bar: position it at left:0
   with width matching the score. The existing .sc-marker already has
   the score-color utility classes applied by the renderer, so repainting
   it as a fill keeps the hero's palette in sync with tier colors. */
.sc-card-hero .sc-marker {
    position: absolute;
    top: 0; bottom: 0;
    left: 0 !important;
    width: var(--pos, 0%);
    border-radius: 0;
    pointer-events: none;
}
.sc-card-hero .sc-marker::after { display: none; }
.sc-card-hero .sc-val { font-size: 1em; }

/* ---- Status feedback (loading / error) ------------------------ */
.sc-status {
    color: var(--dim);
    font-family: var(--font-mono);
    font-size: 0.85em;
    padding: 0.6em 0;
}
.sc-status.err { color: var(--red); }
@keyframes sc-pulse { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }
.sc-dot1, .sc-dot2, .sc-dot3 { animation: sc-pulse 1.4s infinite; }
.sc-dot2 { animation-delay: 0.2s; }
.sc-dot3 { animation-delay: 0.4s; }
