/* Treasure Waters Battle – design resolution 1080 × 1920 (9:16) */

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #1a1a2e;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}

img {
    display: block;
    max-width: 100%;
    background: transparent;
    user-select: none;
    -webkit-user-drag: none;
}

/* ── Viewport shell ─────────────────────────────────────────── */

#battle-app {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    background: #1a1a2e;
}

#battle-viewport {
    position: relative;
    aspect-ratio: 9 / 16;
    width: min(
        100vw,
        calc((100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 9 / 16)
    );
    max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    overflow: hidden;
    background: #0d1b2a;
}

/* ── Shared layer base ──────────────────────────────────────── */

#arena-layer,
#unit-layer,
#ground-fx-layer,
#projectile-shadow-layer,
#projectile-layer,
#fx-layer,
#world-ui-layer,
#screen-ui-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* ── Layer 1: Arena background ────────────────────────────── */

#arena-layer {
    z-index: 1;
}

.arena-background {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

#arena-layer::after {
    content: none;
}

/* ── Layer 2: Units ─────────────────────────────────────────── */

#unit-layer {
    z-index: 4;
}

#ground-fx-layer {
    z-index: 3;
}

#projectile-shadow-layer {
    z-index: 5;
}

#projectile-layer {
    z-index: 6;
}

.unit-sprite-wrapper.is-dead {
    opacity: 0;
    transition: opacity 0.15s ease;
    pointer-events: none;
}

