/* Chess Widget Styling */

/* Remove prose max-width on mobile for better space utilization */
@media (max-width: 768px) {
    .blog-post-content.prose,
    .blog-post-content.prose-lg,
    .blog-post-content.prose-2xl {
        max-width: 100% !important;
    }
}

/* Container for the chess widget with board on left, moves on right */
.chess-widget-container {
    display: flex;
    gap: 2rem;
    margin: 2rem auto 8rem auto;
    padding: 0;
    background-color: transparent;
    border: none !important;
    border-radius: 0;
    box-shadow: none;
    max-width: 100%;
    width: 100%;
}

/* Prevent container collapse and ensure it contains all children */
.chess-widget-container::after {
    content: "";
    display: table;
    clear: both;
}

/* Dark mode support */
.chess-widget-container {
    background-color: transparent;
}

/* Ensure chess-widget-board has no border (keep player names and moves borders) */
.chess-widget-container > .chess-widget-board {
    border: none !important;
    outline: none !important;
}

/* Player names header */
.chess-players {
    text-align: center;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background-color: rgba(31, 41, 55, 0.6);
    border-radius: 0.5rem;
    border: 1px solid rgba(75, 85, 99, 0.5);
}

.chess-players h3 {
    margin: 0.25rem 0;
    font-size: 1rem;
    font-weight: 600;
    color: #f3f4f6;
}

.dark .chess-players h3 {
    color: #f9fafb;
}

/* Board container */
.chess-widget-board {
    flex: 1;
    max-width: 100%;
    overflow: visible;
    border: none;
    padding: 0;
}

/* Override PgnViewerJS inline grid styles */
.chess-widget-board .pgnvjs {
    width: 100% !important;
    max-width: 100% !important;
    grid-template-columns: 500px 1fr !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    background: transparent !important;
}

.chess-widget-board .pgnvjs .moves {
    min-width: 400px !important;
    max-width: 100% !important;
    width: 100% !important;
}

/* Moves and comments panel */
.chess-widget-moves {
    flex: 1;
    overflow: hidden !important;
    max-height: none;
    padding: 1rem;
    background-color: rgba(31, 41, 55, 0.4);
    border-radius: 0.5rem;
    border: 1px solid rgba(75, 85, 99, 0.5);
}

/* PgnViewerJS moves container */
.chess-widget-container .moves {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    max-height: 700px !important;
    padding: 1rem;
    color: #f3f4f6 !important;
    word-wrap: break-word !important;
}

.dark .chess-widget-container .moves {
    color: #f9fafb !important;
}

/* All move text should be light colored */
.chess-widget-container .moves span,
.chess-widget-container .moves a,
.chess-widget-container .moves button {
    color: #e5e7eb !important;
}

.dark .chess-widget-container .moves span,
.dark .chess-widget-container .moves a,
.dark .chess-widget-container .moves button {
    color: #f3f4f6 !important;
}

/* Ensure comments break onto new line */
.moves .comment::before {
    content: "";
    display: block;
    clear: both;
}

.moves .comment::after {
    content: "";
    display: block;
    clear: both;
}

/* PgnViewerJS customizations */
.merida {
    border: 2px solid #d1d5db;
    border-radius: 0.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    width: 500px !important;
    height: 500px !important;
}

.dark .merida {
    border-color: #4b5563;
}

/* Make chess board squares larger */
.merida img {
    width: 100% !important;
    height: 100% !important;
}

/* Style for move buttons */
.moves button {
    padding: 0.375rem 0.625rem;
    margin: 0.125rem;
    border-radius: 0.25rem;
    background-color: rgba(55, 65, 81, 0.4) !important;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    color: #e5e7eb !important;
    font-size: 16px;
    font-weight: 500;
}

.moves button:hover {
    background-color: rgba(55, 65, 81, 0.7) !important;
}

.dark .moves button:hover {
    background-color: rgba(75, 85, 99, 0.7) !important;
}

/* Main line moves - darker background */
.moves > button,
.moves .move {
    background-color: rgba(31, 41, 55, 0.6) !important;
}

.moves > button:hover,
.moves .move:hover {
    background-color: rgba(31, 41, 55, 0.9) !important;
}

