:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f4f9;
  --border: #e4e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #3b82f6;
  --primary-soft: #eff6ff;
  --primary-hover: #2563eb;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --success-border: #86efac;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --danger-border: #fca5a5;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(15, 23, 42, 0.05);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}

.hidden {
  display: none !important;
}

.muted-text {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0;
}

.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 310px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  z-index: 30;
  transition: margin-left 0.2s ease, transform 0.2s ease;
}

@media (min-width: 861px) {
  .sidebar.collapsed {
    margin-left: -310px;
  }
}

.sidebar-header {
  padding: 16px 16px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  font-size: 24px;
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.25;
}

.overall-progress-wrap {
  padding: 0 16px 12px;
}

.progress-bar {
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.filter-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 0 16px 12px;
}

.filter-tab {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 6px 4px;
  font-size: 12.5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.15s;
}

.filter-tab:hover {
  background: var(--surface-2);
  color: var(--text);
}

.filter-tab.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

.badge {
  background: var(--surface-2);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 0 5px;
  font-size: 11px;
  line-height: 16px;
}

.filter-tab.active .badge {
  background: var(--primary);
  color: #fff;
}

.batch-selector {
  padding: 0 16px 10px;
}

.batch-selector select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13.5px;
  outline: none;
}

.catalog-tree {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 20px;
}

.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

.small-btn {
  flex: 1;
  font-size: 12.5px;
  padding: 6px 8px;
  text-align: center;
}

.tree-all-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.tree-all-btn:hover {
  background: var(--surface-2);
}

.tree-all-btn.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.subject-group {
  margin-bottom: 6px;
}

.subject-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.subject-row:hover {
  background: var(--surface-2);
}

.subject-row.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.caret-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  flex-shrink: 0;
  border-radius: 4px;
}

.caret-btn:hover {
  background: rgba(0, 0, 0, 0.06);
}

.subject-name {
  flex: 1;
  font-size: 13.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-count {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.chapter-list {
  padding-left: 20px;
  margin-top: 2px;
}

.chapter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: all 0.15s;
}

.chapter-row:hover {
  background: var(--surface-2);
  color: var(--text);
}

.chapter-row.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.chapter-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Main Area */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.breadcrumb {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.search-wrap input {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--text);
  width: 170px;
  outline: none;
}

.search-wrap input:focus {
  border-color: var(--primary);
  background: var(--surface);
}

.pill-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 11px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.pill-btn:hover {
  background: var(--surface-2);
}

.pill-btn.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

.pill-btn.danger-ghost:hover {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger);
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Workspace */
.workspace {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.question-card {
  width: 100%;
  max-width: 820px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 28px;
}

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

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

.q-index {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
}

.type-badge {
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
}

.chapter-tag {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 2px 8px;
  border-radius: 6px;
}

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

.ghost-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 13px;
  cursor: pointer;
}

.ghost-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.ghost-btn.fav-active {
  background: var(--warn-soft);
  border-color: #fcd34d;
  color: var(--warn);
  font-weight: 600;
}

.q-stem {
  font-size: 16.5px;
  font-weight: 500;
  line-height: 1.7;
  margin-bottom: 20px;
  color: var(--text);
}

.rich-content p {
  margin: 0 0 8px;
}

.rich-content p:last-child {
  margin-bottom: 0;
}

.rich-content img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 8px 0;
  border: 1px solid var(--border);
  display: block;
}

/* Options */
.q-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 16px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
  width: 100%;
  font-size: 15px;
  color: var(--text);
}

.option-item:hover:not(.locked) {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.option-item.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.option-item.correct {
  border-color: var(--success-border);
  background: var(--success-soft);
}

.option-item.wrong {
  border-color: var(--danger-border);
  background: var(--danger-soft);
}

.option-label {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
  background: var(--surface);
  color: var(--text-muted);
}

.option-item.selected .option-label {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.option-item.correct .option-label {
  border-color: var(--success);
  background: var(--success);
  color: #fff;
}

.option-item.wrong .option-label {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

.option-body {
  flex: 1;
  min-width: 0;
}

.option-pic {
  max-width: 100%;
  border-radius: 6px;
  margin-top: 6px;
  display: block;
}

.multi-submit-wrap {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
}

.primary-btn {
  border: none;
  background: var(--primary);
  color: #fff;
  border-radius: 8px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.primary-btn:hover {
  background: var(--primary-hover);
}

/* Feedback */
.q-feedback {
  margin-top: 22px;
  border-top: 1px solid var(--border);
  padding-top: 18px;
}

.feedback-banner {
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 12px;
}

.feedback-banner.correct {
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid var(--success-border);
}

.feedback-banner.wrong {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger-border);
}

.feedback-banner.study {
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid #bfdbfe;
}

.keypoint-box {
  display: inline-block;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 6px;
  margin-bottom: 10px;
}

.analyse-box {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 14px 16px;
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--text);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  max-width: 420px;
}

.empty-icon {
  font-size: 42px;
  margin-bottom: 12px;
}

.empty-state h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.empty-state p {
  margin-bottom: 18px;
}

/* Bottom Bar */
.bottom-bar {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.nav-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.nav-btn:hover:not(:disabled) {
  background: var(--surface-2);
}

.nav-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.nav-btn.primary-nav {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.nav-btn.primary-nav:hover:not(:disabled) {
  background: var(--primary-hover);
}

.shortcut-hint code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.modal-panel {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 640px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.2);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  margin: 0 0 2px;
  font-size: 16px;
}

.sheet-legend {
  display: flex;
  gap: 16px;
  padding: 10px 20px;
  font-size: 12.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.sheet-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
}

.dot-unanswered { background: var(--surface-2); border: 1px solid var(--border); }
.dot-correct { background: var(--success); }
.dot-wrong { background: var(--danger); }
.dot-current { background: #fff; border: 2px solid var(--primary); }

.sheet-grid {
  padding: 16px 20px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 8px;
}

.sheet-cell {
  height: 38px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.sheet-cell.correct {
  background: var(--success-soft);
  border-color: var(--success-border);
  color: var(--success);
}

.sheet-cell.wrong {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger);
}

.sheet-cell.current {
  box-shadow: 0 0 0 2px var(--primary);
}

.mobile-only {
  display: none;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  z-index: 25;
}

@media (max-width: 860px) {
  .mobile-only {
    display: inline-flex;
  }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .shortcut-hint {
    display: none;
  }
  .question-card {
    padding: 18px 16px;
  }
  .search-wrap input {
    width: 130px;
  }
}
