/* 奏 · 手机桌宠 —— 夜色里的安静工作室 */
:root {
  --ink: #2f3945;
  --ink-2: #5c6b79;
  --accent: #934657;
  --accent-2: #7d3a49;
  --line: #d7dde1;
  --paper: #faf8f4;
  --paper-2: #f1ece6;
  --glass: rgba(250, 248, 244, 0.9);
  --night: #191a21;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --kb: 0px;                 /* 键盘挡住的高度，由 ui.js 实时更新 */
  --chat-h: 54px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overflow: hidden; overscroll-behavior: none;
  background: var(--night);
  color: var(--ink);
  font-family: "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  -webkit-user-select: none; user-select: none;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  -webkit-touch-callout: none;
}
body.pet-surface { background: transparent; }
input, textarea, button, select { font-family: inherit; }

/* ---------- 背景 ---------- */
#bg {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(120% 90% at 78% -10%, #3d3444 0%, rgba(61, 52, 68, 0) 55%),
    radial-gradient(90% 70% at 12% 8%, #26303c 0%, rgba(38, 48, 60, 0) 60%),
    linear-gradient(178deg, #20222b 0%, #1b1c24 44%, #121319 100%);
}
/* 五线谱的淡淡横线 + 底部一点暖光 */
#bg::before {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 46%;
  background-image: repeating-linear-gradient(to top, rgba(211, 199, 207, 0.055) 0 1px, transparent 1px 17px);
  mask-image: linear-gradient(to top, rgba(0, 0, 0, 0.9), transparent 85%);
  -webkit-mask-image: linear-gradient(to top, rgba(0, 0, 0, 0.9), transparent 85%);
}
#bg::after {
  content: ""; position: absolute; left: 50%; bottom: 2%; width: 76vw; height: 90px;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at center, rgba(147, 70, 87, 0.22), rgba(147, 70, 87, 0) 68%);
  filter: blur(6px);
}
/* 飘着的音符（纯装饰） */
.note {
  position: fixed; z-index: 0; color: rgba(211, 199, 207, 0.13); pointer-events: none;
  font-size: 20px; animation: drift 14s linear infinite;
}
@keyframes drift {
  0% { transform: translateY(12vh) scale(0.9); opacity: 0; }
  20% { opacity: 1; }
  80% { opacity: 0.9; }
  100% { transform: translateY(-42vh) scale(1.08); opacity: 0; }
}

/* ---------- 舞台 ---------- */
#stage { position: fixed; inset: 0; z-index: 2; }
#stage canvas { display: block; touch-action: none; }

/* ---------- 气泡 ---------- */
#bubble {
  position: fixed; left: 0; right: 0; margin: 0 auto; width: fit-content;
  top: calc(var(--safe-t) + 8px); transform: translateY(6px);
  max-width: calc(100% - 30px);
  max-height: 52vh !important; overflow-y: auto !important;
  padding: 10px 15px; border-radius: 16px;
  background: rgba(250, 248, 244, 0.97); color: #303c49;
  border: 1.5px solid #aebfc9;
  box-shadow: 0 6px 22px rgba(8, 10, 16, 0.35);
  font-size: 15px; line-height: 1.58; letter-spacing: 0.25px;
  opacity: 0; transition: opacity .24s ease, transform .24s ease;
  pointer-events: none; white-space: pre-wrap;
  text-wrap: pretty; line-break: strict; overflow-wrap: anywhere; word-break: keep-all;
  z-index: 6;
}
#bubble.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
/* 手机版不用小三角：滚动气泡时它会被算进溢出，右侧冒出一条滚动条 */
#bubble::after { display: none; }
#bubble.long { font-size: 14px; line-height: 1.58; padding: 9px 13px; }
#bubble.long .ja { font-size: 12px; }
#bubble.notice { border-color: #934657; }
#bubble .ja {
  display: block; margin-top: 6px; padding-top: 5px; border-top: 1px dashed #d3dbe0;
  font-size: 12.5px; line-height: 1.5; color: #5d7182;
  font-family: "Hiragino Sans", "Yu Gothic", "Noto Sans CJK JP", "Noto Sans JP", sans-serif;
  word-break: auto-phrase;
}
#bubble .ja.karaoke .k { color: #b8c5cd; transition: color .12s; }
#bubble .ja.karaoke .k.on { color: #823b4d; }
#bubble .tag { display: block; font-size: 11px; color: #934657; margin-bottom: 3px; letter-spacing: 1px; }

