/* Báo Oán: game điện thoại cầm ngang. Thế giới vẽ trên canvas, mọi bảng là lớp DOM nổi trên. Khung, nút mượn bộ UI của Giả Kim Thoa. */
:root {
  --ink: #0b090d; --gold: #e2b866; --gold-soft: #f3d797; --paper: #f7ecd6; --muted: #cbb89c; --dim: #8f877c;
  --blood: #c8423a; --soul: #9fe0ff; --jade: #7fe0c0;
  --display: 'Cormorant Garamond', 'Songti SC', Georgia, serif; --body: 'Be Vietnam Pro', system-ui, sans-serif;
  --safe-l: max(12px, env(safe-area-inset-left, 0px)); --safe-r: max(12px, env(safe-area-inset-right, 0px));
  --safe-t: max(8px, env(safe-area-inset-top, 0px)); --safe-b: max(10px, env(safe-area-inset-bottom, 0px));
  --f-dialog: url('art/ga/ui/frame-dialog.webp'); --f-popup: url('art/ga/ui/frame-popup.webp'); --f-chip: url('art/ga/ui/frame-chip.webp');
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--ink); color: var(--paper); font: 14px/1.45 var(--body); overflow: hidden; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }
/* Giữ ngón lâu trên ảnh/nút: không bật menu Lưu ảnh, Sao chép của trình duyệt. */
img, canvas, button, .portrait, .card-port, .menu-art { -webkit-touch-callout: none; -webkit-user-drag: none; user-drag: none; -webkit-user-select: none; user-select: none; }
img { pointer-events: none; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid rgba(220,60,50,.8); outline-offset: 2px; }
#game { position: fixed; inset: 0; overflow: hidden; }
canvas#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* Xoay ngang, màn tải */
/* Như Ta là Quân Đại: điện thoại cầm dọc thì che cả game, mời xoay ngang. */
#rotate { position: fixed; inset: 0; z-index: 60; background: #050306; display: none; place-items: center; text-align: center; padding: 24px; color: var(--paper); }
#rotate .rot-box { display: grid; gap: 18px; justify-items: center; max-width: 300px; }
#rotate svg { width: 96px; height: 96px; color: #d9534a; animation: rot 2.4s ease-in-out infinite; }
#rotate p { margin: 0; font: 700 22px/1.3 var(--display); }
#rotate small { color: var(--dim); font-size: 14px; }
@keyframes rot { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
@media (prefers-reduced-motion: reduce) { #rotate svg { animation: none; } }
@media (orientation: portrait) and (pointer: coarse) { #rotate { display: grid; } }
#boot { position: fixed; inset: 0; z-index: 40; background: var(--ink); display: grid; place-items: center; }
.boot-box { display: grid; gap: 10px; justify-items: center; }
.boot-box b { font: 700 34px var(--display); color: var(--gold-soft); letter-spacing: .04em; }
.boot-bar { width: 200px; height: 4px; background: rgba(255,255,255,.12); border-radius: 2px; overflow: hidden; }
.boot-bar i { display: block; height: 100%; width: 0; background: var(--blood); transition: width .2s; }
.boot-box small { color: var(--dim); }

/* Nút, khung chung */
.round { width: 40px; height: 40px; border-radius: 50%; border: 1px solid rgba(150,28,28,.6); background: rgba(10,4,6,.82); box-shadow: 0 0 12px rgba(0,0,0,.6);
  color: #d8cfc2; font: 700 17px var(--display); display: grid; place-items: center; padding: 0; }
.chip { background: linear-gradient(180deg, rgba(14,6,8,.84), rgba(14,6,8,.62)); border: 1px solid rgba(150,28,28,.45); border-radius: 2px;
  box-shadow: 0 0 16px rgba(0,0,0,.65), inset 0 0 12px rgba(110,0,0,.22); padding: 5px 10px; }
.primary { min-height: 44px; padding: 0 22px; border-radius: 2px; border: 1px solid #b3302b; background: linear-gradient(180deg, #8e1a1d, #4a0a0d);
  color: #fff4dc; font-weight: 700; box-shadow: 0 6px 18px rgba(0,0,0,.4); }
.ghost { min-height: 44px; padding: 0 18px; border-radius: 2px; border: 1px solid rgba(216,207,194,.3); background: rgba(10,4,6,.6); color: #d8cfc2; font-weight: 600; }

/* HUD: trái tên map + điềm báo; giữa hai thanh; phải canh giờ + nút */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
#hud button { pointer-events: auto; }
.hud-left { position: absolute; left: var(--safe-l); top: var(--safe-t); display: flex; flex-direction: column; gap: 4px; max-width: 30vw; }
#hudMap { font: 700 14px/1.2 var(--display); color: #d8cfc2; letter-spacing: .03em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.omens { display: grid; gap: 0; font-size: 10.5px; line-height: 1.3; }
.omens .h { font-size: 10px; letter-spacing: .06em; color: #ffb4a8; font-weight: 700; }
.omens .o { color: var(--dim); white-space: nowrap; }
.omens .o.ok { color: #ff9f8f; }
.hud-mid { position: absolute; left: 50%; top: var(--safe-t); transform: translateX(-50%); display: grid; gap: 3px; width: 200px; }
.bar-row { display: grid; grid-template-columns: 46px 1fr; align-items: center; gap: 6px; font-size: 10.5px; color: var(--soul); }
.bar-row.seen { color: #ff8c7a; }
.bar { height: 6px; border-radius: 3px; background: rgba(255,255,255,.14); overflow: hidden; }
.bar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #3d7ea0, var(--soul)); box-shadow: 0 0 8px var(--soul); transition: width .15s linear; }
.bar-row.seen .bar i { background: linear-gradient(90deg, #5a0a0a, #e0302a); box-shadow: 0 0 10px #e0302a; width: 0; }
.hud-right { position: absolute; right: var(--safe-r); top: var(--safe-t); display: flex; align-items: center; gap: 6px; }
#hudCanh { font-size: 12px; color: var(--paper); white-space: nowrap; display: flex; align-items: center; gap: 4px; }

/* Câu thoại ngắn khi đang chơi (không chặn) */
#say { position: absolute; left: 50%; bottom: calc(var(--safe-b) + 8px); transform: translateX(-50%); z-index: 6; pointer-events: none;
  max-width: min(56vw, 560px); padding: 6px 22px; background: linear-gradient(90deg, transparent, rgba(6,2,4,.85) 18%, rgba(6,2,4,.85) 82%, transparent);
  display: flex; flex-direction: column; gap: 1px; font-size: 13px; line-height: 1.4; text-align: center; }
#say b { font-size: 11px; color: #e0473f; letter-spacing: .08em; }
#say span { font-style: italic; color: #e6ddd0; }

/* Cần điều khiển nổi và nút hành động */
#joy { position: absolute; width: 112px; height: 112px; margin: -56px 0 0 -56px; border-radius: 50%; border: 2px solid rgba(255,255,255,.28);
  background: rgba(255,255,255,.06); z-index: 6; pointer-events: none; }
#joy i { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px; border-radius: 50%; background: rgba(255,255,255,.32); }
#act { position: absolute; right: calc(var(--safe-r) + 10px); bottom: calc(var(--safe-b) + 14px); z-index: 6; width: 84px; height: 84px; border-radius: 50%;
  border: 2px solid rgba(159,224,255,.65); background: radial-gradient(circle at 50% 40%, rgba(40,60,90,.92), rgba(12,12,22,.92));
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 6px; box-shadow: 0 0 18px rgba(120,200,255,.25); }
#act span { font-size: 13px; font-weight: 700; line-height: 1.15; text-align: center; }
#act small { font-size: 9.5px; color: var(--soul); line-height: 1.1; text-align: center; }
#act.red { border-color: var(--blood); background: radial-gradient(circle at 50% 40%, rgba(130,24,30,.95), rgba(40,6,10,.95)); box-shadow: 0 0 22px rgba(255,60,50,.4); }
#act:disabled { opacity: .45; }

/* Hội thoại cảnh xem: hai chân dung hai bên, người nói trồi lên, người kia lùi mờ */
#dialog { position: absolute; inset: 0; z-index: 8; background: linear-gradient(0deg, rgba(8,3,5,.8), rgba(8,3,5,0) 55%); cursor: pointer; }
.portrait { position: absolute; bottom: 0; height: min(88%, calc(100% - 40px)); width: 30%; display: flex; align-items: flex-end;
  justify-content: center; transform-origin: 50% 100%; transition: transform .22s ease-out, filter .22s ease-out; overflow: hidden; }
.portrait.left { left: var(--safe-l); } .portrait.right { right: var(--safe-r); }
.portrait img { max-height: 100%; max-width: 100%; object-fit: contain; object-position: 50% 100%; }
.portrait img.flip { transform: scaleX(-1); }
.portrait.empty { opacity: 0; }
.portrait.front { transform: scale(1.03); filter: none; opacity: 1; z-index: 1; }
.portrait.back { transform: translateY(6%) scale(.93); filter: brightness(.42) saturate(.6); opacity: .9; z-index: 0; }
.dbox { position: absolute; left: calc(var(--safe-l) + 22%); right: calc(var(--safe-r) + 22%); bottom: var(--safe-b); z-index: 2; min-height: 96px;
  padding: 12px 22px 8px; background: linear-gradient(180deg, rgba(10,4,6,.9), rgba(4,2,3,.95)); border-top: 1px solid rgba(170,30,30,.6);
  box-shadow: 0 -10px 30px rgba(0,0,0,.6); }
#dialog.spk-right .dbox { left: calc(var(--safe-l) + 14%); right: calc(var(--safe-r) + 30%); }
#dialog.spk-left .dbox { left: calc(var(--safe-l) + 30%); right: calc(var(--safe-r) + 14%); }
#dialog.narr .dbox { left: calc(var(--safe-l) + 16%); right: calc(var(--safe-r) + 16%); }
#dName { display: block; font-size: 13px; color: #ffb4a8; min-height: 0; }
#dialog.spk-right #dName { text-align: right; color: #ff9f8f; }
#dialog.spk-left #dName { color: #9fd8b0; }
#dText { margin: 2px 0 0; font-size: 15px; line-height: 1.5; }
#dText.in { animation: txtin .22s ease-out; }
@keyframes txtin { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
#dialog.narr #dText { font-style: italic; color: var(--muted); text-align: center; }
.dnext { display: block; text-align: right; color: var(--gold); font-size: 12px; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .3; } }
#blackout { position: absolute; inset: 0; z-index: 7; background: #000; pointer-events: none; }

/* Màn chính: ảnh tràn màn, tên game và vài lựa chọn chữ trơn như màn tiêu đề RPG */
#menu { position: absolute; inset: 0; z-index: 9; background: #040305; overflow: hidden; }
/* Nền: giếng hoang sau phủ Lục (map có sẵn), tối và mờ, như nhìn qua màn mưa. */
.menu-bg { position: absolute; inset: -4%; background: url('art/ga/maps/hoi-sau/luc_phu_rung_gieng.webp') 62% 40% / cover no-repeat;
  filter: blur(1.5px) brightness(.42) saturate(.5) contrast(1.1); animation: breathe 18s ease-in-out infinite alternate; }
@keyframes breathe { from { transform: scale(1.02); } to { transform: scale(1.08) translateX(-1%); } }
/* Hồn Quân Đại: chân dung áo đỏ có sẵn, mờ ảo, lơ lửng, viền phát sáng lạnh, chân tan vào sương. */
.menu-ghost { position: absolute; right: 7vw; bottom: -4%; height: 92%; aspect-ratio: 2 / 3; background: url('art/ga/portraits/quan-dai-trang.webp') 50% 0 / contain no-repeat;
  opacity: .72; filter: grayscale(.35) saturate(.8) brightness(.85) contrast(1.1);
  -webkit-mask-image: radial-gradient(ellipse 48% 62% at 50% 38%, #000 62%, transparent 100%); mask-image: radial-gradient(ellipse 48% 62% at 50% 38%, #000 62%, transparent 100%);
  animation: hover 6s ease-in-out infinite, flicker 11s steps(1) infinite; }
@keyframes hover { 0%, 100% { translate: 0 0; } 50% { translate: 0 -1.6%; } }
@keyframes flicker { 0%, 100% { opacity: .72; } 47% { opacity: .72; } 48% { opacity: .25; } 49% { opacity: .72; } 50% { opacity: .4; } 51% { opacity: .72; } 83% { opacity: .72; } 84% { opacity: .35; } 85% { opacity: .72; } }
/* Thoáng chốc mặt giận dữ hiện chồng lên rồi tắt. */
.menu-flash { position: absolute; right: 7vw; bottom: -4%; height: 92%; aspect-ratio: 2 / 3; background: url('art/ga/portraits/quan-dai-angry.webp') 50% 0 / contain no-repeat;
  opacity: 0; filter: grayscale(.6) contrast(1.3) brightness(.8) sepia(.4) hue-rotate(-30deg); mix-blend-mode: screen;
  -webkit-mask-image: radial-gradient(ellipse 45% 55% at 50% 35%, #000 55%, transparent 100%); mask-image: radial-gradient(ellipse 45% 55% at 50% 35%, #000 55%, transparent 100%); animation: scare 11s steps(1) infinite; }
@keyframes scare { 0%, 100% { opacity: 0; transform: none; } 48% { opacity: .55; transform: translateX(-1.5%) scale(1.03); } 49% { opacity: 0; } 50% { opacity: .35; transform: translateX(1%); } 51% { opacity: 0; transform: none; } }
.fog { position: absolute; inset: -20%; pointer-events: none; opacity: .55; filter: blur(30px);
  background: radial-gradient(ellipse 40% 18% at 30% 80%, rgba(150,170,180,.28), transparent 70%), radial-gradient(ellipse 35% 14% at 75% 92%, rgba(150,170,180,.25), transparent 70%); }
.fog.f1 { animation: drift 38s linear infinite alternate; } .fog.f2 { animation: drift 54s linear infinite alternate-reverse; opacity: .4; }
@keyframes drift { from { transform: translateX(-8%); } to { transform: translateX(8%); } }
.menu-rain { position: absolute; inset: 0; pointer-events: none; opacity: .5;
  background: repeating-linear-gradient(105deg, rgba(190,210,255,.10) 0 1px, transparent 1px 13px); animation: rain .35s linear infinite; }
@keyframes rain { from { background-position: 0 0; } to { background-position: -30px 120px; } }
/* Giấy tiền vàng mã bay (code tạo trong main.js). */
.menu-paper { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.menu-paper i { position: absolute; top: -6%; width: 10px; height: 14px; background: linear-gradient(135deg, #d9c27a, #a8863a); opacity: .55;
  box-shadow: 0 0 6px rgba(230,200,120,.3); animation: fall linear infinite; }
.menu-paper i::after { content: ''; position: absolute; inset: 3px; border: 1px solid rgba(140,40,30,.5); }
@keyframes fall { from { transform: translate(0, 0) rotate(0); } to { transform: translate(var(--dx), 112vh) rotate(var(--rot)); } }
/* Chữ 冤 (oan) lớn, đỏ mờ, sau tên game. */
.menu-han { position: absolute; left: 30vw; top: 50%; transform: translate(-50%, -50%); font: 400 86vh/1 'Ma Shan Zheng', 'Songti SC', serif; color: rgba(150,14,18,.16);
  pointer-events: none; text-shadow: 0 0 40px rgba(170,0,0,.25); animation: pulse 5s ease-in-out infinite; }
@keyframes pulse { 50% { color: rgba(180,18,22,.26); } }
#menu::after { content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(90deg, rgba(4,3,5,.92) 0%, rgba(4,3,5,.55) 36%, rgba(4,3,5,0) 62%), radial-gradient(ellipse at 66% 45%, transparent 38%, rgba(0,0,0,.85) 100%), linear-gradient(0deg, rgba(70,0,6,.45), transparent 40%); }
.menu-col { position: absolute; z-index: 1; left: calc(var(--safe-l) + 5vw); top: 0; bottom: 0; display: flex; flex-direction: column; justify-content: center; gap: 6vh; }
#menu h1 { margin: 0; font: 700 clamp(34px, 9vh, 68px)/.95 var(--display); color: #e8ddcf; text-shadow: 0 0 22px rgba(0,0,0,.9), 0 0 3px rgba(200,20,20,.6); animation: glitch 7s infinite steps(1); }
@keyframes glitch { 0%, 100% { text-shadow: 0 0 22px rgba(0,0,0,.9), 0 0 3px rgba(200,20,20,.6); transform: none; } 71% { text-shadow: -3px 0 rgba(220,20,20,.8), 3px 0 rgba(80,200,220,.5); transform: translateX(1px); } 72% { text-shadow: 2px 0 rgba(220,20,20,.8), -2px 0 rgba(80,200,220,.5); transform: translateX(-1px) skewX(-2deg); } 73% { text-shadow: 0 0 22px rgba(0,0,0,.9); transform: none; } }
#menu .menu-line { margin: -2vh 0 0; font: italic 600 clamp(13px, 3.4vh, 17px)/1.4 var(--display); color: #a99f92; max-width: 34ch; }
#menu h1 small { display: block; font-size: .55em; color: #b3221d; letter-spacing: .32em; margin-top: 1.2vh; text-shadow: 0 0 18px rgba(200,40,40,.5); }
.menu-list { display: flex; flex-direction: column; align-items: flex-start; gap: .4vh; }
.menu-item { background: none; border: 0; padding: 6px 0; min-height: 44px; font: 700 clamp(17px, 4.6vh, 24px) var(--display); color: #bdb3a6;
  letter-spacing: .04em; text-shadow: 0 2px 10px #000; position: relative; }
.menu-item::before { content: ''; position: absolute; left: -18px; top: 50%; width: 8px; height: 8px; margin-top: -4px; transform: rotate(45deg) scale(0); background: var(--blood); transition: transform .15s; }
.menu-item:hover, .menu-item:focus-visible { color: #f1e6d8; text-shadow: 0 0 12px rgba(220,30,30,.7); outline: none; }
.menu-item:hover::before, .menu-item:focus-visible::before { transform: rotate(45deg) scale(1); }
.menu-item:disabled { color: var(--dim); cursor: default; }
.menu-item:disabled::before { display: none; }

/* Bảng nổi: giới thiệu màn, mẹo, thua, tha hay không, kết */
#panel { position: absolute; inset: 0; z-index: 10; background: rgba(4,2,6,.7); display: grid; place-items: center; padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l); }
.card { display: flex; gap: 18px; align-items: stretch; max-width: min(760px, 92vw); max-height: 92vh;
  padding: 18px 22px; background: linear-gradient(180deg, rgba(14,5,7,.96), rgba(5,2,3,.97)); border: 1px solid rgba(150,28,28,.5);
  box-shadow: 0 0 60px rgba(0,0,0,.8), inset 0 0 40px rgba(90,0,0,.25); }
.card-port { width: 26%; min-width: 110px; background: 50% 0 / cover no-repeat; border-radius: 2px; filter: grayscale(.35) contrast(1.08); -webkit-mask-image: linear-gradient(180deg, #000 70%, transparent); mask-image: linear-gradient(180deg, #000 70%, transparent); }
.card-port:empty:not([style*='url']) { display: none; }
.card-body { display: flex; flex-direction: column; gap: 6px; min-width: 0; overflow: auto; }
.card small { font-size: 11px; color: var(--blood); letter-spacing: .1em; font-weight: 700; }
.card h2 { margin: 0; font: 700 clamp(22px, 5vh, 32px)/1.1 var(--display); color: #e8ddcf; text-shadow: 0 0 14px rgba(200,30,30,.45); }
.card p { margin: 0; font-size: 13.5px; line-height: 1.5; color: var(--paper); white-space: pre-line; }
.tips { display: grid; gap: 2px; font-size: 12.5px; line-height: 1.4; }
.tips div { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 10px; }
.tips span:first-child { color: var(--soul); }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }

@media (max-height: 420px) {
  .card { padding: 12px 16px; } .card p { font-size: 12.5px; } .tips { font-size: 11.5px; }
  .dbox { min-height: 84px; } #dText { font-size: 13.5px; }
}

/* Không khí: hạt nhiễu phim phủ mọi màn, viền tối quanh màn chơi đỏ dần khi sắp bị phát hiện */
#grain { position: fixed; inset: -50%; z-index: 30; pointer-events: none; opacity: .09; mix-blend-mode: overlay; animation: grain .5s steps(4) infinite; }
@keyframes grain { 0% { transform: translate(0,0); } 25% { transform: translate(-4%,3%); } 50% { transform: translate(3%,-2%); } 75% { transform: translate(-2%,-4%); } }
#vig { position: absolute; inset: 0; pointer-events: none; z-index: 4; --danger: 0;
  background: radial-gradient(ellipse at 50% 50%, transparent 45%, rgba(0,0,0,.75) 100%),
              radial-gradient(ellipse at 50% 50%, transparent 35%, rgba(170,0,0, calc(var(--danger) * .75)) 100%); }
#vig.beat { animation: beat .9s ease-in-out infinite; }
@keyframes beat { 0%, 100% { opacity: 1; } 15% { opacity: .7; } 30% { opacity: 1; } 45% { opacity: .82; } }
.bar-row.seen.hot { animation: beat .9s infinite; }
@media (prefers-reduced-motion: reduce) { .menu-bg, .menu-ghost, .menu-flash, .menu-rain, .menu-paper i, .menu-han, .fog, #menu h1, #grain, #vig.beat { animation: none !important; } .menu-paper { display: none; } }

.music-btn .slash { display: none; } .music-btn.off .slash { display: inline; } .music-btn.off .wave { display: none; } .music-btn.off { color: var(--dim); }
#menuMusic { position: absolute; z-index: 2; right: var(--safe-r); top: var(--safe-t); }

/* Mục tiêu màn trong bảng giới thiệu và bảng tạm dừng */
.goal { display: grid; gap: 3px; padding: 8px 12px; border-left: 2px solid var(--blood); background: rgba(120,10,14,.14); }
.goal b { font-size: 11px; letter-spacing: .12em; color: #e0473f; }
.goal span { font-size: 13px; line-height: 1.45; color: #efe6d8; }
.goal span::before { content: '◆ '; color: var(--blood); font-size: 10px; }
.card .sub { font-size: 11px; letter-spacing: .12em; color: var(--dim); font-weight: 700; margin-top: 2px; }

/* Danh sách màn trong bảng Chọn màn: mỗi màn một dòng */
.btns.col { flex-direction: column; align-items: stretch; }
.btns.col button { text-align: left; }
#skipCut { position: absolute; right: calc(var(--safe-r) + 4px); top: var(--safe-t); z-index: 9; min-height: 40px; padding: 0 16px; border-radius: 2px; border: 1px solid rgba(216,207,194,.35); background: rgba(10,4,6,.7); color: #d8cfc2; font-size: 13px; }

/* Cảnh xem: lúc nhân vật còn đi tới chỗ, ẩn hộp thoại và chân dung. */
#dialog.waiting .dbox, #dialog.waiting .portrait { visibility: hidden; }
