/* 世界频道 · H5 大厅
 *
 * 视觉方向：DNF 游戏内聊天框。半透明黑底、细金边、单行紧凑排版。
 * 取色沿用天赐官网（114dnf.com）的鎏金 / 血红 / 暗紫，
 * 这样从官网或群链接点进来不会觉得跳到了别的站。
 *
 * ★ 单行排版（昵称和正文同一行）是这套风格自带的密度红利：
 *   原来每条占两行，375×812 只能看到 8 条；玩家在 QQ 群里习惯一屏十几条，
 *   密度太低会让频道显得"没人气"——而世界频道最怕的就是看起来没人。
 */

:root {
  /* 底色：接近纯黑，像游戏里压在画面上的聊天框 */
  --bg:        #0a0a0c;
  --bg-panel:  rgba(12, 10, 16, .92);
  --bg-input:  rgba(20, 16, 26, .95);

  /* 取自官网 114dnf.com 的变量，保持同一套视觉语言 */
  --gold:      #c9a96b;
  --gold-lt:   #f0dca8;
  --gold-dim:  #9c8452;
  --blood:     #8b1538;
  --purple:    #2d1b3d;

  --line:      rgba(201, 169, 107, .22);
  --line-soft: rgba(201, 169, 107, .10);

  --fg:        #d8d4cc;   /* 正文：略暖的灰白，比纯白柔和 */
  --fg-dim:    #8a8579;
  --fg-mute:   #635f56;

  /* 来源色：游戏内是靠颜色区分频道的，这里靠颜色区分来源 */
  --src-game:     #c9a96b;
  --src-dongfeng: #6fa8dc;
  --src-guest:    #8a8579;

  --ok:     #6fbf8a;
  --danger: #d9534f;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* ★ 必须显式压过 hidden。浏览器默认的 [hidden]{display:none} 是 UA 样式，
   任何带 display 的 class（本页的 .mask / .guest-tip 都是 flex）都会盖掉它，
   结果就是「明明写了 hidden，弹窗一进页面就糊在屏幕中间」。 */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; height: 100%;
  /* 纹理已整体压暗到平均灰度 ~11，正文（#d8d4cc）对比度仍在 13:1 以上。
     原图有零星亮点会把对比度拉到 2.2:1（低于 WCAG AA 的 4.5:1），
     所以是先压暗再用，而不是铺原图再调不透明度。 */
  background: var(--bg) url("img/texture.webp") repeat;
  color: var(--fg);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
        "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
}

/* ★ 100dvh 而不是 100vh：手机地址栏收起/展开会改变 vh，
   用 vh 会把输入框顶到屏幕外，正是「输入框被键盘遮挡」那条验收项。 */
#app {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  max-width: 720px; margin: 0 auto;
  background: rgba(12, 10, 16, .78);
  border-left: 1px solid var(--line-soft);
  border-right: 1px solid var(--line-soft);
}

