/* Material Symbols Sharp（400 字重，默认档），只子集了 add/arrow_downward/
 * arrow_upward 三个 ligature 用到的字形，约 2KB。按钮图标用 ligature 文本触发
 * （见 index.html / redminitool/index.html），不是图片。 */
@font-face {
  font-family: "Material Symbols Sharp";
  src: url("./assets/fonts/material-symbols-sharp-subset.woff2?v=612ed052") format("woff2");
  font-weight: 400;
  font-display: block;
}
.material-symbol {
  font-family: "Material Symbols Sharp";
  font-weight: 400;
  font-style: normal;
  line-height: 1;
  -webkit-font-smoothing: antialiased;
}

/* Figtree（可变字重字体），只子集了 0~9 数字字形，约 4KB。强度刻度上方的数字用它，
 * 见 .scale-label / buildStrengthScale。 */
@font-face {
  font-family: "Figtree Digits";
  src: url("./assets/fonts/figtree-digits-subset.woff2?v=9e7eb1a9") format("woff2");
  font-display: block;
}

/* =========================================================
 * 设计令牌（沿用 Riso 项目的令牌结构，字体换成系统字体）
 * =======================================================*/
:root {
  --bg: #000;
  --surface: #1a1a1a;
  --fg: #fff;
  --fg-muted: #888;
  --fg-subtle: #555;
  --line: #333;
  --accent: var(--fg);
  --mask-opacity: 0.6;

  --font-title: -apple-system, "PingFang SC", "Helvetica Neue", sans-serif;
  --font-body: -apple-system, "PingFang SC", "Helvetica Neue", sans-serif;

  --fs-title: 18px;
  --fs-body-lg: 15px;
  --fs-body: 14px;
  --fs-caption: 13px;
  --fs-micro: 12px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 28px;
  --space-8: 32px;

  --ls-wide: 0.5px;
  --ls-normal: 0.2px;

  color-scheme: dark;
}

* { box-sizing: border-box; }
* {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
* { scrollbar-width: none; -ms-overflow-style: none; }
*::-webkit-scrollbar { width: 0; height: 0; display: none; }
body {
  position: fixed;
  inset: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
}

/* =========================================================
 * App 容器 & 布局（桌面两栏，同 Riso 约定）
 * =======================================================*/
#app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
}

#stage-wrap {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

@media (min-width: 481px) and (min-height: 600px) {
  #stage-wrap {
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    align-items: center;
    padding: 80px;
    overflow: auto;
  }
  #app {
    width: 375px;
    height: 812px;
    margin: 0;
    padding-top: 0;
    border: none;
    box-shadow: 0 0 0 2px var(--fg);
    justify-self: center;
  }
  #info-panel {
    display: flex;
    flex-direction: column;
    height: 812px;
  }
  #info-panel.hidden { display: none; }
  #install-btn { display: none; }
}

@media (display-mode: standalone) {
  #stage-wrap { padding: 0; align-items: stretch; justify-content: stretch; }
  #app {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    margin: 0;
    padding-top: 0;
    border: none;
  }
  #info-panel { display: none !important; }
  #install-btn { display: flex; }
}

/* =========================================================
 * 信息面板（桌面右侧，同 Riso）
 * =======================================================*/