/* ---------- 底部聊天条 ---------- */
#chat {
  position: fixed; left: 10px; right: 10px;
  bottom: calc(var(--safe-b) + 10px + var(--kb, 0px));
  display: flex; gap: 4px; align-items: center; padding: 6px 6px 6px 8px;
  background: rgba(250, 248, 244, 0.97);
  border: 1.5px solid #b7c6cf; border-radius: 19px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.38);
  opacity: 0; transform: translateY(12px) scale(0.98);
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none; z-index: 12;
}
#chat.show { opacity: 1; transform: none; pointer-events: auto; }
#chatInput {
  flex: 1; min-width: 0; border: 0; outline: none; background: transparent;
  font-size: 16px; color: var(--ink); padding: 6px 4px;
}
#chatInput::placeholder { color: #7c8d9a; }
#chat button {
  border: 0; background: none; color: var(--accent); padding: 0;
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex: none;
}
#chat button:active { background: #efe7e6; }
#chatSend { background: var(--accent) !important; color: #fff !important; border-radius: 14px !important; }
#chatSend:active { background: var(--accent-2) !important; }
#chatClose { color: #7c8d9a !important; width: 34px !important; }
#chat.busy #chatSend { opacity: .4; pointer-events: none; }
#chatImg { display: none; position: relative; flex: none; width: 36px; height: 36px; border-radius: 9px; overflow: hidden; border: 1.5px solid #d6d2ea; }
#chatImg.show { display: block; }
#chatImg img { width: 100%; height: 100%; object-fit: cover; display: block; }
#chatImg span { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(59, 56, 80, .45); color: #fff; font-size: 16px; }
#chat.drag { border-color: #934657; background: #f0eefa; }

/* 桌宠页面自带的两个按钮：手机上有常驻 FAB，这两个不显示 */
#chatBtn, #callBtn { display: none !important; }

/* ---------- 常驻按钮 ---------- */
#menuBtn, #chatFab {
  position: fixed; z-index: 8; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; padding: 0;
  background: rgba(24, 25, 32, 0.42);
  color: #f5eef0; border: 1.5px solid rgba(233, 220, 224, 0.32);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  transition: transform .15s ease, background .15s ease, opacity .2s;
}
#menuBtn:active, #chatFab:active { transform: scale(0.92); background: rgba(250, 248, 244, 0.24); }
#menuBtn {
  left: calc(var(--safe-l) + 12px);
  bottom: calc(var(--safe-b) + 22px);
  background: rgba(24, 25, 32, 0.46);
}
#chatFab {
  right: calc(var(--safe-r) + 12px);
  bottom: calc(var(--safe-b) + 22px);
  width: 54px; height: 54px;
  background: linear-gradient(145deg, #a55264, #833a4b);
  border-color: rgba(255, 235, 238, 0.35);
  color: #fff;
  box-shadow: 0 8px 22px rgba(94, 33, 47, 0.45);
}
#chatFab svg { margin-top: -2px; }
body.chat-open #chatFab { opacity: 0; pointer-events: none; transform: scale(.8); }
body.sheet-open #chatFab, body.sheet-open #menuBtn { opacity: 0; pointer-events: none; }

/* ---------- 启动画面 ---------- */
#boot {
  position: fixed; inset: 0; z-index: 60; display: grid; place-content: center; justify-items: center; gap: 14px;
  background: radial-gradient(80% 60% at 50% 40%, #24222c 0%, #15161d 70%);
  transition: opacity .5s ease; color: #d9cfd3;
}
#boot.hide { opacity: 0; pointer-events: none; }
#boot .boot-note { font-size: 34px; color: #a55264; animation: bootPulse 1.6s ease-in-out infinite; }
#boot .boot-text { font-size: 13px; letter-spacing: 2px; color: #9c8f95; }
#boot .boot-sub { font-size: 11px; letter-spacing: 1px; color: #6c626a; margin-top: 2px; }
@keyframes bootPulse { 50% { transform: scale(1.12); opacity: .65; } }

