/* ── 全局重置 ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── 亮色主题（默认）── */
:root {
  --c-bg:           #fafaf8;
  --c-white:        #fff;
  --c-text:         #1a1a1a;
  --c-text-2:       #555;
  --c-text-muted:   #888;
  --c-accent:       #c45a2c;
  --c-accent-light: #f5ebe6;
  --c-accent-dark:  #8b3a18;
  --c-border:       #e5e0da;
  --c-dark:         #1a1a1a;
  --c-surface:      #fff;
  --font:           'Noto Sans SC', -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --max-width:      1100px;
  --content-width:  800px;
  --radius:         10px;
}

/* ── 暗色主题 ── */
[data-theme="dark"] {
  --c-bg:           #0f1117;
  --c-white:        #1a1d27;
  --c-text:         #e8eaf0;
  --c-text-2:       #9ca3b4;
  --c-text-muted:   #6b7280;
  --c-accent:       #e06830;
  --c-accent-light: #2a1a0e;
  --c-accent-dark:  #f08050;
  --c-border:       #2e3247;
  --c-dark:         #0a0c12;
  --c-surface:      #1a1d27;
}

html { font-size: 17px; scroll-behavior: smooth; }
body { font-family: var(--font); background: var(--c-bg); color: var(--c-text); line-height: 1.6; transition: background .25s, color .25s; }

/* ── 顶部导航 ── */
.lesson-nav {
  background: var(--c-dark);
  padding: 0.75rem 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.lesson-nav a { color: rgba(255,255,255,.65); text-decoration: none; font-size: 0.9rem; transition: color .2s; }
.lesson-nav a:hover { color: #fff; }
.lesson-nav .sep { color: rgba(255,255,255,.3); }
.lesson-nav .lesson-title { color: #fff; font-weight: 600; font-size: 0.9rem; }

/* 主题切换按钮（嵌入导航右侧）*/
.theme-toggle {
  margin-left: 6px;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.2);
  color: rgba(255,255,255,.8);
  border-radius: 20px;
  padding: 0.2rem 0.8rem;
  font-size: 0.78rem;
  cursor: pointer;
  font-family: var(--font);
  transition: background .2s;
  white-space: nowrap;
}
.theme-toggle:hover { background: rgba(255,255,255,.2); }

/* ── 主内容区 ── */
.lesson-wrap { max-width: var(--content-width); margin: 0 auto; padding: 2.5rem 2rem 5rem; }

/* ── 标题 ── */
h1 { font-size: clamp(1.5rem, 4vw, 2.2rem); font-weight: 900; margin-bottom: 0.5rem; color: var(--c-text); text-wrap: balance; }
h2 {
  font-size: 1.4rem; font-weight: 700; color: var(--c-text);
  display: inline-block;
  border-bottom: 2px solid var(--c-accent);
  padding-bottom: 0.25rem;
  margin: 2rem 0 0.3rem;
}
h3 { font-size: 1.1rem; font-weight: 600; margin: 1.4rem 0 0.5rem; color: var(--c-text); }
p  { color: var(--c-text-2); margin-bottom: 0.7rem; font-size: 1rem; }
p strong { color: var(--c-text); }
.section-subtitle { font-size: 1rem; color: var(--c-text-muted); margin-bottom: 1rem; }

/* ── 分隔线 ── */
hr { border: none; border-top: 1px solid var(--c-border); margin: 2rem 0; }

/* ── 提示通知条 ── */
.tuzi-notice {
  background: rgba(196,90,44,.06);
  border-left: 3px solid var(--c-accent);
  border-radius: 0 6px 6px 0;
  padding: 12px 16px;
  margin: 20px 0 24px;
  font-size: 0.88rem;
  color: var(--c-text-2);
  line-height: 1.65;
}
.tuzi-notice strong { color: var(--c-text); }
.tuzi-notice.warn {
  background: rgba(239,68,68,.06);
  border-left-color: #dc2626;
}

[data-theme="dark"] .tuzi-notice {
  background: rgba(224, 104, 48, 0.1);
}
[data-theme="dark"] .tuzi-notice.warn {
  background: rgba(220, 38, 38, 0.1);
}

/* ── 作业卡片 ── */
.homework-card {
  background: var(--c-white);
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin: 24px 0;
}
.homework-card h3 { margin-top: 0; display: flex; align-items: center; gap: 10px; }
.homework-card .badge-sm {
  font-size: .65rem; padding: 2px 8px; background: var(--c-accent); color: #fff;
  border-radius: 10px; font-weight: 700; text-transform: uppercase;
}
.homework-card ul { margin: 12px 0 0; padding-left: 20px; color: var(--c-text-2); }
.homework-card li { margin-bottom: 8px; line-height: 1.7; font-size: 0.92rem; }
.homework-card li strong { color: var(--c-text); }

[data-theme="dark"] .homework-card {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.1);
}

/* ── 卡片 ── */
.card {
  background: var(--c-white);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 1.4rem;
  margin-bottom: 1rem;
  position: relative;
}
.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--c-accent);
  border-radius: var(--radius) var(--radius) 0 0;
}
.card h3 { margin-top: 0; }