/* Highlight variations with grey background (like Lichess) */
.moves .variation,
.moves button.variation {
    background-color: rgba(107, 114, 128, 0.5) !important;
    color: #d1d5db !important;
    font-style: italic;
    font-size: 15px;
    border: 1px solid rgba(156, 163, 175, 0.3) !important;
    padding: 0.375rem 0.625rem;
    margin: 0.25rem;
    border-radius: 0.25rem;
}

.dark .moves .variation,
.dark .moves button.variation {
    background-color: rgba(75, 85, 99, 0.6) !important;
    color: #e5e7eb !important;
    border-color: rgba(107, 114, 128, 0.4) !important;
}

.moves button.variation:hover {
    background-color: rgba(107, 114, 128, 0.7) !important;
}

.dark .moves button.variation:hover {
    background-color: rgba(75, 85, 99, 0.8) !important;
}

/* Variation container */
.moves .variationContainer {
    display: block;
    margin: 0.5rem 0;
    padding: 0.5rem;
    background-color: rgba(107, 114, 128, 0.3) !important;
    border-left: 3px solid rgba(156, 163, 175, 0.5);
    border-radius: 0.25rem;
}

.dark .moves .variationContainer {
    background-color: rgba(75, 85, 99, 0.4) !important;
    border-left-color: rgba(107, 114, 128, 0.6);
}

/* Style for comments */
.moves .comment {
    display: block !important;
    color: #6ee7b7 !important;
    font-style: italic;
    font-size: 15px;
    padding: 0.75rem 1rem;
    margin: 0.5rem 0 0.75rem 0;
    background-color: rgba(6, 78, 59, 0.5);
    border-radius: 0.375rem;
    border-left: 4px solid #10b981;
    line-height: 1.7;
    clear: both;
    width: 100%;
    box-sizing: border-box;
}

.dark .moves .comment {
    color: #86efac !important;
    background-color: rgba(6, 78, 59, 0.4);
    border-left-color: #34d399;
}

/* Current move highlight */
.moves button.active,
.moves button.current {
    background-color: #ef4444 !important;
    color: white !important;
    font-weight: 700;
    font-size: 16px;
    border-color: #dc2626;
}

/* Responsive layout */
@media (max-width: 1280px) {
    .chess-widget-container {
        flex-direction: column;
        max-width: 100% !important;
        width: 100%;
        margin-left: 0;
        margin-right: 0;
    }

    .chess-widget-board {
        margin: 0 auto;
        width: 100%;
    }

    /* Override PgnViewerJS grid to stack vertically on tablet */
    .chess-widget-board .pgnvjs {
        display: flex !important;
        flex-direction: column !important;
        grid-template-columns: none !important;
        gap: 1.5rem !important;
        position: relative !important;
    }

    .chess-widget-board .pgnvjs > * {
        position: relative !important;
    }

    .merida {
        width: 100% !important;
        max-width: 500px;
        height: auto !important;
        aspect-ratio: 1 / 1;
        margin: 0 auto;
    }

    .chess-widget-board .pgnvjs .moves {
        min-width: 100% !important;
        width: 100% !important;
    }

    .chess-widget-moves {
        max-height: none;
        min-width: 100%;
    }

    .chess-widget-container .moves {
        max-height: 600px !important;
    }
}

@media (max-width: 640px) {
    .chess-widget-container {
        padding: 0.5rem;
        gap: 1rem;
        margin: 1.5rem auto 4rem auto;
        min-height: 850px !important;
        overflow: visible !important;
    }

    .chess-widget-container::after {
        content: "";
        display: block;
        clear: both;
        height: 0;
    }

    .chess-widget-board {
        width: 100%;
        max-width: 100%;
        padding: 0;
    }

    /* Ensure vertical stacking on phones */
    .chess-widget-board .pgnvjs {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
        align-items: center !important;
        position: relative !important;
    }

    .chess-widget-board .pgnvjs > * {
        position: relative !important;
    }

    .merida {
        width: 85vw !important;
        max-width: 350px !important;
        height: auto !important;
        aspect-ratio: 1 / 1;
        margin: 0 auto !important;
    }

    .chess-players {
        padding: 0.625rem 0.875rem;
        margin-bottom: 0.75rem;
        max-width: 85vw;
        width: 100%;
        margin-left: auto;
        margin-right: auto;
    }

    .chess-players h3 {
        font-size: 0.9375rem;
    }

    .chess-widget-moves {
        max-height: none;
        min-width: 100%;
        padding: 0.875rem;
    }

    .chess-widget-container .moves {
        min-height: 300px !important;
        max-height: 450px !important;
        height: auto !important;
        padding: 0.875rem;
        font-size: 15px;
        position: relative !important;
        display: block !important;
        width: 100% !important;
    }

    .moves button {
        font-size: 15px;
        padding: 0.3125rem 0.5625rem;
    }

    .moves .comment {
        font-size: 14px;
        padding: 0.625rem 0.875rem;
    }

    .moves .moveNumber {
        font-size: 15px;
    }
}

