/* ====================================================================
   Chess game (modal, board, chat)
   ==================================================================== */

/* ===== Chess modal ===== */
.chess-modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(60, 60, 90, 0.25);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}
.chess-modal.open { opacity: 1; pointer-events: auto; }

.chess-window {
    width: 100%;
    max-width: 540px;
    max-height: 92vh;
    overflow-y: auto;
    background: rgba(255, 255, 255, 0.55);
    backdrop-filter: blur(30px) saturate(180%);
    -webkit-backdrop-filter: blur(30px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: 28px;
    box-shadow:
        0 12px 50px rgba(100, 100, 150, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
    padding: 1.75rem 1.5rem;
    transform: scale(0.92);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.chess-modal.open .chess-window { transform: scale(1); }

.chess-close {
    position: absolute;
    top: 1.25rem;
    right: 1.25rem;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.5);
    color: #4a4a6a;
    font-size: 1.3rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background 0.2s ease;
}
.chess-close:hover { background: rgba(255, 255, 255, 0.8); }

.chess-title {
    font-family: 'Parisienne', cursive;
    font-size: 2rem;
    color: #4a4a6a;
    text-align: center;
    margin-bottom: 1.25rem;
}

/* Setup screens */
.chess-setup { text-align: center; }
.chess-setup-q {
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-size: 1.4rem;
    color: #3a3a5a;
    margin-bottom: 1.25rem;
}
.chess-choices {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.chess-choice {
    flex: 1;
    min-width: 120px;
    padding: 1.25rem 1rem;
    font-family: 'Caveat', cursive;
    font-size: 1.5rem;
    color: #3a3a5a;
    background: rgba(255, 255, 255, 0.45);
    border: 2px solid rgba(255, 255, 255, 0.6);
    border-radius: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
}
.chess-choice:hover {
    background: rgba(255, 255, 255, 0.75);
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(100, 100, 150, 0.15);
}
.chess-choice.selected {
    border-color: #7a7ac4;
    background: rgba(122, 122, 196, 0.18);
}
.chess-choice .big-ico { display: block; font-size: 2.2rem; margin-bottom: 0.4rem; }

/* White / black colour swatches */
.swatch-white { color: #2a2a3a; }
.swatch-white .big-ico { color: #fafafa; text-shadow: 0 0 2px rgba(0,0,0,0.4); }
.swatch-black .big-ico { color: #2a2a3a; }

/* Board */
.chess-board-wrap { margin: 0 auto; }
.chess-status {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.2rem;
    color: #3a3a5a;
    text-align: center;
    margin-bottom: 0.75rem;
    min-height: 1.5rem;
}
.chess-status .turn-name { font-weight: 600; color: #5a4a8a; }

.chess-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    max-width: 400px;
    aspect-ratio: 1 / 1;
    margin: 0 auto;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 6px 24px rgba(100, 100, 150, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.5);
    touch-action: manipulation;
}
.chess-sq {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1 / 1;
    width: 100%;
    height: 100%;
    font-size: clamp(1.5rem, 7vw, 2.2rem);
    cursor: pointer;
    user-select: none;
    position: relative;
    line-height: 1;
    overflow: hidden;
}
.chess-sq.light { background: rgba(255, 255, 255, 0.55); }
.chess-sq.dark  { background: rgba(150, 150, 190, 0.45); }
.chess-sq.sel   { background: rgba(122, 122, 196, 0.55) !important; }
.chess-sq.move::after {
    content: '';
    position: absolute;
    width: 28%;
    height: 28%;
    border-radius: 50%;
    background: rgba(90, 74, 138, 0.45);
}
.chess-sq.capture {
    box-shadow: inset 0 0 0 3px rgba(196, 77, 109, 0.6);
}
.chess-piece-w { color: #ffffff; text-shadow: 0 1px 2px rgba(0,0,0,0.45), 0 0 1px rgba(0,0,0,0.6); }
.chess-piece-b { color: #2a2a3a; text-shadow: 0 1px 1px rgba(255,255,255,0.3); }

.chess-controls {
    display: flex;
    gap: 0.6rem;
    justify-content: center;
    margin-top: 1rem;
    flex-wrap: wrap;
}
.chess-btn {
    padding: 0.5rem 1.1rem;
    font-family: 'Caveat', cursive;
    font-size: 1.15rem;
    color: #3a3a5a;
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.2s ease;
}
.chess-btn:hover { background: rgba(255, 255, 255, 0.8); }

/* ===== Chat ===== */
.chess-chat {
    margin-top: 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.5);
    padding-top: 1rem;
}
.chess-chat-title {
    font-family: 'Caveat', cursive;
    font-size: 1.2rem;
    color: #6a6a8a;
    margin-bottom: 0.5rem;
}
.chess-chat-log {
    height: 130px;
    overflow-y: auto;
    background: rgba(255, 255, 255, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 14px;
    padding: 0.6rem 0.75rem;
    margin-bottom: 0.6rem;
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.05rem;
}
.chat-msg { margin-bottom: 0.4rem; line-height: 1.3; }
.chat-msg .who { font-weight: 600; color: #5a4a8a; }
.chat-msg.olya .who { color: #c44d6d; }
.chat-msg.maks .who { color: #4a6aa0; }
.chess-chat-form { display: flex; gap: 0.5rem; }
.chess-chat-input {
    flex: 1;
    padding: 0.55rem 0.9rem;
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.05rem;
    color: #3a3a5a;
    background: rgba(255, 255, 255, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: 999px;
    outline: none;
}
.chess-chat-input::placeholder { color: rgba(90, 90, 130, 0.5); }
.chess-chat-send {
    padding: 0.55rem 1.1rem;
    font-family: 'Caveat', cursive;
    font-size: 1.1rem;
    color: #fff;
    background: rgba(80, 80, 120, 0.85);
    border: none;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.2s ease;
}
.chess-chat-send:hover { background: rgba(70, 70, 110, 0.95); }

@media (max-width: 640px) {
    .chess-window {
        padding: 1.25rem 0.85rem;
        max-width: 100%;
        max-height: 95vh;
        border-radius: 20px;
    }
    .chess-title { font-size: 1.6rem; margin-bottom: 0.75rem; }
    .chess-board { max-width: 100%; }
    .chess-choice { min-width: 100px; padding: 1rem 0.75rem; font-size: 1.3rem; }
    .chess-choice .big-ico { font-size: 1.9rem; }
    .chess-chat-log { height: 100px; }
    .chess-controls { gap: 0.4rem; }
    .chess-btn { padding: 0.45rem 0.85rem; font-size: 1.05rem; }
    .chess-close { top: 0.85rem; right: 0.85rem; width: 34px; height: 34px; }
}

/* ===== Score ===== */
.chess-score {
    text-align: center;
    font-family: 'Caveat', cursive;
    font-size: 1.35rem;
    margin-bottom: 0.5rem;
    color: #4a4a6a;
}
.chess-score .sc-olya { color: #c44d6d; font-weight: 600; }
.chess-score .sc-maks { color: #4a6aa0; font-weight: 600; }

/* ===== Selected setup choice ===== */
.chess-choice.selected {
    border-color: #7a7ac4;
    background: rgba(122, 122, 196, 0.18);
}
.chess-choice small { font-size: 0.7rem; opacity: 0.7; }

/* ===== Fact message in chat ===== */
.chat-msg.fact { opacity: 0.85; }
.chat-msg.fact .who { color: #6a6a8a; }

/* ===== Victory overlay + fireworks ===== */
.chess-victory {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(40, 40, 70, 0.45);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
    overflow: hidden;
}
.chess-victory.show { opacity: 1; pointer-events: auto; }

.victory-card {
    text-align: center;
    padding: 2.5rem 2rem;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(30px) saturate(180%);
    -webkit-backdrop-filter: blur(30px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: 28px;
    box-shadow: 0 12px 50px rgba(100, 100, 150, 0.3);
    transform: scale(0.85);
    transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    z-index: 2;
}
.chess-victory.show .victory-card { transform: scale(1); }
.victory-emoji { font-size: 3.5rem; margin-bottom: 0.5rem; animation: victoryBounce 1s ease-in-out infinite; }
@keyframes victoryBounce { 0%,100%{transform:translateY(0) scale(1);} 50%{transform:translateY(-10px) scale(1.1);} }
.victory-text {
    font-family: 'Parisienne', cursive;
    font-size: 2rem;
    color: #4a4a6a;
    line-height: 1.3;
}
.victory-text span { color: #c44d6d; }
.victory-card .chess-btn { margin-top: 1.25rem; }

.firework {
    position: absolute;
    top: 60%;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 1;
    animation: fireworkBurst 1.5s ease-out forwards;
}
@keyframes fireworkBurst {
    0%   { transform: translate(0,0) scale(1); opacity: 1; }
    100% { transform: translate(var(--fx,0), var(--fy,-200px)) scale(0.3); opacity: 0; }
}

/* ===== King in check highlight ===== */
.chess-sq.in-check {
    background: rgba(196, 77, 109, 0.5) !important;
    box-shadow: inset 0 0 0 3px rgba(196, 77, 109, 0.8);
}

/* ===== Move announcement in chat ===== */
.chat-msg.move-msg { opacity: 0.8; }
.chat-msg.move-msg .who { color: #5a4a8a; }
