/**
 * Chess Diagram Styles
 *
 * @package     com_chessdiagram
 * @copyright   (C) 2026 WarumSchach
 */

/* Force text rendering for chess Unicode characters */
/* Prevents Chrome from rendering black pawn as colored emoji */
.chess-square {
    font-variant-emoji: text;
    text-rendering: geometricPrecision;
}

/* Board Container — !important prevents template theme leaks (e.g. Educon II) */
.chess-diagram-container {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 14px !important;
    line-height: 1.5 !important;
    margin: 20px auto;
    box-sizing: border-box;
}

.chess-diagram-container *,
.chess-diagram-container *::before,
.chess-diagram-container *::after {
    box-sizing: border-box;
}

.chess-diagram-title {
    text-align: center;
    font-size: 1.15em !important;
    font-weight: 700;
    margin-bottom: 10px;
    color: #222;
}

.chess-diagram-wrapper {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    justify-content: center;
}

.chess-board {
    border: none;
    overflow: visible !important;
}

.chess-board-inner {
    border: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    overflow: visible !important;
}

/* Move List */
.chess-moves {
    font-size: 13px !important;
    line-height: 1.6 !important;
    padding: 10px;
    background: #fafafa;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow-x: hidden;
    overflow-y: auto;
    min-width: 200px;
}

.chess-moves .move-number {
    font-weight: bold;
    color: #666;
}

.chess-moves .move {
    cursor: pointer;
    padding: 1px 4px;
    border-radius: 3px;
}

.chess-moves .move:hover {
    background: #e0e0e0;
}

.chess-moves .move.active {
    background: #4a90d9;
    color: white;
}

/* Puzzle Move List — !important to resist template theme overrides */
.chess-puzzle-moves {
    font-size: 14px !important;
    line-height: 1.5 !important;
    padding: 10px;
    background: #fafafa;
    border: 1px solid #ddd;
    border-radius: 4px;
    flex: 0 0 180px;
    overflow-x: hidden;
    overflow-y: auto;
}

.chess-puzzle-moves-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px !important;
}

.chess-puzzle-moves-table td {
    padding: 3px 6px;
    vertical-align: top;
    font-size: 14px !important;
    line-height: 1.5 !important;
    border: none;
    background: transparent;
}

.chess-puzzle-moves-table .puzzle-move-num {
    font-weight: bold;
    color: #888;
    width: 35px;
    text-align: right;
    padding-right: 8px;
}

.chess-puzzle-moves-table .puzzle-move-san {
    min-width: 55px;
}

.chess-puzzle-moves-table tr:last-child .puzzle-move-san:last-child {
    font-weight: bold;
    color: #2c7a2c;
}

.chess-puzzle-variation-label {
    font-size: 11px;
    font-weight: bold;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 4px 0 2px;
    border-bottom: 1px solid #e0e0e0;
    margin-bottom: 2px;
}

.chess-puzzle-variation-label:not(:first-child) {
    margin-top: 8px;
}

.chess-puzzle-current-label {
    color: #2b2467;
}

.chess-puzzle-completed {
    opacity: 0.55;
}

.chess-puzzle-completed .puzzle-move-san {
    font-weight: normal !important;
    color: #888 !important;
}

/* Controls */
.chess-controls {
    margin-top: 8px;
    text-align: center;
}

.chess-controls .btn {
    margin: 0 2px;
    min-width: 36px;
    font-size: 14px !important;
    padding: 4px 8px !important;
    border-radius: 4px;
    line-height: 1.5 !important;
}

/* Description */
.chess-diagram-description {
    text-align: center;
    font-style: italic;
    color: #555;
    margin-top: 8px;
    font-size: inherit !important;
}

/* Editor Specific Styles */
.piece-selector {
    display: inline-block;
    margin: 5px;
}

.piece-btn {
    display: inline-block;
    width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
    font-size: 28px;
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 4px;
    transition: all 0.15s;
    user-select: none;
    font-variant-emoji: text;
    text-rendering: geometricPrecision;
}

.piece-btn:hover {
    background: #e8e8e8;
    border-color: #999;
}

.piece-btn.active {
    background: #4a90d9;
    border-color: #2a70b9;
    color: white;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

/* Mini Preview in List */
.chess-mini-preview {
    display: inline-block;
    border: 1px solid #ccc;
}

/* Move Table */
.chess-moves-table tr:hover {
    background: #f0f0f0;
}

.chess-moves-table td {
    padding: 2px 4px;
    font-size: 13px !important;
    border: none;
    background: transparent;
}

/* Gallery Card */
.chess-diagram-card {
    transition: box-shadow 0.2s ease;
}

.chess-diagram-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.15) !important;
}

