* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Kosugi Maru", "Noto Serif JP", sans-serif;
    color: #203225;
    background:
        radial-gradient(circle at 10% 15%, rgba(181, 214, 156, .34), transparent 28%),
        radial-gradient(circle at 92% 12%, rgba(151, 130, 196, .23), transparent 30%),
        linear-gradient(180deg, #f4f7eb 0%, #dbe7d1 48%, #c4d0b5 100%);
}

@media (min-width: 1181px) and (min-height: 760px) {
    body {
        height: 100dvh;
        overflow: hidden;
    }
}

button, a { font-family: inherit; }

.site-header {
    height: 58px;
    padding: 0 min(4vw, 42px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, .64);
    border-bottom: 1px solid rgba(77, 108, 81, .24);
    backdrop-filter: blur(14px);
}

.brand img {
    height: 34px;
    width: auto;
    display: block;
}

.header-actions a,
.header-controls button,
.command-panel button {
    border: 1px solid rgba(54, 88, 58, .28);
    border-radius: 6px;
    background: rgba(255, 255, 255, .78);
    color: #25442d;
    cursor: pointer;
    text-decoration: none;
}

.header-actions a {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 0 14px;
    font-size: 13px;
}

#game-shell {
    width: min(1480px, 98vw);
    margin: 0 auto;
    padding: 12px 0 14px;
}

@media (min-width: 1181px) and (min-height: 760px) {
    #game-shell {
        height: calc(100dvh - 58px);
        display: flex;
        flex-direction: column;
        min-height: 0;
        padding: 8px 0 10px;
    }
}

.battle-header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 10px;
}

@media (min-width: 1181px) and (min-height: 760px) {
    .battle-header {
        flex: 0 0 auto;
        margin-bottom: 8px;
    }
}

.kicker {
    margin: 0 0 3px;
    color: #687b4d;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .18em;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    color: #263d2a;
    font-size: clamp(22px, 3vw, 34px);
    line-height: 1.1;
    letter-spacing: .04em;
}

.header-controls {
    display: flex;
    gap: 8px;
}

.header-controls button {
    min-width: 96px;
    min-height: 34px;
    padding: 0 14px;
}

.game-layout {
    display: grid;
    grid-template-columns: 220px minmax(540px, 1fr) 280px;
    gap: 10px;
    align-items: stretch;
    min-height: 0;
}

@media (min-width: 1181px) and (min-height: 760px) {
    .game-layout {
        flex: 1 1 auto;
        height: auto;
        overflow: hidden;
    }
}

.left-panel,
.right-panel {
    display: grid;
    gap: 8px;
    align-content: start;
    max-height: 100%;
    min-height: 0;
    overflow: auto;
}

@media (min-width: 1181px) and (min-height: 760px) {
    .left-panel {
        grid-template-rows: auto auto minmax(92px, .65fr) minmax(220px, 1.8fr);
        overflow: auto;
    }

    .right-panel {
        grid-template-rows: auto minmax(0, 1fr);
        overflow: hidden;
    }
}

.panel-block,
.unit-card,
.command-panel {
    border: 1px solid rgba(70, 103, 73, .24);
    border-radius: 8px;
    background: rgba(255, 255, 255, .72);
    box-shadow: 0 18px 38px rgba(39, 66, 39, .12);
}

.panel-block {
    padding: 10px;
    min-height: 0;
}

.turn-block,
.log-block {
    display: flex;
    flex-direction: column;
}

.panel-block h2 {
    margin: 0 0 7px;
    color: #2c482f;
    font-size: 14px;
}

.legend-details summary {
    cursor: pointer;
    color: #2c482f;
    font-size: 14px;
    font-weight: 800;
    line-height: 1.25;
}

.legend-details .howto-list {
    margin-top: 8px;
}

.help-block {
    overflow: auto;
}

.help-block:has(.legend-details[open]) {
    max-height: min(34vh, 270px);
}

.panel-block p {
    margin: 0;
    color: rgba(32, 50, 37, .78);
    font-size: 12px;
    line-height: 1.5;
}

.howto-list {
    display: grid;
    gap: 5px;
    margin: 0;
    padding: 0;
    list-style: none;
    color: rgba(32, 50, 37, .78);
    font-size: 12px;
    line-height: 1.35;
}

