/* Chess Modal */
.chess-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background-color: rgba(0, 0, 0, 0);
    backdrop-filter: blur(0px);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                backdrop-filter 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                background-color 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.chess-modal.active {
    opacity: 1;
    visibility: visible;
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
    pointer-events: auto;
}

.chess-modal-content {
    background-color: #0a0a0a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0;
    max-width: 600px;
    width: 100%;
    padding: 32px;
    position: relative;
    transform: translateY(50px) scale(0.96);
    opacity: 0;
    transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1),
                opacity 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    will-change: transform, opacity;
}

.chess-modal.active .chess-modal-content {
    transform: translateY(0) scale(1);
    opacity: 1;
    transition-delay: 0.08s;
}

/* Smooth exit animation */
.chess-modal:not(.active) .chess-modal-content {
    transform: translateY(30px) scale(0.98);
    opacity: 0;
    transition-delay: 0s;
    transition-duration: 0.3s;
}

.chess-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-bottom: 24px;
}

.chess-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.8rem;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease;
    line-height: 1;
    -webkit-tap-highlight-color: rgba(255, 255, 255, 0.1);
    touch-action: manipulation;
    border-radius: 4px;
}

.chess-close:hover {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.05);
}

/* Bot Info Tooltip */
.chess-bot-tooltip {
    position: absolute;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    max-width: 320px;
    background-color: rgba(10, 10, 10, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-secondary);
    opacity: 0;
    visibility: hidden;
    transform: translateX(-50%) translateY(-8px);
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
    pointer-events: none;
    z-index: 100;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.chess-bot-tooltip.visible {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

.chess-bot-tooltip .tooltip-content strong {
    color: #fff;
    font-weight: 500;
    display: block;
    margin-bottom: 6px;
}

/* Chess Board Wrapper */
.chess-board-wrapper {
    position: relative;
    margin-bottom: 20px;
}

.chess-player-top {
    position: relative;
}

/* Compact Player Display */
.chess-player-top,
.chess-player-bottom {
    display: flex;
    justify-content: center;
    margin-bottom: 8px;
}

.chess-player-bottom {
    margin-bottom: 0;
    margin-top: 8px;
}

.chess-player-compact {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background-color: rgba(255, 255, 255, 0.02);
    border-radius: 6px;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.chess-player-compact .player-piece {
    font-size: 1.1rem;
    line-height: 1;
}

.chess-player-compact .player-name {
    font-weight: 500;
    color: #fff;
    letter-spacing: -0.01em;
}

.chess-player-compact .player-flag {
    display: inline-block;
    margin-left: 4px;
    line-height: 1;
    vertical-align: middle;
}

.chess-player-compact .player-flag .flag-icon {
    width: 20px;
    height: auto;
    display: inline-block;
    vertical-align: middle;
    border-radius: 2px;
    box-shadow: 0 0 0 0.5px rgba(255, 255, 255, 0.1);
}

.chess-info-trigger {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 4px;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s ease, transform 0.2s ease;
    line-height: 1;
    -webkit-tap-highlight-color: rgba(255, 255, 255, 0.1);
    touch-action: manipulation;
    border-radius: 3px;
    margin-left: 2px;
    opacity: 0.6;
}

.chess-info-trigger:hover {
    opacity: 1;
    transform: scale(1.1);
}

.chess-info-trigger .info-icon {
    width: 100%;
    height: 100%;
    filter: brightness(0) invert(1);
    transition: opacity 0.2s ease;
    opacity: 0.8;
}

.chess-info-trigger:hover .info-icon {
    opacity: 1;
}

/* Bot Speech Bubble */
.chess-bot-speech {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    margin-top: 8px;
    z-index: 1000;
    animation: speechBubblePop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.speech-bubble-content {
    background-color: rgba(10, 10, 10, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 0.85rem;
    color: #fff;
    max-width: 280px;
    line-height: 1.4;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    position: relative;
    font-style: italic;
}


.speech-bubble-tail {
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid rgba(255, 255, 255, 0.2);
}

.speech-bubble-tail::after {
    content: '';
    position: absolute;
    top: 1px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 5px solid rgba(10, 10, 10, 0.95);
}

.chess-player-compact .player-status {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: transparent;
    transition: all 0.3s ease;
    margin-left: 4px;
}

.chess-player-compact .player-status.active {
    background-color: #3b82f6;
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.6);
}

.chess-player-compact .player-status.thinking {
    background-color: #fbbf24;
    box-shadow: 0 0 8px rgba(251, 191, 36, 0.6);
    animation: statusPulse 1.5s ease-in-out infinite;
}

.chess-player-compact .chess-thinking {
    display: inline-flex;
    align-items: center;
    margin-left: 6px;
}

.chess-player-compact .thinking-dots {
    display: inline-flex;
    gap: 3px;
    align-items: center;
}

.chess-player-compact .thinking-dots span {
    width: 4px;
    height: 4px;
    background-color: #fbbf24;
    border-radius: 50%;
    animation: thinkingPulse 1.4s ease-in-out infinite;
    box-shadow: 0 0 4px rgba(251, 191, 36, 0.6);
}

.chess-player-compact .thinking-dots span:nth-child(1) {
    animation-delay: 0s;
}

.chess-player-compact .thinking-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.chess-player-compact .thinking-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

.chess-status {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 20px;
    letter-spacing: -0.01em;
    font-weight: 400;
    min-height: 20px;
}

.chess-status-text {
    display: block;
}

.chess-board-container {
    display: flex;
    justify-content: center;
}

.chess-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    width: 100%;
    max-width: 520px;
    aspect-ratio: 1;
    box-sizing: border-box;
    overflow: hidden;
    transition: opacity 0.3s ease;
}

.chess-board.bot-thinking {
    cursor: wait;
}

.chess-square {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.15s ease;
    user-select: none;
    position: relative;
    margin: 0;
    padding: 0;
    border: none;
    outline: none;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    min-width: 44px;
    min-height: 44px;
}

.chess-square[draggable="true"] {
    cursor: grab;
}

.chess-square[draggable="true"]:active {
    cursor: grabbing;
}

.chess-square:active:not(.bot-thinking *) {
    transform: scale(0.95);
}

.chess-square:hover:not(.selected) {
    background-color: rgba(255, 255, 255, 0.15) !important;
}

.chess-square.selected {
    background-color: rgba(59, 130, 246, 0.3) !important;
}

.chess-square.possible-move::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.4);
}

.chess-square.bot-move-from {
    background-color: rgba(251, 191, 36, 0.5) !important;
    animation: botMoveFrom 0.6s ease-out;
}

.chess-square.bot-move-to {
    background-color: rgba(251, 191, 36, 0.6) !important;
    animation: botMoveTo 0.6s ease-out;
    box-shadow: 0 0 20px rgba(251, 191, 36, 0.4);
}

/* Last move highlight */
.chess-square.last-move {
    background-color: rgba(255, 255, 0, 0.15) !important;
    transition: background-color 0.3s ease;
}

.chess-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 20px;
}