.unit-marker {
    position: absolute;
    width: 6.85%;
    aspect-ratio: 1;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.unit-marker.team-blue {
    animation: unitAdvanceBlue 2.5s ease-in-out infinite;
}

.unit-marker.team-red {
    animation: unitAdvanceRed 2.5s ease-in-out infinite;
}

@keyframes unitAdvanceBlue {
    0%, 100% { transform: translate(-50%, -50%) translateY(0); }
    50%      { transform: translate(-50%, -50%) translateY(-12px); }
}

@keyframes unitAdvanceRed {
    0%, 100% { transform: translate(-50%, -50%) translateY(0); }
    50%      { transform: translate(-50%, -50%) translateY(12px); }
}

.unit-body {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.unit-marker.team-blue .unit-body {
    border: 5px solid #2E86DE;
    box-shadow: 0 0 8px rgba(46, 134, 222, 0.4);
}

.unit-marker.team-red .unit-body {
    border: 5px solid #E74C3C;
    box-shadow: 0 0 8px rgba(231, 76, 60, 0.4);
}

.unit-icon {
    font-size: clamp(14px, 3.5vw, 28px);
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
    line-height: 1;
}

.unit-marker.team-red .unit-body {
    transform: rotate(180deg);
}

.unit-level {
    position: absolute;
    top: -18%;
    left: 50%;
    transform: translateX(-50%);
    min-width: 22%;
    padding: 2px 6px;
    border-radius: 8px;
    font-size: clamp(8px, 2vw, 14px);
    font-weight: 700;
    text-align: center;
    color: #fff;
    background: rgba(0, 0, 0, 0.75);
    border: 1px solid #D4AF37;
    white-space: nowrap;
    z-index: 1;
}

.unit-marker.team-red .unit-level {
    transform: translateX(-50%) rotate(180deg);
}

/* ── Animated unit sprites ──────────────────────────────────── */

.unit-sprite-wrapper {
    position: absolute;
    transform: translate(-50%, -50%);
    pointer-events: none;
    left: 50%;
    contain: layout style;
}

body:not(.demo-mode) .unit-sprite-wrapper[data-unit-id="red-captain"] {
    top: 46%;
}

body:not(.demo-mode) .unit-sprite-wrapper[data-unit-id="blue-captain"] {
    top: 46%;
}

.unit-sprite-clip {
    position: relative;
    z-index: 2;
    width: 100%;
    aspect-ratio: 1;
    overflow: hidden;
    padding: 4px;
    margin: -4px;
    box-sizing: content-box;
}

.unit-sprite-img {
    display: block;
    width: 400%;
    height: auto;
    max-width: none;
    background: transparent;
    --unit-outline-filter:
        drop-shadow(0 0 0.5px rgba(8, 16, 24, 0.55))
        drop-shadow(0 1px 0 rgba(8, 16, 24, 0.55))
        drop-shadow(0 -1px 0 rgba(8, 16, 24, 0.55))
        drop-shadow(1px 0 0 rgba(8, 16, 24, 0.55))
        drop-shadow(-1px 0 0 rgba(8, 16, 24, 0.55));
    filter:
        brightness(1.14)
        contrast(1.10)
        saturate(1.08)
        var(--unit-outline-filter);
    transform: translate(0, 0);
    transition: filter 0.1s ease-out;
    transform-origin: center center;
}

.unit-sprite-wrapper.team-blue .unit-sprite-img {
    filter:
        brightness(1.14)
        contrast(1.10)
        saturate(1.08)
        var(--unit-outline-filter)
        drop-shadow(0 -2px 2px rgba(120, 200, 255, 0.18));
}

.unit-sprite-wrapper.team-red .unit-sprite-img {
    filter:
        brightness(1.14)
        contrast(1.10)
        saturate(1.08)
        var(--unit-outline-filter)
        drop-shadow(0 -2px 2px rgba(255, 170, 120, 0.18));
}

/* Cutlass Carl: no upward team tint — it reads as enemy-colored dots in melee. */
.unit-sprite-wrapper.unit-cutlass-carl .unit-sprite-img,
.unit-sprite-wrapper.unit-enemy-cutlass-carl .unit-sprite-img {
    --unit-outline-filter: drop-shadow(0 0 0.5px rgba(8, 16, 24, 0.45));
    filter:
        brightness(1.14)
        contrast(1.10)
        saturate(1.08)
        var(--unit-outline-filter);
}

/* Tighter clip prevents adjacent attack-frame pixels bleeding through padding. */
.unit-sprite-wrapper.unit-cutlass-carl .unit-sprite-clip,
.unit-sprite-wrapper.unit-enemy-cutlass-carl .unit-sprite-clip {
    clip-path: inset(2px round 1px);
}

/* Deckhands walk sheet — trim drop-shadow halos like Carl. */
.unit-sprite-wrapper.unit-enemy-deckhands .unit-sprite-img {
    --unit-outline-filter: drop-shadow(0 0 0.5px rgba(8, 16, 24, 0.45));
    filter:
        brightness(1.14)
        contrast(1.10)
        saturate(1.08)
        var(--unit-outline-filter);
}

.unit-sprite-wrapper.unit-enemy-deckhands .unit-sprite-clip {
    clip-path: inset(2px round 1px);
}

.unit-sprite-wrapper.unit-enemy-shield-mate .unit-sprite-img {
    --unit-outline-filter: none;
    filter: none;
    transition: none;
    opacity: 1;
    transform-origin: 0 0;
}

.unit-sprite-wrapper.unit-enemy-shield-mate.is-attack-loop .unit-sprite-img {
    will-change: transform;
    backface-visibility: hidden;
}

.unit-sprite-wrapper.unit-enemy-shield-mate .unit-sprite-clip {
    overflow: hidden;
    background: transparent;
    padding: 0;
    margin: 0;
}

/* Visible when a unit PNG 404s — empty lanes look like “nothing spawned”. */
.unit-sprite-wrapper.is-sprite-missing .unit-sprite-clip {
    background: rgba(180, 20, 20, 0.55);
    outline: 2px solid #ffd36a;
}
.unit-sprite-missing {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    z-index: 5;
    color: #ffd36a;
    font: 700 11px/1.1 system-ui, sans-serif;
    text-align: center;
    pointer-events: none;
    text-shadow: 0 1px 2px #000;
}

.unit-sprite-img.is-explosion-flash {
    filter:
        brightness(1.48)
        contrast(1.10)
        saturate(1.28)
        var(--unit-outline-filter);
}

.unit-sprite-shadow {
    position: absolute;
    top: 86%;
    bottom: auto;
    left: 50%;
    transform: translate(-50%, -42%) scaleY(0.52);
    width: 42%;
    height: 4.5%;
    border-radius: 50%;
    background: radial-gradient(
        ellipse at center,
        rgba(0, 0, 0, 0.36) 0%,
        rgba(0, 0, 0, 0.16) 58%,
        transparent 76%
    );
    filter: blur(0.4px);
    z-index: 1;
    pointer-events: none;
}

.unit-sprite-wrapper[data-unit-id="red-captain"] .unit-sprite-shadow,
.unit-sprite-wrapper[data-unit-id^="red-captain-"] .unit-sprite-shadow {
    top: 85%;
    width: 40%;
    height: 4%;
    transform: translate(-50%, -40%) scaleY(0.48);
}

/* ── Layer 3: FX ────────────────────────────────────────────── */

#fx-layer {
    z-index: 7;
}

.fx-sprite-wrapper {
    position: absolute;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 6;
}

.fx-bombard-explosion {
    transform: translate(-50%, -38%);
    transform-origin: 50% 85%;
}

.fx-bombard-explosion--near-friendly {
    opacity: 0.94;
}

.fx-bombard-explosion .fx-sprite-img {
    mix-blend-mode: screen;
}

.fx-bombard-explosion--near-friendly .fx-sprite-img {
    filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.32)) blur(0.45px);
}

.fx-bombard-explosion.is-smoke-frame .fx-sprite-img {
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.28)) blur(0.65px);
}

