/* 规划图 · 外观。照 TokenLens 默认主题「石墨工作台」：冷灰表面、细边界、小圆角、少量强调色，跟随系统浅色 / 深色。
   强调色可以换（五种，和 TokenLens 一样），选中、在做和计划的状态、链路图的「›」、按钮都跟着变；状态的绿色、危险的红色不变。 */

:root {
  color-scheme: light;
  --font-ui: "Segoe UI Variable Text", "Segoe UI", -apple-system, "PingFang SC", "Source Han Sans SC", "Noto Sans SC",
    "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif;
  --font-number: "Bahnschrift", "Segoe UI Variable Display", "Segoe UI", -apple-system, system-ui, sans-serif;

  --surface-page: #eceeef;
  --surface-window: #f5f6f7;
  --surface-chrome: #f3f5f6;
  --surface-card: #f9fafb;
  --surface-card-strong: #ffffff;
  --surface-inset: #f0f2f3;
  --surface-raised: #ffffff;
  --surface-tooltip: #ffffff;
  --surface-backdrop: rgba(15, 23, 42, 0.42);
  --surface-control-hover: #e6e9ea;
  --surface-nav-hover: #e9edef;

  --text-primary: #23282d;
  --text-secondary: #454c52;
  --text-muted: #6b7278;
  --text-faint: #99a1a7;
  --text-on-accent: #ffffff;

  --border: rgba(35, 40, 45, 0.14);
  --border-subtle: rgba(35, 40, 45, 0.08);
  --border-strong: rgba(35, 40, 45, 0.24);
  --dash: rgba(35, 40, 45, 0.34);
  --wire: #8d959b;

  --accent: #0e7c82;
  --accent-hover: #0a6165;
  --accent-soft: rgba(14, 124, 130, 0.08);
  --accent-border: rgba(14, 124, 130, 0.38);
  /* 选中时很淡的一层主题色，由当前主题色换算，换颜色、换深浅色都是同一个比例 */
  --accent-selected-bg: color-mix(in srgb, var(--accent) 5%, transparent);
  /* 可以选的强调色，和 TokenLens 一样 */
  --accent-choice-teal: #0e7c82;
  --accent-choice-indigo: #4b58b8;
  --accent-choice-violet: #6e4fb3;
  --accent-choice-rose: #a83f63;
  --accent-choice-graphite: #465159;

  --tone-success: #2f9e63;
  --tone-warning: #c8961e;
  --tone-warning-text: #7d5c0d;
  --tone-danger: #cd4b3c;
  --tone-danger-text: #96352b;
  --tone-danger-bg: rgba(205, 75, 60, 0.1);
  --tone-danger-border: rgba(205, 75, 60, 0.3);

  --grid-dot: rgba(35, 40, 45, 0.13);
  --focus-ring: 0 0 0 1px rgba(14, 124, 130, 0.4);
  --shadow-card-soft: 0 1px 3px rgba(35, 40, 45, 0.08);
  --shadow-thumb: 0 1px 3px rgba(35, 40, 45, 0.16);
  --shadow-raised: 0 12px 32px rgba(35, 40, 45, 0.14);
  --shadow-transient: 0 2px 4px rgba(35, 40, 45, 0.1);
  --shadow-lift: 0 10px 24px rgba(35, 40, 45, 0.16);

  --radius-card: 6px;
  --radius-control: 5px;
  --radius-small: 3px;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --ease-page: cubic-bezier(0.4, 0, 0.2, 1);
  --module-w: 264px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-page: #17191c;
    --surface-window: #1a1d20;
    --surface-chrome: #1b1e21;
    --surface-card: #1e2124;
    --surface-card-strong: #24282b;
    --surface-inset: #191c1f;
    --surface-raised: #262a2d;
    --surface-tooltip: #262a2d;
    --surface-control-hover: #262a2d;
    --surface-nav-hover: #24282c;

    --text-primary: #e6e9eb;
    --text-secondary: #b9bfc4;
    --text-muted: #9aa1a7;
    --text-faint: #6d757c;
    --text-on-accent: #0f1518;

    --border: #33383c;
    --border-subtle: #2a2e32;
    --border-strong: #454c52;
    --dash: #5a6268;
    --wire: #737c83;

    --accent: #5bc6cc;
    --accent-hover: #79d2d7;
    --accent-soft: #16333a;
    --accent-border: #2f6b70;
    --accent-choice-teal: #5bc6cc;
    --accent-choice-indigo: #8f9bf0;
    --accent-choice-violet: #b49ae8;
    --accent-choice-rose: #df86a3;
    --accent-choice-graphite: #aeb8bf;

    --tone-success: #57b87f;
    --tone-warning: #d9a23c;
    --tone-warning-text: #e2bc6b;
    --tone-danger: #e06052;
    --tone-danger-text: #ef9086;
    --tone-danger-bg: #3a211d;
    --tone-danger-border: #643229;

    --grid-dot: rgba(230, 233, 235, 0.08);
    --focus-ring: 0 0 0 1px rgba(91, 198, 204, 0.4);
    --shadow-raised: none;
    --shadow-transient: none;
    --shadow-lift: 0 10px 28px rgba(0, 0, 0, 0.45);
  }
}

/* 换强调色：数值和 TokenLens 一样（青绿是默认，不用另写）。只换操作和选择用的颜色，状态的含义不变 */
:root[data-accent="indigo"] {
  --accent: #4b58b8;
  --accent-hover: #39469c;
  --accent-soft: rgba(75, 88, 184, 0.09);
  --accent-border: rgba(75, 88, 184, 0.38);
  --focus-ring: 0 0 0 1px rgba(75, 88, 184, 0.4);
}

