/* Màn hình học: sân khấu nhân vật + thẻ bài học từng bước + sổ tay; công thức sống, video, mô phỏng mới.
   Chế độ «Đọc liền mạch» (mặc định khi chưa có JS) giữ nguyên trang cuộn; chế độ «Học từng bước» (body.mode-learn) bật màn hình học. */

/* ---------- công tắc Học / Đọc ---------- */
.mode-switch { display: inline-flex; border: 1.5px solid var(--ink); border-radius: 999px; overflow: hidden; background: var(--flour); flex: none; }
.mode-switch button { font: 600 12.5px var(--display); border: 0; background: transparent; padding: 6px 14px; cursor: pointer; color: var(--ink); white-space: nowrap; }
.mode-switch button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.mode-switch[data-where="read"] { margin: 0 0 14px; }
body.mode-learn .mode-switch[data-where="read"] { display: none; }

/* ---------- ở chế độ Đọc: ẩn mọi thứ của màn hình học ---------- */
.lstage, .lhead, .lbar, .step.cover, .drawer { display: none; }
.lmain, .lcard { display: block; }

/* ---------- chế độ Học ---------- */
body.mode-learn .ch-head, body.mode-learn .crumbs, body.mode-learn .pager, body.mode-learn .toc-btn,
body.mode-learn .terms, body.mode-learn .source, body.mode-learn .path-xp { display: none; }
body.mode-learn .wrap.chapter { max-width: 1320px; padding-top: 8px; padding-bottom: 14px; }
body.mode-learn .path { position: static; margin: 0 0 8px; padding: 4px 6px; justify-content: center; }
body.mode-learn .foot { display: none; }
body.mode-learn { overflow-x: hidden; }

body.mode-learn .lesson { display: grid; grid-template-columns: minmax(300px, 37%) minmax(0, 1fr); height: var(--lh, 640px);
  border: 1.5px solid var(--ink); border-radius: 22px; overflow: hidden; background: var(--flour); box-shadow: var(--shadow); }
