@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

:root {
    --bg-canvas: #fafafa;
    --bg-dots: #d1d5db;
    --text-main: #1f2937;
    --bg-card: white;
    --border-card: #e5e7eb;
    --border-card-focus: #9ca3af;
    --text-placeholder: #9ca3af;
    --bg-btn: #f3f4f6;
    --text-btn: #4b5563;
    --bg-btn-hover: #111827;
    --text-btn-hover: white;
    --border-tree: #cbd5e1;
    --bg-delete-hover: #fee2e2;
    --text-delete-hover: #ef4444;
    --text-delete: #d1d5db;
    --shadow-card: rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] {
    --bg-canvas: #111827;
    --bg-dots: #374151;
    --text-main: #f3f4f6;
    --bg-card: #1f2937;
    --border-card: #374151;
    --border-card-focus: #60a5fa;
    --text-placeholder: #6b7280;
    --bg-btn: #374151;
    --text-btn: #d1d5db;
    --bg-btn-hover: #f3f4f6;
    --text-btn-hover: #111827;
    --border-tree: #4b5563;
    --bg-delete-hover: #7f1d1d;
    --text-delete-hover: #fca5a5;
    --text-delete: #4b5563;
    --shadow-card: rgba(0, 0, 0, 0.3);
}

html, body {
    font-family: 'Inter', system-ui, sans-serif;
    background-color: var(--bg-canvas);
    background-image: radial-gradient(var(--bg-dots) 1px, transparent 1px);
    background-size: 24px 24px;
    margin: 0;
    padding: 0;
    color: var(--text-main);
    overflow: hidden;
    overscroll-behavior: none;
    width: 100vw;
    height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.node-card, .zoom-controls { 
    cursor: default; 
}

#root-node > .node-card .delete-btn {
    display: none !important;
}

#canvas {
    position: absolute;
    width: 100000px;
    padding: 80px 0;
    display: flex;
    justify-content: center;
    transform-origin: 0 0;
    left: 0;
    top: 0;
    cursor: grab;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease;
}

#canvas.loaded {
    opacity: 1;
    visibility: visible;
}

.node {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    padding: 40px 15px 0 15px;
    flex-shrink: 0;
}

.node-card {
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px var(--shadow-card), 0 2px 4px -1px var(--shadow-card);
    width: 300px;
    padding: 16px;
    transition: box-shadow 0.2s ease, transform 0.2s ease, border-color 0.2s ease, background-color 0.3s ease;
    position: relative;
    z-index: 2;
}

.node-card:focus-within {
    box-shadow: 0 10px 15px -3px var(--shadow-card);
    border-color: var(--border-card-focus);
    transform: translateY(-2px);
}

textarea {
    width: 100%;
    box-sizing: border-box;
    min-height: 100px;
    height: auto;
    border: none;
    resize: none;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-main);
    outline: none;
    background: transparent;
    overflow: hidden;
}

textarea::placeholder { color: var(--text-placeholder); }

.fork-btn {
    background-color: var(--bg-btn);
    color: var(--text-btn);
    border: 1px solid transparent;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    margin-top: 24px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.fork-btn:hover {
    background-color: var(--bg-btn-hover);
    color: var(--text-btn-hover);
    box-shadow: 0 2px 4px var(--shadow-card);
}

.delete-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: none;
    border: none;
    color: var(--text-delete);
    cursor: pointer;
    font-size: 18px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
    opacity: 0;
}

.node-card:hover .delete-btn { 
    opacity: 1; 
}

.delete-btn:hover {
    background-color: var(--bg-delete-hover);
    color: var(--text-delete-hover);
}

.children {
    display: flex;
    justify-content: center;
    position: relative;
    padding-top: 40px;
    align-items: flex-start;
}

.children::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    margin-left: -1px;
    border-left: 2px solid var(--border-tree);
    width: 0;
    height: 40px;
    transition: border-color 0.3s ease;
}

.children:empty::before { 
    display: none; 
}

.node::before, .node::after {
    content: '';
    position: absolute;
    top: 0;
    width: 50%;
    height: 40px;
    border-top: 2px solid var(--border-tree);
    transition: border-color 0.3s ease;
}

.node::before { 
    right: calc(50% + 1px); 
}

