/**
 * Chess Interactive Board — Frontend Styles.
 *
 * @package Chess_Interactive_Board
 */

/* ------------------------------------------------------------------ */
/*  Wrapper                                                            */
/* ------------------------------------------------------------------ */
.cib-wrapper {
        display: flex;
        flex-wrap: wrap;
        gap: 20px;
        margin: 20px 0;
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, sans-serif;
        font-size: 14px;
        line-height: 1.5;
        color: #333;
        max-width: 100%;
}

/* ------------------------------------------------------------------ */
/*  Board Container                                                    */
/* ------------------------------------------------------------------ */
.cib-board-container {
        flex: 0 0 auto;
        display: flex;
        flex-direction: column;
        gap: 8px;
}

/* ------------------------------------------------------------------ */
/*  Status Bar                                                         */
/* ------------------------------------------------------------------ */
.cib-status {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 6px 12px;
        border-radius: 6px;
        font-weight: 600;
        font-size: 14px;
}

.cib-status-active {
        background: #f0f4f8;
        color: #334155;
}

.cib-status-check {
        background: #fef3c7;
        color: #92400e;
        border: 1px solid #fbbf24;
}

.cib-status-thinking {
        background: #eff6ff;
        color: #1e40af;
        border: 1px solid #93c5fd;
        animation: cib-pulse 1.5s infinite;
}

@keyframes cib-pulse {
        0%, 100% { opacity: 1; }
        50% { opacity: 0.7; }
}

.cib-status-checkmate {
        background: #fee2e2;
        color: #991b1b;
        border: 1px solid #f87171;
}

.cib-status-draw {
        background: #f1f5f9;
        color: #475569;
        border: 1px solid #cbd5e1;
}

/* ------------------------------------------------------------------ */
/*  FEN Bar                                                            */
/* ------------------------------------------------------------------ */
.cib-fen-bar {
        display: flex;
        align-items: center;
        gap: 6px;
        background: #f8fafc;
        border: 1px solid #e2e8f0;
        border-radius: 6px;
        padding: 4px 8px;
        font-size: 12px;
}

.cib-fen-text {
        flex: 1;
        font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        color: #475569;
        user-select: all;
}

/* ------------------------------------------------------------------ */
/*  Buttons                                                            */
/* ------------------------------------------------------------------ */
.cib-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 28px;
        height: 28px;
        border: 1px solid #d1d5db;
        border-radius: 4px;
        background: #fff;
        color: #6b7280;
        cursor: pointer;
        font-size: 16px;
        transition: all 0.15s ease;
        flex-shrink: 0;
        padding: 0;
}

.cib-btn svg {
        width: 16px;
        height: 16px;
        flex-shrink: 0;
        display: block;
}

.cib-btn:hover {
        background: #f3f4f6;
        color: #374151;
        border-color: #9ca3af;
}

.cib-btn:active {
        transform: scale(0.95);
}

.cib-copied {
        color: #16a34a !important;
        border-color: #16a34a !important;
}

.cib-sound-off {
        opacity: 0.5 !important;
}

.cib-sound-toggle {
        font-size: 14px !important;
        line-height: 1 !important;
        padding: 0 !important;
}

/* ------------------------------------------------------------------ */
/*  Moves Panel                                                        */
/* ------------------------------------------------------------------ */
.cib-moves-panel {
        flex: 1 1 200px;
        min-width: 200px;
        max-width: 300px;
        background: #fff;
        border: 1px solid #e2e8f0;
        border-radius: 8px;
        overflow: hidden;
}

.cib-moves-title {
        margin: 0;
        padding: 10px 14px;
        font-size: 14px;
        font-weight: 600;
        border-bottom: 1px solid #e2e8f0;
        background: #f8fafc;
        color: #334155;
}

.cib-moves-list {
        max-height: 350px;
        overflow-y: auto;
        padding: 6px 0;
}

/* Custom scrollbar for moves list. */
.cib-moves-list::-webkit-scrollbar {
        width: 6px;
}
.cib-moves-list::-webkit-scrollbar-track {
        background: transparent;
}
.cib-moves-list::-webkit-scrollbar-thumb {
        background: #cbd5e1;
        border-radius: 3px;
}
.cib-moves-list::-webkit-scrollbar-thumb:hover {
        background: #94a3b8;
}

