:root {
    color-scheme: dark;
    --bg: #17181c;
    --panel: #24262d;
    --panel-strong: #30333c;
    --line: #f3f4f6;
    --red: #e12222;
    --red-dark: #681616;
    --yellow: #ffd166;
    --blue: #6ec6ff;
    --green: #37d67a;
    --violet: #b794f4;
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    background:
        linear-gradient(180deg, #20232b 0%, var(--bg) 58%),
        var(--bg);
    color: white;
    font-family: Arial, sans-serif;
}

.game {
    width: min(960px, 100%);
    margin: auto;
    padding: 20px;
    text-align: center;
}

h1 {
    margin: 8px 0 18px;
    font-size: clamp(2rem, 7vw, 4rem);
}

.arena {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: end;
    min-height: 430px;
    overflow: hidden;
    padding: 28px 22px 18px;
    border: 2px solid #3d414d;
    border-radius: 8px;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent 48%),
        linear-gradient(0deg, #30333b 0 18%, transparent 18%),
        #20222a;
}

.arena::after {
    content: "";
    position: absolute;
    right: 0;
    bottom: 78px;
    left: 0;
    height: 2px;
    background: #50545f;
}

.fighter {
    position: relative;
    z-index: 1;
    display: grid;
    justify-items: center;
    align-content: end;
    gap: 16px;
    min-width: 0;
}

.fighter-left {
    justify-self: end;
    margin-right: clamp(-42px, -4vw, -12px);
}

.fighter-right {
    justify-self: start;
    margin-left: clamp(-42px, -4vw, -12px);
}

.fighter-hud {
    width: min(260px, 100%);
}

.fighter-name {
    display: block;
    margin-bottom: 7px;
    font-size: 1.15rem;
    font-weight: 700;
}

.health-bar {
    width: 100%;
    height: 18px;
    overflow: hidden;
    border: 2px solid #f2f2f2;
    border-radius: 4px;
    background: var(--red-dark);
}

.meter {
    width: 100%;
    height: 10px;
    overflow: hidden;
    margin-top: 8px;
    border: 1px solid rgba(255, 255, 255, 0.78);
    border-radius: 3px;
    background: #17181c;
}

.meter-fill {
    width: 100%;
    height: 100%;
    transition: width 240ms ease;
}

.stamina-fill {
    background: var(--green);
}

.luck-fill {
    background: var(--violet);
}

.health-fill {
    width: 100%;
    height: 100%;
    background: var(--red);
    transform-origin: left center;
    transition: width 240ms ease;
}

.hp-text,
.meter-text,
.status-text,
.combo-text {
    display: block;
    margin-top: 5px;
    color: #d7d9df;
    font-size: 0.95rem;
}

.meter-text,
.status-text,
.combo-text {
    font-size: 0.78rem;
}

.status-text {
    min-height: 18px;
    color: #ffd166;
}

.combo-text {
    color: #9fe7ff;
    font-weight: 700;
}

.stickman {
    width: clamp(130px, 27vw, 210px);
    height: auto;
    overflow: visible;
    filter: drop-shadow(0 10px 12px rgba(0, 0, 0, 0.35));
}

.body-part,
.limb {
    fill: none;
    stroke: var(--line);
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 9;
}

.head {
    fill: #20222a;
}

.limb {
    opacity: 0;
}

.target-head-line,
.target-body-line {
    stroke: var(--yellow);
    stroke-width: 12;
}

.fighter.attacking {
    transform-origin: bottom center;
    animation: fighter-step var(--attack-speed, 520ms) ease-in-out;
}

.fighter.attacking .attack-arm {
    animation: punch-arm var(--attack-speed, 520ms) ease-in-out;
}

.fighter.attacking.attack-head .attack-arm {
    animation-name: punch-head;
}

.fighter.defending.hit {
    animation: hit-shake 260ms ease-in-out;
}

.fighter.defending.hit-head .head {
    animation: target-flash 360ms ease;
}

.fighter.defending.hit-body .torso {
    animation: target-flash 360ms ease;
}

.fighter.dodging .head,
.fighter.dodging .torso,
.fighter.dodging .arm {
    transform-box: view-box;
    transform-origin: 80px 126px;
    animation: matrix-dodge var(--attack-speed, 1250ms) ease-in-out;
}

.fighter.missed {
    animation: miss-drift var(--attack-speed, 760ms) ease-in-out;
}

.fighter.missed .attack-arm {
    animation: miss-head-arm var(--attack-speed, 760ms) ease-in-out;
}

.impact {
    position: absolute;
    z-index: 2;
    width: 18px;
    height: 18px;
    border: 3px solid var(--yellow);
    border-radius: 50%;
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.4);
    pointer-events: none;
}

