/*
=========================================================
THE CRIMSON COURT — BLOODLINES
=========================================================

The family tree at /family-tree, drawn by js/bloodlines.js as a pedigree:
one house at a time, spouses joined by a bar, children hanging from it.

Colours come from the :root block in crimson-court.css. Gold frames, crimson
marks the current thing, parchment speaks; a house's colour appears only on
that house's own people (the portrait ring, the children's bus) - never on
a section. House values are set inline as --house by the script, from the
per-house accents recorded in BRANDING.md.
*/

.bloodlines-main {
    --bl-node-w: 150px;
    --bl-node-h: 168px;
    --bl-stage-h: clamp(520px, 72vh, 860px);
}

/* Buttons in the court vocabulary: square, hairline, small caps. */
.bloodlines-main .court-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0 14px;
    height: 36px;
    background: transparent;
    border: 1px solid var(--court-border);
    border-radius: 2px;
    color: var(--parchment);
    font: 600 11px/1 'Cinzel', Georgia, serif;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.bloodlines-main .court-btn:hover,
.bloodlines-main .court-btn:focus-visible {
    background: var(--court-hover);
    border-color: var(--royal-gold);
}

.bloodlines-main .court-btn.is-on {
    border-color: var(--crimson-light);
    color: var(--crimson-light);
}

.bloodlines-main .court-btn i {
    color: var(--royal-gold);
    font-size: 0.85rem;
}

.bloodlines-main .court-btn.is-on i {
    color: inherit;
}

/*
======================
TOOLBAR
======================
*/
.bl-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px 24px;
    margin-bottom: 18px;
}

.bl-houses {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex: 1 1 520px;
}

.bl-house {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 34px;
    padding: 0 12px 0 10px;
    background: var(--court-surface);
    border: 1px solid var(--court-line);
    border-radius: 2px;
    color: var(--court-secondary);
    font: 600 11px/1 'Cinzel', Georgia, serif;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    cursor: pointer;
    transition: border-color 0.18s ease, color 0.18s ease, background 0.18s ease;
}

.bl-house small {
    font: 12px/1 'EB Garamond', Georgia, serif;
    color: var(--court-secondary);
    opacity: 0.8;
}

.bl-house-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--house, var(--royal-gold));
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
}

.bl-house-dot--all {
    background: conic-gradient(#3A7734, #3a7ab8, #2aaeae, #9a72c8, #c8a040, #e06040, #800020, #3A7734);
}

.bl-house:hover,
.bl-house:focus-visible {
    border-color: var(--court-border);
    color: var(--parchment);
    background: var(--court-hover);
}

.bl-house.is-active {
    border-color: var(--crimson-light);
    color: var(--parchment);
    box-shadow: inset 0 -2px 0 var(--crimson-light);
}

.bl-toolbar-right {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    flex: 0 1 auto;
}

/* Search */
.bl-search {
    position: relative;
    flex: 1 1 240px;
    min-width: 220px;
}

.bl-search > i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--royal-gold);
    font-size: 0.85rem;
    pointer-events: none;
}

.bl-search input {
    width: 100%;
    height: 36px;
    padding: 0 12px 0 34px;
    background: var(--court-surface);
    border: 1px solid var(--court-border);
    border-radius: 2px;
    color: var(--parchment);
    font: 16px/1 'EB Garamond', Georgia, serif;
}

.bl-search input::placeholder {
    color: var(--court-secondary);
    font-style: italic;
}

.bl-search input:focus {
    outline: none;
    border-color: var(--royal-gold);
    box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.2);
}

.bl-search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 30;
    background: var(--court-raised);
    border: 1px solid var(--court-border);
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.5);
    max-height: 320px;
    overflow-y: auto;
}

.bl-search-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 100%;
    padding: 9px 12px 9px 14px;
    background: none;
    border: 0;
    border-left: 3px solid var(--house, var(--royal-gold));
    color: var(--parchment);
    text-align: left;
    font-family: 'EB Garamond', Georgia, serif;
    cursor: pointer;
}

.bl-search-item strong {
    font: 600 14px/1.2 'Cinzel', Georgia, serif;
}

.bl-search-item span {
    font-size: 13px;
    color: var(--court-secondary);
}

