:root {
  --bg: #0e1015;
  --bg2: #14171e;
  --line: #232833;
  --text: #eceef5;
  --dim: #8c95a8;
  --owner: #262b35;
  --owner-line: #313846;
  --her: #1b2740;
  --her-line: #2a3d63;
  --accent: #6ea8ff;
  --warn: #ffb020;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 17px/1.65 -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body {
  display: flex; flex-direction: column;
  height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

#bar {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bg2); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
#who { display: flex; align-items: center; gap: 8px; font-size: 16px; }
#name { font-weight: 600; letter-spacing: .02em; }
#state { color: var(--dim); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #444; display: inline-block; }
.dot.on { background: #35d07f; box-shadow: 0 0 8px rgba(53,208,127,.6); }
.dot.off { background: #b94a4a; }

#menu { background: none; border: 0; color: var(--dim); font-size: 20px; padding: 4px 8px; }

#log {
  flex: 1 1 auto; overflow-y: auto; padding: 16px 14px 10px;
  display: flex; flex-direction: column; gap: 16px;
  scroll-behavior: smooth;
}
#log .cont { margin-top: -10px; }

.msg { display: flex; gap: 10px; align-items: flex-start; max-width: 86%; }
.msg.her { align-self: flex-start; }
.msg.owner { align-self: flex-end; flex-direction: row-reverse; }

.avatar {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%;
  background: #1a2130 center/cover no-repeat;
  border: 1px solid var(--line);
}
.avatar.spacer { visibility: hidden; }

.body { display: flex; flex-direction: column; min-width: 0; }
.msg.owner .body { align-items: flex-end; }

.who-name {
  font-size: 12px; color: var(--dim); margin: 0 4px 4px;
}

.bubble {
  padding: 10px 15px; border-radius: 18px;
  white-space: pre-wrap; word-break: break-word;
  background: var(--her); border: 1px solid var(--her-line);
  border-top-left-radius: 6px;
}
.msg.owner .bubble {
  background: var(--owner); border-color: var(--owner-line);
  border-top-left-radius: 18px; border-top-right-radius: 6px;
}
.msg.proactive .bubble { border-color: var(--warn); box-shadow: 0 0 0 1px rgba(255,176,32,.18) inset; }

.meta {
  font-size: 11px; color: #6f788a; margin: 5px 6px 0; line-height: 1.4;
}
.msg.proactive .meta::before { content: "她主动 · "; color: var(--warn); }

.jump {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + env(safe-area-inset-bottom));
  background: var(--accent); color: #06122b; border: 0;
  padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,.4); z-index: 6;
}
.hidden { display: none; }

#composer {
  flex: 0 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg2); border-top: 1px solid var(--line);
}
#input {
  flex: 1 1 auto; resize: none; max-height: 132px;
  background: #0b0d12; color: var(--text); font: inherit;
  border: 1px solid var(--line); border-radius: 20px;
  padding: 11px 15px; outline: none;
}
#input:focus { border-color: #33405a; }
#send {
  flex: 0 0 auto; width: 42px; height: 42px; border-radius: 50%;
  border: 0; background: var(--accent); color: #06122b; font-size: 18px; font-weight: 700;
}
#send:disabled { opacity: .4; }

.gate {
  position: fixed; inset: 0; background: rgba(8,10,14,.96);
  display: flex; align-items: center; justify-content: center; z-index: 20;
}
.gate.hidden { display: none; }
.gatebox { width: 260px; text-align: center; }
.gatebox h1 { font-size: 18px; margin: 0 0 6px; }
.hint { color: var(--dim); font-size: 12px; margin: 0 0 16px; }
#pin {
  width: 100%; padding: 12px; text-align: center; letter-spacing: .5em;
  font-size: 20px; background: #0b0d12; color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; outline: none;
}
#pinok {
  width: 100%; margin-top: 12px; padding: 12px; border: 0; border-radius: 12px;
  background: var(--accent); color: #06122b; font-size: 15px; font-weight: 600;
}
.err { color: #ff7b72; font-size: 12px; min-height: 16px; margin-top: 8px; }