#info-panel { color: var(--fg); }
#info-panel.hidden { display: none; }
.info-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: var(--space-5);
  gap: var(--space-5);
}
.info-header { width: 320px; display: flex; align-items: center; gap: var(--space-4); }
.info-icon { width: 80px; height: 80px; border-radius: 0; flex: 0 0 auto; }
.info-text { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2); text-align: left; }
.info-name { margin: 0; font-family: var(--font-title); font-weight: 600; font-size: 22px; letter-spacing: var(--ls-wide); }
.info-desc { margin: 0; font-family: var(--font-body); font-size: var(--fs-body); color: var(--fg); letter-spacing: var(--ls-normal); line-height: 1.6; }
.info-actions { display: flex; flex-direction: column; gap: var(--space-3); }
.info-action-btn {
  width: 320px;
  height: 48px;
  padding: 0;
  background: var(--bg);
  border: 1px solid var(--fg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: var(--fs-body);
  letter-spacing: var(--ls-wide);
  cursor: pointer;
  display: flex;
  align-items: stretch;
  transition: background 0.1s, border-color 0.1s, transform 0.08s;
}
.btn-icon { width: 48px; display: flex; align-items: center; justify-content: center; flex: 0 0 auto; border-right: 1px solid var(--fg); }
.btn-icon img { width: 32px; height: 32px; flex: 0 0 auto; display: block; }
.info-action-btn > span:not(.btn-icon):not(.btn-toggle) { flex: 1; display: flex; align-items: center; padding: 0 var(--space-5); }
.btn-toggle { flex: 0 0 auto; align-self: center; margin-right: var(--space-4); font-size: 18px; line-height: 1; font-family: var(--font-body); }
.info-action-btn:hover { border-color: var(--fg); }
.info-action-btn:active { background: var(--fg); color: var(--bg); transform: scale(0.99); }
.info-action-btn:active .btn-icon img { filter: brightness(0); }
.info-action-btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.title-bar { position: relative; display: flex; align-items: center; justify-content: center; padding: var(--space-5) 0; }
#title { margin: 0; padding: var(--space-5) 0; font-family: var(--font-title); font-weight: 600; font-size: var(--fs-title); text-align: center; letter-spacing: var(--ls-wide); }
.title-bar #title { padding: 0; }

/* 标题栏：固定高度 56px，纯 logo 居中，不放文字（web 版与小工具版共用同一套 UI）。
 * 底部加一条发丝分割线，跟下面的预览区分开——下面 #panel、.actions 同款处理，
 * 让标题栏/预览区/刻度区/按钮区四块区域各自的边界都看得清楚 */
body #title {
  height: 56px;
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 0.5px solid var(--line);
}
body #title .logo { height: 16px; width: auto; display: block; }

/* =========================================================
 * 预览框
 * =======================================================*/
/* #stage 分上下两块：#frame 照片占余下全部空间，#formatBar 固定 40px 贴在照片下面 */
#stage { flex: 1; min-height: 0; padding: 0 var(--space-4); display: flex; flex-direction: column; }
#frame { flex: 1; min-height: 0; position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; }
/* 格式徽标栏：固定不动（web 版与小工具版都有这块 DOM）。
 * 默认隐藏——没图/加载失败时两个空徽标不该露出两个没文字的空描边小方块，跟 #empty
 * 一样靠 main.ts 的 setFormatBar/hideFormatBar 切换 hidden。 */
#formatBar {
  flex: 0 0 auto;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
#formatBar.hidden { display: none; }
.format-badge {
  border: 0.5px solid color-mix(in srgb, var(--fg) 60%, transparent);
  border-radius: 4px;
  padding: 1px 4px;
  font-family: "Figtree Digits", var(--font-body); /* 跟刻度下面的数字徽标同款字体 */
  font-size: 9px;
  font-weight: 700;
  letter-spacing: var(--ls-wide);
  color: var(--fg);
  white-space: nowrap;
}
/* 图层式预览：5 个挡位的图叠放（见 main.ts 的 buildLayers），切挡位只切
 * opacity/pointer-events（合成器操作，零解码零布局）。所有图层统一绝对定位铺满
 * 预览区 + object-fit:contain 各自居中缩放——不能用"正常流一张撑尺寸"的方案：
 * 那张的 max-height:100% 在内容撑高的容器里没有确定参照（WebKit 按原始尺寸渲染），
 * 跟其余 contain 层几何不一致，切到那一挡时画面会突然变大。
 * 长按/右键保存要用：全局 * 选择器把 user-select/touch-callout 都关了（像 app
 * 不像网页），但生成结果图必须保留这两个能力，否则浏览器预览模式下存不下来 */
.preview-stack {
  position: absolute;
  inset: 0;
}
/* .layer 既可以是 <img>（5 个挡位图层）也可以是 <canvas>（生成期间亮出原图的占位，
 * 见 main.ts 的 showOriginalPlaceholder） */
