/* MyFly 学习舱 —— 深色主题，手机优先 */
:root {
  --bg: #17181d;
  --bg-deep: #0f1015;
  --card: #1d1f27;
  --border: #262833;
  --text: #e8eaf0;
  --text-dim: #8b93a7;
  --text-faint: #6b7280;
  --blue: #2f6fed;
  --blue-hover: #3d7bf5;
  --green: #3fa34d;
  --green-text: #6fa878;
  --red: #e06c5a;
  --yellow: #ffd479;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: "PingFang SC", "Microsoft YaHei UI", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ============ 顶栏 ============ */
#topbar {
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}
#topbar .title { font-size: 17px; font-weight: 700; }
#topbar .stage { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

/* ============ 视图区 ============ */
#views { flex: 1; overflow: hidden; position: relative; }
.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px 20px;
  display: none;
}
.view.active { display: block; }
/* 学习舱视图的滚动容器由消息区自己管 */
#view-chat { display: none; padding: 0; }
#view-chat.active { display: flex; flex-direction: column; }
#messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#projectPicker {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
#projectPicker h2 { font-size: 20px; }
#projectPicker .sub { color: var(--text-dim); font-size: 13px; margin-bottom: 4px; }

/* ============ 聊天气泡 ============ */
.bubble {
  max-width: 88%;
  border-radius: 14px;
  padding: 10px 14px 12px;
  word-break: break-word;
  overflow-wrap: anywhere;
  flex-shrink: 0;
}
.bubble.user {
  align-self: flex-end;
  background: #2d5bd7;
  color: #fff;
}
.bubble.coding {
  align-self: flex-start;
  background: #1f2129;
  border-left: 3px solid var(--blue);
}
.bubble.english {
  align-self: flex-start;
  background: #1b211d;
  border-left: 3px solid var(--green);
  width: 88%;
}
.bubble.error {
  align-self: flex-start;
  background: #2a1c19;
  border-left: 3px solid var(--red);
  color: #f0b4a8;
}
.bubble .who {
  font-size: 11px;
  color: var(--text-faint);
  margin-bottom: 4px;
}
.bubble.coding .who { color: #7ba3f0; }
.bubble.english .who { color: var(--green-text); }

/* Coach 折叠卡片 */
.coach-toggle {
  background: none;
  border: none;
  color: var(--green-text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 0 0 6px;
}
.coach-body { color: var(--text); }
.bubble.english.collapsed .coach-body { display: none; }

/* 消息内 Markdown 内容 */
.bubble :is(h1, h2, h3, h4) { margin: 10px 0 6px; line-height: 1.35; }
.bubble h1 { font-size: 18px; } .bubble h2 { font-size: 16px; } .bubble h3 { font-size: 15px; }
.bubble p { margin: 6px 0; }
.bubble ul, .bubble ol { margin: 6px 0 6px 20px; }
.bubble table { border-collapse: collapse; margin: 8px 0; width: 100%; font-size: 13px; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 5px 8px; text-align: left; }
.bubble pre {
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
  margin: 4px 0;
}
.bubble pre span { background: transparent !important; }
.bubble a { color: #7ba3f0; }
.bubble blockquote {
  border-left: 3px solid var(--border);
  padding-left: 10px;
  color: var(--text-dim);
  margin: 6px 0;
}

/* 流式光标 */
.cursor { color: var(--text-faint); }

/* 鼓励语 */
#encourage {
  align-self: center;
  color: var(--green-text);
  font-size: 12px;
  padding: 4px;
  flex-shrink: 0;
}

/* ============ 输入区 ============ */
#inputbar {
  flex-shrink: 0;
  background: var(--bg-deep);
  border-top: 1px solid var(--border);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  display: none;
  flex-direction: column;
  gap: 8px;
}
#inputbar.show { display: flex; }
#inputbar .quick {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
#inputbar .quick::-webkit-scrollbar { display: none; }
#inputbar .row { display: flex; gap: 8px; align-items: flex-end; }
#input {
  flex: 1;
  background: #101116;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
}
#input:focus { outline: none; border-color: var(--blue); }

/* ============ 底部导航 ============ */
#tabbar {
  flex-shrink: 0;
  display: flex;
  background: var(--bg-deep);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabbar button {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 12px;
  padding: 10px 0 8px;
  cursor: pointer;
  position: relative;
  font-family: inherit;
}
#tabbar button.active { color: #7ba3f0; font-weight: 700; }
.badge {
  display: inline-block;
  background: var(--red);
  color: #fff;
  border-radius: 9px;
  font-size: 10px;
  min-width: 17px;
  padding: 1px 5px;
  margin-left: 4px;
  vertical-align: top;
}

