/* =====================================================================
   Code2Flow · style.css
   ===================================================================== */

:root {
  --bg: #0a0e14;
  --bg2: #0e131b;
  --panel: #111823;
  --panel2: #161f2b;
  --line: #1f2a37;
  --line2: #2b3a4c;
  --text: #e8eef6;
  --muted: #8ea1b8;
  --muted2: #61748a;
  --brand: #5eead4;
  --brand2: #4f8cff;
  --ok: #3fb950;
  --warn: #d29922;
  --err: #f85149;
  --dot: rgba(146, 176, 210, .10);
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, .45);
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, "SF Mono", Menlo, monospace;
  --sans: Inter, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
}

[data-theme="light"] {
  --bg: #eef2f8;
  --bg2: #f7f9fc;
  --panel: #ffffff;
  --panel2: #f4f7fb;
  --line: #dde5ef;
  --line2: #c8d4e2;
  --text: #1b2530;
  --muted: #5d6f85;
  --muted2: #8494a8;
  --dot: rgba(70, 100, 140, .16);
  --shadow: 0 18px 50px rgba(28, 45, 70, .16);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

/* 首帧统一切换主题时不要播放过渡，避免闪一下 */
html.no-anim * { transition: none !important; animation: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------- 顶栏 ------------------------------- */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  height: 60px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(94, 234, 212, .04), transparent 70%), var(--panel);
  position: relative;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { display: flex; filter: drop-shadow(0 4px 12px rgba(79, 140, 255, .28)); }
.brand-text h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: .2px;
  background: linear-gradient(92deg, var(--brand), var(--brand2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1.15;
}
.brand-text p { margin: 0; font-size: 11px; color: var(--muted2); letter-spacing: .3px; }

.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* ------------------------------ 控件 ------------------------------ */

.btn {
  appearance: none;
  border: 1px solid var(--line2);
  background: var(--panel2);
  color: var(--text);
  border-radius: 10px;
  padding: 7px 13px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .06s, color .15s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { border-color: var(--brand2); color: #fff; background: rgba(79, 140, 255, .12); }
[data-theme="light"] .btn:hover { color: #0a3d80; }
.btn:active { transform: translateY(1px); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 9px; }
.btn.icon { padding: 6px 10px; line-height: 1; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: rgba(255, 255, 255, .06); border-color: var(--line2); }
.btn.primary {
  border: 0;
  background: linear-gradient(96deg, #4f8cff, #5eead4);
  color: #06202b;
  font-weight: 800;
  box-shadow: 0 6px 18px rgba(79, 140, 255, .3);
}
.btn.primary:hover { filter: brightness(1.06); color: #06202b; }

kbd {
  font-family: var(--mono);
  font-size: 10.5px;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, .22);
  background: rgba(0, 0, 0, .18);
  font-weight: 700;
}

.select-wrap { position: relative; }
.select-wrap select {
  appearance: none;
  border: 1px solid var(--line2);
  background: var(--panel2);
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 7px 30px 7px 11px;
  border-radius: 10px;
  cursor: pointer;
  outline: none;
}
.select-wrap::after {
  content: "▾";
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  font-size: 10px;
  color: var(--muted);
}
.select-wrap select:hover { border-color: var(--brand2); }
.select-wrap option { background: var(--panel); color: var(--text); }

/* 视图切换（流程图 / N-S 图） */
.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: 10px;
  background: var(--panel2);
  border: 1px solid var(--line2);
  flex: 0 0 auto;
}
.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.seg button:hover { color: var(--text); }
.seg button.on {
  background: linear-gradient(96deg, #4f8cff, #5eead4);
  color: #06202b;
  box-shadow: 0 3px 12px rgba(79, 140, 255, .25);
}

/* --------------------------- 左右分栏 --------------------------- */

.workspace {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(340px, 40%) 1fr;
  min-height: 0;
}

.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.editor-pane { border-right: 1px solid var(--line); background: var(--panel); }
.canvas-pane { background: var(--bg2); }

.pane-head,
.pane-foot,
.canvas-foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  min-height: 46px;
}
.pane-head { border-bottom: 1px solid var(--line); background: var(--panel); }
.pane-foot { border-top: 1px solid var(--line); background: var(--panel); justify-content: space-between; }
.canvas-foot {
  border-top: 1px solid var(--line);
  color: var(--muted2);
  font-size: 12px;
  background: var(--panel);
  min-height: 34px;
}

.pane-title { font-weight: 700; font-size: 13px; letter-spacing: .3px; }
.pane-sub { color: var(--muted2); font-size: 12px; }
.spacer { flex: 1 1 auto; }

.tool-group {
  display: flex;
  align-items: center;
  gap: 5px;
  padding-left: 8px;
  margin-left: 4px;
  border-left: 1px solid var(--line);
}
.tool-group:first-of-type { border-left: 0; }
.zoom-label {
  min-width: 46px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.status { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status.err { color: var(--err); }
.status.ok { color: var(--ok); }

/* ------------------------------ 编辑器 ------------------------------ */

.editor-wrap { flex: 1 1 auto; display: flex; min-height: 0; position: relative; }

.gutter {
  flex: 0 0 auto;
  width: 50px;
  padding: 14px 8px 220px 0;
  text-align: right;
  font: 13px/22px var(--mono);
  color: var(--muted2);
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow: hidden;
  user-select: none;
  white-space: pre;
  font-variant-numeric: tabular-nums;
}

#code {
  flex: 1 1 auto;
  min-width: 0;
  padding: 14px 18px 60px 14px;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font: 13px/22px var(--mono);
  white-space: pre;
  overflow: auto;
  tab-size: 2;
  caret-color: var(--brand);
}
#code::placeholder { color: var(--muted2); opacity: .75; }
#code::-webkit-scrollbar,
.gutter::-webkit-scrollbar,
.modal-body::-webkit-scrollbar { width: 10px; height: 10px; }
#code::-webkit-scrollbar-thumb,
.gutter::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
  background: var(--line2);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: content-box;
}

/* ------------------------------ 画布 ------------------------------ */

.canvas-wrap {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
  cursor: grab;
  background-image:
    radial-gradient(circle at 1px 1px, var(--dot) 1px, transparent 0),
    radial-gradient(120% 90% at 50% 0%, rgba(79, 140, 255, .07), transparent 60%);
  background-size: 22px 22px, 100% 100%;
}
.canvas-wrap.dragging { cursor: grabbing; }
.canvas-wrap svg { width: 100%; height: 100%; display: block; }

/* 可点击节点：悬停发光，选中后保持高亮 */
.canvas-wrap g.fc-node { cursor: default; }
.canvas-wrap g.fc-node[data-line] { cursor: pointer; }
.canvas-wrap g.fc-node[data-line]:hover { filter: drop-shadow(0 0 7px rgba(79, 140, 255, .65)); }
.canvas-wrap g.fc-node.active { filter: drop-shadow(0 0 11px rgba(94, 234, 212, .85)); }

/* 跳到代码行时的一闪高亮条 */
.line-flash {
  position: absolute;
  left: 50px;
  right: 0;
  pointer-events: none;
  opacity: 0;
  border-left: 3px solid var(--brand2);
  border-radius: 0 5px 5px 0;
  background: linear-gradient(90deg, rgba(79, 140, 255, .30), rgba(94, 234, 212, .10) 70%, transparent);
  z-index: 3;
}
.line-flash.show { animation: lineFlash 1.5s ease-out forwards; }
@keyframes lineFlash { 0% { opacity: 1; } 65% { opacity: .8; } 100% { opacity: 0; } }

.empty-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--muted2);
  text-align: center;
  pointer-events: none;
  padding: 20px;
}
.empty-hint p { margin: 0; font-size: 13px; }
.empty-hint .muted { font-size: 12px; opacity: .8; }
.empty-icon {
  font-size: 40px;
  line-height: 1;
  color: var(--brand2);
  opacity: .5;
  margin-bottom: 6px;
}

/* ------------------------------ 弹层 ------------------------------ */

.popover {
  position: fixed;
  top: 66px;
  right: 16px;
  width: min(720px, calc(100vw - 32px));
  max-height: min(70vh, 620px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 60;
  overflow: hidden;
  animation: pop .16s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(-6px) scale(.99); } }

.popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.examples-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 8px;
  padding: 12px;
  overflow: auto;
}
.example-card {
  text-align: left;
  border: 1px solid var(--line2);
  background: var(--panel2);
  border-radius: 11px;
  padding: 10px 12px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  transition: border-color .15s, transform .1s, background .15s;
}
.example-card:hover {
  border-color: var(--brand2);
  background: rgba(79, 140, 255, .1);
  transform: translateY(-1px);
}
.example-card b { display: block; font-size: 13px; margin-bottom: 3px; }
.example-card span { display: block; font-size: 11.5px; color: var(--muted2); }
.example-card .tag {
  display: inline-block;
  margin-top: 7px;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 20px;
  background: rgba(94, 234, 212, .14);
  color: var(--brand);
  font-weight: 700;
  letter-spacing: .4px;
  font-style: normal;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 14, .66);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 80;
}
.modal-card {
  width: min(760px, 100%);
  max-height: min(86vh, 860px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line2);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: pop .18s ease-out;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 15px; font-weight: 800; }
.modal-body { padding: 6px 22px 26px; overflow: auto; line-height: 1.75; font-size: 13.5px; }
.modal-body h3 {
  margin: 22px 0 8px;
  font-size: 13.5px;
  color: var(--brand);
  letter-spacing: .3px;
}
.modal-body p { margin: 8px 0; color: var(--muted); }
.modal-body b { color: var(--text); }
.modal-body code {
  font-family: var(--mono);
  font-size: 12px;
  background: rgba(127, 160, 200, .14);
  padding: 1px 5px;
  border-radius: 5px;
  color: var(--text);
}
.steps { margin: 8px 0; padding-left: 20px; color: var(--muted); }
.steps li { margin: 7px 0; }
.faq { margin: 8px 0; padding-left: 18px; color: var(--muted); }
.faq li { margin: 6px 0; }

.tbl { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 12.5px; }
.tbl th, .tbl td {
  border: 1px solid var(--line);
  padding: 7px 10px;
  text-align: left;
  color: var(--muted);
  vertical-align: top;
}
.tbl th { background: var(--panel2); color: var(--text); font-weight: 700; }
.tbl code { font-size: 11.5px; }

/* ------------------------------ Toast ------------------------------ */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 20px);
  background: #0c1520;
  color: #eaf2ff;
  border: 1px solid var(--line2);
  padding: 9px 16px;
  border-radius: 11px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 200;
  max-width: 80vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: var(--err); }

/* ---------------------------- 响应式 ---------------------------- */

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: minmax(200px, 38%) 1fr; }
  .editor-pane { border-right: 0; border-bottom: 1px solid var(--line); }
  .pane-sub { display: none; }
  .brand-text p { display: none; }
  .topbar { gap: 8px; height: 54px; padding: 0 10px; }
  .btn { padding: 6px 10px; font-size: 12px; }
  .tool-group { padding-left: 4px; }
  .zoom-label { min-width: 40px; }
  .pane { overflow: hidden; }
  .pane-head { flex-wrap: wrap; row-gap: 6px; padding: 8px 10px; }
  .pane-title { white-space: nowrap; flex: 0 0 auto; }
  .pane-foot { padding: 8px 10px; }
  .canvas-foot { font-size: 11px; padding: 6px 10px; }
  .canvas-foot .muted { display: none; }
}
@media (max-width: 620px) {
  .top-actions .btn:not(.icon) { display: none; }
  .pane-head .tool-group { border-left: 0; padding-left: 0; margin-left: 0; }
  .btn.sm { padding: 4px 8px; font-size: 11.5px; }
  .pane-foot kbd { display: none; }
  .pane-foot .status { font-size: 11px; }
}
