/* ============================================================
   按钮系统 v1 · 2026-11-25
   ------------------------------------------------------------
   五型 × 两档。**只有这两档**（lg 36 / md 32）——
   多一档就多一次「这里该用哪个」的犹豫。

   玻璃钻石感 = 四个切面件，缺一件就退化成一块扁色：
       ① 顶亮线（inset 0 1px 0 白）
       ② 斜向高光（135° 白 → 透明，用 ::before）
       ③ 底暗线（inset 0 -1px 0 墨）
       ④ 带主色的外投影（灰投影会让水晶发脏）

   🔴 三件事不许做：
      · 不许跨色相渐变（同一色相走 6~8%，跨色相读作广告）
      · 不许一屏两个 .ubtn--primary
      · 不许给按钮写死 width（宽 = 字 + padding）

   🔴 为什么叫 .ubtn 而不是 .btn：App.vue 里已经有 4 处 `btn btn-primary`
      （另一套实现）。沿用 .btn 会把在用的按钮一起改掉 —— 改名是为了
      迁移期两套并存、互不影响。全站替换完成后删旧的 .btn。

   用法：
     <button class="ubtn ubtn--primary">去配置</button>
     <button class="ubtn ubtn--md ubtn--secondary">取消</button>
     <button class="ubtn ubtn--soft"><svg …></svg>继续</button>
     <button class="ubtn ubtn--ghost">拆开</button>
   加载中：
     <button class="ubtn ubtn--primary is-loading">
       <span class="ubtn__bl"><i></i><i></i><i></i></span>保存中
     </button>
   ============================================================ */

.ubtn {
  /* 尺寸全部走变量：加一档只改这里，页面不用动 */
  --btn-h: 36px;
  --btn-px: 18px;
  --btn-r: 10px;
  --btn-fs: 13px;
  --btn-fw: 600;
  --btn-ic: 14px;
  --btn-gloss: 0.2;

  position: relative;
  isolation: isolate;            /* 让 ::before 的高光待在背景之上、文字之下 */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--btn-h);
  padding: 0 var(--btn-px);
  border: 0;
  border-radius: var(--btn-r);
  font-family: inherit;
  font-size: var(--btn-fs);
  font-weight: var(--btn-fw);
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  vertical-align: middle;
  transition: background-color 0.16s ease, box-shadow 0.16s ease, transform 0.08s ease;
  /* ① ③：一条 inset 同时给顶亮线与底暗线（比两条 border 干净） */
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4),
              inset 0 -1px 0 rgba(31, 35, 51, 0.07);
}

/* 中档 */
.ubtn--md {
  --btn-h: 32px;
  --btn-px: 14px;
  --btn-r: 9px;
  --btn-fs: 12.5px;
  --btn-ic: 13px;
}

/* ② 斜向高光 */
.ubtn::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(255, 255, 255, var(--btn-gloss)), transparent 42%);
  pointer-events: none;
}

/* ---------------- 五型 ---------------- */

