:root {
    --bg-color: #f8fafc;
    --dot-color: #cbd5e1;
    --sidebar-bg: rgba(255, 255, 255, 0.85);
    --sidebar-border: rgba(255, 255, 255, 0.5);
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --accent-color: #3b82f6;
    --danger-color: #ef4444;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    /* Prevent body scroll, canvas handles it */
    height: 100vh;
    width: 100vw;
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    position: relative;
}

/* --- Toolbar --- */
.toolbar {
    width: 260px;
    height: 100%;
    background: var(--sidebar-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-right: 1px solid rgba(226, 232, 240, 0.8);
    display: flex;
    flex-direction: column;
    padding: 20px;
    z-index: 100;
    box-shadow: var(--shadow-md);
    transition: transform 0.3s ease;
}

.toolbar-header {
    display: flex;
    align-items: center;
    margin-bottom: 30px;
    gap: 10px;
}

.back-link {
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    transition: color 0.2s;
}

.back-link:hover {
    color: var(--accent-color);
}

.logo {
    font-weight: 700;
    font-size: 1.25rem;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.tool-group {
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tool-group.bottom {
    margin-top: auto;
}

.tool-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: white;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.tool-btn:hover {
    background: #f1f5f9;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.tool-btn:active {
    transform: translateY(0);
}

.tool-btn.primary {
    background: var(--accent-color);
    color: white;
}

.tool-btn.primary:hover {
    background: #2563eb;
}

.tool-btn.danger {
    color: var(--danger-color);
    border-color: #fee2e2;
}

.tool-btn.danger:hover {
    background: #fef2f2;
}

.tool-btn.icon-only {
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    display: inline-flex;
}

.tool-group:has(.icon-only) {
    flex-direction: row;
    justify-content: center;
}

/* Color Picker */
.color-picker-wrapper label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 500;
}

.color-options {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
}

.color-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid white;
    cursor: pointer;
    box-shadow: 0 0 0 1px #e2e8f0;
    transition: transform 0.2s;
}

.color-btn:hover {
    transform: scale(1.2);
}

.color-btn.active {
    box-shadow: 0 0 0 2px var(--text-primary);
}

/* --- Canvas --- */
.canvas-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
    background-color: var(--bg-color);
    background-image: radial-gradient(var(--dot-color) 1px, transparent 1px);
    background-size: 24px 24px;
    cursor: grab;
}

.canvas-wrapper:active {
    cursor: grabbing;
}

#mindmap-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform-origin: 0 0;
    /* Will be transformed by JS for Zoom/Pan */
}

#connections-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Let clicks pass through to nodes */
    z-index: 1;
    overflow: visible;
}

.connection-path {
    fill: none;
    stroke: #cbd5e1;
    stroke-width: 2px;
    transition: stroke 0.3s;
}

#nodes-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
}

/* --- Nodes --- */
.node {
    position: absolute;
    min-width: 100px;
    max-width: 300px;
    padding: 12px 20px;
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    border: 2px solid transparent;
    /* For selection state */
    cursor: pointer;
    user-select: none;
    transition: box-shadow 0.2s, transform 0.2s, background-color 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-weight: 500;
    color: white;
    /* Default text color for colored nodes */
}

.node:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.node.selected {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.4), var(--shadow-lg);
    z-index: 10;
}

.node.root {
    font-size: 1.2rem;
    font-weight: 700;
    padding: 16px 32px;
}

.node-content {
    outline: none;
    pointer-events: none;
    /* Enable only on double click */
}

.node.editing .node-content {
    pointer-events: auto;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-decoration-color: rgba(255, 255, 255, 0.5);
}

/* Shortcuts Hint */
.shortcuts-hint {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(4px);
    padding: 10px 16px;
    border-radius: 20px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    box-shadow: var(--shadow-md);
    pointer-events: none;
    z-index: 50;
}

/* --- Modals --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    animation: fadeIn 0.2s forwards;
}

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

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 16px;
    width: 90%;
    max-width: 450px;
    box-shadow: var(--shadow-lg);
    transform: scale(0.95);
    animation: scaleIn 0.2s forwards;
}

@keyframes scaleIn {
    to {
        transform: scale(1);
    }
}

#modal-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text-primary);
}

#modal-body {
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.6;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.modal-btn {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

.modal-btn:hover {
    opacity: 0.9;
}

.modal-btn.primary {
    background: var(--accent-color);
    color: white;
}

.modal-btn.secondary {
    background: #e2e8f0;
    color: var(--text-primary);
}

/* Instructions Panel */
.instructions-panel {
    margin-top: auto;
    margin-bottom: 20px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 12px;
    border: 1px solid rgba(226, 232, 240, 0.8);
    font-size: 0.85rem;
}

.instructions-panel h4 {
    margin-bottom: 10px;
    font-size: 0.9rem;
    color: var(--accent-color);
    font-weight: 600;
}

.instructions-panel ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.instructions-panel li {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

.instructions-panel li:last-child {
    margin-bottom: 0;
}

.instructions-panel li span {
    background: white;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid #e2e8f0;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
    min-width: 50px;
    text-align: center;
}

/* Responsive */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .toolbar {
        width: 100%;
        height: auto;
        flex-direction: row;
        overflow-x: auto;
        padding: 10px;
        gap: 16px;
    }

    .toolbar-header {
        margin-bottom: 0;
        margin-right: 10px;
    }

    .tool-group {
        margin-bottom: 0;
        flex-direction: row;
    }

    .tool-btn .label {
        display: none;
        /* Hide labels on mobile */
    }

    .color-picker-wrapper {
        display: none;
        /* Hide complex controls on mobile for now */
    }
}