/* ============ Sober · 第一轮：只改外观，不碰逻辑 ============ */

/* ---- 字体（自托管，OFL 协议；文件由小d下载并子集化，见任务单）---- */
@font-face {
  font-family: "Newsreader";
  src: url("fonts/Newsreader-var.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "LXGW WenKai";
  src: url("fonts/LXGWWenKai-subset.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* ---- 配色与尺寸 ---- */
:root {
  --bg: #faf9f5;
  --surface: #ffffff;
  --ink: #2b2a27;
  --ink-soft: #6f6b63;
  --line: #e7e3d8;
  --accent: #b8694a;
  --accent-ink: #ffffff;
  --bubble-me: #efe9db;
  --bubble-ai: transparent;
  --radius: 18px;
  --font-serif: "Newsreader", "LXGW WenKai", "Noto Serif SC", "Songti SC", Georgia, serif;
  --font-ui: "Inter", "LXGW WenKai", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1b19;
    --surface: #262521;
    --ink: #ece8de;
    --ink-soft: #a29d92;
    --line: #36342f;
    --accent: #d08463;
    --accent-ink: #1c1b19;
    --bubble-me: #2e2c27;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 17px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---- 门（密码层）---- */
.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate-card {
  width: min(360px, 100%);
  text-align: center;
}
.brand {
  font-size: 30px;
  letter-spacing: 0.32em;
  padding-left: 0.32em;
  font-weight: 500;
}
.sub {
  margin: 8px 0 28px;
  color: var(--ink-soft);
  font-size: 15px;
}
#pass {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px; /* 16px 以防 iOS 聚焦时自动放大 */
  font-family: var(--font-ui);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  text-align: center;
}
#pass:focus { border-color: var(--accent); }
#enter {
  margin-top: 12px;
  width: 100%;
  padding: 13px 16px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  letter-spacing: 0.3em;
  cursor: pointer;
}
#enter:active { transform: scale(0.98); }
.gerr { min-height: 1.4em; margin-top: 12px; color: #c0463a; font-size: 14px; }
.gate-card.shake { animation: shake 0.35s; }
@keyframes shake {
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* ---- 主界面骨架 ---- */
.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
}
header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 20px 12px;
  border-bottom: 1px solid var(--line);
}
header .dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--accent);
}
header .title { font-size: 19px; font-weight: 500; flex: 1; }
.out {
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-family: var(--font-ui);
  font-size: 14px;
  cursor: pointer;
  padding: 6px 8px;
}
.out:hover { color: var(--ink); }

/* ---- 聊天区 ---- */
main#log {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}
.hello {
  margin: auto;
  text-align: center;
  color: var(--ink-soft);
  font-size: 16px;
}

/* 消息：class 名需与 app.js 对应，见任务单第 3 条 */
.msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-break: break-word;
  animation: rise 0.25s ease-out both;
}
.msg.user, .msg.me {
  align-self: flex-end;
  background: var(--bubble-me);
  border-bottom-right-radius: 6px;
}
.msg.assistant, .msg.ai, .msg.bot {
  align-self: flex-start;
  background: var(--bubble-ai);
  padding-left: 2px;
}
/* 分段回复：连续的 AI 气泡靠得近一点，读起来像一口气说的几句 */
.msg.assistant + .msg.assistant,
.msg.ai + .msg.ai,
.msg.bot + .msg.bot { margin-top: -8px; }

.msg.typing { color: var(--ink-soft); }
.msg.typing::after {
  content: "…";
  animation: blink 1.2s infinite;
}
.msg.err { color: #c0463a; font-size: 15px; }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@keyframes blink { 50% { opacity: 0.2; } }

/* ---- 输入区 ---- */
footer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 16px calc(14px + env(safe-area-inset-bottom));
}
#box {
  flex: 1;
  resize: none;
  max-height: 180px;
  padding: 12px 16px;
  font-size: 16px;
  font-family: var(--font-ui);
  line-height: 1.5;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  outline: none;
}
#box:focus { border-color: var(--accent); }
#send {
  padding: 11px 18px;
  border: 0;
  border-radius: 22px;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font-ui);
  cursor: pointer;
}
#send:disabled { opacity: 0.45; cursor: default; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; scroll-behavior: auto !important; }
}