.chess-button {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    padding: 10px 20px;
    min-height: 40px;
    cursor: pointer;
    font-size: 0.875rem;
    font-family: var(--font-main);
    letter-spacing: -0.01em;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: rgba(255, 255, 255, 0.1);
    touch-action: manipulation;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.chess-button svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.draw-icon {
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1;
}

.chess-button:hover {
    border-color: rgba(255, 255, 255, 0.2);
    color: #fff;
    background-color: rgba(255, 255, 255, 0.05);
}

.chess-resign:hover {
    border-color: rgba(239, 68, 68, 0.5);
    color: #ef4444;
    background-color: rgba(239, 68, 68, 0.1);
}

.chess-offer-draw:hover {
    border-color: rgba(59, 130, 246, 0.5);
    color: #3b82f6;
    background-color: rgba(59, 130, 246, 0.1);
}

/* Game Over Popup */
.chess-game-over {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    pointer-events: none;
}

.game-over-content {
    background: linear-gradient(135deg, rgba(10, 10, 10, 0.98), rgba(20, 20, 20, 0.98));
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    padding: 32px 40px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
    animation: gameOverPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    max-width: 90%;
}

.game-over-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    animation: gameOverIconBounce 0.6s ease-out 0.2s both;
}

.game-over-text {
    font-size: 1.25rem;
    font-weight: 500;
    color: #fff;
    letter-spacing: -0.02em;
    animation: gameOverTextFade 0.4s ease-out 0.3s both;
    white-space: pre-line;
    line-height: 1.4;
}

@keyframes speechBubblePop {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(0) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(8px) scale(1);
    }
}

@keyframes gameOverPop {
    from {
        opacity: 0;
        transform: scale(0.5) translateY(50px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes gameOverIconBounce {
    0% {
        opacity: 0;
        transform: scale(0) rotate(-180deg);
    }
    60% {
        transform: scale(1.2) rotate(10deg);
    }
    80% {
        transform: scale(0.9) rotate(-5deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
}

@keyframes gameOverTextFade {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

