:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1a1a2e;
  --muted: #64748b;
  --primary: #b45309;
  --primary-hover: #92400e;
  --primary-light: #fff7ed;
  --success: #059669;
  --danger: #dc2626;
  --border: #e2e8f0;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.app { max-width: 760px; margin: 0 auto; padding: 24px 16px 48px; }

header { text-align: center; margin-bottom: 24px; }
.home-link {
  display: inline-block;
  margin-bottom: 12px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
}
.home-link:hover { color: var(--primary); }
header h1 { font-size: 1.75rem; font-weight: 700; }
.subtitle { color: var(--muted); font-size: 0.9rem; margin-top: 4px; }

.tabs {
  display: flex; gap: 4px; background: var(--surface);
  padding: 4px; border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 20px; overflow-x: auto;
}
.tab {
  flex: 1; border: none; background: transparent; padding: 10px 6px;
  border-radius: 8px; font-size: 0.85rem; cursor: pointer;
  color: var(--muted); white-space: nowrap; transition: all 0.2s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--primary); color: white; font-weight: 600; }

.panel { display: none; }
.panel.active { display: block; }

.workflow-card {
  background: var(--primary-light); border-radius: var(--radius);
  padding: 16px 20px; margin-bottom: 16px; border-left: 4px solid var(--primary);
}
.workflow-card h3 { font-size: 0.95rem; margin-bottom: 8px; color: var(--primary); }
.workflow-steps { padding-left: 20px; font-size: 0.88rem; color: var(--text); }
.workflow-steps li { margin-bottom: 4px; }

.stats-grid {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 12px; margin-bottom: 20px;
}
.stat-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); text-align: center;
}
.stat-value { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.85rem; color: var(--muted); margin-top: 2px; }

.action-cards { display: flex; flex-direction: column; gap: 12px; }
.card-btn {
  display: flex; flex-direction: column; align-items: flex-start;
  background: var(--surface); border: 2px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; cursor: pointer;
  text-align: left; transition: all 0.2s;
}
.card-btn:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.card-btn.primary { border-color: var(--primary); background: var(--primary-light); }
.card-icon { font-size: 1.5rem; margin-bottom: 4px; }
.card-title { font-size: 1.1rem; font-weight: 600; }
.card-desc { font-size: 0.85rem; color: var(--muted); margin-top: 2px; }

.filter-bar {
  display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center;
}
.filter-bar select, .filter-bar input[type="search"] {
  flex: 1; min-width: 120px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 0.9rem;
}

.knowledge-list { display: flex; flex-direction: column; gap: 10px; }

.knowledge-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.knowledge-card-header {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
}
.knowledge-card-title { font-weight: 600; font-size: 1.05rem; }
.knowledge-card-meta { display: flex; gap: 6px; flex-shrink: 0; align-items: center; }
.knowledge-card-content {
  margin-top: 10px; font-size: 0.92rem; color: var(--text);
  white-space: pre-wrap;
}
.knowledge-card-extra {
  margin-top: 8px; font-size: 0.85rem; color: var(--muted);
  padding: 8px 12px; background: var(--bg); border-radius: 8px;
}
.knowledge-card-actions { margin-top: 12px; display: flex; gap: 8px; }

