/* ══════════════════════════════════════════════════════════════
   境明 Jingming · 主题层 jm-theme.css
   ──────────────────────────────────────────────────────────────
   设计：
   · dark 为默认（沿用既有视觉：墨蓝底 + 青紫辉光），零回归
   · light 为新增（青调纸白 + 深青点色），全部通过变量切换
   · --*-rgb 为通道值，供 rgba(var(--x-rgb), α) 使用
   · 本文件同时承载移动端基础增强与 PWA 界面样式
   载入顺序需在页面 <style> 之后，或依赖 :root / html[..] 的高特异性
   ══════════════════════════════════════════════════════════════ */

:root {
  color-scheme: dark;

  /* ── 强调色通道 ── */
  --accent-rgb: 80, 200, 240;
  --violet-rgb: 167, 139, 250;
  --gold-rgb:   251, 191, 36;
  --ok-rgb:     34, 197, 94;
  --err-rgb:    239, 83, 79;
  --skyrgb:     125, 211, 252;
  --soft-rgb:   143, 220, 245;

  /* ── 面 ── */
  --bg:          #070c10;
  --panel-rgb:   8, 14, 22;
  --bubble-rgb:  15, 22, 32;
  --overlay-rgb: 5, 6, 16;
  --card:        #0e1120;
  --hairline-rgb: 255, 255, 255;
  --shade-rgb:   0, 0, 0;

  /* ── 文字梯度（亮 → 暗）── */
  --text:    #d0d8e0;
  --text-hi: #e8edf4;
  --text-2:  #b9c6d6;
  --text-3:  #8896a8;
  --text-4:  #6b7a8d;
  --text-5:  #4d5c6e;
  --text-6:  #3d4a5c;

  /* ── 强调实色 ── */
  --accent:    #50c8f0;
  --accent-2:  #8fdcf5;
  --violet:    #a78bfa;
  --gold:      #fbd38d;
  --ok:        #22c55e;
  --err:       #ef5350;
  --sky:       #7dd3fc;
  --on-accent: #070c10;
  /* 高亮浅字：信息页（购买/条款/隐私/退款/从业者）用它 */
  --soft:      #8fdcf5;
  --dim:       #93a1b0;

  /* ── 画布与阴影 ── */
  --canvas-bg:  #0a0a18;
  --grain-rgb:  80, 200, 240;
  --shadow:     0 10px 30px rgba(0, 0, 0, 0.45);
}

/* ══════════════════════════════════════════════════════════════
   LIGHT 主题
   ══════════════════════════════════════════════════════════════ */
html[data-theme="light"] {
  color-scheme: light;

  /* 强调色在白底上必须压暗才够对比度：
     青 #50c8f0 → #0a789e（白底 4.9:1）
     紫 #a78bfa → #6d4bd1（白底 5.4:1）
     金 #fbd38d → #8a5a00（白底 5.2:1）*/
  --accent-rgb: 10, 120, 158;
  --violet-rgb: 109, 75, 209;
  --gold-rgb:   168, 106, 0;
  --ok-rgb:     21, 128, 61;
  --err-rgb:    190, 40, 36;
  --skyrgb:     12, 96, 140;
  --soft-rgb:   11, 107, 142;

  --bg:          #f2f6f8;
  --panel-rgb:   255, 255, 255;
  --bubble-rgb:  255, 255, 255;
  --overlay-rgb: 15, 23, 42;
  --card:        #ffffff;
  --hairline-rgb: 15, 23, 42;
  --shade-rgb:   15, 23, 42;

  --text:    #26323d;
  --text-hi: #0f1a24;
  --text-2:  #3a4a58;
  /* 白底上次级文字按 WCAG AA 校正：原值 #66788a/#7a8c9c/#93a3b1 仅 4.4/3.0/2.2:1 */
  --text-3:  #4f6273;
  --text-4:  #5c6e80;
  --text-5:  #6b7d8e;
  --text-6:  #7f91a1;

  --accent:    #0a789e;
  --accent-2:  #0b6b8e;
  --violet:    #6d4bd1;
  --gold:      #8a5a00;
  --ok:        #15803d;
  --err:       #be2824;
  --sky:       #0c608c;
  --on-accent: #ffffff;

  --canvas-bg:  #fbfdfe;
  --grain-rgb:  10, 120, 158;
  --shadow:     0 10px 30px rgba(15, 23, 42, 0.10);
  --soft:       #0b6b8e;

  /* ── 兼容：purchase / pro / terms / privacy / refund 用的是另一套变量名 ──
     这几页各有自己的 :root 定义，特异性为 (0,1,0)；
     html[data-theme="light"] 为 (0,1,1)，故无论加载顺序都能压过。── */
  --panel: rgba(255, 255, 255, 0.94);
  --line:  rgba(10, 120, 158, 0.20);
  --txt:   #26323d;
  --dim:   #5c6e80;
  --cyan:  #0a789e;
}