/* ── 顶栏：做窄，像游戏窗口的标题条 ── */
.bar {
  flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 7px) 12px 7px;
  background: linear-gradient(180deg, rgba(45,27,61,.55), rgba(12,10,16,.2));
  border-bottom: 1px solid var(--line);
}
.bar-left { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.title {
  font-size: 14px; font-weight: 600; letter-spacing: 2px;
  color: var(--gold-lt); text-shadow: 0 0 10px rgba(201,169,107,.35);
}
.online { font-size: 11px; color: var(--fg-dim); }
.state { font-size: 11px; padding: 1px 7px; border-radius: 3px; white-space: nowrap;
         border: 1px solid transparent; }
.state-connecting { color: var(--fg-dim); border-color: var(--line-soft); }
.state-online     { color: var(--ok);     border-color: rgba(111,191,138,.3); }
.state-offline    { color: var(--danger); border-color: rgba(217,83,79,.4);
                    background: rgba(217,83,79,.1); }

/* ── 消息列表 ── */
.list {
  flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 8px 12px 4px;
}

/* ★ 单行排版：昵称和正文在同一行，长了自动换行。
   这是 DNF 游戏内聊天的样子，也是密度的来源。 */
.msg {
  margin: 0 0 2px;
  word-wrap: break-word; overflow-wrap: anywhere;
  padding: 1px 0 1px 6px;
  border-left: 2px solid transparent;
}
.msg-head { display: inline; }
.msg-name { font-size: 14px; }
.msg-name::after { content: "："; color: var(--fg-mute); }
.msg-body { display: inline; white-space: pre-wrap; color: var(--fg); }

/* 来源色直接染在昵称上 —— 游戏内就是靠颜色认频道的 */
.msg.src-game     .msg-name { color: var(--src-game); }
.msg.src-dongfeng .msg-name { color: var(--src-dongfeng); }
.msg.src-guest    .msg-name { color: var(--src-guest); }

/* ★ 自己的消息要一眼认出来：世界频道滚得快，
   找自己刚发的那条如果要逐条看名字，体验很差。 */
.msg.self {
  border-left-color: var(--gold);
  background: linear-gradient(90deg, rgba(201,169,107,.07), transparent 60%);
}
.msg.self .msg-name { color: var(--gold-lt); font-weight: 600; }

/* 时间戳默认不显示。每条都带时间是纯视觉噪音，
   真正有用的是「隔了多久」——所以改成按时间跨度插分隔线。 */
.msg-time { display: none; }

.time-sep {
  text-align: center; color: var(--fg-mute); font-size: 11px;
  margin: 10px 0 8px; position: relative;
}
.time-sep::before, .time-sep::after {
  content: ""; position: absolute; top: 50%; width: 26%;
  border-top: 1px solid var(--line-soft);
}
.time-sep::before { left: 6%; }
.time-sep::after  { right: 6%; }

/* 来源角标：做成游戏里的方括号标签 */
.badge {
  font-size: 11px; padding: 0 2px; white-space: nowrap;
  color: var(--fg-dim); background: none;
}
.badge::before { content: "["; }
.badge::after  { content: "]"; }
.badge-game     { color: var(--src-game); }
.badge-dongfeng { color: var(--src-dongfeng); }
.badge-guest    { color: var(--src-guest); }

.msg-system {
  text-align: center; color: var(--gold-dim); font-size: 12px;
  margin: 8px 0; padding: 0 20px;
}

.hint { text-align: center; color: var(--fg-mute); font-size: 12px; padding: 22px 0; }

/* ── 新消息跳转 ── */
.jump {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: 132px; z-index: 5;
  background: rgba(139,21,56,.9); color: var(--gold-lt); font-size: 12px;
  padding: 5px 13px; border-radius: 3px; cursor: pointer;
  border: 1px solid rgba(201,169,107,.35);
  box-shadow: 0 4px 14px rgba(0,0,0,.5);
}

/* ── 游客引导 ── */
.guest-tip {
  flex: none; position: relative;
  display: flex; align-items: center; gap: 8px;
  margin: 0 8px 6px; padding: 6px 26px 6px 10px;
  background: rgba(139,21,56,.14); border: 1px solid rgba(201,169,107,.25);
  border-radius: 3px; font-size: 12px; color: #d9c9a8; line-height: 1.45;
}
.guest-tip b { color: var(--gold-lt); font-weight: 600; }
.guest-tip button {
  flex: none; background: none; color: var(--gold-lt); border: 1px solid var(--line);
  padding: 2px 9px; border-radius: 3px; font-size: 12px; cursor: pointer;
}
.tip-close {
  position: absolute; top: 2px; right: 4px;
  border: 0 !important; color: var(--fg-mute) !important;
  font-size: 15px !important; padding: 2px 5px !important; line-height: 1;
}

/* ── 输入区 ── */
.composer {
  flex: none; position: relative;
  padding: 7px 10px calc(env(safe-area-inset-bottom) + 8px);
  background: linear-gradient(180deg, rgba(12,10,16,.2), rgba(45,27,61,.35));
  border-top: 1px solid var(--line);
}
.composer-row { display: flex; gap: 7px; align-items: flex-end; }
#input {
  flex: 1 1 auto; resize: none; max-height: 96px;
  background: var(--bg-input); color: var(--fg);
  border: 1px solid var(--line); border-radius: 3px;
  padding: 8px 10px; font: inherit; line-height: 1.5;
  /* ★ 必须 ≥16px，否则 iOS Safari 聚焦时会自动放大整个页面，
     放大后布局错位，看起来像「页面坏了」。 */
  font-size: 16px;
}
#input:focus { outline: none; border-color: var(--gold-dim);
               box-shadow: 0 0 0 1px rgba(201,169,107,.15); }
#sendBtn {
  flex: none; background: linear-gradient(180deg, #3a2a18, #241a0f);
  color: var(--gold-lt); border: 1px solid var(--gold-dim);
  padding: 8px 16px; border-radius: 3px;
  font-size: 14px; font-weight: 600; cursor: pointer; letter-spacing: 1px;
}
#sendBtn:active { background: #241a0f; }
#sendBtn:disabled { opacity: .4; cursor: default; }

.me {
  display: flex; align-items: center; gap: 5px;
  margin-top: 5px; font-size: 11px; color: var(--fg-mute);
}
.me-name { color: var(--fg-dim); }

/* ── 提示条 ── */
.toast {
  position: absolute; left: 10px; right: 10px; top: -36px;
  background: rgba(20,16,26,.97); color: var(--fg);
  border: 1px solid var(--line); border-radius: 3px;
  padding: 7px 11px; font-size: 12px; text-align: center;
}
.toast.err { background: rgba(139,21,56,.35); border-color: rgba(217,83,79,.45);
             color: #f2d5d4; }

/* ── 弹窗 ── */
.mask {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0,0,0,.72); display: flex; align-items: center; justify-content: center;
  padding: 22px;
}
.dialog {
  background: var(--bg-input); border: 1px solid var(--line); border-radius: 4px;
  padding: 18px; max-width: 340px; width: 100%;
  box-shadow: 0 18px 50px rgba(0,0,0,.6), 0 0 24px rgba(201,169,107,.08);
}
.dialog h2 { margin: 0 0 10px; font-size: 15px; color: var(--gold-lt);
             letter-spacing: 1px; font-weight: 600; }
