:root {
    --earth: #8a5832;
    --earth-dark: #59351f;
    --grass: #78a844;
    --grass-dark: #426b2f;
    --earth-texture: radial-gradient(ellipse at 25% 30%, #ad7547 0 5%, transparent 6%), radial-gradient(ellipse at 72% 70%, #704326 0 5%, transparent 6%), linear-gradient(135deg, #9a6439, #744523)
}

body[data-battleships-room] {
    --game-ui-accent: #78a844;
    --game-ui-panel: #172744f2;
    --game-ui-header-background: #304d29f2;
    --game-ui-primary-background: #426b2f;
}

body {
    background: radial-gradient(circle at 50% 20%, #9fcb62 0, #5b8736 42%, #304d29 100%) fixed
}

.battle-resume-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 9px
}

.battle-resume-buttons button {
    border: 0;
    border-radius: 999px;
    padding: 6px 10px;
    background: #e2e8f0;
    color: #172033;
    font-weight: 700;
    cursor: pointer
}

#kn-recent {
    color: #fff
}

#kn-recent .maedn-recent-session {
    color: #172033
}

.maedn-recent-session {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: start
}

.maedn-recent-session small {
    display: block;
    color: #64748b;
    margin-top: 2px
}

.battle-game {
    --battle-board-size: min(calc((100vw - 58px) / 2), calc(100dvh - 215px));
    width: 100%;
    height: 100dvh;
    min-height: 0;
    margin: 0 auto;
    padding: calc(var(--nav-height) + 12px) 14px 62px;
    display: grid;
    position: relative;
    grid-template-columns: repeat(2, var(--battle-board-size));
    grid-template-rows: auto minmax(0, 1fr);
    justify-content: center;
    align-content: center;
    justify-items: center;
    gap: 10px 0;
    color: #fff
}

.battle-placement {
    --battle-board-size: min(calc(100vw - 40px), calc(100dvh - 210px));
    grid-template-columns: var(--battle-board-size);
    justify-content: center;
    text-align: center
}

.battle-game:not(.battle-placement) {
    grid-template-rows: auto
}

.battle-side {
    width: var(--battle-board-size);
    min-width: 0;
    position: relative;
    height: var(--battle-board-size)
}

.battle-side h2 {
    height: 25px;
    margin: 0 0 5px;
    font-size: clamp(.9rem, 2vw, 1.2rem);
    text-align: center
}

.battle-placement-board {
    width: 100%
}

.battle-placement p {
    margin: 0 0 12px;
    font-weight: 800
}

.battle-placement-actions,
.battle-wait {
    position: absolute;
    z-index: 6;
    top: 50%;
    left: 50%;
    width: max-content;
    max-width: calc(100% - 28px);
    margin: 0;
    text-align: center;
    transform: translate(-50%, -50%);
}

.battle-placement-actions p {
    margin: 0 0 16px;
    font-weight: 800
}

.battle-player-strip {
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap
}

.battle-player {
    display: block;
    box-sizing: border-box;
    max-width: 100%;
    padding: 8px 12px;
    border: 1px solid #ffffff55;
    border-radius: 999px;
    background: #36542dcc;
    color: #fff;
    overflow-wrap: anywhere
}

.battle-player.you {
    border-color: #d6ed9d
}

.battle-player.active {
    background: #e83f4b;
    border-color: #fecdd3
}

.battle-cell.ship.selected::after {
    background: #b07943
}

.battle-cell.ship.destroyed::after {
    background: #4c2e20
}

.battle-cell.mine {
    padding: 0
}

.battle-mine-icon {
    display: block;
    position: relative;
    z-index: 2;
    width: 100%;
    height: 100%;
    margin: auto;
    object-fit: contain;
    opacity: 1;
    pointer-events: none
}

.battle-hard-mode {
    display: flex !important;
    align-items: center;
    gap: 7px;
    cursor: pointer
}

