/* ===== 基础 ===== */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #f7f5f1;
  color: #1f2937;
  font-size: 15px;
  line-height: 1.65;
}

.hidden { display: none !important; }
.screen { min-height: 100vh; display: flex; flex-direction: column; }
.error { color: #c0392b; min-height: 1.4em; font-size: 13px; margin: 8px 0 0; }

/* ===== 登录屏 ===== */

#login-screen {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #fdf6e3 0%, #e8dccc 100%);
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 36px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
  width: 90%;
  max-width: 380px;
  text-align: center;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card .subtitle { color: #6b7280; font-size: 14px; margin: 0 0 24px; }
.login-card input {
  width: 100%; padding: 12px 14px; font-size: 15px;
  border: 1px solid #d1d5db; border-radius: 10px; margin-bottom: 12px;
  outline: none; transition: border-color .15s;
}
.login-card input:focus { border-color: #d97706; }
.login-card button {
  width: 100%; padding: 12px; font-size: 15px;
  background: #d97706; color: #fff; border: none; border-radius: 10px;
  cursor: pointer; font-weight: 600;
}
.login-card button:hover { background: #b45309; }
.login-card .tip { font-size: 12px; color: #9ca3af; margin: 18px 0 0; }

/* 开始研学卡片 */
#setup-screen {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #fdf6e3 0%, #e8dccc 100%);
}
.setup-card { text-align: left; }
.setup-card h1 { text-align: center; }
.setup-card .subtitle { text-align: center; }
.field-label {
  display: block; font-size: 13px; color: #6b7280;
  margin: 14px 0 6px;
}
.setup-card select {
  width: 100%; padding: 12px 14px; font-size: 15px;
  border: 1px solid #d1d5db; border-radius: 10px;
  background: #fff; cursor: pointer; outline: none;
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' stroke='%239ca3af' stroke-width='1.5' fill='none'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
.setup-card select:focus { border-color: #d97706; }
.setup-card #start-btn {
  width: 100%; padding: 12px; font-size: 15px; margin-top: 20px;
  background: #d97706; color: #fff; border: none; border-radius: 10px;
  cursor: pointer; font-weight: 600;
}
.setup-card #start-btn:hover { background: #b45309; }
.setup-card #start-btn:disabled { background: #d1d5db; cursor: not-allowed; }

/* ===== 研学屏 ===== */

.top-bar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 600; font-size: 15px; flex-shrink: 0; }

.progress {
  display: flex; gap: 4px; flex: 1; overflow-x: auto;
}
.q-chip {
  padding: 4px 10px; font-size: 12px;
  background: #f3f4f6; color: #6b7280;
  border-radius: 12px; white-space: nowrap;
  border: 1px solid transparent;
  transition: all .2s;
  cursor: pointer;        /* 可点击跳到该步 */
  user-select: none;
}
.q-chip:hover {
  background: #fde9c8; color: #92400e;
  border-color: #f0c27a;
}
.q-chip.active {
  background: #fef3c7; color: #92400e; border-color: #fbbf24;
  font-weight: 600;
}
.q-chip.done {
  background: #d1fae5; color: #065f46;
}

.ghost {
  background: none; border: 1px solid #d1d5db;
  padding: 6px 12px; border-radius: 8px;
  cursor: pointer; font-size: 13px; color: #6b7280;
}
.ghost:hover { color: #1f2937; border-color: #9ca3af; }

/* 重试按钮(网络中断时) */
.retry-btn {
  background: #d97706; color: #fff; border: none;
  padding: 4px 12px; border-radius: 6px; cursor: pointer;
  font-size: 13px; font-weight: 600; margin-left: 4px;
}
.retry-btn:hover { background: #b45309; }

/* ===== 聊天区 ===== */

.chat-area {
  flex: 1; overflow-y: auto;
  padding: 24px 0 32px;
  background: #f7f5f1;
}
.chat-inner { max-width: 760px; margin: 0 auto; padding: 0 20px; }

.bubble {
  margin: 0 auto 18px;
  max-width: 760px;
  padding: 0 20px;
  display: flex; gap: 12px;
}
.bubble .avatar {
  width: 36px; height: 36px; flex-shrink: 0;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; background: #fff;
  border: 1px solid #e5e7eb;
}
.bubble .body { flex: 1; min-width: 0; }
.bubble .meta {
  font-size: 12px; color: #9ca3af; margin-bottom: 4px;
}
.bubble .meta .q-tag {
  display: inline-block; padding: 1px 6px;
  background: #fbbf24; color: #fff; border-radius: 4px;
  font-weight: 600; margin-right: 6px;
}

.bubble .content {
  background: #fff;
  padding: 13px 17px;
  /* 左上角收一个小尖,像从头像里"说"出来的气泡 */
  border-radius: 4px 16px 16px 16px;
  border: 1px solid #eceae6;
  box-shadow: 0 2px 8px rgba(120, 100, 70, 0.05);
}

/* 用户气泡靠右 + 宽度跟随文字自适应,不再撑满整行 */
.bubble.user {
  flex-direction: row-reverse;
}
.bubble.user .body {
  flex: 0 1 auto;          /* 不撑满,跟随内容收缩 */
  max-width: 76%;
  min-width: 0;
  text-align: right;       /* 让 inline-block 的气泡靠右 */
}
.bubble.user .avatar {
  background: #d97706; color: #fff; border: none;
  box-shadow: 0 2px 6px rgba(217, 119, 6, 0.3);
}
.bubble.user .content {
  display: inline-block;   /* 关键:气泡宽度贴合文字 */
  text-align: left;        /* 气泡内文字仍正常左对齐 */
  background: #d97706; color: #fff; border: none;
  border-radius: 16px 16px 4px 16px;   /* 右下角收尖 */
  box-shadow: 0 2px 8px rgba(217, 119, 6, 0.18);
  max-width: 100%;
}
/* 气泡内首尾段落不要多余外边距,短消息才贴合 */
.bubble.user .content > p:first-child { margin-top: 0; }
.bubble.user .content > p:last-child { margin-bottom: 0; }
.bubble.user .meta { text-align: right; }

/* 老师气泡(统一) */
.bubble.teacher .avatar { background: #fef3c7; }

/* 模式徽章——挂在老师名字前面,提示当前是引导/挑战/讲细节 */
.bubble .meta .mode-tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 4px;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  margin-right: 6px;
}

/* 配图 */
.bubble .ref-img {
  margin: 12px 0 4px;
  border: 1px solid #e5e7eb; border-radius: 10px;
  overflow: hidden; background: #fafafa;
}
.bubble .ref-img img { display: block; width: 100%; }
.bubble .ref-img figcaption {
  font-size: 12px; color: #6b7280; padding: 6px 10px;
  background: #f9fafb;
}

/* Markdown 内基础样式 */
.content h1, .content h2, .content h3 { margin: 10px 0 6px; line-height: 1.3; }
.content h1 { font-size: 18px; }
.content h2 { font-size: 16px; }
.content h3 { font-size: 15px; }
.content p { margin: 6px 0; }
.content ul, .content ol { padding-left: 20px; margin: 6px 0; }
.content code {
  background: #f3f4f6; padding: 1px 5px; border-radius: 3px;
  font-size: 13px; font-family: "SF Mono", Menlo, monospace;
}
.content blockquote {
  border-left: 3px solid #d97706; margin: 8px 0;
  padding: 4px 12px; color: #6b7280; background: #fef3c7;
  border-radius: 0 8px 8px 0;
}
.content strong { color: #111827; }

/* 表格——放进一个圆角框里，可横向滚动 */
.content .md-table {
  margin: 12px 0;
  border: 1px solid #e7e2d8;
  border-radius: 10px;
  overflow: hidden;
  overflow-x: auto;
  box-shadow: 0 1px 3px rgba(120, 100, 70, 0.06);
}
.content table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13.5px;
  line-height: 1.5;
}
.content thead th {
  background: #fef3c7;
  color: #92400e;
  font-weight: 600;
  text-align: left;
  padding: 9px 14px;
  white-space: nowrap;
  border-bottom: 2px solid #fbbf24;
}
.content tbody td {
  padding: 9px 14px;
  border-bottom: 1px solid #f0ede6;
  vertical-align: top;
}
.content tbody tr:last-child td { border-bottom: none; }
.content tbody tr:nth-child(even) { background: #faf8f4; }

/* 公式(KaTeX 渲染,这里只管间距 + 横向滚动,字体交给 KaTeX) */
.content .formula-block {
  margin: 12px 0;
  padding: 8px 4px;
  overflow-x: auto;
  overflow-y: hidden;
}
.content .katex { font-size: 1.05em; }
.content .katex-display { margin: 0; }

/* 围栏代码块（Stata / Python 等）——深色框,带语言标签,可横向滚动 */
.content .code-block {
  margin: 12px 0;
  border-radius: 10px;
  overflow: hidden;
  background: #282c34;
  border: 1px solid #21252b;
}
.content .code-block .code-lang {
  font-size: 11px; color: #9aa4b2;
  padding: 6px 14px; background: #21252b;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  text-transform: uppercase; letter-spacing: 0.06em;
}
.content .code-block pre {
  margin: 0; padding: 14px 16px; overflow-x: auto;
}
.content .code-block code {
  background: none; color: #e6e6e6; padding: 0;
  font-family: "SF Mono", Menlo, Consolas, "Courier New", monospace;
  font-size: 13px; line-height: 1.7; white-space: pre;
}

/* ===== 底部输入 ===== */

.composer {
  background: #fff;
  border-top: 1px solid #e5e7eb;
  padding: 12px 20px 16px;
}
.input-row {
  display: flex; gap: 10px;
  max-width: 760px; margin: 0 auto;
}
.input-row textarea {
  flex: 1; padding: 10px 14px; font-size: 14px;
  font-family: inherit; line-height: 1.5;
  border: 1px solid #d1d5db; border-radius: 10px;
  resize: vertical; outline: none;
  max-height: 160px;
}
.input-row textarea:focus { border-color: #d97706; }
.input-row button {
  padding: 0 22px; background: #d97706; color: #fff;
  border: none; border-radius: 10px;
  cursor: pointer; font-weight: 600; font-size: 14px;
  flex-shrink: 0;
}
.input-row button:hover { background: #b45309; }
.input-row button:disabled {
  background: #d1d5db; cursor: not-allowed;
}

.composer .hint {
  font-size: 12px; color: #9ca3af;
  text-align: center; margin-top: 6px;
}

/* 加载中 */
.loading-dots::after {
  content: "…"; animation: dots 1.2s steps(4, end) infinite;
}
@keyframes dots {
  0%, 20% { content: "."; }
  40% { content: ".."; }
  60% { content: "..."; }
  80%, 100% { content: ""; }
}