/* ---------- 底部抽屉 ---------- */
#sheetBackdrop {
  position: fixed; inset: 0; z-index: 28; background: rgba(8, 9, 13, 0.58);
  opacity: 0; pointer-events: none; transition: opacity .22s ease;
}
#sheetBackdrop.open { opacity: 1; pointer-events: auto; }
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  max-height: 86vh; display: flex; flex-direction: column;
  background: var(--paper); color: var(--ink);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.4);
  transform: translateY(103%); transition: transform .28s cubic-bezier(.22, .9, .3, 1);
  padding-bottom: var(--safe-b);
}
#sheet.open { transform: translateY(0); }
#sheet .grip {
  width: 42px; height: 4px; border-radius: 4px; background: #d8d2ca; margin: 9px auto 2px; flex: none;
}
#sheet .sheet-head {
  display: flex; align-items: center; gap: 10px; padding: 8px 18px 10px; flex: none;
  border-bottom: 1px solid #ebe4dc;
}
#sheet .sheet-head h2 {
  margin: 0; font-size: 16px; font-weight: 600; letter-spacing: 1px; color: var(--accent);
  display: flex; align-items: center; gap: 8px;
}
#sheet .sheet-head h2::before { content: "♫"; font-size: 14px; color: #b9899a; }
#sheet .sheet-head .close {
  margin-left: auto; width: 34px; height: 34px; border: 0; border-radius: 50%;
  background: #efe9e3; color: #6a5b63; display: grid; place-items: center;
}
#sheet .sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 16px 22px; overscroll-behavior: contain; }