.bl-search-item:hover,
.bl-search-item.is-active {
    background: var(--court-hover);
}

/* Tree / list switch */
.bl-mode {
    display: inline-flex;
    border: 1px solid var(--court-border);
    border-radius: 2px;
    overflow: hidden;
}

.bl-mode button {
    height: 34px;
    padding: 0 12px;
    background: transparent;
    border: 0;
    color: var(--court-secondary);
    font: 600 11px/1 'Cinzel', Georgia, serif;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    cursor: pointer;
}

.bl-mode button + button {
    border-left: 1px solid var(--court-border);
}

.bl-mode button i {
    margin-right: 6px;
    color: var(--royal-gold);
}

.bl-mode button.is-active {
    background: var(--court-hover);
    color: var(--parchment);
    box-shadow: inset 0 -2px 0 var(--crimson-light);
}

/*
======================
WORKSPACE: STAGE + PANEL
======================
*/
.bl-workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    align-items: start;
}

.bl-workspace[data-panel="open"] {
    grid-template-columns: minmax(0, 1fr) 360px;
}

.bl-stage-wrap {
    min-width: 0;
}

.bl-stage {
    position: relative;
    height: var(--bl-stage-h);
    overflow: hidden;
    background-color: var(--royal-black);
    background-image: radial-gradient(var(--court-line) 1px, transparent 1px);
    background-size: 22px 22px;
    border: 1px solid var(--court-border);
    border-top: 2px solid var(--royal-gold);
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.bl-stage:focus-visible {
    outline: 2px solid var(--royal-gold);
    outline-offset: -2px;
}

.bl-stage.is-dragging {
    cursor: grabbing;
}

.bl-canvas {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    will-change: transform;
}

.bl-lines {
    position: absolute;
    top: 0;
    left: 0;
    overflow: visible;
    pointer-events: none;
}

/* Lines. A bar joins spouses; a bus carries a couple's children and takes
   the parent house's colour; a consort link reaches a parent drawn
   elsewhere in the tree. */
.bl-link {
    fill: none;
    stroke-linecap: square;
    transition: opacity 0.18s ease, stroke-width 0.18s ease;
}

.bl-link--marriage {
    stroke: var(--royal-gold);
    stroke-width: 2;
}

.bl-link--faint {
    stroke-dasharray: 2 5;
    opacity: 0.55;
}

.bl-link--betrothal {
    stroke: var(--royal-gold);
    stroke-width: 2;
    stroke-dasharray: 6 5;
}

.bl-link--bus {
    stroke: var(--house, var(--royal-gold));
    stroke-width: 1.6;
    opacity: 0.85;
}

.bl-link--consort {
    stroke: var(--parchment);
    stroke-width: 1.2;
    stroke-dasharray: 2 5;
    opacity: 0.4;
}

.bl-link.is-hover,
.bl-link.is-active {
    stroke-width: 3;
    opacity: 1;
}

.bl-link--consort.is-hover,
.bl-link--consort.is-active {
    stroke-width: 2;
    opacity: 0.9;
}

.bl-link.is-dimmed {
    opacity: 0.12;
}

/* Nodes */
.bl-node {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    width: var(--bl-node-w);
    height: var(--bl-node-h);
    padding: 12px 8px 8px;
    background: var(--court-raised);
    border: 1px solid var(--court-border);
    border-radius: 2px;
    color: var(--parchment);
    text-align: center;
    cursor: pointer;
    font-family: 'EB Garamond', Georgia, serif;
    transition: border-color 0.18s ease, opacity 0.18s ease, box-shadow 0.18s ease;
}

.bl-node:hover,
.bl-node:focus-visible {
    border-color: var(--royal-gold);
    outline: none;
    z-index: 2;
}

.bl-node.is-selected {
    border-color: var(--crimson-light);
    box-shadow: 0 0 0 1px var(--crimson-light), 0 0 24px rgba(214, 51, 92, 0.35);
    z-index: 3;
}

.bl-node.is-dimmed {
    opacity: 0.28;
}

.bl-node--inlaw {
    border-style: dashed;
}

.bl-node--stub {
    border-style: dotted;
    background: var(--court-surface);
}

.bl-node--stub .bl-node-name {
    color: var(--court-secondary);
}

.bl-node--throne::before {
    content: "\f521";
    font-family: "Font Awesome 6 Free", "Font Awesome 5 Free";
    font-weight: 900;
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    color: var(--royal-gold);
    font-size: 13px;
    background: var(--royal-black);
    padding: 0 4px;
}

.bl-node-portrait,
.bl-mini-portrait,
.bl-panel-portrait {
    position: relative;
    display: block;
    flex-shrink: 0;
    border-radius: 50%;
    overflow: hidden;
    background: var(--royal-black);
    box-shadow: 0 0 0 2px var(--house, var(--royal-gold));
}

.bl-node-portrait {
    width: 72px;
    height: 72px;
}

.bl-node-portrait img,
.bl-mini-portrait img,
.bl-panel-portrait img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top;
    display: block;
}

