/* 视觉系统
   方向：Editorial / 杂志编辑部。深夜文学刊物的通信栏 + 手稿批注。
   角色消息是左侧竖线的批注块，不是气泡；会话列表是刊物目录，不是卡片。
   三套底色可切换（html[data-skin]）：ink 暖墨 / paper 宣纸 / night 冷夜
   字体自托管：Noto Serif SC（见 fonts.css）
   角色署名色不在这里 —— 由人设数据注入 --char-dark / --char-light */

/* 3 套皮肤只差 token，结构完全共用 */
html[data-skin="ink"] {
  --paper: #0e0d0b;
  --paper-2: #181613;
  --paper-3: #201d19;
  --ink: #eae3d6;
  --ink-2: #a79e8e;
  --ink-3: #6b6357;
  --rule: #2a2721;
  --rule-strong: #3a352c;
  --accent: #c2402a;
  --accent-ink: #f7f0e6;
  --grain: 0.075;
  --glow: rgba(194, 64, 42, 0.06);
}
html[data-skin="paper"] {
  --paper: #f3ede1;
  --paper-2: #fbf6ec;
  --paper-3: #e9e2d3;
  --ink: #1a1714;
  --ink-2: #6b6154;
  --ink-3: #9c9284;
  --rule: #ddd4c2;
  --rule-strong: #c9bda6;
  --accent: #b23a25;
  --accent-ink: #fbf6ec;
  --grain: 0.06;
  --glow: rgba(178, 58, 37, 0.05);
}
html[data-skin="night"] {
  --paper: #0b0e12;
  --paper-2: #141a21;
  --paper-3: #1b222b;
  --ink: #e4e8ec;
  --ink-2: #94a0ac;
  --ink-3: #5e6874;
  --rule: #1f2730;
  --rule-strong: #2c3641;
  --accent: #d4553c;
  --accent-ink: #0b0e12;
  --grain: 0.07;
  --glow: rgba(212, 85, 60, 0.07);
}

:root {
  color-scheme: dark light;

  --font: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "SimSun", Georgia, serif;

  /* 字号阶梯 */
  --t-masthead: 40px;
  --t-title1: 28px;
  --t-title2: 21px;
  --t-title3: 18px;
  --t-body: 16px;
  --t-sub: 14px;
  --t-note: 13px;
  --t-tiny: 11px;

  --lh-body: 1.75;   /* 宋体需要更松的行距 */
  --lh-title: 1.35;

  --gutter: 22px;
  --nav-h: 48px;
  --hairline: 1px;

  --ease: cubic-bezier(0.32, 0.72, 0, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; height: 100%; overscroll-behavior: none; }

body {
  font-family: var(--font);
  font-size: var(--t-body);
  line-height: var(--lh-body);
  color: var(--ink);
  background-color: var(--paper);
  /* 氛围：顶部散射光 + 极淡纸纹。不做纯色平铺。 */
  background-image: radial-gradient(130% 70% at 50% 0%, var(--glow), transparent 62%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
/* 纸纹噪点单独一层，压在背景之上、内容之下 */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none; z-index: 0;
  opacity: var(--grain);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

#app {
  position: relative; z-index: 1;
  height: var(--vvh, 100dvh);
  display: flex; flex-direction: column;
}
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }

@media (min-width: 720px) {
  #app {
    max-width: 700px; margin: 0 auto;
    border-left: var(--hairline) solid var(--rule);
    border-right: var(--hairline) solid var(--rule);
  }
}

/* ── 刊头 / 导航 ────────────────────────────────────────── */
.nav {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 6px;
  min-height: var(--nav-h);
  padding: 0 10px;
  padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: saturate(140%) blur(18px);
  -webkit-backdrop-filter: saturate(140%) blur(18px);
  border-bottom: var(--hairline) solid var(--rule);
}

