/* =========================================================================
   .er-relation — the shared relationship primitive.

   One styling vocabulary for how Eternal Roam presents relationships between
   saints, places, relics, routes, and cities. Scoped entirely under .er-relation
   and built on the global --er-* tokens, so it resolves the same on a saint-v1
   page, a place-v1 page, or anywhere else it is later adopted.

   Modes:  --cards (image-led)  --rows (compact)  --list (text-only)
   Density: --dominant / --compact realise the page demotion rule.

   No grey placeholder slot exists anywhere in this file: a card without an image
   falls back to a textured, inked monogram plate (--plate--monogram), and a set
   with no image is rendered as --list by the PHP primitive before it reaches here.
   ========================================================================= */

.er-relation {
    /* Local echoes of the page-scoped tokens the bespoke modules used, so the
       primitive carries its own quiet metadata treatment in any context. */
    --erl-eye: 0.14em;
    --erl-fs-meta: 0.75rem;

    list-style: none;
    margin: 0;
    padding: 0;
}

.er-relation__item {
    list-style: none;
    min-width: 0;
}

.er-relation__link {
    color: inherit;
    text-decoration: none;
    min-width: 0;
}

.er-relation__kicker {
    display: block;
    font-family: var(--er-mono);
    font-size: var(--erl-fs-meta);
    letter-spacing: var(--erl-eye);
    text-transform: uppercase;
    color: var(--er-clay-deep);
}

.er-relation__title {
    margin: 0;
    font-family: var(--er-serif);
    font-weight: 500;
    line-height: 1.18;
    color: var(--er-ink);
}

.er-relation__type {
    display: block;
    margin-top: 4px;
    font-family: var(--er-mono);
    font-size: var(--erl-fs-meta);
    letter-spacing: var(--erl-eye);
    text-transform: uppercase;
    color: var(--er-ink-3);
}

.er-relation__note {
    display: block;
    font-family: var(--er-sans);
    font-size: var(--er-fs-small);
    line-height: var(--er-lh-body);
    color: var(--er-ink-2);
    max-width: 60ch;
}

