.text-node {
    position: absolute;
    min-width: 20px;
    min-height: 24px;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 16px;
    line-height: 1.5;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--text-color);
    transition: box-shadow 0.2s, border-color 0.2s, background 0.2s;
    cursor: text;
    user-select: text;
}

.text-node:hover {
    border-color: var(--node-hover-border);
}

.text-node:focus-within {
    background: var(--node-focus-bg);
    border-color: var(--brand-color);
    box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.15);
}

.text-node-body {
    min-width: 20px;
    min-height: 24px;
    padding: 2px 4px;
    white-space: pre-wrap;
    background: transparent;
    color: inherit;
    outline: none;
    user-select: text;
    cursor: inherit;
}

.text-node-body:empty {
    min-width: 40px;
    background-image:
        radial-gradient(circle, var(--ui-text-color) 2px, transparent 2.5px),
        radial-gradient(circle, var(--ui-text-color) 2px, transparent 2.5px),
        radial-gradient(circle, var(--ui-text-color) 2px, transparent 2.5px);
    background-size: 8px 8px;
    background-repeat: no-repeat;
    animation: typingBounce 1.2s infinite ease-in-out both;
}

@keyframes typingBounce {
    0%, 80%, 100% { background-position: 6px 12px, 16px 12px, 26px 12px; }
    16% { background-position: 6px 6px, 16px 12px, 26px 12px; }
    32% { background-position: 6px 12px, 16px 6px, 26px 12px; }
    48% { background-position: 6px 12px, 16px 12px, 26px 6px; }
}

.text-node-body:empty::before {
    content: "   ";
    white-space: pre;
    visibility: hidden;
}

.text-node-help {
    display: none;
    margin-top: 6px;
    padding: 4px 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11px;
    line-height: 1.55;
    color: var(--ui-text-color);
    opacity: 0.6;
    user-select: none;
}
.text-node-help > span {
    display: block;
}
.text-node-help-title {
    font-weight: 600;
    opacity: 0.85;
    margin-bottom: 2px;
}
.text-node-help a {
    color: inherit;
    text-decoration: underline;
    pointer-events: auto;
    cursor: pointer;
}
.text-node.text-node-empty:focus-within .text-node-help {
    display: block;
}

.text-node.postit {
    background: transparent;
    padding: 10px 14px;
    border-radius: 2px;
    color: #1a1a1a;
    transform: translateZ(0);
    will-change: transform;
}
.text-node.postit::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: -2;
    background: linear-gradient(
        to bottom,
        transparent 0%,
        transparent 30%,
        rgba(0, 0, 0, 0.22) 100%
    );
    filter: blur(5px);
    transform: translateY(5px) rotate(-1deg);
    transform-origin: center center;
}
.text-node.postit::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: -1;
    border-radius: inherit;
    background:
        linear-gradient(
            to bottom,
            rgba(0, 0, 0, 0.06) 0%,
            rgba(0, 0, 0, 0) 35%,
            rgba(0, 0, 0, 0) 94%,
            rgba(0, 0, 0, 0.015) 100%
        ),
        #fff59d;
}
[data-theme="dark"] .text-node.postit {
    color: #e0e0e0;
}
[data-theme="dark"] .text-node.postit::before {
    background: linear-gradient(
        to bottom,
        transparent 0%,
        transparent 30%,
        rgba(15, 15, 15, 0.9) 100%
    );
}
[data-theme="dark"] .text-node.postit::after {
    background:
        linear-gradient(
            to bottom,
            rgba(0, 0, 0, 0.25) 0%,
            rgba(0, 0, 0, 0) 35%,
            rgba(0, 0, 0, 0) 94%,
            rgba(0, 0, 0, 0.08) 100%
        ),
        #330086;
}

.pdf-export .text-node.postit,
.pdf-export[data-theme="dark"] .text-node.postit,
[data-theme="dark"] .pdf-export .text-node.postit {
    color: #1a1a1a;
}
.pdf-export .text-node.postit::before,
[data-theme="dark"] .pdf-export .text-node.postit::before {
    display: none;
}
.pdf-export .text-node.postit::after,
[data-theme="dark"] .pdf-export .text-node.postit::after {
    background: #fff59d;
}

@media (hover: hover) {
    :root:not([data-postit-discovered]) .text-node:not(.postit):not(:focus-within):not(.link-node):not(.mermaid-node):not(.dragging):hover > .text-node-body::after {
        content: "Right-click to turn into a sticky note";
        position: absolute;
        top: calc(100% + 6px);
        left: 50%;
        transform: translateX(-50%);
        white-space: nowrap;
        background: var(--glass-bg);
        backdrop-filter: blur(8px);
        border: 1px solid var(--border-color);
        color: var(--ui-text-color);
        padding: 4px 8px;
        border-radius: 6px;
        font-size: 11px;
        font-weight: 500;
        font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
        line-height: 1.2;
        pointer-events: none;
        box-shadow: var(--shadow);
        z-index: 2000;
        opacity: 0;
        animation: textNodeHintFade 0.15s ease 0.6s forwards;
    }
}

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

.text-node.markdown-node {
    user-select: none;
    -webkit-user-select: none;
}

.text-node.markdown-node .text-node-body {
    white-space: normal;
}

.text-node.markdown-node p {
    margin: 0;
}

.text-node.markdown-node h1,
.text-node.markdown-node h2,
.text-node.markdown-node h3,
.text-node.markdown-node h4,
.text-node.markdown-node h5,
.text-node.markdown-node h6 {
    margin: 0;
    line-height: 1.3;
    font-weight: 700;
}

.text-node.markdown-node h1 {
    font-size: calc(1em + 6px);
}

