.chessboard {
    width: 480px;
    height: 480px;
    max-width: 100%;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    border: 2px solid #4a4a4a; /* Thin dark grey border */
    background: #d4c4a8; /* Light tan-grey */
    border-radius: 6px;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    flex-shrink: 0; /* Prevent shrinking */
}

@media (max-width: 600px) {
    .chessboard {
        width: 100%;
        max-width: calc(100vw - 20px);
        height: calc(100vw - 20px); /* Fixed height based on width */
        min-height: calc(100vw - 20px);
        max-height: calc(100vw - 20px);
    }
}

.square {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    transition: background-color 0.2s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    flex-shrink: 0; /* Prevent squares from resizing */
    min-width: 0; /* Allow grid to handle sizing */
    min-height: 0;
}

.square.light {
    background-color: #d4c4a8; /* Light tan-grey */
}

.square.dark {
    background-color: #8b7355; /* Medium grey-brown */
}

.square.selected {
    background-color: rgba(255, 100, 50, 0.4) !important; /* Soft reddish-orange */
}

.square.possible-move::before {
    content: '';
    position: absolute;
    width: 30%;
    height: 30%;
    background-color: rgba(255, 100, 50, 0.5);
    border-radius: 50%;
}

.square.possible-capture::after {
    content: '';
    position: absolute;
    width: 90%;
    height: 90%;
    border: 2px solid rgba(255, 100, 50, 0.7);
    border-radius: 50%;
    box-sizing: border-box;
}

.square.in-check {
    background-color: rgba(255, 100, 50, 0.5) !important; /* Soft reddish-orange highlight */
}

.square.last-move {
    background-color: rgba(255, 200, 100, 0.3) !important; /* Subtle highlight for last move */
}

/* Last move arrow */
.square.last-move-from::after,
.square.last-move-to::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

.chess-piece {
    width: 85%;
    height: 85%;
    font-size: clamp(2em, 8vw, 3em);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    position: relative;
    z-index: 10;
    font-weight: bold;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    transition: transform 0.15s;
}

.chess-piece:active {
    cursor: grabbing;
    transform: scale(1.05);
    z-index: 100;
}

@media (max-width: 480px) {
    .chess-piece {
        font-size: 2.2em;
    }
}

.chess-piece.dragging {
    cursor: grabbing;
    opacity: 0.6;
    z-index: 100;
}

.chess-piece.white {
    color: #ffffff;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
}

.chess-piece.black {
    color: #2c2c2c; /* Dark grey/black */
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.2));
}

/* King in check - glowing red outline */
.chess-piece.in-check {
    filter: drop-shadow(0 0 8px #ff3333) drop-shadow(0 0 12px #ff3333) drop-shadow(0 0 16px #ff3333);
    animation: check-pulse 1s ease-in-out infinite;
}

@keyframes check-pulse {
    0%, 100% { 
        filter: drop-shadow(0 0 8px #ff3333) drop-shadow(0 0 12px #ff3333) drop-shadow(0 0 16px #ff3333);
    }
    50% { 
        filter: drop-shadow(0 0 12px #ff3333) drop-shadow(0 0 16px #ff3333) drop-shadow(0 0 20px #ff3333);
    }
}

/* Last move arrow indicator */
.last-move-arrow {
    position: absolute;
    pointer-events: none;
    z-index: 8;
    width: 100%;
    height: 100%;
}

.last-move-arrow svg {
    width: 100%;
    height: 100%;
}

/* Coordinate labels - hide on mobile */
.square::before {
    content: attr(data-coord);
    position: absolute;
    font-size: 9px;
    color: rgba(0,0,0,0.2);
    bottom: 2px;
    left: 2px;
    pointer-events: none;
    font-weight: 600;
}

@media (max-width: 480px) {
    .square::before {
        display: none;
    }
}