:root[data-accent="violet"] {
  --accent: #6e4fb3;
  --accent-hover: #563a96;
  --accent-soft: rgba(110, 79, 179, 0.09);
  --accent-border: rgba(110, 79, 179, 0.38);
  --focus-ring: 0 0 0 1px rgba(110, 79, 179, 0.4);
}

:root[data-accent="rose"] {
  --accent: #a83f63;
  --accent-hover: #87314f;
  --accent-soft: rgba(168, 63, 99, 0.09);
  --accent-border: rgba(168, 63, 99, 0.38);
  --focus-ring: 0 0 0 1px rgba(168, 63, 99, 0.4);
}

:root[data-accent="graphite"] {
  --accent: #465159;
  --accent-hover: #303940;
  --accent-soft: rgba(70, 81, 89, 0.09);
  --accent-border: rgba(70, 81, 89, 0.4);
  --focus-ring: 0 0 0 1px rgba(70, 81, 89, 0.4);
}

@media (prefers-color-scheme: dark) {
  :root[data-accent="indigo"] {
    --accent: #8f9bf0;
    --accent-hover: #aab3f5;
    --accent-soft: #252a4a;
    --accent-border: #59639d;
    --focus-ring: 0 0 0 1px rgba(143, 155, 240, 0.4);
  }

  :root[data-accent="violet"] {
    --accent: #b49ae8;
    --accent-hover: #c6b2ed;
    --accent-soft: #332845;
    --accent-border: #725d94;
    --focus-ring: 0 0 0 1px rgba(180, 154, 232, 0.4);
  }

  :root[data-accent="rose"] {
    --accent: #df86a3;
    --accent-hover: #e7a0b7;
    --accent-soft: #422632;
    --accent-border: #8b5266;
    --focus-ring: 0 0 0 1px rgba(223, 134, 163, 0.4);
  }

  :root[data-accent="graphite"] {
    --accent: #aeb8bf;
    --accent-hover: #c2c9ce;
    --accent-soft: #2a3034;
    --accent-border: #5d676e;
    --focus-ring: 0 0 0 1px rgba(174, 184, 191, 0.4);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--surface-page);
  color: var(--text-primary);
  font: 13px/19px var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

[hidden] {
  display: none !important;
}

.ic {
  flex: none;
  display: block;
}

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

/* ----- 顶栏：左上角标记、图表标签和「＋」；右边同步状态、撤销重做、「⋯」 ----- */
.bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  height: calc(48px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(10px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  background: var(--surface-chrome);
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-control);
  background: var(--accent);
  color: var(--text-on-accent);
  transition: background-color 240ms var(--ease);
}

.crumbs {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
}

.tabs {
  position: relative;
  flex: 0 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 3px 2px;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab-list {
  position: relative;
  display: flex;
  align-items: center;
  gap: 2px;
  width: max-content;
}

/* 当前标签下面那块白底：凸起一点，切换时滑过去 */
.tab-ind {
  position: absolute;
  left: 2px;
  top: 3px;
  width: var(--w, 0);
  height: 30px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-control);
  background: var(--surface-card-strong);
  box-shadow: var(--shadow-thumb);
  transform: translateX(var(--x, 0));
  pointer-events: none;
  transition: transform 240ms var(--ease-page), width 240ms var(--ease-page);
}

.tab-ind.still {
  transition: none;
}

.tab {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  height: 30px;
  max-width: 240px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color 180ms var(--ease), color 180ms var(--ease), transform 180ms var(--ease);
}

.tab-label {
  min-width: 1em;
  overflow: hidden;
  text-overflow: ellipsis;
  outline: none;
}

.tab:not(.is-active):hover {
  background: var(--surface-nav-hover);
  color: var(--text-primary);
}

.tab:active:not(.editing) {
  transform: scale(0.975);
}

.tab.is-active {
  color: var(--text-primary);
  font-weight: 600;
}

/* 改名：还是这个标签，字和留白不变，只多一圈主题色细框和光标 */
.tab.editing {
  cursor: text;
  border-color: var(--accent);
  border-radius: var(--radius-control);
}

.tab.editing .tab-label {
  overflow: visible;
  text-overflow: clip;
  user-select: text;
  -webkit-user-select: text;
  caret-color: var(--accent);
}

.tab-add {
  flex: none;
}

.bar-tools {
  flex: none;
  display: flex;
  align-items: center;
  gap: 2px;
}

.bar-sep {
  width: 1px;
  height: 18px;
  margin: 0 6px;
  background: var(--border);
}

.sync {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: none;
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
  cursor: default;
}

.sync[data-state="offline"],
.sync[data-state="error"] {
  color: var(--tone-warning-text);
}

.sync[data-state="auth"] {
  color: var(--accent);
  font-weight: 500;
  cursor: pointer;
}

.sync[data-state="auth"]:hover {
  background: var(--accent-soft);
}

/* 有没保存的改动：同步状态变成「保存」按钮 */
.sync[data-state="unsaved"] {
  color: var(--accent);
  font-weight: 500;
  border-color: var(--accent-border);
  cursor: pointer;
}

.sync[data-state="unsaved"]:hover {
  background: var(--accent-soft);
}

/* 图标按钮：和 TokenLens 一样，悬停灰底淡框，按下缩一点 */
.ib {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color 180ms var(--ease), border-color 180ms var(--ease), color 180ms var(--ease), transform 180ms var(--ease);
}

.ib.sm {
  width: 28px;
  height: 28px;
}

.ib:hover:not(:disabled),
.ib[aria-expanded="true"] {
  background: var(--surface-control-hover);
  border-color: var(--border-subtle);
  color: var(--text-primary);
}

.ib:active:not(:disabled) {
  transform: scale(0.92);
}

.ib:disabled {
  opacity: 0.55;
  cursor: default;
}

/* ----- 画布 ----- */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
}

