/* ==========================================================================
   iOS 26 液态玻璃开关（设置 → 实验性 → 按钮样式）
   只在 html[data-switch-style="glass"] 时生效；视觉层 .lg-sw 由 liquid-switch.js 插入。
   规格参考 iOS 26 UISwitch（63×28pt 轨道、37×24pt 胶囊旋钮），按比例缩放：
   开启 #34C759 / 深色 #30D158，关闭为系统填充灰；按下时旋钮弹起成比轨道更高的透明玻璃。
   动画由 liquid-switch.js 的弹簧物理逐帧驱动，这里只负责外观。
   ========================================================================== */

html[data-switch-style="glass"] {
  --lg-w: 58px;
  --lg-h: 26px;
  --lg-kw: 34px;
  --lg-kh: 22px;
  --lg-in: 2px;
  --lg-lw: 54px;               /* 浮起后的玻璃尺寸（iOS 26 实拍：宽 ≈ 2.07、高 ≈ 1.36 倍轨道高） */
  --lg-lh: 35px;
  --lg-rx: .63;                /* 静止时的缩放 = 旋钮 / 玻璃（脚本接管前的初始外观用） */
  --lg-ry: .629;
  --lg-on: #007aff;
  --lg-off: rgba(120, 120, 128, .16);
  --lg-slide: cubic-bezier(.32, 1.18, .42, 1);
}
/* 深色模式取自 iOS 26 实拍（设置 → VPN）：关闭 #59595E（在 #1C1C1E 卡片上） */
html[data-theme="dark"][data-switch-style="glass"] {
  --lg-on: #4c8df6;
  --lg-off: rgba(120, 120, 128, .66);
}

/* 开启时的颜色（设置 → 实验性 → 开关颜色；html[data-switch-tint] 由首屏脚本 / switch-style.js 写入）
   blue：默认，macOS 26 / iOS 26 的蓝色强调色（深色模式取自 macOS 实拍 #4C8DF6）
   green：iOS 系统开关的绿（深色取自 iOS 26 实拍 #67CE67） accent：跟随网站主题色 custom：自选 */