/* Initials show when a portrait is missing or fails. */
.bl-node-portrait::before,
.bl-mini-portrait::before,
.bl-panel-portrait::before {
    content: attr(data-initials);
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font: 600 16px 'Cinzel', Georgia, serif;
    color: var(--court-secondary);
}

.bl-node-portrait img,
.bl-mini-portrait img,
.bl-panel-portrait img {
    position: relative;
    z-index: 1;
}

.bl-node-name {
    font: 600 13px/1.2 'Cinzel', Georgia, serif;
    color: var(--royal-gold-light);
    text-shadow: none;
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.bl-node-years {
    font-size: 12px;
    color: var(--court-secondary);
}

.bl-node-tag {
    margin-top: auto;
    font-size: 11px;
    font-style: italic;
    color: var(--house, var(--court-secondary));
    opacity: 0.9;
}

/* Stage furniture */
.bl-stage-tools {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 5;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.bl-stage-tools .court-btn {
    width: 36px;
    padding: 0;
    justify-content: center;
    background: var(--court-raised);
}

.bl-stage-tools .court-btn i {
    font-size: 0.8rem;
}

.bl-stage-hint {
    position: absolute;
    left: 12px;
    bottom: 10px;
    z-index: 5;
    padding: 4px 10px;
    background: rgba(15, 15, 26, 0.8);
    border: 1px solid var(--court-line);
    color: var(--court-secondary);
    font-size: 12px;
    pointer-events: none;
}

.bl-stage-hint kbd {
    font: inherit;
    color: var(--parchment);
}

.bl-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 18px;
    margin-top: 8px;
    padding: 6px 2px;
    color: var(--court-secondary);
    font-size: 13px;
}

.bl-legend span {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.bl-legend i {
    display: inline-block;
    width: 22px;
    height: 0;
    border-top: 2px solid var(--royal-gold);
}

.bl-legend i.dashed { border-top-style: dashed; }
.bl-legend i.dotted { border-top: 2px dotted var(--parchment); opacity: 0.6; }
.bl-legend i.bus { border-top-color: #3A7734; }

.bl-legend b {
    display: inline-block;
    width: 14px;
    height: 12px;
    border: 1px solid var(--court-border);
    background: var(--court-raised);
}

.bl-legend b.dashed-box { border-style: dashed; }
.bl-legend b.dotted-box { border-style: dotted; background: var(--court-surface); }

/* Status: loading and errors */
.bl-status {
    padding: 40px 20px;
    text-align: center;
    color: var(--court-secondary);
    border: 1px dashed var(--court-border);
}

.bl-status .court-btn {
    margin-left: 10px;
}

/* Full screen: the workspace fills the display, the stage takes the height
   the legend and scrubber leave. */
.bl-workspace.is-fullscreen {
    padding: 14px;
    background: var(--royal-black);
    --bl-stage-h: calc(100vh - 150px);
}

.bl-workspace.is-fullscreen .bl-panel {
    max-height: calc(100vh - 28px);
}

/*
======================
YEAR SCRUBBER
======================
*/
.bl-year {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 16px;
    margin-top: 12px;
    padding: 10px 14px;
    background: var(--court-surface);
    border: 1px solid var(--court-line);
    color: var(--court-secondary);
    font-size: 15px;
}

.bl-year label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font: 600 11px/1 'Cinzel', Georgia, serif;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--parchment);
}

.bl-year input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--crimson-light);
}