.node::after { 
    left: calc(50% - 1px); 
    border-left: 2px solid var(--border-tree); 
}

.node:first-child::before { 
    border-top: none; 
} 

.node:last-child::after { 
    border-top: none; border-left: none; 
}

.node:first-child::after { 
    border-radius: 12px 0 0 0; 
}

.node:last-child::before { 
    border-right: 2px solid var(--border-tree); 
    border-radius: 0 12px 0 0; 
}
.node:only-child::after { 
    border-top: none; 
    border-left: 2px solid var(--border-tree); 
    border-radius: 0; 
}

.node:only-child::before { 
    display: none; 
}

#root-node { 
    padding-top: 0; 
}

#root-node::before, #root-node::after { 
    display: none; 
}

.bottom-right-controls {
    position: fixed;
    bottom: 30px;
    right: 30px;
    display: flex;
    gap: 12px;
    z-index: 100;
}

.control-group {
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: 8px;
    display: flex;
    align-items: center;
    box-shadow: 0 4px 6px -1px var(--shadow-card);
    font-family: inherit;
    color: var(--text-btn);
    overflow: hidden;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.control-group button {
    background: none;
    border: none;
    border-right: 1px solid var(--border-card);
    padding: 8px 12px;
    cursor: pointer;
    font-size: 16px;
    color: inherit;
    transition: background 0.2s, opacity 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-group button:last-child { border-right: none; }

.control-group button:hover:not(:disabled) {
    background: var(--bg-btn);
    color: var(--text-main);
}

.control-group button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    background: transparent;
}

#zoom-level {
    font-size: 13px;
    font-weight: 600;
    padding: 0 12px;
    min-width: 48px;
    text-align: center;
    cursor: default;
    border-right: 1px solid var(--border-card);
    display: flex;
    align-items: center;
    justify-content: center;
}

.export-wrapper { position: relative; }

.export-dropdown {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px var(--shadow-card);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 160px;
    transition: opacity 0.2s, transform 0.2s;
}

.export-dropdown.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
}

.export-dropdown button {
    background: none;
    border: none;
    border-bottom: 1px solid var(--bg-btn);
    padding: 10px 16px;
    text-align: left;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-main);
    font-family: inherit;
    transition: background 0.2s;
}

.export-dropdown button:last-child { 
    border-bottom: none; 
}

.export-dropdown button:hover {
    background: var(--bg-btn);
}

.hide-for-export { 
    display: none !important; 
}


.collapse-btn {
    position: absolute;
    bottom: -12px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-placeholder);
    cursor: pointer;
    transition: all 0.2s ease;
    opacity: 0;
    pointer-events: none;
    z-index: 3;
}

.collapse-btn:hover {
    color: var(--text-main);
    border-color: var(--border-card-focus);
    box-shadow: 0 2px 4px var(--shadow-card);
}

.node:has(> .children > .node) > .node-card .collapse-btn {
    opacity: 1;
    pointer-events: auto;
}

.node.collapsed > .children {
    display: none !important;
}

.node.collapsed > .node-card .collapse-btn svg {
    transform: rotate(-90deg);
}

.node.collapsed > .node-card::after {
    display: none;
}


body.focus-mode-active {
    background-image: none;
}

body.focus-mode-active .node-card,
body.focus-mode-active .children::before,
body.focus-mode-active .node::before,
body.focus-mode-active .node::after {
    opacity: 0.15;
    transition: opacity 0.4s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

body.focus-mode-active .node.focused-node > .node-card {
    opacity: 1;
    box-shadow: 0 0 0 2px var(--border-card-focus), 0 10px 20px -5px var(--shadow-card);
    transform: scale(1.02);
    z-index: 10;
}

body.focus-mode-active .node:has(.focused-node) > .node-card,
body.focus-mode-active .node:has(.focused-node) > .children::before,
body.focus-mode-active .node:has(.focused-node)::before,
body.focus-mode-active .node:has(.focused-node)::after {
    opacity: 0.6;
}

#focus-toggle.active {
    background-color: var(--bg-card);
    color: var(--border-card-focus);
}

.modal-overlay, 
.splash-screen, 
.bottom-right-controls, 
.bottom-left-hud {
    cursor: default;
}