.text-node.markdown-node h2 {
    font-size: calc(1em + 4px);
}

.text-node.markdown-node h3 {
    font-size: calc(1em + 2px);
}

.text-node.markdown-node h4,
.text-node.markdown-node h5,
.text-node.markdown-node h6 {
    font-size: 1em;
}

.text-node.markdown-node p + p,
.text-node.markdown-node p + h1,
.text-node.markdown-node p + h2,
.text-node.markdown-node p + h3,
.text-node.markdown-node p + h4,
.text-node.markdown-node p + h5,
.text-node.markdown-node p + h6,
.text-node.markdown-node p + ul,
.text-node.markdown-node p + ol,
.text-node.markdown-node h1 + p,
.text-node.markdown-node h2 + p,
.text-node.markdown-node h3 + p,
.text-node.markdown-node h4 + p,
.text-node.markdown-node h5 + p,
.text-node.markdown-node h6 + p,
.text-node.markdown-node h1 + ul,
.text-node.markdown-node h2 + ul,
.text-node.markdown-node h3 + ul,
.text-node.markdown-node h4 + ul,
.text-node.markdown-node h5 + ul,
.text-node.markdown-node h6 + ul,
.text-node.markdown-node h1 + ol,
.text-node.markdown-node h2 + ol,
.text-node.markdown-node h3 + ol,
.text-node.markdown-node h4 + ol,
.text-node.markdown-node h5 + ol,
.text-node.markdown-node h6 + ol,
.text-node.markdown-node h1 + h1,
.text-node.markdown-node h1 + h2,
.text-node.markdown-node h1 + h3,
.text-node.markdown-node h2 + h1,
.text-node.markdown-node h2 + h2,
.text-node.markdown-node h2 + h3,
.text-node.markdown-node h3 + h1,
.text-node.markdown-node h3 + h2,
.text-node.markdown-node h3 + h3,
.text-node.markdown-node ul + p,
.text-node.markdown-node ol + p,
.text-node.markdown-node ul + ul,
.text-node.markdown-node ol + ol {
    margin-top: 0.22em;
}

.text-node.markdown-node p + p {
    margin-top: 1em;
}

.text-node.markdown-node ul,
.text-node.markdown-node ol {
    margin: 0;
    padding-left: 1.25em;
}

.text-node.markdown-node li + li {
    margin-top: 0.1em;
}

.text-node.markdown-node a {
    color: var(--brand-color);
    text-decoration: underline;
    text-decoration-thickness: 1.5px;
    text-underline-offset: 2px;
    cursor: pointer;
}

.text-node.mermaid-node {
    min-height: 80px;
}

.text-node.mermaid-node .text-node-body {
    min-height: 80px;
}

.text-node.mermaid-node svg {
    display: block;
    max-width: 100%;
    height: auto;
}

.mermaid-loading {
    color: var(--ui-text-color);
    font-size: 13px;
    white-space: nowrap;
}

.text-resize-handle {
    position: absolute;
    right: -2px;
    bottom: -2px;
    width: 16px;
    height: 16px;
    opacity: 0;
    transition: opacity 0.15s ease;
    cursor: nwse-resize;
    touch-action: none;
}

.text-resize-handle::before {
    content: "";
    position: absolute;
    right: 3px;
    bottom: 3px;
    width: 8px;
    height: 8px;
    border-right: 2px solid rgba(128, 128, 128, 0.55);
    border-bottom: 2px solid rgba(128, 128, 128, 0.55);
    border-radius: 0 0 3px 0;
}

.text-node:hover .text-resize-handle,
.text-node:focus-within .text-resize-handle,
.text-node.resizing .text-resize-handle {
    opacity: 1;
}

.text-node.resizing,
.text-node.resizing * {
    cursor: nwse-resize !important;
    user-select: none;
}

.text-node.link-node {
    display: inline-flex;
    align-items: center;
    padding: 5px 12px;
    border-radius: 999px;
    background: var(--brand-color);
    color: #fff;
    border-color: transparent;
    box-shadow: var(--shadow);
    cursor: pointer;
    font-size: 14px;
    line-height: 1.2;
    white-space: nowrap;
    max-width: 420px;
}

.text-node.link-node:hover {
    border-color: transparent;
    box-shadow: 0 6px 16px rgba(0, 122, 255, 0.25);
}

.text-node.link-node:focus-within {
    background: var(--brand-color);
    box-shadow: var(--shadow);
}

.text-node.link-node .text-node-body {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 0;
    padding: 0;
    white-space: nowrap;
    user-select: none;
}

.text-node.link-node .text-resize-handle {
    display: none;
}

.link-node-url {
    color: inherit;
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 360px;
    display: inline-block;
    white-space: nowrap;
    vertical-align: middle;
    cursor: pointer;
    user-select: none;
    -webkit-user-drag: none;
}

.link-edit-btn {
    background: rgba(255, 255, 255, 0.18);
    border: none;
    color: inherit;
    cursor: pointer;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    opacity: 0;
    transition: opacity 0.15s ease, background 0.15s ease;
}

.text-node.link-node:hover .link-edit-btn,
.link-edit-btn:focus-visible {
    opacity: 1;
}

.link-edit-btn:hover {
    background: rgba(255, 255, 255, 0.32);
}

[data-eraser="true"] .text-node,
[data-eraser="true"] .text-node * {
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 48 48"><circle cx="24" cy="24" r="23" fill="none" stroke="black" stroke-width="2" stroke-dasharray="4,4"/><circle cx="24" cy="24" r="23" fill="none" stroke="white" stroke-width="2" stroke-dasharray="4,4" stroke-dashoffset="4"/></svg>') 24 24, crosshair !important;
}