.cib-no-moves {
        text-align: center;
        color: #94a3b8;
        padding: 20px 10px;
        font-size: 13px;
        margin: 0;
}

/* ------------------------------------------------------------------ */
/*  Moves Table                                                        */
/* ------------------------------------------------------------------ */
.cib-moves-table {
        width: 100%;
        border-collapse: collapse;
        font-size: 13px;
}

.cib-moves-table td {
        padding: 3px 10px;
        vertical-align: middle;
}

.cib-moves-table tr:hover {
        background: #f8fafc;
}

.cib-move-num {
        color: #94a3b8;
        font-family: "SF Mono", "Fira Code", Menlo, monospace;
        font-size: 12px;
        width: 32px;
        text-align: right;
}

.cib-move-white,
.cib-move-black {
        font-weight: 500;
        color: #334155;
        width: 60px;
}

/* ------------------------------------------------------------------ */
/*  Board theme overrides                                              */
/* ------------------------------------------------------------------ */

/* Apply custom theme colors to chessboard.js squares.
   chessboard.js uses .square-55d63 for light and .square-a1 for dark (varies).
   We use CSS custom properties set via JS on the board element. */

.cib-board .white-1e1d7 {
        background-color: var(--cib-light-sq, #f0d9b5) !important;
}
.cib-board .black-3c3d37 {
        background-color: var(--cib-dark-sq, #b58863) !important;
}

/* ------------------------------------------------------------------ */
/*  Responsive adjustments                                             */
/* ------------------------------------------------------------------ */
@media (max-width: 600px) {
        .cib-wrapper {
                flex-direction: column;
        }

        .cib-moves-panel {
                max-width: 100%;
        }

        .cib-board-container {
                width: 100%;
        }

        .cib-board {
                max-width: 100% !important;
        }
}

/* Ensure board doesn't overflow container. */
.cib-board {
        max-width: 100%;
        overflow: hidden;
}

/* ------------------------------------------------------------------ */
/*  Touch handling — prevent browser default touch behaviors on board  */
/*  (scroll, zoom, context menu) so click-to-move works on mobile     */
/* ------------------------------------------------------------------ */
.cib-board[id^="cib-board-"],
.cib-board[id^="cib-board-"] .square-55d63,
.cib-board[id^="cib-board-"] .piece-41731,
.cib-board[id^="cib-board-"] img {
        touch-action: none !important;
        -webkit-touch-callout: none !important;
        -webkit-user-select: none !important;
        user-select: none !important;
}

/* ------------------------------------------------------------------ */
/*  CSS Isolation — prevent theme/plugin conflicts (Tutor LMS, etc.)  */
/*  chessboard.js uses percentage-based widths for its grid.          */
/*  Any inherited padding/margin/box-sizing on squares or rows        */
/*  will break the 8×8 layout, causing the 8th square to wrap.       */
/* ------------------------------------------------------------------ */

/* Board container — force exact dimensions, no inherited interference */
.cib-board[id^="cib-board-"] {
        box-sizing: content-box !important;
        padding: 0 !important;
        margin: 0 !important;
        border: none !important;
        overflow: hidden !important;
        max-width: 100% !important;
        line-height: 0 !important;       /* eliminate inline spacing */
        font-size: 0 !important;         /* eliminate whitespace between inline elements */
        letter-spacing: 0 !important;
        word-spacing: 0 !important;
}

/* chessboard.js inner board wrapper */
.cib-board .board-b72b1d {
        box-sizing: content-box !important;
        padding: 0 !important;
        margin: 0 !important;
        border: none !important;
        width: 100% !important;
        line-height: 0 !important;
        font-size: 0 !important;
        letter-spacing: 0 !important;
        word-spacing: 0 !important;
}

/* Each row must be exactly the board width */
.cib-board .row-5277c {
        box-sizing: content-box !important;
        padding: 0 !important;
        margin: 0 !important;
        border: none !important;
        width: 100% !important;
        clear: both !important;
        display: block !important;
        line-height: 0 !important;
        font-size: 0 !important;
        letter-spacing: 0 !important;
        word-spacing: 0 !important;
        float: none !important;
}

/* Each square — must be exactly 12.5% (100/8) width */
.cib-board .square-55d63 {
        box-sizing: content-box !important;
        padding: 0 !important;
        margin: 0 !important;
        border: none !important;
        width: 12.5% !important;
        display: inline-block !important;
        float: left !important;
        line-height: 0 !important;
        font-size: 0 !important;
        letter-spacing: 0 !important;
        word-spacing: 0 !important;
        vertical-align: top !important;
        position: relative !important;
        overflow: hidden !important;
}

/* Piece images inside squares */
.cib-board .square-55d63 img {
        box-sizing: content-box !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        display: block !important;
        width: 100% !important;
        height: 100% !important;
        max-width: 100% !important;
        max-height: 100% !important;
        object-fit: contain !important;
}

/* Piece container (chessboard.js puts pieces in .piece-41731) */
.cib-board .piece-41731 {
        box-sizing: content-box !important;
        padding: 0 !important;
        margin: 0 !important;
        border: none !important;
        width: 100% !important;
        height: 100% !important;
        position: absolute !important;
        pointer-events: none !important;
        z-index: 1 !important;
        line-height: 0 !important;
        font-size: 0 !important;
}

.cib-board .piece-41731 img {
        box-sizing: content-box !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        display: block !important;
        width: 100% !important;
        height: 100% !important;
        max-width: 100% !important;
        max-height: 100% !important;
}

/* Spare pieces containers (top/bottom) */
.cib-board .spare-pieces-44920 {
        box-sizing: content-box !important;
        padding: 0 !important;
        margin: 0 !important;
        border: none !important;
        width: 100% !important;
        line-height: 0 !important;
        font-size: 0 !important;
        letter-spacing: 0 !important;
        word-spacing: 0 !important;
}

/* Dragging piece */
.cib-board .dragging-5ad85 {
        z-index: 100 !important;
        position: absolute !important;
}

/* Highlight squares */
.cib-board .highlight-white,
.cib-board .highlight-black {
        box-shadow: inset 0 0 3px 3px rgba(255, 255, 0, 0.5) !important;
}

/* ------------------------------------------------------------------ */
/*  Nuclear option: override ALL possible Tutor LMS / theme conflicts */
/*  by scoping everything under .cib-wrapper with !important          */
/* ------------------------------------------------------------------ */
.cib-wrapper *,
.cib-wrapper *::before,
.cib-wrapper *::after {
        box-sizing: content-box !important;
}

/* Re-enable border-box for our own UI elements (not the board) */
.cib-board-container *,
.cib-board-container *::before,
.cib-board-container *::after,
.cib-moves-panel *,
.cib-moves-panel *::before,
.cib-moves-panel *::after {
        box-sizing: border-box !important;
}

/* But keep content-box for the board grid itself */
.cib-board[id^="cib-board-"],
.cib-board[id^="cib-board-"] *,
.cib-board[id^="cib-board-"] *::before,
.cib-board[id^="cib-board-"] *::after {
        box-sizing: content-box !important;
}

/* Re-apply border-box for piece images inside board */
.cib-board[id^="cib-board-"] img,
.cib-board[id^="cib-board-"] .piece-41731 img {
        box-sizing: content-box !important;
}

/* ------------------------------------------------------------------ */
/*  Highlight last-move squares (future enhancement placeholder)       */
/* ------------------------------------------------------------------ */
.cib-highlight-white {
        box-shadow: inset 0 0 3px 3px rgba(255, 255, 0, 0.5);
}
.cib-highlight-black {
        box-shadow: inset 0 0 3px 3px rgba(255, 255, 0, 0.5);
}

/* ------------------------------------------------------------------ */
/*  Click-to-move — selected piece & legal move indicators            */
/* ------------------------------------------------------------------ */

/* Selected piece square */
.cib-board .square-55d63.cib-selected {
        box-shadow: inset 0 0 0 4px rgba(255, 200, 0, 0.85) !important;
        background-color: rgba(255, 255, 0, 0.35) !important;
}

/* Legal move target — small dot */
.cib-board .square-55d63.cib-legal-move::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        width: 28%;
        height: 28%;
        transform: translate(-50%, -50%);
        border-radius: 50%;
        background: rgba(0, 0, 0, 0.18);
        pointer-events: none;
        z-index: 5;
}

/* Legal capture target — ring */
.cib-board .square-55d63.cib-legal-capture::after {
        content: '';
        position: absolute;
        top: 0; left: 0; right: 0; bottom: 0;
        border-radius: 50%;
        border: 5px solid rgba(0, 0, 0, 0.18);
        pointer-events: none;
        z-index: 5;
}

/* Ensure squares are positioned for ::after pseudo-elements */
.cib-board .square-55d63 {
        position: relative !important;
}

/* ------------------------------------------------------------------ */
/*  Board coordinate labels (notation)                                */
/*  chessboard.js uses .notation-322f9, .alpha-d2270, .numeric-fc462 */
/*  Our font-size:0 and overflow:hidden on squares clip them.         */
/*  Override to restore readable coordinates.                         */
/* ------------------------------------------------------------------ */
.cib-board .square-55d63 .notation-322f9 {
        font-size: 10px !important;
        line-height: 1 !important;
        pointer-events: none !important;
        z-index: 3 !important;
}
.cib-board .square-55d63 .alpha-d2270 {
        bottom: 1px !important;
        right: 2px !important;
}
.cib-board .square-55d63 .numeric-fc462 {
        top: 1px !important;
        left: 2px !important;
}
/* Light square notation = dark color, dark square notation = light color */
.cib-board .white-1e1d7 .notation-322f9 {
        color: var(--cib-dark-sq, #b58863) !important;
}
.cib-board .black-3c3d37 .notation-322f9,
.cib-board .black-3c85d .notation-322f9 {
        color: var(--cib-light-sq, #f0d9b5) !important;
}

/* ------------------------------------------------------------------ */
/*  Flip board button                                                 */
/* ------------------------------------------------------------------ */
.cib-flip {
        font-size: 16px !important;
        line-height: 1 !important;
}

/* ------------------------------------------------------------------ */
/*  Ghost/drag piece — make it transparent to mouse events            */
/*  chessboard.js creates a ghost <img> as direct child of <body>    */
/*  during drag. It intercepts mouseup/click events, preventing      */
/*  click-to-move from working. Setting pointer-events: none allows   */
/*  events to pass through to the board squares underneath.           */
/*  The drag still works because mousemove is tracked on window.      */
/* ------------------------------------------------------------------ */
body > img.piece-417db {
        pointer-events: none !important;
}

/* ------------------------------------------------------------------ */
/*  Hint button                                                       */
/* ------------------------------------------------------------------ */
.cib-hint {
        font-size: 15px !important;
        line-height: 1 !important;
        padding: 0 !important;
}

/* Hint highlight — from square (green) */
.cib-board .square-55d63.cib-hint-from {
        box-shadow: inset 0 0 0 4px rgba(34, 197, 94, 0.8) !important;
        background-color: rgba(34, 197, 94, 0.3) !important;
}

/* Hint highlight — to square (green with arrow indicator) */
.cib-board .square-55d63.cib-hint-to::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        width: 36%;
        height: 36%;
        transform: translate(-50%, -50%);
        border-radius: 50%;
        background: rgba(34, 197, 94, 0.5);
        pointer-events: none;
        z-index: 5;
}

/* Hint text tooltip */
.cib-hint-text {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        background: rgba(0, 0, 0, 0.8);
        color: #fff;
        padding: 6px 14px;
        border-radius: 6px;
        font-size: 14px;
        font-weight: 600;
        z-index: 200;
        white-space: nowrap;
        pointer-events: none;
        animation: cib-hint-fade 3s ease-out forwards;
}

@keyframes cib-hint-fade {
        0% { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
        10% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
        80% { opacity: 1; }
        100% { opacity: 0; }
}

/* ------------------------------------------------------------------ */
/*  Lichess Analysis Button                                            */
/* ------------------------------------------------------------------ */
.cib-lichess-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 8px 16px;
        border: 1px solid #d1d5db;
        border-radius: 6px;
        background: #fff;
        color: #475569;
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, sans-serif;
        font-size: 13px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s ease;
        white-space: nowrap;
        width: 100%;
}

.cib-lichess-btn:hover {
        background: #f0fdf4;
        color: #15803d;
        border-color: #86efac;
}

.cib-lichess-btn:active {
        transform: scale(0.98);
}

.cib-lichess-btn:focus {
        outline: 2px solid #86efac;
        outline-offset: 2px;
}

.cib-lichess-icon {
        flex-shrink: 0;
        color: #15803d;
}

.cib-lichess-btn:hover .cib-lichess-icon {
        color: #166534;
}

/* ------------------------------------------------------------------ */
/*  Lichess Analysis Modal                                             */
/* ------------------------------------------------------------------ */
.cib-lichess-modal {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 99999;
        display: none;
        align-items: center;
        justify-content: center;
}

.cib-lichess-modal-backdrop {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.6);
}

.cib-lichess-modal-content {
        position: relative;
        z-index: 1;
        background: #fff;
        border-radius: 12px;
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
        overflow: hidden;
        width: 90vw;
        max-width: 520px;
        display: flex;
        flex-direction: column;
}

.cib-lichess-modal-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 12px 16px;
        background: #f8fafc;
        border-bottom: 1px solid #e2e8f0;
        flex-shrink: 0;
}

