:root {
  --ink: #6b4f6e;
  --ink-soft: #9b82a0;
  --pink: #ff9fc0;
  --pink-deep: #f07aa3;
  --glass: rgba(255, 255, 255, 0.78);
  --glass-strong: rgba(255, 255, 255, 0.92);
  --line: rgba(240, 170, 200, 0.45);
  --shadow: 0 8px 28px rgba(160, 110, 170, 0.22);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --font: "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #cfe8fb;
  color: var(--ink);
  font-family: var(--font);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#stage {
  position: fixed;
  inset: 0;
  background: linear-gradient(#a9d6f5, #ffe3ee);
}

#stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  outline: none;
}

button {
  font-family: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
}

/* ———— 顶部时间 ———— */
#hud {
  position: fixed;
  top: calc(12px + var(--safe-t));
  left: calc(14px + var(--safe-l));
  pointer-events: none;
  z-index: 5;
}

#clock {
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: 0 4px 14px rgba(160, 110, 170, 0.15);
  white-space: pre;
}

/* ———— 对话气泡 ———— */
#bubbles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  overflow: hidden;
}

.bubble {
  position: absolute;
  left: 0;
  top: 0;
  max-width: min(64vw, 260px);
  padding: 7px 12px;
  border-radius: 16px;
  background: var(--glass-strong);
  box-shadow: 0 6px 18px rgba(160, 110, 170, 0.25);
  font-size: 14px;
  line-height: 1.4;
  font-weight: 600;
  color: var(--ink);
  text-align: center;
  will-change: transform, opacity;
  transform-origin: 50% 100%;
}

.bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 12px;
  height: 12px;
  background: inherit;
  transform: translateX(-50%) rotate(45deg);
  border-radius: 2px;
}

.bubble.letter {
  background: #fff7fb;
  border: 1.5px dashed var(--pink);
  font-weight: 500;
  font-size: 13.5px;
}

/* ———— 字幕与提示 ———— */
#caption {
  position: fixed;
  left: 50%;
  top: calc(18% + var(--safe-t));
  transform: translate(-50%, 10px);
  padding: 10px 20px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--pink-deep);
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.2s ease, transform 1.2s ease;
  z-index: 6;
  white-space: nowrap;
}

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

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-b));
  transform: translate(-50%, 12px);
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--glass-strong);
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 30;
}

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

#flash {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 40;
}

#flash.go {
  animation: flash 0.5s ease-out;
}

@keyframes flash {
  0% { opacity: 0.85; }
  100% { opacity: 0; }
}

/* ———— 右下角的小云按钮 ———— */
#fab {
  position: fixed;
  right: calc(16px + var(--safe-r));
  bottom: calc(16px + var(--safe-b));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  z-index: 20;
  display: grid;
  place-items: center;
  animation: bob 3.2s ease-in-out infinite;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s;
}

#fab:active {
  transform: scale(0.9);
}

#fab.open {
  background: #ffe3ef;
}

.fab-cloud {
  position: relative;
  width: 30px;
  height: 14px;
  margin-top: 8px;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 0 0 2.5px var(--pink);
}

.fab-cloud::before,
.fab-cloud::after {
  content: "";
  position: absolute;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 2.5px var(--pink);
  z-index: -1;
}

.fab-cloud::before {
  width: 14px;
  height: 14px;
  left: 3px;
  top: -8px;
}

.fab-cloud::after {
  width: 17px;
  height: 17px;
  left: 11px;
  top: -11px;
}

@keyframes bob {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -4px; }
}

/* ———— 控制面板 ———— */
#panel {
  position: fixed;
  right: calc(12px + var(--safe-r));
  bottom: calc(86px + var(--safe-b));
  width: min(340px, calc(100vw - 24px));
  max-height: min(62vh, 520px);
  overflow-y: auto;
  padding: 14px 14px 12px;
  border-radius: 24px;
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  z-index: 19;
  transform-origin: 90% 100%;
  animation: pop-in 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#panel[hidden] {
  display: none;
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.85) translateY(10px); }
  to { opacity: 1; transform: none; }
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
  font-size: 15px;
}

.panel-head button {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
  font-size: 13px;
}

.row-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 2px 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  letter-spacing: 0.08em;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chips button,
button.mini {
  min-height: 34px;
  padding: 6px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  border: 1.5px solid transparent;
  font-size: 13.5px;
  font-weight: 600;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s, border-color 0.2s;
}

button.mini {
  min-height: 26px;
  padding: 3px 9px;
  font-size: 11.5px;
  letter-spacing: 0;
  color: var(--ink);
}