html[data-switch-style="glass"] { --lg-on: #007aff; }
html[data-switch-style="glass"][data-switch-tint="green"] { --lg-on: #34c759; }
html[data-theme="dark"][data-switch-style="glass"][data-switch-tint="green"] { --lg-on: #67ce67; }
html[data-switch-style="glass"][data-switch-tint="accent"] { --lg-on: var(--accent, #007aff); }
html[data-switch-style="glass"][data-switch-tint="custom"] { --lg-on: var(--lg-tint-custom, #007aff); }

/* 选回经典样式时，已插入的视觉层直接隐藏 */
html:not([data-switch-style="glass"]) .lg-sw { display: none; }

/* ---------------------------------------------------------------- 宿主控件：只保留尺寸、焦点和点击区域 */
html[data-switch-style="glass"] .dsh-switch,
html[data-switch-style="glass"] .switch > input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  box-sizing: border-box;
  flex: none;
  width: var(--lg-w);
  height: var(--lg-h);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: calc(var(--lg-h) / 2);
  background: var(--lg-off);
  box-shadow: none;
  overflow: visible;
  cursor: pointer;
  touch-action: pan-y;               /* 横向手势留给拖动，竖向仍能滚动页面 */
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  transition: background .3s ease;
}
html[data-switch-style="glass"] .dsh-switch::before,
html[data-switch-style="glass"] .switch > input[type="checkbox"]::before { content: none; display: none; }

/* 引擎还没加载完（或加载失败）时的静态外观：同样的轨道和白色胶囊旋钮，只是没有玻璃动画 */
html[data-switch-style="glass"] .dsh-switch[aria-checked="true"],
html[data-switch-style="glass"] .switch > input[type="checkbox"]:checked { background: var(--lg-on); }
html[data-switch-style="glass"] .dsh-switch::after,
html[data-switch-style="glass"] .switch > input[type="checkbox"]::after {
  content: "";
  display: block;
  position: absolute;
  top: var(--lg-in);
  left: var(--lg-in);
  width: var(--lg-kw);
  height: var(--lg-kh);
  border-radius: calc(var(--lg-kh) / 2);
  background: #fff;
  box-shadow: 0 1px 1.5px rgba(0, 0, 0, .12), 0 3px 8px -2px rgba(0, 0, 0, .16);
  transform: none;
  transition: translate .45s var(--lg-slide);
}
html[data-switch-style="glass"] .dsh-switch[aria-checked="true"]::after,
html[data-switch-style="glass"] .switch > input[type="checkbox"]:checked::after {
  transform: none;
  translate: calc(var(--lg-w) - var(--lg-kw) - var(--lg-in) * 2) 0;
}

/* 引擎接管后（.lg-host）：宿主只负责尺寸、焦点和点击区域，外观全部交给 .lg-sw */
html[data-switch-style="glass"] :is(.dsh-switch, .switch > input[type="checkbox"]).lg-host:is(*, [aria-checked="true"], :checked) {
  background: transparent;
  transition: none;
}
html[data-switch-style="glass"] :is(.dsh-switch, .switch > input[type="checkbox"]).lg-host:is(*, [aria-checked="true"], :checked)::after {
  content: none;
  display: none;
}

html[data-switch-style="glass"] .switch {
  position: relative;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------------------------------------------------------------- 视觉层定位 */
.lg-sw {
  position: absolute;
  display: block;
  width: var(--lg-w);
  height: var(--lg-h);
  pointer-events: none;
  z-index: 1;
}
.dsh-switch > .lg-sw { left: 0; top: 0; }
.switch > input + .lg-sw { left: 0; top: 50%; margin-top: calc(var(--lg-h) / -2); }

/* ---------------------------------------------------------------- 轨道 */
.lg-track {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: calc(var(--lg-h) / 2);
  background: var(--lg-off);
}
.lg-fill {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--lg-on);
  opacity: 0;
}
.dsh-switch[aria-checked="true"] > .lg-sw .lg-fill,
.switch > input:checked + .lg-sw .lg-fill { opacity: 1; }   /* 脚本接管前的初始值 */

/* ---------------------------------------------------------------- 旋钮盒子：尺寸 = 浮起后的玻璃，静止时由脚本缩小成旋钮 */
.lg-knob {
  position: absolute;
  left: calc(var(--lg-in) + var(--lg-kw) / 2 - var(--lg-lw) / 2);
  top: calc(var(--lg-h) / 2 - var(--lg-lh) / 2);
  width: var(--lg-lw);
  height: var(--lg-lh);
  border-radius: 999px;
  transform-origin: 50% 50%;
  transform: scale(var(--lg-rx), var(--lg-ry));
  backface-visibility: hidden;
}
.dsh-switch[aria-checked="true"] > .lg-sw .lg-knob,
.switch > input:checked + .lg-sw .lg-knob {
  transform: translateX(calc(var(--lg-w) - var(--lg-kw) - var(--lg-in) * 2)) scale(var(--lg-rx), var(--lg-ry));
}
.lg-face,
.lg-lens,
.lg-rim,
.lg-optic {
  position: absolute;
  inset: 0;
  border-radius: inherit;
}

/* 静止的白色旋钮（盒子静止时约缩小到 0.65 倍，阴影按放大前的尺寸写） */
.lg-face {
  background: #fff;
  box-shadow:
    0 0 0 .75px rgba(0, 0, 0, .04),
    0 4px 12px -2px rgba(0, 0, 0, .16),
    0 1.5px 2.5px rgba(0, 0, 0, .1);
}
html[data-theme="dark"] .lg-face {
  box-shadow:
    0 0 0 .75px rgba(0, 0, 0, .25),
    0 4px 12px -2px rgba(0, 0, 0, .45),
    0 1.5px 3px rgba(0, 0, 0, .3);
}

/* ---------------------------------------------------------------- 液态玻璃
   玻璃层比看到的胶囊大 --lg-pad 一圈（折射要读到胶囊外几像素的内容），再用 clip-path 裁回胶囊。
   投影放在单独的 .lg-shade 上，因为 clip-path 会把玻璃自己的 box-shadow 一起裁掉。 */
.lg-lens {
  --lg-filter: blur(0px);
  inset: calc(var(--lg-pad, 0px) * -1);
  border-radius: 0;
  overflow: visible;
  opacity: 0;
  isolation: isolate;
  -webkit-clip-path: inset(var(--lg-pad, 0px) round calc(var(--lg-lh) / 2));
  clip-path: inset(var(--lg-pad, 0px) round calc(var(--lg-lh) / 2));
}
.lg-shade {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 0 0 .5px rgba(0, 0, 0, .14), 0 6px 18px -6px rgba(0, 0, 0, .22), 0 1px 3px rgba(0, 0, 0, .06);
}
html[data-theme="dark"] .lg-shade {
  box-shadow: 0 0 0 .75px rgba(0, 0, 0, .55), 0 8px 22px -6px rgba(0, 0, 0, .55);
}

/* Chromium：真实的背景折射（位移贴图由 liquid-switch.js 按玻璃尺寸生成）。
   实拍里玻璃不带颜色、也不提亮：只做折射，饱和度几乎不动。 */
html[data-lg-refract="1"] .lg-lens {
  -webkit-backdrop-filter: var(--lg-filter) saturate(1.04);
  backdrop-filter: var(--lg-filter) saturate(1.04);
}
/* 实拍深色模式下，玻璃里的底色比外面略亮一点点（玻璃本身的一层极淡的白） */
html[data-theme="dark"] .lg-lens { background: rgb(255 255 255 / calc(.07 * var(--lg-k, 1))); }   /* --lg-k：折射强度，脚本逐帧写 */
html[data-lg-refract="1"] .lg-optic { display: none; }

/* 其他浏览器（Safari / Firefox）：玻璃里画一份放大、经过同一张位移贴图折射的轨道 */
.lg-optic {
  border-radius: 0;
  overflow: hidden;
  background: var(--lg-under, transparent);
}
.lg-mirror {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--lg-w);
  height: var(--lg-h);
  border-radius: calc(var(--lg-h) / 2);
  overflow: hidden;
  background: var(--lg-mirror-off, var(--lg-off));
  transform-origin: 0 0;
}
.lg-mirror > .lg-fill { border-radius: inherit; }
/* 实拍里透过玻璃看到的轨道边缘是虚的 */
html:not([data-lg-refract="1"]) .lg-mirror { filter: blur(.7px); }
/* 边缘一圈的轨道颜色：已停用。它在玻璃上下沿画出一条轨道色的细条（两端还是硬切口），
   和 Chromium 那边去掉的「边缘折返」是同一个毛病；实拍（iOS / macOS 26）里没有。节点保留，结构不变。 */
.lg-band { display: none; }
/* 深色模式：玻璃本身一层极淡的白（实拍约 7%） */
html[data-theme="dark"] .lg-optic::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, .07);
}

/* 玻璃边缘（对照 macOS 26 实拍）：一圈清楚但很细的亮边，带一点点色散的颜色——
   左边偏蓝、上沿和右上偏白、右边微微泛青、下沿偏紫；外面再贴一圈极细的暗线（.lg-shade）。
   不做顶部白色渐变或粗内阴影（会像塑料），立体感交给折射。 */
.lg-rim {
  /* 亮边放在玻璃层外面（不受裁切），透明度由脚本跟玻璃同步 */
  inset: 0;
  border-radius: calc(var(--lg-lh) / 2);
  opacity: 0;
  pointer-events: none;
  padding: .8px;
  /* 不能用 mix-blend-mode：旋钮里一有混合模式，Chromium 就把整个旋钮单独画一层，
     玻璃的 backdrop-filter 读不到后面的轨道，折射直接消失 */
  background: conic-gradient(from 0deg,
    rgb(255 255 255 / .42) 0deg,
    rgb(228 242 255 / .6) 55deg,
    rgb(205 255 236 / .48) 100deg,
    rgb(196 178 255 / .4) 150deg,
    rgb(168 176 255 / .28) 205deg,
    rgb(118 168 255 / .46) 262deg,
    rgb(178 214 255 / .58) 312deg,
    rgb(255 255 255 / .42) 360deg);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  box-shadow: none;
}

/* 含开关的毛玻璃卡片（由 liquid-switch.js 第一次浮起时加上）：卡片自己的 backdrop-filter 挪到 ::before，
   卡片就不再是 backdrop 的边界，开关玻璃能折射到卡片后面的页面（否则会透出没折射的轨道，形成重影）。 */
html[data-switch-style="glass"] .lg-bd-host {
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
  isolation: isolate;
}
html[data-switch-style="glass"] .lg-bd-host::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  pointer-events: none;
  -webkit-backdrop-filter: var(--lg-bd);
  backdrop-filter: var(--lg-bd);
}

/* ---------------------------------------------------------------- 紧凑尺寸（文件管理、日志面板） */
html[data-switch-style="glass"] :is(.fm-scope, .server-log-auto) {
  --lg-w: 48px;
  --lg-h: 22px;
  --lg-kw: 28px;
  --lg-kh: 18px;
  --lg-lw: 46px;
  --lg-lh: 30px;
  --lg-rx: .609;
  --lg-ry: .6;
}

/* ---------------------------------------------------------------- 状态与无障碍 */
html[data-switch-style="glass"] :is(.dsh-switch, .switch > input[type="checkbox"]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
html[data-switch-style="glass"] :is(.dsh-switch, .switch > input[type="checkbox"]):disabled,
html[data-switch-style="glass"] .switch > input[type="checkbox"]:disabled + .lg-sw { cursor: not-allowed; }
html[data-switch-style="glass"] :is(.dsh-switch, .switch > input[type="checkbox"]):disabled:not(.lg-host),
html[data-switch-style="glass"] .dsh-switch:disabled > .lg-sw,
html[data-switch-style="glass"] .switch > input[type="checkbox"]:disabled + .lg-sw { opacity: .45; }

@media (prefers-reduced-motion: reduce) {
  .lg-lens { display: none; }
}
@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
  .lg-lens {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    background: rgba(255, 255, 255, .92);
  }
  .lg-track { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .18); }
}

/* ---------------------------------------------------------------- 设置页：效果预览 */
.experimental-preview {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  margin-top: 18px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--glass-inset);
}
.experimental-preview .tiny { margin-right: 2px; }

/* 设置 → 实验性：自定义开关颜色（选「自定义」时才显示） */
[data-switch-tint-custom-field][hidden] { display: none; }
[data-switch-tint-custom-field] input[type="color"] { width: 72px; height: 36px; padding: 3px; cursor: pointer; }
