/* game3d.css — giao diện trò chơi mô phỏng. Không có tài nguyên ngoài, không có phông web. */
:root {
  --nen: #f4f1e8; --the: #ffffff; --chu: #26303a; --phu: #5b6772; --vien: #d8d2c2; --nhan: #e9e2cf;
  --chinh: #2f6f5e; --chinh-dam: #245547; --nhan-manh: #c0452e; --dung: #2e7d4f; --sai: #b3382c; --vang: #f5c84b;
}
@media (prefers-color-scheme: dark) {
  :root { --nen: #1c2229; --the: #262e37; --chu: #e8edf1; --phu: #a6b2bc; --vien: #3b4652; --nhan: #323c46; --chinh: #4fa88e; --chinh-dam: #3c8a73; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--nen); color: var(--chu);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; overflow-wrap: anywhere; }
body { overflow-x: hidden; }
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; min-height: 44px; border-radius: 10px; border: 1px solid var(--vien);
  background: var(--the); padding: 6px 12px; touch-action: manipulation; }
button:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible { outline: 3px solid var(--vang); outline-offset: 1px; }
.nut-nho { min-height: 44px; padding: 4px 10px; font-size: 14px; }
.nut-vuong { min-width: 44px; padding: 4px 0; font-weight: 700; font-size: 17px; }
.nut-chinh { background: var(--chinh); color: #fff; border-color: var(--chinh-dam); font-weight: 600; }
.nut-chinh:hover:not(:disabled) { background: var(--chinh-dam); }
.nut-chinh.thieu { background: #8a949c; border-color: #6f7a82; }
.nut-nguy { background: var(--sai); border-color: #8c2a20; }
.nut-phu { background: var(--the); }
.nut-nho[aria-pressed="true"] { background: var(--chinh); color: #fff; border-color: var(--chinh-dam); }

/* HUD */
#hud { padding: 4px 12px 4px; background: var(--the); border-bottom: 1px solid var(--vien); flex: 0 0 auto; }
.hang-tren { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
#ten-game { margin: 0 auto 0 0; font-size: 17px; line-height: 1.2; min-width: 0; flex: 1 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hang-so { display: flex; gap: 6px; margin-top: 4px; }
.chip-hud { flex: 1 1 0; min-width: 0; background: var(--nhan); border-radius: 999px; padding: 4px 8px; text-align: center; font-size: 15px; white-space: nowrap; }
.chip-hud b { font-variant-numeric: tabular-nums; }
.hang-mt { position: relative; height: 44px; margin-top: 3px; }
.muc-tieu { position: absolute; left: 0; right: 0; top: 0; z-index: 7; display: block; width: 100%; height: 44px; text-align: left; padding: 4px 10px;
  font-size: 14px; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: var(--nhan); border-color: var(--vien); }
.muc-tieu .nhan-mt { color: var(--chinh-dam); margin-right: 4px; }
.muc-tieu[aria-expanded="true"] { height: auto; min-height: 44px; white-space: normal; box-shadow: 0 6px 16px rgba(0,0,0,.25); }
.canh-bao { margin: 4px 0 0; padding: 4px 8px; font-size: 13.5px; background: #fde8e4; color: #8c2a20; border-radius: 8px; }

/* cảnh + bảng */
#giua { position: relative; flex: 1 1 auto; min-height: 0; }
#canh { position: absolute; inset: 0; background: #bfe3f2; overflow: hidden; }
/* hướng dẫn: bong bóng ở đầu cảnh, vòng sáng trên nút cần chạm, nút bị khoá */
.bong-bong { position: absolute; left: 8px; right: 8px; top: 8px; z-index: 6; max-width: 460px; margin: 0 auto; background: var(--the); color: var(--chu);
  border: 2px solid var(--vang); border-radius: 14px; padding: 6px 10px 8px; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.bong-bong .h-dau { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.bong-bong .h-dau b { color: var(--chinh-dam); font-size: 14px; }
.bong-bong p { margin: 2px 0 4px; font-size: 14.5px; line-height: 1.4; }
.bong-bong .nut-nho { font-size: 12.5px; padding: 2px 8px; }
.thanh { height: 8px; border-radius: 999px; background: var(--nhan); overflow: hidden; margin: 4px 0; }
.thanh i { display: block; height: 100%; width: 100%; background: var(--chinh); transform: scaleX(0); transform-origin: left center; transition: transform .3s; }
.sang { outline: 3px solid var(--vang); outline-offset: 1px; animation: nhapNhay 1s ease-in-out infinite; }
@keyframes nhapNhay { 0%, 100% { box-shadow: 0 0 0 0 rgba(245,200,75,.9); } 50% { box-shadow: 0 0 0 7px rgba(245,200,75,0); } }
button.khoa { opacity: .45; }
#goi { position: absolute; left: 8px; right: 8px; top: 8px; z-index: 6; max-width: 460px; margin: 0 auto; pointer-events: none; }
#goi .goi-the { pointer-events: none; background: var(--the); border: 2px solid var(--chinh); border-radius: 14px; padding: 6px 10px 8px; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
#goi .goi-the p { margin: 0 0 4px; font-size: 14.5px; line-height: 1.4; }
#goi .goi-the button { pointer-events: auto; }
#luu { position: absolute; right: 8px; bottom: 6px; z-index: 3; font-size: 12px; color: #fff; background: rgba(30,38,46,.72); padding: 2px 10px; border-radius: 999px;
  opacity: 0; transition: opacity .6s; pointer-events: none; }
#luu.hien { opacity: 1; transition: opacity .1s; }
.the-cai { border: 1px solid var(--vien); border-radius: 12px; padding: 8px 10px; margin: 0 0 10px; }
.o-ma { display: block; width: 100%; margin: 6px 0; font: 12px/1.3 ui-monospace, Consolas, monospace; border: 1px solid var(--vien); border-radius: 8px; padding: 6px;
  background: var(--nen); color: var(--chu); resize: vertical; word-break: break-all; }
.ds-huong { margin: 4px 0 8px 18px; padding: 0; font-size: 14.5px; line-height: 1.45; }
canvas.canh-3d { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
canvas.canh-3d:active { cursor: grabbing; }
.luoi-2d { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 0; padding: 4px; max-width: 480px; margin: 0 auto; }
.o2d { min-height: 44px; padding: 0; font-size: 13px; border-radius: 6px; }
.o2d.chon { outline: 3px solid var(--vang); }
#bang { position: absolute; left: 0; right: 0; bottom: 0; max-height: 58%; display: flex; flex-direction: column; z-index: 5;
  background: var(--nen); border-top: 2px solid var(--chinh); box-shadow: 0 -6px 18px rgba(0,0,0,.18); }
#bang.bang-cao { max-height: 100%; top: 0; }
#bang-dau { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px; background: var(--the); border-bottom: 1px solid var(--vien); flex: 0 0 auto; }
#bang-noi { padding: 10px 12px 14px; overflow-y: auto; overflow-x: hidden; flex: 1 1 auto; -webkit-overflow-scrolling: touch; }
#o-sheet { position: absolute; left: 8px; right: 8px; bottom: 8px; max-width: 460px; z-index: 4; background: var(--the);
  border: 1px solid var(--vien); border-radius: 14px; padding: 8px 10px; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
.o-dau { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.o-nut { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 6px; }
#bao { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); z-index: 8; background: rgba(30,38,46,.92); color: #fff;
  border-radius: 999px; padding: 6px 14px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 92%; text-align: center; }
#bao.hien { opacity: 1; }

/* tabs */
#tabs { display: flex; flex: 0 0 auto; background: var(--the); border-top: 1px solid var(--vien); padding-bottom: env(safe-area-inset-bottom); }
.tab { flex: 1 1 0; min-width: 0; border-radius: 0; border: 0; border-right: 1px solid var(--vien); font-size: 12.5px; padding: 6px 2px; min-height: 48px; background: transparent; }
.tab:last-child { border-right: 0; }
.tab.chon { background: var(--chinh); color: #fff; font-weight: 600; }

/* thẻ và nội dung */
.the { background: var(--the); border: 1px solid var(--vien); border-radius: 14px; padding: 12px; margin: 0 0 10px; }
.the-don, .the-nc { background: var(--the); border: 1px solid var(--vien); border-radius: 12px; padding: 10px 12px; margin: 0 0 8px; display: flex; flex-direction: column; gap: 6px; }
.ten-don { font-weight: 600; }
.thuong { color: var(--nhan-manh); font-weight: 600; }
.phu { color: var(--phu); margin: 6px 0; font-size: 14.5px; }
.nho { color: var(--phu); font-size: 13.5px; margin: 6px 0; }
.tieu { font-size: 20px; margin: 4px 0 6px; line-height: 1.35; }
.tieu-nc { margin: 0; font-size: 18px; }
.tieu-nho { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--phu); margin: 14px 0 6px; }
.tieu-v, .dich { color: var(--phu); font-size: 15px; }
.nhan { display: inline-block; background: var(--nhan); border-radius: 999px; padding: 1px 10px; font-size: 12.5px; margin: 0 6px 6px 0; }
.nam-lon { font-size: 26px; font-weight: 700; color: var(--chinh); }
.dong-kho { padding: 6px 0; border-bottom: 1px dashed var(--vien); }
.ok-nc { color: var(--dung); font-weight: 700; margin: 0; }
.khoa-ky { padding: 8px 12px; border: 2px dashed var(--vien); border-radius: 12px; text-align: center; color: var(--phu); }
.hanh-dong { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.hanh-dong .nut-chinh, .hanh-dong .nut-phu { flex: 1 1 140px; }
.hang-cai { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.bac-sao { list-style: none; margin: 0; padding: 0; font-size: 14.5px; }
.bac-sao li { padding: 3px 0; color: var(--phu); }
.bac-sao li.da { color: var(--dung); font-weight: 600; }
.ds-cau-tt { display: flex; flex-wrap: wrap; gap: 6px; }
.tt-cau { background: var(--nhan); border-radius: 8px; padding: 2px 8px; font-size: 13.5px; }

/* furigana / dịch */
body.an-furi rt, body.an-furi rp { display: none; }
body.an-dich .dich, body.an-dich .vn.dich { display: none; }
ruby { ruby-position: over; }
rt { font-size: .55em; color: var(--phu); }
.jp { font-size: 18px; line-height: 2; }
/* dòng có furigana: đặt line-height ≥ 2 trên phần tử chứa ruby (cách player.html: .jp 18px/2, tiêu đề 34px/2.1) để dòng không giãn thất thường */
.so-that .tieu, .tieu-y { line-height: 2; }
ruby { line-height: 1; }
.tieu-y { font-size: 20px; }
.dong-tu, .vd { padding: 6px 0; border-bottom: 1px dashed var(--vien); }

/* thẻ cảnh có ▶ */
.ds-cau { margin: 8px 0; }
.cau-canh { display: flex; gap: 8px; align-items: flex-start; padding: 6px 4px; border-radius: 10px; }
.cau-canh.dang { background: rgba(245,200,75,.28); }
.cau-canh .nd { flex: 1 1 auto; min-width: 0; }
.nut-am { flex: 0 0 44px; width: 44px; height: 44px; padding: 0; border-radius: 999px; background: var(--chinh); color: #fff; border-color: var(--chinh-dam); }
.hang-so .chip { display: inline-block; background: var(--nhan); border-radius: 8px; padding: 2px 8px; }
.nguon { font-size: 12.5px; color: var(--phu); margin-top: 4px; }
.hang-the { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 6px 0; }
.dem-the { font-size: 14px; color: var(--phu); }

/* câu hỏi */
.dau-phien { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.tien-do { font-weight: 600; }
.hd { color: var(--phu); font-size: 14.5px; margin-bottom: 4px; }
.vn { margin: 2px 0 8px; }
.lua-chon { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
button.lc { text-align: left; display: flex; gap: 10px; align-items: center; min-height: 48px; font-size: 17px; line-height: 1.9; }
button.lc .so-lc { flex: 0 0 24px; height: 24px; line-height: 24px; text-align: center; border-radius: 999px; background: var(--nhan); font-size: 13px; }
button.lc.chon { border-color: var(--chinh); box-shadow: inset 0 0 0 2px var(--chinh); }
button.lc.dung, .xep-dong li.dung { background: rgba(46,125,79,.18); border-color: var(--dung); }
button.lc.sai, .xep-dong li.sai { background: rgba(179,56,44,.16); border-color: var(--sai); }
.o { display: inline-block; min-width: 3em; border-bottom: 2px solid var(--phu); text-align: center; }
.o.dien { color: var(--dung); border-bottom-color: var(--dung); font-weight: 600; }
.xep-dong { list-style: none; margin: 8px 0; padding: 0; display: flex; flex-direction: column; gap: 6px; counter-reset: xep; }
.xep-dong li { counter-increment: xep; min-height: 46px; border: 2px dashed var(--vien); border-radius: 10px; padding: 3px 6px; display: flex; align-items: center; gap: 8px; }
.xep-dong li::before { content: counter(xep); color: var(--phu); font-size: 13px; flex: 0 0 18px; }
.xep-dong li.co { border-style: solid; }
.xep-dong li .manh { flex: 1 1 auto; text-align: left; }
.xep-kho { display: flex; flex-wrap: wrap; gap: 6px; }
.manh { min-height: 44px; font-size: 16.5px; line-height: 1.9; max-width: 100%; }
.phan-hoi { border-radius: 12px; padding: 10px 12px; margin-top: 10px; border: 2px solid var(--vien); background: var(--the); }
.phan-hoi.ok { border-color: var(--dung); }
.phan-hoi.sai { border-color: var(--sai); }
.phan-hoi .ket { font-weight: 700; font-size: 17px; }
.phan-hoi.ok .ket { color: var(--dung); }
.phan-hoi.sai .ket { color: var(--sai); }
.sao-moi { margin: 6px 0; padding: 6px 10px; border-radius: 10px; background: rgba(245,200,75,.35); font-weight: 600; }
.giai { margin-top: 6px; }
.kem { color: var(--phu); font-size: 14px; }
.thu-tu { margin: 4px 0 8px 18px; padding: 0; }
.noi-dung-phien { min-height: 0; }

/* màn phụ + hộp thoại */
.man-phu { position: fixed; inset: 0; z-index: 20; background: var(--nen); overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
#hop { z-index: 30; background: rgba(20,26,32,.55); display: flex; align-items: center; justify-content: center; padding: 12px; }
#hop[hidden] { display: none; }
.khung-hop { background: var(--the); border-radius: 16px; padding: 14px 16px; width: 100%; max-width: 460px; max-height: 92vh; overflow-y: auto; overflow-x: hidden; }
.khung-hop.rong { max-width: 640px; }
.chuc-mung { text-align: center; }
.bieu-lon { font-size: 48px; }
.khung-gt { max-width: 640px; margin: 0 auto; padding: 14px 14px 28px; }
.tieu-gt { font-size: 26px; margin: 4px 0 10px; }

@media (min-width: 900px) {
  #bang { left: auto; width: 420px; top: 0; max-height: none; border-top: 0; border-left: 2px solid var(--chinh); box-shadow: -6px 0 18px rgba(0,0,0,.15); }
  #bang.bang-cao { width: 520px; }
  #ten-game { font-size: 20px; }
}
@media (prefers-reduced-motion: reduce) { #bao { transition: none; } }
