:root {
  --bg: #08131f;
  --bg-2: #0d1e30;
  --panel: rgba(17, 36, 55, .92);
  --panel-2: #12283d;
  --line: rgba(255, 255, 255, .08);
  --text: #e8f2fb;
  --muted: #8fa6bb;
  --blue: #4cc2ff;
  --blue-2: #2a8fd6;
  --pearl: #f3fbff;
  --user: linear-gradient(135deg, #2a8fd6, #3fb7ef);
  --bot: rgba(20, 43, 64, .96);
  --danger: #ff6b81;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 80% -10%, rgba(76, 194, 255, .16), transparent 60%),
    radial-gradient(900px 600px at -10% 110%, rgba(35, 98, 153, .22), transparent 60%),
    var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login {
  position: fixed; inset: 0; display: grid; place-items: center;
  padding: 24px; background: rgba(5, 12, 20, .94); z-index: 50;
}
.login-card {
  width: min(380px, 100%); padding: 28px 24px; border-radius: 24px;
  background: linear-gradient(160deg, rgba(24, 52, 78, .96), rgba(10, 23, 36, .98));
  border: 1px solid var(--line); box-shadow: 0 24px 80px rgba(0, 0, 0, .45);
  text-align: center;
}
.logo { width: 84px; height: 84px; border-radius: 26px; object-fit: cover; border: 1px solid var(--line); }
.login h1 { margin: 14px 0 6px; font-size: 22px; letter-spacing: .5px; }
.login .muted { margin: 0 0 20px; line-height: 1.7; font-size: 13px; }
.login input {
  width: 100%; padding: 13px 14px; border-radius: 14px; border: 1px solid var(--line);
  background: rgba(4, 12, 20, .7); outline: none; text-align: center; letter-spacing: 2px;
}
.login input:focus { border-color: var(--blue-2); }
.login button, .primary {
  width: 100%; margin-top: 14px; padding: 13px 16px; border: 0; border-radius: 14px;
  background: linear-gradient(135deg, var(--blue-2), var(--blue)); color: #04121f;
  font-weight: 700;
}
.error { color: var(--danger); min-height: 18px; font-size: 13px; margin: 10px 0 0; }

.app { height: 100dvh; display: flex; flex-direction: column; max-width: 920px; margin: 0 auto; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: rgba(8, 19, 31, .82); backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
  padding-top: max(12px, env(safe-area-inset-top));
}
.avatar { width: 44px; height: 44px; border-radius: 15px; object-fit: cover; border: 1px solid var(--line); }
.who { flex: 1; min-width: 0; }
.name-row { display: flex; align-items: center; gap: 7px; }
.name-row h1 { font-size: 17px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #7a8a99; }
.dot.on { background: #41d68b; box-shadow: 0 0 10px rgba(65, 214, 139, .8); }
.status { color: var(--muted); font-size: 12px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.affection {
  padding: 6px 10px; border-radius: 999px; border: 1px solid rgba(76, 194, 255, .3);
  background: rgba(76, 194, 255, .08); color: #bfeaff; font-size: 12px; font-weight: 700;
  white-space: nowrap;
}
.icon-btn {
  border: 1px solid var(--line); background: rgba(255, 255, 255, .04);
  width: 38px; height: 38px; border-radius: 13px; display: inline-grid; place-items: center;
  font-size: 18px; flex: 0 0 auto;
}
.icon-btn:active { transform: scale(.96); }
.icon-btn svg, .send-btn svg {
  width: 20px; height: 20px; display: block; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.send-btn svg { width: 21px; height: 21px; }

.messages {
  flex: 1; overflow-y: auto; padding: 16px 14px 20px; display: flex; flex-direction: column;
  gap: 10px; scroll-behavior: smooth;
}
.msg { display: flex; flex-direction: column; max-width: min(78%, 620px); gap: 4px; animation: pop .16s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.bot { align-self: flex-start; align-items: flex-start; }
.bubble {
  padding: 10px 13px; border-radius: 18px; line-height: 1.55; font-size: 15px;
  white-space: pre-wrap; word-break: break-word; border: 1px solid var(--line);
}
.msg.bot .bubble { background: var(--bot); border-bottom-left-radius: 6px; }
.msg.user .bubble { background: var(--user); color: #04121f; border: 0; border-bottom-right-radius: 6px; }
.msg .meta { color: var(--muted); font-size: 11px; padding: 0 4px; }
.bubble img, .bubble video {
  display: block; max-width: 100%; max-height: 320px; border-radius: 12px; margin-top: 6px;
  background: #04101a;
}
.bubble .sticker { max-width: 180px; max-height: 180px; image-rendering: auto; }
.bubble a { color: inherit; word-break: break-all; }

.typing { display: flex; gap: 4px; padding: 0 20px 8px; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--blue); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: rgba(8, 19, 31, .9); backdrop-filter: blur(16px); border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1; resize: none; max-height: 120px; min-height: 40px; padding: 10px 12px;
  border-radius: 14px; border: 1px solid var(--line); background: rgba(4, 12, 20, .65);
  outline: none; line-height: 1.4;
}
.composer textarea:focus { border-color: var(--blue-2); }
.send-btn {
  width: 44px; height: 44px; border-radius: 15px; border: 0; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--blue-2), var(--blue)); color: #04121f;
  font-size: 18px; font-weight: 800;
}
.preview { padding: 8px 12px; display: flex; gap: 8px; align-items: center; background: rgba(4, 12, 20, .7); }
.preview img { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; }
.preview button { border: 0; background: transparent; color: var(--danger); font-size: 18px; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  max-height: 78dvh; display: flex; flex-direction: column;
  background: linear-gradient(180deg, #102337, #0a1725);
  border-top: 1px solid var(--line); border-radius: 24px 24px 0 0;
  box-shadow: 0 -20px 60px rgba(0, 0, 0, .45);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.sheet-head b { font-size: 16px; }
.sheet-head .close { border: 0; background: transparent; color: var(--muted); font-size: 20px; }
.sheet-body { overflow-y: auto; padding: 16px 18px 30px; }
.sheet-body section { margin-bottom: 20px; }
.sheet-body h3 { font-size: 13px; color: var(--blue); margin: 0 0 10px; letter-spacing: .5px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid rgba(255, 255, 255, .05); }
.row span { color: #cfe4f5; font-size: 14px; }
.row input[type="text"], .row input[type="number"], .row input[type="time"], .row select {
  width: min(52%, 240px); padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line);
  background: rgba(4, 12, 20, .65); outline: none;
}
.row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--blue); }
.row input[type="file"] { width: min(52%, 240px); font-size: 12px; color: var(--muted); }
.sticker-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 14px; overflow-y: auto; }
.sticker-grid button { border: 1px solid var(--line); background: rgba(255, 255, 255, .04); border-radius: 12px; padding: 6px; aspect-ratio: 1; }
.sticker-grid img { width: 100%; height: 100%; object-fit: contain; }
.sticker-add { margin-left: auto; margin-right: 10px; padding: 6px 10px; border-radius: 999px; border: 1px dashed rgba(77, 194, 255, .35); color: var(--blue); font-size: 12px; cursor: pointer; }
.save-sticker { display: block; margin-top: 6px; padding: 4px 9px; border-radius: 999px; border: 1px solid var(--line); background: rgba(0, 0, 0, .18); color: var(--muted); font-size: 11px; }
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 60;
  background: rgba(10, 26, 40, .96); border: 1px solid var(--line); color: var(--text);
  padding: 10px 16px; border-radius: 999px; font-size: 13px; max-width: 80vw;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
.primary { width: 100%; margin-top: 8px; }
.empty { color: var(--muted); text-align: center; margin: 40px auto; font-size: 13px; line-height: 1.8; }
.load-older {
  align-self: center; margin: 4px auto 10px; padding: 7px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, .04);
  color: var(--muted); font-size: 12px;
}
.load-older:disabled { opacity: .5; }

@media (min-width: 720px) {
  .app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .messages { padding: 22px 22px 28px; }
  .bubble { font-size: 15px; }
  .sticker-grid { grid-template-columns: repeat(6, 1fr); }
}

/* polish */
body {
  background:
    radial-gradient(900px 520px at 85% -15%, rgba(76, 194, 255, .15), transparent 62%),
    radial-gradient(700px 520px at -15% 105%, rgba(42, 143, 214, .16), transparent 62%),
    linear-gradient(180deg, #07111c, #08131f 45%, #07101a);
}
.topbar {
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(7, 17, 28, .76);
  border-bottom: 1px solid rgba(255, 255, 255, .075);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .16);
}
.avatar {
  width: 46px; height: 46px; border-radius: 16px;
  border: 1px solid rgba(76, 194, 255, .3);
  box-shadow: 0 0 0 3px rgba(76, 194, 255, .07), 0 6px 18px rgba(0, 0, 0, .24);
}
.name-row h1 { font-size: 18px; letter-spacing: .2px; }
.status { font-size: 11.5px; color: #93aec3; }
.affection {
  border: 1px solid rgba(76, 194, 255, .28);
  background: linear-gradient(135deg, rgba(76, 194, 255, .15), rgba(42, 143, 214, .07));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08);
  letter-spacing: .2px;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 14px;
  background: rgba(255, 255, 255, .045);
  transition: background .18s, border-color .18s, transform .12s;
}
.icon-btn:hover { background: rgba(76, 194, 255, .12); border-color: rgba(76, 194, 255, .28); }
.messages { gap: 12px; padding: 18px 16px 22px; }
.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-thumb { background: rgba(76, 194, 255, .18); border-radius: 99px; }
.msg { max-width: min(76%, 620px); gap: 5px; }
.bubble {
  padding: 11px 14px; border-radius: 19px;
  box-shadow: 0 5px 18px rgba(0, 0, 0, .16);
  border-color: rgba(255, 255, 255, .075);
}
.msg.bot .bubble {
  background: linear-gradient(160deg, rgba(24, 50, 73, .98), rgba(16, 35, 53, .98));
  border-bottom-left-radius: 7px;
}
.msg.user .bubble {
  background: linear-gradient(135deg, #2b93da, #48c2ff);
  box-shadow: 0 7px 20px rgba(42, 143, 214, .22);
  border-bottom-right-radius: 7px;
}
.msg .meta { font-size: 10.5px; opacity: .72; }
.bubble img, .bubble video {
  border-radius: 14px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .18);
}
.bubble .sticker { max-width: 190px; max-height: 190px; }
.composer {
  gap: 7px; padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(8, 19, 31, .6), rgba(7, 16, 26, .97));
  border-top: 1px solid rgba(255, 255, 255, .075);
}
.composer textarea {
  border-radius: 17px;
  background: rgba(3, 10, 18, .72);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .035);
  transition: border-color .18s, box-shadow .18s;
}
.composer textarea:focus {
  border-color: rgba(76, 194, 255, .55);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .04), 0 0 0 3px rgba(76, 194, 255, .07);
}
.send-btn {
  border-radius: 16px;
  box-shadow: 0 8px 20px rgba(42, 143, 214, .25);
  transition: transform .12s, filter .18s;
}
.send-btn:hover { filter: brightness(1.06); }
.send-btn:active { transform: scale(.95); }
.sheet {
  background: linear-gradient(180deg, #11263b, #0a1725);
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -24px 70px rgba(0, 0, 0, .5);
}
.sheet::before {
  content: ""; display: block; width: 36px; height: 4px; margin: 8px auto 0;
  border-radius: 99px; background: rgba(255, 255, 255, .16);
}
.sheet-head { padding: 10px 18px 14px; }
.sheet-head b { font-size: 16px; letter-spacing: .3px; }
.sheet-body section {
  margin-bottom: 12px; padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, .065); border-radius: 16px;
  background: rgba(255, 255, 255, .025);
}
.sheet-body h3 { margin-bottom: 8px; font-size: 12px; letter-spacing: .8px; }
.row { padding: 10px 0; }
.row:last-child { border-bottom: 0; }
.row input[type="text"], .row input[type="number"], .row input[type="time"], .row select {
  border-radius: 11px; background: rgba(3, 10, 18, .7);
  transition: border-color .18s;
}
.row input:focus, .row select:focus { border-color: rgba(76, 194, 255, .5); outline: none; }
.sticker-grid { gap: 7px; padding: 12px; }
.sticker-grid button {
  border-radius: 14px; background: rgba(255, 255, 255, .035);
  transition: background .16s, border-color .16s, transform .12s;
}
.sticker-grid button:hover { background: rgba(76, 194, 255, .1); border-color: rgba(76, 194, 255, .3); }
.sticker-grid button:active { transform: scale(.96); }
.sticker-add { transition: background .18s, border-color .18s; }
.sticker-add:hover { background: rgba(76, 194, 255, .1); border-color: rgba(76, 194, 255, .55); }
.save-sticker { transition: color .18s, border-color .18s, background .18s; }
.save-sticker:hover { color: var(--blue); border-color: rgba(76, 194, 255, .4); background: rgba(76, 194, 255, .08); }
.toast { box-shadow: 0 12px 36px rgba(0, 0, 0, .35); backdrop-filter: blur(12px); }
.login { background: radial-gradient(700px 500px at 50% 20%, rgba(76, 194, 255, .12), transparent 65%), rgba(4, 10, 17, .96); }
.login-card { border-color: rgba(76, 194, 255, .14); box-shadow: 0 28px 90px rgba(0, 0, 0, .52), inset 0 1px 0 rgba(255, 255, 255, .04); }
.logo { box-shadow: 0 0 0 4px rgba(76, 194, 255, .07), 0 16px 40px rgba(0, 0, 0, .35); }
.login input { transition: border-color .18s, box-shadow .18s; }
.login input:focus { box-shadow: 0 0 0 3px rgba(76, 194, 255, .08); }
.load-older { transition: background .18s, border-color .18s; }
.load-older:hover { background: rgba(76, 194, 255, .08); border-color: rgba(76, 194, 255, .3); }
