:root {
  --board: #1b1d1a;
  --ink: #e6ebdd;
  --acid: #b6ff2e;
  --acid-ink: #16200a;
}

/* 全局禁用浏览器原生触摸手势：双击缩放、长按菜单、滚动回弹全部交给我们自己处理。
   viewport 的 user-scalable=no 在 iOS 10+ 已失效，必须靠 touch-action 兜底。
   注意 touch-action 不继承，故用通配符覆盖所有 UI（含按钮/搜索栏/canvas-wrap）。 */
* {
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: "SF Mono", "PingFang SC", "Microsoft YaHei", monospace;
  color: var(--ink);
  background: var(--board);
}

.layout { position: fixed; inset: 0; overflow: hidden; transform: translateX(0); transition: transform .45s cubic-bezier(.2,.8,.2,1); }
/* 库页面与画布互换：画布向右退场，库卡片向左收起；进入库时反向，全程不刷新页面 */
.layout.off-right { transform: translateX(100%); }

/* 库选择页与画布同一套卡片渲染：两块布局左右对滑，互不刷新 */
.library-layout { z-index: 39; background: var(--board); transform: translateX(-100%); transition: transform .45s cubic-bezier(.2,.8,.2,1); }
.library-layout.open { transform: translateX(0); }
/* 用户画布是最外层：与库画布同构，从左侧滑入 */
.user-layout { z-index: 39; background: var(--board); transform: translateX(-100%); transition: transform .45s cubic-bezier(.2,.8,.2,1); }
.user-layout.open { transform: translateX(0); }
/* 库备注编辑态：右侧对勾按钮，绿底黑图案，点它才进入该库主画布 */
.lib-enter {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 42;
  width: 64px;
  height: 64px;
  padding: 10px;
  border: 3px solid #16200a;
  background: var(--acid);
  cursor: pointer;
}
.lib-enter[hidden] { display: none; }
.lib-enter svg { width: 100%; height: 100%; fill: #16200a; display: block; }
.lib-input { position: fixed; z-index: 44; padding: 8px 10px; width: 200px; background: var(--board); border: 2px solid var(--acid); color: var(--ink); font: 16px monospace; outline: none; }
.lib-input[hidden] { display: none; }

.canvas-wrap {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--board);
}

#board {
  position: absolute;
  inset: 0;
  display: block;
  cursor: grab;
  touch-action: none;
}

/* IME 承接键盘与输入法：必须极小但可见（Safari 才会聚焦），定位由 JS 跟光标。
   主画布与库画布共用同一份样式，避免漏掉其中一个变成可见的默认输入框。 */
.mp-ime {
  position: absolute;
  width: 1px;
  height: 14px;
  opacity: .01;
  border: 0;
  padding: 0;
  margin: 0;
  resize: none;
  outline: none;
  overflow: hidden;
  background: transparent;
  color: transparent;
  z-index: 1;
}

:root {
  --search-w: min(640px, calc(100vw - 160px));
  --add-btn-size: 64px;
  --search-gap: 12px;
}

