
:root {
  --bg: #f4f1eb;
  --surface: #fffaf3;
  --surface-2: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e6dccd;
  --accent: #6d4aff;
  --accent-2: #ede8ff;
  --shadow: 0 18px 48px rgba(31, 41, 55, 0.10);
  --radius: 22px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background: radial-gradient(circle at top left, #fff 0, var(--bg) 38%, #ede7db 100%);
  color: var(--text);
}
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 315px minmax(0, 1fr); grid-template-rows: auto 1fr; }
.topbar {
  grid-column: 1 / -1; position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 14px; padding: 14px 22px;
  border-bottom: 1px solid rgba(230, 220, 205, 0.9); background: rgba(255, 250, 243, 0.86); backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; cursor: pointer; }
.brand-mark { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; background: var(--text); color: white; font-weight: 800; }
.brand-title { font-weight: 800; line-height: 1.1; }
.brand-subtitle { color: var(--muted); font-size: 13px; margin-top: 2px; }
.sidebar { position: sticky; top: 71px; height: calc(100vh - 71px); padding: 22px; overflow: auto; border-right: 1px solid rgba(230, 220, 205, 0.85); background: rgba(255, 250, 243, 0.55); }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sidebar nav { display: grid; gap: 8px; }
.nav-link { width: 100%; text-align: left; display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid transparent; background: transparent; color: var(--text); padding: 12px 12px; border-radius: 16px; }
.nav-link:hover, .nav-link.active { background: var(--surface-2); border-color: var(--line); box-shadow: 0 8px 24px rgba(31,41,55,0.06); }
.nav-link.empty { color: var(--muted); }
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 28px; height: 24px; padding: 0 8px; border-radius: 999px; background: var(--accent-2); color: var(--accent); font-weight: 700; font-size: 12px; flex-shrink: 0; }
.sidebar-note { margin-top: 22px; color: var(--muted); font-size: 13px; line-height: 1.45; padding: 14px; border: 1px dashed var(--line); border-radius: 16px; background: rgba(255,255,255,0.5); }
.content { min-width: 0; padding: 28px; max-width: 1240px; width: 100%; margin: 0 auto; }
.hero { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 20px; align-items: stretch; padding: 28px; border-radius: var(--radius); background: linear-gradient(135deg, #1f2937 0%, #4c3db8 100%); color: white; box-shadow: var(--shadow); }
.hero h1 { margin: 6px 0 8px; font-size: clamp(28px, 5vw, 46px); letter-spacing: -0.04em; }
.hero p { margin: 0; max-width: 720px; color: rgba(255,255,255,0.78); line-height: 1.55; }
.hero .small-label { color: rgba(255,255,255,0.58); }
.hero-stat { min-width: 150px; display: grid; place-items: center; text-align: center; padding: 18px; border-radius: 20px; background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.18); }
.hero-stat span { display:block; font-size: 42px; font-weight: 850; line-height:1; }
.hero-stat small { color: rgba(255,255,255,0.7); }
.search-panel { margin: 18px 0; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(255,250,243,0.9); box-shadow: 0 10px 28px rgba(31,41,55,0.05); }
.search-panel label { display: block; font-weight: 760; margin-bottom: 10px; }
.search-row { display: flex; gap: 10px; }
.search-row input { width: 100%; border: 1px solid var(--line); border-radius: 16px; background: white; color: var(--text); padding: 14px 15px; outline: none; }
.search-row input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-2); }
.search-hint { margin-top: 8px; color: var(--muted); font-size: 13px; }
.primary-btn, .ghost-btn, .icon-btn { border: 0; border-radius: 15px; padding: 12px 16px; font-weight: 760; }
.primary-btn { background: var(--accent); color: white; }
.ghost-btn { background: white; color: var(--text); border: 1px solid var(--line); }
.icon-btn { background: white; color: var(--text); border: 1px solid var(--line); width: 42px; height: 42px; padding: 0; }
.mobile-only { display: none; }
.small-label { color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; }
.grid { display: grid; gap: 14px; }
.cards-grid { grid-template-columns: repeat(auto-fit, minmax(245px, 1fr)); }
.card { padding: 18px; border-radius: var(--radius); border: 1px solid var(--line); background: rgba(255, 250, 243, 0.92); box-shadow: 0 10px 28px rgba(31,41,55,0.05); }
.card h2, .card h3 { margin: 0 0 8px; letter-spacing: -0.02em; }
.card p { color: var(--muted); line-height: 1.5; margin: 0 0 14px; }
.block-card { min-height: 168px; display: flex; flex-direction: column; justify-content: space-between; }
.block-card.ready { border-color: rgba(109,74,255,0.25); }
.block-card.empty { opacity: 0.68; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.question-list { display: grid; gap: 12px; }
.question-card { display: grid; gap: 12px; }
.question-top { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.question-num { color: var(--accent); font-weight: 850; font-size: 13px; }
.question-title { font-weight: 800; font-size: 18px; line-height: 1.32; margin: 2px 0 0; }
.keyword-row { display: flex; flex-wrap: wrap; gap: 6px; }
.keyword { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; padding: 5px 9px; color: #4b5563; background: rgba(255,255,255,0.65); font-size: 12px; }
.fav-btn { border: 1px solid var(--line); background: white; border-radius: 999px; padding: 8px 11px; white-space: nowrap; color: var(--text); }
.fav-btn.active { background: #fff3bf; border-color: #f3d675; }
.breadcrumbs { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; color: var(--muted); font-size: 14px; }
.breadcrumbs button { border: 0; background: transparent; color: var(--accent); padding: 0; font-weight: 760; cursor: pointer; }
.answer-shell { padding: 0; overflow: hidden; }
.answer-head { padding: 22px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,0.55); }
.answer-head h2 { margin: 6px 0 12px; font-size: clamp(24px, 4vw, 36px); line-height: 1.15; letter-spacing: -0.03em; }
.answer-body { padding: 24px; line-height: 1.65; font-size: 16px; overflow-wrap: anywhere; }
.answer-body h1, .answer-body h2, .answer-body h3, .answer-body h4 { margin-top: 1.45em; line-height: 1.25; letter-spacing: -0.02em; }
.answer-body h1 { font-size: 1.55rem; }
.answer-body h2 { font-size: 1.35rem; }
.answer-body h3 { font-size: 1.15rem; }
.answer-body p { margin: 0 0 0.9em; color: var(--text); }
.answer-body ul, .answer-body ol { padding-left: 1.35em; }
.answer-body li { margin-bottom: 0.42em; }
.answer-body img { display: block; max-width: 100%; height: auto !important; margin: 16px auto; border-radius: 14px; border: 1px solid rgba(230,220,205,0.8); background: white; }
.table-wrap { width: 100%; overflow-x: auto; margin: 16px 0; border: 1px solid var(--line); border-radius: 14px; background: white; }
.answer-table { width: 100%; border-collapse: collapse; min-width: 620px; }
.answer-table td, .answer-table th { border: 1px solid var(--line); padding: 10px; vertical-align: top; }
.answer-table p { margin: 0; }
.source-box { margin-top: 22px; padding: 16px; border-radius: 16px; background: #f8fafc; border: 1px solid #e5e7eb; color: #4b5563; line-height: 1.55; }
.source-box strong { color: var(--text); }
.empty-state { text-align: center; padding: 32px; color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(20px); background: #111827; color: white; padding: 12px 16px; border-radius: 999px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: 0.2s ease; z-index: 80; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
mark { background: #fff3bf; border-radius: 4px; padding: 0 2px; }
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .mobile-only { display: inline-grid; place-items: center; }
  .topbar { padding: 12px; }
  .brand-subtitle { display: none; }
  .ghost-btn#homeBtn { display: none; }
  .sidebar { position: fixed; inset: 0 auto 0 0; top: 0; width: min(88vw, 350px); height: 100vh; z-index: 60; transform: translateX(-102%); transition: transform 0.22s ease; background: var(--surface); box-shadow: 30px 0 80px rgba(31,41,55,0.22); }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 16px; }
  .hero { grid-template-columns: 1fr; padding: 22px; }
  .hero-stat { min-width: 0; display: flex; justify-content: space-between; }
  .search-row { flex-direction: column; }
  .primary-btn, .ghost-btn { width: 100%; }
  .question-top { flex-direction: column; }
  .fav-btn { width: 100%; }
  .answer-body { padding: 18px; font-size: 15.5px; }
  .answer-head { padding: 18px; }
}
@media print {
  .topbar, .sidebar, .search-panel, .fav-btn, .card-actions { display: none !important; }
  .app-shell { display: block; }
  .content { max-width: none; padding: 0; }
  .card { box-shadow: none; border: 0; }
  body { background: white; }
}

/* Updates: question navigation, expandable sidebar questions, mobile formula scrolling */
.nav-block { display: grid; gap: 6px; }
.nav-block.active { padding: 4px; border-radius: 18px; background: rgba(255,255,255,0.44); border: 1px solid rgba(230,220,205,0.72); }
.nav-questions-toggle {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border: 1px solid var(--line); background: rgba(255,255,255,0.72); color: var(--muted);
  padding: 9px 11px; border-radius: 13px; font-size: 13px; font-weight: 760;
}
.nav-questions-toggle.open { color: var(--accent); background: var(--accent-2); border-color: rgba(109,74,255,0.25); }
.nav-question-list { display: none; gap: 6px; padding: 2px 0 8px 8px; }
.nav-question-list.open { display: grid; }
.nav-question-link {
  width: 100%; display: grid; grid-template-columns: 28px minmax(0, 1fr); align-items: start; gap: 8px;
  text-align: left; border: 1px solid transparent; background: transparent; color: var(--text);
  padding: 8px 9px; border-radius: 12px; font-size: 13px; line-height: 1.28;
}
.nav-question-link:hover, .nav-question-link.active { background: white; border-color: var(--line); box-shadow: 0 6px 18px rgba(31,41,55,0.06); }
.nav-question-link.active { color: var(--accent); font-weight: 760; }
.nav-question-num {
  display: inline-flex; align-items: center; justify-content: center; min-width: 24px; height: 22px;
  border-radius: 999px; background: var(--accent-2); color: var(--accent); font-weight: 850; font-size: 11px;
}
.question-nav-panel {
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 10px; align-items: center;
  padding: 14px 22px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,0.38);
}
.answer-body + .question-nav-panel { border-top: 1px solid var(--line); border-bottom: 0; }
.question-nav-btn { min-width: 0; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.question-nav-count { color: var(--muted); font-size: 13px; font-weight: 760; white-space: nowrap; }
.answer-shell { overflow: visible; }
.answer-body { max-width: 100%; overflow-x: hidden; overflow-wrap: break-word; }
.answer-body pre,
.answer-body code,
.answer-body .formula,
.answer-body .math,
.answer-body .equation {
  max-width: 100%; overflow-x: auto; white-space: pre; display: block;
}
.answer-body mjx-container {
  max-width: 100%; overflow-x: auto; overflow-y: hidden;
}
.answer-body mjx-container[display="true"] {
  display: block; padding: 8px 0 10px; margin: 8px 0;
}
.answer-body mjx-container[jax="SVG"] > svg {
  max-width: none !important;
}
.answer-body table {
  display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse;
}
@media (max-width: 860px) {
  .question-nav-panel { grid-template-columns: 1fr; padding: 12px 18px; }
  .question-nav-count { text-align: center; order: -1; }
  .question-nav-btn { white-space: normal; text-align: center; }
  .nav-question-list { padding-left: 0; }
}
