/* ============================================================
   CanBangHoaHoc.com — Design System
   Mobile-first, education-focused, clean & minimal
   ============================================================ */

:root {
  --bg: #faf9f7;
  --fg: #171412;
  --muted: #6b635c;
  --muted-2: #8a8079;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --accent-fg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f5f3f0;
  --line: #e8e5e1;
  --line-strong: #d4cfc8;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.08);
  --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, 'SF Mono', Consolas, monospace;
}

html.dark {
  --bg: #0f0f10;
  --fg: #f4f3f1;
  --muted: #a8a09a;
  --muted-2: #8a827c;
  --accent: #60a5fa;
  --accent-hover: #93c5fd;
  --accent-soft: rgba(96, 165, 250, 0.12);
  --accent-fg: #0f0f10;
  --surface: #1a1a1c;
  --surface-2: #232326;
  --line: #2a2a2e;
  --line-strong: #3a3a40;
  --ok: #4ade80;
  --ok-soft: rgba(74, 222, 128, 0.12);
  --bad: #f87171;
  --bad-soft: rgba(248, 113, 113, 0.12);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.12);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.4);
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.6;
  font-size: 16px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
img, svg, video { max-width: 100%; display: block; }
button { font: inherit; cursor: pointer; background: none; border: 0; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.container { width: 100%; max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.container-narrow { width: 100%; max-width: 720px; margin: 0 auto; padding: 0 16px; }
.container-tool { width: 100%; max-width: 720px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 768px) {
  .container, .container-narrow, .container-tool { padding: 0 24px; }
}

/* Typography */
h1, h2, h3, h4, h5, h6 { font-weight: 700; line-height: 1.25; letter-spacing: -0.01em; color: var(--fg); }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.5rem; margin-top: 2rem; margin-bottom: 0.75rem; }
h3 { font-size: 1.2rem; margin-top: 1.5rem; margin-bottom: 0.5rem; }
h4 { font-size: 1.05rem; margin-top: 1rem; margin-bottom: 0.5rem; }
@media (min-width: 768px) {
  h1 { font-size: 2.4rem; }
  h2 { font-size: 1.75rem; }
  h3 { font-size: 1.3rem; }
}
p { margin-bottom: 0.85rem; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.tiny { font-size: 0.78rem; }
.mono { font-family: var(--font-mono); }

/* Navbar */
.navbar {
  position: sticky; top: 0; z-index: 50;
  height: 56px;
  background: rgba(250, 249, 247, 0.85);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
html.dark .navbar { background: rgba(15, 15, 16, 0.85); }
.navbar-inner { display: flex; align-items: center; justify-content: space-between; height: 100%; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; color: var(--fg); text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--accent); color: var(--accent-fg);
  display: grid; place-items: center; font-weight: 800; font-size: 0.95rem;
  font-family: var(--font-mono);
}
.brand-text { font-size: 1rem; }
.brand-text .dot { color: var(--accent); }
.nav-links { display: none; align-items: center; gap: 20px; }
.nav-links a { color: var(--fg); font-size: 0.92rem; font-weight: 500; }
.nav-links a:hover { color: var(--accent); text-decoration: none; }
@media (min-width: 900px) { .nav-links { display: flex; } }
.nav-actions { display: flex; align-items: center; gap: 8px; }
.nav-icon-btn {
  width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center;
  color: var(--muted); border: 1px solid transparent;
  transition: all 0.15s;
}
.nav-icon-btn:hover { background: var(--surface-2); color: var(--fg); }
.menu-btn { display: grid; }
@media (min-width: 900px) { .menu-btn { display: none; } }

/* Mobile drawer */
.drawer {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,0.4); display: none;
}
.drawer.open { display: block; }
.drawer-panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: 84%; max-width: 320px;
  background: var(--bg); padding: 16px;
  display: flex; flex-direction: column; gap: 4px;
  border-left: 1px solid var(--line);
}
.drawer-panel a {
  display: block; padding: 12px 14px; border-radius: 10px;
  color: var(--fg); font-weight: 500; font-size: 0.95rem;
}
.drawer-panel a:hover { background: var(--surface-2); text-decoration: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 0 12px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.drawer-section { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); padding: 12px 14px 4px; }

/* Hero */
.hero { padding: 32px 0 16px; }
@media (min-width: 768px) { .hero { padding: 56px 0 24px; } }
.hero h1 { letter-spacing: -0.02em; }
.hero-sub { color: var(--muted); font-size: 1.05rem; margin-top: 8px; max-width: 560px; }