.canvas {
  position: absolute;
  inset: 0;
  overflow: hidden;
  outline: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  background-color: var(--surface-page);
}

/* 点阵：比画布大一格，平移时只挪这一层（见 view.js 的 applyCamera） */
.grid {
  position: absolute;
  left: 0;
  top: 0;
  right: -64px;
  bottom: -64px;
  background-image: radial-gradient(circle, var(--grid-dot) 1px, transparent 1.3px);
  background-size: 24px 24px;
  pointer-events: none;
  will-change: transform;
}

/* 画布正在平移缩放：画布那一层交给显卡挪，不每帧重画；停下后去掉，按新的比例重画一次 */
.canvas.moving .world {
  will-change: transform;
}

/* 拖边改大小：鼠标停在能改大小的边上、正在改的时候，整块画布都用改大小的光标 */
.canvas[data-rz="e"],
.canvas[data-rz="e"] * {
  cursor: ew-resize !important;
}

.canvas[data-rz="s"],
.canvas[data-rz="s"] * {
  cursor: ns-resize !important;
}

.canvas[data-rz="se"],
.canvas[data-rz="se"] * {
  cursor: nwse-resize !important;
}

.canvas.is-panning,
.canvas.is-panning * {
  cursor: grabbing !important;
}

/* 按着空格：左键拖动是移动画布 */
.canvas.space-pan,
.canvas.space-pan * {
  cursor: grab !important;
}

.world {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
}

/* 上下层次：分区的底 → 普通连线 → 卡片 → 展开的链路图 → 连到链路图里的线 → 线上的字。
   块那一层不单独成一层（不设 z-index），这样卡片能盖在线上面、分区的底又在线下面：线从卡片底下穿过，不挡字 */
.blocks,
.floats {
  position: absolute;
  left: 0;
  top: 0;
}

.blocks .blk[data-role="module"],
.blocks .blk[data-role="box"] {
  z-index: 2;
}

/* 展开的链路图总在最上面；正拖着的卡片在链路图下面、别的卡片上面 */
.floats {
  z-index: 3;
}

.links {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
  pointer-events: none;
  z-index: 1;
}

.links.over {
  z-index: 4;
}

.links path {
  fill: none;
  stroke-linejoin: round;
  stroke-linecap: round;
}

/* 连线：平时灰色细线；连着选中的块时、选中这条线时变成主题色 */
.links .arrow {
  stroke: var(--wire);
  stroke-width: 1.5;
  transition: stroke 180ms var(--ease);
}

.links .arrow.head {
  fill: var(--wire);
  stroke: none;
}

.links .arrow.on {
  stroke: var(--accent);
}

.links .arrow.sel {
  stroke: var(--accent);
  stroke-width: 2.25;
}

.links .head.on,
.links .head.sel {
  fill: var(--accent);
}

/* 展开的链路图和挂着的地方之间的细线（虚线只留给对齐线） */
.links .tether {
  stroke: var(--accent-border);
  stroke-width: 1.25;
}

/* 正在连线时跟着指针的那条线：在所有东西上面 */
.links.preview {
  z-index: 7;
}

/* 线的可点范围比看到的线粗一些；按住拖，离按的地方近的那一头跟着走 */
.links .link-hit {
  stroke: transparent;
  stroke-width: calc(14px / var(--z, 1));
  pointer-events: stroke;
  cursor: pointer;
}

/* 线上的说明：线的正中间一个小胶囊。线太短时缩成一个小点，鼠标放上去才展开 */
.labels {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 5;
}

.lbl {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  align-items: center;
  max-width: 220px;
  height: 22px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-card-strong);
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 20px;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 180ms var(--ease), color 180ms var(--ease);
}

.lbl-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  outline: none;
}

