/* Initiative tracker - add row, combat list, active-turn marker, HP, conditions, kind. */

/* Player blue + bloodied amber are local; healthy-green / hostile-red use the global --good/--bad. */
.init { color: var(--text);
    --init-player: #2563eb; --init-monster: var(--bad);
    --init-hp-ok: var(--good); --init-hp-low: #d98a00; }
[data-theme="dark"] .init { --init-player: #60a5fa; --init-hp-low: #fbbf24; }
.init-intro { color: var(--muted); margin: 0.25rem 0 1.25rem; }

/* Add panel - a labelled surface card holding the add row. Inputs use .field, the submit uses
   .btn (base.css). The flex layout lives on the inner .init-add-row. */
.init-add { background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
    box-shadow: var(--shadow); padding: 0.85rem 0.9rem; margin-bottom: 1.25rem; }
.init-add-title { margin: 0 0 0.6rem; font-size: 0.72rem; font-weight: 700;
    letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); }
.init-add-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.init-add-row input[type="text"] { flex: 1 1 12rem; }
.init-add-row input[type="number"] { width: 5.5rem; }

/* Combat section header - small heading + a divider rule that introduces the tracker. */
.init-combat-head { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.9rem; }
.init-combat-title { margin: 0; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em;
    text-transform: uppercase; color: var(--faint); white-space: nowrap; }
.init-combat-rule { flex: 1; height: 1px; background: var(--border); }

/* Controls - turn buttons use .btn-outline (base.css). */
.init-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 1rem; margin-bottom: 1rem; }
.init-round { margin: 0; color: var(--muted); }
.init-round b { color: var(--text); font-size: 1.1rem; }
.init-turn { display: flex; gap: 0.4rem; }
.init-clear { margin-left: auto; color: var(--muted); }

/* List - each card is a 3-column grid: aside (kind badge + HP bar) | body (two stacked rows) | remove.
   The aside and remove stretch full height, so they straddle both rows of the body. The list keeps a
   gutter on both sides that the active card grows into, so the current turn reads as a bigger box. */
.init-list { list-style: none; margin: 0; padding: 0 1.5rem; display: flex; flex-direction: column; gap: 0.4rem; }
.init-card { position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 0.5rem 0.6rem;
    background: var(--surface); border: 1px solid var(--border); border-left: 4px solid transparent;
    border-radius: 10px; padding: 0.45rem 0.6rem; box-shadow: var(--shadow); }