/* 菜单列表 */
.menu-list { display: flex; flex-direction: column; gap: 6px; }
.menu-item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 9px 12px; border: 1.5px solid #e7ded6; border-radius: 14px;
  background: #fffdfa; color: var(--ink); text-align: left;
}
.menu-item:active { background: #f5efe9; transform: scale(0.99); }
.menu-item .ico {
  width: 34px; height: 34px; flex: none; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(145deg, #f2e6e8, #e9edf0); color: var(--accent); font-size: 14px;
}
.menu-item .txt { flex: 1; min-width: 0; }
.menu-item .txt b { display: block; font-size: 14.5px; font-weight: 600; }
.menu-item .txt small { display: block; font-size: 11px; color: #8b7d84; margin-top: 1px; }
.menu-item .arrow { color: #c2b6ba; font-size: 16px; flex: none; }
.menu-item.danger .ico { background: #f7e6e9; color: #b0475a; }
.menu-item.danger .txt b { color: #a34253; }

/* 表单 */
.field { margin-bottom: 15px; }
.field > label { display: block; font-size: 13px; color: #6d5f66; margin-bottom: 6px; letter-spacing: .5px; }
.field .sub { font-size: 11.5px; color: #9a8d93; margin-top: 5px; line-height: 1.5; }
.field input[type=text], .field input[type=password], .field input[type=url], .field input[type=number], .field textarea, .field select {
  width: 100%; border: 1.5px solid #ddd4cd; border-radius: 12px; background: #fffdfa;
  color: var(--ink); font-size: 15px; padding: 10px 12px; outline: none;
  -webkit-user-select: text; user-select: text;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(147, 70, 87, 0.1); }
.field textarea { min-height: 96px; resize: vertical; line-height: 1.55; font-size: 14px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button {
  flex: 1; min-width: 62px; padding: 9px 8px; border: 1.5px solid #ddd4cd; border-radius: 11px;
  background: #fffdfa; color: #6d5f66; font-size: 13.5px;
}
.seg button.on { border-color: var(--accent); background: #f6eaec; color: var(--accent); font-weight: 600; }
/* 滑杆用暗红色，和整体配色一致 */
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; margin: 2px 0; }
input[type=range]::-webkit-slider-runnable-track { height: 5px; border-radius: 3px; background: #e6ddd6; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; margin-top: -7.5px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .22);
}
input[type=range]::-moz-range-track { height: 5px; border-radius: 3px; background: #e6ddd6; }
input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--accent); border: 2px solid #fff; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0 2px; }
.switch-row .lbl { font-size: 14.5px; }
.switch-row .sub { display: block; font-size: 11.5px; color: #9a8d93; margin-top: 2px; }
.switch {
  position: relative; width: 48px; height: 28px; flex: none; border-radius: 20px; background: #d9d1ca;
  transition: background .18s; border: 0;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .22); transition: transform .18s;
}
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(20px); }
.btn-row { display: flex; gap: 9px; margin-top: 4px; flex-wrap: wrap; }
.btn {
  border: 1.5px solid #d8cfc8; background: #fffdfa; color: var(--ink); border-radius: 12px;
  padding: 10px 14px; font-size: 14px; font-weight: 500;
}
.btn:active { background: #f4eee8; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-2); }
.btn.ghost { color: var(--accent); border-color: #e3d3d7; background: #fdf6f7; }
.btn.danger { color: #b0475a; border-color: #eccfd4; background: #fdf3f4; }
.btn.small { padding: 7px 11px; font-size: 12.5px; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.hint-box { background: #f2ece6; border-radius: 12px; padding: 10px 12px; font-size: 12.5px; line-height: 1.6; color: #6d5f66; }
.hint-box b { color: var(--accent); }
.result { margin-top: 10px; font-size: 12.5px; line-height: 1.55; padding: 9px 11px; border-radius: 10px; display: none; white-space: pre-wrap; word-break: break-word; }
.result.show { display: block; }
.result.ok { background: #edf5ee; color: #376b46; }
.result.err { background: #fbeef0; color: #a34253; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs button {
  flex: 1; padding: 8px 4px; border: 0; border-bottom: 2px solid transparent; background: none;
  color: #8b7d84; font-size: 13.5px; border-radius: 8px 8px 0 0;
}
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); background: #f6efef; font-weight: 600; }
.section-title { font-size: 12px; letter-spacing: 1.5px; color: #a99aa1; margin: 18px 2px 9px; }
.section-title:first-child { margin-top: 0; }

/* 记忆 / 好感 */
.item-list { display: flex; flex-direction: column; gap: 7px; }
.mem-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 11px; border: 1.5px solid #e9e0d8; border-radius: 13px; background: #fffdfa; }
.mem-item .body { flex: 1; min-width: 0; }
.mem-item .body p { margin: 0; font-size: 14px; line-height: 1.5; word-break: break-word; -webkit-user-select: text; user-select: text; }
.mem-item .body time { display: block; font-size: 10.5px; color: #a99aa1; margin-top: 3px; }
.mem-item .del { border: 0; background: #f6eaec; color: #a34253; border-radius: 9px; width: 30px; height: 30px; flex: none; font-size: 15px; }
.empty { text-align: center; color: #a99aa1; font-size: 13px; padding: 26px 10px; line-height: 1.7; }

.aff-hero { text-align: center; padding: 8px 0 16px; }
.aff-hero .num { font-size: 46px; font-weight: 300; color: var(--accent); line-height: 1; font-variant-numeric: tabular-nums; }
.aff-hero .num small { font-size: 15px; color: #b9a9af; margin-left: 4px; }
.aff-hero .band { margin-top: 8px; font-size: 14px; letter-spacing: 3px; color: #6d5f66; }
.aff-bar { height: 9px; border-radius: 6px; background: #ece4dd; overflow: hidden; margin: 14px 0 4px; }
.aff-bar i { display: block; height: 100%; border-radius: 6px; background: linear-gradient(90deg, #c78a97, #934657); transition: width .4s; }
.aff-ends { display: flex; justify-content: space-between; font-size: 10.5px; color: #a99aa1; }
.log-item { display: flex; gap: 10px; align-items: baseline; padding: 8px 2px; border-bottom: 1px dashed #ebe2da; font-size: 13px; }
.log-item:last-child { border-bottom: 0; }
.log-item .d { font-variant-numeric: tabular-nums; font-weight: 600; flex: none; width: 38px; }
.log-item .d.up { color: #4e7d5c; }
.log-item .d.down { color: #a34253; }
.log-item .why { flex: 1; color: #6d5f66; line-height: 1.5; }
.log-item time { font-size: 10.5px; color: #a99aa1; flex: none; }

/* 提示条 */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 88px); transform: translate(-50%, 10px);
  z-index: 40; max-width: 86vw; padding: 9px 15px; border-radius: 12px;
  background: rgba(34, 35, 43, 0.94); color: #f2eaec; font-size: 13px; line-height: 1.55;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .4); opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 横屏 / 大屏 */
@media (orientation: landscape) and (max-height: 520px) {
  #bubble { max-width: 70vw; font-size: 13.5px; padding: 8px 12px; }
  #chat { left: 18%; right: 18%; }
  #chatFab { width: 46px; height: 46px; }
  #menuBtn { width: 38px; height: 38px; }
}
