/* ============================================================
   ♾️ AI · 控制台角色层 / 微恐层
   白天：二次元角色（随模块切换不同角色）
   夜间：微恐（扫描线、暗角、跟随眼、字符抖动、故障角色）
   ============================================================ */

/* ---------- 角色层 ---------- */
#ai-art {
  position: fixed;
  right: -3vw;
  bottom: -5vh;
  width: 42vw;
  height: 90vh;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .6s ease;
}
body.ai-ambience #ai-art { opacity: 1; }
body.ai-ambience #ai-art { opacity: .55; }
body.ai-ambience #ai-art { opacity: .42; }

#ai-art img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: bottom right;
  opacity: 0;
  transform: translateX(140px) scale(1.02);
  transition: opacity .5s ease-out, transform .78s cubic-bezier(.18,.85,.22,1);
  filter: saturate(1.05) contrast(1.02);
  -webkit-mask-image: radial-gradient(118% 84% at 58% 42%, #000 46%, rgba(0,0,0,.5) 72%, transparent 94%);
  mask-image: radial-gradient(118% 84% at 58% 42%, #000 46%, rgba(0,0,0,.5) 72%, transparent 94%);
}
#ai-art img.show { opacity: 1; transform: none; }

/* 只让角色在右侧边缘显影，左侧完全淡出，避免压住卡片文字 */
#ai-art {
  -webkit-mask-image: radial-gradient(120% 100% at 72% 58%, #000 42%, rgba(0,0,0,.82) 66%, transparent 84%);
  mask-image: radial-gradient(120% 100% at 72% 58%, #000 42%, rgba(0,0,0,.82) 66%, transparent 84%);
}
#ai-art img.leaving {
  opacity: 0;
  transform: translateX(-90px) scale(.99);
  transition: opacity .4s ease-in, transform .6s cubic-bezier(.4,0,.6,1);
}
body.ai-ambience #ai-art img {
  filter: saturate(1.05) contrast(1.04);
}
body.ai-ambience #ai-art img {
  filter: saturate(.65) contrast(1.14) brightness(.92);
}


/* ---------- 微恐层（仅夜间）---------- */
#ai-grain, #ai-vignette {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .6s ease;
}
body.ai-ambience #ai-grain {
  opacity: .5;
  background: repeating-linear-gradient(to bottom, rgba(255,255,255,.035) 0 1px, transparent 1px 3px);
}
body.ai-ambience #ai-vignette {
  opacity: 1;
  background: radial-gradient(circle at 50% 38%, transparent 46%, rgba(0,0,0,.55) 100%);
  animation: aiBreath 14s ease-in-out infinite;
}
@keyframes aiBreath {
  0%, 100% { opacity: .82; }
  46% { opacity: .95; }
  58% { opacity: .88; }
}

/* 跟随眼睛 */
#ai-eyes {
  position: fixed;
  right: 6vw;
  top: 12vh;
  display: none;
  gap: 30px;
  z-index: 1;
  pointer-events: none;
}
body.ai-ambience #ai-eyes { display: flex; }
body.ai-day #ai-eyes { display: none; }
#ai-eyes span {
  position: relative;
  width: 34px;
  height: 20px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 50% 50%, rgba(255,59,92,.18), transparent 72%);
  animation: aiBlink 9s ease-in-out infinite;
}
#ai-eyes span i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 38%, #ff9fb1, #ff3b5c 55%, #5b0a18);
  box-shadow: 0 0 10px rgba(255, 59, 92, .8);
  transition: transform .12s linear;
}
@keyframes aiBlink {
  0%, 90%, 100% { transform: scaleY(1); }
  92% { transform: scaleY(.08); }
  94% { transform: scaleY(1); }
}

/* 标题偶发抖动 */
.ai-glitch {
  animation: aiJitter .22s steps(2) 2;
  text-shadow: 1px 0 rgba(53,230,255,.45), -1px 0 rgba(255,59,92,.5);
}
@keyframes aiJitter {
  0% { transform: translate(0,0) skewX(0); }
  50% { transform: translate(-1.5px,1px) skewX(-5deg); }
  100% { transform: translate(1px,-1px) skewX(3deg); }
}