/* highlight box */
.highlight-box {
  background: var(--c-accent-light);
  border-left: 4px solid var(--c-accent);
  padding: 1rem 1.2rem;
  margin: 1rem 0;
  border-radius: 0 6px 6px 0;
}
.highlight-box p { margin: 0; color: var(--c-text); }

/* dark box */
.dark-box {
  background: var(--c-accent-light);
  border: 1px solid var(--c-border);
  border-left: 4px solid var(--c-accent);
  padding: 1.2rem 1.5rem;
  margin: 1rem 0;
  border-radius: 0 8px 8px 0;
}
.dark-box p { color: var(--c-text-2); }
.dark-box p:last-child { margin-bottom: 0; }

/* quote */
.quote {
  background: var(--c-white);
  border-left: 4px solid var(--c-accent);
  padding: 1rem 1.2rem;
  margin: 0.8rem 0;
  font-size: 1rem;
  line-height: 1.65;
  color: var(--c-text);
}

/* ── 按钮 ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0.55rem 1.5rem;
  border-radius: 6px; border: none; cursor: pointer;
  font-size: 0.95rem; font-weight: 600;
  text-decoration: none;
  transition: background .2s;
  font-family: var(--font);
}
.btn-primary { background: var(--c-accent); color: #fff; }
.btn-primary:hover { background: var(--c-accent-dark); }
.btn-ghost { background: transparent; color: var(--c-text-2); border: 1px solid var(--c-border); }
.btn-ghost:hover { border-color: var(--c-accent); color: var(--c-accent); }

/* ── 表单 ── */
input[type=text], input[type=password], textarea, select {
  width: 100%;
  background: var(--c-white);
  border: 1px solid var(--c-border);
  border-radius: 6px;
  color: var(--c-text);
  padding: 0.55rem 0.9rem;
  font-size: 0.95rem;
  font-family: var(--font);
  outline: none;
  transition: border-color .15s, background .25s;
}
input:focus, textarea:focus, select:focus { border-color: var(--c-accent); }
textarea { resize: vertical; min-height: 80px; }

/* ── 标签 ── */
.tag {
  display: inline-block; padding: 0.15rem 0.7rem;
  border-radius: 3px; font-size: 0.8rem; font-weight: 600;
  background: var(--c-accent); color: #fff;
}
.tag-outline {
  background: transparent; color: var(--c-text-muted);
  border: 1px solid var(--c-border); border-radius: 3px;
  padding: 0.15rem 0.7rem; font-size: 0.8rem;
}

/* ── 流式输出区域 ── */
.output-box {
  background: var(--c-white);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  min-height: 60px;
  font-size: 0.95rem;
  line-height: 1.8;
  white-space: pre-wrap;
  color: var(--c-text);
  transition: background .25s;
}
.output-box.empty { color: var(--c-text-muted); font-style: italic; }

/* ── 预设问题 ── */
.preset-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  padding: 0.35rem 0.9rem;
  background: var(--c-white); border: 1px solid var(--c-border);
  border-radius: 20px; font-size: 0.88rem; color: var(--c-text-2);
  cursor: pointer; transition: all .15s;
}
.chip:hover { border-color: var(--c-accent); color: var(--c-accent); background: var(--c-accent-light); }

/* ── 表格 ── */
table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: 0.95rem; }
th { background: var(--c-accent-light); padding: 0.6rem 0.8rem; text-align: left; font-weight: 600; color: var(--c-text); border-bottom: 2px solid var(--c-accent); }
td { padding: 0.5rem 0.8rem; border-bottom: 1px solid var(--c-border); color: var(--c-text-2); }
tr:last-child td { border-bottom: none; }