.init-body { min-width: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.init-main { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.5rem 0.6rem; }
/* Aside: kind badge + vertical HP bar, full card height, immediately left of the body. */
.init-aside { align-self: stretch; display: flex; align-items: stretch; gap: 0.4rem; }
/* Active turn: pull the whole card into both gutters so it grows wider on each side + accent ring
   + tint + a touch more padding. */
.init-card.is-active { margin-left: -1.5rem; margin-right: -1.5rem; padding: 0.55rem 0.7rem;
    background: color-mix(in srgb, var(--surface) 86%, var(--accent));
    box-shadow: inset 0 0 0 1.5px var(--accent), var(--shadow); }
@media (prefers-reduced-motion: no-preference) {
    /* Plays each time a card becomes the active turn (next/prev): expands out of the row. */
    .init-card.is-active.is-entering { animation: init-turn-in 0.32s cubic-bezier(.2,.7,.2,1); }
    @keyframes init-turn-in {
        from { margin-left: 0; margin-right: 0; transform: scale(0.97); }
        to { margin-left: -1.5rem; margin-right: -1.5rem; transform: scale(1); }
    }
}
.init-card.is-active .init-init { border-color: var(--border-strong); }
.init-init { font: inherit; width: 3.2rem; text-align: center; color: var(--text); background: transparent;
    border: 1px solid var(--border); border-radius: 6px; padding: 0.25rem; flex: 0 0 auto; }
.init-name { font: inherit; width: 100%; color: var(--text); background: transparent;
    border: 1px solid var(--border); border-radius: 6px; padding: 0.25rem 0.4rem; }
.init-name:hover, .init-name:focus, .init-init:focus { border-color: var(--border-strong); }
.init-init:focus, .init-name:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
/* Per-field label groups (name + init): a tiny caps label stacked above the input. */
.init-grp { display: inline-flex; flex-direction: column; gap: 0.15rem; }
.init-grp-name { flex: 1 1 7rem; min-width: 0; }
.init-grp-init { flex: 0 0 auto; }
.init-minilabel { font-size: 0.6rem; font-weight: 700; letter-spacing: 0.06em;
    text-transform: uppercase; color: var(--faint); line-height: 1; padding-left: 0.15rem; }
/* Remove - right column, stretched so it spans both body rows. */
.init-remove { cursor: pointer; align-self: stretch; display: inline-flex; align-items: center; justify-content: center;
    font-size: 1rem; color: var(--faint);
    border: 1px solid var(--border-strong); border-radius: 8px; background: transparent;
    padding: 0 0.5rem; }
.init-remove:hover { border-color: var(--accent); color: var(--accent-strong); }

/* Player vs monster: left stripe + the badge (left column, stretched to span both rows). The badge
   shows the kind while alive, or the life-state (ghost/skull) at 0 HP. */
.init-card.kind-player { border-left-color: var(--init-player); }
.init-card.kind-monster { border-left-color: var(--init-monster); }
.init-kind { cursor: pointer; align-self: stretch; display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.25rem; width: 2.1rem;
    border: 1px solid var(--border); border-radius: 8px; background: transparent; padding: 0; }
.init-kind:hover { border-color: var(--border-strong); }
.init-card.kind-player .init-kind { color: var(--init-player); }
.init-card.kind-monster .init-kind { color: var(--init-monster); }
.init-card.is-unconscious .init-kind { color: var(--muted); }
.init-card.is-dead .init-kind { color: var(--init-monster); border-color: var(--init-monster); }

/* Type picker (add form): segmented radios with the same icons as the cards. */
.init-kindpick { display: inline-flex; align-items: stretch; min-inline-size: 0; margin: 0; padding: 0;
    border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.init-kindpick-opt { position: relative; display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; width: 2.6rem; font-size: 1.15rem; color: var(--muted); background: var(--surface); }
.init-kindpick-opt + .init-kindpick-opt { border-left: 1px solid var(--border); }
.init-kindpick-opt input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.init-kindpick-opt:has(input:checked) { background: var(--accent-weak); }
.init-kindpick-opt.kind-monster:has(input:checked) { color: var(--init-monster); }
.init-kindpick-opt.kind-player:has(input:checked) { color: var(--init-player); }
.init-kindpick-opt:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }

/* HP block - current/max + damage/heal amount (the ratio bar lives in .init-aside). */
.init-hp { display: inline-flex; flex-direction: column; gap: 0.15rem; flex: 0 0 auto; color: var(--muted); }
.init-hp-fields { display: inline-flex; align-items: center; gap: 0.3rem; }
.init-hp-cur, .init-hp-max, .init-hp-amt { font: inherit; width: 2.8rem; text-align: center; color: var(--text);
    background: transparent; border: 1px solid var(--border); border-radius: 6px; padding: 0.2rem; }
.init-hp-amt { width: 2.6rem; }
.init-hp-cur:focus, .init-hp-max:focus, .init-hp-amt:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.init-hp-sep { color: var(--faint); }
/* Vertical HP gauge in the aside: fill grows from the bottom (JS sets its height). */
.init-hp-bar { width: 7px; align-self: stretch; min-height: 1.6rem; border-radius: 999px;
    background: var(--border); overflow: hidden; flex: 0 0 auto;
    display: flex; flex-direction: column; justify-content: flex-end; }
.init-hp-fill { display: block; width: 100%; height: 100%; background: var(--init-hp-ok); }

/* Death saving throws - a downed player swaps the HP bar for two columns of pips (left = successes,
   right = failures), three each, laid out row-major (s0 f0 / s1 f1 / s2 f2). */
.init-deaths { display: none; grid-template-columns: repeat(2, auto); gap: 3px; align-self: center; }
.init-card.is-dying .init-deaths { display: grid; }
.init-card.is-dying .init-hp-bar { display: none; }
.init-pip { width: 12px; height: 12px; padding: 0; border-radius: 50%; cursor: pointer;
    border: 1.5px solid var(--border-strong); background: transparent; }
.init-pip.pip-success { border-color: color-mix(in srgb, var(--init-hp-ok) 55%, var(--border-strong)); }
.init-pip.pip-fail { border-color: color-mix(in srgb, var(--init-monster) 55%, var(--border-strong)); }
.init-pip.pip-success.is-on { background: var(--init-hp-ok); border-color: var(--init-hp-ok); }
.init-pip.pip-fail.is-on { background: var(--init-monster); border-color: var(--init-monster); }
.init-pip:hover { border-color: var(--accent); }
.init-pip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.init-card.is-bloodied .init-hp-fill { background: var(--init-hp-low); }
.init-dmg, .init-heal { font: inherit; cursor: pointer; line-height: 1; min-width: 1.7rem;
    border: 1px solid var(--border-strong); border-radius: 6px; background: transparent; color: var(--text); padding: 0.2rem 0.35rem; }
.init-dmg:hover { border-color: var(--init-monster); color: var(--init-monster); }
.init-heal:hover { border-color: var(--init-hp-ok); color: var(--init-hp-ok); }
/* No HP tracked yet: show only the max field (type a number to start tracking). */
.init-card:not(.has-hp) .init-hp-cur,
.init-card:not(.has-hp) .init-hp-sep,
.init-card:not(.has-hp) .init-hp-bar,
.init-card:not(.has-hp) .init-hp-amt,
.init-card:not(.has-hp) .init-dmg,
.init-card:not(.has-hp) .init-heal { display: none; }
/* Downed (0 HP). */
.init-card.is-down { opacity: 0.7; }
.init-card.is-down .init-name { text-decoration: line-through; color: var(--muted); }

/* Conditions - second body row: chips (linked) + add select. */
.init-conds { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; }
.init-chips { display: contents; }
.init-chip { display: inline-flex; align-items: center; gap: 0.1rem; font-size: 0.85rem;
    background: var(--accent-weak); border: 1px solid var(--border); border-radius: 999px; padding: 0.05rem 0.1rem 0.05rem 0.5rem; }
.init-chip-link { font: inherit; cursor: pointer; border: 0; background: transparent; padding: 0;
    color: var(--accent-strong); text-decoration: none; }
.init-chip-link:hover { text-decoration: underline; }
.init-chip-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* Condition TLDR: a native popover toggled by the chip button. Anchored above the chip where the
   browser supports CSS anchor positioning; otherwise the UA centers it (a mini-modal fallback). */
.init-cond-tldr { margin: 0; max-width: min(22rem, calc(100vw - 2rem));
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: var(--shadow);
    padding: 0.7rem 0.8rem; font-size: 0.85rem; line-height: 1.45; }
.init-cond-tldr-name { display: block; margin-bottom: 0.3rem; color: var(--accent-strong); }
.init-cond-tldr-body :where(p) { margin: 0 0 0.4rem; }
.init-cond-tldr-body :where(p):last-child { margin-bottom: 0; }
.init-cond-tldr-link { display: inline-block; margin-top: 0.5rem; font-size: 0.85em;
    color: var(--accent-strong); text-decoration: none; }
.init-cond-tldr-link:hover { text-decoration: underline; }

@supports (anchor-name: --a) {
    .init-cond-tldr { position-area: top span-right; position-try-fallbacks: bottom span-right, top span-left, bottom span-left;
        margin-bottom: 0.4rem; }
}
.init-chip-x { font: inherit; font-size: 0.8em; cursor: pointer; display: inline-flex; align-items: center;
    color: var(--faint); border: 0; background: transparent; padding: 0 0.3rem; border-radius: 999px; }
.init-chip-x:hover { color: var(--init-monster); }
.init-cond-add { font: inherit; font-size: 0.85rem; color: var(--muted); background: var(--surface);
    border: 1px dashed var(--border-strong); border-radius: 999px; padding: 0.15rem 0.4rem; cursor: pointer; }
.init-cond-add:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

.init-empty { color: var(--muted); }

/* One-shot motion for combat state changes. All gated behind reduced-motion; resting styles never
   set opacity:0, so under "reduce" cards simply render statically. Classes are added by the
   controller to freshly-built rows (see _applyFx / render in initiative_controller.js). */
@media (prefers-reduced-motion: no-preference) {
    /* New combatant card fades + slides in. */
    .init-card.is-adding { animation: init-card-in 0.3s cubic-bezier(.2,.7,.2,1); }
    @keyframes init-card-in {
        from { opacity: 0; transform: translateY(-0.4rem) scale(0.98); }
        to { opacity: 1; transform: none; }
    }
    /* Life-state badges idle in character: the ghost (unconscious) bobs up and down, the skull
       (dead) pulses. Continuous while in that state - not a transition. Only the icon moves; the
       badge button box (border/background) stays put. */
    .init-card.is-unconscious .init-kind svg { animation: init-ghost-float 2.4s ease-in-out infinite; }
    @keyframes init-ghost-float {
        0%, 100% { transform: translateY(0); }
        50% { transform: translateY(-0.18rem); }
    }
    .init-card.is-dead .init-kind svg { animation: init-skull-pulse 1.6s ease-in-out infinite; }
    @keyframes init-skull-pulse {
        0%, 100% { transform: scale(1); opacity: 1; }
        50% { transform: scale(1.12); opacity: 0.75; }
    }
    /* HP bar fill tweens between the previous and new ratio (custom props set inline by JS). */
    .init-card.is-hp-anim .init-hp-fill { animation: init-hp-move 0.4s cubic-bezier(.4,0,.2,1); }
    @keyframes init-hp-move {
        from { height: var(--hp-from); }
        to { height: var(--hp-to); }
    }
    /* Damage (red) / heal (green) glow pulse on the HP bar, concurrent with the fill tween. */
    .init-card.is-damaged .init-hp-bar { animation: init-glow-dmg 0.6s ease; }
    .init-card.is-healed .init-hp-bar { animation: init-glow-heal 0.6s ease; }
    @keyframes init-glow-dmg {
        0% { box-shadow: 0 0 0 0 transparent; }
        30% { box-shadow: 0 0 0.5rem 0.15rem var(--init-monster); }
        100% { box-shadow: 0 0 0 0 transparent; }
    }
    @keyframes init-glow-heal {
        0% { box-shadow: 0 0 0 0 transparent; }
        30% { box-shadow: 0 0 0.5rem 0.15rem var(--init-hp-ok); }
        100% { box-shadow: 0 0 0 0 transparent; }
    }
    /* Removed card fades + slides out; JS commits the data removal on the timer (see remove()). */
    .init-card.is-leaving { animation: init-card-out 0.25s ease forwards; pointer-events: none; }
    @keyframes init-card-out {
        from { opacity: 1; transform: none; }
        to { opacity: 0; transform: translateX(0.6rem) scale(0.98); }
    }
}
