/**
 * @file mchess-board-theme.css
 * @description Centralized Board Themes & Customization Engine for MCHESS.
 * Defines CSS custom properties for multiple visual themes (Classic Slate, Lichess Wood, ChessBase Blue, Emerald Tournament, Midnight Sapphire)
 * and styles the interactive, responsive board theme picker modal.
 * @project MCHESS Interactive Chess Portal
 */

/* ==========================================================================
   1. Theme Color Tokens (CSS Custom Properties)
   ========================================================================== */

/* Default Theme: Classic MChess Slate */
:root,
html,
html[data-board-theme="mchess-slate"] {
    --mchess-sq-light: #e6e6e6;
    --mchess-sq-dark: #616261;
    --mchess-sq-light-text: #1e293b;
    --mchess-sq-dark-text: #f8fafc;
    --mchess-sq-highlight: rgba(56, 189, 248, 0.45);
    --mchess-board-border: #475569;
    --mchess-theme-accent: #38bdf8;
    --mchess-theme-name: "Classic Slate";
}

/* Lichess Classic Wood Theme */
html[data-board-theme="lichess-wood"] {
    --mchess-sq-light: #f0d9b5;
    --mchess-sq-dark: #b58863;
    --mchess-sq-light-text: #4a2e18;
    --mchess-sq-dark-text: #fff3e6;
    --mchess-sq-highlight: rgba(34, 197, 94, 0.45);
    --mchess-board-border: #8b5a2b;
    --mchess-theme-accent: #b58863;
    --mchess-theme-name: "Lichess Wood";
}

/* ChessBase / Fritz Classic Blue Theme */
html[data-board-theme="chessbase-blue"] {
    --mchess-sq-light: #dee3e6;
    --mchess-sq-dark: #4e7c99;
    --mchess-sq-light-text: #0f2738;
    --mchess-sq-dark-text: #f0f9ff;
    --mchess-sq-highlight: rgba(245, 158, 11, 0.45);
    --mchess-board-border: #33536b;
    --mchess-theme-accent: #4e7c99;
    --mchess-theme-name: "ChessBase Blue";
}

/* Emerald Tournament (Chess.com Green) Theme */
html[data-board-theme="tournament-green"] {
    --mchess-sq-light: #eeeed2;
    --mchess-sq-dark: #769656;
    --mchess-sq-light-text: #263816;
    --mchess-sq-dark-text: #f7fee7;
    --mchess-sq-highlight: rgba(250, 204, 21, 0.5);
    --mchess-board-border: #4a6333;
    --mchess-theme-accent: #769656;
    --mchess-theme-name: "Tournament Green";
}

/* Midnight Sapphire / Ocean Dark Theme */
html[data-board-theme="midnight-dark"] {
    --mchess-sq-light: #cbd5e1;
    --mchess-sq-dark: #1e3a8a;
    --mchess-sq-light-text: #091e42;
    --mchess-sq-dark-text: #eff6ff;
    --mchess-sq-highlight: rgba(56, 189, 248, 0.5);
    --mchess-board-border: #0f172a;
    --mchess-theme-accent: #3b82f6;
    --mchess-theme-name: "Midnight Sapphire";
}

/* ==========================================================================
   2. Board Square Color Overrides
   ========================================================================== */

