:root {
  --bg: #fff0f6;
  --bg2: #f5f0ff;
  --card: #ffffff;
  --soft: #fff6f9;
  --line: #ffe0ec;
  --text: #55404f;
  --dim: #a98fa6;
  --pink: #ff7ea8;
  --pink-d: #ff5c8a;
  --purple: #b79bff;
  --ok: #4fd39a;
  --danger: #ff5c7a;
  --shadow: 0 8px 24px rgba(255, 126, 168, .14);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(circle at 12% 8%, #ffe3ef 0%, transparent 42%),
    radial-gradient(circle at 88% 88%, #ede4ff 0%, transparent 45%),
    var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(104px + env(safe-area-inset-bottom));
  min-height: 100vh;
}
body::before {
  content: "";
  position: fixed; inset: 0; pointer-events: none; opacity: .5;
  background-image: radial-gradient(#ffd3e3 1px, transparent 1px);
  background-size: 18px 18px;
  mask-image: radial-gradient(circle at 50% 0%, #000 0%, transparent 70%);
}
.bg-deco { position: fixed; inset: 0; pointer-events: none; font-size: 18px; color: #ffc3d8; }
.bg-deco span { position: absolute; animation: float 6s ease-in-out infinite; }
.bg-deco span:nth-child(1) { left: 8%; top: 18%; }
.bg-deco span:nth-child(2) { right: 10%; top: 12%; animation-delay: 1.2s; color: #d9c8ff; }
.bg-deco span:nth-child(3) { left: 14%; bottom: 26%; animation-delay: 2.4s; color: #d9c8ff; }
.bg-deco span:nth-child(4) { right: 12%; bottom: 32%; animation-delay: .6s; }
@keyframes float { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-10px) } }

.app { max-width: 520px; margin: 0 auto; padding: 0 16px; position: relative; }

/* ---------- 顶部 ---------- */
.top { display: flex; align-items: center; gap: 12px;
  padding: calc(16px + env(safe-area-inset-top)) 2px 14px; }
.mascot { width: 58px; height: 58px; flex: 0 0 58px; display: grid; place-items: center;
  background: #fff; border-radius: 20px; box-shadow: var(--shadow); animation: bob 3s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-2deg) } 50% { transform: translateY(-5px) rotate(2deg) } }
.titles { flex: 1; min-width: 0; }
h1 { font-size: 21px; margin: 0 0 3px; letter-spacing: .04em; font-weight: 800; color: #6b4a5e; }
h1::after { content: " ♡"; color: var(--pink); font-size: 16px; }
.status { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--dim); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #e5d3dc; }
.status.wait .dot { background: #ffc857; animation: blink 1.2s infinite; }
.status.on .dot { background: var(--ok); box-shadow: 0 0 8px rgba(79,211,154,.8); }
.status.on { color: #3aa87a; }
@keyframes blink { 50% { opacity: .35 } }
.cap { font-size: 11.5px; color: #c07f9b; background: #fff; border: 1px solid var(--line);
  padding: 4px 10px; border-radius: 999px; white-space: nowrap; }

/* ---------- 卡片 ---------- */
.card { background: var(--card); border-radius: 24px; padding: 18px;
  box-shadow: var(--shadow); margin-bottom: 14px; border: 1px solid #fff; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 800; color: #6b4a5e;
  display: flex; align-items: center; gap: 8px; }
.num { width: 22px; height: 22px; border-radius: 50%; background: linear-gradient(135deg, #ffd3e3, #e3d4ff);
  color: #8a5b74; font-size: 12px; font-weight: 800; display: grid; place-items: center; }
.tag { font-style: normal; font-size: 10.5px; font-weight: 600; color: #8a5b74;
  background: #fff0f6; padding: 2px 8px; border-radius: 999px; margin-left: auto; }
.tag.ok { color: #2f9e73; background: #e7fbf1; }
.tag.off { color: #b5a0ae; background: #f7f2f5; }

.hint { color: var(--dim); font-size: 13px; line-height: 1.7; margin: 0 0 14px; }
.hint.center { text-align: center; margin: 10px 0 0; }
.hint.inline { margin: 0; }
.hint.tiny { font-size: 11.5px; margin: 8px 0 0; line-height: 1.6; }
.hint b { color: #8a5b74; }

/* ---------- 按钮 ---------- */
button { font: inherit; border: 0; cursor: pointer; transition: transform .12s ease, box-shadow .12s ease; }
button:active { transform: scale(.97); }
.primary { width: 100%; padding: 16px; border-radius: 18px; font-size: 16px; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, var(--pink) 0%, #ff9ec0 55%, #c8a8ff 100%);
  box-shadow: 0 10px 22px rgba(255, 126, 168, .32); letter-spacing: .03em; }
.primary:disabled { background: #f0e3ea; color: #c0a9b7; box-shadow: none; }
.ghost { background: var(--soft); color: #7d5a6f; padding: 12px 16px; border-radius: 14px;
  border: 1.5px solid var(--line); font-size: 14px; font-weight: 600; }
.ghost:active { background: #ffeaf3; }
.ghost.wide { display: block; width: 100%; text-align: center; margin-top: 10px; text-decoration: none; }
.ghost.icon { padding: 12px 13px; }
.grow { flex: 1; }

/* ---------- 配对 ---------- */
.pair { margin-top: 16px; }
.qr { background: #fff; border-radius: 20px; padding: 10px; width: 100%; max-width: 250px;
  margin: 0 auto; border: 2.5px solid #ffe0ec; box-shadow: 0 6px 18px rgba(255,126,168,.18); }
.qr.svgWrap { line-height: 0; }
#qr svg { display: block; width: 100%; height: auto; border-radius: 12px; }

/* ---------- 设备 ---------- */
.devline { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 14px; }
.devline b { font-size: 15px; color: #6b4a5e; }
.devline span { color: var(--dim); font-size: 12.5px; }
.channels { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.ch { background: linear-gradient(160deg, #fff7fa, #f7f2ff); border: 1.5px solid #ffe8f1;
  border-radius: 20px; padding: 12px 8px; text-align: center; }
.chHead { font-size: 12px; color: #b08fa3; font-weight: 600; }
.val { font-size: 42px; font-weight: 800; line-height: 1.15; color: #6b4a5e; font-variant-numeric: tabular-nums; }
.chBtns { display: flex; gap: 10px; justify-content: center; margin-top: 8px; }
.rnd { width: 56px; height: 48px; border-radius: 16px; font-size: 22px; font-weight: 700; color: #8a5b74;
  background: #fff; border: 1.5px solid #ffdcea; box-shadow: 0 4px 10px rgba(255,126,168,.14); }
.rnd:active { background: #fff0f6; }

/* ---------- 表单 ---------- */
.row { display: flex; gap: 9px; align-items: center; }
.row + .row { margin-top: 10px; }
.row.small { font-size: 13px; color: var(--dim); gap: 10px; }
.row.small label { display: flex; align-items: center; gap: 5px; color: #7d5a6f; }
.label { white-space: nowrap; font-size: 12.5px; color: #b08fa3; }
select, input[type="text"] {
  flex: 1; min-width: 0; font: inherit; font-size: 14px; color: var(--text);
  background: var(--soft); border: 1.5px solid var(--line); border-radius: 14px; padding: 12px 14px;
  appearance: none; -webkit-appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, #c9a8bb 50%), linear-gradient(135deg, #c9a8bb 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%; background-size: 6px 6px, 6px 6px; background-repeat: no-repeat;
  padding-right: 34px; }
input:focus, select:focus { outline: none; border-color: #ffc3da; background: #fff; }
input[type="radio"] { accent-color: var(--pink); width: 16px; height: 16px; }

/* ---------- AI ---------- */
.chat { max-height: 210px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px;
  margin-bottom: 12px; font-size: 14px; line-height: 1.6; scroll-behavior: smooth; }
.chat:empty::after { content: "还什么都没说呢～"; color: #c9b4c1; font-size: 12.5px; text-align: center; padding: 12px 0; }
.chat .m { padding: 8px 13px; border-radius: 16px; max-width: 86%; word-break: break-word; }
.chat .me { align-self: flex-end; background: linear-gradient(135deg, #ffd6e6, #ffe9f2); color: #6b4a5e; border-bottom-right-radius: 5px; }
.chat .ai { align-self: flex-start; background: #f6f1ff; color: #5f5270; border-bottom-left-radius: 5px; }
.chat .act { align-self: center; font-size: 11.5px; color: #b39bb0; background: #fdf6f9; padding: 4px 12px; border-radius: 999px; }
.sep { height: 1px; background: linear-gradient(90deg, transparent, #ffe0ec, transparent); margin: 14px 0; }
.keybox { display: flex; gap: 8px; align-items: center; }
.keybox input { flex: 1; min-width: 0; font-size: 13px; padding: 11px 13px;
  background: #fffafc; border: 1.5px dashed #ffd3e3; border-radius: 14px; }
.keybox input::placeholder { color: #d4bcc9; }
#aiMode { margin: 6px 0 12px; color: #c09aae; }

/* ---------- 急停 ---------- */
.estop { position: fixed; left: 16px; right: 16px; bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: 10; max-width: 488px; margin: 0 auto;
  padding: 17px 20px; font-size: 16px; font-weight: 800; letter-spacing: .08em; color: #fff;
  background: linear-gradient(135deg, #ff7f97, #ff5470);
  border-radius: 20px; border: 2px solid #ffd3dd;
  box-shadow: 0 10px 26px rgba(255, 84, 112, .35); }
.estop:active { filter: brightness(.94); transform: scale(.985); }

/* ---------- 提示 ---------- */
.toast { position: fixed; left: 50%; top: calc(16px + env(safe-area-inset-top)); transform: translateX(-50%);
  background: #fff; color: #6b4a5e; padding: 10px 20px; border-radius: 999px; font-size: 13.5px;
  font-weight: 600; box-shadow: 0 10px 28px rgba(180, 110, 145, .22); z-index: 30;
  border: 1.5px solid #ffe0ec; max-width: 88vw; text-align: center; }
.hidden { display: none !important; }

#autoBtn.running { background: #fff0f3; border-color: #ffc9d4; color: #e0506e; }
.hint.safe { background: #fff8fb; border: 1.5px dashed #ffd3e3; border-radius: 12px;
  padding: 8px 12px; color: #b08fa3; }
.hint.safe b { color: #e0506e; }