/* Small phones - optimize for narrow screens */
@media (max-width: 480px) {
    .chess-widget-container {
        padding: 0.25rem;
        gap: 0.875rem;
        margin: 1rem auto 3rem auto;
        min-height: 800px !important;
        overflow: visible !important;
    }

    .chess-widget-container::after {
        content: "";
        display: block;
        clear: both;
        height: 0;
    }

    .chess-widget-board {
        width: 100%;
        max-width: 100%;
        padding: 0;
    }

    /* Ensure vertical stacking with minimal gap */
    .chess-widget-board .pgnvjs {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.875rem !important;
        align-items: center !important;
        position: relative !important;
    }

    .chess-widget-board .pgnvjs > * {
        position: relative !important;
    }

    .merida {
        width: 88vw !important;
        max-width: 320px !important;
        height: auto !important;
        aspect-ratio: 1 / 1;
        border-width: 1px;
        margin: 0 auto !important;
    }

    .chess-players {
        padding: 0.5rem 0.75rem;
        margin-bottom: 0.625rem;
        max-width: 88vw;
        width: 100%;
        margin-left: auto;
        margin-right: auto;
    }

    .chess-players h3 {
        font-size: 0.875rem;
    }

    .chess-widget-moves {
        padding: 0.75rem;
    }

    .chess-widget-container .moves {
        min-height: 280px !important;
        max-height: 400px !important;
        height: auto !important;
        padding: 0.75rem;
        font-size: 14px;
        line-height: 1.6;
        position: relative !important;
        display: block !important;
        width: 100% !important;
    }

    .moves button {
        font-size: 14px;
        padding: 0.25rem 0.5rem;
        margin: 0.0625rem;
    }

    .moves .comment {
        font-size: 13px;
        padding: 0.5rem 0.75rem;
        margin: 0.375rem 0 0.625rem 0;
    }

    .moves .moveNumber {
        font-size: 14px;
    }

    .moves button.active,
    .moves button.current {
        font-size: 14px;
    }

    .moves button.variation {
        font-size: 13px;
        padding: 0.3125rem 0.5rem;
    }
}

/* Force scrolling to work */
.moves {
    font-size: 16px;
    line-height: 1.8;
    display: block !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    max-width: 100% !important;
}

/* Hide all coordinate text elements */
.merida .coordinate {
    display: none !important;
}

.merida text {
    display: none !important;
}

/* Hide SVG text elements that render coordinates */
.merida svg text {
    display: none !important;
}

/* Additional coordinate hiding for different renderers */
.chess-widget-board text,
.chess-widget-board .coordinate,
#chess-widget-board text {
    display: none !important;
    visibility: hidden !important;
}

/* Move numbers styling */
.moves .moveNumber {
    color: #9ca3af !important;
    font-weight: 600;
    font-size: 16px;
    margin-right: 0.375rem;
}

.dark .moves .moveNumber {
    color: #d1d5db !important;
}

/* Control buttons styling */
.chess-widget-controls {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.chess-widget-controls button {
    padding: 0.5rem 1rem;
    background-color: #dc2626;
    color: white;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    font-weight: 500;
    transition: background-color 0.2s;
}

.chess-widget-controls button:hover {
    background-color: #b91c1c;
}

.dark .chess-widget-controls button {
    background-color: #991b1b;
}

.dark .chess-widget-controls button:hover {
    background-color: #7f1d1d;
}

/* Navigation arrows */
.chess-widget-controls button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chess-widget-controls button:disabled:hover {
    background-color: #dc2626;
}

.dark .chess-widget-controls button:disabled:hover {
    background-color: #991b1b;
}
