/* Character panel (web/js/hud.js): the bar along the bottom, the other
   players' cards over the board, their read-only panel and the full sheet.
   Talisman-style: a dark bevelled bar with gold edges, the portrait at the
   left, counters and stats, then the cards you hold. */

:root {
    --hud-bg: linear-gradient(180deg, #1b1a22 0%, #121118 100%);
    --hud-edge: rgba(196, 164, 78, 0.55);
    --hud-edge-soft: rgba(196, 164, 78, 0.22);
    --hud-tile: rgba(255, 255, 255, 0.04);
    --hud-tile-edge: rgba(255, 255, 255, 0.08);
    --hud-icon-cut: #16151c;
    --hud-label-bg: rgba(10, 9, 14, 0.82);
    --hud-label-edge: rgba(196, 164, 78, 0.5);
    --hud-label-ink: #f3ead2;
    --hud-life: #d9534f;
    --hud-life-off: rgba(217, 83, 79, 0.22);
    --hud-influence: #d8b24a;
    --hud-level: #7db7e8;
    --hud-corruption: #b065e0;
    --hud-trophies: #d2a54a;
    --hud-relics: #57c7b8;
    --hud-hand: #c9c1ad;
    --hud-warn: #ff6b5e;
    --hud-up: #6fd38a;
    --hud-down: #ff7a6e;
    --hud-str: #e05a4f;
    --hud-wil: #5a86e0;
    --hud-cun: #e0bd45;
    --hud-card-back: repeating-linear-gradient(45deg, #2a2230 0 0.375rem, #231c29 0.375rem 0.75rem);
    --hud-shadow: 0 -0.375rem 1.5rem rgba(0, 0, 0, 0.45);
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        --hud-bg: linear-gradient(180deg, #fbf8f1 0%, #eee8da 100%);
        --hud-edge: rgba(138, 116, 48, 0.6);
        --hud-edge-soft: rgba(138, 116, 48, 0.25);
        --hud-tile: rgba(0, 0, 0, 0.035);
        --hud-tile-edge: rgba(0, 0, 0, 0.1);
        --hud-icon-cut: #f4efe3;
        --hud-life: #c63d39;
        --hud-life-off: rgba(198, 61, 57, 0.2);
        --hud-influence: #a77f12;
        --hud-level: #2f6fa8;
        --hud-corruption: #7f35b0;
        --hud-trophies: #9c7217;
        --hud-relics: #1d8577;
        --hud-hand: #6b624f;
        --hud-warn: #c62d22;
        --hud-up: #1f8a3e;
        --hud-down: #c62d22;
        --hud-str: #c23b31;
        --hud-wil: #2f5fc0;
        --hud-cun: #a88411;
        --hud-card-back: repeating-linear-gradient(45deg, #d9cfbd 0 0.375rem, #cfc4b0 0.375rem 0.75rem);
        --hud-shadow: 0 -0.375rem 1.25rem rgba(60, 40, 10, 0.15);
    }
}

:root[data-theme="dark"] {
    --hud-bg: linear-gradient(180deg, #1b1a22 0%, #121118 100%);
    --hud-edge: rgba(196, 164, 78, 0.55);
    --hud-edge-soft: rgba(196, 164, 78, 0.22);
    --hud-tile: rgba(255, 255, 255, 0.04);
    --hud-tile-edge: rgba(255, 255, 255, 0.08);
    --hud-icon-cut: #16151c;
    --hud-life: #d9534f;
    --hud-life-off: rgba(217, 83, 79, 0.22);
    --hud-influence: #d8b24a;
    --hud-level: #7db7e8;
    --hud-corruption: #b065e0;
    --hud-trophies: #d2a54a;
    --hud-relics: #57c7b8;
    --hud-hand: #c9c1ad;
    --hud-warn: #ff6b5e;
    --hud-up: #6fd38a;
    --hud-down: #ff7a6e;
    --hud-str: #e05a4f;
    --hud-wil: #5a86e0;
    --hud-cun: #e0bd45;
    --hud-card-back: repeating-linear-gradient(45deg, #2a2230 0 0.375rem, #231c29 0.375rem 0.75rem);
    --hud-shadow: 0 -0.375rem 1.5rem rgba(0, 0, 0, 0.45);
}

/* ===== The bar ===== */

.hud {
    position: relative;
    z-index: 20;
    flex-shrink: 0;
    display: flex;
    align-items: stretch;
    gap: 0.875rem;
    padding: 0.5rem var(--gutter) 0.5rem;
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
    background: var(--hud-bg);
    border-top: 1px solid var(--hud-edge);
    box-shadow: var(--hud-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    color: var(--text);
    min-width: 0;
}

.hud:empty { display: none; }

.hud-bar {
    display: flex;
    align-items: stretch;
    gap: 0.75rem;
    flex: none;
    min-width: 0;
}

.hud-portrait {
    position: relative;
    flex: none;
    width: 5.75rem;
    height: 7rem;
    padding: 0;
    border: 0.125rem solid var(--hud-edge);
    border-radius: 0.5rem;
    overflow: hidden;
    background: var(--art-bg);
    cursor: pointer;
    box-shadow: 0 0.125rem 0.625rem rgba(0, 0, 0, 0.35);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.hud-portrait img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: 50% 18%;
}

/* Your seat's colour (your figure's rim on the board) along the top. */
.hud-portrait::after {
    content: ''; position: absolute; left: 0; right: 0; top: 0; height: 0.1875rem;
    background: var(--pc, transparent); pointer-events: none;
}

.hud-portrait:hover, .hud-portrait:focus-visible { border-color: var(--accent-hover); }

.hud--active .hud-portrait {
    border-color: var(--reach);
    box-shadow: 0 0 0 1px var(--reach), 0 0 1.125rem var(--reach-halo);
}

.hud-turn {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    padding: 0.125rem 0;
    background: var(--reach);
    color: #1a1406;
    font-size: 0.6rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    text-align: center;
}

.hud-turn[hidden] { display: none; }

.hud-main {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 0.375rem;
    min-width: 0;
}

.hud-id { display: flex; align-items: baseline; gap: 0.5rem; min-width: 0; white-space: nowrap; }
.hud-name { font-weight: 700; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; }
.hud-char { font-size: 0.75rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; }

/* --- Counters --- */

.hud-counters { display: flex; gap: 0.25rem; }

.hud-counter {
    position: relative;
    display: grid;
    grid-template-columns: auto auto;
    grid-template-rows: auto auto;
    align-items: center;
    column-gap: 0.25rem;
    min-width: 2.875rem;
    padding: 0.1875rem 0.375rem 0.125rem;
    border: 1px solid var(--hud-tile-edge);
    border-radius: 0.375rem;
    background: var(--hud-tile);
    cursor: default;
    outline-offset: 0.125rem;
    transition: border-color 0.2s, background 0.2s;
}

.hud-counter .hud-icon, .hud-counter .hud-pips { grid-row: 1; grid-column: 1; }
.hud-num { grid-row: 1; grid-column: 2; white-space: nowrap; line-height: 1; }
.hud-label {
    grid-row: 2; grid-column: 1 / span 2;
    font-size: 0.55rem; letter-spacing: 0.06em; text-transform: uppercase;
    color: var(--text-muted); text-align: center; line-height: 1.3;
}

.hud-icon { width: 1rem; height: 1rem; flex: none; display: block; }
.hud-val { font-size: 1rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.hud-sub { font-size: 0.7rem; font-weight: 600; color: var(--text-muted); margin-left: 1px; }

.hud-counter--fate { color: var(--hud-level); }
.hud-counter--gold { color: var(--hud-influence); }
.hud-counter--trophies { color: var(--hud-trophies); }
.hud-counter--spells { color: var(--hud-hand); }
.hud-counter .hud-val { color: inherit; }
.hud-counter--lives { color: var(--hud-life); }
/* The Digital Edition's tokens (Fate, gold) in place of an icon. */
.hud-icon.hud-token { width: 1.25rem; height: 1.25rem; object-fit: contain; filter: drop-shadow(0 1px 1px rgb(0 0 0 / 0.4)); }

/* Hearts: one per point of Life (compact: one heart and the numbers). */
.hud-pips { display: flex; gap: 1px; align-items: center; }
.hud-heart { width: 0.75rem; height: 0.75rem; fill: var(--hud-life-off); }
.hud-heart.on { fill: var(--hud-life); }
/* Life above the starting value (it may go up to 12). */
.hud-heart.on.over { fill: var(--accent); }
.hud-pips--compact .hud-heart { width: 1rem; height: 1rem; }

.hud-counter.is-warn { border-color: var(--hud-warn); background: color-mix(in srgb, var(--hud-warn) 12%, transparent); }
.hud-counter.is-warn .hud-val { color: var(--hud-warn); }
.hud-counter.is-ready { border-color: var(--hud-trophies); box-shadow: 0 0 0.625rem color-mix(in srgb, var(--hud-trophies) 45%, transparent); }

/* A changed counter pulses, with the change floating off it. */
.hud-counter.is-bump-up { animation: hud-bump 0.7s ease; border-color: var(--hud-up); }
.hud-counter.is-bump-down { animation: hud-bump 0.7s ease; border-color: var(--hud-down); }

@keyframes hud-bump {
    0% { transform: scale(1); }
    30% { transform: scale(1.18); }
    100% { transform: scale(1); }
}

.hud-delta {
    position: absolute;
    left: 50%; top: -0.25rem;
    transform: translate(-50%, 0);
    font-size: 0.8rem; font-weight: 800;
    pointer-events: none;
    animation: hud-delta 1.1s ease-out forwards;
    text-shadow: 0 1px 0.125rem rgba(0, 0, 0, 0.6);
}
.hud-delta--up { color: var(--hud-up); }
.hud-delta--down { color: var(--hud-down); }

@keyframes hud-delta {
    from { opacity: 1; transform: translate(-50%, 0); }
    to { opacity: 0; transform: translate(-50%, -1.375rem); }
}

/* --- Stats --- */

.hud-stats { display: flex; gap: 0.25rem; }

.hud-stat {
    display: flex; align-items: baseline; gap: 0.25rem;
    padding: 0.1875rem 0.5rem;
    border-radius: 0.375rem;
    border: 1px solid var(--hud-tile-edge);
    border-left: 0.1875rem solid var(--stat);
    background: var(--hud-tile);
    white-space: nowrap;
    cursor: default;
}

.hud-stat--str { --stat: var(--hud-str); }
.hud-stat--cra { --stat: var(--hud-wil); }
.hud-stat { align-items: center; }
/* The Strength cone and Craft token from the Digital Edition. */
.hud-stat-token { width: 1.1rem; height: 1.1rem; object-fit: contain; filter: drop-shadow(0 1px 1px rgb(0 0 0 / 0.35)); }
.hud-stat.is-lowered .hud-stat-val { color: var(--hud-warn); }

.hud-stat-key { font-size: 0.6rem; font-weight: 700; letter-spacing: 0.06em; color: var(--stat); }
.hud-stat-val { font-size: 1.05rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.hud-stat.is-raised .hud-stat-val { color: var(--hud-up); }

.hud-stat-bonus {
    font-size: 0.65rem; font-weight: 700;
    padding: 0 0.25rem; border-radius: 0.5rem;
    border: 1px solid currentColor;
}
/* Battle bonus: spiked (square corners); skill bonus: round, as on the cards. */
.hud-stat-bonus--battle { color: var(--stat); border-radius: 0.125rem; }
.hud-stat-bonus--skill { color: var(--text-muted); }

/* --- Card rows --- */

.hud-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.hud-body-head { display: none; }

.hud-zones {
    display: flex;
    gap: 0.875rem;
    align-items: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    padding-bottom: 0.125rem;
    min-height: 0;
    height: 100%;
}

.hud-zone { flex: none; display: flex; flex-direction: column; gap: 0.1875rem; }
.hud-zone[hidden] { display: none; }
.hud-zone + .hud-zone { padding-left: 0.875rem; border-left: 1px solid var(--hud-edge-soft); }

.hud-zone-title {
    margin: 0;
    font-size: 0.6rem; font-weight: 700;
    letter-spacing: 0.07em; text-transform: uppercase;
    color: var(--accent);
    white-space: nowrap;
}
.hud-zone-count { color: var(--text-muted); font-weight: 600; margin-left: 0.125rem; }

.hud-cards { display: flex; gap: 0.375rem; align-items: flex-start; }
.hud-empty { font-size: 0.75rem; color: var(--text-muted); font-style: italic; padding: 0.25rem 0; white-space: nowrap; }

.hud .hud-card {
    position: relative;
    flex: none;
    width: 3.875rem;
    height: 5.375rem;
    padding: 0;
    border: 1px solid var(--hud-tile-edge);
    border-radius: 0.3125rem;
    overflow: hidden;
    background: var(--art-bg);
    cursor: pointer;
    font: inherit;
    color: inherit;
    transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.hud .hud-card:hover, .hud .hud-card:focus-visible {
    transform: translateY(-0.25rem);
    border-color: var(--accent);
    box-shadow: 0 0.375rem 0.875rem rgba(0, 0, 0, 0.4);
}

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

/* The card's own name is a few pixels high on a 62 px thumbnail (and the
   rules text under it is left out at that size), so the name goes across
   the card's lower middle in a band, in the UI font: up to two lines,
   clear of the charge pips, the mission progress and the Play/Use tag at
   the foot. Overlapping trophies keep their art; cards without art are
   all name. */
.hud-card-name {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    position: absolute;
    left: 0;
    right: 0;
    top: 40%;
    z-index: 3;
    padding: 0.1875rem 0.1875rem 0.1875rem;
    background: var(--hud-label-bg);
    border-top: 1px solid var(--hud-label-edge);
    border-bottom: 1px solid var(--hud-label-edge);
    color: var(--hud-label-ink);
    font-size: 0.6rem;
    font-weight: 700;
    line-height: 1.15;
    text-align: center;
    overflow-wrap: anywhere; /* only a word too long even at the smallest size */
    pointer-events: none;
}
/* Long words ("Disciplined", "Inquisitorial") get a smaller size rather
   than a break in the middle (hudmodel.js nameFit). */
.hud-card-name--long { font-size: 0.53rem; letter-spacing: -0.01em; }
.hud-card-name--longer { font-size: 0.47rem; letter-spacing: -0.015em; }
.hud-card-name--longest { font-size: 0.4rem; letter-spacing: -0.035em; }
/* Mission progress fills the foot: the name goes higher. */
.hud-card:has(.hud-card-progress) .hud-card-name { top: 22%; }
.hud-cards--stack .hud-card-name { display: none; }
.hud-card--text .hud-card-name {
    display: flex; align-items: center; justify-content: center;
    inset: 0; top: 0; padding: 0.25rem;
    background: none; border: 0; color: inherit;
    font-weight: 400; line-height: 1.2;
}

.hud .hud-card--back { background: var(--hud-card-back); cursor: default; border-color: var(--hud-edge-soft); }
.hud .hud-card--back:hover { transform: none; box-shadow: none; }
.hud .hud-card--done { opacity: 0.55; }

.hud-charges {
    position: absolute; left: 0; right: 0; bottom: 0.125rem;
    display: flex; justify-content: center; gap: 0.125rem;
}
.hud-charges i {
    width: 0.4375rem; height: 0.4375rem; border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.55);
}
.hud-charges i.on { background: var(--reach); border-color: #fff3c4; box-shadow: 0 0 0.25rem var(--reach-halo); }

.hud-card-badge {
    position: absolute; top: 0.125rem; right: 0.125rem;
    min-width: 1rem; height: 1rem; padding: 0 0.1875rem;
    border-radius: 0.5rem;
    background: var(--hud-trophies); color: #1a1406;
    font-size: 0.65rem; font-weight: 800; line-height: 1rem; text-align: center;
}

.hud-card-progress {
    position: absolute; left: 0; right: 0; bottom: 0;
    padding: 0.125rem 0.1875rem;
    background: rgba(8, 8, 14, 0.85); color: #f1e4be;
    font-size: 0.55rem; line-height: 1.15; text-align: center;
    max-height: 3.5em; overflow: hidden;
}

/* Trophies overlap like a stack of cards. */
.hud-cards--stack .hud-card + .hud-card { margin-left: -2.5rem; }
.hud-cards--stack .hud-card:hover { z-index: 1; }

.hud-chips { display: flex; flex-wrap: wrap; gap: 0.25rem; max-width: 13.75rem; }
.hud-chip {
    font-size: 0.7rem; padding: 0.125rem 0.375rem; border-radius: 0.625rem;
    border: 1px solid var(--hud-tile-edge); background: var(--hud-tile);
    white-space: nowrap;
}
/* Alignment and status, under the stats. */
.hud-status { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.25rem; }
.hud-status:empty { display: none; }
.hud-chip--align-good { color: #2f7d4f; border-color: color-mix(in srgb, #2f7d4f 50%, transparent); }
.hud-chip--align-neutral { color: var(--text-muted); }
.hud-chip--align-evil { color: #b03a3a; border-color: color-mix(in srgb, #b03a3a 50%, transparent); }
.hud-chip--toad { color: var(--text); background: color-mix(in srgb, #4caf50 22%, transparent); border-color: #4caf50; }
.hud-chip--miss, .hud-chip--slave { color: var(--hud-warn); border-color: var(--hud-warn); }
.hud-chip--out { color: var(--text-muted); }
.hud--out .hud-portrait img { filter: grayscale(1); }

/* --- Tools (sheet, fold) --- */

.hud-tools { flex: none; display: flex; flex-direction: column; gap: 0.375rem; justify-content: flex-start; }
.hud-tools .btn-icon { display: inline-flex; align-items: center; gap: 0.25rem; }
.hud-tools .btn-icon .hud-icon { width: 1rem; height: 1rem; }
.hud-tool-label { font-size: 0.7rem; }
.hud-fold .hud-icon { transform: rotate(180deg); transition: transform 0.2s; }
.hud--folded .hud-fold .hud-icon { transform: none; }
.hud-sheet-btn--body .hud-icon { width: 0.875rem; height: 0.875rem; vertical-align: -0.125rem; }

/* ===== Folded (desktop): the slim bar ===== */

:is(.hud--folded, .hud--auto-fold) { padding-top: 0.3125rem; padding-bottom: calc(0.3125rem + env(safe-area-inset-bottom)); }
:is(.hud--folded, .hud--auto-fold) .hud-body { display: none; }
:is(.hud--folded, .hud--auto-fold) .hud-bar { flex: 1; }
:is(.hud--folded, .hud--auto-fold) .hud-portrait { width: 2.75rem; height: 2.75rem; border-radius: 50%; }
:is(.hud--folded, .hud--auto-fold) .hud-turn { display: none; }
:is(.hud--folded, .hud--auto-fold) .hud-main { flex-direction: row; align-items: center; gap: 0.875rem; }
:is(.hud--folded, .hud--auto-fold) .hud-id { flex-direction: column; gap: 0; min-width: 7rem; }
:is(.hud--folded, .hud--auto-fold) .hud-label { display: none; }
:is(.hud--folded, .hud--auto-fold) .hud-pips .hud-heart:not(:first-child) { display: none; }
:is(.hud--folded, .hud--auto-fold) .hud-pips .hud-heart { width: 1rem; height: 1rem; fill: var(--hud-life); }
:is(.hud--folded, .hud--auto-fold) .hud-tools { flex-direction: row; align-items: center; }
:is(.hud--folded, .hud--auto-fold) .hud-tool-label { display: none; }

/* Mid widths: names under each other, fewer labels. */
@media (min-width: 769px) and (max-width: 1180px) {
    .hud { gap: 0.625rem; }
    .hud-bar { gap: 0.625rem; }
    .hud-portrait { width: 5rem; }
    .hud-counter { min-width: 2.5rem; padding: 0.1875rem 0.25rem 0.125rem; }
    .hud-pips .hud-heart:not(:first-child) { display: none; }
    .hud-pips .hud-heart { width: 1rem; height: 1rem; fill: var(--hud-life); }
    .hud-tool-label { display: none; }
}

/* ===== Phones: a slim bar that opens a sheet ===== */

@media (max-width: 768px) {
    #hud {
        gap: 0.375rem;
        height: calc(3.25rem + env(safe-area-inset-bottom));
        padding: 0.375rem 0.5rem calc(0.375rem + env(safe-area-inset-bottom));
        align-items: center;
    }
    #hud.hud--folded { padding-top: 0.375rem; }
    #hud .hud-bar { flex: 1; gap: 0.5rem; align-items: center; cursor: pointer; }
    #hud .hud-portrait, #hud.hud--folded .hud-portrait { width: 2.5rem; height: 2.5rem; border-radius: 50%; }
    #hud .hud-turn { display: none; }
    #hud .hud-main, #hud.hud--folded .hud-main { flex: 1; flex-direction: row; align-items: center; gap: 0; }
    #hud .hud-bar .hud-id, #hud .hud-bar .hud-stats { display: none; }
    #hud .hud-counters { flex: 1; justify-content: space-between; gap: 0.125rem; }
    #hud .hud-counter { min-width: 0; padding: 0.125rem 0.1875rem; border-color: transparent; background: none; column-gap: 0.125rem; }
    #hud .hud-label { display: none; }
    #hud .hud-icon { width: 0.875rem; height: 0.875rem; }
    #hud .hud-val { font-size: 0.9rem; }
    #hud .hud-sub { font-size: 0.6rem; }
    #hud .hud-pips .hud-heart:not(:first-child) { display: none; }
    #hud .hud-pips .hud-heart { width: 0.875rem; height: 0.875rem; fill: var(--hud-life); }
    #hud .hud-counter--trophies.is-zero { display: none; }
    #hud .hud-tools { flex-direction: row; }
    #hud .hud-tools .hud-sheet-btn { display: none; }
    #hud .hud-fold .hud-icon, #hud.hud--folded .hud-fold .hud-icon { transform: none; }
    #hud.hud--open .hud-fold .hud-icon { transform: rotate(180deg); }

    /* The sheet: over the board, above the bar. */
    #hud .hud-body, #hud.hud--folded .hud-body { display: none; }
    #hud.hud--open .hud-body {
        display: flex;
        position: fixed;
        left: 0; right: 0;
        bottom: calc(3.25rem + env(safe-area-inset-bottom));
        max-height: min(72dvh, calc(100dvh - 7.5rem));
        overflow-y: auto;
        padding: 0.75rem var(--gutter) 0.875rem;
        background: var(--bg-panel);
        border-top: 1px solid var(--hud-edge);
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        box-shadow: 0 -0.75rem 2.5rem rgba(0, 0, 0, 0.5);
        z-index: 53; /* over the battle screen (50), under the modals (54) and card inspection (55) */
        animation: hud-sheet-in 0.22s ease;
        gap: 0.625rem;
    }
    #hud .hud-body-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; }
    #hud .hud-body-head .hud-id { flex: 1 1 100%; }
    #hud .hud-body-head .hud-sheet-btn { margin-left: auto; width: auto; }
    #hud .hud-zones { flex-direction: column; overflow: visible; height: auto; gap: 0.625rem; }
    #hud .hud-zone + .hud-zone { padding-left: 0; border-left: 0; padding-top: 0.5rem; border-top: 1px solid var(--hud-edge-soft); }
    #hud .hud-cards { overflow-x: auto; padding-bottom: 0.125rem; }
    #hud .hud-card { width: 4.125rem; height: 5.75rem; }
    #hud .hud-chips { max-width: none; }
}

@keyframes hud-sheet-in {
    from { transform: translateY(1rem); opacity: 0; }
    to { transform: none; opacity: 1; }
}

/* ===== Other players (over the board, top left) ===== */

.hud-others {
    position: absolute;
    top: 0.75rem;
    left: var(--gutter);
    z-index: 22;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    width: 12.25rem;
}

.hud-others[hidden] { display: none; }

.hud-other {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.5rem 0.5rem 0.375rem;
    border: 1px solid var(--border-light);
    border-radius: 0.5rem;
    background: var(--glass);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
    overflow: hidden;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.hud-other:hover, .hud-other:focus-visible { border-color: var(--accent); }
.hud-other.is-active { border-color: var(--reach); box-shadow: 0 0 0 1px var(--reach), 0 0 1rem var(--reach-halo); }

.hud-other-portrait { position: relative; flex: none; width: 2.5rem; height: 2.5rem; }
.hud-other-portrait img {
    width: 2.5rem; height: 2.5rem; border-radius: 50%;
    object-fit: cover; object-position: 50% 18%;
    border: 0.125rem solid var(--border-light);
    display: block;
}
.hud-other.is-active .hud-other-portrait img { border-color: var(--reach); }

.hud-other-turn {
    display: none;
    position: absolute; left: 50%; bottom: -0.3125rem; transform: translateX(-50%);
    padding: 0 0.25rem; border-radius: 0.1875rem;
    background: var(--reach); color: #1a1406;
    font-size: 0.5rem; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase;
}
.hud-other.is-active .hud-other-turn { display: block; }

/* A bot's badge: a small round chip on the portrait's top right. */
.hud-other-bot {
    position: absolute; right: -0.25rem; top: -0.25rem;
    width: 1.05rem; height: 1.05rem; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--bg-panel); border: 1px solid var(--border-light);
    color: var(--text-muted); font-size: 0.7rem;
}
.hud-other-bot[hidden] { display: none; }
.hud-other-bot .bot-icon { width: 0.7rem; height: 0.7rem; color: inherit; }

.hud-other-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.hud-other-name { font-weight: 700; font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-other-char { font-size: 0.65rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-other-stats { display: flex; gap: 0.4375rem; margin-top: 0.125rem; }
.hud-o { position: relative; display: inline-flex; align-items: center; gap: 0.125rem; font-size: 0.72rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.hud-o .hud-icon { width: 0.6875rem; height: 0.6875rem; }
.hud-o--life { color: var(--hud-life); }
.hud-o--str { color: var(--hud-str); }
.hud-o--cft { color: var(--hud-wil); }
.hud-o--gold { color: var(--hud-influence); }
.hud-o img { width: 0.8rem; height: 0.8rem; object-fit: contain; }
.hud-o.is-bump-down, .hud-o.is-bump-up { animation: hud-bump 0.7s ease; }

/* Life as a thin bar along the bottom. */
.hud-other-life { position: absolute; left: 0; right: 0; bottom: 0; height: 0.1875rem; background: var(--hud-life-off); }
.hud-other-life i { display: block; height: 100%; width: calc(var(--life, 1) * 100%); background: var(--hud-life); transition: width 0.4s; }
.hud-other.is-low .hud-other-life i { background: var(--hud-warn); }
.hud-other.is-out { opacity: 0.45; filter: grayscale(1); }

/* The seat's colour (the figure's rim on the board): a stripe down the
   card's left edge; round on phones, a ring. */
.hud-other::before {
    content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 0.1875rem;
    background: var(--pc, transparent); box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.3);
}

/* Four or more others (five- and six-player games): slimmer cards. */
.hud-others--many { gap: 0.25rem; }
.hud-others--many .hud-other { padding: 0.25rem 0.5rem 0.375rem 0.375rem; }
.hud-others--many .hud-other-portrait,
.hud-others--many .hud-other-portrait img { width: 2.125rem; height: 2.125rem; }
.hud-others--many .hud-other-char { display: none; }

@media (max-width: 768px) {
    .hud-others { top: 3.25rem; left: 0.5rem; width: auto; gap: 0.5rem; }
    .hud-other { padding: 0.1875rem; border-radius: 50%; gap: 0; }
    .hud-other-info { display: none; }
    .hud-other-portrait, .hud-other-portrait img { width: 2.375rem; height: 2.375rem; }
    .hud-other-life { left: 0.375rem; right: 0.375rem; bottom: 1px; border-radius: 0.125rem; }
    .hud-other::before { display: none; }
    .hud-other { box-shadow: inset 0 0 0 0.125rem var(--pc, transparent); }
    .hud-others--many { gap: 0.3125rem; }
    .hud-others--many .hud-other { padding: 0.1875rem; }
    .hud-others--many .hud-other-portrait,
    .hud-others--many .hud-other-portrait img { width: 2.125rem; height: 2.125rem; }
}

/* ===== Modals: another player's panel, the full sheet ===== */

.hud-modal {
    position: fixed;
    inset: 0;
    z-index: 54; /* under the card inspection (55) and choices (57) */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--gutter);
    animation: fade-in 0.2s ease;
}

.hud-modal[hidden] { display: none; }
.hud-modal-backdrop { position: absolute; inset: 0; background: var(--overlay); }

.hud-modal-panel {
    position: relative;
    max-height: calc(100dvh - 2 * var(--gutter));
    overflow: auto;
    background: var(--bg-panel);
    border: 1px solid var(--hud-edge);
    border-radius: var(--radius-lg);
    box-shadow: 0 1.25rem 3.75rem rgba(0, 0, 0, 0.55);
}

.hud-modal-close { position: absolute; top: 0.375rem; right: 0.375rem; z-index: 2; font-size: 1.2rem; }

/* Another player's panel: the same parts, open, read-only. */
.hud-modal-panel--peek { width: min(47.5rem, 100%); }
.hud--peek { flex-wrap: wrap; border-top: 0; box-shadow: none; padding: 0.875rem; background: transparent; }
.hud--peek .hud-bar { flex: 1 1 100%; }
.hud--peek .hud-body { flex: 1 1 100%; }
.hud--peek .hud-zones { flex-wrap: wrap; overflow: visible; gap: 0.75rem; }
.hud--peek .hud-tools { position: absolute; right: 2.75rem; top: 0.5rem; flex-direction: row; }

@media (max-width: 768px) {
    .hud--peek .hud-bar { flex-wrap: wrap; }
    .hud--peek .hud-main { flex: 1; min-width: 0; }
    .hud--peek .hud-counters { flex-wrap: wrap; }
    .hud--peek .hud-stats { flex-wrap: wrap; }
    .hud--peek .hud-portrait { width: 4.5rem; height: 5.5rem; border-radius: 0.5rem; }
    .hud--peek .hud-tools { position: static; }
    .hud--peek .hud-zones { flex-direction: row; }
}

.hud-modal-panel--sheet { width: min(68.75rem, 100%); padding: 0.875rem 1rem 1rem; }
.hud-sheet-title { margin: 0 2.5rem 0.625rem 0; font-size: 0.95rem; color: var(--accent); }
.hud-sheet-scroll { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(13.75rem, 1fr); gap: 1rem; align-items: start; }

.hud-sheet-img { position: relative; border-radius: 0.375rem; overflow: hidden; line-height: 0; }
.hud-sheet-img img { width: 100%; height: auto; display: block; }

.hud-level-mark {
    position: absolute;
    border: 0.1875rem solid var(--reach);
    border-radius: 0.25rem;
    box-shadow: 0 0 0 0.125rem rgba(0, 0, 0, 0.6), 0 0 1.125rem var(--reach), inset 0 0 0.875rem var(--reach-halo);
    pointer-events: none;
    animation: hud-mark 1.8s ease-in-out infinite;
}
.hud-level-mark[hidden] { display: none; }

@keyframes hud-mark {
    50% { box-shadow: 0 0 0 0.125rem rgba(0, 0, 0, 0.6), 0 0 0.375rem var(--reach), inset 0 0 0.375rem var(--reach-halo); }
}

.hud-sheet-info h4 {
    margin: 0 0 0.375rem; font-size: 0.65rem; letter-spacing: 0.07em; text-transform: uppercase; color: var(--accent);
}
.hud-sheet-info section + section { margin-top: 0.875rem; }

.hud-track { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.125rem; font-size: 0.8rem; }
.hud-track li { display: flex; gap: 0.5rem; align-items: baseline; padding: 0.125rem 0.375rem; border-radius: 0.25rem; color: var(--text-muted); }
.hud-track li.is-done { color: var(--text); }
.hud-track li.is-current { background: var(--accent-dim); outline: 1px solid var(--accent); }
.hud-track li.is-next { color: var(--text); background: color-mix(in srgb, var(--reach) 10%, transparent); }
.hud-track li.is-next::after { content: "next"; margin-left: auto; font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); }
.hud-track-n { min-width: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--accent); }

.hud-abilities p { margin: 0 0 0.5rem; font-size: 0.82rem; line-height: 1.45; }
.hud-abilities strong { color: var(--accent); }

@media (max-width: 768px) {
    .hud-sheet-scroll { grid-template-columns: 1fr; }
    .hud-modal { padding: 0.5rem; }
    .hud-modal-panel--sheet { padding: 0.75rem; }
}

/* ===== Hover card (big view of a thumbnail) ===== */

.hud-card-peek {
    position: fixed;
    z-index: 70;
    width: 13.75rem;
    pointer-events: none;
    filter: drop-shadow(0 0.75rem 1.875rem rgba(0, 0, 0, 0.6));
    animation: fade-in 0.12s ease;
}
.hud-card-peek[hidden] { display: none; }
.hud-card-peek img { width: 100%; display: block; border-radius: 0.625rem; }
.hud-card-peek-note {
    margin-top: 0.375rem; padding: 0.25rem 0.5rem; border-radius: 0.375rem;
    background: var(--bg-panel); border: 1px solid var(--hud-edge);
    font-size: 0.75rem; text-align: center;
}

/* Mission text in the card inspection keeps its lines. */
#card-inspection-text { white-space: pre-line; }

@media (prefers-reduced-motion: reduce) {
    .hud-counter.is-bump-up, .hud-counter.is-bump-down, .hud-o.is-bump-up, .hud-o.is-bump-down,
    .hud-level-mark, .hud--open .hud-body { animation: none; }
    .hud .hud-card { transition: none; }
}

/* Narrow phones at a larger UI size (style.css): the slim bar keeps its
   counters in one row by dropping the "/limit" parts (the sheet has them). */
@media (max-width: 420px) {
    :root:is([data-ui-size="large"], [data-ui-size="xlarge"]) #hud .hud-bar .hud-sub { display: none; }
}

/* Halls of Terra: the affiliation row (the badges themselves are in cards.css). */
/* Only the held ones as badges, then "All 9" (hover or tap) for the list
   with their names. */
.hud-affs { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 0.2rem; }
.hud-affs-none { font-size: 0.7rem; color: var(--text-muted); }
.hud-affs-more {
    flex: none;
    margin-left: 0.25rem;
    padding: 0.125rem 0.4rem;
    border: 1px solid var(--border-light);
    border-radius: 0.625rem;
    background: none;
    color: var(--text-muted);
    font: inherit;
    font-size: 0.62rem;
    font-weight: 700;
    cursor: pointer;
}
.hud-affs-more:hover, .hud-affs-more[aria-expanded="true"] { color: var(--accent); border-color: var(--accent); }
.hud-affs-list {
    /* On the page (hud.js places it by the button): the panel clips. */
    position: fixed;
    z-index: 62;
    min-width: 14rem;
    padding: 0.5rem 0.625rem;
    border: 1px solid var(--border-light);
    border-radius: 0.5rem;
    background: var(--bg-panel);
    color: var(--text);
    box-shadow: 0 0.375rem 1.25rem rgb(0 0 0 / 0.35);
}
.hud-affs-list[hidden] { display: none; }
.aff-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.25rem; }
.aff-list-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.75rem; color: var(--text-muted); }
.aff-list-row.is-owned { color: var(--text); font-weight: 600; }
.aff-list-name { flex: 1; white-space: nowrap; }
.aff-list-held { font-size: 0.62rem; color: var(--accent); text-transform: uppercase; letter-spacing: 0.04em; }

/* Missions: the name band may take three lines (hudmodel.js nameFit). */
.hud-card:has(.hud-card-progress) .hud-card-name { -webkit-line-clamp: 3; top: 16%; }

/* Special abilities on hovering a portrait (hud.js showAbilityTip); built on .kw-tip. */
.ability-tip { max-width: 22rem; }
.ability-tip p { margin: 0.3rem 0 0; }
.ability-tip b { color: var(--accent); font-weight: 600; }

/* The character sheet: the full figure from the Digital Edition. */
.hud-sheet-img--figure { background: radial-gradient(circle at 50% 45%, #4a3c22, #16110a 75%); }
.hud-sheet-img--figure img { max-height: 60vh; width: 100%; object-fit: contain; }
.hud-sheet-printed { margin: 0; line-height: 1.4; }

/* What you may do now (server actions): ability buttons under the stats, and
   a Cast / Use tag on the cards you may use. */
.hud-actions { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.3rem; }
.hud-actions[hidden] { display: none; }
.hud-action { white-space: nowrap; border-color: var(--accent); color: var(--accent); }
.hud-card-use {
    position: absolute; top: 0.2rem; right: 0.2rem; z-index: 2;
    padding: 0.05rem 0.35rem; border-radius: 0.5rem;
    font-size: 0.6rem; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase;
    background: var(--accent); color: #1b1408; box-shadow: 0 1px 3px rgb(0 0 0 / 0.4);
}