.legend {
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-right: 6px;
    border-radius: 4px;
    vertical-align: -2px;
}

.legend.move { background: #75e06b; box-shadow: 0 0 0 2px rgba(117, 224, 107, .28); }
.legend.threat { background: #8f3038; box-shadow: 0 0 0 2px rgba(143, 48, 56, .24); }
.legend.attack { background: #ef7d69; box-shadow: 0 0 0 2px rgba(239, 125, 105, .26); }
.legend.support { background: #8397ef; box-shadow: 0 0 0 2px rgba(131, 151, 239, .24); }
.legend.boss { background: #7d55d6; box-shadow: 0 0 0 2px rgba(125, 85, 214, .24); }
.legend.tutor { background: #e2b747; box-shadow: 0 0 0 2px rgba(226, 183, 71, .24); }
.legend.minion { background: #d96d67; box-shadow: 0 0 0 2px rgba(217, 109, 103, .24); }
.legend.core { background: #5a9bb5; box-shadow: 0 0 0 2px rgba(90, 155, 181, .24); }

.status-sample {
    display: inline-block;
    width: 12px;
    height: 12px;
    margin: 0 4px 0 8px;
    border: 2px solid #fff;
    border-radius: 50%;
    vertical-align: -2px;
    box-shadow: 0 0 0 1px rgba(45, 65, 48, .18);
}

.status-sample.barrier { background: #7b8fe6; }
.status-sample.chant { background: #e6bd55; }
.status-sample.down {
    border-radius: 4px;
    background: #59625a;
}

#turn-order {
    display: grid;
    gap: 5px;
    max-height: 214px;
    overflow: auto;
}

@media (min-width: 1181px) and (min-height: 760px) {
    #turn-order {
        flex: 1 1 auto;
        max-height: none;
        min-height: 0;
    }
}

.turn-chip {
    display: grid;
    grid-template-columns: 30px 1fr auto;
    gap: 8px;
    align-items: center;
    padding: 4px 5px;
    border-radius: 6px;
    background: rgba(226, 234, 214, .78);
    color: #263d2a;
    font-size: 12px;
}

.turn-chip.active {
    background: #f0d985;
    box-shadow: inset 0 0 0 2px rgba(112, 92, 36, .22);
}

.turn-chip.enemy { background: rgba(230, 209, 213, .9); }
.turn-chip.boss {
    background: rgba(222, 211, 247, .96);
    box-shadow: inset 0 0 0 2px rgba(125, 85, 214, .22);
}
.turn-chip.tutorial {
    background: rgba(246, 229, 179, .96);
    box-shadow: inset 0 0 0 2px rgba(160, 119, 27, .18);
}
.turn-chip.core {
    background: rgba(207, 225, 235, .96);
    box-shadow: inset 0 0 0 2px rgba(63, 107, 130, .18);
}

.turn-chip span {
    display: grid;
    gap: 2px;
}

.turn-chip small {
    color: rgba(38, 61, 42, .62);
    font-size: 9px;
    line-height: 1;
    letter-spacing: .06em;
}

.turn-chip img {
    width: 24px;
    height: 24px;
    object-fit: cover;
    border-radius: 50%;
}

#battle-log {
    height: min(38vh, 300px);
    margin: 0;
    padding: 0;
    overflow: auto;
    list-style: none;
}

@media (min-width: 1181px) and (min-height: 760px) {
    #battle-log {
        flex: 1 1 auto;
        height: auto;
        min-height: 0;
    }
}

#battle-log li {
    padding: 8px 0;
    border-bottom: 1px solid rgba(65, 91, 68, .12);
    color: rgba(32, 50, 37, .82);
    font-size: 13px;
    line-height: 1.58;
}

#battle-log strong {
    color: #213725;
    font-weight: 800;
}

#battle-log .log-note {
    color: #5d4a20;
}

.map-wrap {
    position: relative;
    border: 1px solid rgba(51, 78, 48, .28);
    border-radius: 8px;
    background:
        linear-gradient(rgba(242, 247, 233, .22), rgba(242, 247, 233, .22)),
        radial-gradient(circle at 22% 28%, rgba(74, 112, 61, .2), transparent 24%),
        radial-gradient(circle at 76% 14%, rgba(113, 91, 159, .14), transparent 20%),
        linear-gradient(135deg, #9ab676, #6c8c5e 45%, #536f50);
    box-shadow: 0 20px 46px rgba(31, 57, 33, .22);
    overflow: hidden;
    height: min(100%, calc((98vw - 520px) * 12 / 14));
    min-height: 0;
    display: grid;
    place-items: center;
}

@media (min-width: 1181px) and (min-height: 760px) {
    .map-wrap {
        height: 100%;
    }
}

#phase-banner {
    position: absolute;
    z-index: 5;
    top: 8px;
    left: 8px;
    min-height: 32px;
    max-width: calc(100% - 24px);
    display: inline-flex;
    align-items: center;
    padding: 0 14px;
    border: 1px solid rgba(42, 75, 43, .28);
    border-radius: 6px;
    background: rgba(255, 255, 255, .86);
    color: #243f28;
    box-shadow: 0 10px 24px rgba(25, 48, 28, .18);
    font-size: 12px;
    line-height: 1.4;
    pointer-events: none;
}

.boss-hud {
    position: absolute;
    z-index: 6;
    top: 8px;
    right: 8px;
    width: min(330px, calc(100% - 260px));
    padding: 9px 11px 10px;
    border: 1px solid rgba(88, 57, 162, .42);
    border-radius: 8px;
    background: rgba(255, 255, 255, .9);
    box-shadow: 0 10px 24px rgba(39, 23, 80, .2);
    pointer-events: none;
}

.boss-hud-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 6px;
    color: #3f2b78;
    font-size: 12px;
    line-height: 1;
}

.boss-hud-row strong {
    font-size: 14px;
}

.boss-hud-bar {
    position: relative;
    height: 12px;
    border-radius: 999px;
    background: rgba(42, 28, 80, .22);
    overflow: visible;
    box-shadow: inset 0 0 0 1px rgba(42, 28, 80, .15);
}

.boss-hud-bar span {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #7d55d6, #dc544b, #f0d66b);
    transition: width .25s ease;
}

.boss-hud-bar::after {
    content: "";
    position: absolute;
    z-index: 2;
    left: 25%;
    top: -4px;
    width: 2px;
    height: 20px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .96);
    box-shadow: 0 0 0 1px rgba(63, 43, 110, .35), 0 0 8px rgba(63, 43, 110, .2);
}

.boss-hud-bar::before {
    content: "撃退";
    position: absolute;
    z-index: 3;
    left: calc(25% + 5px);
    top: -18px;
    color: #432c80;
    font-size: 10px;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
}

.boss-hud.warning {
    border-color: rgba(220, 84, 75, .48);
}

.boss-hud.warning .boss-hud-bar span {
    background: linear-gradient(90deg, #dc544b, #f0d66b);
}

.boss-hud.critical .boss-hud-bar span {
    background: linear-gradient(90deg, #dc544b, #f0d66b);
}

#map {
    --cols: 14;
    --rows: 12;
    --cell: min(calc((98vw - 540px) / 14), calc((100dvh - 128px) / 12));
    display: grid;
    grid-template-columns: repeat(var(--cols), var(--cell));
    grid-template-rows: repeat(var(--rows), var(--cell));
    width: calc(var(--cell) * var(--cols));
    height: calc(var(--cell) * var(--rows));
    max-height: 100%;
    min-height: 0;
    background:
        linear-gradient(rgba(245, 250, 235, .08), rgba(33, 56, 35, .08)),
        url('forest-battlefield.png') center center / cover no-repeat;
}

@media (min-width: 1181px) and (min-height: 760px) {
    #map {
        --cell: min(calc((98vw - 540px) / 14), calc((100dvh - 128px) / 12));
    }
}

.cell {
    position: relative;
    width: var(--cell);
    height: var(--cell);
    min-width: 0;
    border: 1px solid transparent;
    display: grid;
    place-items: center;
    overflow: visible;
}

.show-grid .cell {
    border-color: rgba(255, 255, 255, .26);
}

.cell.path { background: rgba(233, 226, 166, .08); }
.cell.deep { background: rgba(31, 88, 47, .18); }
.cell.cover { background: rgba(41, 67, 39, .22); }
.cell.mana { background: rgba(151, 112, 209, .24); }
.cell.clearing { background: rgba(234, 216, 151, .16); }
.cell.blocked {
    background:
        repeating-linear-gradient(135deg, rgba(43, 69, 39, .86) 0 8px, rgba(36, 58, 32, .88) 8px 16px);
}

.cell.blocked::after {
    content: "";
    width: 62%;
    height: 62%;
    border-radius: 6px;
    background: rgba(30, 53, 31, .72);
    box-shadow: inset 0 0 0 2px rgba(189, 209, 166, .1);
}

.cell.move-ok,
.cell.attack-ok,
.cell.support-ok {
    cursor: pointer;
}

.cell.threat-ok {
    background-color: rgba(128, 39, 47, .34);
    box-shadow: inset 0 0 0 2px rgba(255, 177, 161, .42), inset 0 0 20px rgba(95, 23, 31, .36);
}

.cell.move-ok {
    background-color: rgba(99, 219, 88, .68);
    box-shadow: inset 0 0 0 3px rgba(236, 255, 214, .88), inset 0 0 22px rgba(55, 134, 54, .54);
}

.cell.move-ok::before,
.cell.attack-ok::before,
.cell.support-ok::before {
    position: absolute;
    z-index: 1;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    min-width: 30px;
    min-height: 18px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    color: #17331c;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .08em;
    pointer-events: none;
}

.cell.move-ok::before {
    content: "";
    min-width: 0;
    min-height: 0;
    background: transparent;
}

.cell.guide-move {
    box-shadow:
        inset 0 0 0 4px #f0d985,
        inset 0 0 22px rgba(244, 214, 111, .82),
        0 0 0 3px rgba(240, 217, 133, .46);
}

.cell.guide-move::before {
    content: "GUIDE";
    background: #f0d985;
    color: #33270b;
}

.guide-arrow {
    position: absolute;
    z-index: 9;
    left: 50%;
    top: -26px;
    transform: translateX(-50%);
    display: grid;
    justify-items: center;
    gap: 1px;
    padding: 3px 7px 4px;
    border: 1px solid rgba(111, 82, 15, .35);
    border-radius: 6px;
    background: rgba(255, 247, 211, .96);
    color: #3a3017;
    box-shadow: 0 6px 14px rgba(63, 48, 12, .2);
    font-size: 10px;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
    pointer-events: none;
}

.guide-arrow-symbol {
    color: #d16c29;
    font-size: 16px;
    line-height: .8;
}

.cell.attack-ok {
    background-color: rgba(232, 103, 86, .72);
    box-shadow: inset 0 0 0 3px rgba(255, 231, 225, .9), inset 0 0 22px rgba(143, 45, 41, .42);
}

.cell.attack-ok::before {
    content: "ATK";
    background: rgba(255, 232, 226, .92);
    color: #5c1e1d;
}

.cell.guide-target {
    box-shadow:
        inset 0 0 0 4px #f0d985,
        inset 0 0 22px rgba(244, 214, 111, .72),
        0 0 0 3px rgba(240, 217, 133, .42);
}

.cell.guide-target::before {
    content: "TARGET";
    min-width: 48px;
    background: #f0d985;
    color: #33270b;
}

.cell.support-ok {
    background-color: rgba(126, 145, 235, .7);
    box-shadow: inset 0 0 0 3px rgba(232, 237, 255, .88), inset 0 0 22px rgba(50, 67, 152, .38);
}

.cell.support-ok::before {
    content: "HELP";
    background: rgba(235, 239, 255, .94);
    color: #24357c;
}

.cell.guide-target::before {
    content: "TARGET";
    min-width: 48px;
    background: #f0d985;
    color: #33270b;
}

.cell.selected { box-shadow: inset 0 0 0 3px #f4d66f; }
.cell.active-origin {
    box-shadow: inset 0 0 0 4px #ffffff, inset 0 0 20px rgba(244, 214, 111, .72);
}

.cell.active-origin::after {
    content: "NOW";
    position: absolute;
    z-index: 3;
    left: 4px;
    top: 4px;
    padding: 3px 5px;
    border-radius: 4px;
    background: #f4d66f;
    color: #352a10;
    font-size: 9px;
    font-weight: 800;
    pointer-events: none;
}

.unit {
    position: relative;
    z-index: 2;
    --unit-scale: 1;
    width: 86%;
    height: 86%;
    border: 2px solid rgba(255, 255, 255, .8);
    border-radius: 50%;
    background: rgba(255, 255, 255, .72);
    box-shadow: 0 10px 20px rgba(20, 43, 24, .22);
    scale: var(--unit-scale);
    overflow: visible;
    cursor: pointer;
    pointer-events: none;
}

.unit img,
.hp-ring {
    clip-path: circle(50% at 50% 50%);
}

.unit.enemy {
    border-color: rgba(106, 43, 63, .82);
    background: rgba(245, 221, 224, .84);
}

.unit.boss {
    --unit-scale: 1.08;
    border-color: #7d55d6;
    box-shadow: 0 0 0 3px rgba(125, 85, 214, .26), 0 13px 22px rgba(61, 43, 104, .26);
}

.unit.boss::before {
    content: "";
    position: absolute;
    inset: -9px;
    z-index: -1;
    border-radius: 50%;
    border: 2px solid rgba(222, 211, 247, .54);
    border-left-color: transparent;
    border-bottom-color: transparent;
    animation: bossAura 2.6s linear infinite;
}

.unit.tutorial {
    border-color: #e2b747;
    box-shadow: 0 0 0 3px rgba(226, 183, 71, .24), 0 12px 20px rgba(98, 72, 16, .2);
}

.unit.minion {
    border-color: #d96d67;
}

.unit.core {
    border-color: #5a9bb5;
    box-shadow: 0 0 0 3px rgba(90, 155, 181, .24), 0 12px 20px rgba(34, 75, 94, .2);
}

.unit.anim-attack {
    animation: unitAttack .34s ease-out;
}

.unit.anim-hit {
    animation: unitHit .36s ease-out;
}

.unit.anim-heal {
    animation: unitHeal .42s ease-out;
}

.unit.anim-guard {
    animation: unitGuard .4s ease-out;
}

@keyframes unitAttack {
    0% { translate: 0 0; filter: none; }
    42% { translate: 0 -7px; filter: brightness(1.14); }
    100% { translate: 0 0; filter: none; }
}

@keyframes unitHit {
    0%, 100% { translate: 0 0; filter: none; }
    22% { translate: -5px 0; filter: brightness(1.28); }
    44% { translate: 5px 0; filter: brightness(.92); }
    66% { translate: -3px 0; filter: brightness(1.12); }
}

@keyframes unitHeal {
    0% { filter: none; box-shadow: 0 10px 20px rgba(20, 43, 24, .22); }
    45% { filter: brightness(1.14); box-shadow: 0 0 0 5px rgba(128, 219, 133, .35), 0 10px 20px rgba(20, 43, 24, .22); }
    100% { filter: none; box-shadow: 0 10px 20px rgba(20, 43, 24, .22); }
}

@keyframes unitGuard {
    0% { box-shadow: 0 10px 20px rgba(20, 43, 24, .22); }
    45% { box-shadow: 0 0 0 6px rgba(125, 143, 230, .38), 0 10px 20px rgba(20, 43, 24, .22); }
    100% { box-shadow: 0 10px 20px rgba(20, 43, 24, .22); }
}

.cell-effect,
.float-text {
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 12;
    pointer-events: none;
}

.cell-effect {
    width: 82%;
    height: 82%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    opacity: 0;
    animation: cellFx .52s ease-out;
}

.cell-effect::before,
.cell-effect::after {
    content: "";
    position: absolute;
    pointer-events: none;
}

.cell-effect.fx-slash::before {
    left: 12%;
    top: 48%;
    width: 76%;
    height: 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .95);
    box-shadow: 0 0 8px rgba(255, 241, 198, .88);
    transform: rotate(-28deg);
}

.cell-effect.fx-fire {
    background: radial-gradient(circle, rgba(255, 226, 120, .62) 0 22%, rgba(220, 84, 75, .52) 38%, transparent 68%);
}

.cell-effect.fx-lightning::before {
    left: 43%;
    top: 8%;
    width: 16%;
    height: 84%;
    background: linear-gradient(180deg, rgba(244, 230, 255, .98), rgba(125, 85, 214, .72));
    clip-path: polygon(45% 0, 78% 0, 57% 42%, 88% 42%, 35% 100%, 48% 54%, 18% 54%);
    filter: drop-shadow(0 0 7px rgba(125, 85, 214, .72));
}

.cell-effect.fx-moon {
    box-shadow: inset 0 0 0 3px rgba(235, 229, 255, .9), 0 0 16px rgba(125, 85, 214, .42);
}

.cell-effect.fx-wind {
    border: 3px solid rgba(226, 247, 236, .9);
    border-left-color: transparent;
    border-bottom-color: transparent;
    transform: translate(-50%, -50%) rotate(22deg);
}

.cell-effect.fx-heal {
    box-shadow: inset 0 0 0 3px rgba(217, 255, 205, .86), 0 0 18px rgba(120, 200, 104, .5);
}

.cell-effect.fx-guard {
    box-shadow: inset 0 0 0 4px rgba(226, 231, 255, .9), 0 0 18px rgba(86, 103, 200, .44);
}

.cell-effect.fx-debuff,
.cell-effect.fx-taunt {
    box-shadow: inset 0 0 0 3px rgba(255, 223, 170, .92), 0 0 16px rgba(126, 77, 34, .42);
}

.cell-effect.fx-defeat {
    background: radial-gradient(circle, rgba(255, 255, 255, .56) 0 18%, rgba(80, 58, 96, .32) 38%, transparent 72%);
}

.cell-effect.fx-taunt::before {
    left: 50%;
    top: 50%;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: rgba(240, 217, 133, .96);
    transform: translate(-50%, -50%);
}

.float-text {
    min-width: 36px;
    transform: translate(-50%, -62%);
    color: #fff;
    font-size: clamp(12px, calc(var(--cell) * .26), 18px);
    font-weight: 900;
    line-height: 1;
    text-align: center;
    text-shadow: 0 2px 4px rgba(27, 26, 20, .62), 0 0 7px rgba(27, 26, 20, .35);
    white-space: nowrap;
    animation: floatText .76s ease-out forwards;
}

.float-text.damage {
    color: #fff0df;
}

.float-text.heal {
    color: #e9ffd8;
}

.float-text.status {
    color: #fff4bd;
    font-size: clamp(11px, calc(var(--cell) * .22), 15px);
}

@keyframes cellFx {
    0% { opacity: 0; scale: .6; }
    18% { opacity: 1; scale: 1; }
    100% { opacity: 0; scale: 1.18; }
}

@keyframes floatText {
    0% { opacity: 0; translate: 0 6px; scale: .9; }
    18% { opacity: 1; translate: 0 0; scale: 1.08; }
    100% { opacity: 0; translate: 0 -24px; scale: 1; }
}

@keyframes bossAura {
    from { rotate: 0deg; }
    to { rotate: 360deg; }
}

@keyframes defeatFade {
    0% { opacity: .9; filter: brightness(1.25) grayscale(.15); translate: 0 0; }
    55% { opacity: .55; filter: brightness(1.05) grayscale(.45); translate: 0 -3px; }
    100% { opacity: 0; filter: grayscale(1); translate: 0 -8px; }
}

.unit-kind-badge {
    position: absolute;
    z-index: 4;
    left: 50%;
    bottom: 8%;
    transform: translateX(-50%);
    max-width: 94%;
    padding: 2px 5px;
    border-radius: 4px;
    background: rgba(255, 255, 255, .92);
    color: #3d2a52;
    font-size: 8px;
    font-weight: 800;
    line-height: 1;
    letter-spacing: .04em;
    white-space: nowrap;
    pointer-events: none;
}

.unit.boss .unit-kind-badge {
    bottom: 9%;
    width: auto;
    max-width: 94%;
    padding: 2px 5px;
    background: #7d55d6;
    color: #fff;
    font-size: 8px;
    box-shadow: 0 2px 8px rgba(39, 23, 80, .28);
}

.boss-nameplate {
    position: absolute;
    z-index: 8;
    left: 50%;
    top: -18px;
    transform: translateX(-50%);
    padding: 3px 7px;
    border-radius: 4px;
    background: rgba(255, 255, 255, .96);
    border: 1px solid rgba(125, 85, 214, .42);
    color: #432c80;
    font-size: 10px;
    font-weight: 800;
    line-height: 1;
    letter-spacing: .02em;
    box-shadow: 0 4px 12px rgba(39, 23, 80, .2);
    white-space: nowrap;
    pointer-events: none;
}

.unit-top-hp {
    position: absolute;
    z-index: 7;
    left: 50%;
    top: -8px;
    width: 86%;
    height: 7px;
    transform: translateX(-50%);
    border: 1px solid rgba(72, 35, 41, .5);
    border-radius: 999px;
    background: rgba(47, 25, 29, .56);
    box-shadow: 0 2px 8px rgba(32, 16, 18, .22);
    overflow: hidden;
    pointer-events: none;
}

.unit-top-hp span {
    display: block;
    height: 100%;
}

.unit-top-hp.ally span {
    background: linear-gradient(90deg, #61c77a, #d4ef70);
}

.unit-top-hp.enemy span {
    background: linear-gradient(90deg, #dc544b, #f0d66b);
}

.unit.boss .unit-top-hp {
    top: -10px;
    width: 104%;
    height: 8px;
    border-color: rgba(89, 57, 162, .62);
    background: rgba(42, 28, 80, .6);
}

.unit.tutorial .unit-kind-badge {
    background: #e2b747;
    color: #33270b;
}

.unit.minion .unit-kind-badge {
    background: #d96d67;
    color: #fff;
}

.unit.core .unit-kind-badge {
    background: #5a9bb5;
    color: #fff;
}

.unit.acted {
    opacity: .54;
    filter: grayscale(.2);
}

.unit.dead {
    opacity: .32;
    filter: grayscale(1);
}

.unit.ally.dead::after {
    content: "DOWN";
    position: absolute;
    z-index: 9;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    padding: 3px 6px;
    border-radius: 4px;
    background: rgba(35, 42, 36, .82);
    color: #fff;
    font-size: 9px;
    font-weight: 900;
    line-height: 1;
    pointer-events: none;
}

.unit.defeat {
    opacity: .85;
    animation: defeatFade .62s ease-out forwards;
}

.unit img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 18%;
    display: block;
}

.hp-ring {
    position: absolute;
    left: 8%;
    right: 8%;
    bottom: 6%;
    height: 5px;
    border-radius: 999px;
    background: rgba(35, 39, 28, .32);
    overflow: hidden;
}

.hp-ring span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #85c86d, #f1d26d);
}

.status-dot {
    position: absolute;
    right: 5px;
    top: 5px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid #fff;
}

.status-dot.barrier { background: #7b8fe6; }
.status-dot.chant { background: #e6bd55; }

.unit-card {
    min-height: 0;
    overflow: hidden;
}

.empty-state {
    min-height: 140px;
    display: grid;
    place-items: center;
    padding: 20px;
    color: rgba(32, 50, 37, .56);
    text-align: center;
    line-height: 1.7;
}

.portrait-wrap {
    height: clamp(112px, 21vh, 160px);
    background: linear-gradient(135deg, rgba(77, 112, 66, .2), rgba(127, 97, 177, .18));
    overflow: hidden;
}

.portrait-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 18%;
    display: block;
}

.unit-info {
    padding: 10px;
}

.unit-info h2 {
    margin: 0 0 4px;
    color: #263d2a;
    font-size: 18px;
}

.unit-info .role {
    margin: 0 0 8px;
    color: #61784a;
    font-size: 12px;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.kind-tag {
    display: block;
    width: fit-content;
    max-width: 100%;
    margin: 0 0 8px;
    padding: 5px 8px;
    border-radius: 6px;
    background: rgba(234, 240, 221, .9);
    color: #314733;
    font-size: 11px;
    line-height: 1.3;
}

.kind-tag.boss {
    background: rgba(222, 211, 247, .96);
    color: #432c80;
}

.kind-tag.tutorial {
    background: rgba(246, 229, 179, .98);
    color: #5c4210;
}

.kind-tag.minion {
    background: rgba(244, 216, 214, .98);
    color: #78322e;
}

.kind-tag.core {
    background: rgba(207, 225, 235, .98);
    color: #2a5b70;
}

.stat-line {
    display: grid;
    grid-template-columns: 52px 1fr auto;
    gap: 8px;
    align-items: center;
    margin: 6px 0;
    font-size: 12px;
}

.bar {
    height: 8px;
    border-radius: 999px;
    background: rgba(42, 66, 45, .16);
    overflow: hidden;
}

.bar span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #78bd68, #f0d16a);
}

.unit-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.unit-tags span {
    padding: 4px 7px;
    border-radius: 999px;
    background: rgba(234, 240, 221, .9);
    color: #3d583d;
    font-size: 11px;
}

.command-panel {
    padding: 8px;
    display: grid;
    gap: 4px;
    max-height: calc(100dvh - 372px);
    min-height: 0;
    overflow: auto;
}

@media (min-width: 1181px) and (min-height: 760px) {
    .command-panel {
        max-height: none;
        min-height: 0;
    }
}

@media (min-width: 1181px) and (max-height: 759px) {
    body {
        height: auto;
        overflow: auto;
    }

    .game-layout {
        height: auto;
    }

    .map-wrap {
        height: auto;
    }

    #map {
        --cell: min(calc(96vw / 14), 48px);
        min-height: 0;
    }
}

.command-panel button {
    min-height: 32px;
    padding: 5px 8px;
    text-align: left;
    font-size: 12px;
    line-height: 1.35;
}

.command-panel button:disabled {
    cursor: default;
    opacity: .42;
}

.command-panel .primary {
    background: #f0d985;
    border-color: rgba(111, 92, 35, .3);
}

.command-panel .recommended {
    background: #f0d985;
    border-color: rgba(120, 92, 24, .58);
    box-shadow: inset 0 0 0 2px rgba(120, 92, 24, .18), 0 0 0 2px rgba(240, 217, 133, .32);
}

.command-panel .danger {
    background: #efd5d4;
    border-color: rgba(135, 75, 77, .3);
}

.command-group-title {
    margin: 2px 0 0;
    color: rgba(32, 50, 37, .68);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .08em;
    line-height: 1.1;
}

.command-hint {
    color: rgba(32, 50, 37, .68);
    font-size: 11px;
    line-height: 1.45;
}

.tutorial-callout {
    padding: 8px 10px;
    border: 1px solid rgba(120, 92, 24, .3);
    border-radius: 6px;
    background: rgba(255, 247, 211, .86);
    color: #3a3017;
    font-size: 12px;
    line-height: 1.55;
}

.result-panel {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(25, 42, 27, .38);
    backdrop-filter: blur(4px);
}

.result-panel[hidden] {
    display: none;
}

.result-card {
    width: min(360px, 92%);
    padding: 22px;
    border: 1px solid rgba(255, 255, 255, .58);
    border-radius: 8px;
    background: rgba(255, 255, 255, .94);
    color: #243f28;
    box-shadow: 0 24px 60px rgba(20, 34, 21, .34);
    text-align: center;
}

.result-kicker {
    margin: 0 0 6px;
    color: #6b7f54;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.result-card h2 {
    margin: 0 0 10px;
    color: #2c482f;
    font-size: 28px;
}

.result-card p {
    margin: 0 0 18px;
    color: rgba(32, 50, 37, .78);
    font-size: 14px;
    line-height: 1.65;
}

.result-card button {
    min-height: 38px;
    padding: 0 18px;
    border-color: rgba(111, 92, 35, .3);
    background: #f0d985;
}

@media (max-width: 1180px) {
    body {
        height: auto;
        overflow: auto;
    }

    .game-layout {
        grid-template-columns: 1fr;
        height: auto;
    }

    #map {
        --cell: min(calc(94vw / 14), 56px);
        min-height: 0;
    }

    .left-panel,
    .right-panel {
        grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    }

    .unit-card {
        min-height: 0;
    }

    .command-panel {
        max-height: none;
    }
}

@media (max-width: 720px) {
    .site-header,
    .battle-header {
        align-items: flex-start;
        flex-direction: column;
    }

    #game-shell {
        width: 94vw;
    }

    .map-wrap {
        overflow-x: auto;
    }

    #map {
        --cell: 56px;
        width: calc(var(--cell) * var(--cols));
    }
}