/* ============ 通用组件 ============ */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 12px;
}
.page-title { font-size: 20px; margin-bottom: 2px; }
.page-sub { color: var(--text-dim); font-size: 13px; margin-bottom: 14px; }
.section-title { font-size: 14px; margin: 14px 0 8px; }
.hint { color: var(--text-faint); font-size: 12px; margin-top: 8px; }
.center { text-align: center; }

.stat-row { display: flex; gap: 10px; margin-bottom: 12px; overflow-x: auto; }
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  flex: 1;
  min-width: 82px;
  text-align: center;
}
.stat-card .v { font-size: 20px; font-weight: 700; }
.stat-card .n { font-size: 11px; color: var(--text-dim); }

button.primary, button.ghost, button.danger {
  border: none;
  border-radius: 9px;
  padding: 9px 18px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
button.primary { background: var(--blue); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--blue-hover); }
button.primary:disabled { background: #2a3140; color: var(--text-faint); cursor: default; }
button.ghost { background: #23242c; color: #c6cad4; border: 1px solid #33364a; }
button.ghost:hover { background: #2a2c37; color: var(--text); }
button.danger { background: transparent; color: var(--red); border: 1px solid #5a332c; }
button.danger:hover { background: #33201c; }
.btn-row { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; }

/* ============ 选项目卡片 ============ */
.proj-card { display: flex; align-items: center; gap: 14px; }
.proj-card .info { flex: 1; }
.proj-card .name { font-size: 16px; font-weight: 700; }
.proj-card .desc { color: var(--text-dim); font-size: 13px; }
.proj-card .tech { color: var(--text-faint); font-size: 12px; margin-top: 3px; }

/* ============ 词汇本 ============ */
.review-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 18px;
  text-align: center;
  margin-bottom: 12px;
}
.review-card .pos { color: var(--text-faint); font-size: 12px; text-align: left; }
.review-card .word { font-size: 30px; font-weight: 700; margin: 18px 0; }
.review-card .answer { color: #c6cad4; margin-bottom: 16px; white-space: pre-line; }
.review-card .btns { display: flex; gap: 10px; justify-content: center; }
.review-done { color: var(--green-text); text-align: center; padding: 16px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
#vocabTable { width: 100%; border-collapse: collapse; font-size: 13px; }
#vocabTable th {
  background: #1a1c23; color: var(--text-dim); text-align: left;
  padding: 8px 10px; white-space: nowrap;
}
#vocabTable td { padding: 8px 10px; border-top: 1px solid #23242c; vertical-align: top; }
#vocabTable td:first-child { font-weight: 600; white-space: nowrap; }
#vocabTable tr:nth-child(even) { background: #14161c; }

/* ============ 进度页 ============ */
.stage-row {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 7px;
}
.stage-num {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; flex-shrink: 0;
  background: #23242c; color: var(--text-faint);
}
.stage-row.done .stage-num { background: #1f3d2b; color: var(--green-text); }
.stage-row.current .stage-num { background: var(--blue); color: #fff; }
.stage-row .s-title { font-weight: 700; font-size: 13px; }
.stage-row.current .s-title { color: #7ba3f0; }
.stage-row.done .s-title { color: var(--green-text); }
.stage-row .s-goal { color: var(--text-dim); font-size: 12px; }
.stage-row .s-tag { font-size: 11px; color: var(--text-faint); white-space: nowrap; padding-top: 3px; }

.chart { display: flex; align-items: flex-end; gap: 4px; height: 140px; }
.chart .bar-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.chart .bar { background: var(--blue); border-radius: 3px 3px 0 0; min-height: 2px; }
.chart .bar.zero { background: #23242c; }
.chart .bar-val { font-size: 9px; color: var(--text-dim); text-align: center; margin-bottom: 2px; }
.chart .bar-date { font-size: 9px; color: var(--text-faint); text-align: center; margin-top: 4px; }

/* ============ 设置表单 ============ */
.form label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 10px; }
.form input {
  display: block; width: 100%; margin-top: 5px;
  background: #101116; border: 1px solid var(--border); border-radius: 9px;
  color: var(--text); padding: 9px 12px; font-size: 14px;
}
.form input:focus { outline: none; border-color: var(--blue); }

/* ============ 桌面适配 ============ */
@media (min-width: 700px) {
  body { max-width: 860px; margin: 0 auto; box-shadow: 0 0 60px rgba(0,0,0,.5); }
  .bubble { max-width: 76%; }
  .bubble.english { width: 76%; }
}
