body .nl-container,
body .nl-container * {
    box-sizing: border-box !important;
}

.nl-container {
    display: flex;
    flex-wrap: nowrap !important;
    align-items: flex-start;
    gap: 20px;
    width: 100%;
    max-width: 100%;
    margin: 20px auto;
    background: #1e1e1e;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: #fff;
}

.nl-board-wrap {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
}

.cg-wrap {
    width: 100%;
    max-width: 100%;
    max-width: min(100%, 55vh, 600px);
    margin: 0 auto;
    position: relative;
    aspect-ratio: 1/1;
    /* Allow spare pieces to show outside the board. */
    border-radius: 4px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    background: transparent;
}

.nl-spare-pieces.cg-wrap {
    display: flex !important;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin: 15px 0 !important;
    user-select: none;
    width: 100% !important;
    max-width: none !important;
    aspect-ratio: auto !important;
    box-shadow: none !important;
    background: none !important;
    height: auto !important;
    min-height: 45px;
}

.nl-spare-pieces piece {
    position: relative !important;
    width: 45px !important;
    height: 45px !important;
    cursor: grab !important;
    display: inline-block !important;
    background-size: cover !important;
    pointer-events: auto !important;
    visibility: visible !important;
    opacity: 1 !important;
    transform: none !important;
    top: auto !important;
    left: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    transition: transform 0.1s ease;
}

/* Black pieces are hard to see on a dark #1e1e1e background, add a glow */
.nl-spare-pieces piece.black {
    filter: drop-shadow(0px 0px 3px rgba(255, 255, 255, 0.4));
}

.nl-spare-pieces piece.selected {
    transform: scale(1.15) !important;
    filter: drop-shadow(0 0 8px rgba(255, 215, 0, 0.8));
    z-index: 10;
}

.nl-eraser {
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    transition: all 0.2s;
    pointer-events: auto !important;
}

.nl-eraser.selected {
    background: rgba(255, 99, 71, 0.4);
    transform: scale(1.15) !important;
    filter: drop-shadow(0 0 8px rgba(255, 99, 71, 0.8));
    border: 1px solid #ff6b6b;
    z-index: 10;
}

.nl-eraser:hover {
    background: rgba(255, 255, 255, 0.2);
}

.cg-wrap.editor-board {
    margin-top: 10px !important;
    margin-bottom: 10px !important;
}

@supports (aspect-ratio: 1/1) {
    .cg-wrap {
        height: auto;
    }

    .nl-spare-pieces.cg-wrap {
        height: 45px;
    }
}

.nl-sidebar {
    flex: 0 0 300px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: 100%;
}

.nl-title {
    font-size: 16px;
    font-weight: 700;
    margin: 0;
    color: #d1d5db;
}

body .nl-container .nl-controls {
    display: block !important;
    white-space: nowrap !important;
    font-size: 0 !important;
    text-align: center !important;
    width: 100% !important;
    max-width: min(100%, 55vh, 600px) !important;
    margin: 10px auto 0 auto !important;
    clear: both !important;
}

body .nl-container .nl-controls span.nl-btn-ctrl {
    background: #4b5563 !important;
    color: #fff !important;
    border: none !important;
    padding: 8px 0 !important;
    margin: 0 1% !important;
    border-radius: 6px !important;
    cursor: pointer !important;
    font-size: 18px !important;
    line-height: 1.2 !important;
    font-weight: 600 !important;
    width: 18% !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-sizing: border-box !important;
    transition: all 0.2s;
    clear: none !important;
    float: none !important;
    vertical-align: top !important;
}

body .nl-container .nl-controls span.nl-btn-ctrl.tact-hidden {
    display: none !important;
}

body .nl-container .nl-controls span.nl-btn-ctrl:hover {
    background: #374151 !important;
    transform: translateY(-1px);
}

.nl-engine-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #2d2d2d;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 13px;
    color: #d1d5db;
}

.nl-engine-btn {
    background: #374151;
    border: 1px solid #4b5563;
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    font-weight: bold;
    transition: all 0.2s;
}

.nl-engine-btn.on {
    background: #047857;
    border-color: #059669;
}

.nl-engine-eval {
    font-weight: bold;
    font-family: monospace;
    font-size: 15px;
    color: #fff;
}

.nl-engine-depth {
    font-size: 11px;
    color: #9ca3af;
    margin-left: 5px;
}

.nl-controls button:active {
    transform: translateY(1px);
}

.nl-moves {
    flex: 1;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 10px;
    font-size: 15px;
    line-height: 1.6;
    min-height: 250px;
    max-height: 400px;
    overflow-y: auto;
    color: #1f2937;
    position: relative;
    scroll-behavior: smooth;
}

.nl-moves.no-comments .move-comment {
    display: none !important;
}

.nl-moves.no-variations .pgn-variation {
    display: none !important;
}

.move-comment {
    font-size: 14px;
    padding: 6px 10px;
    background: #f5ebe0;
    border-left: 3px solid #d4c1ad;
    color: #000000;
    margin: 6px 0 10px 0;
    border-radius: 0 4px 4px 0;
    display: block;
    word-wrap: break-word;
}

.pgn-variation {
    display: block;
    color: #4b5563;
    font-style: italic;
    margin-top: 4px;
    padding-left: 8px;
    border-left: 2px solid #9ca3af;
    font-size: 13px;
}

.nl-moves .move-row {
    display: block;
    margin-bottom: 2px;
}

.nl-moves .move-row strong {
    color: #6b7280;
    display: inline-block;
    width: 35px;
}

.nl-moves .move-item {
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    display: inline-block;
    transition: background 0.1s;
}

.nl-moves .move-item:hover {
    background: #e5e7eb;
    color: #111827;
}