/* Balancer input */
.balancer { margin-top: 20px; }
.balancer-row {
  display: flex; gap: 8px; align-items: stretch;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 6px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.balancer-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.balancer-input {
  flex: 1; min-width: 0;
  height: 48px;
  padding: 0 12px;
  font-family: var(--font-mono);
  font-size: 1.05rem;
  background: transparent;
  border: 0; outline: 0;
  color: var(--fg);
}
.balancer-input::placeholder { color: var(--muted-2); }
.balancer-btn {
  height: 48px;
  padding: 0 22px;
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 1rem;
  display: inline-flex; align-items: center; gap: 8px;
  transition: background 0.15s, transform 0.05s;
}
.balancer-btn:hover { background: var(--accent-hover); }
.balancer-btn:active { transform: scale(0.98); }
.balancer-btn:disabled { opacity: 0.6; cursor: not-allowed; }
@media (max-width: 480px) {
  .balancer-row { flex-direction: column; padding: 8px; }
  .balancer-input { height: 52px; font-size: 1rem; }
  .balancer-btn { width: 100%; height: 48px; }
}

/* Example chips */
.examples { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.examples-label { font-size: 0.86rem; color: var(--muted); margin-right: 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--font-mono); font-size: 0.85rem;
  color: var(--fg); cursor: pointer;
  transition: all 0.15s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

/* Result cards */
.result-stack { display: flex; flex-direction: column; gap: 14px; margin-top: 24px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
@media (min-width: 640px) { .card { padding: 22px; } }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 12px;
}
.card-title {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 1rem; color: var(--fg);
}
.card-title-icon {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-size: 0.85rem; font-weight: 700;
}

/* Equation display */
.equation {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  line-height: 1.8;
  word-break: break-word;
  overflow-wrap: anywhere;
}
@media (min-width: 640px) { .equation { font-size: 1.4rem; } }
.equation .coef { color: var(--accent); font-weight: 700; }
.equation .plus { color: var(--muted); margin: 0 0.45em; }
.equation .arrow { color: var(--muted); margin: 0 0.55em; position: relative; }
.equation .state { color: var(--muted-2); font-size: 0.78em; margin-left: 2px; }
.equation sub { font-size: 0.7em; line-height: 0; }
.equation sup { font-size: 0.7em; line-height: 0; }
.equation .cond {
  display: inline-block;
  font-size: 0.7em;
  color: var(--muted);
  vertical-align: super;
  margin: 0 4px;
  font-style: italic;
}

/* Step list */
.steps { display: flex; flex-direction: column; gap: 14px; }
.step { display: flex; gap: 12px; align-items: flex-start; }
.step-num {
  flex-shrink: 0;
  width: 28px; height: 28px; border-radius: 999px;
  background: var(--accent); color: var(--accent-fg);
  display: grid; place-items: center;
  font-weight: 700; font-size: 0.85rem;
}
.step-body { flex: 1; min-width: 0; }
.step-body p { margin-bottom: 6px; }
.step-eq { font-family: var(--font-mono); background: var(--surface-2); padding: 8px 12px; border-radius: var(--radius-sm); display: inline-block; margin-top: 4px; font-size: 0.95rem; }

/* Atom table */
.table-wrap { overflow-x: auto; margin: 8px 0; }
.atom-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.atom-table th, .atom-table td {
  padding: 8px 10px; text-align: left;
  border-bottom: 1px solid var(--line);
}
.atom-table th { font-weight: 600; color: var(--muted); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.04em; }
.atom-table td.num { font-family: var(--font-mono); text-align: center; }
.atom-table td.sym { font-family: var(--font-mono); font-weight: 700; }
.atom-table tr:last-child td { border-bottom: 0; }
.ok-mark { color: var(--ok); font-weight: 700; }
.bad-mark { color: var(--bad); font-weight: 700; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-muted { background: var(--surface-2); color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem; font-weight: 600;
  background: var(--surface-2); color: var(--fg);
  border: 1px solid var(--line);
  transition: all 0.15s;
}
.btn:hover { background: var(--line); text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { height: 32px; padding: 0 10px; font-size: 0.82rem; }

/* Error message */
.error-box {
  background: var(--bad-soft);
  border: 1px solid var(--bad);
  color: var(--fg);
  padding: 14px 16px;
  border-radius: var(--radius);
  display: flex; gap: 12px; align-items: flex-start;
  margin-top: 16px;
}
.error-box .err-icon { color: var(--bad); flex-shrink: 0; margin-top: 2px; }
.error-box strong { color: var(--bad); display: block; margin-bottom: 4px; }

/* Loading */
.loading {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Sections */
section { padding: 32px 0; }
@media (min-width: 768px) { section { padding: 48px 0; } }
.section-title { text-align: center; margin-bottom: 8px; }
.section-sub { text-align: center; color: var(--muted); margin-bottom: 28px; max-width: 600px; margin-left: auto; margin-right: auto; }

/* Feature grid */
.feature-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 640px) { .feature-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 960px) { .feature-grid { grid-template-columns: repeat(4, 1fr); } }
.feature-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  transition: all 0.2s;
}
.feature-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
.feature-icon {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center;
  margin-bottom: 12px;
}
.feature-card h3 { font-size: 1.05rem; margin: 0 0 6px; }
.feature-card p { font-size: 0.9rem; color: var(--muted); margin: 0; line-height: 1.55; }

/* How steps */
.how-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 768px) { .how-grid { grid-template-columns: repeat(3, 1fr); } }
.how-step { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; position: relative; }
.how-step-num {
  position: absolute; top: -14px; left: 22px;
  width: 32px; height: 32px; border-radius: 999px;
  background: var(--accent); color: var(--accent-fg);
  display: grid; place-items: center;
  font-weight: 800; font-size: 0.95rem;
  box-shadow: var(--shadow);
}
.how-step h3 { margin: 6px 0 8px; font-size: 1.05rem; }
.how-step p { color: var(--muted); font-size: 0.92rem; margin: 0; }

/* Equation list grid */
.eq-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 640px) { .eq-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 960px) { .eq-grid { grid-template-columns: repeat(3, 1fr); } }
.eq-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: block;
  transition: all 0.15s;
  color: var(--fg);
}
.eq-card:hover { border-color: var(--accent); text-decoration: none; background: var(--accent-soft); }
.eq-card .label { font-size: 0.78rem; color: var(--muted); margin-bottom: 4px; }
.eq-card .formula { font-family: var(--font-mono); font-size: 0.95rem; }