.fx-unit-death-poof {
    transform: translate(-50%, -46%);
    transform-origin: 50% 78%;
    opacity: 0.92;
}

.fx-unit-death-poof .fx-sprite-img {
    mix-blend-mode: screen;
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.35)) saturate(0.92);
}

.fx-unit-death-poof.is-smoke-frame .fx-sprite-img {
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.28)) blur(0.5px) saturate(0.88);
}

.fx-sprite-clip {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    overflow: hidden;
}

.fx-sprite-img {
    display: block;
    max-width: none;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.45));
}

/* ── Bombard Belle projectile ───────────────────────────────── */

.bombard-grenade {
    position: absolute;
    width: 26px;
    height: 26px;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 1;
    filter:
        drop-shadow(0 2px 2px rgba(0, 0, 0, 0.9))
        drop-shadow(0 0 2px rgba(255, 166, 55, 0.55));
}

.bombard-grenade img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.bombard-grenade-shadow {
    position: absolute;
    width: 21px;
    height: 9px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.38);
    filter: blur(2px);
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.bombard-target-indicator {
    position: absolute;
    width: 116px;
    height: 116px;
    border: 2px solid rgba(255, 150, 45, 0.62);
    border-radius: 50%;
    background: rgba(255, 90, 20, 0.1);
    transform: translate(-50%, -50%);
    pointer-events: none;
    animation: bombard-warning 700ms linear forwards;
}

@keyframes bombard-warning {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.72);
    }

    20% {
        opacity: 1;
    }

    100% {
        opacity: 0.22;
        transform: translate(-50%, -50%) scale(1);
    }
}

.torch-glow {
    position: absolute;
    width: 3%;
    aspect-ratio: 1;
    border-radius: 50%;
    background: radial-gradient(
        circle,
        rgba(255, 160, 40, 0.9) 0%,
        rgba(255, 100, 20, 0.5) 40%,
        transparent 70%
    );
    animation: torchPulse 3.5s ease-in-out infinite;
}

.torch-glow:nth-child(odd) {
    animation-duration: 4s;
}

.torch-glow:nth-child(even) {
    animation-duration: 3.2s;
}

@keyframes torchPulse {
    0%, 100% { opacity: 0.5; transform: scale(0.85); }
    50%      { opacity: 1; transform: scale(1.15); }
}

.cannon-flash {
    position: absolute;
    left: 50%;
    top: 17%;
    width: 12%;
    aspect-ratio: 1;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: radial-gradient(
        circle,
        rgba(255, 240, 120, 0.95) 0%,
        rgba(255, 140, 30, 0.7) 30%,
        rgba(255, 80, 0, 0.3) 55%,
        transparent 70%
    );
    opacity: 0;
    pointer-events: none;
}

.cannon-flash.active {
    animation: cannonFlashAnim 200ms ease-out forwards;
}

@keyframes cannonFlashAnim {
    0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
    30%  { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.6); }
}

.water-splash {
    position: absolute;
    left: 50%;
    top: 45%;
    width: 10%;
    aspect-ratio: 1;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: radial-gradient(
        circle,
        rgba(255, 255, 255, 0.85) 0%,
        rgba(180, 230, 255, 0.5) 35%,
        rgba(100, 200, 255, 0.2) 60%,
        transparent 75%
    );
    opacity: 0;
    pointer-events: none;
}

.water-splash.active {
    animation: waterSplashAnim 400ms ease-out forwards;
}

@keyframes waterSplashAnim {
    0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.3); }
    25%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.8); }
}

/* ── Layer 4: World UI ──────────────────────────────────────── */

#world-ui-layer {
    z-index: 8;
    pointer-events: none;
}

#gangplank-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 3;
}

.gangplank-zone {
    position: absolute;
    border: 2px dashed rgba(120, 220, 255, 0);
    border-radius: 12px;
    background: rgba(80, 180, 255, 0);
    transform-origin: 50% 50%;
    transition:
        background 0.15s ease,
        border-color 0.15s ease,
        box-shadow 0.15s ease;
    pointer-events: none;
}

.gangplank-zone[data-gangplank-id="left"],
.gangplank-zone[data-gangplank-id="right"] {
    transform: rotate(var(--gp-rotation, 0deg));
}

#gangplank-layer.active .gangplank-zone {
    border-color: rgba(120, 220, 255, 0.55);
    background: rgba(80, 180, 255, 0.1);
    box-shadow: inset 0 0 16px rgba(100, 210, 255, 0.15);
}

#gangplank-layer.active .gangplank-zone.hover {
    border-color: rgba(170, 245, 255, 0.95);
    background: rgba(90, 210, 255, 0.22);
    box-shadow:
        0 0 18px rgba(100, 220, 255, 0.45),
        inset 0 0 20px rgba(120, 230, 255, 0.25);
}

/* ── Layer 5: Screen UI ─────────────────────────────────────── */

