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

:root {
    --bg: #111214;
    --surface: #191b1f;
    --surface-hover: #1f2228;
    --border: #2a2d35;
    --border-light: #353941;
    --text: #f0f2f5;
    --text-dim: #9aa1ad;
    --text-muted: #666c78;
    --pink: #f472b6;
    --pink-soft: rgba(244,114,182,.1);
    --pink-border: rgba(244,114,182,.28);
    --blue: #60a5fa;
    --blue-soft: rgba(96,165,250,.1);
    --blue-border: rgba(96,165,250,.28);
    --radius: 10px;
    --ease: cubic-bezier(.25,.46,.45,.94);
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
font-family: Roboto, 'Noto Sans SC', 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
}

a, a:link, a:visited, a:hover, a:active {
    text-decoration: none;
    color: inherit;
}

button, textarea { font-family: inherit; }

/* ============================================================
   顶部工具条
   ============================================================ */
.toolbar {
    flex: 0 0 auto;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    padding: 0.3rem 1.25rem;
    background: rgba(17,18,20,.94);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 100;
    box-sizing: border-box;
    flex-wrap: wrap;
    row-gap: 0.5rem;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.2rem 0.45rem ;
    flex-wrap: wrap;
    min-width: 0;
}

.tb-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    height: 34px;
    padding: 0rem 0.85rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-dim);
    font-size: 0.76rem;
    font-weight: 500;
    cursor: pointer;
    transition: border-color .28s var(--ease), color .28s var(--ease),
        background .28s var(--ease), transform .15s var(--ease);
    white-space: nowrap;
    flex-shrink: 0;
}

.tb-btn:hover {
    background: var(--surface-hover);
    border-color: var(--border-light);
    color: var(--text);
}

.tb-btn:active { transform: scale(.96); }

.tb-btn.primary {
    background: var(--blue-soft);
    border-color: var(--blue-border);
    color: var(--blue);
}

.tb-btn.primary:hover { background: rgba(96,165,250,.18); }

.tb-btn.accent {
    background: var(--pink-soft);
    border-color: var(--pink-border);
    color: var(--pink);
}

.tb-btn.accent:hover { background: rgba(244,114,182,.18); }

/* ============================================================
   编辑区滚动容器
   ============================================================ */
.editor-scroll {
    flex: 1 1 auto;
    width: 100%;
    overflow: auto;
    position: relative;
    min-height: 0;
}

.editor-wrap {
    display: inline-block;
    min-width: 100%;
    padding: 2rem 2.5rem 6rem;
    vertical-align: top;
    box-sizing: border-box;
}

.map {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-width: 100%;
}

/* ---------- 节点 ---------- */
.node {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    width: 90vw;
    max-width: 90vw;
    flex-shrink: 0;
}

/* ============================================================
   节点主体：网格两行布局
   第一行：展开按钮 + 输入框
   第二行：操作按钮组（跨整行）
   ============================================================ */
.node-main {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    align-items: start;
    gap: 0.35rem 0.5rem;
    width: 100%;
}

.toggle-btn {
    grid-column: 1;
    grid-row: 1;
    flex-shrink: 0;
    align-self: flex-start;
    margin-top: 10px;
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.7rem;
    cursor: pointer;
    border-radius: 6px;
    transition: color .25s, background .25s, transform .25s var(--ease);
}

.toggle-btn:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.toggle-btn.collapsed { transform: rotate(-90deg); }

.toggle-btn.placeholder {
    visibility: hidden;
    pointer-events: none;
}

.fields {
    grid-column: 2;
    grid-row: 1;
    flex: 1;
    min-width: 0;
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
    justify-content: flex-start;
}

/* ============================================================
   输入框配色
   ============================================================ */
.field {
    flex: 0 1 auto;
    width: max-content;
    min-width: 10%;
    max-width: 45%;
    display: flex;
    align-items: flex-start;
    padding: 0.5rem 0.85rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    transition: border-color .28s var(--ease), background .28s var(--ease),
        box-shadow .28s var(--ease), color .28s var(--ease);
    position: relative;
    box-sizing: border-box;
}

.field.left {
    background: #bfdbfe;
    color: #111214;
}

.field.right {
    background: #fbcfe8;
    color: #111214;
    font-style: italic;
}