.impact.show {
    animation: impact-pop 360ms ease-out;
}

#turnText {
    min-height: 28px;
    margin: 18px 0 10px;
    font-size: 1.25rem;
    font-weight: 700;
}

#botStyleText {
    min-height: 20px;
    margin: 0 0 12px;
    color: #cbd5e1;
    font-size: 0.95rem;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

button {
    min-width: 150px;
    padding: 12px 22px;
    border: 0;
    border-radius: 6px;
    background: var(--blue);
    color: #0e1820;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
}

button:hover:not(:disabled) {
    filter: brightness(1.08);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

#modeBtn {
    background: #f4f4f5;
    color: #17181c;
}

#log {
    min-height: 118px;
    max-height: 190px;
    overflow: auto;
    margin-top: 18px;
    padding: 10px 14px;
    border-radius: 8px;
    background: var(--panel);
    text-align: left;
}

#log p {
    margin: 6px 0;
    color: #e9ebef;
}

@keyframes fighter-step {
    0%, 100% {
        transform: translateX(0) rotate(0deg);
    }

    45%, 58% {
        transform: translateX(var(--attack-distance, 48px)) rotate(var(--attack-lean, 3deg));
    }
}

@keyframes punch-arm {
    0%, 100% {
        transform: rotate(0deg);
    }

    52% {
        transform: rotate(var(--punch-rotation, -7deg)) translateX(var(--punch-reach, 3px));
    }
}

@keyframes punch-head {
    0%, 100% {
        transform: rotate(0deg);
    }

    52% {
        transform:
            rotate(var(--head-punch-rotation, -14deg))
            translateX(var(--punch-reach, 3px))
            translateY(var(--head-punch-lift, -12px));
    }
}

@keyframes miss-head-arm {
    0%, 100% {
        transform: rotate(0deg);
    }

    52% {
        transform:
            rotate(var(--miss-head-rotation, -22deg))
            translateX(var(--miss-arm-x, 7px))
            translateY(var(--miss-arm-y, -24px));
    }
}

@keyframes matrix-dodge {
    0%, 18%, 100% {
        transform: translateX(0) rotate(0deg);
    }

    34%, 78% {
        transform:
            translateX(var(--dodge-slide, 18px))
            rotate(var(--dodge-lean, 18deg));
    }

    88% {
        transform:
            translateX(calc(var(--dodge-slide, 18px) * 0.35))
            rotate(calc(var(--dodge-lean, 18deg) * 0.35));
    }
}

@keyframes hit-shake {
    0%, 100% {
        transform: translateX(0);
    }

    35% {
        transform: translateX(var(--hit-distance, -14px));
    }

    70% {
        transform: translateX(calc(var(--hit-distance, -14px) * -0.45));
    }
}

@keyframes target-flash {
    0%, 100% {
        stroke: var(--line);
    }

    35% {
        stroke: var(--yellow);
    }
}

@keyframes miss-drift {
    0%, 100% {
        transform: translateX(0);
    }

    55% {
        transform: translateX(var(--miss-distance, 34px));
    }
}

@keyframes impact-pop {
    0% {
        opacity: 0.95;
        transform: translate(-50%, -50%) scale(0.4);
    }

    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(2.4);
    }
}

@media (max-width: 620px) {
    .game {
        padding: 14px;
    }

    .arena {
        min-height: 360px;
        padding: 18px 10px 12px;
    }

    .fighter-left,
    .fighter-right {
        margin: 0;
    }

    .fighter-name {
        font-size: 1rem;
    }

    .hp-text {
        font-size: 0.82rem;
    }

    .meter-text,
    .status-text,
    .combo-text {
        font-size: 0.72rem;
    }

    button {
        width: min(100%, 240px);
    }
}