.lbl:hover {
  z-index: 1;
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.lbl.on,
.lbl.sel {
  border-color: var(--accent);
  color: var(--accent);
}

.lbl.empty {
  display: none;
}

.lbl.short:not(:hover) {
  width: 10px;
  height: 10px;
  padding: 0;
  border-color: var(--surface-card-strong);
  background: var(--wire);
}

.lbl.short.on:not(:hover),
.lbl.short.sel:not(:hover) {
  background: var(--accent);
}

.lbl.short:not(:hover) .lbl-text {
  display: none;
}

.lbl.editing {
  max-width: none;
  border-color: var(--accent);
  color: var(--text-primary);
  cursor: text;
}

.lbl.editing .lbl-text {
  overflow: visible;
  user-select: text;
  -webkit-user-select: text;
  caret-color: var(--accent);
}

.lbl.editing .lbl-text:empty::before {
  content: attr(data-placeholder);
  color: var(--text-faint);
}

/* ----- 块：分区（area）、卡片（module，链路图里的叫 box）、卡片里的条目（item） -----
   样子是第二版的：都是浅色的框，一层套一层，靠框和留白分组，不加多余的底色。
   状态由上一层说：卡片标题右边一个状态图标（自己没设就是里面最没做完的那种）；
   条目和分区不放图标，用框线表示自己的状态（已有和没标的保持原样） */
.blk {
  --blk-line: var(--border);
  --blk-fill: var(--surface-card);
  --blk-wash: transparent;
  position: relative;
  border: 1px solid var(--blk-line);
  border-radius: var(--radius-control);
  background: linear-gradient(var(--blk-wash), var(--blk-wash)), var(--blk-fill);
  transition: border-color 180ms var(--ease), background-color 180ms var(--ease);
}

/* 自由摆的块（分区、卡片）按位置放；条目由卡片一行一行排 */
.blk:not([data-role="item"]) {
  position: absolute;
}

/* 标题一行：名称、有链路图时一个「›」、（卡片的）状态图标 */
.blk-head {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  min-width: 0;
}

.blk-title {
  flex: 0 1 auto;
  min-width: 0;
  min-height: 19px;
  line-height: 19px;
  color: var(--text-secondary);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  outline: none;
}

.blk-title.untitled:not(.editing)::before {
  content: "未命名";
  color: var(--text-faint);
  font-weight: 400;
}

.blk-title.editing {
  flex: 1;
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
  caret-color: var(--accent);
}

.blk-title.editing:empty::before {
  content: attr(data-placeholder);
  color: var(--text-faint);
  font-weight: 400;
}

.blk-note {
  margin-top: 2px;
  font-size: 12px;
  line-height: 17px;
  color: var(--text-muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

.blk-kids {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

/* 分区 */
.blk[data-role="area"] {
  --blk-fill: var(--surface-window);
  width: max-content;
  min-width: var(--module-w);
  padding: 14px 16px 16px;
  border-radius: var(--radius-card);
}

.blk[data-role="area"] > .blk-head > .blk-title {
  min-height: 22px;
  font-size: 16px;
  line-height: 22px;
  font-weight: 600;
  color: var(--text-primary);
}

.blk[data-role="area"] > .blk-note {
  max-width: 40em;
}

/* 分区里放卡片的地方：卡片按记下的位置自由摆，大小刚好包住它们（见 view.js 的 sizeFrame）。
   拖动时分区跟着变大变小，带过渡；重新排版时不带，量得才准 */
.blk[data-role="area"] > .blk-kids {
  position: relative;
  display: block;
  margin-top: 12px;
  transition: width 200ms var(--ease), height 200ms var(--ease);
}

.canvas.measuring .blk-kids,
.canvas.is-resizing .blk-kids {
  transition: none !important;
}

.blk[data-role="area"]:not(.has-kids) > .blk-kids::before {
  content: "把卡片拖到这里，或右键新建";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius-card);
  color: var(--text-faint);
  font-size: 12px;
}

/* 卡片 */
.blk[data-role="module"],
.blk[data-role="box"] {
  --blk-fill: var(--surface-card-strong);
  padding: 10px 12px 12px;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card-soft);
}

.blk[data-role="module"] {
  width: var(--module-w);
}

.blk[data-role="box"] {
  width: max-content;
  min-width: 168px;
  max-width: 280px;
}

.blk[data-role="module"] > .blk-head > .blk-title,
.blk[data-role="box"] > .blk-head > .blk-title {
  min-height: 20px;
  font-size: 14px;
  line-height: 20px;
  font-weight: 600;
  color: var(--text-primary);
}

/* 条目：浅色小框，有子项的里面再套一层（深浅交替） */
.blk[data-role="item"] {
  padding: 5px 10px 6px;
}

.blk[data-role="item"] > .blk-kids {
  gap: 5px;
  margin-top: 5px;
}

.blk[data-role="item"] .blk[data-role="item"] {
  --blk-fill: var(--surface-card-strong);
}

.blk[data-role="item"] .blk[data-role="item"] .blk[data-role="item"] {
  --blk-fill: var(--surface-card);
}

.blk[data-role="item"].has-kids > .blk-head > .blk-title {
  font-weight: 500;
  color: var(--text-primary);
}

/* 状态 · 卡片：标题右边一个图标（已有打勾、在做转圈、计划虚线圈、待定问号）；卡片自己和里面都没标就没有 */
.st-ic {
  --c: var(--text-faint);
  flex: none;
  display: grid;
  place-items: center;
  height: 20px;
  color: var(--c);
  transition: color 180ms var(--ease);
}

.blk-st {
  flex: none;
  display: flex;
  margin-left: auto;
}

.blk-st:empty {
  display: none;
}

.st-ic[data-tone="success"] {
  --c: var(--tone-success);
}

.st-ic[data-tone="accent"] {
  --c: var(--accent);
}

.st-ic[data-tone="warning"] {
  --c: var(--tone-warning);
}

.st-ic[data-tone="danger"] {
  --c: var(--tone-danger);
}

/* 状态 · 分区和条目：用框线表示——在做：黄色实线框；计划：黄色虚线框；待定：灰色虚线框、字变浅。
   框的样子和卡片上的图标对应（实线圈对实线框，虚线圈对虚线框），框里再加很淡的底色 */
.blk[data-role="area"][data-tone="accent"],
.blk[data-role="item"][data-tone="accent"] {
  --blk-line: var(--accent-border);
  --blk-wash: color-mix(in srgb, var(--accent) 5%, transparent);
}

.blk[data-role="area"][data-mark="ring"],
.blk[data-role="item"][data-mark="ring"] {
  border-style: dashed;
  --blk-wash: color-mix(in srgb, var(--accent) 2.5%, transparent);
}

.blk[data-role="area"][data-tone="muted"],
.blk[data-role="item"][data-tone="muted"] {
  --blk-line: var(--dash);
  --blk-wash: transparent;
}

.blk[data-role="area"][data-tone="warning"],
.blk[data-role="item"][data-tone="warning"] {
  --blk-line: color-mix(in srgb, var(--tone-warning) 50%, transparent);
  --blk-wash: color-mix(in srgb, var(--tone-warning) 5%, transparent);
}

.blk[data-role="area"][data-tone="warning"][data-mark="ring"],
.blk[data-role="item"][data-tone="warning"][data-mark="ring"] {
  --blk-wash: color-mix(in srgb, var(--tone-warning) 2.5%, transparent);
}

/* 条目的框小，框线用全色才看得出来（分区大，用淡一点的） */
.blk[data-role="item"][data-tone="warning"] {
  --blk-line: var(--tone-warning);
}

.blk[data-role="area"][data-tone="danger"],
.blk[data-role="item"][data-tone="danger"] {
  --blk-line: color-mix(in srgb, var(--tone-danger) 50%, transparent);
}

.blk[data-tone="muted"] > .blk-head > .blk-title,
.blk[data-tone="muted"] > .blk-note {
  color: var(--text-faint);
}

/* 有链路图的项：名字后面一个「›」，点它在旁边展开、再点收起；鼠标停一会儿看缩略图 */
.blk-flows {
  flex: none;
  display: flex;
  gap: 2px;
}

.flow-go {
  display: grid;
  place-items: center;
  width: 18px;
  height: 19px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-small);
  background: none;
  color: var(--accent);
  cursor: pointer;
  transition: background-color 180ms var(--ease), transform 180ms var(--ease);
}

.flow-go .ic {
  transition: transform 240ms var(--ease);
}

.flow-go:hover,
.flow-go[aria-expanded="true"] {
  background: var(--accent-soft);
}

/* 展开着：「›」转成朝下，表示内容已经打开在旁边 */
.flow-go[aria-expanded="true"] .ic {
  transform: rotate(90deg);
}

.flow-go:active {
  transform: scale(0.92);
}

/* 拖动时的对齐线 */
.guides {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
  pointer-events: none;
  z-index: 7;
}

.guides line {
  stroke: var(--accent);
  stroke-width: 1;
  stroke-dasharray: 4 3;
  vector-effect: non-scaling-stroke;
}

/* 框选：拖出来的一块淡淡的主题色 */
.marquee {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 8;
  border: calc(1px / var(--z, 1)) solid var(--accent-border);
  border-radius: var(--radius-small);
  background: var(--accent-selected-bg);
  pointer-events: none;
}

/* 挂着的链路图：浮在别的块上面的一块小窗口，左上角从挂着的地方展开 */
.blk.flow {
  --blk-fill: var(--surface-raised);
  box-shadow: var(--shadow-raised);
  transform-origin: 0 0;
}

/* 链路图像一张卡片，没有标题栏：收起的 × 浮在右上角，不占地方，里面的框可以一直摆到最上面 */
.blk.flow {
  padding: 16px;
}

.blk.flow > .blk-head {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 3;
}

/* 链路图里不再写一遍标题（细线连着的那个块就是出处） */
.blk.flow > .blk-head > .blk-title {
  display: none !important;
}

.blk.flow > .blk-kids {
  margin-top: 0;
}

.flow-close {
  flex: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 22px;
  margin: 0;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 180ms var(--ease), color 180ms var(--ease), transform 180ms var(--ease);
}

.flow-close:hover {
  background: var(--surface-control-hover);
  border-color: var(--border-subtle);
  color: var(--text-primary);
}

.flow-close:active {
  transform: scale(0.92);
}

.blk.flow.folded {
  visibility: hidden;
  pointer-events: none;
}

.blk.flow.closing {
  pointer-events: none;
}

/* 链路图的缩略图：鼠标停在「›」上时浮出来 */
.peek {
  position: fixed;
  z-index: 35;
  padding: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface-page);
  box-shadow: var(--shadow-raised);
  pointer-events: none;
  opacity: 0;
  transition: opacity 180ms var(--ease);
}