.preview-stack .layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  will-change: opacity; /* 阻止 WebKit 丢弃非活动图层的渲染缓存，切换才不掉帧 */
}
.preview-stack img.layer {
  -webkit-touch-callout: default;
  -webkit-user-select: auto;
  user-select: auto;
}
#empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-3); color: var(--fg-muted); padding: var(--space-6); }
#empty.hidden { display: none; }
#empty img { max-width: 70%; max-height: 60%; object-fit: contain; opacity: 0.9; }
#empty p { margin: 0; font-size: var(--fs-caption); text-align: center; line-height: 1.6; }

/* =========================================================
 * Loading：选图后全部挡位生成期间盖住预览区（视觉复刻像素格波前 loader，
 * Drive 变体：3×3 方形格按箭头形状错峰点亮，向右推进；650ms 周期短于扫完
 * 整格的时长，同时有两个波前在跑。格子的 opacity 动画走合成器线程，
 * 主线程被生成占满时波前照样流动）
 * =======================================================*/
.loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.45);
  z-index: 10;
}
.loading.hidden { display: none; }
/* 不加遮罩（不调暗画面），loader 本体回到照片区正中间（web 版与小工具版共用） */
body .loading {
  background: none;
}
.loader-grid {
  display: grid;
  grid-template-columns: repeat(3, 4px);
  gap: 1.5px;
}
.loader-grid span {
  width: 4px;
  height: 4px;
  background: var(--fg);
  border-radius: 1px;
  opacity: 0.15;
  animation: pixel-on 650ms ease-in-out infinite;
}
@keyframes pixel-on {
  0%, 100% { opacity: 0.15; }
  50% { opacity: 1; }
}
.loader-label {
  font-size: 13px;
  color: var(--fg-muted);
  /* 用透明度脉动替代渐变流光（background-clip:text 在 iOS WebKit 上容易出重影） */
  animation: loader-pulse 1.4s ease-in-out infinite;
}
@keyframes loader-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}
/* 生成期间锁掉底部面板交互（换挡必然全缓存命中才开放，见 main.ts 的 useBitmap） */
body.app-loading #panel { pointer-events: none; opacity: 0.5; }
@media (prefers-reduced-motion: reduce) {
  .loader-grid span { animation: none; }
  .loader-label { animation: none; }
}

/* =========================================================
 * 控制面板：强度滑杆
 * =======================================================*/
#panel {
  position: relative; /* toast 挂在这里（见 toast.ts），不能盖到上面的预览图 */
  padding-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
}
/* 顶部加发丝分割线，跟上面的预览区分开（web 版与小工具版共用） */
body #panel {
  border-top: 0.5px solid var(--line);
}
.sliders { padding: var(--space-4); }
.slider-row { display: flex; align-items: center; gap: var(--space-3); }
.slider-row label { font-size: var(--fs-caption); color: var(--fg-muted); flex: 0 0 auto; white-space: nowrap; }
.slider-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 1px;
  background: var(--line);
  outline: none;
}
.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--fg);
  cursor: pointer;
}
.slider-row .slider-value { width: 32px; text-align: right; font-size: var(--fs-caption); color: var(--fg); flex: 0 0 auto; }

/* 强度刻度：镶头对焦环风格的线刻度，可拖动（0~4，见 buildStrengthScale）。
 * 整块区域高 112px，"刻度+数字"整体在区域内垂直居中，两者间距 8px。数字徽标在刻度
 * 下面，横向位置跟着当前选中的刻度走。整条轨道都是竖线，没有横线；两端不留padding，
 * 贴着容器边缘。5 个整数值位置更高更粗，选中的那一个比其他整数值刻度更粗；中间穿插
 * 的细刻度只做视觉装饰，不可单独点选。（格式徽标不在这里，挪到预览区底部了，见
 * #formatBar）
 * 刻度由 JS 摆在整数像素上（buildStrengthScale 的 layout()），不走 flex：flex 摆位
 * 带小数，1px 竖线落在半像素上会被渲染成两条半覆盖的物理像素，看起来"一半白一半
 * 半透明"。 */
