/* ═══════════════════════════════════════════════════════
   REPERTOIRE BUILDER — Hệ Thống Khai Cuộc
   CSS styles for the Repertoire Builder feature
   Diamond Member exclusive — Chess Kingdom
   ═══════════════════════════════════════════════════════ */

/* ── Layout ── */
.rep-container {
    display: flex;
    flex-direction: column;
    gap: 0;
    height: calc(100vh - 120px);
    min-height: 580px;
    overflow: hidden;
    /* Dark island — bắt buộc để tất cả rgba(255,255,255,...) hiển thị đúng */
    background: linear-gradient(135deg, #0f0f23 0%, #1a1a35 100%);
    border-radius: 16px;
    padding: 16px;
    color: #e8e8f0;
    box-shadow: 0 8px 40px rgba(0,0,0,0.4);
}

.rep-editor-layout {
    display: grid;
    grid-template-columns: minmax(280px, 420px) 1fr;
    gap: 16px;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* ── Board Panel ── */
.rep-board-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: hidden;
}

.rep-board-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 6px 32px rgba(0,0,0,0.5);
    flex-shrink: 0;
}

#rep-board {
    width: 100%;
    height: 100%;
}

.rep-board-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.rep-btn {
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.05);
    color: #e0e0e0;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    white-space: nowrap;
}

.rep-btn:hover {
    background: rgba(255,255,255,0.12);
    border-color: rgba(255,255,255,0.25);
    transform: translateY(-1px);
}

.rep-btn.rep-btn--primary {
    background: linear-gradient(135deg, #6c5ce7, #a29bfe);
    border-color: transparent;
    color: #fff;
    box-shadow: 0 3px 12px rgba(108,92,231,0.35);
}

.rep-btn.rep-btn--primary:hover {
    box-shadow: 0 5px 18px rgba(108,92,231,0.5);
}

.rep-btn.rep-btn--danger {
    background: rgba(231,76,60,0.12);
    border-color: rgba(231,76,60,0.3);
    color: #e74c3c;
}

.rep-btn.rep-btn--danger:hover {
    background: rgba(231,76,60,0.2);
}

.rep-btn.rep-btn--success {
    background: rgba(39,174,96,0.12);
    border-color: rgba(39,174,96,0.3);
    color: #2ecc71;
}

.rep-btn.rep-btn--success:hover {
    background: rgba(39,174,96,0.22);
}

.rep-btn.rep-btn--tree {
    background: linear-gradient(135deg,rgba(39,174,96,0.15),rgba(39,174,96,0.08));
    border-color: rgba(39,174,96,0.35);
    color: #2ecc71;
    position: relative;
}

.rep-btn.rep-btn--tree.active {
    background: linear-gradient(135deg,rgba(39,174,96,0.3),rgba(39,174,96,0.18));
    box-shadow: 0 0 12px rgba(39,174,96,0.25);
}

.rep-nav-controls {
    display: flex;
    gap: 4px;
}

.rep-nav-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(255,255,255,0.04);
    color: #ccc;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rep-nav-btn:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

/* ── Save Status ── */
.rep-save-status {
    font-size: 0.72rem;
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 600;
    transition: all 0.3s;
}

.rep-save-status.saved {
    background: rgba(39,174,96,0.12);
    color: #2ecc71;
    border: 1px solid rgba(39,174,96,0.25);
}

.rep-save-status.unsaved {
    background: rgba(240,180,41,0.12);
    color: #f0b429;
    border: 1px solid rgba(240,180,41,0.25);
    animation: repPulse 1.5s ease-in-out infinite;
}

.rep-save-status.saving {
    background: rgba(108,92,231,0.12);
    color: #a29bfe;
    border: 1px solid rgba(108,92,231,0.25);
}

@keyframes repPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ── Right Panel (Notation + Tree) ── */
.rep-right-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: hidden;
    min-height: 0;
}

/* ── Notation Panel ── */
.rep-notation-panel {
    background: rgba(14,14,30,0.7);
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 12px;
    padding: 14px 16px;
    flex: 1;
    overflow-y: auto;
    font-family: 'Baloo 2', 'Roboto Mono', monospace;
    font-size: 0.9rem;
    line-height: 1.9;
    scrollbar-width: thin;
    scrollbar-color: rgba(108,92,231,0.4) transparent;
}

.rep-notation-panel::-webkit-scrollbar { width: 5px; }
.rep-notation-panel::-webkit-scrollbar-track { background: transparent; }
.rep-notation-panel::-webkit-scrollbar-thumb { background: rgba(108,92,231,0.4); border-radius: 3px; }