.peek.show {
  opacity: 1;
}

.peek-inner {
  position: relative;
  transform-origin: 0 0;
}

.peek-links {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
}

.peek-links path {
  fill: none;
  stroke: var(--wire);
  stroke-width: 1.5;
}

.peek-links .head {
  fill: var(--wire);
  stroke: none;
}

/* 选中：只把框换成 1px 主题色，不加底色（虚线状态选中后仍是虚线）；盖过状态的框色 */
.blk.sel[data-role] {
  --blk-line: var(--accent);
}

/* 改名时就是这一行字，不再套一圈焦点框 */
.blk-title:focus-visible {
  box-shadow: none;
}

/* 图例点了某种状态：别的都变淡，这种状态的照常 */
.canvas[data-filter] .blk-head,
.canvas[data-filter] .blk-note {
  opacity: 0.32;
  transition: opacity 180ms var(--ease);
}

.canvas[data-filter] .blk.match > .blk-head {
  opacity: 1;
}

/* 拖着条目停在另一项中间：外面一圈线慢慢出来，出全了就放进去（和 input.js 的 NEST_MS 一样长） */
.blk.nest-wait {
  outline: calc(1px / var(--z, 1)) dashed transparent;
  outline-offset: calc(2px / var(--z, 1));
  animation: nest-wait 500ms linear forwards;
}

@keyframes nest-wait {
  to {
    outline-color: var(--accent);
  }
}

/* 要放进去的块、连线的起点：外面一圈线。画布缩小时也保持屏幕上 1px，不会细到看不见 */
.blk.drop-into,
.blk.linking-from {
  outline: calc(1px / var(--z, 1)) solid var(--accent);
  outline-offset: calc(2px / var(--z, 1));
}

.blk.drop-into {
  --blk-wash: var(--accent-selected-bg);
}

.blk.dragging {
  z-index: 50;
  pointer-events: none;
  opacity: 0.94;
  box-shadow: var(--shadow-lift);
  transition: none;
}

.blk.dragging[data-role="item"] {
  min-width: 200px;
}

/* 拖动时留的空位：放下去会在这里 */
.blk-ph {
  flex: none;
  border: 1px dashed var(--accent-border);
  border-radius: var(--radius-control);
  background: var(--accent-selected-bg);
  pointer-events: none;
  animation: ph-in 160ms var(--ease);
}

@keyframes ph-in {
  from {
    opacity: 0;
  }
}

