/* ═══════════════ Liquid Glass 设计系统 ═══════════════
   三个层面：光学质感（material）· 几何语法（geometry）· 交互行为（motion）
   使用规则：
   - .glass 只用于浮在内容之上的导航 / 控件层（侧栏、工具栏、输入条、弹窗、提示）
   - 内容本身使用 .surface（不透明度高、无 backdrop-filter）
   - 容器声明 --r（圆角）与 --pad（内边距），子元素用 --r-inner 得到同心圆角
   ═════════════════════════════════════════════════════ */

@property --lg-light-angle {
  syntax: "<angle>";
  inherits: true;
  initial-value: 135deg;
}

:root {
  color-scheme: light dark;

  /* ── 字体：标题 Display、正文 Text ── */
  --font-text: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;

  /* ── 间距：4pt 网格 ── */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;

  /* ── 几何：Fixed / Capsule / Concentric ── */
  --lg-radius-fixed-s: 6px;
  --lg-radius-fixed-m: 8px;
  --lg-radius-fixed-l: 12px;
  --lg-radius-capsule: 999px;

  /* ── 动效：弹簧而非线性 ── */
  --lg-easing-spring: cubic-bezier(.34, 1.56, .64, 1);
  --lg-easing-spring-soft: cubic-bezier(.34, 1.22, .64, 1);
  --lg-easing-smooth: cubic-bezier(.32, .72, 0, 1);
  --lg-duration-fast: .32s;
  --lg-duration-normal: .52s;
  --lg-duration-slow: .72s;
  --lg-press-scale: .97;

  /* ── 光源（glass.js 随指针更新；无指针时默认左上方受光） ── */
  --lg-light-x: 12%;
  --lg-light-y: -8%;

  /* ── 文字与系统色（浅色；文字对比度 ≥ 4.5:1） ── */
  --text: #1d1d1f;
  --text-2: rgba(29, 29, 31, .72);
  --text-3: rgba(29, 29, 31, .44);
  --accent: #007aff;
  --accent-text: #0062cc;
  --danger: #ff3b30;
  --danger-text: #d70015;
  --bg-base: #f6f7f9;

  /* ── 玻璃材质 ── */
  /* 白色背景上：更高的白色不透明度 + 细灰描边 + 柔和投影，保证玻璃轮廓清晰 */
  --lg-bg: rgba(255, 255, 255, .58);
  --lg-bg-strong: rgba(255, 255, 255, .86);
  --lg-bg-pressed: rgba(255, 255, 255, .7);
  --lg-border: rgba(15, 23, 42, .07);
  --lg-rim: rgba(255, 255, 255, 1);
  --lg-rim-soft: rgba(255, 255, 255, .7);
  --lg-highlight-top: rgba(255, 255, 255, .95);
  --lg-highlight-bottom: rgba(15, 23, 42, .03);
  --lg-sheen: rgba(255, 255, 255, .7);
  --lg-shadow: 0 12px 36px -14px rgba(15, 23, 42, .16), 0 1px 3px rgba(15, 23, 42, .05);
  --lg-blur: 24px;
  --lg-blur-lens: 4px;      /* 折射模式下模糊更轻，让背景细节在边缘的偏折可见 */
  --lg-saturate: 1.8;
  --lg-lens-band: 28;       /* 边缘折射带宽度（px，供 glass.js 读取） */
  --lg-lens-scale: 56;      /* 折射位移强度（px） */

  /* ── 内容表面（非玻璃） ── */
  --surface: #ffffff;
  --surface-hover: rgba(118, 118, 128, .08);
  --surface-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px -14px rgba(15, 23, 42, .18);
  --surface-border: rgba(15, 23, 42, .07);

  /* ── 控件填充 ── */
  --fill: rgba(118, 118, 128, .1);
  --fill-2: rgba(118, 118, 128, .17);
  --thumb: #ffffff;
  --sep: rgba(60, 60, 67, .12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --text: #f5f5f7;
    --text-2: rgba(245, 245, 247, .7);
    --text-3: rgba(245, 245, 247, .4);
    --accent: #0a84ff;
    --accent-text: #4aa3ff;
    --danger: #ff453a;
    --danger-text: #ff6961;
    --bg-base: #090b14;

    --lg-bg: rgba(28, 30, 42, .36);
    --lg-bg-strong: rgba(50, 52, 66, .76);
    --lg-bg-pressed: rgba(70, 72, 88, .6);
    --lg-border: rgba(255, 255, 255, .1);
    --lg-rim: rgba(255, 255, 255, .5);
    --lg-rim-soft: rgba(255, 255, 255, .16);
    --lg-highlight-top: rgba(255, 255, 255, .22);
    --lg-highlight-bottom: rgba(255, 255, 255, .05);
    --lg-sheen: rgba(255, 255, 255, .1);
    --lg-shadow: 0 20px 60px -16px rgba(0, 0, 0, .7), 0 2px 8px rgba(0, 0, 0, .3);
    --lg-blur: 32px;          /* 深色下加大模糊，维持文字可读性 */
    --lg-blur-lens: 8px;

    --surface: rgba(30, 30, 36, .74);
    --surface-hover: rgba(255, 255, 255, .06);
    --surface-shadow: 0 10px 30px -16px rgba(0, 0, 0, .7);
    --surface-border: rgba(255, 255, 255, .07);

    --fill: rgba(118, 118, 128, .24);
    --fill-2: rgba(118, 118, 128, .34);
    --thumb: rgba(255, 255, 255, .2);
    --sep: rgba(84, 84, 88, .45);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-text);
  font-size: 15px;
  line-height: 1.47;
  color: var(--text);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
h1, h2, h3 { font-family: var(--font-display); line-height: 1.2; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ───────── 背景：给玻璃提供可折射的色彩与细节 ───────── */
.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: linear-gradient(180deg, #fcfcfd 0%, #f4f5f8 100%);
}
.bg::after { /* 细点阵：让透镜折射有可见的偏折参照 */
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(15, 23, 42, .07) 1px, transparent 1.4px);
  background-size: 20px 20px;
}
.blob {
  position: absolute;
  width: 62vmax;
  height: 62vmax;
  border-radius: 50%;
  opacity: .22;   /* 偏白风格：只在角落留一层很淡的色彩 */
  will-change: transform;
  animation: lg-drift 28s ease-in-out infinite alternate;
}
.b1 { background: radial-gradient(circle, #4f9dff 0%, rgba(79, 157, 255, 0) 64%); top: -24vmax; left: -18vmax; }
.b2 { background: radial-gradient(circle, #c56bff 0%, rgba(197, 107, 255, 0) 64%); top: -14vmax; right: -24vmax; animation-duration: 34s; }
.b3 { background: radial-gradient(circle, #ff8a5c 0%, rgba(255, 138, 92, 0) 64%); bottom: -30vmax; left: 8vmax; animation-duration: 31s; animation-delay: -8s; }
.b4 { background: radial-gradient(circle, #2ee6b4 0%, rgba(46, 230, 180, 0) 64%); bottom: -26vmax; right: -14vmax; animation-duration: 38s; animation-delay: -14s; }
.b5 { background: radial-gradient(circle, #ffd25e 0%, rgba(255, 210, 94, 0) 62%); width: 38vmax; height: 38vmax; top: 30%; left: 40%; animation-duration: 25s; animation-delay: -4s; }
@keyframes lg-drift {
  0% { transform: translate3d(0, 0, 0) scale(1); }
  50% { transform: translate3d(7vmax, 4vmax, 0) scale(1.12); }
  100% { transform: translate3d(-5vmax, 9vmax, 0) scale(.94); }
}
@media (prefers-color-scheme: dark) {
  .bg { background: linear-gradient(155deg, #0a1030 0%, #170a2a 48%, #24101a 100%); }
  .bg::after { background-image: radial-gradient(rgba(255, 255, 255, .5) 1px, transparent 1.4px); opacity: .12; }
  .blob { opacity: .5; }
}
.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; pointer-events: none; }

/* ═════════ 材质 ═════════ */
.glass, .surface {
  --r: 28px;
  --pad: 0px;
  --r-inner: max(var(--lg-radius-fixed-m), calc(var(--r) - var(--pad)));  /* 同心圆角 */
  border-radius: var(--r);
}

/* 玻璃：blur + 饱和（吸收背后色相）+ 镜面高光 + 内阴影 + 悬浮投影 */
.glass {
  position: relative;
  isolation: isolate;
  background: var(--lg-bg);
  -webkit-backdrop-filter: blur(var(--lg-blur)) saturate(var(--lg-saturate));
  backdrop-filter: blur(var(--lg-blur)) saturate(var(--lg-saturate));
  box-shadow:
    var(--lg-shadow),
    inset 0 1px 0 var(--lg-highlight-top),       /* 顶部镜面高光 */
    inset 0 -1px 0 var(--lg-highlight-bottom),   /* 底部微弱反光 */
    inset 0 0 0 .5px var(--lg-border);           /* 背光侧也保留可见边缘 */
}
/* 方向性镜面边缘：随 --lg-light-angle 旋转 */
.glass::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  padding: 1.25px;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(var(--lg-light-angle), var(--lg-rim) 0%, transparent 30%, transparent 68%, var(--lg-rim-soft) 100%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
}
/* 表面光泽：光斑位置跟随光源 */
.glass::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(130% 80% at var(--lg-light-x) var(--lg-light-y), var(--lg-sheen), transparent 48%);
}
/* 透镜折射（仅 Chromium，由 glass.js 按元素尺寸生成边缘位移滤镜；其余浏览器保持 blur-only） */
.refract .glass.lens {
  -webkit-backdrop-filter: var(--lg-lens,) blur(var(--lg-blur-lens)) saturate(var(--lg-saturate));
  backdrop-filter: var(--lg-lens,) blur(var(--lg-blur-lens)) saturate(var(--lg-saturate));
}
.glass.strong { --lg-bg: var(--lg-bg-strong); }

/* 内容表面：不玻璃化 */
.surface {
  background: var(--surface);
  box-shadow: var(--surface-shadow), inset 0 0 0 .5px var(--surface-border);
}

/* ═════════ 控件 ═════════ */
.btn {
  appearance: none;
  border: 0;
  height: 40px;
  padding: 0 var(--sp-5);
  border-radius: var(--lg-radius-capsule);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: var(--fill);
  cursor: pointer;
  white-space: nowrap;
  box-shadow: inset 0 1px 0 var(--lg-highlight-bottom);
  transition: transform var(--lg-duration-fast) var(--lg-easing-spring), background .2s, filter .2s, opacity .2s;
}
.btn:hover { background: var(--fill-2); }
.btn:active { transform: scale(var(--lg-press-scale)); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn.primary {
  color: #fff;
  background: linear-gradient(180deg, #3a95ff 0%, #0a6cff 100%);
  box-shadow: 0 8px 22px -8px rgba(0, 110, 255, .75), inset 0 1px 0 rgba(255, 255, 255, .5), inset 0 -1px 0 rgba(0, 0, 0, .12);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.primary:active { filter: brightness(.95); }
.btn.danger { color: var(--danger-text); background: color-mix(in srgb, var(--danger) 13%, transparent); }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 21%, transparent); }
.btn.sm { height: 32px; padding: 0 var(--sp-4); font-size: 14px; }

.icon-btn {
  appearance: none;
  border: 0;
  width: 36px;
  height: 36px;
  flex: none;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  color: var(--text-2);
  background: transparent;
  cursor: pointer;
  transition: transform var(--lg-duration-fast) var(--lg-easing-spring), background .2s, color .2s;
}
.icon-btn:hover { background: var(--fill); color: var(--text); }
.icon-btn:active { transform: scale(.9); background: var(--fill-2); }
.icon-btn.sm { width: 28px; height: 28px; }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
svg.fill { fill: currentColor; stroke: none; }
.icon-btn.sm svg { width: 16px; height: 16px; }

:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

.field {
  width: 100%;
  height: 44px;
  padding: 0 var(--sp-3);
  border: 0;
  border-radius: var(--r-inner, var(--lg-radius-fixed-l));
  font-size: 16px;   /* ≥16px 防止 iOS 聚焦缩放 */
  background: var(--fill);
  outline: none;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .05);
  transition: box-shadow var(--lg-duration-fast) var(--lg-easing-smooth), background .25s;
}
.field::placeholder { color: var(--text-3); }
.field:focus {
  background: var(--lg-bg-strong);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent), inset 0 0 0 1px color-mix(in srgb, var(--accent) 60%, transparent);
}
textarea.field { height: auto; min-height: 96px; padding: var(--sp-3); resize: vertical; line-height: 1.5; }
select.field {
  appearance: none;
  padding-right: 36px;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

/* 分段控件：胶囊容器 + 胶囊滑块（同心） */
.segmented {
  --x: 0px;
  --w: 0px;
  position: relative;
  display: inline-flex;
  flex: none;
  padding: 2px;
  border-radius: var(--lg-radius-capsule);
  background: var(--fill);
}
.segmented .thumb {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 0;
  width: var(--w);
  transform: translateX(var(--x));
  border-radius: var(--lg-radius-capsule);
  background: var(--thumb);
  box-shadow: 0 3px 10px rgba(0, 0, 0, .12), inset 0 1px 0 rgba(255, 255, 255, .75), inset 0 0 0 .5px rgba(255, 255, 255, .5);
  transition: transform var(--lg-duration-normal) var(--lg-easing-spring), width var(--lg-duration-normal) var(--lg-easing-spring);
}
.segmented > button {
  position: relative;
  z-index: 1;
  appearance: none;
  border: 0;
  height: 32px;
  padding: 0 var(--sp-4);
  border-radius: var(--lg-radius-capsule);
  background: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
  transition: color .25s;
}
.segmented > button[aria-pressed="true"] { color: var(--text); }
.segmented.wide { display: flex; }
.segmented.wide > button { flex: 1; }

/* 提示：胶囊玻璃，内部按钮同心 */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--sp-6) + env(safe-area-inset-bottom));
  z-index: 100;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  max-width: calc(100vw - 32px);
  min-height: 48px;
  padding: 8px 8px 8px var(--sp-5);
  font-weight: 500;
  --r: 24px;
  --lg-bg: var(--lg-bg-strong);
  transform: translate(-50%, 160%);
  transition: transform var(--lg-duration-normal) var(--lg-easing-spring);
}
.toast.show { transform: translate(-50%, 0); }
.toast:not(:has(.btn)) { padding-right: var(--sp-5); }

/* ═════════ 登录页 ═════════ */
.login-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--sp-6) var(--sp-4);
  overflow: auto;
}
.login-box { width: min(384px, 100%); }
.login-card {
  --r: 36px;
  --pad: 24px;
  width: 100%;
  padding: 40px var(--pad) var(--pad);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  text-align: center;
  animation: lg-enter var(--lg-duration-slow) var(--lg-easing-spring) both;
}
.app-icon {
  width: 76px;
  height: 76px;
  margin: 0 auto var(--sp-2);
  border-radius: 22px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(160deg, #64d2ff 0%, #0a7aff 55%, #5e5ce6 100%);
  box-shadow: 0 14px 30px -10px rgba(10, 122, 255, .7), inset 0 1px 0 rgba(255, 255, 255, .65), inset 0 -2px 6px rgba(0, 0, 0, .12);
}
.app-icon svg { width: 40px; height: 40px; stroke-width: 2.4; }
.login-card h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -.022em; }
.login-card p { margin: 0 0 var(--sp-2); color: var(--text-2); }
.code-input { height: 52px; text-align: center; font-size: 20px; letter-spacing: .28em; }
.code-input::placeholder { letter-spacing: normal; font-size: 16px; }
.login-card .btn { height: 48px; font-size: 16px; }
.login-card .login-error { min-height: 20px; margin: 0; font-size: 13px; color: var(--danger-text); }
.login-foot { margin-top: var(--sp-4); font-size: 12px; color: var(--text-3); text-align: center; }

/* ═════════ 动效原语 ═════════ */
.shake { animation: lg-shake .5s cubic-bezier(.36, .07, .19, .97); }
@keyframes lg-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}
@keyframes lg-enter { from { opacity: 0; transform: scale(.95) translateY(8px); } }
@keyframes lg-fade { from { opacity: 0; } }

/* ═════════ 性能降级：glass.js 检测到帧率过低时加 .lg-lite ═════════ */
.lg-lite {
  --lg-blur: 12px;
  --lg-saturate: 1.4;
}
.lg-lite .blob { animation-play-state: paused; }
.lg-lite .glass::after { display: none; }

/* ═════════ 无障碍降级 ═════════ */
/* 1. 减少动态：去掉弹簧与位移，仅保留透明度过渡 */
@media (prefers-reduced-motion: reduce) {
  :root {
    --lg-easing-spring: ease-out;
    --lg-easing-spring-soft: ease-out;
    --lg-press-scale: 1;
  }
  .blob { animation: none; }
  .shake { animation: none; }
  .login-card { animation-name: lg-fade; }
  .segmented .thumb { transition-property: opacity; }
  .toast { transform: translate(-50%, 0); opacity: 0; visibility: hidden; transition: opacity .2s, visibility .2s; }
  .toast.show { opacity: 1; visibility: visible; }
  .icon-btn:active { transform: none; }
}

/* 2. 减少透明度：玻璃替换为接近实色的表面 */
@media (prefers-reduced-transparency: reduce) {
  :root {
    --lg-bg: rgba(246, 246, 248, .97);
    --lg-bg-strong: #fff;
    --surface: #fff;
    --thumb: #fff;
  }
  .glass, .refract .glass.lens { -webkit-backdrop-filter: none; backdrop-filter: none; }
  .glass::after { display: none; }
  .blob { opacity: .35; animation: none; }
  .bg::after { display: none; }
  dialog::backdrop { -webkit-backdrop-filter: none !important; backdrop-filter: none !important; }
}
@media (prefers-reduced-transparency: reduce) and (prefers-color-scheme: dark) {
  :root {
    --lg-bg: rgba(28, 28, 32, .97);
    --lg-bg-strong: #2c2c32;
    --surface: #1c1c20;
    --thumb: #48484e;
  }
}

/* 3. 高对比度：实色背景 + 可见边框 */
@media (prefers-contrast: more) {
  :root {
    --text-2: rgba(0, 0, 0, .86);
    --text-3: rgba(0, 0, 0, .62);
    --accent-text: #0040dd;
    --danger-text: #ad0010;
    --lg-bg: #fff;
    --lg-bg-strong: #fff;
    --surface: #fff;
    --sep: rgba(0, 0, 0, .45);
    --hc-border: rgba(0, 0, 0, .7);
  }
  .glass, .surface, .refract .glass.lens {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    box-shadow: 0 0 0 1px var(--hc-border);
  }
  .glass::before, .glass::after { display: none; }
  .field, .segmented, .btn:not(.primary), .chip, .tile, .nav-item.active { box-shadow: inset 0 0 0 1px var(--hc-border) !important; }
  .blob, .bg::after { display: none; }
}
@media (prefers-contrast: more) and (prefers-color-scheme: dark) {
  :root {
    --text-2: rgba(255, 255, 255, .88);
    --text-3: rgba(255, 255, 255, .64);
    --accent-text: #7cbcff;
    --danger-text: #ff8a84;
    --lg-bg: #000;
    --lg-bg-strong: #1c1c1e;
    --surface: #111;
    --sep: rgba(255, 255, 255, .45);
    --hc-border: rgba(255, 255, 255, .75);
  }
}
