/* 画布 · Glass Noir 深色创作工具 */
:root {
  --bg: #0F0E0E;
  --panel: #141414;
  --card: #1A1A1A;
  --input: #1E1E1E;
  --hover: #2A2A2A;
  --border: #262626;
  --text: #F0F0F0;
  --text-2: #A0A0A0;
  --gold: #E8C268;
  --teal: #5BCFC5;
  --danger: #FF6B6B;
  --font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; color: var(--text); }
svg { display: block; }
.mono { font-family: var(--mono); }
[hidden] { display: none !important; }

#app { display: flex; flex-direction: column; height: 100vh; }

/* ---------- 顶部工具栏 ---------- */
#topbar {
  height: 52px; flex: 0 0 52px;
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--gold); }
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: .02em; }
.file-area { display: flex; align-items: center; gap: 4px; padding: 0 4px; }
.file-name {
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  font-size: 13px; font-weight: 500; color: var(--text);
  padding: 5px 8px; width: 150px; outline: none;
}
.file-name:hover { background: var(--input); }
.file-name:focus { background: var(--input); border-color: var(--gold); }
.icon-btn {
  width: 28px; height: 28px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2); transition: background .15s, color .15s;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
#star-btn.starred { color: var(--gold); }
#star-btn.starred svg path { fill: var(--gold); }
.share-btn {
  background: var(--gold); color: #0F0E0E;
  font-size: 12px; font-weight: 600;
  padding: 7px 14px; border-radius: 8px;
  transition: filter .15s, transform .1s;
}
.share-btn:hover { filter: brightness(1.08); }
.share-btn:active { transform: scale(.96); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.save-state { font-size: 11px; color: var(--text-2); }
.save-state.dirty { color: var(--gold); }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--hover); overflow: hidden; }
.avatar svg { width: 28px; height: 28px; }

/* ---------- 主体布局 ---------- */
#main { flex: 1; display: flex; min-height: 0; }

/* ---------- 左侧工具面板 ---------- */
#toolbar {
  width: 52px; flex: 0 0 52px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center;
  padding: 12px 0; gap: 10px;
  z-index: 20;
}
.tool {
  width: 32px; height: 32px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2);
  transition: background .15s, color .15s;
}
.tool svg { width: 20px; height: 20px; }
.tool:hover { background: var(--hover); color: var(--text); }
.tool.active { background: var(--gold); color: #0F0E0E; }
.toolbar-spacer { flex: 1; }
.tool-ai { background: var(--hover); color: var(--gold); border-radius: 50%; }
.tool-ai:hover { background: #3a3a3a; color: var(--gold); }

/* ---------- 画布 ---------- */
#canvas-wrap {
  position: relative; flex: 1; min-width: 0;
  background: var(--bg);
  overflow: hidden;
  cursor: default;
}
#canvas-wrap.panning { cursor: grab; }
#canvas-wrap.panning:active { cursor: grabbing; }
#canvas-wrap.creating { cursor: crosshair; }
#canvas-wrap.drawing { cursor: crosshair; }

#viewport {
  position: absolute; top: 0; left: 0;
  width: 0; height: 0;
  transform-origin: 0 0;
}
#links { position: absolute; top: 0; left: 0; pointer-events: none; }
#links path { fill: none; stroke: #4a4a4a; stroke-width: 2; }
#links circle { fill: #6a6a6a; }

