/* 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;
    /* Side gutter the list reserves so the active card can grow into it (see .init-list /
       .init-card.is-active). Shrunk on mobile so cards stay wide enough for the HP fields. */
    --init-gutter: 1.5rem; }
[data-theme="dark"] .init { --init-player: #60a5fa; --init-hp-low: #fbbf24; }

/* 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); }

/* Turn bar - Prev | round medallion | Next, centred as one group. Rendered above and below the
   list (templates/dnd/_initiative-turnbar.html.twig) so the controls stay in reach at both ends of
   a long initiative order. Turn buttons are accent-filled .btn (base.css). */
.init-turnbar { display: flex; align-items: center; justify-content: center; gap: 1.1rem; margin: 0.5rem 0 1.6rem; }
.init-turnbar-bottom { margin: 2rem 0 0.5rem; }
.init-turnbar .btn { min-width: 6.5rem; }
/* Positioned so the medallion itself (not the block including the label below it) sits on the
   same vertical centre-line as the Prev/Next buttons; the "Round" label floats under it without
   adding to .init-round's own height. */
.init-round { position: relative; margin: 0; }
.init-round-num { display: grid; place-items: center; width: 2.6rem; height: 2.6rem; border-radius: 50%;
    border: 2px solid var(--accent); background: var(--accent-weak); color: var(--text);
    font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.init-round-label { position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
    margin-top: 0.2rem; white-space: nowrap; font-size: 0.62rem; font-weight: 700;
    letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); }
/* Clear lives in its own footer, well below the bottom turn bar (out of the way of Prev/Next -
   and of a mis-click) and set off by a single divider so it doesn't read as part of the controls
   above. Even padding puts 20px between that divider and the button; the negative margin-bottom
   cancels out .tool-content's own 56px margin-top (tool-content.css) so the *next* divider -
   .tool-content's own border-top, on tool pages - lands the same 20px below the button instead of
   ~76px, without stacking a second line right under this one. In the workspace stack (My Screen)
   there's no .tool-content to cancel against, so the negative margin just trims trailing space at
   the bottom of that tool's panel - harmless, since the panel scrolls independently. */
.init-footer { display: flex; justify-content: center; margin: 2.5rem 0 -56px; padding: 1.25rem 0;
    border-top: 1px solid var(--border); }
.init-clear { 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 var(--init-gutter); 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: calc(-1 * var(--init-gutter)); margin-right: calc(-1 * var(--init-gutter)); 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: calc(-1 * var(--init-gutter)); margin-right: calc(-1 * var(--init-gutter)); 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); }
/* Armour class: a small, deliberately prominent stat (used constantly mid-combat, unlike
   initiative which only matters for the initial sort). */
.init-ac { font: inherit; font-weight: 600; width: 3rem; text-align: center; color: var(--text);
    background: var(--accent-weak); border: 1px solid var(--border-strong); border-radius: 6px; padding: 0.25rem; flex: 0 0 auto; }
.init-ac::placeholder { font-weight: 400; color: var(--faint); }
.init-ac:hover { border-color: var(--accent); }
.init-ac:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
/* Per-field label groups (name + init + ac): 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, .init-grp-ac { 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-color: var(--surface);
    border: 1px dashed var(--border-strong); border-radius: 999px; padding: 0.15rem 1.2rem 0.15rem 0.4rem; cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%238b95a8' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 0.4rem center; background-size: 0.55rem; }
.init-cond-add:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

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

/* Mobile: claw back horizontal space so cards stay wide. Shrink the side gutter, tighten card
   padding, and let the HP number fields shrink (min-width:0 + smaller bases + tighter gaps) so the
   cur / max / amount / damage / heal row fits instead of overflowing on narrow screens. */
@media (max-width: 560px) {
    .init { --init-gutter: 0.5rem; }
    .init-card { padding: 0.45rem 0.5rem; }
    .init-card.is-active { padding: 0.5rem 0.6rem; }
    .init-hp-fields { gap: 0.2rem; }
    .init-hp-cur, .init-hp-max { width: 2.3rem; min-width: 0; }
    .init-hp-amt { width: 2.1rem; min-width: 0; }
    .init-init, .init-ac { width: 2.6rem; min-width: 0; }
    .init-turnbar { gap: 0.6rem; }
    .init-turnbar .btn { min-width: 0; padding: 0.5rem 0.7rem; }
}

/* 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); }
    }
}
