/* vkt Flow 样式
 *
 * 布局约定：
 *   1) **不滚动**。body 固定视口，画布铺满，touch-action: none 防浏览器手势抢事件。
 *   2) **画布是唯一主视觉**。画布外（页框/工具坞）用中性暗色，UI 全部半透明压在画布上。
 *   3) 墨色不进 CSS——画布颜色全在 JS 的调色板里，这里只管 chrome。
 *   4) **压画布的浮层（顶栏/工具坞/toast）永远浅字压深底**，不跟 body.theme-light 走：
 *      画布底色恒为中深调（见 js/palette.js），浅色主题的 --text 近黑，只服务面板。
 */
:root {
  --page: #191D22;
  --page-2: #14171B;
  --text: #F1F4F0;
  --text-dim: #C2CAC3;
  --line: rgba(241, 244, 240, 0.16);
  --surface: rgba(241, 244, 240, 0.07);
  --accent: #6FB7D9;
  --accent-soft: rgba(111, 183, 217, 0.16);
  --danger: #E4657A;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

body.theme-light {
  --page: #E9E4DA;
  --page-2: #DED8CC;
  --text: #23272E;
  --text-dim: #5A6058;
  --line: rgba(35, 39, 46, 0.2);
  --surface: rgba(35, 39, 46, 0.06);
  color-scheme: light;
}

/* 压在画布上的浮层（顶栏 / 工具坞 / toast）把变量钉回深色套 —— 它们**刻意不参与**
   body.theme-light：画布底色永远是中深调（六套墨色包见 js/palette.js），画布本身
   也不随系统深浅变，所以这几件浮层只能永远「浅字压深底」。浅色主题把 --text 变近黑
   是给抽屉 / 菜单 / 卡片这类不透明白底用的，直接拿去画浮层就成了「深字压深画布」，
   顶栏标题、配额药丸、☰ 与底部工具按钮整片糊掉（toast 更彻底：底色本来就固定深色，
   黑字等于隐形；sand 2026-10-06 踩过，照抄它的钉法）。shatter 的 --chrome-* 是同一件事。
   钉在容器上而不是逐条改 color/border：变量按继承生效，往后往顶栏 / 工具坞里
   加新控件也不会漏。 */
#topbar, #dock, .toast {
  --text: #F1F4F0;
  --text-dim: #C2CAC3;
  --line: rgba(241, 244, 240, 0.16);
  --surface: rgba(241, 244, 240, 0.07);
  --page: #191D22;            /* .swatch.active 选中环的间隔圈 */
  /* 光钉变量不够：.tool-btn / .icon-btn 没写 color，靠 button { color: inherit }
     从 body 一路继承 —— 浅色主题下这条继承链不经过任何变量，只能在这里截断。 */
  color: var(--text);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;      /* 长按画布不弹 iOS 呼出菜单 */
}
html, body { margin: 0; padding: 0; }

html { height: 100%; background: var(--page-2); }

body {
  position: fixed;
  inset: 0;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  background: var(--page);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC",
    "Hiragino Sans", "Microsoft YaHei", sans-serif;
}

button { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- 画布 ---------- */
#flowCanvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;          /* 手指是桨，浏览器手势全让路 */
  cursor: crosshair;
}

#stage { position: absolute; inset: 0; z-index: 1; pointer-events: none; }

/* WebGL 不可用时的降级文案：居中一句话，压在中深底色上（浅字压深底，同浮层口径） */
.gl-fallback {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: 24px;
  pointer-events: none;
}
.gl-fallback p {
  margin: 0;
  max-width: 320px;
  padding: 12px 18px;
  border-radius: 999px;
  background: rgba(12, 15, 19, 0.92);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  text-align: center;
}

/* ---------- 顶栏 ---------- */
#topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }

.brand {
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini {
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 18vw;
}

.pill {
  margin-left: auto;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 5px 11px;
  color: var(--text);
  white-space: nowrap;
}

.icon-btn {
  width: 38px; height: 38px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: border-color 200ms ease;
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn:active { transform: scale(0.94); }

/* ---------- 工具坞 ---------- */
#dock {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 16px calc(14px + var(--safe-b));
  pointer-events: none;
  transition: transform 320ms ease, opacity 320ms ease;
}
#dock > * { pointer-events: auto; }

/* 划动时沉下去：transform 走合成层，不重排 */
body.drawing #dock,
body.dock-hidden #dock {
  transform: translateY(calc(100% + 20px));
  opacity: 0;
  pointer-events: none;
}
body.drawing #dock > *,
body.dock-hidden #dock > * { pointer-events: none; }

.swatch-row { display: flex; gap: 10px; }