.search-bar {
  position: fixed;
  bottom: 32px;
  /* 搜索栏 + 间距 + 按钮作为整体居中：搜索栏中心固定在屏幕中心左移半个(按钮+间距)。
     left 与 transform 都是定值，不参与过渡；只让 width 动画，避免 transform 的百分比
     随 width 变化导致展开瞬间跳到右对齐再弹回。 */
  left: calc(50% - (var(--add-btn-size) + var(--search-gap)) / 2);
  width: 0;
  height: var(--add-btn-size);
  overflow: hidden;
  background: #262a20;
  border: 4px solid var(--acid);
  box-sizing: border-box;
  transform: translateX(-50%);
  /* visibility 延迟到 width 收起动画结束后再隐藏：收起动画照常可见，结束后不留边框残影。
     展开时 visibility 无延迟立即显示；pointer-events 收起瞬间即禁用，动画期间不可交互。 */
  transition: width .18s ease-out, visibility 0s linear .18s;
  z-index: 41; /* 库选择态同样可用搜索栏 */
  visibility: hidden;
  pointer-events: none;
}
.search-bar.open {
  width: var(--search-w);
  transition: width .18s ease-out, visibility 0s linear 0s;
  visibility: visible;
  pointer-events: auto;
}
.search-input {
  width: 100%;
  height: 100%;
  padding: 0 20px;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font: 20px "SF Mono", "PingFang SC", "Microsoft YaHei", monospace;
  caret-color: var(--acid);
  -webkit-user-select: text;
  user-select: text;
}
.search-input::placeholder { color: #7f8875; }
/* AI 执行期间：搜索栏转为状态条，显示正在思考/正在做什么 */
.ai-status {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  box-sizing: border-box;
  background: #262a20;
  color: var(--acid);
  font: 700 16px/1.35 "SF Mono", "PingFang SC", "Microsoft YaHei", monospace;
  letter-spacing: .5px;
  /* 思考概要可能较长：允许折行显示完整语义，只有超出状态条高度才裁掉 */
  white-space: normal;
  overflow-wrap: anywhere;
  overflow: hidden;
}
.ai-status-text { flex: 1 1 auto; min-width: 0; }
/* 进行中闪烁方块：默认暗绿，每来一个思考 token 闪亮一下，纯色硬边无渐变 */
.ai-spin { flex: 0 0 auto; width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; }
.ai-spin i { display: block; width: 14px; height: 14px; background: #3d5a17; } /* 暗端底色 */
/* 每个 token 重触发一次短闪：亮起后 160ms 回暗；频率越高闪得越密 */
.ai-spin.flash i { animation: ai-spin-flash 160ms steps(1, end) 1; }
@keyframes ai-spin-flash { 0% { background: var(--acid); } 100% { background: #3d5a17; } }
.search-bar.ai-status-on .ai-status { display: flex; }
.search-bar.ai-status-on .search-input { visibility: hidden; }
/* 输入框保留长按选择/粘贴，双击缩放仍由全局 touch-action:none 屏蔽 */
.search-input, .mp-ime { -webkit-touch-callout: default; user-select: text; -webkit-user-select: text; }

.add-btn {
  position: fixed;
  bottom: 32px;
  left: 50%;
  margin-left: calc(var(--add-btn-size) / -2);
  width: var(--add-btn-size);
  height: var(--add-btn-size);
  padding: 0;
  border: 0;
  background: var(--acid);
  cursor: pointer;
  z-index: 41; /* 库选择态仍可长按主按钮 */
  transition: transform .18s ease-out;
  /* 图标居中不依赖 button 各浏览器默认的行高/基线/对齐，统一 flex 居中 */
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  font: inherit;
}
.add-btn:hover { background: #d4ff7a; }
.add-btn.search-open { transform: translateX(calc(var(--search-w) / 2 + var(--search-gap) / 2)); }
.add-btn.collapsed { transform: translateY(120px); pointer-events: none; }
.add-ico { display: block; width: 100%; height: 100%; flex: none; fill: var(--acid-ink); }
.add-ico[hidden] { display: none; }

/* 主按钮长按工具栏：位置相对主按钮，与其同步平移；纯色硬边，无渐变 */
.main-tools {
  position: fixed;
  bottom: 108px;
  left: 50%;
  display: flex;
  gap: 12px;
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  transition: transform .12s ease-out, opacity .12s ease-out;
  z-index: 41; /* 库选择态仍可用主按钮 */
}
.main-tools.open { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
.main-tools.search-open { transform: translate(calc(-50% + var(--search-w) / 2 + var(--search-gap) / 2), 12px); }
.main-tools.search-open.open { transform: translate(calc(-50% + var(--search-w) / 2 + var(--search-gap) / 2), 0); }
.main-tools.collapsed { transform: translate(-50%, 132px); opacity: 0; pointer-events: none; }
.main-tools.collapsed.search-open { transform: translate(calc(-50% + var(--search-w) / 2 + var(--search-gap) / 2), 132px); }
.main-tool {
  width: var(--add-btn-size);
  height: var(--add-btn-size);
  padding: 0;
  border: 2px solid var(--acid);
  background: var(--board);
  cursor: pointer;
  /* 与主按钮同：flex 居中图标，忽略浏览器 button 默认对齐 */
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  font: inherit;
}
.main-tool[hidden] { display: none; }
.main-tool:active { background: #2f342a; }
.main-tool-ico { display: block; width: 100%; height: 100%; flex: none; fill: var(--acid); }

/* 设置面板：纯色硬边、居中构图，无渐变 */
.settings-panel {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.72);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .12s linear, visibility 0s linear .12s;
  z-index: 40;
}
.settings-panel.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity .12s linear, visibility 0s linear 0s;
}
.settings-card {
  width: min(520px, calc(100vw - 48px));
  padding: 28px;
  background: var(--board);
  border: 2px solid var(--acid);
}
.settings-title {
  margin: 0 0 24px;
  color: var(--acid);
  font: 700 22px/1.2 "SF Mono", "PingFang SC", "Microsoft YaHei", monospace;
  letter-spacing: 2px;
}
.settings-label {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
  font: 700 15px/1.2 "SF Mono", "PingFang SC", "Microsoft YaHei", monospace;
}
.settings-input {
  width: 100%;
  height: 52px;
  padding: 0 14px;
  border: 2px solid var(--acid);
  outline: none;
  background: #262a20;
  color: var(--ink);
  caret-color: var(--acid);
  font: 16px "SF Mono", "PingFang SC", "Microsoft YaHei", monospace;
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}
.settings-input::placeholder { color: #7f8875; }
.settings-select { appearance: none; -webkit-appearance: none; cursor: pointer; }
.password-error { color: #ff2d6f; font-weight: 700; }
.password-error[hidden] { display: none; }
#user-password-confirm { margin-top: 10px; }
.settings-hint {
  margin: 10px 0 0;
  color: #7f8875;
  font: 13px/1.4 "SF Mono", "PingFang SC", "Microsoft YaHei", monospace;
}
.settings-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}
.settings-btn {
  flex: 1;
  height: 48px;
  border: 2px solid var(--acid);
  background: var(--acid);
  color: var(--acid-ink);
  cursor: pointer;
  font: 700 15px "SF Mono", "PingFang SC", "Microsoft YaHei", monospace;
}
.settings-btn.ghost { background: var(--board); color: var(--acid); }
.settings-btn:active { opacity: .7; }

/* 聊天窗口：搜索栏展开时显示，纯色硬边气泡，无渐变 */
.chat-panel {
  position: fixed;
  left: calc(50% - (var(--add-btn-size) + var(--search-gap)) / 2);
  bottom: 108px;
  transform: translateX(-50%);
  width: var(--search-w);
  max-height: min(46vh, 420px);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
  background: #262a20;
  border: 2px solid var(--acid);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .12s linear, visibility 0s linear .12s;
  z-index: 45; /* 高于库/用户画布（39），引导对话在三种画布上都可见 */
}
.chat-panel.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity .12s linear, visibility 0s linear 0s;
}
.chat-log { display: flex; flex-direction: column; gap: 10px; }
.chat-msg {
  max-width: 82%;
  padding: 10px 14px;
  border: 2px solid var(--acid);
  font: 15px/1.5 "SF Mono", "PingFang SC", "Microsoft YaHei", monospace;
  white-space: pre-wrap;
  word-break: break-word;
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}
/* AI 回复在左（绿底），用户消息在右（深底） */
.chat-msg.ai { align-self: flex-start; background: var(--acid); color: var(--acid-ink); }
.chat-msg.user { align-self: flex-end; background: var(--board); color: var(--ink); }
/* AI 思考：灰底灰白字，可展开，完成后自动收起 */
.chat-think {
  align-self: flex-start;
  max-width: 82%;
  border: 2px solid #7f8875;
  background: #3a3f36;
  color: #cdd2c6;
  font: 12px/1.5 "SF Mono", "PingFang SC", "Microsoft YaHei", monospace;
  padding: 0;
}
.chat-think summary {
  cursor: pointer;
  padding: 6px 10px;
  color: #9aa58a;
  list-style: none;
}
.chat-think summary::-webkit-details-marker { display: none; }
.chat-think[open] summary { border-bottom: 2px solid #7f8875; }
.chat-think .think-body {
  padding: 8px 10px;
  max-height: 180px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: default;
}
.chat-msg.error { align-self: flex-start; background: #3a2029; color: #ff9ab5; border-color: #ff2d6f; }
.chat-msg.tool {
  align-self: center;
  max-width: 92%;
  background: transparent;
  border-color: #7f8875;
  color: #7f8875;
  font-size: 12px;
  padding: 6px 10px;
}

/* 长按进度环与复制按钮：统一画在最上层 overlay，避免被 UI 遮挡或与输入文本渲染冲突 */
.ui-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 70;
}

/* AI 执行工具中：全屏呼吸绿边框，不拦截任何输入 */
.ai-frame {
  position: fixed;
  inset: 0;
  display: none;
  border: 8px solid #3d5a17; /* 呼吸暗端：边框底色，亮端由 ::after 覆盖 */
  pointer-events: none;
  z-index: 59;
}
.ai-frame.show { display: block; }
/* 亮端整层（酸绿边框 + 内发光）只做 opacity 呼吸：视觉等同最初版本的
   「暗绿→酸绿 + 发光渐强」，恢复强烈对比；同时只动 opacity 走合成层，
   不逐帧重绘 border-color/box-shadow，避免当初的流式思考卡顿。 */
.ai-frame::after {
  content: '';
  position: absolute;
  inset: -8px; /* 覆盖本体 8px 边框，两层边框重合 */
  border: 8px solid var(--acid);
  box-shadow: inset 0 0 0 12px rgba(182,255,46,.18);
  animation: ai-frame-breathe 1.1s ease-in-out infinite alternate;
}
@keyframes ai-frame-breathe {
  from { opacity: 0; }
  to   { opacity: 1; }
}