.rep-move-num {
    color: rgba(255,255,255,0.55);
    font-size: 0.82rem;
    font-weight: 700;
    margin-right: 2px;
    user-select: none;
}

/* Move token */
.rep-move {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 600;
    color: #d0e8ff;
    transition: all 0.12s;
    margin: 0 1px;
}

.rep-move:hover {
    background: rgba(108,92,231,0.25);
    color: #fff;
}

.rep-move.rep-move--active {
    background: rgba(108,92,231,0.45);
    color: #fff;
    box-shadow: 0 0 10px rgba(108,92,231,0.3);
}

.rep-move.rep-move--main {
    color: #f0f0f8;
    font-weight: 700;
}

/* Variations */
.rep-variation {
    display: inline;
}

.rep-var-block {
    display: block;
    margin: 2px 0;
    padding: 3px 8px 3px 14px;
    border-left: 2px solid rgba(52,152,219,0.35);
    margin-left: 4px;
    border-radius: 0 6px 6px 0;
    background: rgba(52,152,219,0.04);
}

.rep-var-block.depth-1 {
    border-left-color: rgba(52,152,219,0.4);
    padding-left: 14px;
}

.rep-var-block.depth-2 {
    border-left-color: rgba(155,89,182,0.4);
    padding-left: 22px;
    background: rgba(155,89,182,0.04);
}

.rep-var-block.depth-3 {
    border-left-color: rgba(46,204,113,0.35);
    padding-left: 30px;
    background: rgba(46,204,113,0.03);
}

.rep-var-block.depth-4 {
    border-left-color: rgba(230,126,34,0.35);
    padding-left: 38px;
    background: rgba(230,126,34,0.03);
}

.rep-var-block .rep-move {
    color: #b0d4f8;
    font-size: 0.85rem;
}

.rep-var-block.depth-2 .rep-move { color: #d8aeed; font-size: 0.82rem; }
.rep-var-block.depth-3 .rep-move { color: #a0e8a0; font-size: 0.8rem; }
.rep-var-block.depth-4 .rep-move { color: #f5c842; font-size: 0.78rem; }

/* Collapse toggle for variations */
.rep-var-toggle {
    cursor: pointer;
    font-size: 0.65rem;
    opacity: 0.55;
    user-select: none;
    padding: 0 3px;
    transition: opacity 0.15s;
}
.rep-var-toggle:hover { opacity: 0.85; }

/* Comment inline */
.rep-comment {
    display: inline;
    color: rgba(160,196,232,0.65);
    font-style: italic;
    font-size: 0.82rem;
    margin: 0 4px;
}

.rep-comment-block {
    display: block;
    padding: 6px 10px;
    margin: 4px 0;
    background: rgba(0,0,0,0.15);
    border-radius: 6px;
    border-left: 2px solid rgba(108,92,231,0.4);
    color: rgba(200,220,240,0.75);
    font-style: italic;
    font-size: 0.82rem;
    line-height: 1.5;
}

/* NAG symbols */
.rep-nag {
    display: inline-block;
    font-size: 0.85rem;
    margin: 0 2px;
    color: #f0b429;
}

/* Comment trigger button — hidden by default, shown on hover of sibling move */
.rep-cmt-btn {
    display: inline-block;
    cursor: pointer;
    font-size: 0.72rem;
    opacity: 0;
    padding: 0 3px;
    border-radius: 4px;
    transition: opacity 0.15s, background 0.15s;
    vertical-align: middle;
    user-select: none;
    color: rgba(108,92,231,0.9);
}
/* Show when hovering the entire notation line containing the move */
.rep-notation-panel .rep-move:hover + .rep-cmt-btn,
.rep-cmt-btn:hover { opacity: 1; background: rgba(108,92,231,0.15); }


/* Model game badge */
.rep-game-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 1px 8px;
    background: linear-gradient(135deg, rgba(39,174,96,0.2), rgba(39,174,96,0.1));
    border: 1px solid rgba(39,174,96,0.4);
    border-radius: 20px;
    font-size: 0.68rem;
    font-weight: 700;
    color: #2ecc71;
    cursor: pointer;
    margin: 0 2px;
    transition: all 0.15s;
    vertical-align: middle;
}

.rep-game-badge:hover {
    background: linear-gradient(135deg, rgba(39,174,96,0.35), rgba(39,174,96,0.2));
    box-shadow: 0 0 8px rgba(39,174,96,0.25);
    transform: translateY(-1px);
}

/* ── Node action toolbar (shows on hover/active) ── */
.rep-node-actions {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    opacity: 0;
    transition: opacity 0.15s;
    vertical-align: middle;
}

.rep-notation-panel:hover .rep-node-actions,
.rep-move.rep-move--active + .rep-node-actions {
    opacity: 1;
}

.rep-node-action-btn {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(255,255,255,0.05);
    color: rgba(255,255,255,0.5);
    font-size: 0.65rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.12s;
}

.rep-node-action-btn:hover {
    background: rgba(255,255,255,0.12);
    color: #fff;
}

/* ── Variation Tree Panel ── */
.rep-tree-panel {
    background: #0d0d1f;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    padding: 10px 0 10px 10px;
    max-height: 340px;
    overflow-y: auto;
    font-family: 'Roboto Mono', 'Baloo 2', monospace;
    font-size: 0.82rem;
    transition: all 0.3s;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.15) transparent;
}

.rep-tree-panel::-webkit-scrollbar { width: 4px; }
.rep-tree-panel::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

.rep-tree-panel.hidden {
    display: none;
}

.rep-tree-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    padding: 0 10px 8px 4px;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    font-size: 0.72rem;
    font-weight: 700;
    color: rgba(255,255,255,0.55);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Each row in the tree */
.rep-tree-row {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 2px 4px;
    padding: 2px 8px 2px 0;
    min-height: 24px;
    position: relative;
    line-height: 1.8;
}

.rep-tree-row--var {
    /* connector line on the left */
    border-left: 2px solid rgba(255,255,255,0.12);
    margin-left: 8px;
}

/* Collapse circle button */
.rep-tree-collapse {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.6);
    background: #1a1a35;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 900;
    cursor: pointer;
    flex-shrink: 0;
    margin-right: 6px;
    transition: all 0.15s;
    line-height: 1;
    padding: 0;
    font-family: inherit;
    position: relative;
    top: 1px;
}
.rep-tree-collapse:hover {
    background: rgba(108,92,231,0.4);
    border-color: #a29bfe;
}