#screen-ui-layer {
    z-index: 10;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    pointer-events: none;
}

.bottom-panel {
    pointer-events: auto;
    touch-action: none;
}

/* Top match panel */
.top-panel {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 2%;
    padding: 1.6% 2.5% 0;
    position: relative;
}

.ship-hud {
    flex: 1;
    min-width: 0;
    max-width: 38%;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.ship-hud--enemy {
    align-items: flex-end;
}

.ship-hud__header {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
}

.ship-hud--enemy .ship-hud__header {
    justify-content: flex-end;
}

.ship-hud__titles {
    min-width: 0;
}

.ship-hud--player .ship-hud__titles {
    text-align: left;
}

.ship-hud--enemy .ship-hud__titles {
    text-align: right;
}

.ship-hud__name {
    font-size: clamp(9px, 2.5vw, 16px);
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ship-hud__team {
    font-size: clamp(7px, 1.8vw, 11px);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-top: 1px;
}

.ship-hud--player .ship-hud__team {
    color: #6ec4ff;
}

.ship-hud--enemy .ship-hud__team {
    color: #ff8a80;
}

.enemy-energy-readout {
    margin-top: 4px;
    font-size: clamp(8px, 2vw, 12px);
    font-weight: 700;
    color: rgba(255, 190, 150, 0.82);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
    letter-spacing: 0.04em;
}

.enemy-energy-readout.is-ready {
    color: #ffd166;
}

.ship-hud__flag {
    flex: 0 0 auto;
    width: clamp(14px, 4vw, 22px);
    height: clamp(14px, 4vw, 22px);
    border-radius: 3px;
    position: relative;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
}

.ship-hud__flag::after {
    content: "☠";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(7px, 2vw, 11px);
    color: rgba(255, 255, 255, 0.92);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.ship-hud__flag--blue {
    background: linear-gradient(180deg, #2f86de 0%, #145da0 100%);
    border: 1px solid rgba(170, 220, 255, 0.55);
}

.ship-hud__flag--red {
    background: linear-gradient(180deg, #e74c3c 0%, #922b21 100%);
    border: 1px solid rgba(255, 170, 160, 0.55);
}

.ship-hp-bar {
    position: relative;
    width: 100%;
    height: clamp(14px, 3.6vw, 22px);
    border-radius: 999px;
    overflow: hidden;
    background: rgba(8, 12, 20, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow:
        inset 0 1px 3px rgba(0, 0, 0, 0.55),
        0 1px 2px rgba(0, 0, 0, 0.35);
}

.ship-hp-bar__fill {
    position: absolute;
    inset: 0 auto 0 0;
    width: 100%;
    border-radius: inherit;
    transition: width 700ms ease-out;
}

.ship-hp-bar--blue .ship-hp-bar__fill {
    background: linear-gradient(
        180deg,
        #66b8ff 0%,
        #2f86de 42%,
        #145da0 100%
    );
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.35),
        0 0 8px rgba(47, 134, 222, 0.45);
}

.ship-hp-bar--red .ship-hp-bar__fill {
    background: linear-gradient(
        180deg,
        #ff8a80 0%,
        #e74c3c 42%,
        #922b21 100%
    );
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.28),
        0 0 8px rgba(231, 76, 60, 0.45);
}

.ship-hp-bar.is-low .ship-hp-bar__fill {
    animation: shipHpPulse 1.1s ease-in-out infinite;
}

@keyframes shipHpPulse {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.18); }
}

.ship-hp-bar__label {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(8px, 2.1vw, 13px);
    font-weight: 800;
    color: #fff;
    text-shadow:
        0 1px 2px rgba(0, 0, 0, 0.95),
        0 0 4px rgba(0, 0, 0, 0.65);
    pointer-events: none;
    z-index: 1;
}

.timer-panel {
    position: absolute;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
    background: rgba(15, 15, 25, 0.88);
    border: 2px solid #B8860B;
    border-radius: 8px;
    padding: 4px 16px 6px;
    text-align: center;
    min-width: 22%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    z-index: 2;
}

.timer-label {
    font-size: clamp(7px, 1.8vw, 12px);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #D4AF37;
}

.timer-value {
    font-size: clamp(14px, 4vw, 28px);
    font-weight: 700;
    color: #fff;
    line-height: 1.1;
}

/* Bottom card + energy panel */
.bottom-panel {
    margin-top: auto;
    height: 22%;
    display: flex;
    flex-direction: column;
    background: linear-gradient(
        180deg,
        rgba(14, 29, 48, 0) 0%,
        rgba(14, 29, 48, 0.88) 24%,
        rgba(7, 17, 31, 0.98) 100%
    );
}

.battle-card-bar {
    background:
        linear-gradient(
            180deg,
            rgba(14, 29, 48, 0.97) 0%,
            rgba(7, 17, 31, 0.98) 100%
        );
    border-top: 1px solid rgba(112, 190, 255, 0.28);
}

.card-row {
    flex: 1.15;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5%;
    padding: 0 2% 0.5%;
    min-height: 0;
}

.battle-card {
    flex: 1;
    position: relative;
    aspect-ratio: 1;
    height: 92%;
    width: auto;
    max-height: 100%;
    border-radius: 10px;
    border: 2px solid rgba(255, 255, 255, 0.92);
    background: linear-gradient(180deg, #ffffff 0%, #eef1f6 100%);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: stretch;
    overflow: hidden;
    box-shadow:
        0 3px 7px rgba(0, 0, 0, 0.72),
        0 0 4px rgba(66, 164, 255, 0.22);
    min-width: 0;
    min-height: 0;
    transition: transform 120ms ease-out;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.battle-card.has-art {
    padding: 0;
    cursor: grab;
    touch-action: manipulation;
    border: none;
    background: transparent;
    box-shadow:
        0 3px 7px rgba(0, 0, 0, 0.72),
        0 0 4px rgba(66, 164, 255, 0.22);
}

.battle-card.is-dragging {
    opacity: 0.35;
    touch-action: none;
}

.battle-card-bar.is-card-dragging .battle-card:not(.is-dragging),
.card-row-wrap.is-card-dragging .battle-next-card {
    pointer-events: none;
}

.battle-card-bar.is-card-dragging .battle-card:not(.is-dragging) {
    transform: none;
}

.battle-card-bar.is-card-dragging .battle-card:not(.is-dragging) .battle-card__image {
    filter:
        brightness(1.14)
        contrast(1.06)
        saturate(1.08);
}

.battle-card.is-selected {
    transform: translateY(-6px);
}

.battle-card.is-unaffordable {
    opacity: 0.90;
    cursor: not-allowed;
}

.battle-card.card-shake {
    animation: cardShake 0.35s ease;
}

@keyframes cardShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.card-drag-ghost {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    transform: translate(-50%, -50%) scale(1.08);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
    opacity: 0.92;
}

.battle-card__portrait {
    position: relative;
    overflow: hidden;
    border-radius: inherit;
    width: 100%;
    height: 100%;
    flex: 1;
}

.battle-card__portrait::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(
            circle at 50% 34%,
            rgba(255, 244, 214, 0.12) 0%,
            rgba(255, 244, 214, 0.05) 38%,
            rgba(255, 244, 214, 0) 70%
        );
}

.battle-card__image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 12%;
    background: #ffffff;
    pointer-events: none;
    user-select: none;
    filter:
        brightness(1.14)
        contrast(1.06)
        saturate(1.08);
    transition: filter 120ms ease-out;
}

.battle-card[data-character="pirate-captain"] .battle-card__image {
    filter:
        brightness(1.20)
        contrast(1.07)
        saturate(1.10);
}

.battle-card[data-character="pirate-captain"] .battle-card__portrait::after {
    background:
        radial-gradient(
            circle at 52% 36%,
            rgba(255, 238, 198, 0.16) 0%,
            rgba(255, 238, 198, 0.07) 34%,
            rgba(255, 238, 198, 0) 68%
        );
}

.battle-card:active .battle-card__image,
.battle-card.is-selected .battle-card__image {
    filter:
        brightness(1.20)
        contrast(1.08)
        saturate(1.10);
}

.battle-card.is-unaffordable .battle-card__image {
    filter:
        brightness(0.72)
        contrast(0.96)
        saturate(0.62);
}

.battle-card.is-unaffordable .battle-card__portrait::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
    background: rgba(4, 10, 20, 0.18);
}

.battle-card .card-cost {
    position: absolute;
    top: 4%;
    left: 6%;
    width: 22%;
    aspect-ratio: 1;
    border-radius: 50%;
    background: radial-gradient(circle, #D4AF37 0%, #B8860B 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(8px, 2.2vw, 16px);
    font-weight: 800;
    color: #1a1a2e;
    border: 1px solid #F0D060;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.battle-card .card-icon {
    font-size: clamp(16px, 5vw, 36px);
    font-weight: 800;
    color: rgba(255, 255, 255, 0.25);
    line-height: 1;
    margin-bottom: 4%;
}

.battle-card .card-title {
    font-size: clamp(6px, 1.6vw, 12px);
    font-weight: 700;
    color: #fff;
    text-align: center;
    padding: 0 4px 6%;
    line-height: 1.15;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.next-card-slot {
    flex: 0.7;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
}

.next-label {
    font-size: clamp(7px, 1.8vw, 12px);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: #D4AF37;
}

.card-back {
    width: 70%;
    aspect-ratio: 3 / 4;
    border-radius: 6px;
    border: 2px solid #8B6914;
    background: repeating-linear-gradient(
        45deg,
        #1a1a2e,
        #1a1a2e 4px,
        #252540 4px,
        #252540 8px
    );
    box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.6);
    position: relative;
}

.card-back::after {
    content: "☠";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(12px, 3.5vw, 24px);
    color: rgba(212, 175, 55, 0.5);
}

/* Energy bar */
.energy-bar-container {
    padding: 0 2% 2%;
    height: 24%;
    display: flex;
    align-items: center;
}

.energy-panel {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 3%;
    padding: 2.5% 3.5%;
    border-radius: 12px;
    background: linear-gradient(
        180deg,
        rgba(22, 28, 48, 0.94) 0%,
        rgba(8, 10, 20, 0.97) 100%
    );
    border: 1px solid rgba(212, 175, 55, 0.5);
    box-shadow:
        0 4px 14px rgba(0, 0, 0, 0.45),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.energy-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 14%;
}

.energy-icon {
    font-size: clamp(12px, 3.2vw, 20px);
    line-height: 1;
    filter: drop-shadow(0 0 6px rgba(255, 210, 80, 0.85));
}

.energy-label {
    font-size: clamp(6px, 1.5vw, 11px);
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: #f0d060;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
    white-space: nowrap;
}

.energy-track {
    flex: 1;
    padding: 3px 5px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.42);
    border: 1px solid rgba(255, 255, 255, 0.07);
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.55);
}

