/* Bilingual Math Olympiad Books (Primary 1-8) — matches site.css light & dark tokens */
.ob-shell { max-width: 1040px; margin: 0 auto; }
.ob-hero {
  background: linear-gradient(135deg, var(--ob-h1, #2a1659) 0%, var(--ob-h2, #4b2a9c) 55%, var(--ob-h3, #0e7490) 100%);
  color: #fff; padding: 28px 26px; border-radius: 18px; margin-bottom: 18px;
  box-shadow: var(--shadow);
}
body.ob-book-p12, body.ob-book-p12 .kb-paper { --col1: #047857; --cyan: #34d399; --ob-h1: #064e3b; --ob-h2: #047857; --ob-h3: #10b981; }
body.ob-book-p23, body.ob-book-p23 .kb-paper { --col1: #1d4ed8; --cyan: #60a5fa; --ob-h1: #172554; --ob-h2: #1e40af; --ob-h3: #3b82f6; }
body.ob-book-p34, body.ob-book-p34 .kb-paper { --col1: #6d28d9; --cyan: #a78bfa; --ob-h1: #2e1065; --ob-h2: #5b21b6; --ob-h3: #8b5cf6; }
body.ob-book-p56, body.ob-book-p56 .kb-paper { --col1: #be123c; --cyan: #fb7185; --ob-h1: #4c0519; --ob-h2: #9f1239; --ob-h3: #f43f5e; }
body.ob-book-p78, body.ob-book-p78 .kb-paper { --col1: #0e7490; --cyan: #22d3ee; --ob-h1: #083344; --ob-h2: #0e7490; --ob-h3: #06b6d4; }
body[class*="ob-book-"] .kb-actions .btn-primary { background: var(--col1); border-color: var(--col1); }
body[class*="ob-book-"] .kb-actions .btn-outline-teal { border-color: color-mix(in srgb, var(--col1) 40%, #fff); color: var(--col1); }
body[class*="ob-book-"] .kb-stats li { background: color-mix(in srgb, var(--col1) 9%, #ffffff); }
body[class*="ob-book-"] .kb-toc-h::before { background: linear-gradient(90deg, transparent, var(--cyan)); }
body[class*="ob-book-"] .kb-toc-h::after { background: linear-gradient(90deg, var(--cyan), transparent); }
body[class*="ob-book-"] .toc-sub-en,
body[class*="ob-book-"] .kb-sol-banner .ob-ch-card b { color: var(--col1); }
body[class*="ob-book-"] .kb-sol-banner .ob-ch-num { background: linear-gradient(135deg, var(--cyan), var(--col1)); }
body[class*="ob-book-"] .ob-sec-h { border-left-color: var(--col1); background: color-mix(in srgb, var(--col1) 10%, var(--surface)); }
body[class*="ob-book-"] .ob-sec-h .km-t { color: var(--col1); }
.ob-hero .ob-badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px;
  border-radius: 999px; background: rgba(255,255,255,.16); font-size: 13px; font-weight: 700; margin-bottom: 10px;
}
.ob-hero h1 { color: #fff; font-size: clamp(22px, 3vw, 31px); margin: 0 0 6px; line-height: 1.4; }
.ob-hero .ob-sub { color: rgba(255,255,255,.9); font-size: 15.5px; margin: 0 0 14px; line-height: 1.7; }
.ob-hero-acts { display: flex; flex-wrap: wrap; gap: 8px; }
.ob-hero-acts .btn-ghost { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.32); }
.ob-hero-acts .btn-ghost:hover { background: rgba(255,255,255,.22); border-color: #fff; color: #fff; }

.ob-bar {
  position: sticky; top: calc(var(--header-h) + 6px); z-index: 25;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; margin: 14px 0 20px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
}
.ob-lang-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.ob-ltab {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line-2);
  background: var(--bg); color: var(--ink-2); font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer;
}
.ob-ltab:hover { border-color: var(--primary); color: var(--primary); }
.ob-ltab.on { background: var(--primary); border-color: var(--primary); color: #fff; }
:root[data-theme="dark"] .ob-ltab.on { color: #160f2c; }
.ob-bar-right { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

/* Language mode visibility */
html[data-ob-lang="km"] .en-t,
html[data-ob-lang="km"] .bi-sep,
html[data-ob-lang="km"] .ob-sub-bi { display: none !important; }
html[data-ob-lang="en"] .km-t,
html[data-ob-lang="en"] .bi-sep,
html[data-ob-lang="en"] .ob-sub-bi,
html[data-ob-lang="en"] .kb-en { display: none !important; }
html:not([data-ob-lang="en"]) .ob-hero h1 .en-t { display: none !important; }

/* Inline bilingual label tokens inside headings, buttons, badges, stats */
span.km-t, span.en-t {
  display: inline; color: inherit; line-height: inherit; font-size: inherit;
  padding: 0; margin: 0; background: none; border: 0; border-radius: 0;
}
.toc-t span.km-t, .toc-t span.en-t { display: flex; flex-direction: column; align-items: center; }
.km-t .kitem .en-t, .km-t .ob-task-badge .en-t,
.en-t .kitem .km-t, .en-t .ob-task-badge .km-t,
html:not([data-ob-lang="en"]) .bi-univ .kitem .en-t,
html:not([data-ob-lang="en"]) .bi-univ .ob-task-badge .en-t { display: none !important; }

/* Bilingual pairing (block content) */
.bi-block { display: flex; flex-direction: column; gap: 10px; }
div.km-t, div.bi-univ { color: var(--ink); line-height: 1.85; }
div.en-t, p.en-t {
  color: var(--ink-2); line-height: 1.72; font-size: 15.8px;
  padding: 10px 14px; border-radius: 10px;
  background: var(--surface-2); border-left: 3px solid var(--gold);
}
html[data-ob-lang="en"] div.en-t,
html[data-ob-lang="en"] p.en-t {
  color: var(--ink); font-size: 16.5px; padding: 0; background: none; border-left: 0;
}

.ob-sec-h {
  margin: 26px 0 14px; padding: 10px 16px; border-left: 5px solid var(--primary);
  border-radius: 0 12px 12px 0; background: var(--primary-soft);
}
.ob-sec-h .km-t { font-weight: 800; font-size: 19px; color: var(--primary); }
.ob-sec-h .en-t { padding: 2px 0 0; border: 0; background: none; font-weight: 700; font-size: 15.5px; color: var(--ink-2); }

.ob-prose { margin: 14px 0; padding: 14px 18px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }

.ob-ex, .ob-pr, .ob-box {
  margin: 18px 0; padding: 18px 20px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
  overflow-x: auto; max-width: 100%;
}
.ob-shell .katex-display { overflow-x: auto; overflow-y: hidden; max-width: 100%; padding: 2px 0; }
.ob-ex { border-left: 5px solid #2b5db8; }
.ob-pr { border-left: 5px solid #1f8a5b; }
.ob-box { border-left: 5px solid var(--gold); background: color-mix(in srgb, var(--gold-soft) 35%, var(--surface)); }
.ob-card-h {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-bottom: 10px; font-weight: 800; font-size: 16px;
}
.ob-ex .ob-card-h { color: #1d4f9c; }
.ob-pr .ob-card-h { color: #157347; }
.ob-box .ob-card-h { color: var(--gold-strong); }
:root[data-theme="dark"] .ob-ex .ob-card-h { color: #7fa6ec; }
:root[data-theme="dark"] .ob-pr .ob-card-h { color: #5fcf9a; }

.ob-ans {
  margin-top: 12px; padding: 12px 16px; border-radius: 12px;
  background: var(--blue-soft); border: 1px solid color-mix(in srgb, var(--blue) 28%, transparent);
}
.ob-ans-lbl { font-weight: 800; font-size: 14px; color: var(--blue); margin-bottom: 6px; }
.ob-explain {
  margin-top: 12px; padding: 12px 15px; border-radius: 10px;
  background: color-mix(in srgb, var(--primary-soft) 55%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--primary) 24%, transparent);
}
.ob-explain-h { font-weight: 800; font-size: 14px; color: var(--primary); margin-bottom: 6px; }

details.qsol {
  margin-top: 12px; border: 1px solid color-mix(in srgb, var(--primary) 26%, transparent);
  border-radius: 12px; background: var(--surface-2);
}
details.qsol > summary {
  cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px;
  padding: 9px 14px; font-weight: 700; font-size: 14.5px; color: var(--primary);
}
details.qsol > summary::-webkit-details-marker { display: none; }
details.qsol > summary .qa { margin-left: auto; transition: transform .18s; }
details.qsol[open] > summary .qa { transform: rotate(180deg); }
.qsolbody { padding: 12px 16px 14px; background: var(--surface); border-top: 1px dashed var(--line-2); border-radius: 0 0 12px 12px; }

/* Figures, mini-grids, tables, options */
.ob-fig { margin: 12px auto; text-align: center; }
.ob-fig img, .ob-img {
  display: inline-block; max-width: 100%; height: auto; border-radius: 8px;
  background: #fff; padding: 4px;
}
.ob-img-inline { display: inline-block; vertical-align: middle; max-height: 150px; width: auto; background: #fff; border-radius: 6px; padding: 2px; }
.ob-grid-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px; margin: 10px 0; align-items: start;
}
.ob-grid-cell {
  text-align: center; padding: 8px; border-radius: 10px;
  background: var(--bg); border: 1px solid var(--line);
}
.tbl-wrap { overflow-x: auto; margin: 10px 0; }
.ob-tbl { border-collapse: collapse; margin: 0 auto; font-size: 15px; background: var(--surface); }
.ob-tbl td, .ob-tbl th { border: 1px solid var(--line-2); padding: 6px 10px; text-align: center; vertical-align: middle; }
.ob-tbl.no-border td { border: 0; text-align: left; }

.ob-tasks, .ob-enum, .ob-list { margin: 8px 0; padding-left: 22px; }
.ob-tasks { display: grid; gap: 6px 14px; list-style: none; padding-left: 0; }
.ob-tasks.cols-2 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.ob-tasks.cols-3 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.ob-tasks.cols-4 { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.ob-task-li { display: flex; align-items: flex-start; gap: 8px; }
.ob-task-badge {
  display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 5px;
  border-radius: 6px; background: #7cb342; color: #fff; font-weight: 700; font-size: 13px; flex: none; margin-top: 3px;
}
.kitem {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 5px;
  border-radius: 5px; background: #7fb03c; color: #fff; font-weight: 700; font-size: 13px; margin-right: 4px; vertical-align: baseline;
}
.ob-box-num { display: inline-block; padding: 1px 7px; border: 1.5px solid var(--ink-2); border-radius: 4px; font-weight: 700; }
.ob-blank { display: inline-block; min-width: 58px; border-bottom: 1.8px solid var(--ink-2); height: 1.1em; vertical-align: baseline; }

.ob-toc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; margin: 18px 0; }
.ob-ch-card {
  display: flex; gap: 12px; align-items: flex-start; padding: 16px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: inherit;
  box-shadow: var(--shadow-sm); transition: border-color .15s, transform .15s, box-shadow .15s;
}
.ob-ch-card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: var(--shadow); }
.ob-ch-num {
  display: grid; place-items: center; width: 38px; height: 38px; flex: none;
  border-radius: 10px; background: var(--primary-soft); color: var(--primary); font-weight: 800; font-size: 16px;
}
.ob-ch-card b { display: block; font-size: 15.5px; line-height: 1.5; color: var(--ink); }
.ob-ch-card small { display: block; font-size: 13.5px; color: var(--ink-3); margin-top: 2px; line-height: 1.45; }

.ob-pager { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; margin: 28px 0 8px; }

/* Digital-book hub layout (matches books-digital / digital/g7/index.html) */
.kb-paper {
  --col1: #0c6662; --cyan: #3fc8f4;
  --kt-title: "Moul", "Khmer OS Muol Light", "Kantumruy Pro", serif;
  --kt-body: "Kantumruy Pro", "Siemreap", sans-serif;
  position: relative; padding: 26px 34px 32px; overflow: hidden;
  background: #fff; color: #1b1b1b;
  border: 1px solid var(--line); border-radius: var(--radius);
  border-right: 14px solid var(--cyan); box-shadow: var(--shadow-sm);
  font-family: var(--kt-body);
}
.kb-intro {
  display: grid; grid-template-columns: minmax(200px, 315px) 1fr;
  gap: 30px; align-items: center; margin: 4px 0 26px;
}
.kb-cov-f {
  position: relative; width: 100%; aspect-ratio: 697 / 891;
  padding: 8.65% 7.90% 6.30% 8.35%;
  filter: drop-shadow(0 10px 18px rgba(80, 50, 10, .22));
}
.kb-cov-f::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: url(../img/khmer/frame-cover-kh.png?v=1) center / 100% 100% no-repeat;
}
.kb-cov-f .kb-cov {
  display: block; width: 100%; height: 100%; object-fit: cover;
  border-radius: 0; box-shadow: none;
}
.kb-intro .kb-info {
  border: 46px solid transparent;
  border-image: url(../img/khmer/frame-info.png) 80 stretch;
  padding: 0 8px;
}
.kb-kick { margin: 0 0 2px; color: #b3171b; font-weight: 700; font-size: 13.5px; letter-spacing: .02em; }
.kb-info h1 {
  margin: 2px 0 4px; color: var(--col1);
  font: 400 clamp(22px, 3vw, 31px)/1.55 var(--kt-title);
}
.kb-info h1::after { display: none; }
.kb-en {
  margin: 0 0 10px; color: #555; letter-spacing: .16em;
  font: 700 13.5px/1.5 Georgia, serif; text-transform: uppercase;
}
.kb-desc-km { margin: 0 0 6px; font-size: 15px; line-height: 1.75; color: #1b1b1b; }
.kb-info p.en-t {
  padding: 6px 10px; margin: 0 0 4px; font-size: 14px; line-height: 1.55;
  color: #3d4852; background: #f8fafc; border-left: 3px solid #c58a12; border-radius: 6px;
}
html[data-ob-lang="en"] .kb-info p.en-t {
  color: #1b1b1b; font-size: 15px; padding: 0; background: none; border-left: 0;
}
.kb-stats { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0; padding: 0; list-style: none; }
.kb-stats li {
  display: flex; flex-direction: column; align-items: center; min-width: 92px;
  padding: 8px 13px; border-radius: 12px; background: #eef7f6; color: #444; font-size: 13.5px;
}
.kb-stats b { color: var(--col1); font: 400 21px/1.4 var(--kt-title); }
.kb-by { margin: 6px 0 14px; font-size: 15px; color: #1b1b1b; }
.kb-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.kb-actions .btn-primary, .kb-actions .btn-primary:hover { color: #fff; }
.kb-actions .btn-outline-teal {
  background: #fff; border: 1px solid #9cc7c3; color: #0c6662;
}
.kb-actions .btn-outline-teal:hover {
  background: #eef7f6; border-color: #0c6662; color: #0c6662;
}

.kb-hub-bar { margin: 8px 0 18px; position: static; }

.kb-toc-h {
  display: flex; align-items: center; gap: 14px; margin: 12px 0 18px;
  color: var(--col1); font: 400 28px/1.6 var(--kt-title);
}
.kb-toc-h .en-t, .kb-info h1 .en-t { font-family: var(--kt-body); font-weight: 800; line-height: 1.35; }
.kb-toc-h::before, .kb-toc-h::after {
  content: ""; flex: 1; height: 2px; background: linear-gradient(90deg, transparent, #9cc7c3);
}
.kb-toc-h::after { background: linear-gradient(90deg, #9cc7c3, transparent); }

.kb-toc {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(275px, 1fr));
  gap: 14px; margin: 0; padding: 0; list-style: none;
}
.toc-card {
  display: flex; flex-direction: column;
  border: 1px solid #eadfbf; border-radius: 14px; background: #fff; overflow: hidden;
  transition: box-shadow .15s, border-color .15s, transform .15s;
}
.toc-card:hover { border-color: #c9a227; box-shadow: 0 6px 18px rgba(170, 130, 20, .18); transform: translateY(-2px); }
.toc-head {
  position: relative; display: block;
  aspect-ratio: 709 / 420; padding: 0; overflow: hidden; text-align: center; text-decoration: none;
  background: url(../img/khmer/frame-gold.png) center / 100% 100% no-repeat;
}
.toc-head > span.toc-t {
  position: absolute; inset: 35.8% 25.5% 34.2%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  overflow-wrap: break-word;
  color: #1f1f1f; font: 400 12px/1.3 var(--kt-title);
}
.toc-head > span.toc-t.en-t {
  color: #1f1f1f; font: 700 12px/1.22 var(--kt-body);
}
.toc-head > span.toc-t small {
  display: block; color: #b3171b; font: 700 0.85em/1.2 var(--kt-body); margin-bottom: 0.14em;
}
html:not([data-ob-lang="en"]) .toc-head .en-t { display: none !important; }
html[data-ob-lang="en"] .toc-head .km-t { display: none !important; }
.toc-sub {
  margin-top: auto; border-top: 1px dashed #eadfbf; padding: 8px 13px 9px;
  display: flex; flex-direction: column; gap: 3px; background: #fffcf5;
}
.toc-sub-en {
  padding: 0; background: none; border-left: 0; border-radius: 0;
  color: #0c6662; font-size: 13.5px; font-weight: 700; line-height: 1.4; text-decoration: none;
}
.toc-sub-en:hover { text-decoration: underline; }
html[data-ob-lang="en"] .toc-sub-en { display: none !important; }
.toc-sub-meta { font-size: 12.5px; color: #5b5344; font-weight: 600; line-height: 1.45; }
.toc-sub-meta .km-t { display: block; color: #4a4336; }
.toc-sub-meta .en-t {
  display: block; padding: 0; margin: 1px 0 0; background: none; border: 0;
  color: #6b6352; font-size: 12px; font-weight: 600; line-height: 1.4;
}
html[data-ob-lang="km"] .toc-sub-meta .en-t { display: none !important; }
html[data-ob-lang="en"] .toc-sub-meta .km-t { display: none !important; }
.kb-sol-banner { margin-top: 22px; }
.kb-sol-banner .ob-ch-card { background: #fffcf5; border-color: #eadfbf; color: #1b1b1b; }
.kb-sol-banner .ob-ch-card b { color: #0c6662; }
.kb-sol-banner .ob-ch-card small { color: #5b5344; }
.kb-sol-banner .ob-ch-num { background: linear-gradient(135deg, #f6d36b, #c58a12); color: #fff; }

@media (max-width: 760px) {
  .kb-paper { padding: 18px 16px 22px; border-right-width: 8px; }
  .kb-intro { grid-template-columns: 1fr; justify-items: center; text-align: center; gap: 18px; }
  .kb-cov-f { max-width: 260px; }
  .kb-intro .kb-info { border-width: 34px; padding: 0; width: 100%; }
  .kb-stats, .kb-actions { justify-content: center; }
  .kb-info .en-t { text-align: left; }
}
@media (max-width: 640px) {
  .ob-bar { position: static; }
  .ob-ex, .ob-pr, .ob-box { padding: 14px 12px; }
  .en-t { padding: 8px 10px; font-size: 15px; }
}
@media print {
  .ob-bar, .ob-pager { display: none !important; }
  details.qsol > summary .qa { display: none; }
}
