/* KhmerChem: shared look for every page */
:root {
  --brand: #2E52AD;
  --brand-2: #1F3C86;
  --brand-soft: #E9EEFB;
  --accent: #F5B800;
  --green: #2EA052;
  --red: #D9534F;
  --bg: #F5F7FC;
  --card: #FFFFFF;
  --ink: #1C2340;
  --muted: #5B6680;
  --line: #E1E6F0;
  --radius: 16px;
  --shadow: 0 6px 24px rgba(28, 35, 64, .07);
  --font: 'Kantumruy Pro', 'Khmer OS Battambang', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
[data-theme="dark"] {
  --bg: #11162A; --card: #1A2140; --ink: #E8ECF8; --muted: #9AA5C4; --line: #2A3358; --brand-soft: #22305E; --shadow: none;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--ink); line-height: 1.75; font-size: 16px; }
a { color: var(--brand); }
[data-theme="dark"] a { color: #8FB0FF; }
img { max-width: 100%; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 18px; }

/* Header */
.top { position: sticky; top: 0; z-index: 20; background: var(--card); border-bottom: 1px solid var(--line); }
.top .wrap { display: flex; align-items: center; gap: 14px; height: 64px; }
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; font-size: 18px; white-space: nowrap; }
.logo img { width: 38px; height: 38px; border-radius: 50%; }
.logo small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); line-height: 1.2; }
.nav { display: flex; gap: 4px; margin-left: auto; }
.nav a { padding: 8px 12px; border-radius: 10px; text-decoration: none; color: var(--ink); font-size: 15px; }
.nav a:hover, .nav a.on { background: var(--brand-soft); color: var(--brand); }
.icon-btn { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 10px; width: 40px; height: 40px; cursor: pointer; font-size: 18px; }
.menu-btn { display: none; }
@media (max-width: 860px) {
  .nav { display: none; position: absolute; top: 64px; left: 0; right: 0; flex-direction: column; background: var(--card); border-bottom: 1px solid var(--line); padding: 8px 18px 14px; }
  .nav.open { display: flex; }
  .menu-btn { display: inline-block; margin-left: auto; }
}

/* Generic blocks */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; border-radius: 12px; border: 1px solid var(--brand); background: var(--card); color: var(--brand); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--brand); color: #fff; }
.btn:disabled { opacity: .45; cursor: default; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 18px; }
.pill { display: inline-block; padding: 2px 12px; border-radius: 99px; background: var(--brand-soft); color: var(--brand); font-size: 13px; font-weight: 600; }
.muted { color: var(--muted); }
h1, h2, h3 { line-height: 1.4; }
.crumb { font-size: 14px; color: var(--muted); margin: 18px 0 6px; }
.crumb a { text-decoration: none; }

/* Footer */
.foot { margin-top: 56px; padding: 28px 0; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.foot .wrap { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; }

/* Lesson */
.lesson { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 28px; align-items: start; }
.toc { position: sticky; top: 84px; }
.toc b { display: block; margin-bottom: 6px; }
.toc a { display: block; padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--muted); font-size: 15px; }
.toc a:hover { background: var(--brand-soft); color: var(--brand); }
@media (max-width: 860px) { .lesson { grid-template-columns: 1fr; } .toc { position: static; } }
.box { border-radius: 14px; padding: 14px 18px; margin: 14px 0; border-left: 5px solid; }
.box.def { background: #EEF3FF; border-color: var(--brand); }
.box.rule { background: #FFF7DC; border-color: var(--accent); }
.box.ex { background: #EAF7EE; border-color: var(--green); }
.box.warn { background: #FDECEC; border-color: var(--red); }
[data-theme="dark"] .box { background: var(--brand-soft); }
.box > b:first-child { display: block; margin-bottom: 4px; }
table.t { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 15px; }
table.t th, table.t td { border: 1px solid var(--line); padding: 8px 10px; text-align: center; }
table.t th { background: var(--brand-soft); }

/* Inline quiz */
.quiz { margin: 18px 0; }
.q { border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 14px; background: var(--card); }
.q .opts { display: grid; gap: 8px; margin-top: 10px; }
.q .opt { text-align: left; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; cursor: pointer; }
.q .opt:hover { border-color: var(--brand); }
.q .opt.right { background: #E3F4E8; border-color: var(--green); color: #14532d; }
.q .opt.wrong { background: #FDE6E6; border-color: var(--red); color: #7f1d1d; }
.q .fb { margin-top: 10px; font-size: 15px; }
.q .fb[hidden] { display: none; }

/* Experiment stage */
.stage { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 860px) { .stage { grid-template-columns: 1fr; } }
.stage svg { width: 100%; height: auto; display: block; background: linear-gradient(#FBFCFF, #EEF2FA); border-radius: 14px; border: 1px solid var(--line); }
.steps-list { counter-reset: s; padding: 0; list-style: none; margin: 0; }
.steps-list li { padding: 8px 10px 8px 40px; position: relative; border-radius: 10px; color: var(--muted); }
.steps-list li::before { counter-increment: s; content: counter(s); position: absolute; left: 8px; top: 9px; width: 24px; height: 24px; border-radius: 50%; background: var(--line); color: var(--ink); font-size: 13px; display: grid; place-items: center; }
.steps-list li.on { background: var(--brand-soft); color: var(--ink); font-weight: 600; }
.steps-list li.on::before { background: var(--brand); color: #fff; }
.steps-list li.done::before { background: var(--green); color: #fff; }
.controls { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.eq { font-size: 20px; text-align: center; padding: 12px; border-radius: 12px; background: var(--brand-soft); margin: 12px 0; }
