/* 老人 / 移动优先：大字、大按钮、高对比、单列 */
:root {
  --app-height: 100dvh;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1a202c;
  --muted: #5a6573;
  --brand: #2b6cb0;
  --brand-dark: #234e7d;
  --user-bubble: #2b6cb0;
  --ai-bubble: #ffffff;
  --border: #d7dde5;
  --danger: #c53030;
  --radius: 16px;
  --fs-base: 20px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: var(--fs-base);
  line-height: 1.6;
}

.hidden { display: none !important; }

.screen {
  height: var(--app-height);
  display: flex;
  flex-direction: column;
}

/* ---------- 登录页 ---------- */
#login { align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border-radius: 20px;
  padding: 36px 28px;
  box-shadow: 0 6px 24px rgba(0,0,0,.08);
  text-align: center;
}
.brand { font-size: 30px; margin: 0 0 8px; color: var(--brand); }
.login-tip { color: var(--muted); margin: 0 0 24px; font-size: 19px; }
#login-form { display: flex; flex-direction: column; gap: 16px; }
#passcode {
  font-size: 22px;
  padding: 16px;
  border: 2px solid var(--border);
  border-radius: 14px;
  text-align: center;
}
#passcode:focus { outline: none; border-color: var(--brand); }
#login-btn {
  font-size: 22px;
  letter-spacing: 6px;
  padding: 16px;
  border: none;
  border-radius: 14px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
}
#login-btn:active { background: var(--brand-dark); }
.error { color: var(--danger); min-height: 24px; margin: 4px 0 0; font-size: 18px; }

/* ---------- 聊天页 ---------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--brand);
  color: #fff;
  padding-top: max(10px, env(safe-area-inset-top));
}
.topbar-title { font-size: 21px; font-weight: 700; }
.icon-btn {
  min-width: 48px;
  height: 48px;
  font-size: 26px;
  background: transparent;
  border: none;
  color: #fff;
  border-radius: 12px;
}
.icon-btn:active { background: rgba(255,255,255,.2); }

.scenes {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  padding: 12px;
  overflow-x: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.scene {
  flex: 1 0 auto;
  min-height: 52px;
  padding: 10px 18px;
  font-size: 19px;
  font-weight: 600;
  border: 2px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  white-space: nowrap;
}
.scene.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  -webkit-overflow-scrolling: touch;
}
.bubble {
  max-width: 86%;
  padding: 14px 16px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
/* 气泡内 markdown 渲染：紧凑、老人友好 */
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 6px 0; padding-left: 24px; }
.bubble li { margin: 3px 0; }
.bubble h3, .bubble h4, .bubble h5 { margin: 10px 0 6px; font-size: 20px; }
.bubble strong { font-weight: 700; }
.bubble code { background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 5px; font-size: .92em; }
.bubble.user code { background: rgba(255,255,255,.22); }

.bubble.user { align-self: flex-end; background: var(--user-bubble); color: #fff; border-bottom-right-radius: 4px; }
.bubble.ai { align-self: flex-start; background: var(--ai-bubble); color: var(--text); border-bottom-left-radius: 4px; }
.bubble.system { align-self: center; background: #eef1f5; color: var(--muted); font-size: 17px; text-align: center; box-shadow: none; }
.bubble.ai.thinking { color: var(--muted); font-style: italic; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .5; } 50% { opacity: 1; } }
.empty-hint { margin: auto; color: var(--muted); text-align: center; font-size: 19px; padding: 0 24px; }

.composer-hint {
  flex: 0 0 auto;
  margin: 0;
  padding: 6px 14px 0;
  font-size: 15px;
  color: var(--muted);
  text-align: center;
  background: var(--surface);
}
.composer {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
#input {
  flex: 1 1 auto;
  font-size: 20px;
  line-height: 1.5;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 18px;
  resize: none;
  max-height: 140px;
  font-family: inherit;
}
#input:focus { outline: none; border-color: var(--brand); }
#send-btn {
  flex: 0 0 auto;
  min-width: 76px;
  height: 52px;
  font-size: 20px;
  font-weight: 700;
  border: none;
  border-radius: 18px;
  background: var(--brand);
  color: #fff;
}
#send-btn:active { background: var(--brand-dark); }
#send-btn:disabled { background: #a9bcd0; }

/* ---------- 历史会话抽屉 ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 20;
}
.drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 84%;
  max-width: 360px;
  background: var(--surface);
  z-index: 21;
  display: flex;
  flex-direction: column;
  box-shadow: 2px 0 16px rgba(0,0,0,.2);
  transform: translateX(0);
  padding-top: env(safe-area-inset-top);
}
.drawer.hidden, .overlay.hidden { display: none; }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  font-size: 21px;
  font-weight: 700;
  background: var(--brand);
  color: #fff;
}
.history-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
}
.history-item .title {
  flex: 1;
  font-size: 19px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-item .del {
  flex: 0 0 auto;
  min-width: 44px; height: 44px;
  border: none; background: transparent;
  font-size: 22px; color: var(--muted);
  border-radius: 10px;
}
.history-item .del:active { background: #f0f2f5; }
.history-empty { padding: 24px 16px; color: var(--muted); text-align: center; font-size: 18px; }