.er-relation__meta {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.er-relation__meta-row {
    display: grid;
    grid-template-columns: 4.5rem minmax(0, 1fr);
    gap: 12px;
    align-items: baseline;
}

.er-relation__meta-label {
    font-family: var(--er-mono);
    font-size: var(--erl-fs-meta);
    letter-spacing: var(--erl-eye);
    text-transform: uppercase;
    color: var(--er-ink-4);
}

.er-relation__meta-value {
    font-family: var(--er-sans);
    font-size: 0.84rem;
    line-height: 1.35;
    color: var(--er-ink-2);
}

.er-relation__arrow {
    flex: 0 0 auto;
    font-family: var(--er-serif);
    font-size: 20px;
    line-height: 1;
    color: var(--er-ink-3);
    transition: color 0.2s ease;
}

/* ---------- Cards mode: image-led ------------------------------------- */

.er-relation--cards {
    display: grid;
    gap: clamp(20px, 2.4vw, 32px);
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.er-relation--cards.er-relation--n1 { grid-template-columns: minmax(0, 560px); }
.er-relation--cards.er-relation--n2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.er-relation--cards.er-relation--n3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.er-relation--cards.er-relation--n4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.er-relation--cards .er-relation__item {
    background: var(--er-paper);
    border: 1px solid var(--er-rule);
    border-radius: var(--er-r-md);
    overflow: hidden;
}

.er-relation--cards .er-relation__link {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.er-relation__plate {
    display: grid;
    place-items: center;
    overflow: hidden;
    aspect-ratio: 4 / 5;
    background:
        repeating-linear-gradient(135deg, rgba(31, 27, 20, 0.05) 0 1px, transparent 1px 10px),
        linear-gradient(180deg, #d8d3c5 0%, #aaa48f 100%);
}

.er-relation__plate img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

/* The imageless fallback: an inked, textured plate with the saint or place
   initial. Deliberately not a grey box. */
.er-relation__plate--monogram {
    background:
        repeating-linear-gradient(135deg, rgba(255, 250, 240, 0.05) 0 1px, transparent 1px 10px),
        linear-gradient(160deg, var(--er-ink-2) 0%, var(--er-ink) 100%);
}

.er-relation__monogram {
    font-family: var(--er-serif);
    font-size: clamp(2.5rem, 4vw, 3.75rem);
    line-height: 1;
    color: rgba(251, 247, 236, 0.92);
}

.er-relation--cards .er-relation__body {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: clamp(18px, 1.6vw, 24px);
    flex: 1 1 auto;
    min-width: 0;
}

.er-relation--cards .er-relation__title {
    font-size: var(--er-fs-h3);
}

.er-relation--cards .er-relation__meta {
    margin: 0;
    padding: 12px clamp(18px, 1.6vw, 24px) clamp(18px, 1.6vw, 24px);
    border-top: 1px solid var(--er-rule-soft);
}

a.er-relation__link:hover .er-relation__title,
a.er-relation__link:focus-visible .er-relation__title {
    color: var(--er-clay-deep);
}

/* Compact density tightens the dominant card treatment into something quieter
   when another module on the page already carries the visual weight. */
.er-relation--cards.er-relation--compact { gap: 16px; }
.er-relation--cards.er-relation--compact .er-relation__plate { aspect-ratio: 16 / 10; }
.er-relation--cards.er-relation--compact .er-relation__title { font-size: 1.125rem; }

/* ---------- Rows mode: compact text rows ------------------------------ */

.er-relation--rows {
    display: flex;
    flex-direction: column;
}

.er-relation--rows .er-relation__item {
    border-top: 1px solid var(--er-rule);
}

.er-relation--rows .er-relation__item:last-child {
    border-bottom: 1px solid var(--er-rule);
}

.er-relation--rows .er-relation__link {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 24px;
    align-items: center;
    padding: 22px 4px;
}

.er-relation--rows .er-relation__title {
    font-size: 1.375rem;
}

.er-relation--rows .er-relation__meta {
    text-align: right;
}

.er-relation--rows .er-relation__meta-row {
    display: block;
}

.er-relation--rows .er-relation__meta-label {
    margin-right: 6px;
}

a.er-relation--rows .er-relation__link:hover .er-relation__arrow,
a.er-relation--rows .er-relation__link:focus-visible .er-relation__arrow,
.er-relation--rows a.er-relation__link:hover .er-relation__arrow,
.er-relation--rows a.er-relation__link:focus-visible .er-relation__arrow {
    color: var(--er-clay-deep);
}

/* ---------- List mode: text-only -------------------------------------- */

.er-relation--list {
    display: flex;
    flex-direction: column;
}

.er-relation--list .er-relation__item {
    border-top: 1px solid var(--er-rule-soft);
}

.er-relation--list .er-relation__item:last-child {
    border-bottom: 1px solid var(--er-rule-soft);
}

.er-relation--list .er-relation__link {
    display: flex;
    align-items: baseline;
    gap: 16px;
    padding: 14px 4px;
}

.er-relation--list .er-relation__body {
    display: flex;
    flex: 1 1 auto;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 14px;
    min-width: 0;
}

.er-relation--list .er-relation__title {
    font-size: 1.125rem;
}

.er-relation--list .er-relation__note {
    color: var(--er-ink-3);
}

.er-relation--list .er-relation__meta {
    flex-direction: row;
    gap: 14px;
}

/* ---------- Responsive ------------------------------------------------ */

@media (max-width: 640px) {
    .er-relation--cards,
    .er-relation--cards.er-relation--n1,
    .er-relation--cards.er-relation--n2,
    .er-relation--cards.er-relation--n3,
    .er-relation--cards.er-relation--n4 {
        grid-template-columns: minmax(0, 1fr);
    }

    .er-relation--rows .er-relation__link {
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 12px 16px;
    }

    .er-relation--rows .er-relation__meta {
        grid-column: 1 / -1;
        text-align: left;
    }

    .er-relation--rows .er-relation__title {
        font-size: 1.2rem;
    }
}