/* ----- 画布上的小控件 ----- */
/* 改大小的小把手：触摸设备上，选中能改大小的块时在它右下角，按住拖就改大小 */
.rz-grip {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 5;
  display: none;
  width: 32px;
  height: 32px;
  margin: -26px 0 0 -26px;
  touch-action: none;
}

.rz-grip::after {
  content: "";
  position: absolute;
  right: 9px;
  bottom: 9px;
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  border-bottom-right-radius: 3px;
}

.drag-hint {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 10;
  padding: 4px 8px;
  font-size: 12px;
  line-height: 17px;
  white-space: nowrap;
  color: var(--text-primary);
  background: var(--surface-tooltip);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-transient);
  pointer-events: none;
}

.empty-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text-faint);
  pointer-events: none;
}

/* 浮在画布角上的两组：左下图例，右下缩放 */
.float {
  position: absolute;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface-raised);
  box-shadow: var(--shadow-transient);
}

.legend {
  left: max(12px, env(safe-area-inset-left));
  bottom: max(12px, env(safe-area-inset-bottom));
  max-width: calc(100% - 220px);
  overflow-x: auto;
  scrollbar-width: none;
}

.legend:empty {
  display: none;
}

.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: none;
  color: var(--text-secondary);
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 180ms var(--ease), border-color 180ms var(--ease), color 180ms var(--ease);
}

.chip .st-ic {
  height: 16px;
}

.chip:hover {
  background: var(--surface-control-hover);
  color: var(--text-primary);
}

.chip.on {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent);
}

.chip .n {
  color: var(--text-muted);
  font-family: var(--font-number);
  font-variant-numeric: tabular-nums;
}

.zoomer {
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
}

.zoom {
  min-width: 48px;
  height: 28px;
  padding: 0 4px;
  border: 0;
  border-radius: var(--radius-control);
  background: none;
  color: var(--text-secondary);
  font: 500 12px/28px var(--font-number);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color 180ms var(--ease), color 180ms var(--ease);
}

.zoom:hover {
  background: var(--surface-control-hover);
  color: var(--text-primary);
}

/* ----- 右侧面板：只在选中时出现，放名称、状态、说明 ----- */
.panel {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 20;
  width: 296px;
  max-height: calc(100% - 24px);
  overflow: auto;
  padding: 14px 16px 16px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-raised);
  animation: panel-in 180ms var(--ease);
  transition: opacity 180ms var(--ease);
}

/* 拖动时让开，松手后再出来 */
.canvas.is-dragging ~ .panel {
  opacity: 0;
  pointer-events: none;
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateX(8px);
  }
}

.panel-head {
  display: none;
}

/* 选中一个时有名称、说明；选中多个时只有「已选几项」、状态、取消选择和删除 */
.panel:not(.is-many) .many-only,
.panel.is-many .one-only,
.panel.is-many .panel-actions {
  display: none;
}

.many-count {
  font-size: 14px;
  line-height: 20px;
  font-weight: 600;
}

.many-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.field {
  display: block;
}

.field + .field {
  margin-top: 14px;
}

.label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  line-height: 17px;
  color: var(--text-muted);
}

.input {
  display: block;
  width: 100%;
  padding: 4px 10px;
  font: 13px/19px var(--font-ui);
  color: var(--text-primary);
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  outline: none;
  resize: none;
  transition: border-color 180ms var(--ease), background-color 180ms var(--ease);
}

.input::placeholder {
  color: var(--text-faint);
}

.input:hover {
  border-color: var(--border-strong);
}

.input:focus {
  background: var(--surface-card-strong);
  box-shadow: var(--focus-ring);
}

.input.name {
  min-height: 30px;
  font-size: 14px;
  line-height: 20px;
  font-weight: 600;
}

.input.note {
  min-height: 64px;
}

.statuses {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

/* 状态按钮：状态图标加名字；选中的和块一样，主题色细框加很淡的主题色底 */
.st {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface-raised);
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color 180ms var(--ease), background-color 180ms var(--ease), color 180ms var(--ease);
}

.st .st-ic {
  height: 16px;
}

.st:hover {
  background: var(--surface-inset);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.st[aria-checked="true"] {
  border-color: var(--accent);
  background: var(--accent-selected-bg);
  color: var(--text-primary);
  font-weight: 600;
}

/* ----- 菜单：每项左边一个图标（和第一版一样），危险的（删除）是红色 ----- */
.menu {
  position: fixed;
  z-index: 40;
  min-width: 184px;
  padding: 4px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-transient);
  opacity: 0;
  transform: translateY(-10px) scale(0.98);
  transform-origin: top left;
  transition: opacity 120ms var(--ease), transform 120ms var(--ease);
}

.menu.show {
  opacity: 1;
  transform: none;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 30px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--radius-control);
  background: none;
  color: var(--text-secondary);
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 120ms var(--ease), color 120ms var(--ease);
}

.menu-item + .menu-item {
  margin-top: 2px;
}

.mi-label {
  flex: 1;
}

.mi-ic {
  flex: none;
  display: grid;
  place-items: center;
  width: 16px;
  color: var(--text-muted);
}

.menu-item:hover:not(:disabled) .mi-ic,
.menu-item:focus-visible .mi-ic,
.menu-item.danger .mi-ic,
.menu-item:disabled .mi-ic {
  color: inherit;
}

.menu-item:hover:not(:disabled),
.menu-item:focus-visible {
  background: var(--surface-nav-hover);
  color: var(--text-primary);
  box-shadow: none;
}

.menu-item.danger {
  color: var(--tone-danger-text);
}

.menu-item.danger:hover:not(:disabled) {
  background: var(--tone-danger-bg);
  color: var(--tone-danger-text);
}

.menu-item:disabled {
  color: var(--text-faint);
  cursor: default;
}

