:root {
  --bg: #f2f2f6;
  --bar: #f6f6f8;
  --line: rgba(60, 60, 67, 0.2);
  --text: #111114;
  --sub: #8a8a90;
  --accent: #0a7cff;
  --mine: #0a7cff;
  --mine-text: #fff;
  --theirs: #fff;
  --theirs-text: #111114;
  --field: #fff;
  --card: #fff;
  --danger: #e5352b;
  --ph: #dcdce2;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000;
    --bar: #111113;
    --line: rgba(120, 120, 128, 0.36);
    --text: #f2f2f6;
    --sub: #8e8e93;
    --accent: #2b8cff;
    --mine: #1f7df0;
    --theirs: #232326;
    --theirs-text: #f2f2f6;
    --field: #1c1c1f;
    --card: #1a1a1d;
    --danger: #ff5449;
    --ph: #2c2c30;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}
button, input, textarea { font: inherit; color: inherit; margin: 0; }
button { cursor: pointer; }
.sprite { position: absolute; }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }
.muted { color: var(--sub); }

/* 高度跟着「看得见的那块屏幕」走：键盘弹出来时输入栏正好贴在键盘上面 */
#app { position: fixed; left: 0; right: 0; top: 0; height: 100%; height: var(--vvh, 100dvh); display: flex; flex-direction: column; }
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.screen.center { align-items: center; justify-content: center; padding: 24px; gap: 16px; }

/* ---------- 登录 ---------- */
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 14px; }
.logo { display: block; width: 84px; height: 84px; margin: 0 auto; border-radius: 20px; }
.login-card h1 { margin: 0 0 8px; text-align: center; font-size: 22px; font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--sub); }
.field input, .group input {
  width: 100%; height: 46px; padding: 0 14px; border: 0.5px solid var(--line); border-radius: 12px;
  background: var(--field); color: var(--text); font-size: 16px; outline: none; -webkit-appearance: none; appearance: none;
}
.field input:focus, .group input:focus, #input:focus { border-color: var(--accent); }
.primary { height: 48px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-size: 17px; font-weight: 600; }
.primary.narrow { padding: 0 28px; }
.primary:disabled { opacity: 0.55; }
.err { margin: 0; color: var(--danger); font-size: 14px; }