.energy-segments {
    display: flex;
    gap: clamp(2px, 0.6vw, 5px);
    height: clamp(12px, 3.2vw, 22px);
    align-items: stretch;
}

.energy-segment {
    flex: 1;
    position: relative;
    overflow: hidden;
    border-radius: 4px 4px 2px 2px;
    background: linear-gradient(
        180deg,
        rgba(48, 54, 72, 0.95) 0%,
        rgba(18, 20, 32, 0.98) 100%
    );
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.55);
    transition:
        background 0.5s ease,
        border-color 0.5s ease,
        box-shadow 0.5s ease;
}

.energy-segment.filled {
    background: linear-gradient(
        180deg,
        #9ef0ff 0%,
        #4db8ff 38%,
        #1f7fd4 72%,
        #155fa8 100%
    );
    border-color: rgba(174, 228, 255, 0.85);
    box-shadow:
        0 0 10px rgba(77, 184, 255, 0.55),
        inset 0 1px 0 rgba(255, 255, 255, 0.5),
        inset 0 -3px 6px rgba(0, 60, 130, 0.45);
}

.energy-segment.filled::after {
    content: "";
    position: absolute;
    top: 12%;
    left: 18%;
    right: 18%;
    height: 38%;
    border-radius: 2px;
    background: linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.55) 0%,
        rgba(255, 255, 255, 0) 100%
    );
    pointer-events: none;
}