/* 开关项：开着时右边一个勾 */
.menu-check {
  display: grid;
  margin-left: 12px;
  color: var(--accent);
  visibility: hidden;
}

.menu-item[aria-checked="true"] .menu-check {
  visibility: visible;
}

/* 开关：和 TokenLens 一样的胶囊开关，关着灰底，开着主题色，圆点滑过去（菜单里小一号） */
.switch {
  flex: none;
  position: relative;
  width: 34px;
  height: 20px;
  margin-left: 16px;
  border-radius: 999px;
  background: var(--border-strong);
  transition: background-color 240ms var(--ease);
}

.switch i {
  position: absolute;
  left: 2px;
  top: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(35, 40, 45, 0.2);
  transition: transform 240ms var(--ease);
}

.menu-item[aria-checked="true"] .switch {
  background: var(--accent);
}

.menu-item[aria-checked="true"] .switch i {
  transform: translateX(14px);
}

.menu-item:active .switch i {
  scale: 0.92;
}

/* 拖动时松手后会落到的空位（不允许重叠、压到别的块时才有） */
.landing {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  border: calc(1px / var(--z, 1)) dashed var(--accent);
  border-radius: var(--radius-card);
  background: var(--accent-selected-bg);
  pointer-events: none;
}

/* 菜单最上面一排状态：点一下就改 */
.menu-status {
  display: flex;
  gap: 2px;
}

.mst {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: none;
  color: var(--text-secondary);
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 120ms var(--ease), color 120ms var(--ease);
}

.mst .st-ic {
  height: 16px;
}

.mst:hover:not(:disabled) {
  background: var(--surface-nav-hover);
  color: var(--text-primary);
}

.mst[aria-checked="true"] {
  border-color: var(--accent);
  background: var(--accent-selected-bg);
  color: var(--text-primary);
  font-weight: 600;
}

/* 一排色块（强调色）：选中的外面多一圈 */
.menu-row {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  margin-top: 2px;
  padding: 0 8px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.swatches {
  display: flex;
  gap: 8px;
  margin-left: auto;
  padding-left: 16px;
}

.swatch {
  width: 16px;
  height: 16px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-small);
  background: var(--sw);
  cursor: pointer;
  transition: transform 180ms var(--ease), box-shadow 180ms var(--ease);
}

.swatch:hover:not(:disabled) {
  transform: scale(1.1);
}

.swatch[aria-checked="true"] {
  box-shadow: 0 0 0 2px var(--surface-raised), 0 0 0 3px var(--sw);
}

.swatch:disabled {
  opacity: 0.45;
  cursor: default;
}

.menu-sep {
  height: 1px;
  margin: 4px 2px;
  background: var(--border-subtle);
}

/* 面板里加东西、删除的按钮：只在触摸设备上出现（电脑上用右键菜单） */
.panel-actions {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.panel-actions .btn {
  height: 36px;
  padding: 0 14px;
}

.panel-actions .btn[hidden] {
  display: none;
}

/* ----- 提示 ----- */
.banner {
  position: fixed;
  top: calc(56px + env(safe-area-inset-top));
  left: 50%;
  z-index: 30;
  transform: translateX(-50%);
  padding: 6px 12px;
  font-size: 12px;
  line-height: 17px;
  color: var(--accent);
  background: var(--surface-raised);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-transient);
  white-space: nowrap;
  pointer-events: none;
}

/* 顶栏下面的提醒：别的设备保存了新版本、别的设备有没保存的改动 */
.notices {
  position: fixed;
  top: calc(56px + env(safe-area-inset-top));
  left: 50%;
  z-index: 31;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: max-content;
  max-width: calc(100vw - 32px);
  transform: translateX(-50%);
}

.banner:not([hidden]) + .notices {
  top: calc(92px + env(safe-area-inset-top));
}

.notice {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 2px 2px 2px 12px;
  font-size: 12px;
  line-height: 18px;
  color: var(--text-primary);
  background: var(--surface-raised);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-transient);
}

.notice-text {
  min-width: 0;
  margin-right: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notice .text-btn {
  flex: none;
  height: 26px;
  padding: 0 8px;
  font-size: 12px;
}

.notice .ib.notice-x {
  flex: none;
  width: 26px;
  height: 26px;
  color: var(--text-muted);
}

.notice .text-btn:not(.primary) {
  color: var(--text-secondary);
}

.notice .text-btn:not(.primary):hover {
  background: var(--surface-control-hover);
}

.devices {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 4px 0 16px;
}

.device {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 4px 8px 10px;
  border-radius: var(--radius-control);
}

.device:hover {
  background: var(--surface-control-hover);
}

.device-main {
  flex: 1;
  min-width: 0;
}

.device-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.device-state {
  font-size: 12px;
}

.text-btn.danger {
  color: var(--tone-danger-text);
}

.text-btn.danger:hover {
  background: var(--tone-danger-bg);
}

.prompt .input {
  width: 100%;
  margin: 4px 0 16px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(60px + env(safe-area-inset-bottom));
  z-index: 45;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 32px);
  padding: 8px 8px 8px 14px;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-raised);
  opacity: 0;
  transform: translate(-50%, 6px);
  transition: opacity 180ms var(--ease), transform 180ms var(--ease);
}

.toast:not(:has(button)) {
  padding-right: 14px;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.text-btn {
  height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-control);
  background: none;
  color: var(--accent);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}

.text-btn:hover {
  background: var(--accent-soft);
}

.tip {
  position: fixed;
  z-index: 35;
  max-width: 300px;
  padding: 7px 10px;
  font-size: 12px;
  line-height: 17px;
  color: var(--text-primary);
  white-space: pre-wrap;
  background: var(--surface-tooltip);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-transient);
  pointer-events: none;
  opacity: 0;
  transition: opacity 320ms var(--ease);
}