.battle-hard-mode input {
    min-height: auto !important;
    width: 1rem;
    height: 1rem
}

.battle-hard-status {
    position: absolute;
    z-index: 6;
    bottom: 12px;
    left: 50%;
    width: max-content;
    max-width: calc(100% - 28px);
    margin: 0;
    padding: .35rem .65rem;
    border-radius: 999px;
    color: #fff;
    background: #36542dcc;
    font-weight: 800;
    text-align: center;
    transform: translateX(-50%)
}

.battle-player-area {
    position: absolute;
    z-index: 5;
    bottom: calc(100% + 5px);
    left: 50%;
    width: max-content;
    max-width: 100%;
    margin: 0;
    text-align: center;
    transform: translateX(-50%)
}

.battle-player-reaction {
    position: absolute;
    z-index: 1;
    left: 50%;
    bottom: calc(100% + 7px);
    min-width: 2.2rem;
    max-width: min(240px, 80vw);
    padding: .3rem .5rem;
    border-radius: .8rem;
    color: #202020;
    background: #fff;
    box-shadow: 0 .25rem .7rem #0007;
    font-size: 1.45rem;
    font-weight: 400;
    line-height: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    overflow-wrap: anywhere;
    transform: translateX(-50%)
}

.battle-player-reaction::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: -6px;
    border: 7px solid transparent;
    border-top-color: #fff;
    border-bottom: 0;
    transform: translateX(-50%)
}

.battle-player-reaction.message {
    font-size: .88rem;
    line-height: 1.25
}

.battle-wait {
    color: #edf8c9;
    font-weight: 800
}

.battle-game > button {
    justify-self: center
}

.battle-board {
    display: grid;
    width: var(--battle-board-size);
    height: var(--battle-board-size);
    max-width: none;
    grid-template-columns:repeat(10, 1fr);
    gap: 0;
    aspect-ratio: 1;
    background: var(--earth-dark);
    border: 10px solid #5d3a22;
    padding: 0;
    box-shadow: 0 18px 38px #071a2a55
}

.battle-board.enemy {
    background: var(--grass-dark);
    border-color: #365b2b;
}

.battle-board-wrap {
    position: relative;
    width: var(--battle-board-size);
    height: var(--battle-board-size)
}

.battle-shot-result {
    position: absolute;
    z-index: 4;
    top: 50%;
    left: 50%;
    padding: .3em .55em;
    border-radius: 6px;
    color: #fff;
    background: #172033d9;
    font-size: clamp(1rem, 4vw, 2rem);
    font-weight: 900;
    letter-spacing: .08em;
    pointer-events: none;
    transform: translate(-50%, -50%);
    animation: battle-shot-result-flash 1.5s ease-out forwards
}

.battle-shot-result.hit {
    background: #c83f3fd9
}

.battle-shot-result.raised {
    top: 15%
}

@keyframes battle-shot-result-flash {
    0%, 55% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1)
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(1.12)
    }
}

.battle-cell {
    min-width: 0;
    border: 0;
    padding: 0;
    position: relative;
    overflow: visible;
    background: var(--earth-texture);
    color: #fff5e3;
    font-weight: 900;
    font-size: clamp(.8rem, 2vw, 1.4rem);
    cursor: pointer;
    aspect-ratio: 1;
    touch-action: none
}

.battle-board.enemy .battle-cell {
    background-image: url(/public/img/find-carrots/grass.png), var(--earth-texture);
    background-repeat: no-repeat, repeat;
    background-size: 100%, auto
}

.battle-cell.ship {
    background: #85512d
}

.battle-cell.ship::after {
    content: '';
    display: block;
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: #b77a43;
    z-index: 0;
}

.battle-cell.ship.hit::after {
    background: #f58a24
}

.battle-cell.ship.invalid::after {
    background: #ef4444
}

.battle-cell.ship.drag-preview::after {
    background: #c99558
}

