:root {
    /* Background & Grid - ปรับให้เข้มกว่าสีขาวเล็กน้อยเพื่อให้ Node สีขาวโดดเด่น */
    --bg-color: #f0f2f5; 
    --grid-color: #d1d5db;
    --node-bg: #ffffff;
    --text-main: #111827; /* สีดำเกือบสนิท */
    --text-sub: #4b5563;  /* สีเทาเข้ม */
    --border: #e5e7eb;    /* เส้นขอบเทาอ่อน */
    
    /* System Colors (Adjusted for Light Theme) */
    --c-ui: #db2777;       
    --c-ctrl: #0891b2;     
    --c-lang: #d97706;     
    --c-voice: #059669;    
    --c-know: #7c3aed;     
    --c-root: #4f46e5;     
    --c-preview: #dc2626;  
    --c-style: #b45309;    
    --c-action: #15803d;   
    --c-icon: #2563eb;     
    --c-monitor: #b91c1c;  
}

/* --- GLOBAL SCROLLBAR (Light Theme) --- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #f3f4f6; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

body {
    margin: 0; overflow: hidden;
    background-color: var(--bg-color);
    background-image: radial-gradient(var(--grid-color) 1px, transparent 1px);
    background-size: 30px 30px; /* ขยายขนาด Grid ให้ดูโปร่งขึ้น */
    font-family: 'Sarabun', sans-serif;
    color: var(--text-main);
    width: 100vw; height: 100vh;
    user-select: none;
}

/* --- CANVAS --- */
#viewport { width: 100%; height: 100%; cursor: grab; overflow: hidden; position: relative; }
#viewport.grabbing { cursor: grabbing; }
#world { transform-origin: 0 0; position: absolute; top: 0; left: 0; width: 0; height: 0; }

.mindmap-layout {
    display: flex; align-items: flex-start;
    padding: 100px; gap: 150px; position: relative;
    width: max-content; height: max-content;
}

.column {
    display: flex; flex-direction: column; gap: 24px;
    min-width: 280px; max-width: 320px;
    justify-content: center; position: relative; z-index: 2;
}

/* --- NODE DESIGN (Modern Card) --- */
.node {
    background: var(--node-bg);
    border: 1px solid rgba(0,0,0,0.05);
    border-left: 5px solid var(--node-color); /* เส้นขอบหนาขึ้นชัดเจน */
    border-radius: 12px;
    padding: 0;
    position: relative;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    display: flex; flex-direction: column;
}

.node:hover { 
    transform: translateY(-4px); 
    z-index: 10; 
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05); 
}

.node.active { 
    background: #fff; 
    box-shadow: 0 0 0 2px var(--node-color), 0 10px 25px rgba(0,0,0,0.1); 
    transform: scale(1.03); 
}

.node-main {
    padding: 16px;
    display: flex; align-items: center; gap: 14px;
}

