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

:root {
  --primary: #667eea;
  --primary-dark: #5a6fd6;
  --accent: #764ba2;
  --bg: #f0f2f5;
  --card: #ffffff;
  --text: #333333;
  --text-light: #666666;
  --border: #e0e0e0;
  --success: #4caf50;
  --error: #f44336;
  --sidebar-w: 240px;
}

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

#app {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
  color: white;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.3s;
}

.sidebar-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
}

.sidebar-header h2 { font-size: 1.3em; }
.sidebar-header .subtitle { font-size: 0.8em; opacity: 0.7; margin-top: 4px; }

.nav-items { flex: 1; padding: 12px 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  cursor: pointer;
  transition: background 0.2s;
  font-size: 0.95em;
}

.nav-item:hover { background: rgba(255,255,255,0.1); }
.nav-item.active { background: rgba(255,255,255,0.2); font-weight: 600; }
.nav-icon { font-size: 1.2em; }

.sidebar-stats {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.15);
  font-size: 0.8em;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  opacity: 0.8;
}

/* Mobile Header */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--primary);
  color: white;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 90;
}

.mobile-header h2 { font-size: 1.1em; }
.menu-btn {
  background: none;
  border: none;
  color: white;
  font-size: 1.5em;
  cursor: pointer;
}

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 99;
}

/* Main Content */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 24px;
  max-width: 900px;
}

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

/* Quiz Controls */
.quiz-controls {
  background: var(--card);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: center;
}

.control-group label {
  font-size: 0.8em;
  font-weight: 600;
  color: var(--text-light);
  display: block;
  margin-bottom: 6px;
}

.btn-group { display: flex; gap: 6px; }

.ctrl-btn {
  padding: 6px 14px;
  border: 2px solid var(--primary);
  border-radius: 16px;
  background: white;
  color: var(--primary);
  cursor: pointer;
  font-size: 0.85em;
  transition: all 0.2s;
}

.ctrl-btn.active, .ctrl-btn:hover {
  background: var(--primary);
  color: white;
}

.search-row {
  margin-top: 12px;
}

.search-row input {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 0.9em;
  outline: none;
  transition: border-color 0.2s;
}

.search-row input:focus { border-color: var(--primary); }

/* Filter Tabs */
.filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  background: var(--card);
  padding: 14px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.filter-tab {
  padding: 6px 14px;
  border-radius: 16px;
  cursor: pointer;
  font-size: 0.8em;
  font-weight: 500;
  border: 1px solid var(--border);
  background: #f8f9fa;
  transition: all 0.2s;
}

.filter-tab:hover { background: #e8eaff; border-color: var(--primary); }
.filter-tab.active { background: var(--primary); color: white; border-color: var(--primary); }
.filter-tab .count {
  display: inline-block;
  background: rgba(0,0,0,0.08);
  border-radius: 8px;
  padding: 0 6px;
  font-size: 0.85em;
  margin-left: 4px;
}
.filter-tab.active .count { background: rgba(255,255,255,0.3); }

/* Question Cards */
.question-list { padding-bottom: 40px; }

.topic-header {
  font-size: 1.05em;
  font-weight: 700;
  color: #4a148c;
  padding: 10px 16px;
  background: linear-gradient(90deg, #f3e5f5, transparent);
  border-left: 4px solid #7b1fa2;
  border-radius: 0 8px 8px 0;
  margin: 20px 0 12px;
}

.subtopic-header {
  font-size: 0.9em;
  font-weight: 600;
  color: #1565c0;
  padding: 6px 12px;
  margin: 14px 0 8px;
  border-left: 3px solid #42a5f5;
}

.q-card {
  background: var(--card);
  border-radius: 10px;
  padding: 18px;
  margin-bottom: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  transition: box-shadow 0.2s;
}

.q-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,0.1); }

.q-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 6px;
}

.q-badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.7em;
  font-weight: 600;
}