.battle-cell-mark {
    position: relative;
    z-index: 2
}

.battle-cell.ship-horizontal.ship-stern::after {
    border-radius: 50% 0 0 50%
}

.battle-cell.ship-horizontal.ship-bow::after {
    border-radius: 0 50% 50% 0
}

.battle-cell.ship-vertical.ship-stern::after {
    border-radius: 50% 50% 0 0
}

.battle-cell.ship-vertical.ship-bow::after {
    border-radius: 0 0 50% 50%
}

.battle-cell.ship-horizontal:not(.ship-stern) {
    margin-left: 0
}

.battle-cell.ship-vertical:not(.ship-stern) {
    margin-top: 0
}

.battle-cell.ship-horizontal:not(.ship-stern)::before,
.battle-cell.ship-vertical:not(.ship-stern)::before {
    content: '';
    position: absolute;
    z-index: 1;
    pointer-events: none;
    background: #b77a43
}

.battle-cell.ship-horizontal:not(.ship-stern)::before {
    top: 0;
    right: 100%;
    width: 2px;
    height: 100%
}

.battle-cell.ship-vertical:not(.ship-stern)::before {
    bottom: 100%;
    left: 0;
    width: 100%;
    height: 2px
}

.battle-cell.drag-preview {
    background: #c99558;
    box-shadow: inset 0 0 0 2px #fff8
}

.battle-cell.ship.drag-preview {
    background: #85512d;
    box-shadow: none
}

.battle-cell.drag-preview.invalid, .battle-cell.invalid {
    background: #ef4444 !important
}

.battle-cell.ship.invalid,
.battle-cell.ship.drag-preview.invalid {
    background: #85512d !important
}

.battle-board.dragging, .battle-board.dragging .battle-cell {
    cursor: grabbing
}