.tip.show {
  opacity: 1;
}

/* ----- 对话框 ----- */
.dialog-back {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--surface-backdrop);
  opacity: 0;
  transition: opacity 180ms var(--ease);
}

.dialog-back.show {
  opacity: 1;
}

.dialog {
  width: min(340px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 20px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-raised);
}

.dialog.wide {
  width: min(440px, 100%);
}

.dialog-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  font-size: 16px;
  line-height: 22px;
  font-weight: 600;
}

.dialog-text {
  margin: 0 0 16px;
  color: var(--text-secondary);
}

.muted {
  color: var(--text-muted);
}

.dialog-err {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--tone-danger-text);
}

.login .input {
  height: 32px;
}

.login .btn {
  width: 100%;
  margin-top: 16px;
}

.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.version-info {
  flex: 1;
  font-size: 12px;
}

.versions {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 300px;
  margin: 0 0 16px;
  overflow: auto;
}

.version {
  height: 32px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: none;
  color: var(--text-secondary);
  text-align: left;
  cursor: pointer;
}

.version:hover {
  background: var(--surface-nav-hover);
  color: var(--text-primary);
}

.version[aria-pressed="true"] {
  background: var(--accent-selected-bg);
  border-color: var(--accent);
  color: var(--text-primary);
}

/* 按钮：主要（主题色实心）、次要（白底细框）、危险（淡红底红框红字） */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface-raised);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 180ms var(--ease), border-color 180ms var(--ease), transform 180ms var(--ease);
}

.btn:hover:not(:disabled) {
  background: var(--surface-inset);
  border-color: var(--border-strong);
  transform: translateY(-0.5px);
}

.btn:active:not(:disabled) {
  transform: translateY(0.5px) scale(0.98);
}

.btn.primary {
  border-color: transparent;
  background: var(--accent);
  color: var(--text-on-accent);
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: transparent;
}

.btn.danger,
.btn.danger:hover:not(:disabled) {
  background: var(--tone-danger-bg);
  border-color: var(--tone-danger-border);
  color: var(--tone-danger-text);
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

/* ----- 触摸屏：点的地方大一点；没有右键，选中后在面板里加 ----- */
@media (pointer: coarse) {
  .panel-actions {
    display: flex;
  }

  /* 手指点线：能点中的范围宽一些 */
  .links .link-hit {
    stroke-width: calc(28px / var(--z, 1));
  }

  .rz-grip {
    display: block;
  }

  .menu-item,
  .mst {
    height: 40px;
    font-size: 15px;
  }

  .ib {
    width: 40px;
    height: 40px;
  }

  .ib.sm {
    width: 36px;
    height: 36px;
  }

  .input,
  .input.name {
    font-size: 16px;
  }
}

/* ----- 窄屏（手机）：面板变成底部抽屉，顶栏只留图标 ----- */
@media (max-width: 720px) {
  .bar {
    gap: 8px;
    padding-left: max(10px, env(safe-area-inset-left));
  }

  .sync span,
  .bar-sep {
    display: none;
  }

  .legend {
    max-width: calc(100% - 200px);
  }

  .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 55%;
    padding: 6px 16px calc(16px + env(safe-area-inset-bottom));
    border-width: 1px 0 0;
    border-radius: 8px 8px 0 0;
    box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.12);
    animation: sheet-in 220ms var(--ease);
    transition: opacity 180ms var(--ease);
  }

  @keyframes sheet-in {
    from {
      transform: translateY(24px);
      opacity: 0;
    }
  }

  .panel-head {
    position: relative;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    height: 32px;
    margin-bottom: 4px;
  }

  .panel-grip {
    position: absolute;
    left: 50%;
    top: 4px;
    width: 36px;
    height: 4px;
    margin-left: -18px;
    border-radius: 2px;
    background: var(--border-strong);
  }

  body.has-panel .zoomer,
  body.has-panel .legend {
    display: none;
  }

  /* 底部抽屉压紧，少挡画布：不写字段名（输入框里有提示）；状态一排，按钮一排；说明框先占一行，写多了再长高 */
  .panel {
    max-height: 45%;
    padding: 0 12px calc(10px + env(safe-area-inset-bottom));
  }

  .panel-head {
    height: 26px;
    margin-bottom: 0;
  }

  .panel .label {
    display: none;
  }

  .panel .field + .field {
    margin-top: 8px;
  }

  .input.note {
    min-height: 0;
    max-height: 96px;
    overflow-y: auto;
  }

  .statuses {
    flex-wrap: nowrap;
  }

  .st {
    flex: 1;
    justify-content: center;
    gap: 4px;
    height: 32px;
    padding: 0 4px;
  }

  .panel-actions {
    flex-wrap: nowrap;
    gap: 6px;
    margin-top: 10px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .panel-actions .btn {
    flex: none;
    height: 32px;
    padding: 0 10px;
    font-size: 13px;
  }

  /* 左下图例、右下缩放：一样高、半透明，少挡画布；图例只留图标和个数（名字在长按、悬停的提示里） */
  .float {
    gap: 0;
    padding: 2px;
    background: color-mix(in srgb, var(--surface-raised) 72%, transparent);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    box-shadow: none;
  }

  .legend {
    left: max(10px, env(safe-area-inset-left));
    bottom: max(10px, env(safe-area-inset-bottom));
    max-width: calc(100% - 170px);
  }

  .zoomer {
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
  }

  .chip {
    gap: 4px;
    height: 30px;
    padding: 0 6px;
  }

  .chip-label {
    display: none;
  }

  .zoomer .ib.sm {
    width: 30px;
    height: 30px;
  }

  .zoom {
    min-width: 40px;
    height: 30px;
    font-size: 11px;
    line-height: 30px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