.nav-title {
  font-size: var(--t-title3);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0.01em;
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* 刊头：左对齐压到边界，用留白做层级，不做居中 */
.nav-title.large {
  display: block; flex: none;
  font-size: var(--t-masthead);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0.08em;
  padding: 26px var(--gutter) 0;
  white-space: normal;
  overflow: visible;
}

.nav-sub {
  font-size: var(--t-note);
  font-weight: 400;
  color: var(--ink-2);
  letter-spacing: 0.04em;
  margin-top: 2px;
  line-height: 1.5;
}
.nav-title.large .nav-sub {
  font-size: var(--t-sub);
  letter-spacing: 0.02em;
  margin-top: 8px;
  color: var(--ink-2);
}

.nav-action, .nav-back {
  display: inline-flex; align-items: center; gap: 3px;
  background: none; border: 0; cursor: pointer;
  font: inherit; font-size: var(--t-sub);
  color: var(--accent);
  padding: 8px 10px;
  letter-spacing: 0.02em;
  flex: none;
}
.nav-action:active, .nav-back:active { opacity: 0.45; }
.nav-back svg { width: 11px; height: 18px; }

.nav-avatar {
  width: 26px; height: 26px;
  border: 1.5px solid var(--rule-strong);
  border-radius: 3px;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
  color: var(--ink-2);
  flex: none;
  letter-spacing: 0;
}

/* ── 滚动区 ─────────────────────────────────────────────── */
.scroll {
  flex: 1; min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  scrollbar-width: none;
}
.scroll::-webkit-scrollbar { display: none; }

/* ── 目录式列表（替代圆角卡片） ────────────────────────── */
.group { margin: 0 var(--gutter); }
.group-label {
  font-size: var(--t-tiny);
  color: var(--ink-3);
  letter-spacing: 0.24em;
  padding: 26px 0 10px;
  border-bottom: var(--hairline) solid var(--rule-strong);
}

.group-body { display: block; }

.list-row {
  display: flex; align-items: baseline; gap: 14px;
  width: 100%; border: 0; background: none;
  font: inherit; color: inherit; text-align: left;
  padding: 16px 0;
  border-bottom: var(--hairline) solid var(--rule);
  cursor: pointer;
  transition: background 0.15s var(--ease);
}
.list-row:active { background: color-mix(in srgb, var(--ink) 5%, transparent); }

/* 期号 */
.row-idx {
  flex: none;
  width: 26px;
  font-size: var(--t-note);
  color: var(--ink-3);
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
}

.row-main { flex: 1; min-width: 0; }
.row-title {
  font-size: var(--t-title3);
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 0.02em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row-sub {
  font-size: var(--t-note);
  color: var(--ink-2);
  line-height: 1.6;
  margin-top: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row-trail {
  flex: none;
  font-size: var(--t-note);
  color: var(--ink-3);
}
.chev { display: none; }

/* 角色在列表里的署名色点 */
.row-dot {
  flex: none; width: 6px; height: 6px;
  border-radius: 50%;
  margin-right: 2px;
  transform: translateY(-1px);
}
.row-dot[data-char] { background: var(--char-dark); }
html[data-skin="paper"] .row-dot[data-char] { background: var(--char-light); }

/* 头像改成印章块 */
.avatar {
  flex: none;
  width: 40px; height: 40px;
  border: 1.5px solid var(--rule-strong);
  border-radius: 3px;
  display: grid; place-items: center;
  font-size: 17px; font-weight: 700;
  color: var(--ink-2);
  background: none;
  letter-spacing: 0;
}
.avatar.sm { width: 26px; height: 26px; font-size: 12px; }
.avatar[data-char] {
  color: var(--char-dark);
  border-color: color-mix(in srgb, var(--char-dark) 45%, transparent);
}
html[data-skin="paper"] .avatar[data-char] {
  color: var(--char-light);
  border-color: color-mix(in srgb, var(--char-light) 45%, transparent);
}

/* ── 表单 ───────────────────────────────────────────────── */
.field {
  width: 100%;
  background: none;
  color: var(--ink);
  border: 0;
  border-bottom: var(--hairline) solid var(--rule-strong);
  border-radius: 0;
  padding: 10px 0;
  font: inherit; font-size: var(--t-body);
  letter-spacing: 0.01em;
  outline: none;
  transition: border-color 0.2s var(--ease);
}
.field::placeholder { color: var(--ink-3); }
.field:focus { border-bottom-color: var(--accent); }

.field-label {
  display: block;
  font-size: var(--t-tiny);
  color: var(--ink-3);
  letter-spacing: 0.2em;
  margin: 22px 0 2px;
}

.btn {
  width: 100%;
  background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: 2px;
  padding: 15px 18px;
  font: inherit; font-size: var(--t-body);
  font-weight: 700;
  letter-spacing: 0.16em;
  cursor: pointer;
  transition: opacity 0.15s var(--ease), transform 0.12s var(--ease);
}
.btn:active { opacity: 0.85; transform: translateY(1px); }
.btn:disabled { opacity: 0.35; }
.btn.plain {
  background: none; color: var(--ink-2);
  font-weight: 400; letter-spacing: 0.04em;
  font-size: var(--t-note);
  padding: 18px 0;
  border-bottom: 0;
}
.btn.plain:active { color: var(--accent); }

.notice { font-size: var(--t-note); color: var(--ink-2); line-height: 1.8; }
.error {
  font-size: var(--t-note);
  color: var(--accent);
  line-height: 1.7;
  border-left: 2px solid var(--accent);
  padding-left: 10px;
}

/* ── 登录页：非对称，左对齐，留白做层级 ─────────────────── */
.auth-wrap {
  flex: 1; min-height: 0; overflow-y: auto;
  display: block;
  padding: 0 var(--gutter);
  padding-bottom: calc(40px + env(safe-area-inset-bottom));
  max-width: 460px; width: 100%;
}

/* 印章 */
.seal {
  width: 54px; height: 54px;
  border: 2.5px solid var(--accent);
  border-radius: 3px;
  display: grid; place-items: center;
  font-size: 26px; font-weight: 700;
  color: var(--accent);
  line-height: 1;
  margin: 64px 0 34px;
  letter-spacing: 0;
}

.auth-title {
  font-size: var(--t-masthead);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.16em;
  margin: 0 0 10px;
  text-align: left;
}
.auth-sub {
  font-size: var(--t-sub);
  color: var(--ink-2);
  line-height: 1.9;
  letter-spacing: 0.05em;
  margin: 0 0 8px;
  text-align: left;
}
.auth-rule {
  height: 0; border-top: var(--hairline) solid var(--rule-strong);
  margin: 34px 0 0;
}
.auth-foot {
  margin-top: 30px;
  font-size: var(--t-tiny);
  color: var(--ink-3);
  letter-spacing: 0.16em;
  line-height: 2;
}

/* ── 聊天 ───────────────────────────────────────────────── */
.screen.chat { position: relative; }
.screen.chat .nav {
  position: absolute; top: 0; left: 0; right: 0; z-index: 20;
}
.screen.chat .nav::after {
  content: "";
  position: absolute; left: 0; right: 0; top: 100%;
  height: 26px;
  background: linear-gradient(to bottom,
    color-mix(in srgb, var(--paper) 96%, transparent) 0%,
    color-mix(in srgb, var(--paper) 70%, transparent) 45%,
    transparent 100%);
  pointer-events: none;
}
.screen.chat .banner {
  position: absolute;
  top: calc(var(--nav-h) + env(safe-area-inset-top) + 8px);
  left: 0; right: 0; z-index: 15;
  margin: 0 var(--gutter);
}

.chat-log {
  flex: 1; min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(var(--nav-h) + env(safe-area-inset-top) + 22px) var(--gutter) 14px;
  display: flex; flex-direction: column;
  gap: 0;
  scrollbar-width: none;
}
.chat-log::-webkit-scrollbar { display: none; }

/* 分隔：日期用对开细线，时间只用小字 */
.day-sep, .time-sep {
  align-self: stretch;
  display: flex; align-items: center; gap: 12px;
  font-size: var(--t-tiny);
  color: var(--ink-2);
  letter-spacing: 0.22em;
  margin: 26px 0 12px;
  text-align: center;
}
.day-sep::before, .day-sep::after {
  content: ""; flex: 1; height: 0;
  border-top: var(--hairline) solid var(--rule-strong);
}
.time-sep {
  justify-content: flex-start;
  letter-spacing: 0.16em;
  margin: 16px 0 6px;
  opacity: 0.8;
}

/* 消息：角色为左竖线批注块，自己为右对齐文字。不再是圆角气泡。 */
.msg {
  display: flex; flex-direction: column;
  max-width: 100%;
  margin-top: 10px;
}
.msg.grp-start { margin-top: 16px; }
.msg.grp-mid { margin-top: 2px; }
.msg.them { align-items: flex-start; }
.msg.me { align-items: flex-end; }

.sender {
  display: flex; align-items: center; gap: 7px;
  font-size: var(--t-tiny);
  letter-spacing: 0.18em;
  margin: 0 0 5px 13px;
  font-weight: 700;
}
.msg[data-char] .sender { color: var(--char-dark); }
html[data-skin="paper"] .msg[data-char] .sender { color: var(--char-light); }
.sender::after {
  content: ""; width: 16px; height: 0;
  border-top: var(--hairline) solid currentColor;
  opacity: 0.4;
}

.bubble {
  max-width: 88%;
  padding: 2px 0 2px 13px;
  font-size: var(--t-body);
  line-height: 1.68;
  letter-spacing: 0.01em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  text-align: justify;
}

.msg.them .bubble {
  border-left: 1.5px solid var(--rule-strong);
  color: var(--ink);
}
/* 竖线用角色自己的署名色，压暗到不抢文字 */
.msg.them[data-char] .bubble {
  border-left-color: color-mix(in srgb, var(--char-dark) 55%, transparent);
}
html[data-skin="paper"] .msg.them[data-char] .bubble {
  border-left-color: color-mix(in srgb, var(--char-light) 55%, transparent);
}

/* 自己的话：右对齐、无框、稍弱，别喧宾夺主 */
.msg.me .bubble {
  padding: 2px 13px 2px 0;
  margin-right: 12px;
  border-right: 1.5px solid color-mix(in srgb, var(--accent) 42%, transparent);
  color: var(--ink-2);
  text-align: right;
}

.msg.grp-mid .sender, .msg.grp-end .sender { display: none; }

.bubble.plain-text {
  background: none !important;
  border-left-color: var(--rule) !important;
  color: var(--ink-3) !important;
  font-size: var(--t-note);
  font-style: italic;
}

/* 正在输入 */
.typing { display: inline-flex; gap: 4px; align-items: center; padding: 6px 0; }
.typing i {
  width: 5px; height: 5px;
  background: var(--ink-3);
  animation: pulse 1.4s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse {
  0%, 60%, 100% { opacity: 0.25; }
  30% { opacity: 1; }
}

.caret {
  display: inline-block;
  width: 1.5px; height: 1em;
  vertical-align: -0.14em;
  background: var(--accent);
  margin-left: 2px;
  animation: caret 1.1s steps(2) infinite;
}
@keyframes caret { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }

/* ── 输入条 ─────────────────────────────────────────────── */
.composer {
  flex: none;
  display: flex; align-items: flex-end; gap: 10px;
  padding: 12px var(--gutter);
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(140%) blur(18px);
  -webkit-backdrop-filter: saturate(140%) blur(18px);
  border-top: var(--hairline) solid var(--rule-strong);
}

.composer-input {
  flex: 1; min-width: 0;
  display: flex; align-items: flex-end;
  border-bottom: var(--hairline) solid var(--rule-strong);
  padding: 4px 0 6px;
  transition: border-color 0.2s var(--ease);
}
.composer-input:focus-within { border-bottom-color: var(--accent); }

.composer textarea {
  flex: 1; min-width: 0;
  background: none; border: 0; outline: none; resize: none;
  color: var(--ink);
  font: inherit; font-size: var(--t-body);
  line-height: 1.7;
  max-height: 120px;
  padding: 0;
  overflow-y: auto;
}
.composer textarea::placeholder { color: var(--ink-3); letter-spacing: 0.08em; }

.send {
  flex: none;
  width: 34px; height: 34px; margin-bottom: 2px;
  border: 1.5px solid var(--accent);
  border-radius: 2px;
  background: none; color: var(--accent);
  cursor: pointer;
  display: grid; place-items: center;
  transition: background 0.16s var(--ease), color 0.16s var(--ease), transform 0.12s var(--ease);
}
.send svg { width: 17px; height: 17px; }
.send:disabled { opacity: 0.28; }
.send:not(:disabled):active { background: var(--accent); color: var(--accent-ink); transform: scale(0.94); }

/* ── 快捷 @ ─────────────────────────────────────────────── */
.quickbar {
  flex: none;
  display: flex; gap: 8px;
  padding: 9px var(--gutter) 1px;
  border-top: var(--hairline) solid var(--rule);
  overflow-x: auto;
  scrollbar-width: none;
}
.quickbar::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  background: none;
  border: var(--hairline) solid var(--rule-strong);
  border-radius: 2px;
  color: var(--ink-2);
  font: inherit; font-size: var(--t-tiny);
  letter-spacing: 0.12em;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.chip:active { color: var(--accent); }
.chip.on { color: var(--ink-3); text-decoration: line-through; }
.chip .dot { display: none; }

/* ── 提示条 ─────────────────────────────────────────────── */
.banner {
  padding: 11px 13px;
  background: var(--paper-2);
  border-left: 2px solid var(--accent);
  color: var(--ink-2);
  font-size: var(--t-note);
  line-height: 1.7;
  letter-spacing: 0.02em;
}

.empty {
  flex: 1; display: grid; place-items: center;
  color: var(--ink-3);
  font-size: var(--t-sub);
  letter-spacing: 0.14em;
  padding: 60px 24px;
  text-align: center;
}
.spinner {
  width: 16px; height: 16px;
  border: 1.5px solid var(--rule-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.center-load { display: grid; place-items: center; padding: 64px; }

/* ── 底部面板 ───────────────────────────────────────────── */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: color-mix(in srgb, var(--paper) 55%, #000);
  opacity: 0; transition: opacity 0.24s var(--ease);
}
.sheet-backdrop.on { opacity: 0.6; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  background: var(--paper-2);
  border-top: 2px solid var(--accent);
  padding-bottom: env(safe-area-inset-bottom);
  transform: translateY(100%);
  transition: transform 0.3s var(--ease);
  max-height: 80vh;
  display: flex; flex-direction: column;
}
.sheet.on { transform: translateY(0); }
.sheet-handle { display: none; }
.sheet-title {
  font-size: var(--t-tiny);
  font-weight: 700;
  color: var(--ink-3);
  letter-spacing: 0.28em;
  padding: 20px var(--gutter) 12px;
  border-bottom: var(--hairline) solid var(--rule-strong);
  flex: none;
}
.sheet-body { overflow-y: auto; margin: 0 var(--gutter) var(--gutter); }

.sheet-body .list-row { padding: 15px 0; }

/* 面板里的小节标题（在场成员 / 编排成员…） */
.sheet-group {
  font-size: var(--t-tiny);
  font-weight: 700;
  color: var(--ink-3);
  letter-spacing: 0.24em;
  padding: 18px 0 4px;
}
.sheet-group:first-child { padding-top: 6px; }

/* 面板内的表单块（建群的群名输入） */
.form-block { padding: 16px 0 4px; }
.form-block .field-label { padding-top: 0; }

/* 面板底部确认区（建群按钮 + 已挑几人的提示） */
.sheet-footer {
  flex: none;
  border-top: var(--hairline) solid var(--rule-strong);
  padding: 12px var(--gutter) calc(12px + env(safe-area-inset-bottom));
}
.sheet-footer-row { display: flex; align-items: center; gap: 12px; }
.sheet-footer-hint { flex: 1; color: var(--ink-3); font-size: var(--t-note); letter-spacing: 0.08em; }
.sheet-footer .btn { min-width: 120px; }

/* ── 开关：改成方章式，跟圆角药丸区分开 ─────────────────── */
.switch {
  flex: none;
  width: 42px; height: 24px;
  border: 1.5px solid var(--rule-strong);
  border-radius: 2px;
  position: relative;
  background: none;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
}
.switch::after {
  content: "";
  position: absolute; top: 2px; left: 2px;
  width: 15px; height: 15px;
  background: var(--ink-3);
  transition: transform 0.22s var(--ease), background 0.2s var(--ease);
}
.switch.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.switch.on::after { transform: translateX(18px); background: var(--accent); }
