:root {
  --bg: #121212;
  --rail: #1b1b1b;
  --panel: #202020;
  --line: rgba(255, 255, 255, 0.07);
  --ink: #e6e6e6;
  --soft: #8b8b8b;
  --green: #2fb55a;
  --bubble-her: #2b2b2b;
  --bubble-me: #2fb55a;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; height: 100vh; overflow: hidden;
  background: var(--bg); color: var(--ink);
  font: 14px/1.6 "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
  user-select: none;
}

/* 左侧栏 */
.rail {
  width: 76px; background: var(--rail); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; padding: 14px 0;
  gap: 6px;
}
.me { display: flex; flex-direction: column; align-items: center; gap: 5px; margin-bottom: 10px; }
.avatar {
  width: 38px; height: 38px; border-radius: 8px; overflow: hidden;
  display: grid; place-items: center; font-size: 15px; font-weight: 600;
  background: linear-gradient(160deg, #3a7bd5, #1f4b8a); color: #fff;
}
.avatar.sm { width: 34px; height: 34px; border-radius: 7px; font-size: 13px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.me-name { font-size: 11px; color: var(--soft); max-width: 66px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tabs { display: flex; flex-direction: column; gap: 4px; width: 100%; align-items: center; flex: 1; }
.tab {
  width: 56px; padding: 9px 0; border: 0; border-radius: 8px; background: transparent;
  color: var(--soft); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font: inherit;
}
.tab .ic { font-size: 18px; }
.tab .tx { font-size: 11px; }
.tab:hover { background: rgba(255,255,255,.05); }
.tab.active { background: rgba(47,181,90,.16); color: var(--green); }
.rail-foot { font-size: 10.5px; color: var(--soft); text-align: center; padding: 0 6px; }

/* 主区 */
.main { flex: 1; display: flex; min-width: 0; }
.view { display: none; flex: 1; flex-direction: column; min-width: 0; }
.view.active { display: flex; }

.chat-head {
  display: flex; align-items: center; gap: 11px; padding: 12px 18px;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.chat-who .nm { font-weight: 600; }
.chat-who .st { font-size: 11.5px; color: var(--soft); }

/* 家里两个人：左上角切换 */
.who-switch { display: flex; gap: 6px; align-items: center; flex: 0 0 auto; }
.who-btn {
  display: flex; align-items: center; gap: 6px; padding: 3px 10px 3px 3px;
  border-radius: 20px; border: 1px solid transparent; background: transparent;
  color: var(--soft); font: inherit; cursor: pointer; transition: .15s;
}
.who-btn:hover { background: rgba(255,255,255,.05); }
.who-btn.on { background: rgba(88,166,255,.16); border-color: rgba(88,166,255,.45); color: var(--ink); }
.who-btn .who-tx { font-size: 12px; line-height: 1; }
.who-btn .avatar { width: 26px; height: 26px; font-size: 12px; border-radius: 50%; }
.who-btn .avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

.log { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; }

.msg { display: flex; gap: 9px; align-items: flex-start; }
.msg.me { flex-direction: row-reverse; }
.msg .av {
  width: 32px; height: 32px; border-radius: 7px; overflow: hidden; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 12px; background: #333; color: #fff;
}
.msg .av img { width: 100%; height: 100%; object-fit: cover; }
.bubble {
  max-width: min(560px, 70%);
  padding: 9px 12px; border-radius: 6px;
  background: var(--bubble-her); white-space: pre-wrap; word-break: break-word;
  border: 1px solid var(--line);
}
.msg.me .bubble { background: var(--bubble-me); color: #06220f; border-color: transparent; }
.bubble img.photo, .bubble video { max-width: 100%; border-radius: 6px; display: block; }
.bubble img.sticker { width: 132px; height: 132px; object-fit: contain; background: transparent; }
.bubble .fname { font-size: 12.5px; }
/* 小群里标出是谁在说话 */
.bubble .spk { font-size: 11px; opacity: .6; margin-bottom: 2px; }
/* 戳一戳：居中一行小字，不占聊天气泡 */
.msg.poke { justify-content: center; }
.msg.poke .av { display: none; }
.msg.poke .bubble { background: transparent; border: 0; color: var(--soft); font-size: 12px; padding: 2px 8px; }
.poke-line { opacity: .85; }
.bubble .fsize { font-size: 11px; opacity: .7; }
.bubble a { color: inherit; }

.time-sep { align-self: center; font-size: 11px; color: var(--soft); margin: 6px 0; }

.typing { display: flex; gap: 9px; align-items: center; color: var(--soft); font-size: 12px; }
.dot { width: 5px; height: 5px; border-radius: 50%; background: var(--soft); animation: b 1.2s infinite; }
.dot:nth-child(3) { animation-delay: .15s; } .dot:nth-child(4) { animation-delay: .3s; }
@keyframes b { 0%,60%,100% { transform: translateY(0); opacity: .4 } 30% { transform: translateY(-3px); opacity: 1 } }

/* 输入区 */
.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 10px 16px 14px;
  border-top: 1px solid var(--line); background: var(--panel); position: relative;
}
.tools { display: flex; gap: 2px; padding-bottom: 6px; }
.tool { border: 0; background: transparent; font-size: 19px; cursor: pointer; padding: 2px 4px; border-radius: 6px; }
.tool:hover { background: rgba(255,255,255,.08); }
textarea {
  flex: 1; resize: none; min-height: 38px; max-height: 150px; padding: 9px 11px;
  border-radius: 7px; border: 1px solid var(--line); background: #171717; color: var(--ink);
  font: inherit; outline: none;
}
textarea:focus { border-color: rgba(47,181,90,.5); }
.send {
  padding: 8px 18px; border-radius: 7px; border: 0; background: var(--green); color: #06220f;
  font: inherit; font-weight: 600; cursor: pointer; margin-bottom: 1px;
}
.send:disabled { opacity: .5; cursor: default; }

.sticker-pop {
  position: absolute; left: 14px; bottom: 62px; width: 340px; max-height: 260px; overflow-y: auto;
  background: #1a1a1a; border: 1px solid var(--line); border-radius: 10px; padding: 10px;
  display: none; grid-template-columns: repeat(4, 1fr); gap: 8px; z-index: 20;
}
.sticker-pop.on { display: block; }
/* 表情浮层：带标题栏和关闭按钮 */
.sticker-pop .sp-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: 2px 2px 8px;
  background: #1a1a1a;
  font-size: 12.5px; color: var(--soft);
}
.sticker-pop .sp-close {
  border: 0; background: rgba(255,255,255,.08); color: #ddd;
  width: 24px; height: 24px; border-radius: 50%; font-size: 15px; line-height: 1;
  cursor: pointer;
}
.sticker-pop .sp-close:hover { background: rgba(255,80,80,.25); color: #fff; }
.sticker-pop .sp-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.sticker-pop img { width: 100%; aspect-ratio: 1; object-fit: contain; cursor: pointer; border-radius: 6px; background: #222; }

/* 面板 */
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
}
/* 日记页 */
.diary { flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.diary-item { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.diary-head { display: flex; gap: 8px; align-items: baseline; margin-bottom: 8px; }
.diary-date { font-size: 12px; color: var(--acc2); }
.diary-where { font-size: 11px; color: var(--soft); }
.diary-text { font-size: 13.5px; line-height: 1.95; color: var(--ink); }

.diary .hint { padding: 24px; text-align: center; }
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 600; }

/* 小屋 / 星图：整屏 iframe */
.frame { flex: 1; width: 100%; min-height: 0; border: 0; background: var(--bg); display: block; }
.ghost { padding: 6px 12px; border-radius: 7px; border: 1px solid var(--line); background: transparent; color: var(--ink); font: inherit; cursor: pointer; }
.ghost:hover { background: rgba(255,255,255,.06); }

.moments { flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.moment { padding: 12px 14px; background: #1b1b1b; border: 1px solid var(--line); border-radius: 10px; }
.moment .meta { font-size: 11.5px; color: var(--soft); margin-bottom: 5px; }
.moment .body { white-space: pre-wrap; }
.moment .pics { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.moment .pics img { width: 108px; height: 108px; object-fit: cover; border-radius: 6px; }

.sticker-grid {
  flex: 1; overflow-y: auto; padding: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  grid-auto-rows: max-content;
  align-content: start;      /* 关键：不要拉伸行高，否则格子会变成细长条 */
  gap: 10px;
}
.sticker-grid .cell {
  position: relative;
  aspect-ratio: 1;                 /* 正方形，像微信表情面板 */
  background: #1b1b1b;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  display: grid;
  place-items: center;
  overflow: hidden;
  cursor: pointer;
}
.sticker-grid .cell:hover { border-color: rgba(47,181,90,.5); }
.sticker-grid img { width: 100%; height: 100%; object-fit: contain; }
.sticker-grid .del {
  position: absolute; right: 3px; top: 3px;
  background: rgba(0,0,0,.65); border: 0; color: #ddd;
  border-radius: 50%; width: 19px; height: 19px; line-height: 1;
  font-size: 13px; cursor: pointer; opacity: 0;
  transition: opacity .15s;
}
.sticker-grid .cell:hover .del { opacity: 1; }
@media (hover: none) { .sticker-grid .del { opacity: .95; } }

.settings { padding: 20px; display: flex; flex-direction: column; gap: 14px; max-width: 520px; }
.srow { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.srow label { color: var(--soft); }
.srow input { flex: 1; max-width: 280px; padding: 8px 10px; border-radius: 7px; border: 1px solid var(--line); background: #171717; color: var(--ink); font: inherit; }
.hint { color: var(--soft); font-size: 12px; }

.mask { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: none; z-index: 40; }
.mask.on { display: block; }
.modal {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(420px, 90vw); background: #1c1c1c; border: 1px solid var(--line);
  border-radius: 12px; padding: 16px; display: none; z-index: 41;
}
.modal.on { display: block; }
.modal h3 { margin: 0 0 10px; font-size: 14px; }
.modal textarea { width: 100%; min-height: 88px; }
.modal .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

/* 朋友圈：头像 + 名字 */
.moment .m-head { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 8px; }
.moment .m-av {
  width: 36px; height: 36px; border-radius: 7px; overflow: hidden; flex: 0 0 auto;
  display: grid; place-items: center; background: #333; color: #fff; font-size: 13px;
}
.moment .m-av img { width: 100%; height: 100%; object-fit: cover; }
.moment .m-name { font-weight: 600; font-size: 13.5px; }
.moment .meta { font-size: 11px; color: var(--soft); }

/* 朋友圈互动 */
.moment .m-likes { margin-top: 8px; font-size: 12.5px; color: #9ad; }
.moment .m-comments { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; }
.moment .m-comment { font-size: 12.5px; color: #cfcfcf; }
.moment .m-comment b { color: var(--green); font-weight: 600; }
.moment .m-actions { display: flex; gap: 8px; margin-top: 10px; }
.moment .m-like, .moment .m-cc {
  border: 1px solid var(--line); background: transparent; color: var(--soft);
  border-radius: 6px; padding: 3px 10px; font: inherit; font-size: 12px; cursor: pointer;
}
.moment .m-like:hover, .moment .m-cc:hover { background: rgba(255,255,255,.06); color: var(--ink); }
.moment .m-ccbox { margin-top: 8px; }
.moment .m-input {
  width: 100%; padding: 7px 10px; border-radius: 6px; border: 1px solid var(--line);
  background: #171717; color: var(--ink); font: inherit;
}

/* ── 手机：底部标签栏（像微信） ── */
@media (max-width: 760px) {
  body {
    flex-direction: column;
    height: 100dvh;
  }

  /* 侧栏变底栏 */
  .rail {
    order: 2;
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: stretch;
    justify-content: space-around;
    padding: 0 0 env(safe-area-inset-bottom);
    border-right: 0;
    border-top: 1px solid var(--line);
    background: #1b1b1b;
  }

  /* 底栏里不重复显示头像 */
  .rail .me { display: none; }
  .rail-foot { display: none; }

  .tabs {
    flex-direction: row;
    flex: 1;
    gap: 0;
    justify-content: space-around;
    align-items: stretch;
  }

  .tab {
    width: auto;
    flex: 1;
    padding: 7px 0 6px;
    border-radius: 0;
    gap: 1px;
    justify-content: center;
  }
  .tab .ic { font-size: 21px; line-height: 1.1; }
  .tab .tx { font-size: 10.5px; }
  .tab.active { background: transparent; color: var(--green); }
  .tab.active .ic { transform: translateY(-1px); }

  /* 主区占满 */
  .main { order: 1; flex: 1; min-height: 0; }
  .view { min-height: 0; }

  /* 聊天头更紧凑 */
  .chat-head { padding: 9px 14px; }
  .panel-head { padding: 11px 14px; }

  .log { padding: 12px; gap: 10px; }
  .bubble { max-width: 78%; font-size: 15px; }
  .bubble img.sticker { width: 110px; height: 110px; }

  /* 输入区：窄屏不能挤成一团 */
  .composer { padding: 7px 8px 8px; gap: 6px; align-items: center; }
  .tools { padding-bottom: 0; gap: 0; }
  .tool { font-size: 20px; padding: 2px 3px; }
  textarea {
    font-size: 16px;              /* 避免安卓聚焦时放大 */
    min-height: 38px; max-height: 96px;
    padding: 8px 10px;
    overflow-y: auto;
    line-height: 1.4;
  }
  .send { padding: 8px 14px; }
  .sticker-pop { left: 8px; right: 8px; width: auto; bottom: 58px; }

  /* 设置页更宽松 */
  .settings { padding: 14px; }
  .srow input { max-width: none; flex: 1; }

  .moments { padding: 12px; }
  .moment .pics img { width: 88px; height: 88px; }

  .sticker-grid { padding: 10px; grid-template-columns: repeat(4, 1fr); gap: 7px; }
  .sticker-grid .cell { padding: 4px; }
}
.moment .m-del {
  border: 1px solid var(--line); background: transparent; color: #a55;
  border-radius: 6px; padding: 3px 10px; font: inherit; font-size: 12px; cursor: pointer;
}
.moment .m-del:hover { background: rgba(255,80,80,.15); color: #f88; }