/* HP Mode overlay — fighting-game health HUD (docs/hp.md).
 *
 * OBS rule: the page is TRANSPARENT. html/body/.hp-stage never get a fill; only
 * the bars, portraits and the finish card paint. Colours of the two sides come
 * from --c1/--c2 (preset slot colours, set by hp.js). */

html, body {
    margin: 0;
    padding: 0;
    background: transparent;
    overflow: hidden;
    scrollbar-width: none;
}

:root {
    --c1: #ec4899;
    --c2: #3b82f6;
    --hp-hi: #34d399;
    --hp-mid: #facc15;
    --hp-low: #f43f5e;
    --hp-trail: #fb7185; /* hp.bar_colors — overridden by hp.js from settings */
    --ink: #ffffff;
    --bar-h: 34px;
    --font-num: 'Bebas Neue', 'Noto Sans Thai', system-ui, sans-serif;
    --font-text: 'Noto Sans Thai', system-ui, sans-serif;
}

.hp-stage {
    position: relative;
    width: 100vw;
    min-height: 100vh;
    background: transparent;
    font-family: var(--font-text);
    color: var(--ink);
    box-sizing: border-box;
    padding: 18px 22px 0;
}
.hp-stage[data-state="empty"] { visibility: hidden; }

/* ── HUD row ─────────────────────────────────────────────────────────────── */
.hp-hud {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 14px;
}

.hp-side {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}
.hp-side--r { flex-direction: row; }
.hp-side--l { --c: var(--c1); }
.hp-side--r { --c: var(--c2); }

/* ── Portrait + win badge ────────────────────────────────────────────────── */
.hp-portrait {
    position: relative;
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.hp-avatar {
    width: 78px;
    height: 78px;
    border-radius: 50%;
    padding: 3px;
    background: conic-gradient(from 210deg, var(--c), #ffffff 40%, var(--c) 70%);
    box-shadow: 0 0 18px var(--c); /* softer color-mix version in the @supports block */
    transition: filter .4s ease, transform .2s ease;
}
.hp-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    background: rgba(0, 0, 0, .55);
    display: block;
}
.hp-avatar img[src=""] { visibility: hidden; }
.hp-win {
    margin-top: -12px;
    padding: 2px 10px;
    border-radius: 999px;
    background: linear-gradient(180deg, #fde047, #f59e0b);
    color: #3b1d00;
    font: 700 13px/1.25 var(--font-text);
    letter-spacing: .3px;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .45);
    position: relative;
    z-index: 2;
}
.hp-win.is-bump { animation: hp-win-bump .6s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes hp-win-bump { 0% { transform: scale(.6); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }

/* ── Meter (name + bar + damage pops) ────────────────────────────────────── */
.hp-meter {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
}
/* Name row: the name on the portrait side, the bound gift icons right after it
 * (mirrored on the right side). */
.hp-head {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    margin-bottom: 5px;
}
.hp-side--r .hp-head { flex-direction: row-reverse; }
.hp-name {
    flex: 0 1 auto;
    min-width: 0;
    font: 700 18px/1.2 var(--font-text);
    text-shadow: 0 2px 6px rgba(0, 0, 0, .8);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.hp-side--r .hp-name { text-align: right; }

/* Bound gifts — what a viewer sends to hit the other side for this cast. */
.hp-gifts {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 2px 6px;
    border-radius: 999px;
    background: rgba(0, 0, 0, .5);
    border: 1px solid var(--c); /* lighter color-mix version in the @supports block */
    box-shadow: 0 2px 8px rgba(0, 0, 0, .45);
}
.hp-gifts[hidden] { display: none; }
.hp-gift {
    width: 26px;
    height: 26px;
    object-fit: contain;
    display: block;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .6));
}
.hp-gift-more {
    font: 400 17px/1 var(--font-num);
    letter-spacing: .5px;
    padding: 0 2px;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .8);
}
.hp-side.is-ko .hp-gifts { filter: grayscale(1); opacity: .6; }

.hp-bar {
    position: relative;
    height: var(--bar-h);
    border-radius: 8px;
    overflow: hidden;
    background: linear-gradient(180deg, rgba(10, 12, 24, .82), rgba(30, 32, 48, .78));
    border: 2px solid var(--c); /* lighter color-mix version in the @supports block */
    box-shadow: 0 4px 14px rgba(0, 0, 0, .55), inset 0 0 0 1px rgba(255, 255, 255, .06);
    transform: skewX(-12deg);
}
.hp-side--r .hp-bar { transform: skewX(12deg); }

/* Fill and trail are anchored at the OUTER edge (the portrait side) and drain
 * toward the centre — the classic versus-HUD reading. */
.hp-bar-fill,
.hp-bar-trail {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
    transform-origin: left center;
}
.hp-side--r .hp-bar-fill,
.hp-side--r .hp-bar-trail { transform-origin: right center; }

.hp-bar-trail {
    /* = linear-gradient(color-mix(trail 12%, white), trail), painted as white
     * fading out over the trail colour — the same pixels, no color-mix(). */
    background: linear-gradient(180deg, rgba(255, 255, 255, .88), rgba(255, 255, 255, 0)), var(--hp-trail);
    opacity: .85;
    transform: scaleX(var(--trail, 1));
    transition: transform .9s cubic-bezier(.4, 0, .2, 1) .35s;
}
/* The HP fill and the damage trail use NO color-mix(): it needs Chromium 111+,
 * and OBS 30 (CEF 103) / older TikTok LIVE Studio drop the whole background —
 * the bars rendered empty on those PCs. The darker edge is a translucent black
 * layer over the colour (rgba(0,0,0,.25) over c = color-mix(c 75%, #000)). */
.hp-bar-fill {
    --tone: var(--hp-hi);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, .35), rgba(255, 255, 255, 0) 45%),
        linear-gradient(90deg, rgba(0, 0, 0, .25), rgba(0, 0, 0, 0)),
        var(--tone);
    transform: scaleX(var(--fill, 1));
    transition: transform .28s cubic-bezier(.3, .8, .3, 1), background-color .3s;
}
.hp-side--r .hp-bar-fill {
    background:
        linear-gradient(180deg, rgba(255, 255, 255, .35), rgba(255, 255, 255, 0) 45%),
        linear-gradient(270deg, rgba(0, 0, 0, .25), rgba(0, 0, 0, 0)),
        var(--tone);
}
.hp-bar-fill[data-tone="mid"] { --tone: var(--hp-mid); }
.hp-bar-fill[data-tone="low"] { --tone: var(--hp-low); animation: hp-low-pulse 0.9s ease-in-out infinite; }
@keyframes hp-low-pulse { 50% { filter: brightness(1.45) saturate(1.3); } }