.chips button:active,
button.mini:active {
  transform: scale(0.92);
}

.chips button.on {
  background: #ffe3ef;
  border-color: var(--pink);
  color: #c2527e;
}

.hint {
  margin: 12px 2px 0;
  font-size: 11.5px;
  color: var(--ink-soft);
  line-height: 1.5;
}

/* ———— 开场 ———— */
#intro {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: radial-gradient(circle at 50% 40%, #fff6fa 0%, #ffe1ee 45%, #d9ecff 100%);
  transition: opacity 0.9s ease, transform 0.9s ease;
  cursor: pointer;
  padding: 24px;
  text-align: center;
}

#intro.leave {
  opacity: 0;
  transform: scale(1.08);
  pointer-events: none;
}

#intro h1 {
  margin: 18px 0 0;
  font-size: 34px;
  letter-spacing: 0.18em;
  color: #e7799f;
  text-shadow: 0 3px 0 #fff;
}

.intro-sub {
  margin: 0;
  font-size: 14px;
  color: var(--ink-soft);
}

.intro-tip {
  margin-top: 26px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.intro-tip .go {
  display: none;
}

#intro.ready .intro-tip .loading {
  display: none;
}

#intro.ready .intro-tip .go {
  display: inline;
  animation: breathe 1.8s ease-in-out infinite;
}

.intro-tip .loading::after {
  content: "";
  animation: dots 1.4s steps(4) infinite;
}

@keyframes dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75% { content: "..."; }
}

@keyframes breathe {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.intro-cloud {
  position: relative;
  width: 150px;
  height: 90px;
  animation: float 2.6s ease-in-out infinite;
}

.intro-cloud .puff {
  position: absolute;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 10px 24px rgba(200, 150, 190, 0.25);
}

.intro-cloud .puff.a { width: 70px; height: 70px; left: 8px; top: 22px; }
.intro-cloud .puff.b { width: 90px; height: 90px; left: 36px; top: 0; }
.intro-cloud .puff.c { width: 64px; height: 64px; left: 84px; top: 26px; }

.intro-cloud .ear {
  position: absolute;
  top: -8px;
  width: 0;
  height: 0;
  border-left: 15px solid transparent;
  border-right: 15px solid transparent;
  border-bottom: 26px solid #e9826a;
}

.intro-cloud .ear.l { left: 44px; transform: rotate(-16deg); }
.intro-cloud .ear.r { left: 86px; transform: rotate(16deg); }

.intro-cloud .face {
  position: absolute;
  left: 58px;
  top: 44px;
  display: flex;
  gap: 18px;
}

.intro-cloud .eye {
  width: 8px;
  height: 10px;
  border-radius: 50%;
  background: #5a4660;
  animation: blink 4s infinite;
}

@keyframes blink {
  0%, 92%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(0.1); }
}

@keyframes float {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  50% { transform: translateY(-10px) scale(1.03, 0.97); }
}

/* ———— 出错 ———— */
#fail {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: linear-gradient(#e3f1ff, #ffe6f0);
  padding: 24px;
}

#fail[hidden] {
  display: none;
}

.fail-card {
  max-width: 320px;
  padding: 26px 22px;
  border-radius: 26px;
  background: var(--glass-strong);
  box-shadow: var(--shadow);
  text-align: center;
}

.fail-icon {
  font-size: 44px;
}

.fail-card h2 {
  margin: 8px 0;
  font-size: 19px;
  color: var(--pink-deep);
}

.fail-card p {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink-soft);
}

/* ———— 调试（地址后加 ?debug 才出现） ———— */
#debug {
  position: fixed;
  left: 8px;
  top: calc(52px + var(--safe-t));
  width: min(92vw, 420px);
  max-height: 45vh;
  overflow: auto;
  padding: 8px;
  border-radius: 12px;
  background: rgba(30, 20, 40, 0.72);
  color: #fff;
  font: 11px/1.4 ui-monospace, Menlo, monospace;
  z-index: 70;
  pointer-events: auto;
  white-space: pre-wrap;
  -webkit-user-select: text;
  user-select: text;
}

#debug[hidden] {
  display: none;
}

.debug-stat {
  font-weight: 700;
  margin-bottom: 6px;
}

.debug-row {
  padding: 3px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.debug-row.error { color: #ffb3c1; }
.debug-row.warn { color: #ffe29a; }

/* 电脑上面板稍微大一点 */
@media (min-width: 900px) and (pointer: fine) {
  #panel {
    width: 360px;
  }
  #clock {
    font-size: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #fab,
  .intro-cloud,
  #intro.ready .intro-tip .go {
    animation: none;
  }
}