/* light 下需要单独校正的少数规则（无法靠变量表达）── */
html[data-theme="light"] body { background: var(--bg); color: var(--text); }

/* 示例报告里的对话气泡原先继承 #welcome 的弱化灰（--text-4），
   在深色与浅色气泡上都偏淡，这里改回正文色 */
.sample-body .msg-bubble { color: var(--text); }

/* 信息页的渐变按钮：深色主题下用深字，浅色主题下渐变已压深，改白字 */
html[data-theme="light"] .lang-btn.active,
html[data-theme="light"] .btn,
html[data-theme="light"] .card .badge.best { color: #fff; }

html[data-theme="light"] .msg-bubble .md-code {
  background: rgba(15, 23, 42, 0.045);
  border-color: rgba(var(--accent-rgb), 0.18);
}

html[data-theme="light"] #archive-modal { background: rgba(15, 23, 42, 0.42); }

/* 深色主题下"hover 变白"的按钮，浅色主题下应为"变深" */
html[data-theme="light"] .start-btn:hover,
html[data-theme="light"] .report-btn:hover,
html[data-theme="light"] #archive-btn:hover,
html[data-theme="light"] .arc-ob.on,
html[data-theme="light"] .verify-btn:hover { color: var(--text-hi); }

/* 浅色下浮层卡片需要真实投影才立得住 */
html[data-theme="light"] .arc-box,
html[data-theme="light"] #archive-modal .arc-box {
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.16);
  border-color: rgba(var(--accent-rgb), 0.22);
}
html[data-theme="light"] .lb-buy:hover { box-shadow: 0 4px 14px rgba(var(--accent-rgb), 0.28); }
html[data-theme="light"] #landing-bar {
  background: linear-gradient(180deg, rgba(var(--accent-rgb), 0.055), transparent);
}
html[data-theme="light"] .msg.assistant .msg-bubble {
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}
html[data-theme="light"] .start-card {
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
}
html[data-theme="light"] #visual-panel { box-shadow: -1px 0 0 rgba(15, 23, 42, 0.06); }

/* ══════════════════════════════════════════════════════════════
   移动端 / 触屏基础增强（为 App 化准备）
   ══════════════════════════════════════════════════════════════ */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: manipulation;
}

html body {
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
  /* iOS Safari 地址栏伸缩：100vh 会溢出，用 dvh 兜底 */
  height: 100vh;
  height: 100dvh;
}

/* 触屏可点元素统一抑制双击缩放延迟 + 保证最小触控面 */
button, a, summary, .eg-item, .quick-prompt, .tool-btn, .lang-btn, .theme-btn {
  touch-action: manipulation;
}