.hp-bar-shine {
    position: absolute;
    inset: 0;
    background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, .55) 50%, transparent 70%);
    background-size: 220% 100%;
    animation: hp-shine 3.2s linear infinite;
    mix-blend-mode: overlay;
}
@keyframes hp-shine { from { background-position: 160% 0; } to { background-position: -60% 0; } }

.hp-bar-ticks {
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 2px), rgba(0, 0, 0, .35) calc(10% - 2px) 10%);
    pointer-events: none;
}

.hp-bar-value {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    padding: 0 14px;
    gap: 6px;
    transform: skewX(12deg);
    font-family: var(--font-num);
    text-shadow: 0 2px 4px rgba(0, 0, 0, .85), 0 0 2px #000;
    pointer-events: none;
}
.hp-side--r .hp-bar-value { justify-content: flex-end; transform: skewX(-12deg); }
.hp-bar-value b { font-size: 28px; font-weight: 400; letter-spacing: 1px; }
.hp-bar-value i { font-style: normal; font-size: 17px; opacity: .8; }

/* Hit reaction — shake the meter, flash the portrait. */
.hp-side.is-hit .hp-bar { animation: hp-shake-l .38s ease-out; }
.hp-side--r.is-hit .hp-bar { animation: hp-shake-r .38s ease-out; }
.hp-side.is-hit .hp-avatar { animation: hp-flash .38s ease-out; }
@keyframes hp-shake-l {
    0%, 100% { transform: skewX(-12deg) translateX(0); }
    20% { transform: skewX(-12deg) translateX(-7px); }
    45% { transform: skewX(-12deg) translateX(6px); }
    70% { transform: skewX(-12deg) translateX(-3px); }
}
@keyframes hp-shake-r {
    0%, 100% { transform: skewX(12deg) translateX(0); }
    20% { transform: skewX(12deg) translateX(7px); }
    45% { transform: skewX(12deg) translateX(-6px); }
    70% { transform: skewX(12deg) translateX(3px); }
}
@keyframes hp-flash { 0% { filter: brightness(2.2) saturate(0); transform: scale(1.06); } 100% { filter: none; transform: none; } }