/* 节点通用 */
.node {
  position: absolute;
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  user-select: none;
  transition: box-shadow .15s;
}
.node.selected { outline: 2px solid var(--gold); outline-offset: 3px; }
.node.dragging { box-shadow: 0 16px 48px rgba(0,0,0,.65); }
.node .thumb {
  width: 100%; border-radius: inherit;
  border-bottom-left-radius: 0; border-bottom-right-radius: 0;
  position: relative; overflow: hidden;
}
.node .play-btn {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);
  width: 38px; height: 38px; border-radius: 50%;
  background: rgba(0,0,0,.55); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, transform .15s;
}
.node .play-btn svg { width: 20px; height: 20px; }
.node .play-btn:hover { background: rgba(0,0,0,.8); transform: translate(-50%,-50%) scale(1.08); }
.node .card-body { padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.node .card-title { font-size: 14px; font-weight: 600; color: var(--text); line-height: 1.4; }
.node .card-meta { display: flex; align-items: center; gap: 6px; }
.node .card-author { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node .like-box {
  margin-left: auto; display: flex; align-items: center; gap: 4px;
  color: var(--text-2); font-size: 12px; padding: 2px 4px; border-radius: 5px;
}
.node .like-box svg { width: 12px; height: 12px; }
.node .like-box:hover { background: rgba(255,255,255,.08); }
.node .like-box.liked { color: var(--gold); }
.node .like-box.liked svg path { fill: var(--gold); }

/* 视频 / 图片卡片布局 */
.node-video, .node-image { display: flex; flex-direction: column; overflow: hidden; }
.node .thumb.playing { background-size: 220% 220% !important; animation: thumb-pan 5s ease-in-out infinite alternate; }
@keyframes thumb-pan { from { background-position: 0% 0%; } to { background-position: 100% 100%; } }

/* 便签 */
.node-note { background: var(--gold); padding: 14px; }
.node-note .note-content {
  color: #0F0E0E; font-size: 13px; font-weight: 500; line-height: 22px;
  white-space: pre-wrap; word-break: break-word; outline: none; height: 100%;
}
/* 文本节点 */
.node-text { background: transparent; box-shadow: none; padding: 4px; }
.node-text .text-content { font-weight: 700; line-height: 1.35; white-space: pre-wrap; word-break: break-word; outline: none; }
.node-text.selected { outline: 1.5px dashed var(--gold); outline-offset: 4px; }
/* 图片卡片 */
.node-image .img-label { padding: 10px; font-size: 12px; font-weight: 500; }
/* 形状 */
.node-shape { box-shadow: 0 4px 16px rgba(0,0,0,.35); }
/* 评论 */
.node-comment {
  background: #20242c; border: 1px solid #33405a; border-radius: 10px;
  padding: 10px 12px; display: flex; gap: 8px; align-items: flex-start;
}
.node-comment .comment-icon { width: 16px; height: 16px; color: var(--teal); flex: 0 0 16px; margin-top: 2px; }
.node-comment .comment-text { font-size: 12px; line-height: 1.6; color: var(--text); outline: none; white-space: pre-wrap; word-break: break-word; }
/* 画笔 */
.draw-path { fill: none; stroke-linecap: round; stroke-linejoin: round; }

[contenteditable="true"] { cursor: text; user-select: text; }

/* 空状态提示 */
.empty-tip {
  position: absolute; top: 24px; left: 50%; transform: translateX(-50%);
  background: var(--card); border: 1px solid var(--border);
  color: var(--text-2); font-size: 12px; padding: 10px 16px; border-radius: 8px;
  pointer-events: none;
}

/* 小地图 */
#minimap {
  position: absolute; right: 20px; bottom: 152px;
  width: 140px; height: 90px;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,.5);
  overflow: hidden; cursor: crosshair; z-index: 10;
}
#minimap-world { position: absolute; inset: 0; }
.mm-node { position: absolute; border-radius: 2px; }
#minimap-view {
  position: absolute; border: 1.5px solid var(--gold);
  background: rgba(232,194,104,.08); border-radius: 2px; pointer-events: none;
}

/* 缩放控件 */
#zoom-ctrl {
  position: absolute; right: 20px; bottom: 20px;
  width: 40px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 4px 0; box-shadow: 0 4px 12px rgba(0,0,0,.5); z-index: 10;
}
.zoom-btn {
  width: 30px; height: 28px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center; color: var(--text);
}
.zoom-btn svg { width: 18px; height: 18px; }
.zoom-btn:hover { background: var(--hover); }
.zoom-pct { font-size: 11px; font-weight: 500; color: var(--text); padding: 4px 0; width: 100%; font-family: var(--mono); }
.zoom-pct:hover { color: var(--gold); }

#canvas-hint {
  position: absolute; left: 16px; bottom: 16px;
  font-size: 11px; color: #5a5a5a; pointer-events: none;
}

/* ---------- 右侧属性面板 ---------- */
#inspector {
  width: 248px; flex: 0 0 248px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  padding: 16px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px;
  z-index: 20;
}
#inspector::-webkit-scrollbar { width: 6px; }
#inspector::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
.panel-header { display: flex; align-items: center; justify-content: space-between; }
.tabs { display: flex; gap: 4px; padding: 3px; background: var(--input); border-radius: 6px; }
.tab { padding: 6px 12px; border-radius: 5px; font-size: 12px; font-weight: 500; color: var(--text-2); }
.tab.active { background: var(--hover); color: var(--text); font-weight: 600; }
.group-title { font-size: 11px; font-weight: 600; color: var(--text-2); margin: 14px 0 8px; }
.sel-type { font-size: 12px; color: var(--gold); font-weight: 600; margin-top: 4px; }