.energy-count {
    font-size: clamp(8px, 2vw, 14px);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: #fff;
    white-space: nowrap;
    min-width: 12%;
    text-align: center;
    padding: 4px 8px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(212, 175, 55, 0.28);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

/* Demo mode: disable unit advance when demoMode off */
body:not(.demo-mode) .unit-marker {
    animation: none !important;
}

body:not(.demo-mode) .torch-glow {
    animation: none !important;
    opacity: 0.6;
}

#build-version-badge {
    position: absolute;
    top: 2%;
    left: 2%;
    z-index: 55;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #d8eefc;
    background: rgba(4, 10, 18, 0.72);
    border: 1px solid rgba(120, 200, 255, 0.35);
    pointer-events: none;
}

#match-report-panel {
    position: absolute;
    right: 2%;
    bottom: 14%;
    left: auto;
    top: auto;
    width: 34%;
    max-height: 28%;
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    border-radius: 8px;
    background: rgba(4, 10, 18, 0.72);
    border: 1px solid rgba(120, 200, 255, 0.35);
    pointer-events: auto;
}

body.playtest-mode #match-report-panel {
    display: none !important;
}

#match-report-panel.is-collapsed #match-report-log,
#match-report-panel.is-collapsed #match-report-copy {
    display: none;
}

#match-report-log {
    width: 100%;
    min-height: 160px;
    max-height: 240px;
    resize: vertical;
    font-size: 10px;
    line-height: 1.35;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color: #d8eefc;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(120, 200, 255, 0.22);
    border-radius: 6px;
    padding: 6px;
}

#match-report-copy {
    font-size: 10px;
    font-weight: 600;
    padding: 4px 8px;
    border: none;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.12);
    color: #d8eefc;
    cursor: pointer;
}

.match-winner-overlay {
    position: absolute;
    inset: 0;
    z-index: 80;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6%;
    background: rgba(4, 10, 18, 0.58);
    pointer-events: auto;
    overflow: hidden;
}

.match-gold-rain {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 0;
}