/* Dot placeholder for rows without collapse button */
.rep-tree-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.3);
    background: transparent;
    flex-shrink: 0;
    margin-right: 8px;
    position: relative;
    top: 1px;
}

/* Move number in tree */
.rep-tree-num {
    color: rgba(255,255,255,0.42);
    font-size: 0.75rem;
    font-weight: 700;
    user-select: none;
    margin-right: 1px;
}

/* Move token in tree */
.rep-tree-move {
    cursor: pointer;
    color: #d8e8ff;
    font-weight: 600;
    font-size: 0.82rem;
    padding: 1px 5px;
    border-radius: 4px;
    transition: all 0.1s;
    white-space: nowrap;
}
.rep-tree-move:hover {
    background: rgba(108,92,231,0.3);
    color: #fff;
}
.rep-tree-move.selected {
    background: rgba(108,92,231,0.55);
    color: #fff;
    box-shadow: 0 0 8px rgba(108,92,231,0.4);
}
.rep-tree-move.has-comment::after {
    content: '\1F4AC';
    font-size: 0.6rem;
    margin-left: 2px;
    opacity: 0.7;
    vertical-align: super;
}

/* Variation moves — slightly different shade */
.rep-tree-row--var .rep-tree-move {
    color: #b0cce8;
}

/* ── List View ── */
.rep-list-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    padding: 4px 0;
}

.rep-card {
    background: linear-gradient(135deg, rgba(108,92,231,0.1), rgba(108,92,231,0.05));
    border: 2px solid rgba(108,92,231,0.2);
    border-radius: 18px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.25s;
    position: relative;
    overflow: hidden;
}

.rep-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, #6c5ce7, #a29bfe, #fd79a8);
    opacity: 0;
    transition: opacity 0.25s;
}

.rep-card:hover {
    transform: translateY(-4px);
    border-color: rgba(108,92,231,0.5);
    box-shadow: 0 8px 32px rgba(108,92,231,0.2);
}

.rep-card:hover::before {
    opacity: 1;
}

.rep-card-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
}

.rep-card-name {
    font-size: 1.05rem;
    font-weight: 800;
    margin-bottom: 6px;
    color: #ffffff;
}

.rep-card-desc {
    font-size: 0.78rem;
    color: rgba(255,255,255,0.72);
    margin-bottom: 12px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.rep-card-meta {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 0.7rem;
}

.rep-card-tag {
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.7);
    border: 1px solid rgba(255,255,255,0.14);
}

.rep-card-actions {
    display: flex;
    gap: 8px;
    margin-top: 14px;
}

.rep-create-card {
    border: 2px dashed rgba(108,92,231,0.3);
    background: rgba(108,92,231,0.04);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 160px;
    border-radius: 18px;
    cursor: pointer;
    transition: all 0.25s;
    color: rgba(108,92,231,0.7);
}