.cib-lichess-modal-title {
        font-weight: 600;
        font-size: 15px;
        color: #334155;
}

.cib-lichess-modal-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 30px;
        height: 30px;
        border: none;
        border-radius: 6px;
        background: transparent;
        color: #64748b;
        font-size: 18px;
        cursor: pointer;
        transition: all 0.15s ease;
}

.cib-lichess-modal-close:hover {
        background: #fee2e2;
        color: #991b1b;
}

.cib-lichess-modal-body {
        flex: 1;
        position: relative;
        overflow: hidden;
}

.cib-lichess-modal-info {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 30px 24px;
        gap: 16px;
        text-align: center;
}

.cib-lichess-modal-icon {
        color: #15803d;
        margin-bottom: 4px;
}

.cib-lichess-modal-desc {
        margin: 0;
        font-size: 15px;
        color: #475569;
        line-height: 1.5;
}

.cib-lichess-modal-fen-wrap {
        display: flex;
        align-items: center;
        gap: 8px;
        background: #f8fafc;
        border: 1px solid #e2e8f0;
        border-radius: 6px;
        padding: 8px 14px;
        width: 100%;
        max-width: 440px;
}

.cib-lichess-modal-fen-label {
        font-size: 12px;
        font-weight: 600;
        color: #94a3b8;
        flex-shrink: 0;
}