.battle-board.enemy .battle-cell.miss {
    background: radial-gradient(ellipse at 50% 46%, #3c2519 0 19%, #61391f 21% 34%, #88552f 36% 51%, transparent 53%), var(--earth-texture);
    box-shadow: inset 0 2px 3px #27170d99, inset 0 -2px 2px #c18a5599;
    color: #e7c28f;
    opacity: 1;
}

.battle-board.enemy .battle-cell.found-carrot {
    background: none;
    box-shadow: none
}

.battle-board.own .battle-cell.miss {
    background: radial-gradient(ellipse at 50% 46%, #3c2519 0 19%, #61391f 21% 34%, #88552f 36% 51%, transparent 53%), var(--earth-texture);
    box-shadow: inset 0 2px 3px #27170d99, inset 0 -2px 2px #c18a5599;
    color: #e7c28f
}

.battle-board.own .battle-cell.hit {
    background: radial-gradient(ellipse at 50% 46%, #f08234 0 22%, #c9682b 24% 34%, #88552f 36% 52%, transparent 54%), var(--earth-texture);
    box-shadow: inset 0 2px 3px #4c271599, inset 0 -2px 2px #ffc07d99;
    color: #fff7dc
}

.battle-cell.ship.destroyed::after {
    background: #4c2e20
}

.battle-board.enemy .battle-cell.ship.hit:disabled {
    opacity: 1;
}

.battle-cell:disabled {
    cursor: default
}

.battle-cell.found-carrot,
.battle-cell.found-worm,
.battle-cell.empty,
.battle-cell.mine,
.battle-cell.carrot-complete {
    opacity: 1 !important
}

.battle-board.enemy .battle-cell:not(:disabled):hover {
    background: radial-gradient(circle at 50% 50%, #b7d975 0 19%, #85b94e 21% 50%, #61933d 52%)
}

.battle-cell.carrot-complete::after,
.battle-cell.carrot-complete::before {
    display: none
}

.battle-board.enemy .battle-cell.carrot-complete {
    background: var(--earth-texture)
}

.battle-cell.carrot-own::before {
    display: none
}

.battle-cell.carrot-own::after {
    display: none
}

.battle-cell.carrot-own.hit::after {
    display: none
}

.battle-board.own .battle-cell.carrot-own:not(.hit) {
    background: var(--earth-texture) !important
}

.battle-carrot-icon {
    position: absolute;
    z-index: 3;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    pointer-events: none
}

.battle-found-icon {
    display: block;
    width: 100%;
    height: 100%;
    opacity: 1;
    object-fit: fill;
    pointer-events: none;
    background: #88552f73;
}

.battle-own-found-icon {
    position: absolute;
    z-index: 4;
    inset: 0
}

.battle-found-icon.rotation-90 { transform: rotate(90deg) }
.battle-found-icon.rotation-180 { transform: rotate(180deg) }
.battle-found-icon.rotation-270 { transform: rotate(270deg) }

.battle-worm-hello {
    position: fixed;
    z-index: 100;
    top: 15vh;
    right: 0;
    width: auto;
    max-width: 85vw;
    height: 70vh;
    max-height: 680px;
    pointer-events: none;
    transform: translateX(110%);
    animation: battle-worm-hello 3.6s ease-in-out forwards
}

@keyframes battle-worm-hello {
    0% { transform: translateX(110%) }
    24%, 72% { transform: translateX(0) }
    100% { transform: translateX(110%) }
}

.battle-cell.invalid .battle-carrot-icon {
    opacity: 0.5;
    filter: hue-rotate(313deg);
}

.battle-carrot-icon.carrot-size-2 { width: 200% }
.battle-carrot-icon.carrot-size-3 { width: 300% }
.battle-carrot-icon.carrot-size-4 { width: 400% }
.battle-carrot-icon.carrot-size-5 { width: 500% }
.battle-carrot-icon.vertical {
    left: 100%;
    transform: rotate(90deg);
    transform-origin: top left
}

.axis {
    display: none
}

.battle-result {
    position: absolute;
    z-index: 10;
    top: 50%;
    left: 50%;
    width: max-content;
    max-width: calc(100% - 28px);
    margin: 0;
    padding: .7rem 1rem;
    border-radius: .8rem;
    color: #fff;
    background: #172033e8;
    box-shadow: 0 .4rem 1.2rem #0007;
    text-align: center;
    transform: translate(-50%, -50%)
}

.battle-result h2 {
    margin: 0 0 .6rem;
    font-size: clamp(1.2rem, 4vw, 2rem)
}

@media (max-width: 640px) {
    .battle-game {
        padding-top: calc(var(--nav-height) + 10px)
    }

    .maedn-nav .maedn-wordmark {
        font-size: 1rem
    }

    .battle-board {
        border-width: 7px;
        gap: 0
    }

    .battle-cell {
        font-size: .85rem
    }
}

@media (orientation: portrait) {
    .battle-game:not(.battle-placement) {
        --battle-board-size: min(calc(100vw - 42px), calc((100dvh - 220px) / 2));
        grid-template-columns: var(--battle-board-size);
        grid-template-rows: repeat(2, minmax(0, 1fr));
        gap: 5px;
        padding-bottom: 48px
    }

    .battle-game:not(.battle-placement) .battle-side.enemy {
        order: 1;
        align-self: end
    }

    .battle-game:not(.battle-placement) .battle-side.own {
        order: 2;
        align-self: start
    }

    .battle-game:not(.battle-placement) .battle-player-area {
        position: absolute;
        width: max-content;
        max-width: 100%;
        bottom: auto;
        margin: 0;
        transform: none
    }

    .battle-game:not(.battle-placement) .battle-side.enemy .battle-player-area {
        right: 0;
        bottom: calc(100% + 5px);
        left: auto
    }

    .battle-game:not(.battle-placement) .battle-side.own .battle-player-area {
        top: calc(100% + 5px);
        right: auto;
        left: 0
    }
}