.q-badge.single { background: #e3f2fd; color: #1565c0; }
.q-badge.multi { background: #fce4ec; color: #c62828; }

.q-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.q-tag {
  font-size: 0.65em;
  padding: 2px 7px;
  border-radius: 8px;
  background: #e8f5e9;
  color: #2e7d32;
}

.q-num { font-size: 0.75em; color: #999; }

.q-text { font-size: 0.95em; margin-bottom: 12px; font-weight: 500; }

.q-options { list-style: none; }

.q-options li {
  padding: 10px 12px;
  margin: 5px 0;
  border-radius: 8px;
  background: #f8f9fa;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.15s;
  font-size: 0.9em;
}

.q-options li:hover { background: #e8eaff; }

.q-options li .opt-letter {
  display: inline-block;
  width: 22px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  border-radius: 50%;
  background: #e0e0e0;
  color: #555;
  font-size: 0.75em;
  font-weight: bold;
  margin-right: 10px;
}

.q-card.revealed .q-options li.correct {
  background: #e8f5e9;
  border-color: var(--success);
  color: #2e7d32;
}

.q-card.revealed .q-options li.correct .opt-letter {
  background: var(--success);
  color: white;
}

.q-card.revealed .q-options li.wrong {
  background: #ffebee;
  border-color: var(--error);
  color: #c62828;
}

.q-card.revealed .q-options li.wrong .opt-letter {
  background: var(--error);
  color: white;
}

.q-answer {
  margin-top: 10px;
  padding: 8px 12px;
  background: #f3e5f5;
  border-radius: 8px;
  color: #6a1b9a;
  font-weight: 600;
  font-size: 0.85em;
  display: none;
}

.q-card.revealed .q-answer { display: block; }

/* AI Page */
.ai-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 48px);
  background: var(--card);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}

.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.ai-welcome {
  text-align: center;
  padding: 60px 20px;
}

.welcome-icon { font-size: 3em; margin-bottom: 12px; }
.ai-welcome h3 { font-size: 1.3em; margin-bottom: 8px; color: var(--primary); }
.ai-welcome p { color: var(--text-light); margin-bottom: 20px; }

.quick-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.quick-prompts button {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #f8f9fa;
  cursor: pointer;
  font-size: 0.8em;
  transition: all 0.2s;
}

.quick-prompts button:hover {
  background: #e8eaff;
  border-color: var(--primary);
}

.msg {
  margin-bottom: 16px;
  display: flex;
  gap: 10px;
}

.msg.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9em;
  flex-shrink: 0;
}

.msg.user .msg-avatar { background: var(--primary); color: white; }
.msg.assistant .msg-avatar { background: #e8f5e9; }

.msg-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.9em;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user .msg-bubble {
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.msg.assistant .msg-bubble {
  background: #f5f5f5;
  border-bottom-left-radius: 4px;
}

.msg-thinking {
  font-size: 0.8em;
  color: var(--text-light);
  font-style: italic;
  margin-bottom: 6px;
  padding: 6px 10px;
  background: #fff8e1;
  border-radius: 6px;
  border-left: 3px solid #ffc107;
}

.ai-input-area {
  display: flex;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: #fafafa;
}

.ai-input-area textarea {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 0.9em;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.5;
  transition: border-color 0.2s;
}

.ai-input-area textarea:focus { border-color: var(--primary); }

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: white;
  font-size: 1.1em;
  cursor: pointer;
  transition: background 0.2s;
  align-self: flex-end;
}

.send-btn:hover { background: var(--primary-dark); }
.send-btn:disabled { background: #ccc; cursor: not-allowed; }

/* Back to top */
.back-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  font-size: 1.1em;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(102,126,234,0.4);
  display: none;
  z-index: 50;
}

.back-top.show { display: block; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .overlay.open { display: block; }
  .mobile-header { display: flex; }
  .main-content {
    margin-left: 0;
    padding: 70px 12px 12px;
    max-width: 100%;
  }
  .ai-container { height: calc(100vh - 70px); }
  .msg-bubble { max-width: 85%; }
  .control-row { gap: 12px; }
}
