/* ============================================================================
 * UI — CS 宠物小鸡 · 基于 frontend-design-vault + frontend-button-motion v2
 * ----------------------------------------------------------------------------
 * 纪律:
 *  · 动效参数(时长/缓动)一律引用 styles/motion.tokens.css 的 --mo-* 令牌,
 *    本文件不出现手写毫秒数与 cubic-bezier。
 *  · 分层靠 1px 发丝线(--line)+ 字号跳跃 + 留白,不靠区块底色。
 *  · 元数据(英文小字)等宽大写、字距 ≥0.16em,承担"仪器读数"的秩序感。
 * ========================================================================== */

:root {
  /* 命名走 ink / line / surface 体系(vault 11 域命名策略) */
  --ink: #3d4a5f;            /* 主文字 */
  --ink-2: #8b98ac;          /* 次级文字 / 元数据 */
  --ink-3: #b3bfd0;          /* 弱提示 */
  --line: rgba(61, 74, 95, 0.12);          /* 发丝线 */
  --line-strong: rgba(61, 74, 95, 0.22);
  --surface: rgba(252, 254, 255, 0.62);    /* 玻璃面板 */
  --surface-strong: rgba(255, 255, 255, 0.82);
  --surface-line: rgba(255, 255, 255, 0.7);
  --accent: #e8930c;         /* 主题橙(激活态) */
  --accent-ink: #7c4a00;     /* 激活态文字 */
  --accent-soft: rgba(255, 214, 122, 0.55);
  --shadow-1: 0 1px 2px rgba(61, 74, 95, 0.06), 0 6px 20px rgba(61, 74, 95, 0.10);
  --shadow-2: 0 2px 6px rgba(61, 74, 95, 0.08), 0 14px 36px rgba(61, 74, 95, 0.16);
  --radius-l: 22px;
  --radius-m: 15px;
  --radius-s: 11px;
  --mono: "Cascadia Code", "JetBrains Mono", ui-monospace, Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1100px 660px at 16% -8%, rgba(219, 233, 252, 0.9), transparent 62%),
    radial-gradient(960px 600px at 88% 6%, rgba(255, 243, 219, 0.7), transparent 58%),
    linear-gradient(180deg, #dfeafd 0%, #f0f6fd 46%, #f9fbfe 72%, #e9f1f9 100%);
}
button { font-family: inherit; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-s); }

#stage { position: fixed; inset: 0; z-index: 0; }
#stage canvas { display: block; }

/* ================= 浮状文案(逐字符揭示) ================= */
#caption {
  position: fixed; inset: 0; z-index: 5; pointer-events: none;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 6vw;
}
.cap-side { opacity: 0; transform: translateY(10px);
  transition: opacity var(--mo-dur-slow) var(--mo-ease-standard);
}
#caption.show .cap-side { opacity: 1; transform: none; }
#caption.show .cap-side.right { transition-delay: 160ms; }
.cap-side.right { text-align: right; }

.cap-en {
  font-family: var(--mono);
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--ink-2);
  margin-bottom: 10px;
  opacity: 0; transition: opacity var(--mo-dur-slow) var(--mo-ease-standard) 180ms;
}
#caption.show .cap-en { opacity: 0.9; }

.cap-zh {
  font-size: clamp(38px, 5.6vw, 78px);
  font-weight: 800; line-height: 1.16;
  color: var(--ink);
  letter-spacing: 0.04em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.9), 0 6px 26px rgba(255, 255, 255, 0.65);
}
.cap-zh span {
  display: inline-block;
  opacity: 0; transform: translateY(34px);
  transition:
    opacity var(--mo-dur-slow) var(--mo-ease-decel),
    transform var(--mo-dur-slow) var(--mo-ease-decel);
}
#caption.show .cap-zh span { opacity: 1; transform: none; }