.bl-year input[type="range"] {
    flex: 1 1 240px;
    min-width: 160px;
    accent-color: var(--royal-gold);
}

.bl-year input[type="range"]:disabled {
    opacity: 0.4;
}

.bl-year output {
    min-width: 5ch;
    font: 600 15px 'Cinzel', Georgia, serif;
    color: var(--royal-gold-light);
}

.bl-year-count {
    font-style: italic;
}

/*
======================
PANEL: THE SELECTED PERSON
======================
*/
.bl-panel {
    position: sticky;
    top: 16px;
    max-height: var(--bl-stage-h);
    overflow-y: auto;
    background: var(--court-raised);
    border: 1px solid var(--court-border);
    border-top: 2px solid var(--crimson-light);
}

.bl-panel-close {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    width: 32px;
    height: 32px;
    background: var(--court-surface);
    border: 1px solid var(--court-border);
    color: var(--court-secondary);
    cursor: pointer;
}

.bl-panel-close:hover {
    color: var(--parchment);
    border-color: var(--royal-gold);
}

.bl-panel-body {
    padding: 18px 18px 22px;
}

.bl-panel-head {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    padding-right: 28px;
}

.bl-panel-portrait {
    width: 84px;
    height: 84px;
}

.bl-panel-portrait::before {
    font-size: 22px;
}

.bl-panel-title {
    min-width: 0;
}

.bl-eyebrow {
    display: block;
    margin-bottom: 4px;
    font: 600 10px/1.3 'Cinzel', Georgia, serif;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--crimson-light);
}

.bl-panel-title h3 {
    margin: 0 0 3px;
    font: 600 20px/1.2 'Cinzel', Georgia, serif;
    color: var(--royal-gold-light);
    text-shadow: none;
}

.bl-panel-epithet {
    margin: 0 0 6px;
    font-style: italic;
    color: var(--parchment);
    font-size: 15px;
}

.bl-panel-years {
    margin: 0;
    font-size: 14px;
    color: var(--court-secondary);
}

.bl-panel-years i {
    color: var(--royal-gold);
    margin-right: 4px;
}

.bl-panel-years span {
    opacity: 0.8;
}

.bl-panel-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 14px 0;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--court-line);
}

/* The same person elsewhere: their dossier, their card. */
.bl-panel-kin {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
    margin: -4px 0 14px;
}

.bl-kin-link {
    font: 600 11px 'Cinzel', Georgia, serif;
    letter-spacing: .12em;
    text-transform: uppercase;
    text-decoration: none;
    color: var(--royal-gold);
    transition: color .18s ease;
}

.bl-kin-link i { margin-right: 6px; }

.bl-kin-link:hover,
.bl-kin-link:focus-visible { color: var(--royal-gold-light); }

.bl-panel-desc {
    margin: 0 0 10px;
    font-size: 16px;
    line-height: 1.55;
    color: var(--parchment);
}

.bl-panel-aliases {
    margin: 0 0 12px;
    font-size: 14px;
    color: var(--court-secondary);
}

.bl-panel-aliases span {
    font: 600 10px 'Cinzel', Georgia, serif;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--royal-gold);
    margin-right: 6px;
}

.bl-panel-aliases em {
    color: var(--parchment);
}

.bl-panel-group {
    margin-top: 14px;
}

.bl-panel-group h4 {
    margin: 0 0 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--court-line);
    font: 600 10px/1.4 'Cinzel', Georgia, serif;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--royal-gold);
    text-shadow: none;
}

.bl-panel-empty {
    margin: 0;
    font-size: 14px;
    font-style: italic;
    color: var(--court-secondary);
}

.bl-relatives {
    list-style: none;
    margin: 0;
    padding: 0;
}

.bl-relative {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 6px 4px;
    background: none;
    border: 0;
    border-bottom: 1px solid var(--court-line);
    color: var(--parchment);
    text-align: left;
    font-family: 'EB Garamond', Georgia, serif;
    cursor: pointer;
}

.bl-relative:hover,
.bl-relative:focus-visible {
    background: var(--court-hover);
    outline: none;
}

.bl-relative:hover strong {
    color: var(--royal-gold-light);
}

.bl-mini-portrait {
    width: 36px;
    height: 36px;
}