.field.left:hover { background: #93c5fd; }
.field.right:hover { background: #f9a8d4; }

.field.left:focus-within {
    background: #dbeafe;
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px rgba(96,165,250,.25);
}

.field.right:focus-within {
    background: #fce7f3;
    border-color: #f472b6;
    box-shadow: 0 0 0 3px rgba(244,114,182,.25);
}

.field textarea {
    width: 100%;
    min-height: 24px;
    border: none;
    outline: none;
    background: transparent;
    color: inherit;
    font-size: 0.84rem;
    font-family: inherit;
    font-style: inherit;
    line-height: 1.5;
    padding-left: 0.5rem;
    resize: none;
    overflow: hidden;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: break-word;
    field-sizing: content;
}

.field textarea::placeholder {
    color: rgba(17,18,20,.45);
    font-size: 0.78rem;
    font-style: normal;
}

/* ============================================================
   节点操作按钮组（默认隐藏，选中或悬停时显示）
   占网格第二行，跨两列
   ============================================================ */
.node-actions {
    grid-column: 1 / -1;
    grid-row: 2;
    display: none;
    align-items: center;
    gap: 0.3rem;
    padding-left: 2rem;
    opacity: 0.4;
    transition: opacity .25s var(--ease);
}

/* 悬停或焦点在节点内时显示按钮 */
.node:hover .node-actions,
.node:focus-within .node-actions {
    display: flex;
    opacity: 1;
}

/* 节点主体被选中时显示按钮 */
/* 选中时显示按钮 */
.node-main.selected .node-actions {
    display: flex !important;
    opacity: 1;
    flex-basis: 100%;         /* 占满整行，强制换行到输入框下方 */
    padding-left: 2rem;       /* 与输入框左侧视觉对齐（保留你原来的缩进感） */
}

.mini-btn {
    height: 24px;
    min-width: 26px;
    padding: 0 0.45rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: 1px solid transparent;
    color: #111214;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: filter .2s, transform .12s;
    white-space: nowrap;
}

.mini-btn:active { transform: scale(.94); }
.mini-btn:hover { filter: brightness(0.94); }

/* 各按钮配色 */
.mini-btn.btn-s   { background: #bfdbfe; }
.mini-btn.btn-f   { background: #fbcfe8; }
.mini-btn.btn-up  { background: #f3f4f6; }
.mini-btn.btn-down{ background: #f3f4f6; }
.mini-btn.btn-add-sibling { background: #d1fae5; } /* 更浅的绿（原 #bbf7d0 加深反而变深，改用淡薄荷绿） */
.mini-btn.btn-add-child   { background: #a7f3d0; } /* 略深的绿，与 sibling 只差一档 */
.mini-btn.btn-cut { background: #fef08a; }
.mini-btn.btn-clone       { background: #ddd6fe; } /* 淡紫，避开黄/红，与绿系区分 */
.mini-btn.btn-delete { background: #fca5a5; }

/* ============================================================
   子节点容器
   ============================================================ */
.children {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-left: 2.2rem;
    padding-left: 1rem;
    overflow: visible;
}

.children.collapsed { display: none; }

.node.collapsed > [data-children] {
    display: none;
}

/* ============================================================
   输入框内联编辑按钮（确定/取消）
   ============================================================ */
.field {
    display: flex;
    flex-direction: column;
}

.edit-actions {
    display: none;
    gap: 4px;
    margin-top: 4px;
}

.field textarea:not([readonly]) ~ .edit-actions {
    display: flex;
}

/* ============================================================
   左下角常驻悬浮按钮
   ============================================================ */
.screen-toggle {
    position: fixed;
    left: 20px;
    bottom: 20px;
    z-index: 200;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid var(--border-light);
    background: var(--surface);
    color: var(--text-dim);
    font-size: 1.05rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0,0,0,.4);
    transition: color .25s var(--ease), border-color .25s var(--ease),
        background .25s var(--ease), transform .15s var(--ease);
}

.screen-toggle:hover {
    color: var(--blue);
    border-color: var(--blue-border);
    background: var(--blue-soft);
    transform: translateY(-2px);
}

.screen-toggle:active { transform: scale(.94); }

.editor-scroll::-webkit-scrollbar { width: 10px; height: 10px; }
.editor-scroll::-webkit-scrollbar-track { background: transparent; }
.editor-scroll::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 8px;
    border: 2px solid var(--bg);
}
.editor-scroll::-webkit-scrollbar-thumb:hover { background: #444a55; }

@media (max-width: 640px) {
    .toolbar { padding: 0.1rem 0.3rem; }
    .tb-btn { height: 32px; font-size: 0.72rem; padding: 0 0.3rem; }
    .editor-wrap { padding: 1.25rem 1rem 6rem; }
    .children { margin-left: 1.2rem; padding-left: 0.7rem; }
    .field { min-width: 10%; max-width: 50%; }
    .screen-toggle { width: 40px; height: 40px; left: 14px; bottom: 14px; }
}