.dialog-note { margin: 0 0 9px; font-size: 13px; line-height: 1.7; }
.dialog-note b { color: var(--gold-lt); }
.dialog-note.dim { color: var(--fg-dim); }
.dialog button {
  width: 100%; margin-top: 7px;
  background: linear-gradient(180deg, #3a2a18, #241a0f);
  color: var(--gold-lt); border: 1px solid var(--gold-dim);
  padding: 9px; border-radius: 3px; font-size: 14px; font-weight: 600;
  cursor: pointer; letter-spacing: 1px;
}

/* ── 角色选择 ── */
.charlist { margin: 4px 0 8px; max-height: 46vh; overflow-y: auto; }
.charitem {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px; margin-bottom: 6px; cursor: pointer;
  background: rgba(45,27,61,.3); border: 1px solid var(--line-soft); border-radius: 3px;
}
.charitem:hover { border-color: var(--line); background: rgba(45,27,61,.5); }
.charitem.off { opacity: .45; cursor: not-allowed; }
.charitem .cn { font-weight: 600; color: var(--gold); }
.charitem .cm { font-size: 11px; color: var(--fg-dim); margin-left: auto; text-align: right; }
.charitem .cw { font-size: 11px; color: var(--blood); }
.charlist .empty { color: var(--fg-mute); font-size: 12px; text-align: center; padding: 14px 0; }
.dialog #charSkip {
  background: none; color: var(--fg-dim); border-color: var(--line-soft); font-weight: 400;
}

/* ── 头像 ── */
/* ★ 行内显示、高度贴着行高，所以加头像**不增加任何垂直空间** ——
   前面刚为密度把每条消息压成一行，不能又靠头像把它撑回去。 */
.msg-avatar {
  /* ★ 26 而不是 20：Q 版人物头像在 20px 下五官会糊成一团，认不出是谁。
     代价是每行高一点点（下面把行距收紧了 1px 补回来），
     换来的是头像真的能看清 —— 一个看不清的头像等于没有。 */
  width: 26px; height: 26px; border-radius: 4px;
  vertical-align: -8px; margin-right: 6px;
  background: #161020; border: 1px solid var(--line-soft);
}
.msg.src-game     .msg-avatar { border-color: rgba(201,169,107,.5); }
.msg.src-dongfeng .msg-avatar { border-color: rgba(111,168,220,.5); }
.msg.self         .msg-avatar { border-color: var(--gold); }

.me-avatar { width: 22px; height: 22px; border-radius: 3px; vertical-align: -5px;
             border: 1px solid var(--line-soft); }
.me-change {
  margin-left: auto; background: none; color: var(--fg-mute);
  border: 1px solid var(--line-soft); border-radius: 3px;
  padding: 1px 7px; font-size: 11px; cursor: pointer;
}
.me-change:hover { color: var(--gold); border-color: var(--line); }

.avatar-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  margin: 8px 0 10px;
}
.avatar-grid img {
  width: 100%; aspect-ratio: 1; border-radius: 4px; cursor: pointer;
  border: 2px solid transparent; background: #161020;
}
.avatar-grid img:hover { border-color: var(--line); }
.avatar-grid img.on { border-color: var(--gold); }

/* ── 表情 ── */
.sticker-btn {
  flex: none; width: 36px; height: 36px; padding: 0;
  background: var(--bg-input); color: var(--gold-dim);
  border: 1px solid var(--line); border-radius: 3px;
  font-size: 19px; line-height: 1; cursor: pointer;
}
.sticker-btn:hover { color: var(--gold-lt); border-color: var(--gold-dim); }

/* 面板贴在输入框上方。★ absolute 定位而不是插进文档流：
   插进流里会把消息列表挤上去，一开一关整屏跳动。 */
.sticker-panel {
  position: absolute; left: 10px; right: 10px; bottom: 100%;
  margin-bottom: 6px; z-index: 6;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px;
  padding: 9px; max-height: 46vh; overflow-y: auto;
  background: rgba(20,16,26,.98); border: 1px solid var(--line);
  border-radius: 4px; box-shadow: 0 -8px 30px rgba(0,0,0,.6);
}
.sticker-panel img {
  width: 100%; aspect-ratio: 1; cursor: pointer;
  border: 1px solid transparent; border-radius: 4px; background: #161020;
}
.sticker-panel img:hover { border-color: var(--gold-dim); }

/* 消息里的表情 */
.msg-sticker { display: inline-block; width: 76px; height: 76px; vertical-align: middle; }