@media (max-width: 860px) {
  /* iOS 聚焦输入框会自动放大页面，除非字号 ≥16px */
  html body #msg-input {
    font-size: 16px;
    line-height: 1.45;
  }
  /* 刘海屏 / 手势条安全区 */
  html body #input-bar {
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
  html body #site-footer {
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
  html body #landing-bar {
    padding-left: max(14px, env(safe-area-inset-left, 0px));
    padding-right: max(14px, env(safe-area-inset-right, 0px));
  }
  /* 顶栏与输入区的触控目标放大到 32px 高，横向仍保持紧凑 */
  html body .lang-btn,
  html body .theme-btn {
    min-height: 34px;
    padding-left: 10px;
    padding-right: 10px;
  }
  html body #send-btn {
    width: 46px;
    height: 46px;
  }
  /* 对话区底部留白，避免最后一条被输入栏压住 */
  html body #chat-area {
    padding-bottom: 18px;
    -webkit-overflow-scrolling: touch;
  }
  /* 移动端顶部信息条只保留「价格 + 购买」；从业者版入口由页脚承载，
     否则两个大按钮会各占一行，吃掉近 1/6 屏 */
  html body #landing-bar .lb-right > a.lb-buy:nth-of-type(2) { display: none; }
  html body #landing-bar .lb-right { gap: 6px; }
  html body #landing-bar .lb-lang { margin-left: auto; }

  /* ── 可视化栏 → 底部抽屉（App 化关键：输入框必须贴底）──
     面板移出文档流，默认完全收起；由顶栏「🧰 工具」唤出，
     展开时恢复完整信息（标题 + 罗盘 + 竖排工具 + 页脚）。 */
  html body #visual-panel {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 60;
    width: 100%;
    min-width: 0;
    max-width: none;
    max-height: 80vh;
    border-left: none;
    border-top: 1px solid rgba(var(--accent-rgb), .18);
    border-radius: 16px 16px 0 0;
    background: rgba(var(--panel-rgb), .985);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    box-shadow: 0 -14px 40px rgba(var(--shade-rgb), .28);
    transform: translateY(101%);
    transition: transform .3s cubic-bezier(.32, .72, 0, 1);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  html body #visual-panel.is-open { transform: translateY(0); }

  /* 顶栏：390px 下五个元素放不下，隐藏标题（品牌已在信息条上），
     其余一律不换行、不压缩，避免出现「档\n案」这类竖排断字 */
  html body #topbar { gap: 6px; }
  html body #topbar .page-title { display: none; }
  html body #topbar #help-btn,
  html body #topbar #archive-btn,
  html body #topbar #tools-btn,
  html body #topbar #yun-pill {
    white-space: nowrap;
    flex-shrink: 0;
  }
  html body #topbar #yun-pill { font-size: .66rem; padding: 4px 8px; }

  /* 抽屉内恢复完整布局：标题 + 罗盘 + 两列工具卡 */  html body #visual-panel.is-open #visual-header { display: block; }
  html body #visual-panel.is-open #compass-preview {
    display: flex;
    flex: 0 0 auto;
    min-height: 254px;
    max-height: 254px;
    margin-bottom: 6px;
  }
  html body #visual-panel.is-open #compass-preview canvas {
    width: 218px !important;
    height: 218px !important;
  }
  html body #visual-panel.is-open #tool-buttons {
    flex-direction: row;
    flex-wrap: wrap;
    overflow: visible;
    gap: 8px;
    padding: 6px 14px 14px;
    border-top: none;
  }
  html body #visual-panel.is-open #tool-buttons .tool-btn {
    flex: 1 1 calc(50% - 4px);
    min-width: calc(50% - 4px);
    flex-direction: row;
    align-items: center;
    text-align: left;
    justify-content: flex-start;
    min-height: 56px;
    padding: 9px 12px;
  }
  html body #visual-panel.is-open #tool-buttons .tool-btn .desc { display: block; }
  html body #visual-panel.is-open #tool-buttons .tool-group-label,
  html body #visual-panel.is-open #tool-buttons .divider { display: block; flex: 1 1 100%; }
  html body #visual-panel.is-open #tool-buttons .tool-more { display: block; flex: 1 1 100%; }
  html body #visual-panel.is-open #tool-buttons .tool-more .tool-btn { flex: 1 1 100%; min-width: 100%; }
  html body #visual-panel.is-open #site-footer { display: block; }
  html body #visual-panel.is-open #jm-install { margin: 8px 14px 12px; }

  /* 收起状态：页脚与安装入口一并隐藏，不留残影 */
  html body #visual-panel:not(.is-open) #site-footer { display: none; }
  html body #visual-panel:not(.is-open) #jm-install { display: none !important; }
}