body.mode-learn .lstage, body.mode-learn .lhead, body.mode-learn .lbar { display: flex; }
body.mode-learn .lmain { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

/* sân khấu */
.lstage { position: relative; overflow: hidden; background: #e8d8b6; align-items: flex-end; justify-content: center; border-right: 1.5px solid var(--ink); }
.lstage-bg { position: absolute; inset: 0; background-size: cover; background-position: 30% 60%; transition: opacity .5s ease; }
.lstage-bg[data-bg="bakery"] { background-image: url(../img/scenes/bakery.webp); }
.lstage-bg[data-bg="street"] { background-image: url(../img/scenes/street.webp); background-position: 52% 60%; }
.lstage-bg[data-bg="ben-do"] { background-image: url(../img/scenes/ben-do.webp); background-position: 50% 60%; }
.lstage-bg::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(246, 239, 224, 0) 55%, rgba(60, 40, 10, .28)); }
.lchar { position: relative; z-index: 2; width: 100%; height: 80%; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; pointer-events: none; }
.lchar-img { max-height: 100%; width: auto; max-width: 92%; object-fit: contain; filter: drop-shadow(0 8px 10px rgba(50, 30, 5, .35)); transform-origin: 50% 100%; }
.lchar.swap .lchar-img { animation: charIn .45s cubic-bezier(.2, .9, .3, 1.2); }
.lchar.nochar .lchar-img, .lchar-img:not([src]) { visibility: hidden; }
.lchar-img.speak { animation: charTalk 1.6s ease-in-out 1; }
@keyframes charIn { from { transform: translateY(26px) scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes charTalk { 0%, 100% { transform: none; } 30% { transform: translateY(-5px) rotate(-1deg); } 60% { transform: translateY(0) rotate(.8deg); } }
.lname { position: absolute; z-index: 3; bottom: 10px; left: 50%; transform: translateX(-50%); background: var(--c, var(--ink)); color: #fff; padding: 5px 16px 6px; border-radius: 999px;
  font: 600 14px/1.2 var(--display); white-space: nowrap; box-shadow: var(--shadow); text-align: center; border: 2px solid #fffaf0; }
.lname small { display: block; font: 500 11.5px var(--display); opacity: .92; }
.lbubble { position: absolute; z-index: 4; top: 14px; left: 14px; right: 14px; background: #fffaf0; border: 2px solid var(--ink); border-radius: 18px; padding: 11px 15px 12px; font-size: 15.5px; line-height: 1.5; color: var(--ink); box-shadow: var(--shadow); animation: bubIn .35s ease; }
.lbubble[hidden] { display: none; }
.lbubble::after { content: ""; position: absolute; left: 44px; bottom: -11px; width: 18px; height: 18px; background: #fffaf0; border-right: 2px solid var(--ink); border-bottom: 2px solid var(--ink); transform: rotate(45deg); }
.lbubble b { display: block; font: 600 12px var(--display); text-transform: uppercase; letter-spacing: .06em; color: var(--c, var(--crust)); margin-bottom: 2px; }
@keyframes bubIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* đầu, thân, chân của màn hình */
.lhead { align-items: center; gap: 10px; padding: 9px 14px; border-bottom: 1px solid var(--line); background: var(--paper); flex-wrap: wrap; }
.lh-ch { font: 600 13.5px var(--display); color: var(--ink2); margin-right: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lh-step { font: 600 12.5px var(--display); color: var(--wheat-d); white-space: nowrap; }
.nb-open b { display: inline-block; min-width: 1.4em; text-align: center; background: var(--wheat); color: #fff; border-radius: 999px; padding: 0 5px; margin-left: 4px; }
.lcard { flex: 1; min-height: 0; overflow-y: auto; padding: 20px clamp(16px, 2.6vw, 32px) 26px; outline: none; scroll-behavior: auto; }
.lbar { align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line); background: var(--paper); }
.ldots { list-style: none; display: flex; gap: 5px; margin: 0; padding: 0; flex: 1; justify-content: center; flex-wrap: wrap; }
.ldots li { width: 12px; height: 12px; border-radius: 50%; border: 2.5px solid var(--sc, var(--line)); background: transparent; cursor: pointer; padding: 0; transition: transform .15s; }
.ldots li.seen { background: var(--sc); opacity: .55; } .ldots li.done { background: var(--sc); opacity: 1; }
.ldots li.cur { transform: scale(1.45); box-shadow: 0 0 0 3px rgba(201, 138, 27, .35); }
.lbar .btn { border: 0; cursor: pointer; padding: 11px 22px; } .lbar .btn[disabled] { opacity: .4; cursor: default; }
.lbar .btn.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(201, 138, 27, .55); } 50% { box-shadow: 0 0 0 9px rgba(201, 138, 27, 0); } }

/* chặng và bước */
body.mode-learn .stage { display: none; margin: 0; border: 0; padding: 0; }
body.mode-learn .stage.cur { display: block; }
body.mode-learn .stage .stage-tag { position: static; display: inline-block; margin: 0 0 12px; }
body.mode-learn .step { display: none; }
body.mode-learn .step.on { display: block; animation: stepIn .35s ease; }
@keyframes stepIn { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }
body.mode-learn .step > .act, body.mode-learn .step > .story, body.mode-learn .step > .block, body.mode-learn .step > .callout, body.mode-learn .step > .quote,
body.mode-learn .step > .remember, body.mode-learn .step > .bridge, body.mode-learn .step > .fig { margin: 0; }
body.mode-learn .step > .act { background: transparent; border: 0; box-shadow: none; padding: 0; }
body.mode-learn .step > .story { background: transparent; border: 0; box-shadow: none; padding: 0; }
body.mode-learn .step > .bridge { border-top: 0; margin-top: 0; padding-top: 0; }
body.mode-learn .step > .fig img { max-height: 46vh; }
body.mode-learn .step > .remember { margin: 0; }
body.mode-learn .step .act-h { font-size: clamp(20px, 2vw, 26px); }

/* câu chuyện theo nhịp: từng lời hiện dần */
body.mode-learn .step[data-kind="story"] .beat { display: none; }
body.mode-learn .step[data-kind="story"] .beat.shown { display: flex; animation: stepIn .35s ease; }
body.mode-learn .step[data-kind="story"] .narr.beat.shown { display: block; }
body.mode-learn .step[data-kind="story"] .say:nth-of-type(even) { flex-direction: row; }   /* ở màn hình học luôn đặt người nói bên trái */
body.mode-learn .step[data-kind="story"] .say:nth-of-type(even) .bub { border-radius: 18px 18px 18px 4px; }
.say .av.has-img { background: var(--c); overflow: hidden; padding: 0; width: 46px; height: 46px; border: 2px solid var(--c); }
.say .av.has-img img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 14%; transform: scale(1.5); transform-origin: 50% 20%; background: #fffaf0; }
.say.cur .bub { box-shadow: 0 0 0 3px rgba(201, 138, 27, .4); }
.hint-next { font: 600 13px var(--display); color: var(--wheat-d); margin: 4px 0 0 56px; animation: pulse2 1.4s ease-in-out infinite; }
@keyframes pulse2 { 50% { opacity: .45; } }

/* bước mở đầu */
.cover { text-align: left; }
.cover-num { font: 600 13px var(--display); letter-spacing: .12em; text-transform: uppercase; color: var(--tomato); }
.cover-h { font-size: clamp(30px, 3.6vw, 46px); margin: .1em 0 .25em; }
.cover .hook { font-size: clamp(18px, 1.8vw, 22px); font-weight: 500; color: var(--crust); }
.cover .meta { color: var(--ink2); font-size: 15px; }
.cover-plan { list-style: none; margin: 18px 0 0; padding: 0; display: grid; gap: 8px; }
.cover-plan li { display: grid; grid-template-columns: 112px 1fr; gap: 10px; align-items: baseline; padding: 9px 14px; border-radius: 12px; background: #fff; border: 1px solid var(--line); border-left: 5px solid var(--sc); }
.cover-plan b { font: 600 13px var(--display); text-transform: uppercase; letter-spacing: .04em; color: var(--sc); } .cover-plan span { font-size: 15px; color: var(--ink2); }

/* ---------- sổ tay (ngăn kéo) ---------- */
.drawer { position: fixed; inset: 0; z-index: 90; background: rgba(42, 33, 24, .5); justify-content: flex-end; }
.drawer:not([hidden]) { display: flex; }
.drawer-box { position: relative; width: min(480px, 94vw); height: 100%; background: var(--paper); padding: 22px 20px 30px; overflow: auto; box-shadow: -8px 0 30px rgba(0, 0, 0, .25); }
.drawer h2 { margin-bottom: .6em; } .drawer h3 { font: 600 13px var(--display); text-transform: uppercase; letter-spacing: .08em; color: var(--crust); margin: 20px 0 8px; }
.nb-empty { color: var(--ink2); font-size: 15px; }
.nb-formula { background: #fff; border: 1px solid var(--line); border-left: 5px solid var(--river); border-radius: 12px; padding: 10px 14px; margin: 0 0 8px; }
.nb-formula b { display: block; font: 600 13px var(--display); color: var(--river); text-transform: uppercase; letter-spacing: .04em; } .nb-formula span { font-size: 17px; font-weight: 600; } .nb-formula small { display: block; color: var(--ink2); margin-top: 2px; }
.nb-terms dt { font-weight: 700; margin-top: 10px; } .nb-terms dd { margin: 2px 0 0; color: var(--ink2); font-size: 15px; }
.nb-src { font-size: 14px; color: var(--ink2); }

/* ---------- công thức sống ---------- */
.fx-lab { display: grid; gap: 14px; }
.fx-vars { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; }
.fx-var { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.fx-var label { display: block; font-size: 14.5px; color: var(--ink2); } .fx-var label b { display: block; font: 700 22px var(--display); color: var(--ink); }
.fx-var input[type="range"] { width: 100%; accent-color: var(--wheat); margin-top: 4px; }
.fx-rows { display: grid; gap: 8px; }
.fx-row { background: #fffdf6; border: 1.5px solid var(--line); border-radius: 14px; padding: 12px 16px; display: grid; gap: 2px; }
.fx-row .fx-name { font: 600 12.5px var(--display); text-transform: uppercase; letter-spacing: .06em; color: var(--river); }
.fx-row .fx-text { font: 600 clamp(17px, 1.7vw, 21px)/1.35 var(--display); color: var(--ink); }
.fx-row .fx-calc { font: 500 clamp(15px, 1.5vw, 18px) var(--display); color: var(--ink2); font-variant-numeric: tabular-nums; }
.fx-row .fx-val { font: 800 clamp(22px, 2.4vw, 30px) var(--display); color: var(--crust); font-variant-numeric: tabular-nums; }
.fx-row.hi { border-color: var(--river); background: #eef5f7; } .fx-row.hi .fx-val { color: var(--river); } .fx-row.neg .fx-val { color: var(--tomato); }
.fx-row .fx-val small { font: 500 14px var(--display); color: var(--ink2); margin-left: 6px; }
.fx-read { background: var(--ink); color: var(--paper); border-radius: 14px; padding: 12px 16px; font-size: 15.5px; } .fx-read b { color: var(--wheat); }

/* ---------- video giải thích ---------- */
.vid-box { background: #1b140c; border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); }
.vid-box video { display: block; width: 100%; max-height: 52vh; background: #000; aspect-ratio: 16 / 9; }
.vid-marks { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0; padding: 0; list-style: none; }
.vid-marks button { font: 600 12.5px var(--display); border: 1.5px solid var(--ink); background: var(--flour); border-radius: 999px; padding: 5px 12px; cursor: pointer; } .vid-marks button:hover, .vid-marks button.cur { background: var(--ink); color: #fff; }
.vid-fx { display: grid; gap: 6px; margin: 10px 0 0; }
.vid-fx .nb-formula { margin: 0; }
.vid-tr summary { cursor: pointer; font: 600 13px var(--display); color: var(--crust); margin-top: 10px; } .vid-tr p { font-size: 15.5px; color: var(--ink2); margin: 6px 0; }
.vid-state { font-size: 14px; color: var(--ink2); margin-top: 8px; }

/* ---------- mô phỏng: nướng bao nhiêu ổ ---------- */
.bp-scn { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; } .bp-scn > span { font: 600 12.5px var(--display); text-transform: uppercase; letter-spacing: .05em; color: var(--ink2); margin-right: 4px; }
.seg { display: inline-flex; border: 1.5px solid var(--ink); border-radius: 999px; overflow: hidden; background: #fff; } .seg button { border: 0; background: transparent; font: 600 13px var(--display); padding: 6px 13px; cursor: pointer; color: var(--ink); } .seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.bp-ctl, .bn-ctl { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.bp-ctl label, .bn-ctl label { display: block; font-size: 14px; color: var(--ink2); } .bp-ctl label b, .bn-ctl label b { display: block; font: 700 21px var(--display); color: var(--ink); } .bp-ctl input, .bn-ctl input { width: 100%; accent-color: var(--wheat); }
.bp-strip { display: flex; flex-wrap: wrap; gap: 3px; margin: 12px 0 4px; min-height: 30px; }
.loaf { width: 26px; height: 15px; flex: none; } .loaf.sold { color: var(--wheat); } .loaf.waste { color: #b8ae9c; } .loaf.miss { color: transparent; }
.loaf.miss path { stroke: var(--tomato); stroke-dasharray: 3 2; fill: none; } .loaf.sold path, .loaf.waste path { fill: currentColor; stroke: var(--crust); }
.bp-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13.5px; color: var(--ink2); margin: 2px 0 8px; } .bp-legend i { display: inline-block; width: 14px; height: 9px; border-radius: 4px; margin-right: 5px; vertical-align: 0; }
.bp-legend .a i { background: var(--wheat); } .bp-legend .b i { background: #b8ae9c; } .bp-legend .c i { border: 1.5px dashed var(--tomato); }
.bp-chart { width: 100%; height: auto; display: block; background: #fffdf6; border: 1px solid var(--line); border-radius: 14px; margin-top: 6px; }
.bp-chart text { font: 500 11px var(--display); fill: var(--ink2); }
.bp-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin-top: 10px; } .bp-stats div { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; text-align: center; }
.bp-stats b { display: block; font: 700 clamp(17px, 1.7vw, 22px) var(--display); font-variant-numeric: tabular-nums; } .bp-stats span { font-size: 12.5px; color: var(--ink2); } .bp-stats .neg b { color: var(--tomato); } .bp-stats .pos b { color: #2e7d32; }
.bp-msg { margin: 10px 0 0; font-size: 15.5px; } .bp-goals { list-style: none; padding: 0; margin: 10px 0 0; display: flex; gap: 8px; flex-wrap: wrap; }
.bp-goals li { padding: 6px 14px 6px 34px; position: relative; border-radius: 999px; background: #fff; border: 1.5px solid var(--line); font-size: 14px; } .bp-goals li::before { content: "○"; position: absolute; left: 12px; color: var(--ink2); } .bp-goals li.on { border-color: #2e7d32; background: #eaf5e4; } .bp-goals li.on::before { content: "✓"; color: #2e7d32; font-weight: 700; }

/* ---------- mô phỏng: ba thứ có hạn ---------- */
.bn-view { margin-top: 12px; display: grid; gap: 9px; position: relative; padding-bottom: 28px; }
.bn-row { display: grid; grid-template-columns: 120px 1fr; gap: 10px; align-items: center; } .bn-row > b { font: 600 13.5px/1.25 var(--display); } .bn-row > b small { display: block; font: 500 12px var(--display); color: var(--ink2); }
.bn-track { position: relative; height: 30px; background: #fffdf6; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.bn-fill { position: absolute; inset: 0 auto 0 0; background: var(--wheat); border-radius: 7px 0 0 7px; transition: width .25s ease; }
.bn-fill.waste { background: repeating-linear-gradient(135deg, #e6dccb 0 6px, #f3ecde 6px 12px); }
.bn-row.tight .bn-fill { background: var(--tomato); } .bn-row.tight > b { color: var(--tomato); }
.bn-val { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font: 700 13px var(--display); font-variant-numeric: tabular-nums; z-index: 2; }
.bn-lines { position: absolute; left: 130px; right: 0; top: 0; bottom: 26px; pointer-events: none; }
.bn-line { position: absolute; top: -4px; bottom: -4px; width: 0; border-left: 2.5px solid var(--ink); transition: left .25s ease; } .bn-line.d { border-left: 2.5px dashed var(--river); } .bn-line span { position: absolute; top: 100%; left: 4px; font: 600 12px var(--display); white-space: nowrap; margin-top: 2px; } .bn-line.d span { color: var(--river); }
.bn-budget { margin-top: 8px; } .bn-budget .bn-fill { background: var(--river); } .bn-budget.over .bn-fill { background: var(--tomato); }
.bn-msg { margin: 6px 0 0; font-size: 15.5px; } .bn-btns { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.bn-ok { background: #eaf5e4; border: 1.5px solid #2e7d32; border-radius: 12px; padding: 10px 14px; margin-top: 8px; }

/* nhu cầu theo giá trong mô phỏng «Bột về muộn» */
.rb-demand { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 14px; align-items: center; margin-top: 12px; background: #fffdf6; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.rb-demand .dm-num { display: grid; gap: 4px; } .rb-demand .dm-num p { margin: 0; font-size: 15px; } .rb-demand .dm-num b { font: 700 20px var(--display); font-variant-numeric: tabular-nums; }
.rb-demand .short b { color: var(--tomato); } .rb-demand .ok b { color: #2e7d32; }
.rb-demand svg { width: 100%; height: auto; } .rb-demand svg text { font: 500 11px var(--display); fill: var(--ink2); }

/* hình đạo cụ trang trí ở các bước ít chữ (chỉ hiện ở chế độ Học) */
.step-art { display: none; }
body.mode-learn .step-art { display: flex; justify-content: flex-end; align-items: flex-end; gap: 6px; margin-top: 26px; }
.step-art img { height: clamp(78px, 13vh, 128px); width: auto; filter: drop-shadow(0 4px 5px rgba(50, 30, 5, .25)); }
.step-art img:nth-child(odd) { transform: rotate(-5deg); } .step-art img:nth-child(even) { transform: rotate(4deg) translateY(-6px); }

/* trang đầu: dàn nhân vật có ảnh */
.cast li { display: flex; gap: 12px; align-items: flex-end; border-left: 0; padding: 0; background: var(--flour); border: 1px solid var(--line); border-bottom: 5px solid var(--c, var(--wheat)); border-radius: var(--r); padding: 12px 12px 10px; overflow: hidden; }
.cast li img { height: 150px; width: auto; flex: none; filter: drop-shadow(0 4px 4px rgba(50, 30, 5, .25)); }
.cast li div { min-width: 0; padding-bottom: 4px; }

/* ---------- thu hẹp ---------- */
@media (max-width: 899px) {
  body.mode-learn .lesson { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); height: var(--lh, 680px); border-radius: 16px; }
  .lstage { border-right: 0; border-bottom: 1.5px solid var(--ink); height: 150px; justify-content: flex-start; align-items: flex-end; }
  .lchar { width: 118px; height: 100%; flex: none; margin-left: 10px; }
  .lname { left: 50%; bottom: 4px; font-size: 12px; padding: 3px 10px 4px; } .lname small { display: none; }
  .lbubble { position: absolute; top: 10px; left: 142px; right: 10px; font-size: 13.5px; padding: 8px 12px; border-radius: 14px; max-height: 128px; overflow: auto; }
  .lbubble::after { left: -9px; top: 28px; bottom: auto; transform: rotate(135deg); }
  .lh-ch { display: none; }
  .cover-plan li { grid-template-columns: 1fr; gap: 2px; }
  .rb-demand { grid-template-columns: 1fr; } .bn-row { grid-template-columns: 84px 1fr; } .bn-lines { left: 94px; }
  .ldots li { width: 10px; height: 10px; } .lbar .btn { padding: 10px 16px; }
}
@media (prefers-reduced-motion: reduce) { html:not([data-motion="full"]) :is(.lchar.swap .lchar-img, .lchar-img.speak, .lbubble, body.mode-learn .step.on, .lbar .btn.pulse, .hint-next) { animation: none; } }