.rep-create-card:hover {
    border-color: rgba(108,92,231,0.6);
    background: rgba(108,92,231,0.1);
    color: #a29bfe;
    transform: translateY(-2px);
}

.rep-limit-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    background: rgba(240,180,41,0.1);
    border: 1px solid rgba(240,180,41,0.25);
    color: #f0b429;
}

/* ── Modal / Dialog styles ── */
.rep-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: repFadeIn 0.2s ease;
}

@keyframes repFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.rep-modal {
    background: linear-gradient(135deg, #1a1a35, #12122a);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 20px;
    padding: 28px;
    max-width: 600px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    animation: repSlideUp 0.25s ease;
}

@keyframes repSlideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.rep-modal-title {
    font-size: 1.15rem;
    font-weight: 800;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.rep-input {
    width: 100%;
    padding: 10px 14px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 10px;
    color: #e0e0e0;
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.15s;
    box-sizing: border-box;
}

.rep-input:focus {
    outline: none;
    border-color: rgba(108,92,231,0.5);
    background: rgba(108,92,231,0.06);
}

.rep-input::placeholder {
    color: rgba(255,255,255,0.38);
}

textarea.rep-input {
    resize: vertical;
    min-height: 100px;
    font-family: 'Roboto Mono', monospace;
    font-size: 0.8rem;
    line-height: 1.5;
}

.rep-label {
    font-size: 0.8rem;
    font-weight: 700;
    color: rgba(255,255,255,0.82);
    margin-bottom: 6px;
    display: block;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.rep-form-group {
    margin-bottom: 16px;
}

/* ── Comment Editor ── */
.rep-comment-editor {
    background: rgba(108,92,231,0.06);
    border: 1px solid rgba(108,92,231,0.2);
    border-radius: 10px;
    padding: 12px;
    margin-top: 8px;
}

/* ── Model Games Panel ── */
.rep-game-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 400px;
    overflow-y: auto;
}

.rep-game-item {
    padding: 10px 14px;
    border-radius: 10px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.07);
    transition: all 0.15s;
    cursor: pointer;
}

.rep-game-item:hover {
    background: rgba(39,174,96,0.08);
    border-color: rgba(39,174,96,0.25);
}

.rep-game-item.selected {
    background: rgba(39,174,96,0.14);
    border-color: rgba(39,174,96,0.4);
    box-shadow: 0 0 8px rgba(39,174,96,0.15);
}

.rep-game-title {
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rep-game-meta {
    font-size: 0.72rem;
    color: rgba(255,255,255,0.68);
}

/* ── NAG selector ── */
.rep-nag-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 6px;
}

.rep-nag-btn {
    padding: 6px 4px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(255,255,255,0.04);
    color: #ccc;
    font-size: 0.75rem;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s;
    font-family: inherit;
}

.rep-nag-btn:hover {
    background: rgba(240,180,41,0.15);
    border-color: rgba(240,180,41,0.35);
    color: #f0b429;
}

.rep-nag-btn.active {
    background: rgba(240,180,41,0.2);
    border-color: rgba(240,180,41,0.5);
    color: #f0b429;
}

/* ── Tabs (Model Games manager) ── */
.rep-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 16px;
}

.rep-tab {
    padding: 8px 16px;
    border-radius: 10px 10px 0 0;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.6);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.rep-tab.active {
    background: rgba(108,92,231,0.2);
    color: #a29bfe;
    border-bottom: 2px solid #6c5ce7;
}

/* ── Diamond gate message ── */
.rep-diamond-gate {
    text-align: center;
    padding: 60px 20px;
}

.rep-diamond-gate .gate-icon {
    font-size: 4rem;
    margin-bottom: 16px;
    animation: repGateBounce 2s ease-in-out infinite;
}

@keyframes repGateBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* ── Position info bar ── */
.rep-position-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: rgba(0,0,0,0.25);
    border-radius: 8px;
    font-size: 0.72rem;
    flex-wrap: wrap;
    color: rgba(255,255,255,0.85);
}

.rep-fen-display {
    font-family: 'Roboto Mono', monospace;
    font-size: 0.65rem;
    color: rgba(255,255,255,0.45);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 200px;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .rep-editor-layout {
        grid-template-columns: 1fr;
        overflow-y: auto;
    }

    .rep-board-wrap {
        max-width: 360px;
        margin: 0 auto;
    }

    .rep-notation-panel {
        max-height: 280px;
    }

    .rep-tree-panel {
        max-height: 160px;
    }

    .rep-container {
        height: auto;
        overflow: visible;
    }
}

@media (max-width: 480px) {
    .rep-board-toolbar {
        justify-content: center;
    }

    .rep-list-grid {
        grid-template-columns: 1fr;
    }
}