.node-icon { font-size: 26px; color: var(--node-color); }
.node-info { flex-grow: 1; }
.node-title { font-weight: 600; font-size: 15px; color: var(--text-main); letter-spacing: 0.2px; }
.node-desc { font-size: 12px; color: var(--text-sub); margin-top: 4px; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.node-action {
    padding: 10px 16px; display: flex; justify-content: flex-end;
    background: #f9fafb; border-top: 1px solid #f3f4f6;
    border-radius: 0 0 12px 12px;
}

.code-btn {
    background: #fff; border: 1px solid #e5e7eb;
    color: var(--text-sub); border-radius: 8px;
    padding: 6px 12px; font-size: 11px; font-family: 'Sarabun';
    cursor: pointer; display: flex; align-items: center; gap: 6px;
    transition: all 0.2s;
}
.code-btn:hover { background: var(--node-color); border-color: var(--node-color); color: #fff; }

/* Dots */
.node::before, .node::after {
    content: ''; position: absolute; top: 50%;
    width: 10px; height: 10px; background: #d1d5db;
    border-radius: 50%; transform: translateY(-50%);
    transition: 0.3s; z-index: 5; border: 2px solid var(--bg-color);
}
.node::before { left: -7.5px; } 
.node::after { right: -7.5px; }
.node.active::before, .node.active::after { background: var(--node-color); border-color: #fff; }
.node[data-type="root"]::before { display: none; }
.node[data-type="func"]::after { display: none; }

/* SVG - เส้นเชื่อมต่อจะใช้สีเดียวกับ Node ต้นทาง */
svg.connections { position: absolute; top: 0; left: 0; overflow: visible; pointer-events: none; z-index: 1; }
path.link { fill: none; stroke: #cbd5e1; stroke-width: 2px; transition: stroke 0.3s; }
path.link.active { 
    stroke: var(--line-color); /* ใช้สีเดียวกับ node ตามสั่ง */
    stroke-width: 3px; 
    stroke-dasharray: 8, 4; 
    animation: dash 30s linear infinite; 
    opacity: 1; 
}
@keyframes dash { to { stroke-dashoffset: -1000; } }

/* --- CONTROLS --- */
.viewport-controls {
    position: fixed; 
    bottom: 30px; 
    right: 30px; 
    display: flex; gap: 12px; z-index: 100;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ปรับตำแหน่งปุ่มควบคุมเมื่อ Panel ด้านล่างเปิด */
body.panel-open .viewport-controls {
    bottom: calc(18vh + 30px); /* ปรับเป็น 18vh ตามสั่ง */
}

.control-btn {
    background: #fff; border: 1px solid #e5e7eb; color: #374151;
    width: 50px; height: 50px; border-radius: 50%; /* ทรงกลมดูทันสมัยขึ้น */
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05); transition: 0.2s;
}
.control-btn:hover { background: #f9fafb; color: var(--c-root); transform: translateY(-3px); box-shadow: 0 6px 15px rgba(0,0,0,0.1); }

/* --- CLEAN MODAL UI --- */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(31, 41, 55, 0.4); backdrop-filter: blur(8px);
    z-index: 1000; display: none; justify-content: center; align-items: center;
    opacity: 0; transition: opacity 0.2s ease;
}
.modal-overlay.show { display: flex; opacity: 1; }

.editor-container, .modal-box, .preview-container {
    background: #ffffff; 
    border: 1px solid #f3f4f6; 
    border-radius: 20px; 
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.2);
    display: flex; flex-direction: column; overflow: hidden;
}

.editor-bar, .modal-header {
    background: #f9fafb; 
    border-bottom: 1px solid #f3f4f6;
    padding: 20px 25px;
    display: flex; justify-content: space-between; align-items: center;
    flex-shrink: 0;
}
.editor-title, .modal-header h3 {
    font-weight: 600; font-size: 1.25rem; color: var(--text-main);
    display: flex; align-items: center; gap: 12px; margin: 0;
}

.btn-close {
    background: #f3f4f6; border: none; color: var(--text-sub);
    width: 32px; height: 32px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: 0.2s;
}
.btn-close:hover { background: #e5e7eb; color: #000; }

/* --- DETAIL PANEL (BOTTOM) --- */
.detail-panel {
    position: fixed; bottom: 0; left: 0; width: 100%;
    background: #ffffff; border-top: 1px solid #e5e7eb;
    transform: translateY(100%); transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 90; display: flex; flex-direction: column;
    height: auto; max-height: 45vh; min-height: 180px;
}
.detail-panel.active { transform: translateY(0); }
.detail-header { padding: 20px 30px; border-bottom: 1px solid #f3f4f6; background: #295179; }
.detail-title { font-size: 1.3rem; font-weight: 600; color: #000000; } /* บังคับสีดำตามสั่ง */
.detail-type { font-size: 0.75rem; color: #fff; background: var(--c-root); padding: 3px 8px; border-radius: 6px; margin-left: 12px; vertical-align: middle; text-transform: uppercase; }

.detail-body { padding: 25px 30px; display: flex; gap: 50px; overflow-y: auto; }
.detail-desc { font-size: 1rem; line-height: 1.7; color: var(--text-main); flex: 2; font-weight: 400; }
.detail-stats { flex: 1; display: grid; grid-template-columns: 1fr; gap: 16px; border-left: 1px solid #f3f4f6; padding-left: 30px; }
.stat-label { color: var(--text-sub); font-size: 0.85rem; font-weight: 600; text-transform: uppercase; margin-bottom: 4px; }
.stat-value { color: var(--text-main); font-size: 1.1rem; font-weight: 600; }

/* --- STYLE EDITOR UI --- */
.style-editor-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
.style-input-group {
    background: #f9fafb; padding: 16px; border-radius: 12px; border: 1px solid #e5e7eb;
}
.style-text-input {
    width: 100%; background: #fff; border: 1px solid #d1d5db; color: #111;
    font-family: 'JetBrains Mono'; font-size: 0.9rem; padding: 8px 12px; border-radius: 6px;
    margin-top: 8px;
}
.style-text-input:focus { border-color: var(--c-root); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1); }

/* Footer */
.style-actions-footer {
    margin-top: 30px; padding-top: 20px; border-top: 1px solid #f3f4f6;
    display: flex; justify-content: flex-end; gap: 12px;
}

/* --- BUTTONS --- */
.btn {
    background: #fff; border: 1px solid #d1d5db; color: #374151;
    padding: 10px 20px; border-radius: 10px; cursor: pointer; display: flex; gap: 8px; align-items: center;
    font-size: 0.95rem; font-weight: 600; transition: all 0.2s;
}
.btn:hover { border-color: #9ca3af; background: #f9fafb; }
.btn-primary { background: var(--c-root); border-color: var(--c-root); color: #fff; }
.btn-primary:hover { background: #4338ca; border-color: #4338ca; box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2); }

/* Code View Area */
textarea#source-code {
    width: 100%; height: 100%; background: #f8fafc; color: #1e293b;
    border: 1px solid #e2e8f0; border-radius: 12px; padding: 20px; 
    font-family: 'JetBrains Mono', monospace; font-size: 13px; line-height: 1.6;
}