.cap-zh.hello {
  font-style: italic; font-weight: 700;
  background: linear-gradient(92deg, #ff8a3d 0%, #ff4d8d 30%, #7b5bff 58%, #c94df0 82%, #ff6fae 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  opacity: 0; transform: translateY(18px) rotate(-2deg);
  transition:
    opacity var(--mo-dur-slow) var(--mo-ease-decel),
    transform var(--mo-dur-slow) var(--mo-ease-decel);
}
#caption.show .cap-zh.hello { opacity: 1; transform: rotate(-2deg); }

/* ================= 玻璃面板基底 ================= */
.glass {
  background: var(--surface);
  backdrop-filter: blur(16px) saturate(1.45);
  -webkit-backdrop-filter: blur(16px) saturate(1.45);
  border: 1px solid var(--surface-line);
  box-shadow: var(--shadow-1);
  border-radius: var(--radius-l);
}

/* ================= 顶栏 ================= */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 20px 26px; pointer-events: none;
}
#topbar > * { pointer-events: auto; }

.brand { display: flex; align-items: center; gap: 12px; padding: 9px 18px 9px 11px; }
.brand .logo {
  width: 36px; height: 36px; border-radius: var(--radius-s);
  display: grid; place-items: center;
  background: linear-gradient(135deg, #ffe9b0, #ffcf5c);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.8), 0 3px 10px rgba(232, 147, 12, .3);
}
.brand .logo::before {
  content: ""; width: 20px; height: 20px; background: var(--ink); opacity: .8;
  -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M12 13.2c2.6 0 4.4 1.7 4.4 3.6 0 1.6-1.3 2.4-2.6 2.1-.7-.2-1.3-.3-1.8-.3s-1.1.1-1.8.3c-1.3.3-2.6-.5-2.6-2.1 0-1.9 1.8-3.6 4.4-3.6Z"/><circle cx="7.2" cy="10.6" r="1.6"/><circle cx="10.3" cy="7.7" r="1.6"/><circle cx="13.7" cy="7.7" r="1.6"/><circle cx="16.8" cy="10.6" r="1.6"/></svg>') center/contain no-repeat;
          mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M12 13.2c2.6 0 4.4 1.7 4.4 3.6 0 1.6-1.3 2.4-2.6 2.1-.7-.2-1.3-.3-1.8-.3s-1.1.1-1.8.3c-1.3.3-2.6-.5-2.6-2.1 0-1.9 1.8-3.6 4.4-3.6Z"/><circle cx="7.2" cy="10.6" r="1.6"/><circle cx="10.3" cy="7.7" r="1.6"/><circle cx="13.7" cy="7.7" r="1.6"/><circle cx="16.8" cy="10.6" r="1.6"/></svg>') center/contain no-repeat;
}
.brand .name { font-weight: 700; font-size: 15.5px; line-height: 1.3; }
.brand .name small {
  display: block;
  font-family: var(--mono); font-size: 10px; font-weight: 600;
  letter-spacing: 0.2em; color: var(--ink-2); margin-top: 1px;
}

/* 自动演示:switch 形态,与章节按钮明显区分 */
#btnAuto {
  position: relative; display: flex; align-items: center; gap: 10px;
  padding: 10px 14px 10px 16px;
  border: 1px solid var(--surface-line); border-radius: 999px;
  cursor: pointer; color: var(--ink); font-size: 13px; font-weight: 650;
  background: var(--surface);
  backdrop-filter: blur(16px) saturate(1.45);
  -webkit-backdrop-filter: blur(16px) saturate(1.45);
  box-shadow: var(--shadow-1);
  transition: transform var(--mo-dur-fast) var(--mo-ease-standard),
              box-shadow var(--mo-dur-fast) var(--mo-ease-standard),
              background var(--mo-dur-fast) var(--mo-ease-standard);
}
#btnAuto svg { width: 15px; height: 15px; }
#btnAuto::after {
  content: ""; width: 30px; height: 17px; border-radius: 999px; flex: none;
  background: rgba(120, 140, 165, 0.3);
  box-shadow: inset 0 1px 2px rgba(50, 70, 100, .18);
  transition: background var(--mo-dur-fast) var(--mo-ease-standard);
}
#btnAuto::before {
  content: ""; position: absolute; right: 22px; top: 50%;
  width: 13px; height: 13px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(50, 70, 100, .3);
  transform: translateY(-50%);
  transition: transform var(--mo-dur-fast) var(--mo-ease-spring);
}
#btnAuto.active { color: var(--accent-ink); background: var(--accent-soft); }
#btnAuto.active::after { background: var(--accent); }
#btnAuto.active::before { transform: translateY(-50%) translateX(-13px); }
#btnAuto:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }

/* ================= 底部章节 dock ================= */
#chapterBtns {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 10; display: flex; gap: 2px; padding: 7px;
  animation: dock-in var(--mo-dur-slow) var(--mo-ease-decel) 0.25s backwards;
}
@keyframes dock-in { from { opacity: 0; transform: translate(-50%, 24px); } }
#chapterBtns button {
  position: relative; border: none; cursor: pointer; border-radius: var(--radius-m);
  padding: 10px 16px; background: transparent; color: var(--ink-2);
  font-size: 12.5px; font-weight: 650;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  transition: color var(--mo-dur-fast) var(--mo-ease-standard),
              background var(--mo-dur-fast) var(--mo-ease-standard),
              transform var(--mo-dur-fast) var(--mo-ease-standard),
              box-shadow var(--mo-dur-fast) var(--mo-ease-standard);
}
#chapterBtns button svg { width: 21px; height: 21px; }
#chapterBtns button::after {
  content: ""; position: absolute; left: 50%; bottom: 4px;
  width: 0; height: 2px; border-radius: 2px; background: var(--accent);
  transform: translateX(-50%);
  transition: width var(--mo-dur-base) var(--mo-ease-spring);
}
#chapterBtns button:hover {
  color: var(--ink); transform: translateY(-2px);
  box-shadow: 0 3px 0 0 rgba(61, 74, 95, 0.06), 0 10px 22px rgba(61, 74, 95, 0.12);
  background: rgba(255, 255, 255, 0.5);
}
#chapterBtns button.active {
  color: var(--accent-ink);
  background: linear-gradient(180deg, rgba(255, 232, 168, .9), rgba(255, 214, 120, .55));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.85), 0 4px 14px rgba(232, 147, 12, .22);
}
#chapterBtns button.active::after { width: 16px; }

/* ================= 场景内浮动控件 ================= */
#floatPad {
  position: fixed; right: 26px; bottom: 30px; z-index: 10;
  display: flex; flex-direction: column; align-items: flex-end; gap: 12px;
  pointer-events: none;
}
#floatPad > * { pointer-events: auto; }
#floatPad > *:not(.show) { opacity: 0; transform: translateY(12px) scale(.94); pointer-events: none; }
#floatPad > * { transition: opacity var(--mo-dur-fast) var(--mo-ease-standard),
                            transform var(--mo-dur-fast) var(--mo-ease-spring); }

.fab {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 17px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--surface-line); color: var(--ink);
  font-size: 13px; font-weight: 650;
  background: var(--surface);
  backdrop-filter: blur(16px) saturate(1.45);
  -webkit-backdrop-filter: blur(16px) saturate(1.45);
  box-shadow: var(--shadow-1);
  transition: transform var(--mo-dur-quick) var(--mo-ease-spring),
              box-shadow var(--mo-dur-fast) var(--mo-ease-standard);
}
.fab svg { width: 16px; height: 16px; }
.fab:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.fab:active { transform: translateY(0) scale(0.95); }

#skinDots { padding: 12px 14px; gap: 10px; display: flex; align-items: center; }
#skinDots .dot {
  width: 19px; height: 19px; border-radius: 50%; cursor: pointer;
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  background: var(--dot);
  box-shadow: 0 2px 6px rgba(61, 74, 95, .25), inset 0 1px 2px rgba(255,255,255,.5);
  transition: transform var(--mo-dur-quick) var(--mo-ease-spring),
              box-shadow var(--mo-dur-quick) var(--mo-ease-standard);
}
#skinDots .dot:hover { transform: scale(1.16); }
#skinDots .dot.active {
  transform: scale(1.16);
  box-shadow: 0 0 0 2.5px #fff, 0 0 0 4.5px var(--dot), 0 4px 10px rgba(61, 74, 95, .3);
}