.shortcuts-btn, 
.close-modal-btn, 
#dismiss-splash-btn {
    cursor: pointer;
}

textarea {
    cursor: text;
}

.bottom-left-hud {
    position: fixed;
    bottom: 30px;
    left: 30px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 100;
    pointer-events: none;
    opacity: 0.5;
    transition: opacity 0.3s ease;
}

.bottom-left-hud:hover {
    opacity: 1;
}

.hud-item {
    font-size: 12px;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

.hud-item span {
    color: var(--text-placeholder);
}

kbd {
    background-color: var(--bg-card);
    border: 1px solid var(--border-card);
    border-bottom-width: 2px;
    border-radius: 4px;
    padding: 2px 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-main);
}

.splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--bg-canvas);
    background-image: radial-gradient(var(--bg-dots) 1px, transparent 1px);
    background-size: 24px 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1), transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
    overflow: hidden;
}

.splash-screen.hidden {
    opacity: 0;
    transform: scale(1.05);
}

.splash-glow {
    position: absolute;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(96, 165, 250, 0.15) 0%, rgba(96, 165, 250, 0) 70%);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: -1;
    animation: breathe 8s ease-in-out infinite alternate;
}

@keyframes breathe {
    0% { transform: translate(-50%, -50%) scale(0.8); opacity: 0.5; }
    100% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
}

.splash-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    max-width: 900px;
    padding: 40px;
    pointer-events: auto;
}

.animate-fade-up {
    opacity: 0;
    transform: translateY(20px);
    animation: fadeUp 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes fadeUp {
    to { opacity: 1; transform: translateY(0); }
}

.splash-title {
    font-size: 64px;
    font-weight: 700;
    letter-spacing: -2px;
    margin: 0 0 16px 0;
    color: var(--text-main);
}

.typewriter-cursor {
    color: var(--border-card-focus);
    font-weight: 300;
    margin-left: 4px;
    animation: cursor-blink 1s step-end infinite;
}

@keyframes cursor-blink {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0;
    }
}

.splash-subtitle {
    font-size: 20px;
    color: var(--text-placeholder);
    margin: 0 0 64px 0;
}

.splash-cards {
    display: flex;
    gap: 24px;
    margin-bottom: 48px;
}

.splash-card {
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    padding: 32px 24px;
    border-radius: 16px;
    flex: 1;
    text-align: left;
    box-shadow: 0 20px 25px -5px var(--shadow-card);
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}

.splash-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 30px 40px -10px var(--shadow-card);
    border-color: var(--border-card-focus);
}

.splash-icon {
    font-size: 32px;
    margin-bottom: 16px;
}

.splash-card h3 {
    margin: 0 0 8px 0;
    font-size: 18px;
    color: var(--text-main);
}

.splash-card p {
    margin: 0;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-placeholder);
}

.splash-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

.custom-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-placeholder);
    transition: color 0.2s ease;
}

.custom-checkbox:hover {
    color: var(--text-main);
}

.custom-checkbox input {
    display: none;
}

.checkmark {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-card-focus);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    transition: all 0.2s ease;
}

.checkmark svg {
    width: 14px;
    height: 14px;
    stroke: white;
    opacity: 0;
    transform: scale(0.5);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.custom-checkbox input:checked + .checkmark {
    background: var(--text-main);
    border-color: var(--text-main);
}

.custom-checkbox input:checked + .checkmark svg {
    opacity: 1;
    transform: scale(1);
}

.splash-action {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-main);
}

.blinking-cursor {
    animation: blink 1s step-end infinite;
    color: var(--border-card-focus);
}

@keyframes blink {
    50% { opacity: 0; }
}

#dismiss-splash-btn {
    background-color: var(--text-main);
    color: var(--bg-canvas);
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
}

#dismiss-splash-btn kbd {
    background: rgba(255,255,255,0.2);
    border-color: rgba(255,255,255,0.3);
    color: inherit;
}

#dismiss-splash-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px var(--shadow-card);
}

.bottom-left-controls {
    position: fixed;
    bottom: 30px;
    left: 30px;
    z-index: 100;
}

.bottom-left-hud {
    position: fixed;
    bottom: 30px;
    left: 30px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 100;
    opacity: 0.6;
    transition: opacity 0.3s ease;
}