.scale-outer {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.scale-block {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.scale-label-row {
  position: relative;
  height: 20px;
}
.scale-label {
  position: absolute;
  top: 0;
  left: 0; /* 横向位置只由 JS 写 transform（见 buildStrengthScale 的 positionLabel），
   * 不写 left：left 是重排属性走主线程，transform 在合成器线程渲染，主线程被
   * 图片生成占满时徽标照样跟手。x 是徽标中心，宽 16px 所以 translateX 里减 8
   * （见 ui.ts 的 positionLabel，改宽度要同步改那边的偏移量）。 */
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Figtree Digits", var(--font-body);
  font-size: 10px;
  line-height: 1;
  color: var(--bg);
  white-space: nowrap;
  /* 静止/松手吸附时有一段 transform 过渡（丝滑收尾）；拖动中 .dragging 摘掉过渡，
   * 保证 1:1 跟手零延迟 */
  transition: transform 0.15s cubic-bezier(0.2, 0, 0, 1);
  will-change: transform;
}
.scale-label.dragging {
  transition: none;
  transform-origin: center;
}
.scale {
  position: relative;
  width: 100%;
  height: 40px;
  cursor: pointer;
}
/* 刻度三级比例阶梯（每段 8 个小刻度，共 33 根）：
 *   小刻度  1px 宽 / 8px 高  / 透明度 0.35
 *   大刻度  2px 宽 / 18px 高 / 透明度 0.6
 *   选中    3px 宽 / 30px 高 / 透明度 1.0
 * 高度比 8:18:30、透明度比 0.35:0.6:1、粗度比 1:2:3——每级都是清晰的递进关系，
 * 选中的存在感压过普通大刻度，大刻度压过小刻度，波纹峰值的 16px/0.9 仍低于大刻度。 */
.scale-tick {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 1px;
  height: 8px;
  background: var(--fg);
  opacity: 0.35;
  pointer-events: none; /* 拖动/点击交给父级 .scale 统一处理坐标换算 */
}
.scale-tick-major {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 18px;
  background: var(--fg);
  opacity: 0.6;
  transition: height 0.1s, opacity 0.1s;
}
.scale-tick-major.active { height: 30px; width: 3px; opacity: 1; }

/* =========================================================
 * 按钮系统
 * =======================================================*/
.actions { display: flex; gap: var(--space-3); padding: var(--space-4); }
/* 按钮之间不留间隔（紧贴着，靠发丝分割线区分）、不单独铺背景色（跟其余区域一样
 * 纯黑，只留顶部发丝分割线跟上面的调节区区分开）；内容区高 88px，图标+文字垂直
 * 居中堆叠。安全区仍要算进块高、底部 padding 里，保证按钮可点击范围躲开安全区。
 * （web 版与小工具版共用） */
body .actions {
  gap: 0;
  border-top: 0.5px solid var(--line);
  height: calc(88px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
  padding: 0 0 var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  margin-bottom: calc(-1 * var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
}
.action {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  background: var(--bg);
  border: 1px solid var(--fg);
  padding: var(--space-2) var(--space-2);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: var(--fs-body);
  letter-spacing: var(--ls-wide);
  color: var(--fg);
  transition: background 0.1s, transform 0.08s;
}
.action img, .action svg { width: 22px; height: 22px; flex: 0 0 auto; }
.action span { color: var(--fg); white-space: nowrap; }
.action:active { background: var(--fg); transform: scale(0.98); color: var(--bg); }
.action:active span { color: var(--bg); }
.action:active img { filter: brightness(0); }

/* 按钮：不描边、无填充，icon 在上文字在下、垂直居中堆叠（见 index.html / redminitool/index.html） */
.action-solid {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 12px;
  letter-spacing: var(--ls-wide);
  color: var(--fg);
  transition: opacity 0.1s, transform 0.08s;
}
.action-solid .material-symbol { font-size: 28px; color: var(--fg); }
.action-solid span { color: var(--fg); white-space: nowrap; }
/* 按钮之间加发丝分割线（第一个不加，避免贴着按钮区左边缘多一条） */
.action-solid:not(:first-child) { border-left: 0.5px solid var(--line); }
.action-solid:active { opacity: 0.5; transform: scale(0.96); }

#install-btn {
  position: absolute;
  right: var(--space-4);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: none;
  border: 1px solid var(--line);
  padding: var(--space-2) var(--space-3);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: var(--fs-caption);
  letter-spacing: var(--ls-normal);
  cursor: pointer;
  transition: background 0.1s, transform 0.08s;
}
#install-btn:active { background: var(--fg); color: var(--bg); transform: translateY(-50%) scale(0.98); }
#install-btn img { flex: 0 0 auto; width: 20px; height: 20px; border-radius: 5px; }

/* =========================================================
 * Toast
 * =======================================================*/
/* 两版共用：挂在 #frame 上（见 toast.ts），居中在照片正中间（见下方 body #toast） */
#toast {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--fg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: var(--fs-caption);
  letter-spacing: var(--ls-normal);
  text-align: center;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
#toast.show { opacity: 1; }
/* 挂在 #frame 上（见 toast.ts），居中在照片正中间，不贴底部（web 版与小工具版共用） */
body #toast {
  left: 50%;
  bottom: auto;
  top: 50%;
  transform: translate(-50%, -50%);
}

/* =========================================================
 * 安装引导浮层 & 手风琴（同 Riso 结构）
 * =======================================================*/
.install-sheet {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.25s ease; pointer-events: none;
}
.install-sheet.show { opacity: 1; pointer-events: auto; }
.install-sheet-mask { position: absolute; inset: 0; background: rgba(0, 0, 0, var(--mask-opacity)); }
.install-sheet-body {
  position: relative; width: 360px; max-width: calc(100vw - 32px);
  background: var(--surface); padding: var(--space-6);
  display: flex; flex-direction: column; gap: var(--space-5);
}
.install-sheet-header { display: flex; align-items: center; justify-content: space-between; }
.install-sheet-title {
  display: inline-flex; align-items: center; gap: var(--space-4);
  font-family: var(--font-title); font-weight: 600; font-size: var(--fs-body-lg);
  color: var(--fg); letter-spacing: var(--ls-wide);
}
.install-sheet-icon { display: block; width: 48px; height: 48px; border-radius: 11px; flex-shrink: 0; }
.install-sheet-close {
  width: var(--space-8); height: var(--space-8); background: none;
  border: 1px solid var(--line); color: var(--fg); cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
  transition: border-color 0.1s, transform 0.08s;
}
.install-sheet-close:active { border-color: var(--fg); transform: scale(0.98); }

.action-item { display: flex; flex-direction: column; }
.accordion-panel {
  width: 320px;
  border: 1px solid var(--fg);
  border-top: none;
  padding: var(--space-4);
  box-sizing: border-box;
}
.accordion-panel .qr-wrap { padding: 0; display: flex; justify-content: center; }
.accordion-panel .qr-wrap img { width: 200px; height: 200px; }
.accordion-panel .install-steps { display: flex; flex-direction: column; gap: var(--space-4); margin-top: var(--space-4); }
.install-step { display: flex; align-items: center; gap: var(--space-2); }
.step-no {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--fg); color: var(--bg); font-size: 12px; line-height: 1;
  display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
}
.step-inline-icon { display: inline; width: 18px; height: 18px; flex-shrink: 0; color: inherit; }
.step-label { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 0.25em; font-size: 14px; letter-spacing: 0.5px; line-height: 1.5; }
.step-capsule {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
  background: color-mix(in srgb, var(--fg) 10%, var(--bg));
  border: 1px solid var(--fg); border-radius: 999px; font-size: 13px;
}

/* #install-btn 的显隐要赢过桌面/standalone 媒体查询，见 Riso 项目同款注释：
   同优先级选择器靠源码顺序决出胜负，重申一次放在文件最后。 */
@media (min-width: 481px) and (min-height: 600px) {
  #install-btn { display: none; }
}
@media (display-mode: standalone) {
  #install-btn { display: flex; }
}