/* ---------- 聊天 ---------- */
.bar {
  flex: none; position: relative; display: flex; align-items: center; justify-content: center;
  min-height: calc(46px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 56px 0;
  background: var(--bar); border-bottom: 0.5px solid var(--line);
}
.bar-title { display: flex; flex-direction: column; align-items: center; min-width: 0; font-weight: 600; font-size: 17px; line-height: 1.2; }
.bar-title > span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { font-size: 11px; font-weight: 400; color: var(--sub); }
.bar-btn { position: absolute; right: 8px; bottom: 4px; }
.icon-btn { flex: none; width: 38px; height: 38px; padding: 0; border: 0; border-radius: 50%; background: none; display: grid; place-items: center; color: var(--accent); cursor: pointer; }
.icon-btn:active { opacity: 0.5; }
.bar .icon-btn { color: var(--text); }

.list-wrap { flex: 1; min-height: 0; position: relative; display: flex; }
.list { flex: 1; min-width: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 10px 12px 12px; outline: none; }
.empty { margin: 30vh 0 0; text-align: center; color: var(--sub); font-size: 14px; }
.older { position: absolute; top: 8px; left: 0; right: 0; display: flex; justify-content: center; pointer-events: none; z-index: 1; }
.sep { margin: 14px 0 8px; text-align: center; font-size: 12px; color: var(--sub); }
.who { margin: 8px 0 2px 6px; font-size: 12px; color: var(--sub); }
.receipt { margin: 2px 4px 0; text-align: right; font-size: 11px; color: var(--sub); }

.row { display: flex; align-items: flex-end; margin: 3px 0; }
.row.gap { margin-top: 10px; }
.row.mine { justify-content: flex-end; }
.bubble {
  max-width: 78%; padding: 8px 12px; border-radius: 18px; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
  -webkit-user-select: text; user-select: text;
}
.theirs .bubble { background: var(--theirs); color: var(--theirs-text); border-bottom-left-radius: 6px; }
.mine .bubble { background: var(--mine); color: var(--mine-text); border-bottom-right-radius: 6px; }
.bubble a { color: inherit; text-decoration: underline; }
.row.pending .bubble, .row.pending .pic { opacity: 0.6; }
.row.failed .bubble, .row.failed .pic { opacity: 1; }

.state { flex: none; width: 26px; height: 26px; margin-right: 4px; display: grid; place-items: center; }
.retry { width: 22px; height: 22px; padding: 0; border: 0; border-radius: 50%; background: var(--danger); color: #fff; font-weight: 700; font-size: 14px; line-height: 22px; }

.pic { flex: none; display: block; padding: 0; border: 0; border-radius: 14px; overflow: hidden; background: var(--ph); cursor: pointer; }
.pic img { display: block; width: 100%; height: 100%; object-fit: cover; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.pic.broken img { visibility: hidden; }

.voice { display: flex; align-items: center; gap: 6px; border: 0; text-align: left; cursor: pointer; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.mine .voice { flex-direction: row-reverse; }
.voice .dur { font-variant-numeric: tabular-nums; }
.wave { flex: none; width: 20px; height: 20px; }
.mine .wave { transform: scaleX(-1); }
.wave path { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.voice.playing .wave path { animation: wave 1.1s infinite; }
.voice.playing .wave .w2 { animation-delay: 0.18s; }
.voice.playing .wave .w3 { animation-delay: 0.36s; }
@keyframes wave { 0%, 100% { opacity: 1; } 45% { opacity: 0.2; } }

/* 撤回后留下的那一行小字 */
.row.note { justify-content: center; margin: 9px 0; }
.notice { font-size: 12px; color: var(--sub); text-align: center; }
.reedit { margin-left: 8px; padding: 0; border: 0; background: none; color: var(--accent); font-size: 12px; }

/* 表情 */
.stk { flex: none; position: relative; width: 132px; height: 132px; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.stk.em { width: 116px; height: 116px; margin: 2px 6px; }
.stk img, .stk .lot { display: block; width: 100%; height: 100%; }
.stk img { pointer-events: none; -webkit-touch-callout: none; }
.row.pending .stk { opacity: 0.6; }

/* 视频在列表里的样子：封面 + 播放标记 + 时长 */
.pic.vid { position: relative; background: #1d1d20; }
.pic .play { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); pointer-events: none; }
.vdur, .prog { position: absolute; bottom: 6px; padding: 1px 6px; border-radius: 8px; background: rgba(0, 0, 0, 0.5); color: #fff; font-size: 12px; font-variant-numeric: tabular-nums; }
.vdur { right: 7px; }
.prog { left: 7px; }
.row.pending .pic.vid, .row.failed .pic.vid { opacity: 1; }

.jump {
  position: absolute; right: 12px; bottom: 12px; display: flex; align-items: center; gap: 4px; height: 34px; padding: 0 12px;
  border: 0.5px solid var(--line); border-radius: 17px; background: var(--card); color: var(--accent); font-size: 14px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.14);
}

.composer {
  flex: none; display: flex; align-items: flex-end; gap: 4px; padding: 7px 6px calc(7px + env(safe-area-inset-bottom));
  background: var(--bar); border-top: 0.5px solid var(--line);
}
/* 键盘开着时底部不用再给横条留位置 */
.kb .composer { padding-bottom: 7px; }
.entry { flex: 1; min-width: 0; }
#input {
  display: block; width: 100%; height: 38px; max-height: 122px; padding: 8px 13px; border: 0.5px solid var(--line); border-radius: 19px;
  background: var(--field); font-size: 16px; line-height: 21px; resize: none; outline: none; -webkit-appearance: none; appearance: none;
}
.hold {
  display: block; width: 100%; height: 38px; padding: 0; border: 0.5px solid var(--line); border-radius: 19px; background: var(--field); font-weight: 600;
  touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.hold.down { background: var(--ph); }
.send { flex: none; height: 38px; margin: 0 2px 0 4px; padding: 0 15px; border: 0; border-radius: 19px; background: var(--accent); color: #fff; font-weight: 600; }

/* ---------- 表情面板 ---------- */
.panel {
  flex: none; display: flex; flex-direction: column; height: calc(268px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--bar); border-top: 0.5px solid var(--line);
}
.panel-open .composer { padding-bottom: 7px; }
.tabs { flex: none; display: flex; gap: 6px; padding: 8px 10px 4px; }
.tabs button { height: 30px; padding: 0 14px; border: 0; border-radius: 15px; background: none; color: var(--sub); font-size: 14px; }
.tabs button.on { background: var(--field); color: var(--text); font-weight: 600; }
.grid { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; display: grid; gap: 2px; align-content: start; padding: 4px 8px 10px; }
.grid.cols4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols5 { grid-template-columns: repeat(5, 1fr); }
.cell { aspect-ratio: 1; min-width: 0; padding: 3px; border: 0; border-radius: 12px; background: none; }
.grid.cols5 .cell { padding: 9px; }
.cell:active { background: var(--ph); }
.cell img { display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; -webkit-touch-callout: none; }
.credit { grid-column: 1 / -1; margin: 8px 0 2px; text-align: center; font-size: 11px; color: var(--sub); }

/* ---------- 长按消息出来的小菜单 ---------- */
.menu-bg { position: absolute; inset: 0; z-index: 44; }
.menu { position: absolute; z-index: 45; display: flex; overflow: hidden; border-radius: 12px; background: rgba(44, 44, 48, 0.97); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.28); }
.menu button { min-width: 66px; height: 44px; padding: 0 16px; border: 0; background: none; color: #fff; font-size: 15px; white-space: nowrap; }
.menu button + button { border-left: 0.5px solid rgba(255, 255, 255, 0.2); }
.menu button:active { background: rgba(255, 255, 255, 0.16); }

/* ---------- 录音提示 ---------- */
.rec { position: absolute; inset: 0; z-index: 30; display: grid; place-items: center; pointer-events: none; }
.rec-card { min-width: 168px; padding: 22px 20px 18px; border-radius: 18px; background: rgba(40, 40, 44, 0.92); color: #fff; text-align: center; }
.rec-time { margin-top: 6px; font-size: 22px; font-variant-numeric: tabular-nums; }
.rec-hint { margin-top: 6px; font-size: 13px; opacity: 0.85; }
.rec.cancel .rec-card { background: rgba(200, 44, 36, 0.94); }

/* ---------- 看大图 ---------- */
.viewer { position: absolute; inset: 0; z-index: 40; background: #000; }
.vscroll { position: absolute; inset: 0; display: flex; overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.vscroll img { flex: none; margin: auto; display: block; }
.viewer video { position: absolute; left: 0; top: 0; width: 100%; height: 100%; background: #000; }
.vclose { z-index: 2; position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 12px; width: 38px; height: 38px; padding: 0; border: 0; border-radius: 50%; background: rgba(60, 60, 64, 0.72); color: #fff; display: grid; place-items: center; }

/* ---------- 设置 ---------- */
.sheet { position: absolute; inset: 0; z-index: 50; display: flex; align-items: flex-end; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.42); }
.sheet-card {
  position: relative; width: 100%; max-height: 92%; overflow-y: auto; padding: 8px 16px calc(18px + env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0; background: var(--card);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 0 2px; font-size: 17px; }
.sheet-head .icon-btn { color: var(--sub); margin-right: -8px; }
.group { display: flex; flex-direction: column; gap: 8px; padding: 12px 0; border-top: 0.5px solid var(--line); }
.group > label { font-size: 13px; color: var(--sub); }
.line { display: flex; gap: 8px; }
.line input { flex: 1; min-width: 0; }
.small { flex: none; height: 46px; padding: 0 16px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 600; }
.small:disabled, .danger:disabled { opacity: 0.55; }
.looks { display: flex; gap: 12px; }
.looks button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0 8px; border: 1.5px solid var(--line); border-radius: 14px; background: none; font-size: 14px; }
.looks button.on { border-color: var(--accent); background: rgba(10, 124, 255, 0.09); }
.looks img { display: block; width: 72px; height: 72px; }
.credits { margin: 6px 0 0; text-align: center; font-size: 11px; color: var(--sub); }
.kv { display: flex; justify-content: space-between; font-size: 15px; }
.kv span:first-child { color: var(--sub); }
.danger { height: 46px; border: 0.5px solid var(--line); border-radius: 12px; background: none; color: var(--danger); font-weight: 600; }

.toast {
  position: absolute; z-index: 60; left: 50%; top: calc(58px + env(safe-area-inset-top)); transform: translateX(-50%); max-width: 82%;
  padding: 9px 14px; border-radius: 12px; background: rgba(40, 40, 44, 0.94); color: #fff; font-size: 14px; text-align: center;
}

.spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--sub); border-top-color: transparent; animation: spin 0.8s linear infinite; }
.spin.big { width: 28px; height: 28px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin, .voice.playing .wave path { animation-duration: 3s; } }

/* 电脑上打开时别撑满整屏 */
@media (min-width: 720px) {
  #app { left: 50%; right: auto; width: 520px; transform: translateX(-50%); border-left: 0.5px solid var(--line); border-right: 0.5px solid var(--line); }
}

/* 手机上长按文字是出我们自己的菜单（复制 / 撤回），不要系统的选字 */
@media (pointer: coarse) {
  .bubble { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
}