.match-gold-coin {
    position: absolute;
    top: -12%;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background:
        radial-gradient(circle at 32% 28%, #fff6c8 0%, #ffd34d 34%, #c9921d 72%, #7a520e 100%);
    border: 1px solid rgba(255, 236, 160, 0.85);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
    opacity: 0;
    animation-name: match-gold-coin-fall;
    animation-timing-function: cubic-bezier(0.22, 0.61, 0.36, 1);
    animation-fill-mode: forwards;
}

@keyframes match-gold-coin-fall {
    0% {
        transform: translateY(0) rotate(0deg) scale(0.65);
        opacity: 0;
    }
    12% {
        opacity: 1;
    }
    100% {
        transform: translateY(118vh) rotate(540deg) scale(1);
        opacity: 0.92;
    }
}

.match-intro-overlay {
    position: absolute;
    inset: 0;
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8%;
    background: rgba(4, 10, 18, 0.72);
    pointer-events: auto;
}

.match-intro-overlay[hidden] {
    display: none !important;
}

.match-intro-overlay__card {
    width: min(92%, 420px);
    padding: 28px 24px 22px;
    border: 2px solid rgba(120, 200, 255, 0.45);
    border-radius: 16px;
    background: linear-gradient(180deg, rgba(18, 34, 58, 0.98), rgba(8, 16, 30, 0.96));
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: inherit;
    font: inherit;
}

.match-intro-overlay__card:hover {
    border-color: rgba(255, 220, 120, 0.72);
}

.match-intro-overlay__team {
    font-size: clamp(22px, 5vw, 32px);
    font-weight: 800;
    line-height: 1.15;
    text-align: center;
}

.match-intro-overlay__team--blue {
    color: #9fd4ff;
    text-shadow: 0 2px 10px rgba(36, 120, 220, 0.45);
}

.match-intro-overlay__team--red {
    color: #ff9a9a;
    text-shadow: 0 2px 10px rgba(200, 50, 50, 0.45);
}

.match-intro-overlay__vs {
    font-size: 14px;
    letter-spacing: 0.24em;
    text-transform: uppercase;
    color: rgba(255, 220, 120, 0.9);
    margin: 4px 0;
}

.match-intro-overlay__hint {
    margin-top: 8px;
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(216, 238, 252, 0.72);
}

.match-winner-overlay[hidden] {
    display: none !important;
}

.match-winner-overlay__card {
    position: relative;
    z-index: 1;
    min-width: 62%;
    max-width: 88%;
    padding: 18px 22px;
    border-radius: 14px;
    border: 2px solid rgba(255, 220, 120, 0.72);
    background: linear-gradient(180deg, rgba(18, 34, 58, 0.96), rgba(8, 16, 30, 0.94));
    box-shadow: 0 10px 36px rgba(0, 0, 0, 0.45);
    text-align: center;
    pointer-events: auto;
}

.match-winner-overlay__label {
    font-size: 13px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: rgba(255, 220, 120, 0.92);
    margin-bottom: 8px;
}

.match-winner-overlay__name {
    font-size: clamp(24px, 4.8vw, 34px);
    font-weight: 800;
    color: #fff8e8;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
    margin-bottom: 6px;
}

.match-winner-overlay__score {
    font-size: clamp(20px, 4vw, 28px);
    font-weight: 800;
    color: #ffe08a;
    letter-spacing: 0.06em;
    margin-bottom: 6px;
}

.match-winner-overlay__loot {
    font-size: 14px;
    font-weight: 700;
    color: #ffd966;
    margin-bottom: 8px;
    animation: match-loot-pop 0.55s ease-out both;
}

@keyframes match-loot-pop {
    0% {
        transform: scale(0.85);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.match-winner-overlay__duration {
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 220, 120, 0.92);
    margin-bottom: 10px;
}

.match-winner-overlay__stats {
    font-size: 11px;
    line-height: 1.5;
    color: rgba(216, 238, 252, 0.88);
    margin-bottom: 14px;
    max-width: 92%;
    margin-left: auto;
    margin-right: auto;
}

.match-winner-overlay__stats div {
    margin-bottom: 2px;
}

.match-winner-overlay__actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.match-winner-overlay__btn {
    min-width: 112px;
    padding: 10px 16px;
    border-radius: 8px;
    border: 1px solid rgba(120, 200, 255, 0.35);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.match-winner-overlay__btn--primary {
    background: linear-gradient(180deg, rgba(72, 148, 255, 0.95), rgba(36, 98, 196, 0.95));
    color: #f5fbff;
}

.match-winner-overlay__btn--secondary {
    background: rgba(255, 255, 255, 0.08);
    color: #d8eefc;
}

.match-winner-overlay__btn:active {
    transform: translateY(1px);
}

body.battle-match-ended .bottom-panel {
    pointer-events: none;
    opacity: 0.72;
}

#path-debug-panel {
    position: absolute;
    right: 2%;
    bottom: 14%;
    left: auto;
    top: auto;
    width: 34%;
    max-height: 28%;
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    border-radius: 8px;
    background: rgba(4, 10, 18, 0.72);
    border: 1px solid rgba(120, 200, 255, 0.35);
    pointer-events: auto;
}

#path-debug-panel.is-collapsed #path-debug-log,
#path-debug-panel.is-collapsed #path-debug-copy {
    display: none;
}

.path-debug-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.path-debug-panel__title {
    font-size: 10px;
    font-weight: 700;
    color: #9fd4ff;
    letter-spacing: 0.02em;
}

#path-debug-toggle {
    font-size: 10px;
    font-weight: 600;
    padding: 4px 8px;
    border: none;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.12);
    color: #d8eefc;
    cursor: pointer;
}

