/* Turn-based battle screen */
.bf-screen {
    display: flex;
    flex-direction: column;
    gap: 8px;
    animation: mm-fade 0.3s ease both;
}

/* Top bar */
.bf-topbar {
    display: flex;
    align-items: center;
    gap: 10px;
}

.bf-round {
    font-size: 15px;
    font-weight: 900;
    font-style: italic;
    color: #ffcc00;
    text-shadow: 2px 2px 0 #b33a2b;
}

.bf-mode {
    flex: 1;
    font-size: 12px;
    font-weight: bold;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.55);
}

.bf-flag {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    color: #ff7a6b;
    font-size: 18px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.bf-flag:hover {
    background: rgba(255, 122, 107, 0.2);
}

.bf-stakes {
    margin: -4px 0 0;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.45);
}

/* Arena: opponent top-right, player bottom-left, HUDs opposite each */
.bf-arena {
    position: relative;
    height: 300px;
    flex-shrink: 0;
    border-radius: 16px;
    overflow: hidden;
    background:
        radial-gradient(ellipse 80% 40% at 50% 100%, rgba(76, 217, 123, 0.18), transparent 70%),
        linear-gradient(180deg, #1E3A5F 0%, #24324a 55%, #1b2a22 100%);
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.5);
}

.bf-fighter {
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: flex-end;
}

.bf-fighter-opp {
    top: 30px;
    right: 4%;
    width: 40%;
    height: 120px;
    animation: bf-enter-right 0.6s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.bf-fighter-self {
    bottom: 14px;
    left: 4%;
    width: 46%;
    height: 140px;
    animation: bf-enter-left 0.6s cubic-bezier(0.22, 1, 0.36, 1) 0.1s both;
}

.bf-platform {
    position: absolute;
    bottom: -6px;
    left: 8%;
    right: 8%;
    height: 22px;
    border-radius: 50%;
    background: radial-gradient(ellipse, rgba(0, 0, 0, 0.45), transparent 70%);
}

/* The shadow sits on the wrapper so a variant's own filter on the sprite isn't overridden */
.bf-sprite {
    position: relative;
    height: 100%;
    display: flex;
    align-items: flex-end;
    filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.4));
}

.bf-sprite img {
    max-height: 100%;
    max-width: 100%;
    object-fit: contain;
}

.bf-sprite .bf-creature {
    height: 100%;
    max-width: 100%;
    aspect-ratio: 1;
}

/* Animations restart by alternating between identical a/b keyframes on consecutive events */
.bf-fighter-self.is-attacking-a .bf-sprite { animation: bf-lunge-up-a 0.55s ease both; }
.bf-fighter-self.is-attacking-b .bf-sprite { animation: bf-lunge-up-b 0.55s ease both; }
.bf-fighter-opp.is-attacking-a .bf-sprite { animation: bf-lunge-down-a 0.55s ease both; }
.bf-fighter-opp.is-attacking-b .bf-sprite { animation: bf-lunge-down-b 0.55s ease both; }
.bf-fighter.is-hit-a .bf-sprite { animation: bf-hit-a 0.5s ease both; }
.bf-fighter.is-hit-b .bf-sprite { animation: bf-hit-b 0.5s ease both; }
.bf-fighter.is-dodging-a .bf-sprite { animation: bf-dodge-a 0.45s ease both; }
.bf-fighter.is-dodging-b .bf-sprite { animation: bf-dodge-b 0.45s ease both; }
.bf-fighter.is-healing-a .bf-sprite { animation: bf-heal-a 0.7s ease both; }
.bf-fighter.is-healing-b .bf-sprite { animation: bf-heal-b 0.7s ease both; }

.bf-fighter.is-fainted .bf-sprite {
    animation: bf-faint 0.8s ease-in both;
}

.bf-fighter.is-fainted .bf-platform {
    opacity: 0.4;
}