/* ── 课程页脚 ── */
.lesson-footer {
  display: flex; justify-content: space-between;
  margin-top: 3rem; padding-top: 1.5rem;
  border-top: 1px solid var(--c-border);
}

/* ── 代码 ── */
code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.85rem;
  background: var(--c-accent-light);
  border: 1px solid var(--c-border);
  border-radius: 4px;
  padding: 1px 6px;
  color: var(--c-accent);
}

/* ── 响应式 ── */
@media (max-width: 600px) {
  .lesson-wrap { padding: 1.5rem 1rem 4rem; }
  h1 { font-size: 1.4rem; }
  .lesson-footer { flex-direction: column; gap: 0.8rem; }

  /* 顶部导航：移动端只保留首页链接 + 当前标题，隐藏中间层级 */
  .lesson-nav { padding: 0.6rem 1rem; gap: 0.4rem; flex-wrap: nowrap; }
  .lesson-nav .sep { display: none; }
  /* 隐藏除第一个和最后一个子元素之外的 a 标签（中间层级） */
  .lesson-nav > a:not(:first-child) { display: none; }
  .lesson-nav .lesson-title {
    font-size: 0.82rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
  }
  .lesson-nav > a:first-child { white-space: nowrap; font-size: 0.82rem; }
  .theme-toggle { margin-left: auto; padding: 0.15rem 0.6rem; font-size: 0.72rem; }

  /* 移动端隐藏次要状态按钮，只保留 LLM 主状态 */
  #tuzi-status-btn,
  #minimax-status-btn { display: none !important; }

  /* 工具箱按钮缩短 */
  #llm-widget > a { padding: 0.15rem 0.5rem !important; font-size: 0.72rem !important; }
  #llm-status-btn { padding: 0.15rem 0.5rem !important; font-size: 0.72rem !important; }
}

/* ════════════════════════════════════════════
   悬浮 API 配置按钮 (FAB)
   ════════════════════════════════════════════ */
#api-fab-btn {
  position: fixed;
  right: 18px;
  bottom: 22px;
  z-index: 900;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--c-bg-2);
  color: var(--c-text-muted);
  font-size: 1.25rem;
  box-shadow: 0 2px 10px rgba(0,0,0,.18);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s, color .2s, transform .15s;
}
#api-fab-btn:hover { background: var(--c-border); transform: scale(1.08); }
#api-fab-btn.fab-connected { color: var(--c-accent); }

/* FAB Dialog */
#api-fab-dialog {
  border: 1px solid var(--c-border);
  border-radius: 14px;
  padding: 0;
  background: var(--c-bg-1);
  color: var(--c-text-1);
  max-width: 340px;
  width: calc(100vw - 32px);
  box-shadow: 0 8px 32px rgba(0,0,0,.22);
}
#api-fab-dialog::backdrop { background: rgba(0,0,0,.35); }
.fab-dialog-inner { padding: 20px 20px 16px; }
.fab-dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-weight: 700;
  font-size: 1rem;
}
.fab-close-btn {
  background: none;
  border: none;
  font-size: 1rem;
  color: var(--c-text-muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.fab-close-btn:hover { background: var(--c-bg-2); }
.fab-status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: .84rem;
  color: var(--c-text-2);
}
.fab-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #888;
  flex-shrink: 0;
}
.fab-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--c-text-2);
  margin-bottom: 10px;
}
.fab-label input {
  border: 1px solid var(--c-border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: .85rem;
  background: var(--c-bg-2);
  color: var(--c-text-1);
  font-family: inherit;
}
.fab-label input:focus { outline: 2px solid var(--c-accent); border-color: transparent; }
.fab-dialog-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
}
.fab-link { font-size: .82rem; color: var(--c-accent); text-decoration: none; }
.fab-link:hover { text-decoration: underline; }

/* ════════════════════════════════════════════
   进度完成按钮
   ════════════════════════════════════════════ */
.progress-complete-btn {
  color: #16a34a !important;
  border-color: #16a34a !important;
}
.progress-complete-btn.done {
  opacity: .75;
  cursor: default;
}

/* ════════════════════════════════════════════
   撒花动画
   ════════════════════════════════════════════ */
.progress-confetti {
  position: fixed;
  top: -12px;
  border-radius: 2px;
  pointer-events: none;
  z-index: 9999;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}