/* ================= 提示 ================= */
#hint {
  position: fixed; right: 28px; bottom: 8px; z-index: 9;
  font-family: var(--mono); font-size: 10px; font-weight: 500;
  letter-spacing: 0.18em; text-transform: uppercase;
  color: rgba(139, 152, 172, 0.7); pointer-events: none;
}

/* 后台资源加载指示(左下角玻璃胶囊,资源齐后淡出) */
#bgload {
  position: fixed; left: 26px; bottom: 30px; z-index: 10;
  display: flex; align-items: center; gap: 9px;
  padding: 9px 16px; border-radius: 999px;
  font-family: var(--mono); font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.16em; color: var(--ink-2);
  opacity: 0; transform: translateY(6px); pointer-events: none;
  transition: opacity var(--mo-dur-slow) var(--mo-ease-standard),
              transform var(--mo-dur-slow) var(--mo-ease-standard);
}
#bgload.show { opacity: 1; transform: none; }
#bgload .ring {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid rgba(120, 140, 165, .25); border-top-color: var(--accent);
  animation: bgr .9s linear infinite;
}
@keyframes bgr { to { transform: rotate(360deg); } }

/* 章节等待提示(资源未就绪时在 dock 上方浮现) */
#chwait {
  position: fixed; left: 50%; bottom: 92px; z-index: 10;
  transform: translateX(-50%) translateY(6px);
  padding: 8px 18px; border-radius: 999px;
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  letter-spacing: 0.16em; color: var(--ink-2);
  opacity: 0; pointer-events: none;
  transition: opacity var(--mo-dur-fast) var(--mo-ease-standard),
              transform var(--mo-dur-fast) var(--mo-ease-standard);
}
#chwait.show { opacity: 1; transform: translateX(-50%); }

/* ================= 加载层 ================= */
#loading {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  background: linear-gradient(180deg, #dfeafd, #f6f9fd);
  transition: opacity var(--mo-dur-slow) var(--mo-ease-standard);
}
#loading.hide { opacity: 0; pointer-events: none; }
#loading .card {
  padding: 30px 46px; display: flex; flex-direction: column; align-items: center; gap: 14px;
  border-bottom: 1px solid var(--line);
}
#loading .egg { width: 40px; height: 50px; color: var(--accent); }
#loading .egg .shell { stroke-dasharray: 130; stroke-dashoffset: 130; animation: draw 2.2s var(--mo-ease-draw) infinite; }
#loading .egg .crack { stroke-dasharray: 30; stroke-dashoffset: 30; animation: draw 2.2s var(--mo-ease-draw) .5s infinite; }
@keyframes draw { 0% { stroke-dashoffset: 130; opacity: .4; } 45% { stroke-dashoffset: 0; opacity: 1; } 70% { stroke-dashoffset: 0; opacity: 1; } 100% { stroke-dashoffset: -20; opacity: 0; } }
#loading .bar { width: 168px; height: 3px; border-radius: 3px; background: rgba(120, 140, 165, .16); overflow: hidden; }
#loading .bar i {
  display: block; height: 100%; width: 0; border-radius: 3px;
  background: linear-gradient(90deg, var(--accent-soft), var(--accent));
  transition: width .25s var(--mo-ease-standard);   /* 真实字节进度,由 JS 驱动 */
}
#loading .txt {
  font-family: var(--mono); font-size: 11.5px; font-weight: 600;
  letter-spacing: 0.18em; color: var(--ink-2);
}

@media (prefers-reduced-motion: reduce) {
  /* 位移归零、时长保留(motion 规范):安静但不像坏了 */
  .cap-zh span, .cap-zh.hello { transform: none !important; transition: opacity var(--mo-dur-fast) var(--mo-ease-standard); }
  #chapterBtns { animation: none; }
  #chapterBtns button:hover { transform: none; }
  #btnAuto:hover, .fab:hover, #skinDots .dot:hover { transform: none; }
}
@media (max-width: 640px) {
  .brand .name small { display: none; }
  #chapterBtns button { padding: 8px 11px; font-size: 11px; }
  #chapterBtns button svg { width: 18px; height: 18px; }
  #topbar { padding: 14px; }
  #caption { padding: 0 5vw; }
}