.swatch {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}
.swatch.active {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--page), 0 0 0 3.5px var(--text-dim);
  transform: scale(1.08);
}
.swatch:active { transform: scale(0.92); }

.hint {
  margin: 0;
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0.8;
}

.tools { display: flex; gap: 10px; }

.tool-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: blur(6px);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  cursor: pointer;
  transition: border-color 200ms ease, transform 160ms ease;
}
.tool-btn:hover { border-color: var(--accent); }
.tool-btn:active { transform: scale(0.94); }
.tool-btn.icon-only { padding: 10px 14px; font-size: 15px; }

/* ---------- 抽屉 ---------- */
.backdrop {
  position: absolute;
  inset: 0;
  z-index: 8;
  background: rgba(6, 8, 11, 0.5);
  backdrop-filter: blur(2px);
}
.hidden { display: none !important; }

.sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 9;
  max-height: 84vh;            /* 兜底：不认识 dvh 的老 iOS（≤15.3） */
  max-height: 84dvh;
  display: flex;
  flex-direction: column;
  background: var(--page-2);
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -18px 40px rgba(0, 0, 0, 0.38);
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px 8px;
}
.sheet-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 16px calc(22px + var(--safe-b));
}

.field { padding: 12px 0; border-top: 1px solid var(--line); }
.field:first-child { border-top: 0; }
.field-label {
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 180ms ease;
}
.chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

.lang-row { display: flex; flex-wrap: wrap; gap: 8px; }
.lang-row .chip { padding: 6px 10px; font-size: 12px; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 2px;
  font-size: 14px;
}
.switch-row input[type="checkbox"] {
  width: 44px; height: 26px;
  accent-color: var(--accent);
  cursor: pointer;
  flex: 0 0 auto;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}
.stat-cell {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 10px 12px;
}
.stat-cell .v {
  display: block;
  font-size: 20px;
  font-weight: 300;
  font-variant-numeric: tabular-nums;
}
.stat-cell .k {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 14px;
  cursor: pointer;
  width: 100%;
  transition: border-color 180ms ease;
}
.btn.ghost:hover { border-color: var(--accent); }
.btn.primary {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.note {
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-dim);
}
/* 抽屉里的「当前墨色包」——窄屏顶栏藏了那个 mini，这条得留出下边距 */
#schemeNote { margin: 8px 0 14px; }

/* ---------- 弹窗 ---------- */
.modal {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(6, 8, 11, 0.55);
}
.modal-card {
  width: 100%;
  max-width: 340px;
  background: var(--page-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.42);
}
.modal-card h3 { margin: 0 0 8px; font-size: 16px; font-weight: 600; }
.modal-card p { margin: 0; font-size: 13px; line-height: 1.6; color: var(--text-dim); }
.rest-count {
  margin-top: 10px !important;
  font-size: 26px !important;
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  color: var(--text) !important;
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}
.modal-actions .btn { flex: 1 1 0; }

/* ---------- toast ---------- */
.toast {
  position: absolute;
  left: 50%;
  bottom: calc(120px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 12;
  max-width: 84vw;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(12, 15, 19, 0.92);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  text-align: center;
  pointer-events: none;
}

/* ---------- 统一壳：顶栏按钮 / 折叠菜单 / 内容页 / 登录 ---------- */

/* hidden 属性也必须能关掉元素：.sheet / .modal / .menu-item 都自带 display，
   同优先级下后写的规则会赢，属性隐藏会静默失效（菜单里「个人信息」那一格就靠它）。 */
[hidden] { display: none !important; }

.nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 34px; height: 34px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
}
.nav-btn:active { transform: scale(0.94); }

.app-title {
  flex: 0 1 auto;
  min-width: 0;
  margin-left: 2px;
  max-width: 40vw;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 窄屏顶栏只留必要件：← 标题 配额 ⚙ ☰。墨色包名收进设置抽屉
   （renderSchemeRow 会同时写顶栏那个 mini 和抽屉里的 #schemeNote）——
   挤在 390px 上必然溢出，而配额那条文案又不该被截断。 */
@media (max-width: 560px) {
  #topbar .mini { display: none; }
}

/* ---------- 折叠菜单：底部抽屉 ---------- */
.menu-list {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 9;
  display: flex;
  flex-direction: column;
  padding: 10px 10px calc(12px + var(--safe-b));
  background: var(--page-2);
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -18px 40px rgba(0, 0, 0, 0.38);
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}
.menu-item:active { background: var(--surface); }
.menu-ico { flex: 0 0 auto; width: 24px; font-size: 17px; text-align: center; }
.menu-txt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* ---------- 内容页（说明） ---------- */
.page-view {
  position: fixed;
  inset: 0;
  z-index: 11;
  display: flex;
  flex-direction: column;
  background: var(--page);
}
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(12px + var(--safe-t)) 14px 10px;
  border-bottom: 1px solid var(--line);
}
/* 与右侧关闭键等宽，标题才真的落在中间 */
.page-head-pad { flex: 0 0 auto; width: 38px; }
.page-title { font-size: 16px; font-weight: 700; }
.page-body {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 18px 16px calc(22px + var(--safe-b));
}
.page-placeholder { margin: 0; font-size: 14px; color: var(--text-dim); text-align: center; }
/* 占位页是一句居中的话；内容页是长文，必须顶对齐 —— 长文居中会让第一行
   跑到屏幕中间、下面还藏着一半。 */