/* Focus outline for keyboard navigation */
.chess-diagram-container:focus {
    outline: 2px solid #4a90d9;
    outline-offset: 2px;
}

.chess-diagram-container:focus:not(:focus-visible) {
    outline: none;
}

/* Category Filter */
.chess-category-filter {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.chess-cat-filter.active {
    background: #2b2467;
    border-color: #2b2467;
    color: #fff;
}

/* Dashboard */
.dashboard-header {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-bottom: 3px solid #e8881c;
    border-radius: 8px 8px 0 0;
}

.dashboard-logo {
    height: 70px;
    flex-shrink: 0;
}

.dashboard-title {
    color: #2b2467;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.dashboard-card {
    border: 1px solid #dee2e6;
    border-radius: 8px;
    transition: all 0.2s ease;
    cursor: pointer;
}

.dashboard-card:hover {
    border-color: #e8881c;
    box-shadow: 0 4px 16px rgba(232,136,28,0.15);
    transform: translateY(-2px);
}

.dashboard-card .card-title {
    font-weight: 600;
}

.dashboard-card-icon {
    width: 60px;
    height: 60px;
    line-height: 60px;
    margin: 0 auto;
    background: #f0eef5;
    border-radius: 50%;
}

/* ============================================
   Game Mode (Partie-Modus) Styles
   ============================================ */

.chess-game-notation {
    line-height: 1.9;
    padding: 10px;
    font-size: 14px !important;
}

.game-move {
    cursor: pointer;
    padding: 1px 3px;
    border-radius: 3px;
    font-weight: 600;
    white-space: nowrap;
}

.game-move:hover {
    background: #e0e0e0;
}

.game-move.active {
    background: #4a90d9;
    color: white;
}

.game-move-number {
    color: #888;
    font-weight: bold;
    font-size: 0.9em;
}

.game-nag {
    color: #c0392b;
    font-weight: bold;
    font-size: 0.95em;
    margin-left: 1px;
}

.game-comment {
    color: #2980b9;
    font-style: italic;
    font-size: 0.9em;
}

.game-variation {
    display: inline;
    font-size: 13px;
}

.game-variation-bracket {
    color: #999;
    font-weight: bold;
}

.game-variation-depth-1 {
    color: #555;
}

.game-variation-depth-2 {
    color: #777;
    font-size: 12px;
}

.game-variation-depth-3 {
    color: #999;
    font-size: 11px;
}

.game-result {
    font-weight: bold;
    color: #333;
    margin-left: 4px;
}

/* Puzzle Mode Styles */
.chess-puzzle-status {
    font-size: 14px !important;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 4px;
    min-height: 24px;
}

.chess-puzzle-wrong {
    color: #856404;
    background: #fff3cd;
    border: 1px solid #ffc107;
}

.chess-puzzle-solved {
    color: #155724;
    background: #d4edda;
    border: 1px solid #28a745;
}

.chess-puzzle-correct {
    color: #0c5460;
    background: #d1ecf1;
    border: 1px solid #17a2b8;
}

.chess-promotion-chooser button:hover {
    background: #e8e8e8 !important;
    border-color: #4a90d9 !important;
}

/* Responsive */
@media (max-width: 768px) {
    .chess-diagram-container {
        max-width: 100% !important;
        overflow-x: auto;
        overflow-y: visible;
        box-sizing: border-box;
        padding: 0 4px;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .chess-diagram-wrapper {
        flex-direction: column;
        align-items: center;
    }

    .chess-board {
        max-width: 100%;
    }

    .chess-moves,
    .chess-puzzle-moves {
        width: 100%;
        max-width: 100%;
        flex: 0 0 100%;
        max-height: 200px !important;
        box-sizing: border-box;
    }

    .chess-game-notation {
        font-size: 12px;
        line-height: 1.7;
        padding: 6px;
    }

    .chess-controls .btn {
        min-width: 32px;
        padding: 4px 6px;
        font-size: 13px;
        margin: 2px 1px;
    }

    .chess-diagram-title {
        font-size: 1em;
    }

    .chess-diagram-gallery {
        grid-template-columns: 1fr !important;
    }

    /* Tables containing chess diagrams: stack to 1 column on mobile */
    table:has(.chess-diagram-container),
    table:has(.chess-diagram-container) tbody,
    table.chess-responsive-table,
    table.chess-responsive-table tbody {
        display: block !important;
        width: 100% !important;
    }

    table:has(.chess-diagram-container) tr,
    table.chess-responsive-table tr {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
    }

    table:has(.chess-diagram-container) td,
    table:has(.chess-diagram-container) th,
    table.chess-responsive-table td,
    table.chess-responsive-table th {
        display: block !important;
        width: 100% !important;
        box-sizing: border-box;
    }

    /* CSS Grid layouts containing chess diagrams */
    .chess-diagram-grid {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 400px) {
    .chess-diagram-container {
        padding: 0 2px;
    }

    .chess-controls .btn {
        min-width: 28px;
        padding: 3px 4px;
        font-size: 12px;
    }

    .chess-diagram-description {
        font-size: 12px;
    }
}

/* ============================================
   Chess List Grid ([chess-list] shortcode)
   ============================================ */

.chess-list-grid {
    display: grid;
    grid-template-columns: repeat(var(--chess-list-cols, 3), 1fr);
    gap: 16px;
    padding: 10px 0;
}

.chess-list-card {
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    transition: box-shadow 0.2s, transform 0.2s;
    background: #fff;
}

.chess-list-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.chess-list-card a {
    text-decoration: none;
    color: inherit;
    display: block;
}

.chess-list-card .chess-diagram-container {
    margin: 0 !important;
    padding: 8px;
}

.chess-list-card-title {
    padding: 8px 12px;
    font-weight: 600;
    font-size: 0.9em;
    text-align: center;
    border-top: 1px solid #eee;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chess-list-empty {
    color: #888;
    font-style: italic;
    padding: 20px;
    text-align: center;
}

@media (max-width: 768px) {
    .chess-list-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

@media (max-width: 500px) {
    .chess-list-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ============================================
   Gamification: Progress, Leaderboard, Badges
   ============================================ */

.chess-progress-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.chess-stat-card {
    text-align: center;
    padding: 16px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.chess-stat-value {
    font-size: 2em;
    font-weight: bold;
    color: #2c3e50;
    line-height: 1.2;
}

.chess-stat-label {
    font-size: 0.85em;
    color: #7f8c8d;
    margin-top: 4px;
}

.chess-leaderboard {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
}

.chess-leaderboard th {
    background: #34495e;
    color: white;
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
}

.chess-leaderboard td {
    padding: 8px 12px;
    border-bottom: 1px solid #eee;
}

.chess-leaderboard tr:hover td {
    background: #f8f9fa;
}

.chess-leaderboard .rank-1 { color: #f1c40f; font-weight: bold; }
.chess-leaderboard .rank-2 { color: #95a5a6; font-weight: bold; }
.chess-leaderboard .rank-3 { color: #e67e22; font-weight: bold; }

.chess-leaderboard .current-user td {
    background: #eaf2fd;
    font-weight: 600;
}

.chess-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8em;
    margin: 2px;
}

.chess-badge-earned {
    background: #27ae60;
    color: white;
}

.chess-badge-locked {
    background: #ecf0f1;
    color: #bdc3c7;
}

.chess-badge-icon {
    font-size: 1.1em;
}

.chess-streak-counter {
    font-size: 1.2em;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.chess-streak-flame {
    color: #e74c3c;
}

.chess-heatmap {
    display: grid;
    grid-template-columns: repeat(52, 1fr);
    gap: 2px;
    margin: 10px 0;
}

.chess-heatmap-day {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    background: #ebedf0;
}

.chess-heatmap-day.level-1 { background: #9be9a8; }
.chess-heatmap-day.level-2 { background: #40c463; }
.chess-heatmap-day.level-3 { background: #30a14e; }
.chess-heatmap-day.level-4 { background: #216e39; }

.chess-puzzle-result {
    text-align: center;
    padding: 12px;
    margin-top: 8px;
    border-radius: 8px;
    animation: fadeInUp 0.3s ease;
}

.chess-puzzle-result-solved {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.chess-puzzle-result-failed {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.chess-badge-notification {
    display: inline-block;
    animation: badgePop 0.5s ease;
    font-size: 1.1em;
    margin-top: 6px;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes badgePop {
    0% { transform: scale(0); }
    60% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

@media (max-width: 768px) {
    .chess-progress-stats {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 500px) {
    .chess-progress-stats {
        grid-template-columns: 1fr;
    }
}