.bottom-left-hud:hover {
    opacity: 1;
}

body.focus-mode-active .bottom-left-hud {
    opacity: 0;
    pointer-events: none;
}

.hud-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.hud-item {
    font-size: 12px;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

.hud-item span {
    color: var(--text-placeholder);
}

.hud-item kbd {
    background-color: var(--bg-card);
    border: 1px solid var(--border-card);
    border-bottom-width: 2px;
    border-radius: 4px;
    padding: 2px 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-main);
}

.shortcuts-btn {
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: 8px;
    padding: 8px 12px;
    font-family: inherit;
    color: var(--text-btn);
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    box-shadow: 0 4px 6px -1px var(--shadow-card);
    transition: all 0.2s ease;
    width: fit-content;
    pointer-events: auto;
    margin-top: 4px;
}

.shortcuts-btn:hover {
    background: var(--bg-btn);
    color: var(--text-main);
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: 16px;
    box-shadow: 0 20px 25px -5px var(--shadow-card), 0 10px 10px -5px var(--shadow-card);
    transform: translateY(0) scale(1);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.hidden .modal-content {
    transform: translateY(20px) scale(0.95);
}

.shortcuts-content {
    width: 100%;
    max-width: 540px;
    padding: 32px 40px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-card);
}

.modal-header h2 { 
    margin: 0; 
    font-size: 20px; 
    font-weight: 600;
}

.close-modal-btn {
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-placeholder);
    cursor: pointer;
    transition: color 0.2s, transform 0.2s;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
}

.close-modal-btn:hover { 
    color: var(--text-main); 
    background-color: var(--bg-canvas);
}

.shortcuts-grid {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.shortcut-category {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
    color: var(--text-placeholder);
    margin-top: 20px;
    margin-bottom: 8px;
    padding-left: 12px;
}

.shortcut-category:first-child {
    margin-top: 0;
}

.shortcut-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    color: var(--text-main);
    padding: 10px 12px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
}

.shortcut-row:hover {
    background-color: var(--bg-canvas);
}

.shortcut-keys {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-placeholder);
}

.shortcut-row kbd { 
    margin: 0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.hud-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: auto; 
}

body.is-panning, 
body.is-panning * {
    cursor: grabbing !important;
}

.spinner {
    width: 30px;
    height: 30px;
    border: 3px solid var(--border-card);
    border-top: 3px solid var(--border-card-focus);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.premium-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: rgba(var(--bg-canvas-rgb, 250, 250, 250), 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 999999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    animation: fadeIn 0.3s forwards;
}

[data-theme="dark"] .premium-overlay {
    background: rgba(17, 24, 39, 0.7);
}

@keyframes fadeIn {
    to { opacity: 1; }
}

@keyframes fadeOut {
    to { opacity: 0; }
}

.custom-alert-box {
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: 20px;
    padding: 32px;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    transform: translateY(20px) scale(0.95);
    animation: popIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes popIn {
    to { transform: translateY(0) scale(1); }
}

.custom-alert-icon {
    font-size: 40px;
    margin-bottom: 16px;
    line-height: 1;
}

.custom-alert-box h3 {
    margin: 0 0 12px 0;
    font-size: 20px;
    color: var(--text-main);
}

.custom-alert-box p {
    margin: 0 0 24px 0;
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-placeholder);
}

.custom-alert-btn {
    background: var(--text-main);
    color: var(--bg-canvas);
    border: none;
    padding: 12px 32px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.custom-alert-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px var(--shadow-card);
}

.orbital-spinner {
    position: relative;
    width: 80px;
    height: 80px;
    margin-bottom: 24px;
}

.orbital-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 3px solid transparent;
}

.orbital-ring:nth-child(1) {
    border-top-color: var(--border-card-focus);
    animation: spin 1s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite;
}

.orbital-ring:nth-child(2) {
    border-right-color: var(--text-placeholder);
    animation: spin 1.5s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite reverse;
    transform: scale(0.8);
}

.orbital-ring:nth-child(3) {
    border-bottom-color: var(--text-main);
    animation: spin 2s linear infinite;
    transform: scale(0.6);
}

.loader-status {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
    letter-spacing: -0.5px;
    height: 24px;
}