/* 页脚幽灵行 */
body.ai-ambience #ai-ghost {
  display: block;
}
#ai-ghost {
  display: none;
  position: fixed;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  z-index: 1;
  font-size: 10.5px;
  letter-spacing: .06em;
  color: rgba(255, 92, 147, .32);
  font-family: ui-monospace, monospace;
  pointer-events: none;
  white-space: nowrap;
}

/* 模块切换时的轻微色相变化（只影响角色光晕） */
#ai-art::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(closest-side, hsla(var(--ai-hue, 330), 90%, 60%, .18), transparent 70%);
  opacity: .9;
  pointer-events: none;
  transition: background .5s ease;
}

@media (max-width: 1100px) {
  #ai-art { width: 62vw; right: -12vw; opacity: .3; }
  body.ai-ready #ai-art { opacity: .26; }
}
@media (prefers-reduced-motion: reduce) {
  #ai-vignette, #ai-eyes span { animation: none !important; }
}


/* ---------- 用户菜单里的「外观」 ---------- */
.ai-theme-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 8px 8px;
  margin: -2px 0 4px;
  border-bottom: 1px solid var(--border, rgba(255,255,255,.1));
}
.ai-theme-label { font-size: 12px; color: var(--muted-foreground, #8b8398); }
.ai-seg {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border-radius: 8px;
  border: 1px solid var(--border, rgba(255,255,255,.14));
  background: var(--secondary, rgba(255,255,255,.05));
}
.ai-seg button {
  width: 24px;
  height: 21px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted-foreground, #8b8398);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}
.ai-seg button:hover { color: var(--foreground, #fff); transform: translateY(-1px); }
.ai-seg button.on {
  background: var(--primary, #ff5c93);
  color: var(--primary-foreground, #fff);
}

/* ---------- 切换擦除层 ---------- */
#ai-wipe {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
}
#ai-wipe.on { opacity: 1; }
#ai-wipe .layer {
  position: absolute;
  inset: 0;
  clip-path: circle(0% at 50% 50%);
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 92, 147, .22), transparent 48%),
    color-mix(in srgb, var(--background, #0a0b10) 94%, transparent);
  backdrop-filter: blur(2px);
}
#ai-wipe.run .layer { animation: aiWipeIn .95s cubic-bezier(.45,0,.25,1) forwards; }
#ai-wipe.out .layer { animation: aiWipeOut .8s ease forwards; }
@keyframes aiWipeIn { to { clip-path: circle(150% at 50% 50%); } }
@keyframes aiWipeOut { from { opacity: 1; } to { opacity: 0; } }
#ai-wipe .glyph {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%) scale(.5);
  font-size: 72px;
  color: var(--primary, #ff5c93);
  opacity: 0;
}
#ai-wipe.run .glyph { animation: aiGlyph 1s ease forwards; }
@keyframes aiGlyph {
  0% { opacity: 0; transform: translate(-50%,-50%) scale(.5) rotate(-15deg); }
  55% { opacity: .9; }
  100% { opacity: 0; transform: translate(-50%,-50%) scale(1.35) rotate(6deg); }
}


/* ---------- 让页面容器透明，露出角色层 ---------- */
html, body { background-color: var(--background) !important; }
body > div,
#root,
#root > div,
main,
[data-slot="sidebar-inset"] {
  background-color: transparent !important;
}
/* ---------- 主题切换时的柔化过渡 ---------- */
html.ai-theming,
html.ai-theming body {
  transition: background-color .55s ease, color .55s ease !important;
}


/* ---------- 白天：卡片半透明，让角色透出来 ---------- */
body.ai-ambience [data-slot="card"] {
  background-color: color-mix(in srgb, var(--card, #fff) 97%, transparent) !important;
  backdrop-filter: blur(14px) saturate(1.02);
  -webkit-backdrop-filter: blur(14px) saturate(1.02);
}
/* 夜间也一样，但更克制 */
body.ai-ambience [data-slot="card"] {
  background-color: color-mix(in srgb, var(--card, #12141c) 98%, transparent) !important;
  backdrop-filter: blur(14px);
}
/* 表格/输入框保持实底，别影响阅读 */
body.ai-day table, body.ai-night table { background-color: transparent !important; }


/* ============================================================
   曼德拉层 / 越狱层（仅夜间）
   ============================================================ */

/* 视错觉条纹：极低透明度、缓慢横移 */
body.ai-ambience.ai-night::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .045;
  background: repeating-linear-gradient(
    115deg,
    rgba(255, 255, 255, .9) 0 1px,
    transparent 1px 5px,
    rgba(255, 59, 92, .5) 5px 6px,
    transparent 6px 13px
  );
  animation: aiDrift 26s linear infinite;
}
@keyframes aiDrift {
  from { background-position: 0 0; }
  to   { background-position: 260px 0; }
}

/* 闪帧 */
#ai-flash {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at 50% 46%, rgba(255, 59, 92, .10), rgba(0, 0, 0, .55));
  transition: opacity .06s linear;
}
#ai-flash.on { opacity: 1; }

/* 第二组眼 */
#ai-eyes2 {
  position: fixed;
  left: 4vw;
  top: 22vh;
  display: flex;
  gap: 26px;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  transition: opacity .5s ease;
}
#ai-eyes2.show { opacity: 1; }
#ai-eyes2 span {
  position: relative;
  width: 26px;
  height: 15px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 50% 50%, rgba(255, 59, 92, .14), transparent 72%);
  animation: aiBlink2 11s ease-in-out infinite;
}
#ai-eyes2 span i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 38%, #ffb3c4, #ff3b5c 55%, #4a0812);
  box-shadow: 0 0 8px rgba(255, 59, 92, .7);
}
@keyframes aiBlink2 {
  0%, 88%, 100% { transform: scaleY(1); }
  90% { transform: scaleY(.06); }
  92% { transform: scaleY(1); }
}

/* 幽灵行淡入淡出更柔 */
#ai-ghost { transition: opacity .7s ease; }

/* 夜间卡片边框泛红脉动 */
body.ai-ambience [data-slot="card"] {
  animation: aiRedEdge 19s ease-in-out infinite;
}
@keyframes aiRedEdge {
  0%, 100% { box-shadow: 0 0 0 1px rgba(255, 59, 92, 0); }
  48% { box-shadow: 0 0 0 1px rgba(255, 59, 92, .13), 0 0 24px rgba(255, 59, 92, .06) inset; }
  52% { box-shadow: 0 0 0 1px rgba(255, 59, 92, .18), 0 0 30px rgba(255, 59, 92, .08) inset; }
}

@media (prefers-reduced-motion: reduce) {
  body.ai-night::after, #ai-eyes2 span, body.ai-night [data-slot="card"] { animation: none !important; }
}


/* ---------- 氛围模式开关 ---------- */
.ai-amb-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border, rgba(255,255,255,.1));
  font-size: 12px;
}
.ai-amb-toggle {
  min-width: 44px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--border, rgba(255,255,255,.16));
  background: var(--secondary, transparent);
  color: var(--muted-foreground, #8b8398);
  font-size: 12px;
  cursor: pointer;
}
.ai-amb-toggle.on {
  background: var(--primary, #2563eb);
  color: var(--primary-foreground, #fff);
  border-color: transparent;
}


/* ---------- 装饰文字位（错忆作用区，不挡业务）---------- */
#ai-amb-text {
  position: absolute;
  right: 12px;
  bottom: 96px;
  z-index: 3;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  letter-spacing: .04em;
  color: color-mix(in srgb, var(--primary, #ff5c93) 55%, transparent);
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
}


/* ---------- 主导航收敛（方案 v2 §4.1）---------- */
.ai-nav-core {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 0 10px;
  border-bottom: 1px solid var(--border, rgba(255,255,255,.08));
  margin-bottom: 8px;
}
.ai-nav-label,
.ai-nav-toggle {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px 6px;
  font-size: 11.5px;
  letter-spacing: .04em;
  color: var(--muted-foreground, #8b90a0);
  background: transparent;
  border: 0;
  cursor: pointer;
}
.ai-nav-label { cursor: default; }
.ai-nav-toggle:hover { color: var(--foreground, inherit); }

.ai-nav-collapsed-group > *:not(.ai-nav-toggle):not([data-slot="sidebar-group-label"]) {
  display: none;
}
.ai-nav-collapsed-group > [data-slot="sidebar-group-label"] { display: none; }
.ai-nav-collapsed-group.ai-nav-open > *:not(.ai-nav-toggle) { display: revert; }
.ai-nav-collapsed-group.ai-nav-open > [data-slot="sidebar-group-label"] { display: none; }

.ai-nav-help {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--muted-foreground, #8b90a0);
  border-top: 1px solid var(--border, rgba(255,255,255,.08));
  text-decoration: none;
}
.ai-nav-help:hover { color: var(--primary, #ff5c93); }


/* ---------- 总览页头操作（方案 v2 §5.2）---------- */
.ai-ov-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
  align-items: center;
  flex-wrap: wrap;
}
.ai-ov-btn {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--border, rgba(255,255,255,.14));
  background: transparent;
  color: var(--foreground, inherit);
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
  transition: background .16s ease, border-color .16s ease;
}
.ai-ov-btn:hover { border-color: var(--primary, #ff5c93); color: var(--primary, #ff5c93); }
.ai-ov-btn.primary {
  background: var(--primary, #ff5c93);
  border-color: transparent;
  color: var(--primary-foreground, #fff);
}
.ai-ov-btn.primary:hover { filter: brightness(1.06); color: var(--primary-foreground, #fff); }


/* ---------- 钱包：更多金额入口（方案 v2 §5.6）---------- */
.ai-wallet-more {
  display: inline-flex;
  align-items: center;
  height: 34px;
  margin-top: 8px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px dashed var(--border, rgba(255,255,255,.18));
  color: var(--muted-foreground, #8b90a0);
  font-size: 12.5px;
  text-decoration: none;
}
.ai-wallet-more:hover { color: var(--primary, #ff5c93); border-color: var(--primary, #ff5c93); }

/* ---------- 表格：隐藏列后不塌陷 ---------- */
body[data-ai-page="keys"] table th[style*="display: none"],
body[data-ai-page="usage-logs"] table th[style*="display: none"] { width: 0; padding: 0; }


/* ============================================================
   磨砂玻璃 + 无限符号 + 彩蛋（用户需求）
   ============================================================ */

/* 卡片磨砂：高模糊 + 高不透明度，既有质感又不糊字 */
[data-slot="card"], .card, [class*="bg-card"] {
  background-color: color-mix(in srgb, var(--card, #fff) 92%, transparent) !important;
  -webkit-backdrop-filter: blur(18px) saturate(1.12);
  backdrop-filter: blur(18px) saturate(1.12);
}

/* 顶栏磨砂 */
header {
  -webkit-backdrop-filter: blur(20px) saturate(1.15) !important;
  backdrop-filter: blur(20px) saturate(1.15) !important;
  background: color-mix(in srgb, var(--background, #fff) 74%, transparent) !important;
}

/* 侧栏磨砂 */
aside, [data-slot="sidebar"] {
  -webkit-backdrop-filter: blur(16px) saturate(1.08);
  backdrop-filter: blur(16px) saturate(1.08);
  background: color-mix(in srgb, var(--card, #fff) 78%, transparent) !important;
}

/* 弹层磨砂 */
[data-slot="dropdown-menu-content"], [data-slot="popover-content"] {
  -webkit-backdrop-filter: blur(22px) saturate(1.15) !important;
  backdrop-filter: blur(22px) saturate(1.15) !important;
}

/* 无限符号：流动渐变 */
.ai-inf-live {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  line-height: 1;
  position: relative;
  vertical-align: middle;
}
.ai-inf-live svg { width: 100%; height: 100%; display: block; overflow: visible; }
.ai-inf-live .inf-stroke {
  fill: none;
  stroke: url(#aiInfGrad);
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-dasharray: 92 34;
  animation: aiInfFlow 3.6s linear infinite;
  filter: drop-shadow(0 0 6px rgba(255, 92, 147, .55));
}
.ai-inf-live .inf-ghost {
  fill: none;
  stroke: currentColor;
  stroke-width: 3.2;
  stroke-linecap: round;
  opacity: .18;
}
@keyframes aiInfFlow {
  from { stroke-dashoffset: 126; }
  to   { stroke-dashoffset: 0; }
}
.ai-inf-live:hover .inf-stroke { animation-duration: 1.6s; }

/* 彩蛋遮罩 */
#ai-egg {
  position: fixed;
  inset: 0;
  z-index: 9998;
  display: grid;
  place-items: center;
  background: rgba(6, 4, 10, .72);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .28s ease;
}
#ai-egg.on { opacity: 1; pointer-events: auto; }
#ai-egg .egg-card {
  width: min(420px, calc(100vw - 48px));
  padding: 26px 24px 20px;
  border-radius: 16px;
  border: 1px solid rgba(255, 92, 147, .35);
  background: linear-gradient(160deg, rgba(30, 16, 26, .96), rgba(12, 10, 18, .96));
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6), 0 0 0 1px rgba(255, 255, 255, .04) inset;
  color: #f4eef6;
  text-align: center;
  font-family: var(--font-ui-sans, system-ui, sans-serif);
  transform: translateY(10px) scale(.98);
  transition: transform .3s cubic-bezier(.2,.8,.2,1);
}
#ai-egg.on .egg-card { transform: none; }
#ai-egg .egg-inf {
  font-size: 62px;
  line-height: 1;
  margin-bottom: 10px;
  background: linear-gradient(90deg, #ff5c93, #a78bfa, #35e6ff, #ff5c93);
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: aiInfText 3s linear infinite;
}
@keyframes aiInfText {
  from { background-position: 0% 50%; }
  to   { background-position: 300% 50%; }
}
#ai-egg h3 { font-size: 17px; margin: 0 0 8px; font-weight: 600; }
#ai-egg p { font-size: 13px; line-height: 21px; color: #b9aec6; margin: 0 0 16px; }
#ai-egg .egg-close {
  height: 34px;
  padding: 0 18px;
  border-radius: 8px;
  border: 0;
  background: linear-gradient(135deg, #ff5c93, #a78bfa);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}


/* ---------- 角色融合（唯一生效的定义）---------- */
body.ai-ambience #ai-art { pointer-events: none !important; }
body.ai-ambience #ai-art img {
  mix-blend-mode: multiply !important;
  filter: saturate(1.02) contrast(1.02);
}
html.dark body.ai-ambience #ai-art img {
  mix-blend-mode: screen !important;
  filter: saturate(.85) contrast(1.06) brightness(1.05);
}
body.ai-ambience #ai-art {
  -webkit-mask-image: radial-gradient(120% 100% at 72% 58%, #000 42%, rgba(0,0,0,.82) 66%, transparent 84%);
  mask-image: radial-gradient(120% 100% at 72% 58%, #000 42%, rgba(0,0,0,.82) 66%, transparent 84%);
  width: 34vw;
  height: 80vh;
  right: -5vw;
  bottom: -7vh;
}
@media (max-width: 1100px) {
  body.ai-ambience #ai-art { width: 58vw; right: -14vw; bottom: -10vh; opacity: .26 !important; }
}


/* ============================================================
   手机端比例修正
   ============================================================ */
@media (max-width: 767px) {
  /* 1) 页头操作：横向两等分并靠左，不再悬浮在底部 */
  .ai-ov-actions {
    position: static !important;
    width: 100% !important;
    margin: 12px 0 0 !important;
    display: flex !important;
    gap: 10px !important;
    justify-content: flex-start !important;
    flex-wrap: nowrap !important;
  }
  .ai-ov-btn {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    justify-content: center !important;
    height: 40px !important;
    font-size: 13px !important;
  }

  /* 2) 角色更小更淡，别压住正文 */
  body.ai-ambience #ai-art {
    width: 54vw !important;
    height: 64vh !important;
    right: -12vw !important;
    bottom: -4vh !important;
    opacity: .3 !important;
  }

  /* 3) 禁止任何容器横向溢出（避免卡片内出现滚动条） */
  html, body { overflow-x: clip !important; }
  main { overflow-x: clip !important; max-width: none !important; width: auto !important; }
  main [class*="overflow"] { overflow-x: hidden !important; }
  main [class*="min-w-"] { min-width: 0 !important; }

  /* 4) 长文本与代码块换行，不撑宽 */
  main pre, main code, main [class*="font-mono"] {
    max-width: 100% !important;
    overflow-wrap: anywhere !important;
    white-space: pre-wrap !important;
  }

  /* 5) 卡片内边距与圆角适配窄屏 */
  [data-slot="card"], .card, [class*="bg-card"] { padding: 14px !important; }

  /* 6) 引导卡片内的步骤行改为单列堆叠 */
  main [class*="grid-cols-2"], main [class*="grid-cols-3"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}


/* ---------- 手机全屏铺满 ---------- */
@media (max-width: 767px) {
  html, body { min-height: 100dvh; }
  #root, #root > div, body > div:not([id^="ai-"]) { min-height: 100dvh; }
  main { min-height: calc(100dvh - 56px); padding: 12px !important; }
  main > * { max-width: none !important; width: auto !important; margin-left: 0 !important; margin-right: 0 !important; }
}


/* ============================================================
   点击穿透修复 + 手机角色尺寸（必须放文件末尾）
   ============================================================ */

/* 注入的透明全屏层（z-index 最大值）会吃掉所有点击，统一放行 */
[style*="z-index: 2147483647"][style*="position: fixed"],
[style*="position: fixed"][style*="z-index: 2147483647"] {
  pointer-events: none !important;
}

/* 兜底：任何不接收事件的装饰层都不挡点击 */
#ai-art, #ai-grain, #ai-vignette, #ai-evignette, #ai-flash, #ai-amb-text, #ai-ghost, #ai-eyes, #ai-eyes2 {
  pointer-events: none !important;
}

/* 手机端角色尺寸：用更高优先级压过文件前面的桌面规则 */
@media (max-width: 767px) {
  html body.ai-ambience #ai-art,
  html body #ai-art {
    width: 56vw !important;
    height: 62vh !important;
    right: -10vw !important;
    bottom: -3vh !important;
    opacity: .34 !important;
  }
}


/* ============================================================
   层级修正：角色沉到底层，内容永远在上
   ============================================================ */
html { background: var(--background, #0a0b10); }
body { background-color: transparent !important; }

#ai-art,
#ai-grain,
#ai-vignette,
#ai-evignette {
  z-index: -1 !important;
}

@media (min-width: 768px) {
  main, header, aside, [data-slot="sidebar"] {
    position: relative;
    z-index: 1;
  }
}

/* 内容区给一层接近实底的面，避免角色从表格里透出来 */
body main,
main.bg-background,
main[class*="bg-background"],
main > div[class*="bg-background"] {
  background-color: var(--background, #0a0b10) !important;
  background-image: none !important;
}

/* 夜间角色再压淡一点 */
@media (min-width: 768px) {
  html body.ai-ambience #ai-art { opacity: .2 !important; }
}


/* 过渡层彻底禁用（手机曾出现整屏色块） */
.ai-page-ghost { display: none !important; visibility: hidden !important; }
main.ai-page-in > * { animation: none !important; }


/* ============================================================
   切页空白修复：内容区不透明 + 加载时不透出装饰层
   ============================================================ */
body main,
main.bg-background,
main[class*="bg-background"],
main > div[class*="bg-background"] {
  background-color: var(--background, #0a0b10) !important;
  background-image: none !important;
}

/* 装饰层在内容区完全不参与合成 */
#ai-art { opacity: .18 !important; }


/* ============================================================
   手机端：去掉一切全屏装饰层（消除切页色块）
   ============================================================ */
@media (max-width: 767px) {
  #ai-grain,
  #ai-vignette,
  #ai-evignette,
  #ai-flash,
  #ai-ghost,
  #ai-eyes,
  #ai-eyes2 {
    display: none !important;
  }
  body.ai-ambience #ai-art {
    width: 42vw !important;
    height: 44vh !important;
    right: -8vw !important;
    bottom: 0 !important;
    opacity: .22 !important;
    z-index: -1 !important;
  }
  /* 内容区完全实底，切页期间只显示纯色 */
  body main,
  main[class*="bg-background"] {
    background-color: var(--background, #0a0b10) !important;
    background-image: none !important;
  }
}


/* ============================================================
   手机抽屉显示修复
   ============================================================ */
@media (max-width: 767px) {
  /* 抽屉按内容宽度展开，不再被 64px 裁掉 */
  [data-slot="sidebar"],
  aside,
  [data-slot="sheet-content"] {
    width: min(272px, 84vw) !important;
    max-width: 84vw !important;
    z-index: 70 !important;
  }
  /* 折叠态才收窄 */
  [data-slot="sidebar"][data-state="collapsed"],
  aside[data-state="collapsed"] {
    width: 64px !important;
  }
  /* 抽屉内图标+文字不换行、不裁切 */
  [data-slot="sidebar"] a,
  [data-slot="sidebar"] button,
  aside a, aside button {
    white-space: nowrap !important;
  }
  [data-slot="sidebar"] a > span,
  aside a > span {
    overflow: visible !important;
    text-overflow: clip !important;
  }
}


/* ============================================================
   套餐/卡片描述不再截断（显示完整文案）
   ============================================================ */
[data-slot="card"] [class*="truncate"],
[data-slot="card"] [class*="line-clamp"],
[data-slot="card"] p[class*="text-"] {
  white-space: normal !important;
  overflow: visible !important;
  text-overflow: clip !important;
  -webkit-line-clamp: unset !important;
  line-clamp: unset !important;
  display: block !important;
  max-height: none !important;
}
/* 订阅卡片：描述允许两行以上 */
[data-slot="card"] [class*="text-sm"][class*="text-muted"],
[data-slot="card"] [class*="text-xs"][class*="text-muted"] {
  white-space: normal !important;
  overflow: visible !important;
}

/* 更多金额按钮：与金额卡片同一行视觉 */
.ai-wallet-more {
  align-self: flex-start;
  margin-top: 10px;
  height: 32px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px dashed var(--border, rgba(255,255,255,.2));
  background: transparent;
  color: var(--muted-foreground, #8b90a0);
  font-size: 13px;
  cursor: pointer;
}
.ai-wallet-more:hover { color: var(--primary, #ff5c93); border-color: var(--primary, #ff5c93); }


/* ============================================================
   选择器穿透修复：Dialog 打开时 body 被设 pointer-events:none，
   导致 Select 的 portal 弹层也继承 none —— 手机端点不到选项。
   ============================================================ */
[data-radix-popper-content-wrapper],
[role="listbox"],
[data-slot="select-content"],
[data-radix-select-content] {
  pointer-events: auto !important;
}
[role="option"],
[data-radix-collection-item],
[data-slot="select-item"] {
  pointer-events: auto !important;
  cursor: pointer !important;
}


/* ============================================================
   下拉层级修复：弹窗内的 Select 弹层 z-index 只有 50，
   而 Dialog 是 70 —— 弹层被弹窗内容盖住，手机端点不到选项。
   ============================================================ */
[role="presentation"]:has([role="listbox"]) {
  z-index: 120 !important;
}
[role="listbox"] {
  position: relative;
  z-index: 121 !important;
}
[role="option"] {
  position: relative;
  z-index: 122 !important;
}
/* 弹窗内滚动区域不要裁剪弹层 */
[role="dialog"] [role="presentation"]:has([role="listbox"]) {
  overflow: visible !important;
}


/* ============================================================
   iOS 触控修复（必须放末尾）
   1) iOS Safari 对 body 的 overflow-x: clip/hidden 会破坏
      fixed 定位与命中测试 → 只保留 html 层裁剪
   2) 悬浮工单按钮避开 iOS 底部工具栏与安全区
   3) 所有可点元素显式开启 touch-action / 去掉点击高亮延迟
   ============================================================ */
@media (max-width: 767px) {
  html { overflow-x: hidden !important; }
  body { overflow-x: visible !important; overflow-y: visible !important; }
  main { overflow-x: hidden !important; overflow-y: visible !important; }
}

a, button, [role="button"], input, select, textarea, label {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#tk-fab {
  touch-action: manipulation;
}

@media (max-width: 767px) {
  #tk-fab {
    right: 14px;
    bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  }
  #tk-panel {
    bottom: calc(140px + env(safe-area-inset-bottom, 0px)) !important;
  }
}
