/* ==========================================================
   手机端 · 按 1206×2620 设计稿绝对定位，整体等比缩放
   ========================================================== */

/* 设计稿原字体（来自 AI 源文件的 Fonts 目录） */
@font-face {
  font-family: 'DesignSans';
  src: url('../fonts/arial.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: block;
}
@font-face {
  font-family: 'DesignSans';
  src: url('../fonts/arial-bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: block;
}
@font-face {
  font-family: 'DesignMarker';
  src: url('../fonts/cheese-matcha.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: block;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: #a9d6ee;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  touch-action: manipulation;
}

#viewport {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #a9d6ee;
}

#backdrop {
  position: absolute;
  left: -60px;
  top: -60px;
  right: -60px;
  bottom: -60px;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  filter: blur(26px) saturate(1.06);
  opacity: 0.92;
  z-index: 0;
  /* 手机铺满时它被 stage 完全挡住，平时不画：
     万一视口测量有 1~2px 余量，露出来的也是天空色而不是这层模糊花屏。
     只有桌面窗口那种等比留边的情况才打开（JS 会加 .fit-contain） */
  display: none;
}

body.fit-contain #backdrop { display: block; }

/* ---------- 主舞台：不再使用 transform 缩放 ----------
   以前是 #stage 固定 1206×2620 再整体 transform: scale()。这个做法在不同
   安卓机上翻车三次，表现各不相同，但根都是同一个：整块 1206×2620 的缩放
   图层超出了这些机型的光栅化能力。
     · 小米浏览器：只画到设计稿 y≈2250，下面整块空白（按钮、底图下半截消失）
     · 华为浏览器：图片（调色板、工具图标）首次不画，画布还显示成别的 canvas
       的内容，点一下屏幕才补画
   现在改成「真实像素布局」：舞台宽高 = 设计尺寸 × 缩放比，每个元素由 JS 按
   设计坐标 × 比例写到 left/top/width/height。没有任何缩放图层，浏览器就是
   老老实实画一个正常页面，所有机型一致。
   --kx / --ky 供 CSS 里的固定尺寸（图标、色点、字号）跟着缩放。 */
#stage {
  position: absolute;
  z-index: 1;
  left: 0;
  top: 0;
  width: 1206px;
  height: 2620px;
  --kx: 1;
  --ky: 1;
  background: transparent;
}

/* ---------- 底图层（脱离主舞台） ----------
   #stage 是整块 1206×2620 的 transform，按真实像素栅格化时
   在 DPR 2.4 的小米机上只画到设计稿 y≈2250 就停止，之后全空白 ——
   底图下半截变成一片纯色、左下黄色笔刷和右侧绿色笔刷被一条水平线切断。
   所以底图单独放这一层：不做 transform、不做 opacity 过渡、不建合成层，
   由 background-size:100% 100% 直接重采样到「舞台的可视矩形」上，
   视觉位置、缩放和 stage 里的元素完全一致，但不会被截断。 */
#bglayer {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.bgset {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  display: none;              /* 硬切，不用 opacity 过渡（过渡会建合成层） */
  background-repeat: no-repeat;
  background-size: 100% 100%;
  background-position: 0 0;
}

.bgset.on { display: block; }

/* ---------- 屏幕 ----------
   用 display 硬切，不用 opacity 过渡。
   opacity < 1 的元素在很多安卓浏览器里会被提升为合成层，切屏瞬间
   图片 / 画布还没就绪，这一层就被光栅化成空白并缓存下来，之后不再重画 ——
   表现就是「华为上图片全不显示，点一下屏幕才冒出来」。
   display 切换等于每次重新布局绘制，代价极小，但绝对不会有缓存残留。 */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  pointer-events: none;
}

.screen.on {
  display: block;
  pointer-events: auto;
}

.screen.out { display: none; }

.bg {
  position: absolute;
  left: 0;
  top: 0;
  width: 1206px;
  height: 2620px;
  display: block;
}

/* ---------- 通用元素 ---------- */
.el { position: absolute; display: block; }

/* ---------- 底部按钮层（脱离主舞台） ----------
   #stage 是 1206×2620 的整体 transform 层。在 864×1920、DPR 2.4 的小米手机上，
   浏览器把它栅格化时只画到 CSS 1536px（≈ 设计稿 y 2255）就停了，之后全部空白 ——
   表现就是底部按钮整块消失、只剩最上面 3px 的一条边，点一下屏幕才补画。
   落在 y>2255 的按钮放到这个 fixed 层里、按 vw 定位（sx 本来就等于 vw/1206，
   所以和设计稿位置一致），就完全绕开了上面那个限制。 */