/* Floating damage numbers. */
.hp-pops {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 2px);
    height: 0;
    pointer-events: none;
}
.hp-pop {
    position: absolute;
    top: 0;
    font: 400 30px/1 var(--font-num);
    color: #fecdd3;
    -webkit-text-stroke: 1px #9f1239;
    text-shadow: 0 2px 6px rgba(0, 0, 0, .7);
    animation: hp-pop 1.1s cubic-bezier(.2, .8, .3, 1) forwards;
    white-space: nowrap;
}
.hp-side--l .hp-pop { right: 8%; }
.hp-side--r .hp-pop { left: 8%; }
.hp-pop.is-big { font-size: 44px; color: #fff7ed; -webkit-text-stroke: 1.5px #c2410c; }
@keyframes hp-pop {
    0% { opacity: 0; transform: translateY(-6px) scale(.5); }
    15% { opacity: 1; transform: translateY(0) scale(1.15); }
    100% { opacity: 0; transform: translateY(26px) scale(1); }
}

/* Heal (docs/hp.md §4.3) — green "+N" and a green pulse on the bar/portrait. */
.hp-pop.is-heal { color: #bbf7d0; -webkit-text-stroke: 1px #047857; }
.hp-side.is-heal .hp-bar { animation: hp-heal-glow .9s ease-out; }
.hp-side.is-heal .hp-avatar { animation: hp-heal-avatar .9s ease-out; }
@keyframes hp-heal-glow {
    0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, .9), 0 4px 14px rgba(0, 0, 0, .55); }
    100% { box-shadow: 0 0 0 14px rgba(52, 211, 153, 0), 0 4px 14px rgba(0, 0, 0, .55); }
}
@keyframes hp-heal-avatar { 0% { filter: brightness(1.6) saturate(1.4) hue-rotate(60deg); } 100% { filter: none; } }

/* Knocked out side. */
.hp-side.is-ko .hp-avatar { filter: grayscale(1) brightness(.6); }
.hp-side.is-ko .hp-name { opacity: .6; text-decoration: line-through; text-decoration-thickness: 2px; }
.hp-side.is-winner .hp-avatar { animation: hp-winner-glow 1.4s ease-in-out infinite; }
@keyframes hp-winner-glow {
    50% { box-shadow: 0 0 32px 6px var(--c); transform: scale(1.05); }
}