#path-debug-log {
    width: 100%;
    height: 110px;
    min-height: 80px;
    resize: vertical;
    font-family: Consolas, "Courier New", monospace;
    font-size: 10px;
    line-height: 1.4;
    color: #d8eefc;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 4px;
    padding: 6px;
}

#path-debug-copy {
    align-self: flex-start;
    font-size: 10px;
    font-weight: 600;
    padding: 5px 10px;
    border: none;
    border-radius: 4px;
    background: linear-gradient(180deg, #2f86de 0%, #145da0 100%);
    color: #fff;
    cursor: pointer;
}

/* ── Mobil: ljusare bana + tydligare enheter ───────────────── */

@media (pointer: coarse), (max-width: 720px) {
    .arena-background {
        filter: brightness(1.14) contrast(1.08) saturate(1.10);
    }

    #arena-layer::after {
        content: "";
        position: absolute;
        inset: 0;
        background: rgba(255, 246, 214, 0.07);
        pointer-events: none;
    }

    .unit-sprite-img {
        --unit-outline-filter:
            drop-shadow(0 0 1px rgba(8, 16, 24, 0.72))
            drop-shadow(0 1.5px 0 rgba(8, 16, 24, 0.68))
            drop-shadow(0 -1.5px 0 rgba(8, 16, 24, 0.68))
            drop-shadow(1.5px 0 0 rgba(8, 16, 24, 0.68))
            drop-shadow(-1.5px 0 0 rgba(8, 16, 24, 0.68));
        filter:
            brightness(1.26)
            contrast(1.16)
            saturate(1.12)
            var(--unit-outline-filter);
    }

    .unit-sprite-wrapper.team-blue .unit-sprite-img {
        filter:
            brightness(1.26)
            contrast(1.16)
            saturate(1.12)
            var(--unit-outline-filter)
            drop-shadow(0 -2px 3px rgba(120, 200, 255, 0.24));
    }

    .unit-sprite-wrapper.team-red .unit-sprite-img {
        filter:
            brightness(1.26)
            contrast(1.16)
            saturate(1.12)
            var(--unit-outline-filter)
            drop-shadow(0 -2px 3px rgba(255, 170, 120, 0.24));
    }

    .unit-sprite-wrapper.unit-cutlass-carl .unit-sprite-img,
    .unit-sprite-wrapper.unit-enemy-cutlass-carl .unit-sprite-img,
    .unit-sprite-wrapper.unit-enemy-deckhands .unit-sprite-img {
        --unit-outline-filter:
            drop-shadow(0 0 1px rgba(8, 16, 24, 0.62))
            drop-shadow(0 1px 0 rgba(8, 16, 24, 0.58))
            drop-shadow(0 -1px 0 rgba(8, 16, 24, 0.58))
            drop-shadow(1px 0 0 rgba(8, 16, 24, 0.58))
            drop-shadow(-1px 0 0 rgba(8, 16, 24, 0.58));
        filter:
            brightness(1.26)
            contrast(1.16)
            saturate(1.12)
            var(--unit-outline-filter);
    }

    .unit-sprite-shadow {
        opacity: 0.88;
    }
}

/* Animationstest — dölj hand/energi så fokus ligger på uniten */
body.animation-test-mode #card-panel,
body.animation-test-mode .card-panel,
body.animation-test-mode #energy-bar,
body.animation-test-mode .energy-panel {
    display: none !important;
}

.anim-test-label-bar {
    position: absolute;
    left: 50%;
    bottom: 7%;
    transform: translateX(-50%);
    z-index: 40;
    display: flex;
    gap: 10px;
    pointer-events: none;
    max-width: 94%;
}

.anim-test-label {
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 11px;
    line-height: 1.25;
    color: #ffe9a8;
    background: rgba(8, 14, 24, 0.78);
    border: 1px solid rgba(255, 210, 120, 0.35);
    white-space: nowrap;
}