#btnlayer {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

#btnlayer .btn {
  position: absolute;
  display: none;
  pointer-events: auto;
}

#btnlayer .btn.on { display: block; }

/* 底部主按钮：用 div + 背景图绘制，不要用 <img>。
   原因（小米/安卓浏览器实测）：<img> 的解码完成通知会丢，切屏后这块
   不重绘，表现为按钮整块消失、或只画出最上面 3~5 个像素的一条边。
   背景图走 paint 路径，跟着元素一起画，不会丢。
   另外绝对不能给 .btn 加 transform 过渡 —— 带 transform 过渡的元素会被
   提升成独立合成层，缩放过的祖先下该层容易漏栅格化，是同一类问题的根。
   再加同色圆角底色兜底：万一背景图仍没画出来，用户看到的也是一个
   能点的粉色胶囊，而不是一片空白。 */
.btn {
  position: absolute;
  display: block;
  cursor: pointer;
  background-color: #ed1f79;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100% 100%;
  border-radius: 999px;
  transition: none;
}
.btn:active { opacity: 0.9; }
/* 主按钮现在是 pointerdown 即执行，:active 不会触发，用 .tapfx 补一下按下反馈；
   touch-action 写死在按钮上，避免任何祖先的滚动/双击缩放判定把这次触摸吞掉 */
.btn { touch-action: manipulation; }
.btn.tapfx { opacity: .86; }

/* ---------- 绘制页 ---------- */
#pad-wrap {
  position: absolute;
  left: 137px;
  top: 743px;
  width: 933px;
  height: 933px;
  overflow: hidden;
}

#pad {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* 色球保持设计稿原样：球体是烘焙在 palette.webp 里的，.dot 只是透明热区。
   热区直径取 96（与素材球实测直径一致），这样选中态的白色描边正好压在球的最外缘。
   选中态：不放大、不换球，只在外缘加一圈白边 + 一点自身颜色的柔光。 */
.dot {
  position: absolute;
  touch-action: manipulation;
  width: calc(96 * var(--kx, 1) * 1px);
  height: calc(96 * var(--ky, 1) * 1px);
  margin: calc(-48 * var(--ky, 1) * 1px) 0 0 calc(-48 * var(--kx, 1) * 1px);
  border-radius: 50%;
  border: 0;
  background: transparent;
  padding: 0;
  z-index: 3;
  -webkit-tap-highlight-color: transparent;
}

.dot.on {
  z-index: 5;
}

/* 选中态的画法：素材球的位置、大小都不变，直接在上面「重新画一遍」——
   ::before 是一块比热区大一圈的白圆盘（白描边就是它露出来的那一圈，
   盖住素材球自带的浅色泛光和右下角灰色投影）；
   ::after 在原位重画球体：底色用该色点的本色，加一点点左上高光和下缘暗边，
   跟素材球放到一起看不出是另画的。
   这样白描边的内外两条边都是 CSS 画的正圆，上下左右必然等宽同心，
   不会再有「一侧白多、一侧白少」。 */
.dot.on::before {
  content: "";
  position: absolute;
  left: calc(-7 * var(--kx, 1) * 1px);
  top: calc(-7 * var(--ky, 1) * 1px);
  right: calc(-7 * var(--kx, 1) * 1px);
  bottom: calc(-7 * var(--ky, 1) * 1px);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.99);
  box-shadow: 0 0 calc(16 * var(--kx, 1) * 1px) calc(7 * var(--kx, 1) * 1px) var(--glow-soft, rgba(255, 200, 206, 0.40));
}

.dot.on::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  border-radius: 50%;
  pointer-events: none;
  background:
    linear-gradient(180deg,
      rgba(255, 255, 255, 0.34) 0%,
      rgba(255, 255, 255, 0.12) 32%,
      rgba(255, 255, 255, 0) 64%),
    var(--c, #ffc8ce);
  box-shadow: inset 0 calc(-6 * var(--ky, 1) * 1px) calc(9 * var(--kx, 1) * 1px) rgba(0, 0, 0, 0.16);
}