.type-tag {
  display: inline-block; font-size: 0.75rem; padding: 2px 10px;
  border-radius: 10px; font-weight: 600; margin-bottom: 8px;
}
.type-字词 { background: #dbeafe; color: #1e40af; }
.type-古诗 { background: #dcfce7; color: #166534; }
.type-文言文 { background: #fef3c7; color: #92400e; }
.type-文学常识 { background: #e0e7ff; color: #3730a3; }
.type-修辞 { background: #fce7f3; color: #9d174d; }
.type-名著 { background: #ffedd5; color: #9a3412; }
.type-现代文 { background: #f3e8ff; color: #6b21a8; }

.mastery-tag {
  font-size: 0.75rem; padding: 2px 8px; border-radius: 10px; font-weight: 600;
}
.mastery-0 { background: #fee2e2; color: #991b1b; }
.mastery-1 { background: #fef3c7; color: #92400e; }
.mastery-2 { background: #dbeafe; color: #1e40af; }
.mastery-3 { background: #dcfce7; color: #166534; }
.mastery-4 { background: #d1fae5; color: #065f46; }

.chapter-tag { font-size: 0.8rem; color: var(--muted); }

.form-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.form-tab {
  border: 1px solid var(--border); background: var(--surface);
  padding: 8px 16px; border-radius: 8px; cursor: pointer;
}
.form-tab.active { background: var(--primary); color: white; border-color: var(--primary); }
.form-panel { display: none; }
.form-panel.active { display: block; }

label { display: block; margin-bottom: 12px; font-size: 0.9rem; font-weight: 500; }
input, textarea, select {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 1rem; font-family: inherit;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}
.hint { font-size: 0.85rem; color: var(--muted); margin-bottom: 12px; }

.btn {
  border: none; padding: 10px 20px; border-radius: 8px;
  font-size: 1rem; cursor: pointer; background: var(--border); color: var(--text);
}
.btn:hover { filter: brightness(0.95); }
.btn.primary { background: var(--primary); color: white; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.correct { background: var(--success); color: white; }
.btn.wrong { background: var(--danger); color: white; }
.btn.small { padding: 6px 12px; font-size: 0.85rem; }

.message { margin-top: 12px; padding: 12px; border-radius: 8px; font-size: 0.9rem; }
.message.success { background: #dcfce7; color: #166534; }
.message.error { background: #fee2e2; color: #991b1b; }
.hidden { display: none !important; }
.empty-state { text-align: center; padding: 48px 24px; color: var(--muted); }

.setup {
  background: var(--surface); padding: 24px; border-radius: var(--radius); box-shadow: var(--shadow);
}
.setup h3 { margin-bottom: 8px; }
.setup p { margin-bottom: 16px; color: var(--muted); font-size: 0.92rem; }

.progress-bar {
  height: 6px; background: var(--border); border-radius: 3px;
  margin-bottom: 8px; overflow: hidden;
}
.progress-bar > div {
  height: 100%; background: var(--primary); border-radius: 3px;
  transition: width 0.3s; width: 0%;
}
.progress-text { text-align: center; font-size: 0.85rem; color: var(--muted); margin-bottom: 20px; }

.flashcard {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 40px 24px; text-align: center; cursor: pointer;
  min-height: 240px; display: flex; flex-direction: column;
  justify-content: center; margin-bottom: 20px; user-select: none;
}
.card-title { font-size: 1.6rem; font-weight: 700; }
.card-chapter { color: var(--muted); font-size: 0.9rem; margin-top: 8px; }
.card-content { font-size: 1.1rem; text-align: left; white-space: pre-wrap; line-height: 1.8; }
.card-keypoints {
  margin-top: 12px; text-align: left; font-size: 0.9rem;
  color: var(--primary); white-space: pre-wrap;
}
.card-keypoints::before { content: "要点："; font-weight: 600; }
.card-example {
  margin-top: 12px; text-align: left; font-size: 0.9rem;
  color: var(--muted); font-style: italic; white-space: pre-wrap;
}
.card-example::before { content: "例题："; font-weight: 600; font-style: normal; }
.flip-hint { margin-top: 24px; font-size: 0.85rem; color: var(--muted); }

.actions { display: flex; gap: 12px; }
.actions .btn { flex: 1; padding: 14px; font-size: 1.05rem; }

.done {
  text-align: center; padding: 32px; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.done h2 { margin-bottom: 12px; }
.score { font-size: 2.5rem; font-weight: 700; color: var(--primary); margin: 16px 0; }

.quiz-question {
  background: var(--surface); padding: 28px; border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 16px;
}
.quiz-text { font-size: 1.1rem; font-weight: 500; white-space: pre-wrap; }
.quiz-chapter { color: var(--muted); font-size: 0.85rem; margin-top: 8px; }

.options { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.option-btn {
  padding: 14px 16px; border: 2px solid var(--border); border-radius: 8px;
  background: var(--surface); font-size: 0.95rem; cursor: pointer;
  text-align: left; transition: all 0.2s; white-space: pre-wrap;
}
.option-btn:hover:not(:disabled) { border-color: var(--primary); }
.option-btn.correct-answer { border-color: var(--success); background: #dcfce7; }
.option-btn.wrong-answer { border-color: var(--danger); background: #fee2e2; }

.feedback { text-align: center; padding: 12px; border-radius: 8px; margin-bottom: 12px; font-weight: 600; }
.feedback.correct { background: #dcfce7; color: #166534; }
.feedback.wrong { background: #fee2e2; color: #991b1b; }

.badge {
  background: var(--primary); color: white; padding: 4px 12px;
  border-radius: 20px; font-size: 0.85rem; white-space: nowrap;
}
.delete-btn {
  border: none; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 1.2rem; padding: 4px 8px;
}
.delete-btn:hover { color: var(--danger); }

.public-list { display: flex; flex-direction: column; gap: 16px; margin-bottom: 16px; }
.public-chapter {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.public-chapter-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; background: var(--primary-light); border-bottom: 1px solid var(--border);
}
.public-chapter-title { font-weight: 600; font-size: 0.95rem; }
.public-chapter-actions { display: flex; gap: 8px; flex-shrink: 0; }
.public-item {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.public-item:last-child { border-bottom: none; }
.public-item.already-added { opacity: 0.55; }
.public-item input[type="checkbox"] {
  margin-top: 4px; width: 18px; height: 18px; flex-shrink: 0; cursor: pointer;
}
.public-item input[type="checkbox"]:disabled { cursor: not-allowed; }
.public-item-body { flex: 1; min-width: 0; }
.public-item-title { font-weight: 600; margin: 4px 0; }
.public-item-content {
  font-size: 0.9rem; color: var(--muted); white-space: pre-wrap;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.already-badge {
  display: inline-block; font-size: 0.75rem; color: var(--muted);
  background: var(--bg); padding: 2px 8px; border-radius: 10px; margin-left: 6px;
}
.public-import-bar {
  position: sticky; bottom: 0; display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--border);
}
.public-import-bar #public-selected-count { flex: 1; color: var(--muted); font-size: 0.9rem; }

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .card-title { font-size: 1.3rem; }
  .public-import-bar { flex-wrap: wrap; }
  .public-import-bar #public-selected-count { flex-basis: 100%; }
}