.page-view.doc .page-body { align-items: flex-start; justify-content: flex-start; }

.doc-block { width: 100%; max-width: 520px; margin: 0 auto; }
.doc-p { font-size: 14px; line-height: 1.6; margin: 0 0 12px; }
.doc-list {
  display: grid; gap: 8px;
  margin: 0; padding-left: 20px;
  font-size: 14px; line-height: 1.6;
}
.doc-list li { list-style: disc; }
.doc-h { margin: 24px 0 10px; font-size: 14px; font-weight: 600; }
.doc-note {
  margin: 16px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 13px; line-height: 1.55;
  color: var(--text-dim);
}
.doc-row {
  display: flex; align-items: baseline; gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.doc-k { flex: 0 0 auto; font-size: 13px; color: var(--text-dim); }
.doc-link {
  flex: 1 1 auto; min-width: 0;
  font-size: 14px;
  color: var(--accent);
  text-decoration: none;
  overflow-wrap: anywhere;        /* 邮箱 / 长 URL 不许把行撑破 */
}
.doc-link:active { opacity: .7; }

/* ---------- 登录 / 个人信息抽屉 ---------- */
.input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  -webkit-appearance: none;
  appearance: none;
}
.input::placeholder { color: var(--text-dim); }
.input:focus { outline: none; border-color: var(--accent); }

.code-row { display: flex; gap: 8px; margin-top: 10px; }
.code-row .code-input { flex: 1 1 auto; min-width: 0; }
.code-row .btn { flex: 0 0 auto; padding: 11px 14px; white-space: nowrap; }

/* Turnstile 用 interaction-only：平时完全隐形、高度 0，
   只有 Cloudflare 真要用户点一下时才现形 —— 所以没内容时不留空白 */
.turnstile-box:not(:empty) { margin-top: 12px; }

.form-msg {
  min-height: 18px;
  margin: 10px 0 2px;
  font-size: 13px;
  color: var(--danger);
  word-break: break-word;
}
.form-msg.ok { color: #6FBF8B; }
.form-hint {
  margin: 8px 0 0;
  font-size: 12px; line-height: 1.5;
  color: var(--text-dim);
  word-break: break-word;
}

.or-row { display: flex; align-items: center; gap: 12px; margin: 14px 0; }
.or-line { flex: 1; height: 1px; background: var(--line); }
.or-txt { font-size: 12px; color: var(--text-dim); }

/* Google 官方按钮：白底描边 + 四色 G，深浅主题都不变（品牌规范） */
.btn.google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  background: #fff;
  color: #1f1f1f;
  border: 1px solid #dadce0;
}
.g-ico { flex: 0 0 auto; width: 18px; height: 18px; }

#authLoginArea .btn { width: 100%; margin-top: 10px; }
#authLoginArea .code-row .btn,
#authLoginArea .btn.google { margin-top: 0; }

/* ---------- 资料顶部的头像 + 昵称 ---------- */
.profile-head { display: flex; align-items: center; gap: 12px; margin: 4px 0 14px; }
.profile-id { flex: 1; min-width: 0; }
.avatar {
  display: flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
  width: 46px; height: 46px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--surface);
  font-size: 20px; font-weight: 700;
}
.avatar img { display: block; width: 100%; height: 100%; object-fit: cover; }
.user-nick {
  margin: 0;
  font-size: 16px; font-weight: 700;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-email { margin: 2px 0 0; font-size: 13px; color: var(--text-dim); word-break: break-all; }
.user-line { margin: 6px 0; font-size: 14px; color: var(--text-dim); }

/* 确认弹窗里的危险按钮：与 .btn.ghost 同尺寸，只把字染红 */
.btn.danger { background: var(--surface); color: var(--danger); border: 1px solid var(--line); }

/* ---------- 减弱动效：只关装饰过渡，流体模拟照常 ---------- */
@media (prefers-reduced-motion: reduce) {
  #dock, .swatch, .tool-btn { transition: none !important; }
}