.ubtn--primary {
  color: #fff;
  --btn-gloss: 0;                    /* 高光已经在 background-image 里，别再叠一层 */
  /* 🔴 2026-11-25 23:38 波哥：「水晶紫太单一」+「光面别太重，不能影响按钮本身的颜色视觉」。
     体积感由**紫色自己的明暗**承担（#9A90FD → #5647D8），白光只留很低一档。
     六层从上到下，顺序不许换 —— 换一层就被下一层吃掉：
       ① 镜面   斜扁椭圆，只在左上，两端渐隐（硬边像贴白纸）
       ② 棱     42° 窄亮带，硬边才是切面
       ③ 厚度   顶亮线下面必须有"厚"，否则像贴纸
       ④ 底反光 最关键的一笔，没有它永远是平面
       ⑤ 右内暗 只有顶部暗会像一块板
       ⑥ 主体   顶亮 → 中线急降 → 底部更深 → 底缘微回亮 */
  background-image:
    radial-gradient(62% 46% at 33% 17%,
      rgba(255, 255, 255, 0.28) 0%,
      rgba(255, 255, 255, 0.11) 40%,
      rgba(255, 255, 255, 0) 72%),
    linear-gradient(42deg,
      rgba(255, 255, 255, 0) 30%,
      rgba(255, 255, 255, 0.17) 45%,
      rgba(255, 255, 255, 0.03) 52%,
      rgba(255, 255, 255, 0.03) 68%,
      rgba(255, 255, 255, 0) 82%),
    linear-gradient(180deg,
      rgba(43, 42, 94, 0.15) 0%,
      rgba(43, 42, 94, 0) 26%),
    linear-gradient(180deg,
      rgba(255, 255, 255, 0) calc(100% - 2.6px),
      rgba(255, 255, 255, 0.26) calc(100% - 2.6px)),
    linear-gradient(100deg,
      rgba(43, 42, 94, 0) 58%,
      rgba(43, 42, 94, 0.10) 100%),
    linear-gradient(168deg,
      #9a90fd 0%, #7f71f7 38%, #6a5bee 52%,
      #5b4cdf 80%, #5647d8 94%, #6152e1 100%);
  /* ④ 带主色的外投影 —— 灰投影会让水晶发脏 */
  box-shadow: inset 0 1.5px 0 rgba(255, 255, 255, 0.38),
              inset 0 -1px 0 rgba(31, 35, 51, 0.06),
              0 1px 2px rgba(31, 35, 51, 0.12),
              0 6px 18px -6px rgba(91, 84, 224, 0.34);
}
.ubtn--primary:hover {
  /* hover 只整体提亮一档，六层结构不动 —— 结构一变就读作"换了个按钮" */
  background-image:
    radial-gradient(62% 46% at 33% 17%,
      rgba(255, 255, 255, 0.34) 0%,
      rgba(255, 255, 255, 0.13) 40%,
      rgba(255, 255, 255, 0) 72%),
    linear-gradient(42deg,
      rgba(255, 255, 255, 0) 30%,
      rgba(255, 255, 255, 0.19) 45%,
      rgba(255, 255, 255, 0.03) 52%,
      rgba(255, 255, 255, 0.03) 68%,
      rgba(255, 255, 255, 0) 82%),
    linear-gradient(180deg,
      rgba(43, 42, 94, 0.13) 0%,
      rgba(43, 42, 94, 0) 26%),
    linear-gradient(180deg,
      rgba(255, 255, 255, 0) calc(100% - 2.6px),
      rgba(255, 255, 255, 0.30) calc(100% - 2.6px)),
    linear-gradient(100deg,
      rgba(43, 42, 94, 0) 58%,
      rgba(43, 42, 94, 0.09) 100%),
    linear-gradient(168deg,
      #a49bfe 0%, #8879f9 38%, #7466f1 52%,
      #6555e6 80%, #5f50de 94%, #6a5be7 100%);
}

.ubtn--secondary {
  color: #4a4a60;
  background: #fff;
  --btn-gloss: 0.1;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9),
              inset 0 -1px 0 rgba(31, 35, 51, 0.04),
              0 0 0 1px #e4e1f0,
              0 1.5px 3px rgba(59, 53, 96, 0.1);
}
.ubtn--secondary:hover {
  background: #fbf9fe;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9),
              inset 0 -1px 0 rgba(31, 35, 51, 0.04),
              0 0 0 1px #d3cee6,
              0 1.5px 3px rgba(59, 53, 96, 0.1);
}

.ubtn--soft {
  color: #5f58e8;
  --btn-gloss: 0.14;
  background-image: linear-gradient(180deg, #f4f2ff, #e7e4fc);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85),
              inset 0 -1px 0 rgba(31, 35, 51, 0.05);
}
.ubtn--soft:hover {
  background-image: linear-gradient(180deg, #f9f7ff, #efecfd);
}

.ubtn--ghost {
  color: #8c87a0;
  background: transparent;
  --btn-gloss: 0;
  padding: 0 6px;
  box-shadow: none;
}
.ubtn--ghost:hover {
  color: #4a4a60;
  background: #f7f5fd;
}

.ubtn--danger {
  color: #e5484d;
  background: #fff;
  --btn-gloss: 0;               /* 危险操作要「实」，加高光会读作可撤销 */
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9),
              inset 0 -1px 0 rgba(31, 35, 51, 0.04),
              0 0 0 1px #f3c9cb,
              0 1.5px 3px rgba(59, 53, 96, 0.1);
}
.ubtn--danger:hover {
  background: #fef6f6;
}

/* ---------------- 状态 ---------------- */

.ubtn:active {
  transform: translateY(0.5px);
}
.ubtn:disabled,
.ubtn[aria-disabled='true'] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}
/* 聚焦环挪到外面，别用描边宽度表达 —— 会让按钮在聚焦时变胖 */
.ubtn:focus-visible {
  outline: 2px solid #6c67f5;
  outline-offset: 2px;
}

/* 图标 */
.ubtn > svg {
  width: var(--btn-ic);
  height: var(--btn-ic);
  flex: 0 0 auto;
}

/* 加载中：文字保留、**宽度不变**（变宽会把旁边的字挤走） */
.ubtn.is-loading {
  pointer-events: none;
}
.ubtn__bl {
  display: none;
  align-items: flex-end;
  gap: 2.6px;
  height: 12px;
}
.ubtn.is-loading .ubtn__bl {
  display: inline-flex;
}
.ubtn__bl i {
  display: block;
  width: 3.6px;
  height: 100%;
  border-radius: 1.2px;
  background: currentColor;
  transform-origin: bottom;
  animation: btnbl 1.2s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}
.ubtn__bl i:nth-child(1) { animation-delay: 0s; }
.ubtn__bl i:nth-child(2) { animation-delay: 0.14s; }
.ubtn__bl i:nth-child(3) { animation-delay: 0.28s; }

@keyframes btnbl {
  0%, 60%, 100% { transform: scaleY(0.55); }
  30%           { transform: scaleY(1); }
}

@media (prefers-reduced-motion: reduce) {
  .ubtn { transition: none; }
  .ubtn:active { transform: none; }
  .ubtn__bl i { animation: none; transform: scaleY(0.7); }
}

/* ---------------- 提交结果（JS 加类，900ms 后自己去掉） ----------------
   🔴 绿/红只保持 900ms 就回原样。一直绿着，用户会以为按钮坏了。 */

.ubtn.is-success {
  background-image: none;
  background-color: #12b36b;
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4),
              inset 0 -1px 0 rgba(31, 35, 51, 0.14),
              0 0 0 6px rgba(18, 179, 107, 0.14);
  transition: background-color 0.18s ease, box-shadow 0.32s ease;
}

.ubtn.is-success .ubtn__ok {
  display: inline-block;
  animation: ubtn-tick 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.ubtn.is-error {
  background-image: none;
  background-color: #e5484d;
  color: #fff;
  animation: ubtn-shake 0.32s ease-in-out;
}

@keyframes ubtn-tick {
  0%   { transform: scale(0.6); opacity: 0; }
  60%  { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes ubtn-shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-3px); }
  40%      { transform: translateX(3px); }
  60%      { transform: translateX(-2px); }
  80%      { transform: translateX(2px); }
}

@media (prefers-reduced-motion: reduce) {
  .ubtn.is-error { animation: none; }
  .ubtn.is-success .ubtn__ok { animation: none; }
}