/* 抽屉遮罩：点击关闭 */
#jm-tools-mask {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(var(--overlay-rgb), .48);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .26s ease, visibility .26s ease;
}
#jm-tools-mask.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* 顶栏「工具」按钮：仅移动端可见 */
#tools-btn {
  display: none;
  align-items: center;
  gap: 4px;
  background: rgba(var(--accent-rgb), .08);
  border: 1px solid rgba(var(--accent-rgb), .25);
  color: var(--accent-2);
  padding: 5px 12px;
  border-radius: 8px;
  font-size: .74rem;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: all .18s;
  touch-action: manipulation;
}
#tools-btn:hover { background: rgba(var(--accent-rgb), .16); border-color: rgba(var(--accent-rgb), .5); }
@media (max-width: 860px) {
  html body #tools-btn { display: inline-flex; min-height: 32px; }
}

/* 横屏手机：可视化面板彻底收起，把高度全给对话 */
@media (max-width: 900px) and (max-height: 460px) and (orientation: landscape) {
  html body #visual-panel { display: none; }
  html body #landing-bar .lb-trust { display: none; }
}

/* 桌面端减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ══════════════════════════════════════════════════════════════
   主题切换按钮（与语言按钮同组）
   ══════════════════════════════════════════════════════════════ */
.theme-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 10px;
  border-radius: 7px;
  font-size: .86rem;
  line-height: 1;
  border: 1px solid rgba(var(--accent-rgb), .22);
  background: rgba(var(--hairline-rgb), .03);
  color: var(--text-4);
  cursor: pointer;
  transition: .2s;
  white-space: nowrap;
  font-family: inherit;
  min-width: 38px;
}
.theme-btn:hover {
  border-color: var(--accent);
  color: var(--accent-2);
  background: rgba(var(--accent-rgb), .08);
}
/* 图标跟随"用户偏好"而非"实际生效值"：data-theme 是实际明暗，data-theme-mode 才是偏好 */
.theme-btn .ti { display: none; }
html[data-theme-mode="dark"]  .theme-btn .ti-dark  { display: inline; }
html[data-theme-mode="light"] .theme-btn .ti-light { display: inline; }
html[data-theme-mode="auto"]  .theme-btn .ti-auto  { display: inline; }

/* ══════════════════════════════════════════════════════════════
   PWA：安装入口
   ══════════════════════════════════════════════════════════════ */
#jm-install {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  margin: 10px 0 0;
  border-radius: 9px;
  border: 1px solid rgba(var(--accent-rgb), .34);
  background: rgba(var(--accent-rgb), .07);
  color: var(--accent-2);
  font-size: .78rem;
  font-family: inherit;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: .18s;
}
#jm-install.show { display: flex; }
#jm-install:hover {
  background: rgba(var(--accent-rgb), .14);
  border-color: rgba(var(--accent-rgb), .55);
}
#jm-install .ji-txt { flex: 1; }
#jm-install .ji-sub { display: block; font-size: .68rem; color: var(--text-4); margin-top: 2px; }

/* 独立模式（已安装为 App）下隐藏安装入口，去掉多余留白 */
@media (display-mode: standalone) {
  #jm-install { display: none !important; }
}
