#game-area {

    display: flex;
    flex-direction: column;

    align-items: center;
    justify-content: center;

    position: relative;
}

#top-bar {

    width: 90%;

    margin-top: 8px;

    display: flex;

    justify-content: space-between;
    align-items: center;

    margin-bottom: 20px;
}

.timer {

    width: 180px;

    text-align: center;

    padding: 12px;

    background: rgba(0,0,0,0.4);

    border:
        1px solid rgba(0,229,255,0.3);

    font-size: 1.4rem;

    color: var(--cyan);

    box-shadow:
        0 0 12px rgba(0,229,255,0.15);
}

#status-display {

    font-size: 1.1rem;

    color: var(--magenta);

    letter-spacing: 3px;
}

#board-container {
    width: min(85vmin, 900px);
    height: min(85vmin, 900px);

    min-width: 280px;
    min-height: 280px;
}

#chessboard {

    width: min(82vw, 82vh);
    height: min(82vw, 82vh);

    display: grid;

    grid-template-columns:
        repeat(8, 1fr);

    grid-template-rows:
        repeat(8, 1fr);

    aspect-ratio: 1 / 1;

    width: 100%;
    height: 100%;

    border:
        3px solid rgba(0,229,255,0.4);

    box-shadow:
        0 0 30px rgba(0,229,255,0.25);

    position: relative;
}

.square {

    position: relative;

    width: 100%;
    height: 100%;

    display: flex;

    justify-content: center;
    align-items: center;

    overflow: hidden;
}

.board-coordinate {
    position:
        absolute;

    z-index:
        6;

    pointer-events:
        none;

    user-select:
        none;

    font-size:
        clamp(
            0.55rem,
            1.15vmin,
            0.82rem
        );

    font-weight:
        700;

    line-height:
        1;

    opacity:
        0.82;

    text-shadow:
        0 0 5px
            rgba(
                0,
                0,
                0,
                0.9
            );
}

.board-file-coordinate {
    right:
        5%;

    bottom:
        4%;
}

.board-rank-coordinate {
    left:
        5%;

    top:
        4%;
}

.square.light
.board-coordinate {
    color:
        rgba(
            30,
            110,
            140,
            0.9
        );
}

.square.dark
.board-coordinate {
    color:
        rgba(
            110,
            245,
            255,
            0.9
        );
}

.light {
    background: var(--square-light);
}

.dark {
    background: var(--square-dark);
}

.square.highlight::after {

    content: "";

    width: 24%;
    height: 24%;

    border-radius: 50%;

    background: rgba(0,229,255,0.7);

    position: absolute;
}

.square.capture-highlight::after {

    content: "";

    width: 80%;
    height: 80%;

    border-radius: 50%;

    border: 4px solid var(--danger);

    position: absolute;
}

.piece {

    width: 72%;
    height: 72%;

    object-fit: contain;

    pointer-events: none;

    user-select: none;

    transition:
        transform 0.12s ease,
        filter 0.12s ease;
}

.piece:hover {

    transform: scale(1.08);

    box-shadow:
        0 0 15px rgba(5, 12, 243, 0.8);
}

.dragging {

    opacity: 0.7;

    cursor: grabbing;

    transform: scale(1.15);
}

.animated-piece {

    position: absolute;

    width: 12%;
    height: 12%;

    object-fit: contain;

    pointer-events: none;

    z-index: 999;

    transition:
        transform 0.24s ease-in-out;

    will-change:
        transform;
}

.selected-square {

    outline:
        3px solid rgba(255, 0, 200, 0.9);

    box-shadow:
        inset 0 0 18px rgba(255, 0, 200, 0.55),
        0 0 18px rgba(255, 0, 200, 0.8);
}

.legal-move-square {

    box-shadow:
        inset 0 0 18px rgba(0, 255, 255, 0.55),
        0 0 14px rgba(0, 255, 255, 0.65);
}

.legal-move-square::after {

    content: "";

    width: 26%;

    height: 26%;

    border-radius: 50%;

    background:
        rgba(0, 255, 255, 0.7);

    box-shadow:
        0 0 12px rgba(0, 255, 255, 0.9);
}

.capture-move-square {

    box-shadow:
        inset 0 0 20px rgba(255, 48, 79, 0.65),
        0 0 16px rgba(255, 48, 79, 0.75);
}

.capture-move-square::after {

    content: "";

    width: 32%;

    height: 32%;

    border-radius: 50%;

    background:
        rgba(255, 48, 79, 0.8);

    box-shadow:
        0 0 14px rgba(255, 48, 79, 1);
}

.piece-spawn {

    animation:
        pieceSpawnFlicker
        0.9s ease-out;
}