.board-container .white-1e1d7,
.board-b72b1 .white-1e1d7,
.white-1e1d7,
[class*="white-"] {
    background-color: var(--mchess-sq-light, #e6e6e6) !important;
    color: var(--mchess-sq-light-text, #1e293b) !important;
    transition: background-color 0.25s ease, color 0.25s ease;
}

.board-container .black-3c85d,
.board-b72b1 .black-3c85d,
.black-3c85d,
[class*="black-"] {
    background-color: var(--mchess-sq-dark, #616261) !important;
    color: var(--mchess-sq-dark-text, #f8fafc) !important;
    transition: background-color 0.25s ease, color 0.25s ease;
}

.board-wrapper {
    border-color: var(--mchess-board-border, #475569) !important;
    transition: border-color 0.25s ease;
}

/* Active Highlight Overrides */
.square-selected {
    background-color: var(--mchess-sq-highlight, rgba(56, 189, 248, 0.45)) !important;
}

/* ==========================================================================
   3. Theme Trigger Button Styling
   ========================================================================== */

.btn-board-theme {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(168, 85, 247, 0.15)) !important;
    color: #a855f7 !important;
    border: 1px solid rgba(168, 85, 247, 0.4) !important;
    cursor: pointer !important;
    font-weight: 600 !important;
    border-radius: 6px !important;
    transition: all 0.2s ease !important;
    min-height: 38px !important;
    padding: 6px 12px !important;
    user-select: none !important;
    touch-action: manipulation !important;
}

.btn-board-theme:hover,
.btn-board-theme:focus-visible {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.3), rgba(168, 85, 247, 0.3)) !important;
    color: #c084fc !important;
    border-color: #c084fc !important;
    box-shadow: 0 0 12px rgba(168, 85, 247, 0.35) !important;
    transform: translateY(-1px) !important;
}

.btn-board-theme:active {
    transform: translateY(0) !important;
}

/* Dark mode theme button adjustments */
[data-theme="dark"] .btn-board-theme {
    color: #d8b4fe !important;
    border-color: rgba(192, 132, 252, 0.4) !important;
}

/* ==========================================================================
   4. Interactive Board Theme Picker Modal
   ========================================================================== */

.mchess-theme-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999999;
    padding: 16px;
    box-sizing: border-box;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.mchess-theme-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.mchess-theme-modal-card {
    background: #1e293b;
    color: #f8fafc;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px;
    width: 100%;
    max-width: 580px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.5), 0 0 25px rgba(56, 189, 248, 0.15);
    padding: 24px;
    box-sizing: border-box;
    transform: scale(0.95) translateY(10px);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.mchess-theme-modal-overlay.active .mchess-theme-modal-card {
    transform: scale(1) translateY(0);
}

/* Modal Header */
.mchess-theme-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.mchess-theme-modal-title {
    font-size: 18px;
    font-weight: 700;
    color: #f8fafc;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
}

.mchess-theme-modal-close {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #94a3b8;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 16px;
    touch-action: manipulation;
}

.mchess-theme-modal-close:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.4);
}

/* Theme Option Cards Grid */
.mchess-theme-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.mchess-theme-card {
    background: #0f172a;
    border: 2px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    position: relative;
    user-select: none;
    touch-action: manipulation;
}

.mchess-theme-card:hover {
    border-color: rgba(56, 189, 248, 0.5);
    background: #172554;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.mchess-theme-card.active {
    border-color: #38bdf8;
    background: #1e3a8a;
    box-shadow: 0 0 16px rgba(56, 189, 248, 0.4);
}

/* 4-Square Mini Board Preview */
.mchess-theme-preview-board {
    width: 64px;
    height: 64px;
    margin: 0 auto 10px auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    border: 1.5px solid rgba(255, 255, 255, 0.15);
}

.mchess-theme-preview-sq {
    width: 100%;
    height: 100%;
}

.mchess-theme-card-name {
    font-size: 13.5px;
    font-weight: 600;
    color: #f8fafc;
    margin-bottom: 4px;
}

.mchess-theme-card-desc {
    font-size: 11px;
    color: #94a3b8;
}

.mchess-theme-check-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 20px;
    height: 20px;
    background: #38bdf8;
    color: #0f172a;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
}

.mchess-theme-card.active .mchess-theme-check-badge {
    display: flex;
}

/* Modal Footer */
.mchess-theme-modal-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.mchess-theme-modal-hint {
    font-size: 12px;
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: 6px;
}

.mchess-theme-modal-btn-done {
    background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
    color: #ffffff;
    border: none;
    padding: 8px 20px;
    border-radius: 8px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
    min-height: 40px;
}

.mchess-theme-modal-btn-done:hover {
    background: linear-gradient(135deg, #0369a1 0%, #075985 100%);
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.4);
}

/* ==========================================================================
   5. Mobile Responsiveness
   ========================================================================== */

@media (max-width: 600px) {
    .mchess-theme-modal-card {
        padding: 16px 12px !important;
        border-radius: 12px !important;
    }

    .mchess-theme-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

    .mchess-theme-preview-board {
        width: 52px !important;
        height: 52px !important;
    }

    .mchess-theme-card-name {
        font-size: 12.5px !important;
    }

    .mchess-theme-card-desc {
        font-size: 10.5px !important;
    }

    .btn-board-theme {
        min-height: 40px !important;
        font-size: 12.5px !important;
        padding: 6px 10px !important;
        flex: 1 1 auto !important;
    }
}