/* FAQ */
.faq { display: flex; flex-direction: column; gap: 10px; }
.faq-item {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); overflow: hidden;
}
.faq-item summary {
  list-style: none; cursor: pointer;
  padding: 14px 16px;
  font-weight: 600; font-size: 0.98rem;
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after { content: "+"; font-size: 1.4rem; font-weight: 400; color: var(--muted); transition: transform 0.2s; }
.faq-item[open] summary::after { content: "−"; }
.faq-item .answer { padding: 0 16px 14px; color: var(--muted); font-size: 0.94rem; line-height: 1.65; }
.faq-item .answer p { margin-bottom: 8px; }
.faq-item .answer p:last-child { margin-bottom: 0; }

/* Breadcrumb */
.crumbs { font-size: 0.85rem; color: var(--muted); padding: 12px 0; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--accent); }
.crumbs .sep { color: var(--muted-2); }

/* Footer */
.footer { background: var(--surface-2); border-top: 1px solid var(--line); padding: 36px 0 20px; margin-top: 48px; }
.footer-grid { display: grid; grid-template-columns: 1fr; gap: 24px; margin-bottom: 24px; }
@media (min-width: 640px) { .footer-grid { grid-template-columns: 2fr 1fr 1fr 1fr; gap: 32px; } }
.footer-col h4 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 12px; }
.footer-col ul { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.footer-col a { color: var(--fg); font-size: 0.9rem; }
.footer-col a:hover { color: var(--accent); }
.footer-about { color: var(--muted); font-size: 0.9rem; line-height: 1.6; }
.footer-bottom { border-top: 1px solid var(--line); padding-top: 16px; font-size: 0.85rem; color: var(--muted); text-align: center; }

/* Article styling */
.prose { max-width: 720px; }
.prose h2 { margin-top: 2rem; }
.prose h3 { margin-top: 1.5rem; }
.prose p { margin-bottom: 1rem; line-height: 1.75; color: var(--fg); }
.prose ul, .prose ol { margin: 0.5rem 0 1rem 1.5rem; }
.prose ul li, .prose ol li { margin-bottom: 0.4rem; line-height: 1.7; }
.prose strong { font-weight: 700; }
.prose blockquote { border-left: 4px solid var(--accent); padding: 4px 0 4px 16px; margin: 16px 0; color: var(--muted); font-style: italic; }
.prose code { font-family: var(--font-mono); background: var(--surface-2); padding: 2px 6px; border-radius: 4px; font-size: 0.9em; }
.prose .callout {
  background: var(--accent-soft); border-left: 4px solid var(--accent);
  padding: 14px 16px; border-radius: var(--radius-sm);
  margin: 18px 0;
}
.prose .callout strong { color: var(--accent); }

/* Copy state */
.copied { background: var(--ok) !important; color: white !important; border-color: var(--ok) !important; }

/* Utility */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mt-8 { margin-top: 32px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.text-center { text-align: center; }
.hidden { display: none; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
