/* ==========================================================
   手机端 · 按 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(30px) saturate(1.06);
  opacity: 0.94;
  z-index: 0;
  /* 画面是等比缩放的，屏幕比例和设计稿（1:2.1723）不一致时，
     多出来的左右或上下一定会有留边。这层用当前页底图的模糊放大版
     把留边填满，颜色和画面自然过渡，不会出现白边 / 黑边。 */
  display: block;
}

/* ---------- 主舞台：不再使用 transform 缩放 ----------
   以前是 #stage 固定 1206×2620 再整体 transform: scale()。这个做法在不同
   安卓机上翻车三次，表现各不相同，但根都是同一个：整块 1206×2620 的缩放
   图层超出了这些机型的光栅化能力。
     · 小米浏览器：只画到设计稿 y≈2250，下面整块空白（按钮、底图下半截消失）
     · 华为浏览器：图片（调色板、工具图标）首次不画，画布还显示成别的 canvas
       的内容，点一下屏幕才补画
   现在改成「真实像素布局」：舞台宽高 = 设计尺寸 × 同一个等比系数 k，
   每个元素由 JS 按设计坐标 × k 写到 left/top/width/height。没有任何缩放
   图层，浏览器就是老老实实画一个正常页面，所有机型一致。
   横向纵向永远用同一个 k（不像早期那样 kx 铺满宽度、ky 单独压），
   所以字体、图片、按钮圆角在任何屏幕比例下都不会变形；屏幕比例和设计稿
   不一致时，多出来的空间留白，由 #backdrop 的模糊底图填满。
   --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; }

/* 纯文字按钮「View The Wall」：无底色、黑字、带下划线暗示可点。
   字号由 JS 按 data-fs 写成真实像素（见 placeLayerBtn），这里只给设计值兜底。 */
#btnlayer .btn.txt {
  background: none;
  background-color: transparent;
  border-radius: 0;
  box-shadow: none;
  display: none;
  align-items: center;
  justify-content: center;
  font-family: 'DesignSans', Arial, Helvetica, sans-serif;
  font-weight: 700;
  font-size: 48px;
  line-height: 1;
  letter-spacing: .2px;
  color: #111;
  text-decoration: underline;
  text-underline-offset: .22em;
  text-decoration-thickness: 2px;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

#btnlayer .btn.txt.on { display: flex; }
#btnlayer .btn.txt:active { opacity: .5; }

/* 底部主按钮：用 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); }
}

/* 提示条：位置必须避开所有可点控件。
   之前写在 bottom:140px，正好落在主按钮下半部分 —— toast 在 #stage 里（z-index 1），
   主按钮在 #btnlayer 里（z-index 3），于是它被按钮整块盖住；只在按下那一刻
   按钮 .tapfx 变半透明（opacity .86）时才从按钮里透出一块黑影，看着像 bug。
   现在放在爱心卡片内部下缘（设计稿 y 约 1560~1641）：下面是调色板、工具栏、主按钮，
   上面是涂色区，四周都不压任何可点的东西，文案也正好落在「爱心」旁边。
   配色换成浅底 + 品牌粉描边，避免在粉彩页面上像一块系统报错。 */
.toast {
  position: absolute;
  left: 50%;
  bottom: calc(979 * var(--ky, 1) * 1px);
  transform: translate(-50%, 16px);
  padding: calc(18 * var(--ky, 1) * 1px) calc(46 * var(--kx, 1) * 1px);
  border-radius: 999px;
  background: #fff;
  color: #23282d;
  border: calc(2 * var(--kx, 1) * 1px) solid #f4b6cd;
  box-shadow: 0 calc(8 * var(--ky, 1) * 1px) calc(26 * var(--kx, 1) * 1px) rgba(24, 28, 32, 0.16);
  font-size: calc(38 * var(--ky, 1) * 1px);
  font-weight: 500;
  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; }

/* ==========================================================
   第 5 页：围绕大爱心的一圈小爱心
   素材 爱心动态.png 已切好透明通道（assets/p5-sparks.webp，1206×1192），
   JS 按连通域把它切成 55 块，每块用 background-position 从同一张图里取。
   这样只有一个图片请求，而每块都能独立做心跳。
   缩放走百分比：外层容器由 applyLayout 按 kx/ky 调真实像素，
   里面的 left/top/width/height 全是百分比，整圈自动跟着屏幕走。
   ========================================================== */
.p5-ring {
  position: absolute;
  left: 2.5px;
  /* 设计稿 488.5 → 432.5：上移 56 设计像素。
     applyLayout 按 kx（stage 宽 / 1206）缩放，430px 宽的手机上正好是 20 屏幕像素，
     其它尺寸等比跟着走，不会因机型和设计稿跑偏。 */
  top: 432.5px;
  width: 1206px;
  height: 1192px;
  pointer-events: none;
}

.p5-ring .spk {
  position: absolute;
  transform-origin: 50% 50%;
  /* 出场：从几乎看不见弹到原大小，延迟由 --in 错开，由内向外铺开 */
  animation-name: spkIn;
  animation-duration: .5s;
  animation-timing-function: cubic-bezier(.18, 1.5, .38, 1);
  animation-delay: var(--in, 0s);
  animation-fill-mode: both;
  will-change: transform, opacity;
}

.p5-ring .spk i {
  display: block;
  width: 100%;
  height: 100%;
  background-image: url('../assets/p5-sparks.webp?v=20261117a');
  background-repeat: no-repeat;
  transform-origin: 50% 50%;
  animation-timing-function: ease-in-out;
  animation-delay: var(--dl, 0s);
  animation-iteration-count: infinite;
  animation-fill-mode: both;
  will-change: transform;
}

/* 心跳：快起慢落两次跳动，后面留一段静止，才有「咚—咚……咚—咚」的呼吸感 */
.p5-ring .spk.b1 i { animation-name: spkBeat1; animation-duration: var(--d, 2.4s); }
.p5-ring .spk.b2 i { animation-name: spkBeat2; animation-duration: var(--d, 2.4s); }
.p5-ring .spk.b3 i { animation-name: spkBeat3; animation-duration: var(--d, 2.4s); }

@keyframes spkIn {
  0%   { opacity: 0; transform: scale(.12); }
  62%  { opacity: 1; transform: scale(1.06); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes spkBeat1 {
  0%, 100%       { transform: scale(1); }
  8%             { transform: scale(1.12); }
  16%            { transform: scale(.985); }
  24%            { transform: scale(1.055); }
  34%, 62%       { transform: scale(1); }
}

@keyframes spkBeat2 {
  0%, 100%       { transform: scale(1); }
  8%             { transform: scale(1.155); }
  16%            { transform: scale(.98); }
  24%            { transform: scale(1.07); }
  34%, 62%       { transform: scale(1); }
}

@keyframes spkBeat3 {
  0%, 100%       { transform: scale(1); }
  8%             { transform: scale(1.20); }
  16%            { transform: scale(.975); }
  24%            { transform: scale(1.09); }
  34%, 62%       { transform: scale(1); }
}