/* ---------- 工具栏（图标尺寸/位置按参考图 1:1 实测） ---------- */
/* 直接使用设计稿导出的 190×161 双态素材，选中态的高亮块已烘焙在图里 */
.tool {
  position: absolute;
  width: calc(190 * var(--kx, 1) * 1px);
  height: calc(161 * var(--ky, 1) * 1px);
  z-index: 4;
  border: 0;
  background: transparent;
  padding: 0;
  -webkit-appearance: none;
  appearance: none;
  /* 关掉双击缩放/连击判定，触摸按下即算是点击，不会因为连点被吞掉一次 */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.tool img {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(190 * var(--kx, 1) * 1px);
  height: calc(161 * var(--ky, 1) * 1px);
  display: block;
  pointer-events: none;
}

/* 双态用 display 硬切，不用 opacity 过渡：
   opacity < 1 会建立独立合成层，部分安卓机在这类图层上会漏画，
   表现为「点了没反应，再点一下才变」——这里直接从根上避开。 */
.tool .ico-on { display: none; }
.tool.on .ico-on { display: block; }
.tool.on .ico-off { display: none; }
.tool.is-idle .ico-off { opacity: 0.34; }

/* 按下反馈由图标本身的切换完成（pointerdown 即生效），不再用 opacity */
/* ---------- 命名页 ---------- */
#nameInput {
  position: absolute;
  left: 188px;
  top: 1192px;
  width: 828px;
  height: 130px;
  border: 0;
  outline: none;
  background: transparent;
  font-family: 'DesignSans', Arial, Helvetica, sans-serif;
  font-weight: 400;
  font-size: calc(38.43 * var(--ky, 1) * 1px);
  line-height: 1;
  padding-bottom: calc(3 * var(--ky, 1) * 1px);
  color: #000;
  z-index: 4;
  -webkit-user-select: text;
  user-select: text;
}

#nameInput::placeholder {
  color: #646464;
  opacity: 1;
}

#nameInput.is-err { animation: shake 0.34s ease; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-16px); }
  45% { transform: translateX(13px); }
  70% { transform: translateX(-8px); }
}

/* ---------- 结果页 ---------- */
.heart-copy { position: absolute; display: block; }

#p6-heart { filter: drop-shadow(0 0 18px #fff) drop-shadow(0 0 26px rgba(255, 255, 255, 0.9)); }

#countNum {
  position: absolute;
  left: 3.4px;
  top: 823.2px;
  width: 1206px;
  text-align: center;
  font-family: 'DesignSans', Arial, Helvetica, sans-serif;
  font-weight: 700;
  font-size: calc(90.4 * var(--ky, 1) * 1px);
  line-height: 1;
  letter-spacing: 0;
  color: #000;
  font-variant-numeric: tabular-nums;
  font-synthesis: none;
}

.p5-name {
  position: absolute;
  left: 200.8px;
  top: 1544.5px;
  width: 798px;
  height: 246px;
  display: grid;
  place-items: center;
  font-family: 'DesignMarker', 'DesignSans', sans-serif;
  font-weight: 400;
  font-size: calc(137.25 * var(--ky, 1) * 1px);
  line-height: 1;
  color: #000;
  white-space: nowrap;
  font-synthesis: none;
  z-index: 4;
}

.p6-name {
  position: absolute;
  left: -2.7px;
  top: 1138.1px;
  width: 1206px;
  text-align: center;
  font-family: 'DesignMarker', 'DesignSans', sans-serif;
  font-weight: 400;
  font-size: calc(137.25 * var(--ky, 1) * 1px);
  line-height: 1;
  color: #000;
  white-space: nowrap;
  font-synthesis: none;
  z-index: 4;
  /* 设计稿第六屏姓名单独做了纵向拉伸 */
  transform: scaleY(1.08);
  transform-origin: 50% 50%;
}

/* 提交中的轻微呼吸 */
#p5 .heart-copy { animation: popIn 0.55s cubic-bezier(0.2, 1.4, 0.4, 1) both; }

@keyframes popIn {
  0% { opacity: 0; transform: scale(0.86); }
  100% { opacity: 1; transform: scale(1); }
}

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(140 * var(--ky, 1) * 1px);
  transform: translate(-50%, 20px);
  padding: calc(22 * var(--ky, 1) * 1px) calc(44 * var(--kx, 1) * 1px);
  border-radius: calc(26 * var(--kx, 1) * 1px);
  background: rgba(28, 32, 36, 0.92);
  color: #fff;
  font-size: calc(38 * var(--ky, 1) * 1px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s, transform 0.24s;
  white-space: nowrap;
  z-index: 20;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 调试用：隐藏背景图，方便精确量字 */
body.hide-bg .bg,
body.hide-bg .bgset { visibility: hidden; }
body.hide-bg .el,
body.hide-bg .btn,
body.hide-bg .heart-copy { visibility: hidden; }
