/* ===== TideUI — 手机优先深色 IM ===== */
:root {
  --bg:        #070b16;
  --bg-2:      #0b1120;
  --panel:     #111a2e;
  --panel-2:   #16213a;
  --line:      #1e2a44;
  --text:      #e8eefc;
  --text-dim:  #8b9ab8;
  --text-mute: #5b6a88;
  --accent:    #38bdf8;
  --accent-2:  #2563eb;
  --her-bg:    #182337;
  --her-line:  #22314e;
  --me-bg:     #1d6fd8;
  --me-bg-2:   #2563eb;
  --ok:        #34d399;
  --bad:       #f87171;
  --warn:      #fbbf24;
  --radius:    18px;
  --safe-b:    env(safe-area-inset-bottom, 0px);
  --safe-t:    env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}
.hidden { display: none !important; }

/* ================= 口令门 ================= */
.gate {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(900px 500px at 50% -10%, #12325c 0%, transparent 60%),
    radial-gradient(700px 400px at 50% 110%, #0d2b4a 0%, transparent 55%),
    var(--bg);
}
.gate-card {
  width: 100%; max-width: 340px; text-align: center;
  animation: rise .35s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
.gate-logo {
  width: 84px; height: 84px; margin: 0 auto 18px;
  display: grid; place-items: center; font-size: 44px;
  border-radius: 26px;
  background: linear-gradient(145deg, #1b4a7a, #123a63);
  box-shadow: 0 18px 50px -18px #38bdf8aa, inset 0 1px 0 #ffffff22;
}
.gate h1 { margin: 0 0 6px; font-size: 22px; letter-spacing: .06em; font-weight: 600; }
.gate-sub { margin: 0 0 22px; color: var(--text-mute); font-size: 13px; }
.pin-input {
  width: 100%; padding: 16px; text-align: center;
  font-size: 26px; letter-spacing: .55em; text-indent: .55em;
  color: var(--text); background: #0e1728;
  border: 1px solid var(--line); border-radius: 16px;
  outline: none; transition: border-color .18s, box-shadow .18s;
}
.pin-input::placeholder { letter-spacing: .4em; color: #33405c; }
.pin-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #38bdf826; }
.gate-err { min-height: 20px; margin: 10px 0 0; color: var(--bad); font-size: 13px; }
.gate-btn {
  width: 100%; margin-top: 12px; padding: 15px;
  font-size: 15px; font-weight: 600; color: #04121f;
  background: linear-gradient(140deg, #67d6ff, #38bdf8);
  border: 0; border-radius: 16px; cursor: pointer;
  transition: transform .1s, filter .15s;
}
.gate-btn:active { transform: scale(.98); }
.gate-btn:disabled { filter: grayscale(.5) brightness(.7); cursor: default; }
.gate-hint { margin-top: 18px; color: #3f4d69; font-size: 12px; }

/* ================= 主界面 ================= */
.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background:
    radial-gradient(800px 420px at 85% -5%, #10233d 0%, transparent 58%),
    var(--bg);
}

/* ---- 顶栏 ---- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: linear-gradient(180deg, #0b1324 0%, #0b1324f2 70%, #0b132400 100%);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid #ffffff0a;
  z-index: 10;
}
.avatar {
  width: 40px; height: 40px; flex: 0 0 40px;
  display: grid; place-items: center; font-size: 22px;
  border-radius: 14px;
  background: linear-gradient(145deg, #1b4a7a, #0f2c4c);
  box-shadow: inset 0 1px 0 #ffffff1a, 0 4px 14px -6px #000a;
  cursor: pointer;
  overflow: hidden;
  transition: transform .12s ease;
}
.avatar:active { transform: scale(.94); }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.who { flex: 1; min-width: 0; }
.name { font-size: 15px; font-weight: 600; letter-spacing: .02em; }
.status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-mute); }
.dot {
  width: 7px; height: 7px; border-radius: 50%; flex: 0 0 7px;
  background: var(--text-mute);
  transition: background .3s, box-shadow .3s;
}
.dot.online  { background: var(--ok);      box-shadow: 0 0 0 3px #34d39922; animation: pulse 2.4s infinite; }
.dot.offline { background: var(--bad);     box-shadow: 0 0 0 3px #f8717122; }
.dot.retry   { background: var(--warn);    box-shadow: 0 0 0 3px #fbbf2422; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.icon-btn {
  width: 36px; height: 36px; border: 0; border-radius: 12px;
  background: #ffffff0a; color: var(--text-dim); font-size: 15px;
  cursor: pointer; transition: background .15s, color .15s;
}
.icon-btn:active { background: #ffffff16; color: var(--text); }

/* ---- 消息区 ---- */
.scroller {
  position: relative;
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  scroll-behavior: auto;
  padding: 8px 0 4px;
}
.scroller::-webkit-scrollbar { width: 0; }
.feed { display: flex; flex-direction: column; gap: 4px; padding: 6px 12px 14px; }
.history-top { height: 6px; flex: 0 0 auto; }

.row {
  display: flex; align-items: flex-end; gap: 8px;
  max-width: 100%;
  animation: pop .22s cubic-bezier(.22,1,.36,1);
}
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.985); } }
.row.her  { justify-content: flex-start; }
.row.me   { justify-content: flex-end; }
.row.sys  { justify-content: center; }

.mini-avatar {
  width: 27px; height: 27px; flex: 0 0 27px; margin-bottom: 18px;
  display: grid; place-items: center; font-size: 15px;
  border-radius: 9px;
  overflow: hidden;
  background: linear-gradient(145deg, #1b4a7a, #0f2c4c);
  box-shadow: inset 0 1px 0 #ffffff14;
}
.row.me .mini-avatar { order: 2; background: linear-gradient(145deg, #1d4a8a, #12335e); }
.mini-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.bubble-wrap { display: flex; flex-direction: column; max-width: min(78%, 560px); min-width: 0; }
.row.me .bubble-wrap { align-items: flex-end; }

/* 气泡底下的小喇叭，点了用她自己的声音念 */
.speak-btn {
  align-self: flex-start;
  margin-top: 4px;
  padding: 2px 7px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #6b7a99;
  font-size: 13px;
  line-height: 1.3;
  cursor: pointer;
}
.speak-btn:hover, .speak-btn:active { background: rgba(125, 211, 252, .12); color: #7dd3fc; }
.speak-btn[data-on="1"] { color: #7dd3fc; }

.bubble {
  position: relative;
  padding: 10px 13px;
  border-radius: var(--radius);
  font-size: 15px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere;
  text-align: left;
}
.row.her .bubble {
  background: var(--her-bg);
  border: 1px solid var(--her-line);
  border-bottom-left-radius: 6px;
  color: var(--text);
  box-shadow: 0 2px 10px -6px #000c;
}
.row.me .bubble {
  background: linear-gradient(145deg, var(--me-bg), var(--me-bg-2));
  border-bottom-right-radius: 6px;
  color: #f2f8ff;
  box-shadow: 0 4px 16px -8px #2563ebbb, inset 0 1px 0 #ffffff1f;
}
/* 她主动发来的：虚线边 + 小角标 */
.row.her.proactive .bubble {
  border: 1px dashed #3d6fa8;
  background: linear-gradient(160deg, #16243c, #131d31);
}
.proactive-tag {
  display: inline-flex; align-items: center; gap: 3px;
  margin-bottom: 4px;
  font-size: 10.5px; letter-spacing: .04em;
  color: #7fb6e8;
}
.row.sys .bubble {
  max-width: 86%;
  padding: 7px 12px;
  font-size: 12.5px; color: #f0a9a9;
  background: #2a1420; border: 1px solid #4a2333;
  border-radius: 12px; text-align: center;
}

.meta {
  margin-top: 4px; padding: 0 3px;
  font-size: 11px; color: var(--text-mute);
  letter-spacing: .02em;
}
.row.me .meta { text-align: right; }

/* 时间分隔条 */
.day-sep {
  align-self: center; margin: 12px 0 8px;
  padding: 3px 10px; border-radius: 20px;
  font-size: 11px; color: #6b7c9c;
  background: #ffffff08; border: 1px solid #ffffff0a;
}

.jump-btn {
  position: sticky; bottom: 12px; left: 100%;
  margin-right: 14px; margin-top: -46px;
  width: 38px; height: 38px;
  border: 1px solid #ffffff1a; border-radius: 50%;
  background: #16213aee; color: var(--accent);
  font-size: 17px; cursor: pointer;
  box-shadow: 0 8px 24px -10px #000;
  backdrop-filter: blur(8px);
  transition: opacity .2s, transform .2s;
}
.jump-btn:active { transform: scale(.92); }

/* ---- 输入区 ---- */
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 12px calc(10px + var(--safe-b));
  background: linear-gradient(0deg, #0a1122 60%, #0a1122e0 100%);
  border-top: 1px solid #ffffff0a;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.input {
  flex: 1; min-height: 42px; max-height: 132px;
  padding: 11px 14px;
  font: inherit; font-size: 15px; line-height: 1.4;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line); border-radius: 21px;
  outline: none; resize: none;
  transition: border-color .18s, box-shadow .18s;
  scrollbar-width: none;
}
.input::-webkit-scrollbar { width: 0; }
.input::placeholder { color: #46536e; }
.input:focus { border-color: #2c4a75; box-shadow: 0 0 0 3px #38bdf812; }
.send-btn {
  width: 44px; height: 44px; flex: 0 0 44px;
  display: grid; place-items: center;
  color: #04121f;
  background: linear-gradient(140deg, #67d6ff, #38bdf8);
  border: 0; border-radius: 50%; cursor: pointer;
  transition: transform .12s, filter .2s, opacity .2s;
  box-shadow: 0 6px 18px -8px #38bdf8cc;
}
.send-btn:active { transform: scale(.9); }
.send-btn:disabled { opacity: .38; filter: grayscale(.6); cursor: default; }

/* ---- 输入区两侧的工具按钮（图片 / 表情）---- */
.tool-btn {
  width: 38px; height: 44px; flex: 0 0 38px;
  display: grid; place-items: center;
  color: var(--text-dim);
  background: transparent; border: 0; border-radius: 12px;
  cursor: pointer;
  transition: color .16s, background .16s, transform .12s;
}
.tool-btn:hover { color: var(--accent); background: #38bdf810; }
.tool-btn:active { transform: scale(.9); }
.tool-btn.on { color: var(--accent); background: #38bdf81a; }
@media (max-width: 360px) { .tool-btn { width: 32px; flex-basis: 32px; } }

/* ---- 表情面板 ---- */
.panel {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  display: flex; flex-direction: column;
  height: min(46vh, 340px);
  background: var(--bg-2);
  border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -16px 40px -20px #000;
  padding-bottom: var(--safe-b);
  animation: panel-up .2s ease-out;
}
@keyframes panel-up { from { transform: translateY(12px); opacity: 0; } }
.panel-tabs {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px 4px;
  border-bottom: 1px solid #ffffff08;
}
.panel-tab {
  padding: 5px 12px; border-radius: 10px;
  font-size: 13px; color: var(--text-dim);
  background: transparent; border: 0; cursor: pointer;
}
.panel-tab.active { color: #04121f; background: var(--accent); font-weight: 600; }
.panel-hint { flex: 1; font-size: 11px; color: var(--text-mute); text-align: right; padding-right: 4px; }
.panel-close {
  width: 26px; height: 26px; border-radius: 50%;
  color: var(--text-dim); background: #ffffff0d; border: 0;
  font-size: 17px; line-height: 1; cursor: pointer;
}
.panel-groups {
  display: flex; gap: 6px; overflow-x: auto;
  padding: 6px 10px; scrollbar-width: none;
}
.panel-groups::-webkit-scrollbar { height: 0; }
.group-chip {
  flex: 0 0 auto; padding: 4px 11px; border-radius: 999px;
  font-size: 12px; color: var(--text-dim);
  background: #ffffff08; border: 1px solid transparent; cursor: pointer;
}
.group-chip.active { color: var(--accent); background: #38bdf818; border-color: #38bdf840; }
.panel-body { flex: 1; overflow-y: auto; padding: 6px 8px 12px; }
.sticker-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  gap: 6px;
}
.sticker-item {
  aspect-ratio: 1; padding: 2px; border-radius: 10px;
  background: #ffffff06; border: 1px solid transparent;
  cursor: pointer; overflow: hidden;
  transition: background .14s, border-color .14s, transform .1s;
}
.sticker-item:hover { background: #38bdf814; border-color: #38bdf835; }
.sticker-item:active { transform: scale(.92); }
.sticker-item img { width: 100%; height: 100%; object-fit: contain; display: block; }
.emoji-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 2px;
}
.emoji-item {
  aspect-ratio: 1; display: grid; place-items: center;
  font-size: 24px; border-radius: 8px; cursor: pointer;
  background: transparent; border: 0;
}
.emoji-item:hover { background: #38bdf814; }
.panel-empty { padding: 28px 12px; text-align: center; font-size: 13px; color: var(--text-mute); }

/* ---- 消息里的图片 / 表情 ---- */
.bubble.media { padding: 4px; background: transparent; border: 0; }
.bubble.media.sticker { background: transparent; }
.bubble.media img {
  display: block; max-width: 160px; max-height: 160px;
  border-radius: 10px; cursor: zoom-in;
}
.bubble.media.sticker img { max-width: 112px; max-height: 112px; }
.bubble.media .cap {
  margin-top: 4px; padding: 0 4px;
  font-size: 14px; line-height: 1.45;
  white-space: pre-wrap; word-break: break-word;
  color: var(--text);
}
.row.me .bubble.media .cap { text-align: right; }

/* ---- 大图查看 ---- */
.viewer {
  position: fixed; inset: 0; z-index: 95;
  display: grid; place-items: center;
  background: #000;
  cursor: zoom-out;
  animation: fade .16s ease-out;
  touch-action: pan-y;
}
@keyframes fade { from { opacity: 0; } }
.viewer img { max-width: 94vw; max-height: 86vh; border-radius: 8px; }
.viewer-stage { display: grid; place-items: center; width: 100%; height: 100%; }
.viewer-count {
  position: absolute; top: max(14px, env(safe-area-inset-top)); left: 50%;
  transform: translateX(-50%);
  font: 500 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #ffffffb8; background: #ffffff14; padding: 4px 12px;
  border-radius: 999px; pointer-events: none;
}
.viewer-close {
  position: absolute; top: max(10px, env(safe-area-inset-top)); right: 12px;
  width: 36px; height: 36px; border-radius: 50%; border: 0;
  background: #ffffff1f; color: #fff; font-size: 20px; line-height: 1;
  display: grid; place-items: center; cursor: pointer;
}
.viewer-close:active { background: #ffffff33; }
.viewer-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 40px; height: 72px; border: 0; border-radius: 10px;
  background: #ffffff12; color: #ffffffcc; font-size: 30px; line-height: 1;
  display: grid; place-items: center; cursor: pointer;
  user-select: none; -webkit-tap-highlight-color: transparent;
}
.viewer-nav:active { background: #ffffff26; }
.viewer-nav.prev { left: 6px; }
.viewer-nav.next { right: 6px; }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: 88px; transform: translate(-50%, 20px);
  padding: 9px 16px; border-radius: 12px;
  font-size: 13px; color: #ffe6c7;
  background: #2a1b12ee; border: 1px solid #5a3a1f;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 90;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 宽屏：居中一条 IM 宽度 */
@media (min-width: 720px) {
  .app, .gate { max-width: 760px; margin: 0 auto; }
  .app { border-left: 1px solid #ffffff08; border-right: 1px solid #ffffff08; }
  body { background: #05080f; }
}

/* ---- 自拍面板 ---- */
.sf-box { padding: 10px 12px 14px; display: flex; flex-direction: column; gap: 9px; }
.sf-tip { font-size: 12px; color: #6b7a99; }
.sf-row { display: flex; gap: 8px; align-items: flex-start; }
.sf-label { flex: 0 0 34px; font-size: 12px; color: #8b98b3; padding-top: 5px; }
.sf-chips { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.sf-chip {
  background: #1b2230; color: #b7c4da; border: 1px solid #2a3346;
  border-radius: 13px; padding: 4px 11px; font-size: 12px; cursor: pointer;
}
.sf-chip.active { background: #1d4ed8; border-color: #2563eb; color: #fff; }
.sf-extra {
  flex: 1; background: #121822; border: 1px solid #2a3346; color: #dfe6f3;
  border-radius: 8px; padding: 6px 10px; font-size: 12px; outline: none;
}
.sf-extra:focus { border-color: #2563eb; }
.sf-go {
  margin-top: 2px; background: #2563eb; color: #fff; border: 0; border-radius: 9px;
  padding: 9px 0; font-size: 14px; font-weight: 600; cursor: pointer;
}
.sf-go.busy { background: #334155; color: #9fb0c9; }
.panel-body { max-height: 46vh; overflow-y: auto; }