.field-row { display: flex; gap: 8px; margin-bottom: 8px; }
.field {
  flex: 1; display: flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 10px;
  background: var(--input); border: 1px solid transparent; border-radius: 6px;
}
.field:focus-within { border-color: var(--gold); }
.field span { font-size: 11px; font-weight: 500; color: var(--text-2); }
.field input {
  width: 100%; min-width: 0; background: none; border: none; outline: none;
  font-family: var(--mono); font-size: 12px; text-align: right;
  -moz-appearance: textfield; appearance: textfield;
}
.field input::-webkit-outer-spin-button, .field input::-webkit-inner-spin-button { -webkit-appearance: none; }

.fill-row { display: flex; align-items: center; gap: 8px; }
.swatch {
  position: relative; width: 32px; height: 32px; flex: 0 0 32px;
  border: 1px solid #4d4d4d; border-radius: 6px; overflow: hidden; cursor: pointer;
}
.swatch input { position: absolute; inset: -8px; opacity: 0; cursor: pointer; }
#swatch-preview { position: absolute; inset: 3px; border-radius: 4px; background: var(--card); pointer-events: none; }
.hex-input {
  flex: 1; min-width: 0; height: 32px; padding: 0 10px;
  background: var(--input); border: 1px solid transparent; border-radius: 6px;
  font-family: var(--mono); font-size: 12px; outline: none;
}
.hex-input:focus { border-color: var(--gold); }
.opacity-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 12px; color: var(--text-2); }
.opacity-row input[type="range"] { flex: 1; min-width: 0; accent-color: var(--gold); height: 3px; cursor: pointer; }
#opacity-val { font-size: 11px; color: var(--text); width: 38px; text-align: right; }

#f-content {
  width: 100%; resize: vertical; min-height: 60px;
  background: var(--input); border: 1px solid transparent; border-radius: 6px;
  padding: 8px 10px; font-size: 12px; line-height: 1.6; outline: none;
}
#f-content:focus { border-color: var(--gold); }

.delete-area { margin-top: 22px; }
.delete-btn {
  width: 100%; height: 36px; border-radius: 6px;
  background: #2A1A1A; border: 1px solid #663333;
  color: var(--danger); font-size: 12px; font-weight: 500;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .15s;
}
.delete-btn svg { width: 14px; height: 14px; }
.delete-btn:hover { background: #3a2020; }

.inspector-empty { padding-top: 12px; }
.empty-title { font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 8px; }
.empty-desc { font-size: 12px; line-height: 1.7; color: #6a6a6a; }
.empty-shortcuts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 16px; }
.empty-shortcuts span {
  font-size: 10px; font-family: var(--mono); color: var(--text-2);
  background: var(--input); padding: 4px 7px; border-radius: 4px;
}

.proto-desc { font-size: 12px; line-height: 1.7; color: var(--text-2); margin-bottom: 12px; }
.secondary-btn {
  width: 100%; height: 34px; border-radius: 6px; margin-bottom: 12px;
  background: var(--input); border: 1px solid var(--border);
  font-size: 12px; font-weight: 500; color: var(--text);
}
.secondary-btn:hover { background: var(--hover); }
.secondary-btn.on { background: var(--gold); color: #0F0E0E; border-color: var(--gold); }

/* Toast & 预览 */
#toast {
  position: fixed; left: 50%; bottom: 40px; transform: translate(-50%, 12px);
  background: #262626; border: 1px solid #3a3a3a; color: var(--text);
  font-size: 13px; padding: 10px 18px; border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  z-index: 100; max-width: 70vw;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#preview-badge {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%);
  background: var(--gold); color: #0F0E0E; font-size: 12px; font-weight: 600;
  padding: 6px 14px; border-radius: 20px; z-index: 50;
}
body.preview-mode .node { pointer-events: none; }
body.preview-mode .node .play-btn { pointer-events: auto; }
body.preview-mode #inspector, body.preview-mode #toolbar { opacity: .45; pointer-events: none; }

/* 窄屏适配 */
@media (max-width: 900px) {
  #inspector { display: none; }
  .file-name { width: 100px; }
  #canvas-hint { display: none; }
}
