:root {
  --bg: #0c1118;
  --bg-elevated: #141c27;
  --bg-card: #1a2433;
  --border: #2a3544;
  --text: #e8edf4;
  --text-muted: #8b9cb3;
  --accent: #3b9eff;
  --accent-dim: #2563a8;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", monospace;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.hidden { display: none !important; }

/* Loading */
.loading-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 100;
}

.loading-card {
  text-align: center;
  color: var(--text-muted);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 24px;
  background: rgba(12, 17, 24, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.logo {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  border-radius: 10px;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: -0.5px;
}

.header h1 {
  font-size: 1.15rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 220px;
}

.search-box svg { color: var(--text-muted); flex-shrink: 0; }

.search-box input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  outline: none;
  min-width: 0;
}

.search-box input::placeholder { color: var(--text-muted); }

.mode-toggle {
  display: flex;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.mode-btn {
  padding: 8px 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.mode-btn.active {
  background: var(--accent);
  color: #fff;
}

.mode-btn:not(.active):hover {
  color: var(--text);
  background: var(--bg-card);
}

/* Layout */
.layout {
  display: flex;
  min-height: calc(100vh - 77px);
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  position: sticky;
  top: 77px;
  height: calc(100vh - 77px);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.chapter-nav { padding: 0 10px 20px; }

.chapter-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 2px;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.88rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.chapter-btn:hover {
  background: var(--bg-card);
  color: var(--text);
}

.chapter-btn.active {
  background: rgba(59, 158, 255, 0.15);
  color: var(--accent);
  font-weight: 500;
}

.chapter-count {
  font-size: 0.75rem;
  font-family: var(--mono);
  opacity: 0.7;
}

/* Main */
.main {
  flex: 1;
  min-width: 0;
  padding: 0 24px 40px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 0 16px;
  flex-wrap: wrap;
  position: sticky;
  top: 77px;
  background: var(--bg);
  z-index: 10;
}

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

.toolbar-info h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.stats-badge {
  font-size: 0.78rem;
  font-family: var(--mono);
  padding: 3px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
}

.toolbar-filters {
  display: flex;
  gap: 14px;
}

.filter-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
}

.filter-check input { accent-color: var(--accent); }

.icon-btn {
  display: none;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}

/* Questions */
.question-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.question-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}

.question-card:hover { border-color: var(--accent-dim); }

.q-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.q-number {
  flex-shrink: 0;
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 4px 10px;
  background: var(--bg-elevated);
  border-radius: 6px;
  color: var(--accent);
}

.q-stem {
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.55;
  flex: 1;
}

.q-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.tag {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 4px;
  font-family: var(--mono);
}

.tag-page { background: rgba(139, 156, 179, 0.15); color: var(--text-muted); }
.tag-answer { background: rgba(52, 211, 153, 0.15); color: var(--success); }
.tag-fcom { background: rgba(59, 158, 255, 0.15); color: var(--accent); }
.tag-missing { background: rgba(248, 113, 113, 0.15); color: var(--danger); }

.options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 0.92rem;
  cursor: default;
  transition: border-color 0.15s, background 0.15s;
}

.practice-mode .option {
  cursor: pointer;
}

.practice-mode .option:hover {
  border-color: var(--border);
  background: var(--bg);
}

.option.correct {
  border-color: var(--success);
  background: rgba(52, 211, 153, 0.08);
}

.option.wrong {
  border-color: var(--danger);
  background: rgba(248, 113, 113, 0.08);
}

.option-key {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 500;
}

.option.correct .option-key {
  background: var(--success);
  color: #0c1118;
}

.explanation {
  padding: 14px 16px;
  background: var(--bg-elevated);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.65;
}

.explanation strong { color: var(--text); }

.explanation.hidden-block { display: none; }

.reveal-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.reveal-btn:hover { background: var(--accent-dim); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.mobile-only { display: none; }

@media (max-width: 900px) {
  .header {
    flex-direction: column;
    align-items: stretch;
    padding: 14px 16px;
  }

  .header-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .search-box { min-width: 0; }

  .mode-toggle { justify-content: center; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow);
  }

  .sidebar.open { transform: translateX(0); }

  .mobile-only { display: flex; }

  .main { padding: 0 16px 32px; }

  .toolbar { top: 0; }
}