/* Guard bubble */
.bf-shield {
    position: absolute;
    inset: -6% 4% -4%;
    border: 2px solid rgba(var(--sc-primary-rgb), 0.8);
    border-radius: 50%;
    background: radial-gradient(circle, transparent 55%, rgba(var(--sc-primary-rgb), 0.25));
    box-shadow: 0 0 18px rgba(var(--sc-primary-rgb), 0.5);
    pointer-events: none;
    animation: bf-shield-up 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both, bf-shield-pulse 1.2s ease-in-out 0.35s infinite;
}

/* Impact flash and floating numbers */
.bf-burst {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 110px;
    height: 110px;
    margin: -55px 0 0 -55px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0) 65%);
    pointer-events: none;
    animation: bf-burst 0.45s ease-out both;
}

.bf-burst.is-critical {
    width: 160px;
    height: 160px;
    margin: -80px 0 0 -80px;
    background: radial-gradient(circle, rgba(255, 204, 0, 0.95), rgba(255, 122, 107, 0.4) 40%, transparent 70%);
}

.bf-burst.is-heal {
    background: radial-gradient(circle, rgba(76, 217, 123, 0.8), transparent 65%);
}

.bf-burst.is-miss {
    display: none;
}

.bf-float {
    position: absolute;
    top: 10%;
    left: 50%;
    z-index: 2;
    font-size: 26px;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 0 8px rgba(0, 0, 0, 0.8), 2px 2px 0 #b33a2b;
    white-space: nowrap;
    pointer-events: none;
    animation: bf-float 1s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.bf-float.is-critical {
    font-size: 34px;
    color: #ffcc00;
}

.bf-float.is-heal {
    color: #4cd97b;
    text-shadow: 0 0 8px rgba(0, 0, 0, 0.8), 2px 2px 0 #1b5e3a;
}

.bf-float.is-miss {
    font-size: 20px;
    color: rgba(255, 255, 255, 0.8);
    text-shadow: 0 0 8px rgba(0, 0, 0, 0.8);
}

.bf-shake-a { animation: bf-shake-a 0.4s ease both; }
.bf-shake-b { animation: bf-shake-b 0.4s ease both; }

/* HUDs */
.bf-hud {
    position: absolute;
    z-index: 3;
    width: 48%;
    padding: 8px 10px;
    border-radius: 12px;
    background: rgba(10, 12, 18, 0.72);
    backdrop-filter: blur(2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.bf-hud-opp {
    top: 10px;
    left: 10px;
    border-left: 3px solid #ff7a6b;
    animation: mm-enter-top 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.bf-hud-self {
    bottom: 12px;
    right: 10px;
    border-right: 3px solid var(--sc-primary);
    animation: mm-enter-bottom 0.45s cubic-bezier(0.22, 1, 0.36, 1) 0.1s both;
}

.bf-hud-top,
.bf-hud-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.bf-hud-name {
    overflow: hidden;
    font-weight: bold;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.bf-hud-level {
    flex-shrink: 0;
    font-size: 12px;
    font-weight: bold;
    color: #ffcc00;
}

.bf-hp {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 4px 0;
}

.bf-hp-label {
    font-size: 10px;
    font-weight: 900;
    color: #ffcc00;
}

.bf-hp-track {
    position: relative;
    flex: 1;
    height: 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    overflow: hidden;
}

.bf-hp-fill,
.bf-hp-ghost {
    position: absolute;
    inset: 0 auto 0 0;
    border-radius: inherit;
}

/* The ghost trails behind the real bar so each hit leaves a visible chunk */
.bf-hp-ghost {
    background: #ff7a6b;
    transition: width 0.6s ease 0.45s;
}

.bf-hp-fill {
    transition: width 0.45s ease, background-color 0.3s ease;
}

.bf-hp-fill.is-high { background: #4cd97b; }
.bf-hp-fill.is-mid { background: #ffcc00; }
.bf-hp-fill.is-low {
    background: #ff5a4a;
    animation: bf-low-hp 0.9s ease-in-out infinite;
}

.bf-hud-bottom {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.7);
}

.bf-hud-weak {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.bf-hud-status {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    color: #4cd97b;
    font-weight: bold;
    animation: mm-pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.bf-hud-hp {
    font-variant-numeric: tabular-nums;
    font-weight: bold;
    color: #fff;
}

/* Narration box */
.bf-console {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 68px;
    padding: 10px 12px;
    border: 2px solid rgba(72, 142, 255, 0.5);
    border-radius: 12px;
    background: linear-gradient(135deg, #16263d, #1d3352);
}

.bf-narration {
    display: flex;
    flex-direction: column;
    animation: bf-type-in 0.25s ease both;
}

.bf-narration-main {
    font-weight: bold;
}

.bf-narration-detail {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.75);
}

.bf-narration-detail.is-critical { color: #ffcc00; font-weight: bold; }
.bf-narration-detail.is-heal { color: #4cd97b; }
.bf-narration-detail.is-miss { color: rgba(255, 255, 255, 0.55); font-style: italic; }

.bf-timer {
    position: relative;
    height: 16px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    overflow: hidden;
}

.bf-timer-fill {
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--sc-primary), #4cd97b);
    transition: width 0.25s linear;
}

.bf-timer.is-urgent .bf-timer-fill {
    background: linear-gradient(90deg, #ff5a4a, #ffcc00);
    animation: bf-low-hp 0.6s ease-in-out infinite;
}

.bf-timer-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
}

/* Move buttons */
.bf-moves {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.bf-move {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    min-height: 58px;
    padding: 8px 10px;
    border: 2px solid rgba(72, 142, 255, 0.6);
    border-radius: 12px;
    background-image: linear-gradient(135deg, #1E3A5F, #2D507B);
    color: #fff;
    text-align: left;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
    animation: mm-rise-in 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.bf-move:nth-child(2) { animation-delay: 0.05s; }
.bf-move:nth-child(3) { animation-delay: 0.1s; }
.bf-move:nth-child(4) { animation-delay: 0.15s; }

.bf-move:hover:not(:disabled) {
    transform: translateY(-2px);
    border-color: var(--sc-primary);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35), 0 0 10px rgba(var(--sc-primary-rgb), 0.3);
}

.bf-move:active:not(:disabled) {
    transform: scale(0.97);
}

.bf-move:disabled {
    cursor: default;
}

.bf-moves.is-locked .bf-move:not(.is-chosen) {
    opacity: 0.45;
}

.bf-move.is-chosen {
    border-color: #4cd97b;
    box-shadow: 0 0 14px rgba(76, 217, 123, 0.5);
}

.bf-move.is-heal {
    border-color: rgba(76, 217, 123, 0.6);
    background-image: linear-gradient(135deg, #1d3d33, #255443);
}

.bf-move.is-super {
    border-color: #ffcc00;
    box-shadow: 0 0 12px rgba(255, 204, 0, 0.35);
}

.bf-move-guard {
    border-color: rgba(255, 255, 255, 0.3);
    background-image: linear-gradient(135deg, #2a2f3d, #383f52);
}

.bf-move-name {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: bold;
}

.bf-move-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 2px 8px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.65);
}

.bf-move-element {
    color: var(--sc-primary);
}

.bf-move-badge {
    position: absolute;
    top: 6px;
    right: 8px;
    padding: 0 6px;
    border-radius: 999px;
    background: #ffcc00;
    color: var(--sc-bg);
    font-size: 11px;
    font-weight: 900;
}

.bf-move-locked {
    position: absolute;
    right: 8px;
    bottom: 6px;
    font-size: 18px;
    color: #4cd97b;
    animation: mm-pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

/* Battle log */
.bf-log-toggle {
    align-self: center;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border: none;
    background: none;
    color: rgba(255, 255, 255, 0.6);
    font-size: 13px;
    cursor: pointer;
}

.bf-log {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 200px;
    padding: 8px 10px;
    overflow-y: auto;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
}

.bf-log-round {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.bf-log-title {
    font-size: 11px;
    font-weight: bold;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #ffcc00;
}

.bf-log-line {
    padding-left: 8px;
    font-size: 12px;
    border-left: 2px solid transparent;
}

.bf-log-line.is-self { border-left-color: var(--sc-primary); }
.bf-log-line.is-opp { border-left-color: #ff7a6b; }

/* Forfeit confirmation */
.bf-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.6);
    animation: mm-fade 0.2s ease both;
}

.bf-modal {
    max-width: 320px;
    padding: 20px;
    border: 2px solid rgba(255, 122, 107, 0.6);
    border-radius: 16px;
    background: #1c2433;
    text-align: center;
    animation: mm-pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.bf-modal h5 {
    margin: 6px 0;
    font-weight: bold;
}

.bf-modal .mm-actions {
    justify-content: center;
}

.bf-modal-icon {
    font-size: 36px;
    color: #ff7a6b;
}

.bf-btn-danger {
    border-color: #ff7a6b;
    background: #ff7a6b;
}

.bf-btn-danger:hover {
    box-shadow: 0 0 14px rgba(255, 122, 107, 0.5);
}

/* Results */
.bf-results {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    min-height: 100%;
    padding-top: 10px;
    text-align: center;
}

.bf-results-title {
    margin: 0;
    font-size: 52px;
    font-weight: 900;
    font-style: italic;
    line-height: 1;
    animation: mm-vs-slam 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both, mm-shake 0.3s ease 0.45s;
}

.bf-results.is-victory .bf-results-title {
    color: #ffcc00;
    text-shadow: 0 0 22px rgba(255, 204, 0, 0.6), 3px 3px 0 #b33a2b;
}

.bf-results.is-defeat .bf-results-title {
    color: #ff7a6b;
    text-shadow: 0 0 18px rgba(255, 122, 107, 0.4), 3px 3px 0 #3b1a16;
}

.bf-results-subtitle {
    margin: 0;
    color: rgba(255, 255, 255, 0.7);
    animation: mm-fade 0.4s ease 0.4s both;
}

.bf-results-skanimal {
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: mm-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.3s both;
}

.bf-results-skanimal img {
    max-height: 120px;
    max-width: 160px;
}

/* A variant's filter is its colouring, so only plain sprites get the shadow and glow */
.bf-results-skanimal img:not([class*="sk-variant-"]) {
    filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.5));
}

.bf-results.is-victory .bf-results-skanimal img:not([class*="sk-variant-"]) {
    filter: drop-shadow(0 0 16px rgba(255, 204, 0, 0.55));
}

.bf-results-skanimal.is-destroyed img {
    filter: grayscale(1) brightness(0.6);
    opacity: 0.6;
}

.bf-results-name {
    font-size: 18px;
    font-weight: bold;
}

.bf-results-level {
    font-size: 12px;
    font-weight: bold;
    color: #ffcc00;
}

.bf-xp {
    width: 100%;
    max-width: 300px;
    animation: mm-fade 0.4s ease 0.5s both;
}

.bf-xp-labels {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    font-weight: bold;
}

.bf-xp-track {
    height: 10px;
    margin-top: 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.1);
    overflow: hidden;
}

.bf-xp-fill {
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--sc-primary), #ffcc00);
    animation: bf-xp-grow 1.2s cubic-bezier(0.22, 1, 0.36, 1) 0.8s both;
}

.bf-results .is-good { color: #4cd97b; }
.bf-results .is-bad { color: #ff7a6b; }

.bf-results-banner {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 12px;
    font-weight: bold;
    animation: mm-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) 1.2s both;
}

.bf-results-banner.is-good {
    border: 1px solid rgba(76, 217, 123, 0.5);
    background: rgba(76, 217, 123, 0.12);
}

.bf-results-banner.is-bad {
    border: 1px solid rgba(255, 122, 107, 0.5);
    background: rgba(255, 122, 107, 0.12);
}

.bf-level-up {
    animation-delay: 2s;
}

.bf-rewards {
    display: flex;
    gap: 8px;
    animation: mm-fade 0.4s ease 0.9s both;
}

.bf-reward {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(255, 204, 0, 0.12);
    color: #ffcc00;
    font-size: 13px;
    font-weight: bold;
}

.bf-summary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    width: 100%;
    max-width: 340px;
    padding: 10px 0;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    animation: mm-fade 0.4s ease 1s both;
}

.bf-summary div {
    display: flex;
    flex-direction: column;
}

.bf-summary span {
    font-size: 20px;
    font-weight: bold;
    font-variant-numeric: tabular-nums;
}

.bf-summary small {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.55);
    text-transform: uppercase;
}

.bf-confetti-layer {
    position: fixed;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.bf-confetti {
    position: absolute;
    top: -12px;
    width: 8px;
    height: 14px;
    border-radius: 2px;
    animation: bf-confetti 2.4s cubic-bezier(0.3, 0.6, 0.5, 1) both;
}

/* Keyframes */
@keyframes bf-enter-left {
    from { opacity: 0; transform: translateX(-60%); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes bf-enter-right {
    from { opacity: 0; transform: translateX(60%); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes bf-lunge-up-a {
    0%, 100% { transform: translate(0, 0); }
    20% { transform: translate(-6px, 4px); }
    45% { transform: translate(30px, -26px) scale(1.06); }
}

@keyframes bf-lunge-up-b {
    0%, 100% { transform: translate(0, 0); }
    20% { transform: translate(-6px, 4px); }
    45% { transform: translate(30px, -26px) scale(1.06); }
}

@keyframes bf-lunge-down-a {
    0%, 100% { transform: translate(0, 0); }
    20% { transform: translate(6px, -4px); }
    45% { transform: translate(-30px, 26px) scale(1.06); }
}

@keyframes bf-lunge-down-b {
    0%, 100% { transform: translate(0, 0); }
    20% { transform: translate(6px, -4px); }
    45% { transform: translate(-30px, 26px) scale(1.06); }
}

@keyframes bf-hit-a {
    0%, 100% { transform: translateX(0); filter: none; }
    10%, 50% { transform: translateX(-8px); filter: brightness(2.2) saturate(0.4); }
    30%, 70% { transform: translateX(8px); filter: none; }
}

@keyframes bf-hit-b {
    0%, 100% { transform: translateX(0); filter: none; }
    10%, 50% { transform: translateX(-8px); filter: brightness(2.2) saturate(0.4); }
    30%, 70% { transform: translateX(8px); filter: none; }
}

@keyframes bf-dodge-a {
    0%, 100% { transform: translateX(0); opacity: 1; }
    40% { transform: translateX(22px) skewX(-8deg); opacity: 0.6; }
}

@keyframes bf-dodge-b {
    0%, 100% { transform: translateX(0); opacity: 1; }
    40% { transform: translateX(22px) skewX(-8deg); opacity: 0.6; }
}

@keyframes bf-heal-a {
    0%, 100% { transform: translateY(0); filter: none; }
    40% { transform: translateY(-8px); filter: drop-shadow(0 0 14px rgba(76, 217, 123, 0.9)) brightness(1.3); }
}

@keyframes bf-heal-b {
    0%, 100% { transform: translateY(0); filter: none; }
    40% { transform: translateY(-8px); filter: drop-shadow(0 0 14px rgba(76, 217, 123, 0.9)) brightness(1.3); }
}

@keyframes bf-faint {
    0% { transform: translateY(0) rotate(0); opacity: 1; filter: none; }
    30% { transform: translateY(-6px) rotate(-4deg); filter: brightness(2); }
    100% { transform: translateY(40px) rotate(8deg); opacity: 0; filter: grayscale(1); }
}

@keyframes bf-shield-up {
    from { opacity: 0; transform: scale(0.5); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes bf-shield-pulse {
    0%, 100% { box-shadow: 0 0 12px rgba(var(--sc-primary-rgb), 0.4); }
    50% { box-shadow: 0 0 24px rgba(var(--sc-primary-rgb), 0.8); }
}

@keyframes bf-burst {
    from { opacity: 1; transform: scale(0.2); }
    to { opacity: 0; transform: scale(1.4); }
}

@keyframes bf-float {
    0% { opacity: 0; transform: translate(-50%, 10px) scale(0.6); }
    20% { opacity: 1; transform: translate(-50%, -6px) scale(1.15); }
    70% { opacity: 1; transform: translate(-50%, -24px) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -40px) scale(1); }
}

@keyframes bf-shake-a {
    0%, 100% { transform: translate(0, 0); }
    20% { transform: translate(-6px, 3px); }
    40% { transform: translate(6px, -3px); }
    60% { transform: translate(-4px, -2px); }
    80% { transform: translate(3px, 2px); }
}

@keyframes bf-shake-b {
    0%, 100% { transform: translate(0, 0); }
    20% { transform: translate(-6px, 3px); }
    40% { transform: translate(6px, -3px); }
    60% { transform: translate(-4px, -2px); }
    80% { transform: translate(3px, 2px); }
}

@keyframes bf-low-hp {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}

@keyframes bf-type-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes bf-xp-grow {
    from { width: var(--from); }
    to { width: var(--to); }
}

@keyframes bf-confetti {
    0% { opacity: 1; transform: translate(0, 0) rotate(0); }
    100% { opacity: 0; transform: translate(var(--drift), 100vh) rotate(720deg); }
}

/* Surrender: offering, waiting, answering */

.bf-surrender-button {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.bf-surrender-button span {
    font-size: 11px;
    font-weight: 700;
}

.bf-surrender-button:disabled {
    opacity: 0.35;
}

.bf-modal.bf-surrender {
    max-width: 360px;
    border-color: rgba(var(--sc-primary-rgb), 0.45);
    background: linear-gradient(160deg, var(--sc-surface-2), var(--sc-surface));
    box-shadow: var(--sc-shadow-lg);
}

.bf-modal.bf-surrender.is-answer {
    border-color: rgba(255, 200, 61, 0.6);
    box-shadow: var(--sc-shadow-lg), 0 0 40px rgba(255, 200, 61, 0.2);
}

.bf-modal-icon.is-gold {
    color: var(--sc-gold);
}

.bf-modal-backdrop.is-negotiating {
    backdrop-filter: blur(3px);
}

.bf-bribe-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 6px;
    color: var(--sc-text-muted);
    font-size: 13px;
    font-weight: 600;
}

.bf-bribe-input {
    width: 100%;
    margin-top: 6px;
    font-size: 22px;
    font-weight: 700;
    text-align: center;
}

.bf-bribe-presets {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    margin-top: 10px;
}

.bf-bribe-chip {
    padding: 5px 12px;
    border: 1px solid var(--sc-line-strong);
    border-radius: var(--sc-radius-pill);
    background: var(--sc-surface);
    color: var(--sc-text);
    font-size: 13px;
    font-weight: 600;
}

.bf-bribe-chip.is-on {
    border-color: transparent;
    background: var(--sc-gradient-gold);
    color: var(--sc-navy);
}

.bf-bribe-chip:disabled {
    opacity: 0.35;
}

.bf-surrender-note,
.bf-answer-note {
    margin: 10px 0 0;
    color: var(--sc-text-faint);
    font-size: 12px;
}

.bf-negotiation-clock {
    position: relative;
    height: 6px;
    margin: 12px 0 4px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.08);
    overflow: hidden;
}

.bf-negotiation-clock::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: var(--left);
    background: var(--sc-gradient-gold);
    transition: width 0.25s linear;
}

.bf-negotiation-clock span {
    position: absolute;
    top: 8px;
    right: 0;
    color: var(--sc-text-muted);
    font-size: 11px;
}

.bf-answer-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 18px;
}

.bf-answer-actions .mm-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.bf-btn-steal {
    background: linear-gradient(135deg, #c08bff, #7b5cff);
    color: #fff;
}

.bf-btn-steal:disabled {
    opacity: 0.4;
}

.bf-toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--sc-tabbar-height) + 24px + var(--sc-safe-bottom));
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: var(--sc-radius-pill);
    background: var(--sc-surface-3);
    box-shadow: var(--sc-shadow-lg);
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    transform: translateX(-50%);
    animation: mm-pop 0.3s var(--sc-ease-spring) both;
}

.bf-toast.is-bad ion-icon {
    color: var(--sc-danger);
}

/* ==========================================================================
   Visual refresh: calmer chrome, a lit arena floor, glass HUDs and tidy move cards.
   These come last so they win over the original rules above.
   ========================================================================== */

.bf-screen { gap: 10px; }

.bf-topbar {
    gap: 8px;
    padding: 4px;
    border: 1px solid var(--sc-line);
    border-radius: var(--sc-radius-pill);
    background: rgba(var(--sc-bg-rgb), 0.6);
}

.bf-round {
    padding: 4px 12px;
    border-radius: var(--sc-radius-pill);
    background: var(--sc-gradient-primary);
    color: var(--sc-navy);
    font-family: var(--sc-font-display);
    font-size: 13px;
    font-style: normal;
    font-weight: 700;
    text-shadow: none;
}

.bf-mode {
    color: var(--sc-text-muted);
    font-size: 11px;
}

.bf-info,
.bf-flag {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--sc-surface-2);
    color: var(--sc-text-muted);
    font-size: 17px;
    cursor: pointer;
}

.bf-flag { color: var(--sc-danger); }

.bf-stakes {
    margin: 0;
    padding: 8px 12px;
    border-radius: var(--sc-radius);
    background: var(--sc-surface);
    color: var(--sc-text-muted);
    font-size: 12px;
    animation: mm-fade 0.2s ease both;
}

.bf-arena {
    height: 320px;
    border: 1px solid rgba(var(--sc-primary-rgb), 0.25);
    border-radius: var(--sc-radius-lg);
    background:
        radial-gradient(ellipse 70% 45% at 50% 100%, rgba(var(--sc-primary-rgb), 0.22), transparent 70%),
        radial-gradient(ellipse 60% 40% at 50% 0%, rgba(var(--sc-primary-rgb), 0.12), transparent 70%),
        linear-gradient(180deg, var(--sc-bg-elevated) 0%, var(--sc-surface) 60%, var(--sc-bg) 100%);
    box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.45), var(--sc-shadow);
}

/* A faint perspective grid floor, like the decode */
.bf-arena::before {
    content: "";
    position: absolute;
    left: -30%;
    right: -30%;
    bottom: -12%;
    height: 48%;
    background:
        linear-gradient(rgba(var(--sc-primary-rgb), 0.28) 1px, transparent 1px) 0 0 / 100% 28px,
        linear-gradient(90deg, rgba(var(--sc-primary-rgb), 0.28) 1px, transparent 1px) 0 0 / 28px 100%;
    transform: perspective(260px) rotateX(60deg);
    transform-origin: 50% 0;
    mask-image: linear-gradient(to bottom, transparent, #000 40%, transparent);
    pointer-events: none;
}

.bf-hud {
    border: 1px solid var(--sc-line-strong);
    border-radius: var(--sc-radius);
    background: rgba(var(--sc-bg-rgb), 0.72);
    backdrop-filter: blur(8px);
}

.bf-hud-opp { border-left: 3px solid var(--sc-danger); }
.bf-hud-self { border-right: 3px solid var(--sc-primary); }

.bf-moves { gap: 8px; }

.bf-move {
    min-height: 60px;
    padding: 9px 12px;
    border: 1px solid var(--sc-line-strong);
    border-left: 4px solid var(--sc-primary);
    border-radius: var(--sc-radius);
    background: linear-gradient(160deg, var(--sc-surface-2), var(--sc-surface));
    box-shadow: var(--sc-shadow);
}

.bf-move.is-heal { border-left-color: var(--sc-success); }
.bf-move.is-super { border-left-color: var(--sc-gold); box-shadow: 0 0 0 1px rgba(255, 200, 61, 0.4), var(--sc-shadow); }
.bf-move-guard { border-left-color: var(--sc-azure); }
.bf-move.is-chosen { border-color: var(--sc-primary); box-shadow: var(--sc-glow-primary); }

/* Status effects */

.bf-status {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 1px 7px;
    border-radius: var(--sc-radius-pill);
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    animation: mm-pop 0.3s var(--sc-ease-spring) both;
}

.bf-status.is-burn, .bf-move-status.is-burn { background: rgba(255, 106, 43, 0.22); color: #ff9a6b; }
.bf-status.is-poison, .bf-move-status.is-poison { background: rgba(180, 92, 255, 0.22); color: #d3a8ff; }
.bf-status.is-freeze, .bf-move-status.is-freeze { background: rgba(143, 233, 255, 0.22); color: #bff4ff; }
.bf-status.is-stun, .bf-move-status.is-stun { background: rgba(255, 225, 77, 0.22); color: #ffe98a; }

.bf-move-status {
    display: inline-grid;
    place-items: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    font-size: 11px;
}

/* Lasting tints on the afflicted Skanimal */
.bf-fighter.status-burn .bf-sprite { filter: drop-shadow(0 0 8px rgba(255, 106, 43, 0.85)) drop-shadow(0 6px 6px rgba(0, 0, 0, 0.4)); }
.bf-fighter.status-poison .bf-sprite { filter: drop-shadow(0 0 8px rgba(180, 92, 255, 0.85)) drop-shadow(0 6px 6px rgba(0, 0, 0, 0.4)); }
.bf-fighter.status-freeze .bf-sprite { filter: saturate(0.4) brightness(1.15) drop-shadow(0 0 8px rgba(143, 233, 255, 0.95)); }
.bf-fighter.status-stun .bf-sprite { animation: bf-stunned 0.25s linear infinite; }

/* A burn or poison tick flashes the sprite */
.bf-fighter.is-ticking-a .bf-sprite,
.bf-fighter.is-ticking-b .bf-sprite { animation: bf-tick 0.5s ease-out; }

@keyframes bf-stunned {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-2px) rotate(-1deg); }
    75% { transform: translateX(2px) rotate(1deg); }
}

@keyframes bf-tick {
    0%, 100% { opacity: 1; }
    30% { opacity: 0.4; transform: scale(0.96); }
}

/*
 * iPhone Safari: rounded corners plus overflow: hidden don't always clip 3D-transformed children (the grid floor),
 * which can push the battle wider than the screen. Paint containment clips everything to the arena.
 */
.bf-arena {
    contain: paint;
    isolation: isolate;
}

.bf-screen {
    min-width: 0;
    max-width: 100%;
    overflow-x: clip;
}

/* Short iPhones: scale the arena down a little so the moves stay on screen */
@media (max-height: 700px) {
    .bf-arena { height: 270px; }
}

/*
 * Inline SVG creatures get an explicit box. Safari can't resolve height: 100% plus aspect-ratio against a parent
 * whose width depends on its content, and falls back to the SVG's natural (huge) size.
 */
.bf-sprite {
    width: 100%;
    justify-content: center;
}

.bf-sprite .bf-creature {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: none;
    aspect-ratio: auto;
}

/* Pinned to the box: the viewBox then scales the drawing to fit inside it, whatever its proportions */
.bf-sprite .bf-creature svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}