.bl-mini-portrait::before {
    font-size: 11px;
}

.bl-relative-text,
.bl-outline-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.bl-relative-text strong,
.bl-outline-text strong {
    font: 600 14px/1.25 'Cinzel', Georgia, serif;
    color: var(--parchment);
}

.bl-relative-text span,
.bl-outline-text span {
    font-size: 13px;
    color: var(--court-secondary);
}

.bl-relative > i {
    color: var(--court-secondary);
    font-size: 0.7rem;
}

/*
======================
OUTLINE (LIST MODE)
======================
*/
.bl-outline {
    padding: 14px 16px 20px;
    background: var(--royal-black);
    border: 1px solid var(--court-border);
    border-top: 2px solid var(--royal-gold);
}

.bl-outline-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.bl-outline-list--root > .bl-outline-item + .bl-outline-item {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--court-line);
}

.bl-outline-item {
    margin: 0;
}

.bl-outline-person {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 6px 6px;
    background: none;
    border: 0;
    border-left: 3px solid var(--house, var(--royal-gold));
    color: var(--parchment);
    text-align: left;
    font-family: 'EB Garamond', Georgia, serif;
    cursor: pointer;
}

.bl-outline-person:hover,
.bl-outline-person:focus-visible {
    background: var(--court-hover);
    outline: none;
}

.bl-outline-person.is-selected {
    background: var(--court-raised);
    box-shadow: inset 0 0 0 1px var(--crimson-light);
}

.bl-outline-person.is-dimmed {
    opacity: 0.35;
}

.bl-outline-person--inlaw {
    border-left-style: dashed;
}

.bl-outline-person--stub {
    border-left-style: dotted;
}

.bl-outline-group {
    margin: 4px 0 4px 22px;
    padding-left: 14px;
    border-left: 1px solid var(--court-line);
}

.bl-outline-group > summary {
    padding: 4px 0;
    font: 600 11px/1.5 'Cinzel', Georgia, serif;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--royal-gold);
    cursor: pointer;
    list-style: none;
}

.bl-outline-group > summary::-webkit-details-marker {
    display: none;
}

.bl-outline-group > summary::before {
    content: "\25B8";
    display: inline-block;
    width: 1em;
    color: var(--court-secondary);
    transition: transform 0.15s ease;
}

.bl-outline-group[open] > summary::before {
    transform: rotate(90deg);
}

/*
======================
RESPONSIVE
======================
*/
@media (max-width: 1100px) {
    .bl-workspace[data-panel="open"] {
        grid-template-columns: minmax(0, 1fr) 320px;
    }
}

@media (max-width: 900px) {
    .bl-workspace,
    .bl-workspace[data-panel="open"] {
        grid-template-columns: minmax(0, 1fr);
    }

    /* The panel becomes a sheet over the bottom of the screen. */
    .bl-panel {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        z-index: 60;
        max-height: 72vh;
        max-height: 72dvh;
        border-top-width: 2px;
        box-shadow: 0 -16px 40px rgba(0, 0, 0, 0.6);
    }

    .bl-panel-body {
        padding-bottom: 32px;
    }
}

@media (max-width: 700px) {
    .bloodlines-main {
        --bl-stage-h: clamp(420px, 62vh, 640px);
    }

    .bl-toolbar {
        gap: 12px;
    }

    .bl-houses {
        flex: 1 1 100%;
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 6px;
        -webkit-overflow-scrolling: touch;
    }

    .bl-house {
        flex-shrink: 0;
    }

    .bl-toolbar-right {
        flex: 1 1 100%;
    }

    .bl-search {
        flex: 1 1 auto;
    }

    .bl-legend {
        font-size: 12px;
        gap: 4px 12px;
    }

    .bl-stage-hint {
        display: none;
    }

    .bl-outline-group {
        margin-left: 10px;
        padding-left: 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .bl-node,
    .bl-link,
    .bl-house,
    .bloodlines-main .court-btn {
        transition: none;
    }
}

/* What the spoiler shield (js/court-shield.js) is keeping back. */
.bl-spoiler-note {
    margin: 10px 0 0;
    font-size: 15px;
    color: var(--court-secondary);
}

.bl-spoiler-note i { color: var(--crimson-light); }