/* ── Centre: clock / VS / round chip ─────────────────────────────────────── */
.hp-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 92px;
}
.hp-clock {
    min-width: 84px;
    padding: 4px 14px 2px;
    border-radius: 12px;
    text-align: center;
    font: 400 42px/1 var(--font-num);
    letter-spacing: 1px;
    background: linear-gradient(180deg, rgba(17, 24, 39, .9), rgba(3, 7, 18, .9));
    border: 2px solid rgba(255, 255, 255, .25);
    box-shadow: 0 4px 16px rgba(0, 0, 0, .6);
    text-shadow: 0 0 10px rgba(255, 255, 255, .35);
}
.hp-clock.is-vs { font-size: 36px; background: linear-gradient(135deg, var(--c1), var(--c2)); border-color: rgba(255, 255, 255, .6); }
.hp-clock.is-warn { color: #fecaca; border-color: #f43f5e; animation: hp-clock-warn 1s steps(2) infinite; }
@keyframes hp-clock-warn { 50% { color: #ffffff; background: rgba(159, 18, 57, .9); } }
.hp-round {
    padding: 1px 10px;
    border-radius: 999px;
    font: 700 12px/1.5 var(--font-text);
    letter-spacing: .5px;
    background: rgba(0, 0, 0, .55);
    border: 1px solid rgba(255, 255, 255, .25);
}

/* ── Finish card (K.O. / TIME UP + winner) ───────────────────────────────── */
.hp-finish {
    position: absolute;
    left: 0;
    right: 0;
    top: 140px;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
}
.hp-finish[hidden] { display: none; }
.hp-finish-stamp {
    font: 400 132px/0.9 var(--font-num);
    letter-spacing: 6px;
    color: #fff7ed;
    -webkit-text-stroke: 3px #b91c1c;
    text-shadow: 0 0 24px rgba(244, 63, 94, .9), 0 6px 0 #7f1d1d, 0 12px 26px rgba(0, 0, 0, .7);
    animation: hp-stamp .7s cubic-bezier(.2, 1.4, .4, 1) both;
}
.hp-finish.is-time .hp-finish-stamp {
    font-size: 96px;
    -webkit-text-stroke-color: #1d4ed8;
    text-shadow: 0 0 24px rgba(59, 130, 246, .9), 0 6px 0 #1e3a8a, 0 12px 26px rgba(0, 0, 0, .7);
}
.hp-finish.is-draw .hp-finish-stamp { -webkit-text-stroke-color: #6b7280; text-shadow: 0 6px 0 #374151, 0 12px 26px rgba(0, 0, 0, .7); }
@keyframes hp-stamp {
    0% { opacity: 0; transform: scale(3) rotate(-8deg); filter: blur(6px); }
    60% { opacity: 1; transform: scale(.92) rotate(2deg); filter: none; }
    100% { transform: scale(1) rotate(-3deg); }
}
.hp-finish-winner {
    margin-top: 10px;
    padding: 6px 22px;
    border-radius: 12px;
    font: 900 26px/1.3 var(--font-text);
    background: linear-gradient(90deg, transparent, rgba(0, 0, 0, .7) 15%, rgba(0, 0, 0, .7) 85%, transparent);
    text-shadow: 0 2px 6px rgba(0, 0, 0, .8);
    animation: hp-winner-in .5s ease-out .45s both;
}
.hp-finish-winner:empty { display: none; }
@keyframes hp-winner-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* Narrow browser sources (e.g. 720px TikTok Studio layers). */
@media (max-width: 760px) {
    :root { --bar-h: 26px; }
    .hp-avatar { width: 56px; height: 56px; }
    .hp-name { font-size: 14px; }
    .hp-gift { width: 20px; height: 20px; }
    .hp-gift-more { font-size: 14px; }
    .hp-bar-value b { font-size: 21px; }
    .hp-bar-value i { font-size: 13px; }
    .hp-clock { font-size: 30px; min-width: 64px; }
    .hp-finish-stamp { font-size: 88px; }
    .hp-finish { top: 100px; }
}

/* ── Revive countdown (docs/hp.md §4.5) ─────────────────────────────────────
 * A card under the HUD while a knocked-out side's revive window is open. Only
 * the card paints a background (the page stays transparent). Plain colours, no
 * color-mix() — the same old-engine rule as the bars (§4.0). */
.hp-revive {
    --rc: var(--c1);
    position: absolute;
    left: 50%;
    top: 128px;
    transform: translateX(-50%);
    min-width: 300px;
    padding: 10px 22px 12px;
    border-radius: 18px;
    border: 3px solid var(--rc);
    background: rgba(10, 6, 20, .78);
    box-shadow: 0 0 22px var(--rc), 0 10px 26px rgba(0, 0, 0, .55);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    pointer-events: none;
    animation: hp-revive-in .45s cubic-bezier(.2, 1.4, .4, 1) both;
}
.hp-revive[hidden] { display: none; }
.hp-revive[data-side="2"] { --rc: var(--c2); }
.hp-revive-title {
    font: 400 46px/1 var(--font-num);
    letter-spacing: 6px;
    color: #fef9c3;
    text-shadow: 0 0 14px var(--rc), 0 3px 0 rgba(0, 0, 0, .6);
    animation: hp-revive-pulse 1s ease-in-out infinite;
}
.hp-revive-name {
    font: 700 18px/1.2 var(--font-text);
    color: var(--ink);
    max-width: 280px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.hp-revive-row { display: flex; align-items: center; gap: 10px; }
.hp-revive-gift { width: 44px; height: 44px; object-fit: contain; }
.hp-revive-gift[hidden] { display: none; }
.hp-revive-count { font: 400 38px/1 var(--font-num); letter-spacing: 2px; color: var(--ink); }
.hp-revive-bar {
    width: 240px;
    height: 10px;
    border-radius: 6px;
    background: rgba(255, 255, 255, .18);
    overflow: hidden;
}
.hp-revive-fill {
    --fill: 0;
    width: 100%;
    height: 100%;
    background: #34d399;
    transform-origin: left center;
    transform: scaleX(var(--fill));
    transition: transform .3s ease-out;
}
.hp-revive-sec {
    font: 400 64px/1 var(--font-num);
    color: #fff;
    text-shadow: 0 0 12px var(--rc), 0 4px 0 rgba(0, 0, 0, .55);
}
.hp-revive.is-warn .hp-revive-sec { color: #fca5a5; animation: hp-revive-pulse .5s ease-in-out infinite; }
/* The side waiting to be revived: its avatar pulses instead of greying out. */
.hp-side.is-reviving .hp-avatar { animation: hp-revive-pulse .9s ease-in-out infinite; }
@keyframes hp-revive-in {
    from { opacity: 0; transform: translateX(-50%) scale(.6); }
    to   { opacity: 1; transform: translateX(-50%) scale(1); }
}
@keyframes hp-revive-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: .55; }
}

/* Progressive enhancement: engines with color-mix() get the softer tints;
 * older ones keep the plain var(--c) rules above. Never put a bar fill here. */
@supports (color: color-mix(in srgb, red, blue)) {
    .hp-avatar { box-shadow: 0 0 18px color-mix(in srgb, var(--c) 70%, transparent); }
    .hp-gifts { border-color: color-mix(in srgb, var(--c) 70%, #ffffff 30%); }
    .hp-bar { border-color: color-mix(in srgb, var(--c) 75%, #ffffff 25%); }
    @keyframes hp-winner-glow {
        50% { box-shadow: 0 0 32px 6px color-mix(in srgb, var(--c) 85%, #fff 15%); transform: scale(1.05); }
    }
}