.nl-moves .move-item.active {
    background: #3b82f6;
    color: #fff;
    font-weight: bold;
}

@media(max-width: 800px) {
    body .nl-container {
        display: block !important;
        padding: 10px !important;
    }

    body .nl-container .nl-board-wrap {
        width: 100% !important;
        max-width: 100% !important;
        display: block !important;
        margin-bottom: 20px !important;
        min-width: 0 !important;
    }

    body .nl-container .cg-wrap {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
    }

    body .nl-container .nl-sidebar {
        width: 100% !important;
        display: flex;
    }

    body .nl-container .nl-moves {
        min-height: 200px !important;
        height: 200px !important;
    }
}

/* Stack board and move list when the board sits in a narrow column (e.g. a two-column page layout). */
*:has(> .nl-container) {
    container-type: inline-size;
}

@container (max-width: 760px) {
    body .nl-container {
        display: block !important;
        padding: 12px !important;
    }

    body .nl-container .nl-board-wrap {
        width: 100% !important;
        max-width: 100% !important;
        display: block !important;
        margin-bottom: 16px !important;
        min-width: 0 !important;
    }

    body .nl-container .cg-wrap {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
    }

    body .nl-container .nl-controls {
        max-width: 100% !important;
    }

    body .nl-container .nl-sidebar {
        width: 100% !important;
        display: flex;
    }

    body .nl-container .nl-moves {
        min-height: 160px !important;
        height: 200px !important;
    }
}

/* Board-Only Mode Styling Override */
.nl-container.mode-board_only {
    max-width: 450px;
}

/* Promotion choice (board.js window.sfcm_pick_promotion) */
.sfcm-promo { position: fixed; inset: 0; z-index: 100000; background: rgba(0, 0, 0, .4); display: flex; flex-wrap: wrap; align-content: center; justify-content: center; gap: 10px; padding: 16px; }
.sfcm-promo p { flex-basis: 100%; text-align: center; color: #fff; margin: 0 0 4px; font-weight: 700; font-size: 16px; text-shadow: 0 1px 2px rgba(0, 0, 0, .6); }
.sfcm-promo-piece { font-size: 46px; width: 68px; height: 68px; line-height: 1; padding: 0; border: 2px solid #fff; border-radius: 8px; background: #f0d9b5; color: #111; cursor: pointer; box-shadow: 0 4px 14px rgba(0, 0, 0, .35); }
.sfcm-promo-piece:hover { background: #fff3d6; }
.sfcm-promo-piece:focus-visible { outline: 3px solid #2271b1; outline-offset: 2px; }

/* Accessibility (roadmap 2.5): visible keyboard focus, text only for screen readers */
.nl-container [role="button"]:focus-visible, .nl-container button:focus-visible, .nl-container .cg-wrap:focus-visible { outline: 3px solid #60a5fa !important; outline-offset: 2px; }
.sfcm-sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* Training series and "Aufgabe der Woche" (roadmap 3.4, includes/training.php) */
.sfcm-training { margin: 1.5em 0; }
.sfcm-training-title { margin: 0 0 .4em; }
.sfcm-training-task.is-hidden { display: none !important; }
.sfcm-training-progress { margin: 0 0 6px; font-weight: 600; }
.sfcm-training-bar { height: 8px; background: #e5e7eb; border-radius: 4px; overflow: hidden; margin: 0 0 12px; }
.sfcm-training-bar i { display: block; height: 100%; width: 0; background: #15803d; transition: width .3s ease; }
.sfcm-training-dots { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.sfcm-training-dot { min-width: 36px; height: 36px; padding: 0 6px; border: 2px solid #9ca3af; border-radius: 6px; background: #fff; color: #111827; font: inherit; font-weight: 600; cursor: pointer; }
.sfcm-training-dot.is-clean, .sfcm-training-dot.is-solved { background: #dcfce7; border-color: #15803d; color: #14532d; }
.sfcm-training-dot.is-shown { background: #fef3c7; border-color: #b45309; color: #78350f; }
.sfcm-training-dot.is-current { outline: 3px solid #1d4ed8; outline-offset: 1px; }
.sfcm-training-num { margin: 0 0 4px; font-weight: 600; color: #374151; }
.sfcm-training-status { min-height: 1.4em; margin: 0 0 6px; font-weight: 600; }
.sfcm-training-status.is-clean, .sfcm-training-status.is-solved { color: #166534; }
.sfcm-training-status.is-shown { color: #92400e; }
.sfcm-training-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 12px; }
.sfcm-training-nav button { min-height: 44px; padding: 0 18px; border: 2px solid #1f4d3a; border-radius: 8px; background: #1f4d3a; color: #fff; font: inherit; font-weight: 700; cursor: pointer; }
.sfcm-training-nav button:disabled { opacity: .4; cursor: default; }
.sfcm-training button:focus-visible { outline: 3px solid #60a5fa; outline-offset: 2px; }
.sfcm-training-guest, .sfcm-training-login { font-size: .9em; color: #4b5563; }
@media (prefers-reduced-motion: reduce) { .sfcm-training-bar i { transition: none; } }

/* Move editing tools in the backend (roadmap 1.3) */
.sfcm-edit-tools { margin-top: 10px; padding: 10px; background: #f6f7f7; border: 1px solid #dcdcde; border-radius: 4px; font-size: 13px; color: #1d2327; }
.sfcm-edit-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.sfcm-edit-row label { display: inline-flex; gap: 4px; align-items: center; }
.sfcm-edit-comment { margin-top: 8px; }
.sfcm-edit-comment label { display: block; font-weight: 600; }
.sfcm-edit-comment textarea { display: block; width: 100%; margin: 4px 0 6px; }
.sfcm-edit-help { margin: 8px 0 0; color: #50575e; font-size: 12px; }