.cib-lichess-modal-fen {
        font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
        font-size: 12px;
        color: #334155;
        word-break: break-all;
        text-align: left;
        line-height: 1.4;
}

.cib-lichess-modal-link {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 12px 28px;
        border: none;
        border-radius: 8px;
        background: #15803d;
        color: #fff;
        font-size: 15px;
        font-weight: 600;
        text-decoration: none;
        cursor: pointer;
        transition: all 0.2s ease;
        margin-top: 4px;
}

.cib-lichess-modal-link:hover {
        background: #166534;
        color: #fff;
        text-decoration: none;
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(21, 128, 61, 0.3);
}

.cib-lichess-modal-link:active {
        transform: translateY(0);
}

@media (max-width: 600px) {
        .cib-lichess-modal-content {
                width: 95vw;
                max-width: none;
                border-radius: 8px;
        }
        .cib-lichess-modal-info {
                padding: 20px 16px;
        }
}

/* ------------------------------------------------------------------ */
/*  Promotion dialog                                                  */
/* ------------------------------------------------------------------ */
.cib-promotion-overlay {
        position: absolute;
        top: 0; left: 0; right: 0; bottom: 0;
        z-index: 100;
        cursor: pointer;
}
.cib-promotion-dialog {
        position: absolute;
        z-index: 101;
        background: #fff;
        border: 2px solid #333;
        border-radius: 4px;
        box-shadow: 0 4px 20px rgba(0,0,0,0.3);
        overflow: hidden;
}
.cib-promotion-piece {
        display: block;
        width: 100%;
        padding: 4px;
        cursor: pointer;
        border: none;
        background: transparent;
        transition: background 0.15s;
}
.cib-promotion-piece:hover {
        background: #aaddaa;
}
.cib-promotion-piece img {
        width: 100%;
        height: auto;
        display: block;
}