@keyframes pieceSpawnFlicker {

    0% {

        opacity: 0;

        transform:
            scale(0.6);

        filter:
            brightness(4)
            drop-shadow(
                0 0 16px #00ffee
            );
    }

    15% {

        opacity: 1;
    }

    25% {

        opacity: 0.25;
    }

    35% {

        opacity: 1;
    }

    50% {

        opacity: 0.45;
    }

    65% {

        opacity: 1;
    }

    100% {

        opacity: 1;

        transform:
            scale(1);

        filter:
            brightness(1)
            drop-shadow(
                0 0 8px rgba(
                    0,
                    255,
                    238,
                    0.4
                )
            );
    }
}

.piece {

    transition:
        filter 0.25s ease;
}

.piece:hover {

    filter:
        drop-shadow(
            0 0 12px
            rgba(
                0,
                255,
                238,
                0.8
            )
        );
}

#chessboard.pre-game {

    opacity: 0.35;

    transition:
        opacity 0.5s ease;
}

.piece-animation-hidden {
    opacity: 0;
}

.capture-blue-glow::before {
    content: "";

    position: absolute;
    inset: 8%;

    border-radius: 50%;

    background:
        radial-gradient(
            circle,
            rgba(0, 229, 255, 0.5),
            rgba(0, 229, 255, 0.08) 65%,
            transparent 78%
        );

    box-shadow:
        0 0 18px rgba(0, 229, 255, 0.9),
        inset 0 0 18px rgba(0, 229, 255, 0.55);

    pointer-events: none;

    z-index: 3;

    animation:
        captureBlueGlow 0.28s ease;
}

@keyframes captureBlueGlow {
    0% {
        opacity: 0;
        transform: scale(0.65);
    }

    45% {
        opacity: 1;
        transform: scale(1.12);
    }

    100% {
        opacity: 0.65;
        transform: scale(1);
    }
}

.animated-piece {
    position: absolute;

    object-fit: contain;

    pointer-events: none;

    z-index: 999;

    transition:
        transform 0.27s ease-in-out;

    will-change:
        transform;

    filter:
        drop-shadow(0 0 12px rgba(0, 229, 255, 0.7));
}

.king-promotion-glow {
    animation:
        kingPromotionGlow 0.7s ease;
}

@keyframes kingPromotionGlow {
    0% {
        transform: scale(1);
        filter:
            drop-shadow(0 0 0 rgba(180, 70, 255, 0));
    }

    40% {
        transform: scale(1.18);
        filter:
            drop-shadow(0 0 16px rgba(180, 70, 255, 1))
            drop-shadow(0 0 28px rgba(120, 0, 255, 0.75));
    }

    100% {
        transform: scale(1);
        filter:
            drop-shadow(0 0 8px rgba(180, 70, 255, 0.45));
    }
}

/* Tablet / mobile board scaling */
@media (max-width: 1100px) {

    #game-area {
        width: 100%;

        padding:
            18px 0 24px;

        align-items: center;
        justify-content: flex-start;
    }

    #board-container {
        width:
            min(
                96vw,
                calc(100svh - 170px),
                900px
            );

        height: auto;

        aspect-ratio:
            1 / 1;

        min-width: 0;
        min-height: 0;
    }

    #chessboard {
        width: 100%;
        height: 100%;
    }

    #top-bar {
        width:
            min(
                96vw,
                900px
            );

        display: flex;

        justify-content: center;
        align-items: center;

        flex-wrap: wrap;

        gap: 10px 14px;

        margin:
            0 auto 14px;
    }

    .timer {
        width: 135px;

        padding: 9px;

        font-size: 1rem;

        flex:
            0 0 auto;
    }

    #status-display {
        min-width: 150px;

        text-align: center;

        font-size: 0.9rem;

        letter-spacing: 2px;
    }

    #capture-announcer {
        flex-basis: 100%;

        width: 100%;

        text-align: center;

        margin: 0 auto;

        min-height: 1.2em;
    }
}

/* Phones */
@media (max-width: 700px) {

    #game-area {
        padding:
            10px 0 18px;
    }

    #board-container {
        width:
            min(
                98vw,
                calc(100svh - 145px)
            );
    }

    #top-bar {
        width: 98vw;

        gap: 7px;

        margin-bottom: 9px;
    }

    .timer {
        width:
            calc(50% - 12px);

        max-width: 145px;

        padding: 7px;

        font-size: 0.88rem;
    }

    #status-display {
        order: -1;

        flex-basis: 100%;

        width: 100%;

        min-width: 0;

        text-align: center;

        font-size: 0.78rem;

        letter-spacing: 1.4px;
    }

    #capture-announcer {
        flex-basis: 100%;

        width: 100%;

        padding: 0 6px;

        text-align: center;

        font-size: 0.68rem;
    }
}