/* Phông Baloo 2 (SIL OFL, xem assets/fonts/OFL-baloo-2.txt), tự host */
@font-face { font-family: 'Baloo 2'; font-weight: 600; font-display: swap; src: url(assets/fonts/baloo-2-vietnamese-600-normal.woff2) format('woff2');
  unicode-range: U+0102-0103,U+0110-0111,U+0128-0129,U+0168-0169,U+01A0-01A1,U+01AF-01B0,U+0300-0301,U+0303-0304,U+0308-0309,U+0323,U+0329,U+1EA0-1EF9,U+20AB; }
@font-face { font-family: 'Baloo 2'; font-weight: 800; font-display: swap; src: url(assets/fonts/baloo-2-vietnamese-800-normal.woff2) format('woff2');
  unicode-range: U+0102-0103,U+0110-0111,U+0128-0129,U+0168-0169,U+01A0-01A1,U+01AF-01B0,U+0300-0301,U+0303-0304,U+0308-0309,U+0323,U+0329,U+1EA0-1EF9,U+20AB; }
@font-face { font-family: 'Baloo 2'; font-weight: 600; font-display: swap; src: url(assets/fonts/baloo-2-latin-600-normal.woff2) format('woff2');
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: 'Baloo 2'; font-weight: 800; font-display: swap; src: url(assets/fonts/baloo-2-latin-800-normal.woff2) format('woff2');
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }

:root {
  --ink: #3a2410;      /* viền nâu đậm như nét vẽ của tranh */
  --cream: #fff6df;
  --cream2: #f2dfb2;
  --gold: #f6bd3a;
  --gold2: #d98f16;
  --night: #120f33;
  --c: #e2483b;        /* màu phe đang tới lượt, mã đặt lại */
  --c2: #8e2219;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--night); color: var(--ink); font-family: 'Baloo 2', system-ui, 'Segoe UI', sans-serif; }
body { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none;
  background: radial-gradient(120% 60% at 50% 35%, #231d5a 0%, var(--night) 70%); }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
svg { width: 22px; height: 22px; display: block; }

/* ---------- nút kiểu sticker: viền đậm, bóng đáy, bấm thì lún ---------- */
.btn { border: 3px solid var(--ink); border-radius: 16px; background: linear-gradient(#fffaf0, var(--cream2)); color: var(--ink);
  box-shadow: 0 4px 0 var(--ink), inset 0 -3px 0 rgba(160, 110, 40, .25), inset 0 2px 0 #fff; font-weight: 800;
  transition: transform .06s, box-shadow .06s; position: relative; }
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink), inset 0 -2px 0 rgba(160, 110, 40, .25); }
.btn:disabled { cursor: default; }
.btn.chip { white-space: nowrap; padding: 4px 14px; min-height: 42px; border-radius: 999px; font-size: 15px; }
.btn.round { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; padding: 0; }
.btn.round.small { width: 44px; height: 44px; }
.btn.primary { background: linear-gradient(#ffe08a, var(--gold)); padding: 6px 20px; min-height: 46px; border-radius: 999px; font-size: 16px; }

/* ---------- thanh trên ---------- */
#top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px 6px; padding-top: max(8px, env(safe-area-inset-top)); }
.badge { display: flex; align-items: center; gap: 8px; min-width: 0; background: var(--cream); border: 3px solid var(--ink); border-radius: 999px;
  padding: 3px 14px 3px 3px; box-shadow: 0 4px 0 var(--ink); }
.avatar { width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--ink); background: var(--c); overflow: hidden; flex: none; display: block; }
.avatar img { width: 130%; margin: 2px 0 0 -15%; display: block; }
.turn-text { display: flex; flex-direction: column; line-height: 1.05; min-width: 0; }
.turn-text b { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.turn-text b em { font-style: normal; color: var(--c2); }
.turn-text small { font-size: 12.5px; font-weight: 600; opacity: .75; }
.tools { display: flex; gap: 8px; flex: none; }
.badge.pop { animation: pop .35s ease-out; }
@keyframes pop { 40% { transform: scale(1.08) rotate(-2deg); } }

/* ---------- hộp thoại: giấy kem, ruy băng vàng ---------- */
dialog { background: var(--cream); color: var(--ink); border: 3px solid var(--ink); border-radius: 22px; width: min(92vw, 420px);
  padding: 30px 16px 16px; box-shadow: 0 6px 0 var(--ink); overflow: visible; max-height: 88dvh; }
dialog[open] { animation: dlg .25s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes dlg { from { transform: scale(.85); opacity: 0; } }
dialog::backdrop { background: rgba(10, 8, 30, .6); }
.ribbon { position: absolute; left: 50%; top: -22px; transform: translateX(-50%); margin: 0; padding: 4px 26px; font-size: 20px; font-weight: 800; white-space: nowrap;
  background: linear-gradient(#ffe08a, var(--gold)); border: 3px solid var(--ink); border-radius: 14px; box-shadow: 0 4px 0 var(--ink); }
dialog label { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 8px 0; font-size: 15px; font-weight: 600; }
dialog label.check { justify-content: space-between; flex-direction: row-reverse; }
dialog select { appearance: none; -webkit-appearance: none; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%233a2410' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 10px center / 12px;
  color: var(--ink); border: 2.5px solid var(--ink); border-radius: 12px; padding: 6px 30px 6px 10px; font: 600 15px 'Baloo 2', system-ui; min-height: 40px; }
/* công tắc bật/tắt */
.switch { appearance: none; -webkit-appearance: none; width: 50px; height: 28px; flex: none; border-radius: 99px; border: 2.5px solid var(--ink); background: #d8cdb4;
  position: relative; cursor: pointer; transition: background .15s; margin: 0; }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 19px; height: 19px; border-radius: 50%; background: #fff; border: 2.5px solid var(--ink); transition: left .15s; }
.switch:checked { background: #7fcf6a; }
.switch:checked::after { left: 23px; }

dialog ul { padding-left: 20px; line-height: 1.45; font-size: 15px; font-weight: 600; margin: 4px 0; }
dialog p { font-size: 15px; font-weight: 600; margin: 6px 0; }
.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.credit { font-size: 12.5px !important; opacity: .75; }
.credit a { color: inherit; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }
[hidden] { display: none !important; }

/* avatar: quân tướng của phe đang tới lượt */
.avatar { display: grid !important; place-items: center; background: radial-gradient(circle at 40% 35%, #fff7e2, #f2d9a6) !important; }
.avatar b { font: 700 24px/1 KaiTi, STKaiti, "Kaiti SC", "Noto Serif CJK SC", serif; color: var(--c); }

/* ---------- sân khấu ---------- */
#stage { position: relative; flex: 1; min-height: 0; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.caps { position: absolute; left: 10px; right: 10px; display: flex; flex-wrap: wrap; gap: 3px; pointer-events: none; min-height: 0; }
.caps.top { top: 2px; }
.caps.bot { bottom: 2px; justify-content: flex-end; }
.cap-chip { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: #fff3d6; border: 2px solid var(--ink);
  font: 700 13px/1 KaiTi, STKaiti, "Kaiti SC", "Noto Serif CJK SC", "Baloo 2", serif; box-shadow: 0 2px 0 var(--ink); }
.cap-chip.red { color: #c4281f; } .cap-chip.black { color: #22305c; }

/* ---------- thanh dưới ---------- */
#bar { padding: 4px 10px 10px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.speech { position: relative; background: var(--cream); border: 3px solid var(--ink); border-radius: 18px; padding: 5px 12px; font-size: 14.5px; font-weight: 600;
  line-height: 1.3; height: calc(2.6em + 16px); overflow: hidden; margin-bottom: 10px; box-shadow: 0 3px 0 var(--ink); display: flex; align-items: center; }
.speech b { font-weight: 800; color: var(--c2); }
.row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.btn.act { min-height: 54px; border-radius: 16px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; padding: 4px 2px;
  font-size: 13.5px; line-height: 1.1; }
.btn.act svg { width: 22px; height: 22px; }
.btn.act.primary { padding: 4px 2px; min-height: 54px; border-radius: 16px; font-size: 13.5px; }
.btn.act:disabled { opacity: .5; }

/* ---------- biên bản ---------- */
.move-list { max-height: 55dvh; overflow: auto; margin: 4px 0; padding-left: 34px !important; font-size: 15px; font-weight: 700;
  background: #fff; border: 2.5px solid var(--ink); border-radius: 14px; padding-top: 6px !important; padding-bottom: 6px !important; }
.move-list li { padding: 1px 0; }
.move-list li span { display: inline-block; min-width: 5.5em; }
.mv-red { color: #c4281f; } .mv-black { color: #22305c; }
.move-list li.empty { list-style: none; margin-left: -20px; color: #8a7a5c; }

/* ---------- hết ván ---------- */
.end-img { display: block; width: 130px; height: 150px; object-fit: contain; margin: -4px auto 0; animation: hop 1.2s ease-in-out infinite; }
.end-text { text-align: center; font-size: 17px !important; font-weight: 800 !important; }
@keyframes hop { 0%, 60%, 100% { transform: none; } 70% { transform: translateY(-7px) scale(1.04, .97); } 80% { transform: translateY(0) scale(1.04, .96); } }

@media (min-width: 720px) {
  .row { max-width: 560px; margin: 0 auto; }
  .speech { max-width: 560px; margin-left: auto; margin-right: auto; }
}

/* ---------- âm thanh ---------- */
.btn.sound .ic-off { display: none; }
.btn.sound.off .ic-on { display: none; }
.btn.sound.off .ic-off { display: block; }
.btn.sound.off { opacity: .8; }
.no-audio .btn.sound { display: none; }

/* ---------- màn bắt đầu: ván máy chơi phía sau, chữ và nút phủ lên ---------- */
.start { position: fixed; inset: 0; display: none; flex-direction: column; justify-content: space-between; align-items: center; z-index: 20;
  pointer-events: none; padding: max(18px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom)); }
.at-start .start { display: flex; }
.at-start #top, .at-start #bar, .at-start .caps { display: none; }
.start > * { pointer-events: auto; }
.start-top { text-align: center; pointer-events: none; }
.start-bottom { width: min(100%, 440px); display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: linear-gradient(rgba(18, 15, 51, 0), rgba(18, 15, 51, .85) 22%); padding-top: 26px; border-radius: 24px; }
.logo { margin: 0; line-height: .9; font-weight: 800; color: #fff; -webkit-text-stroke: 9px var(--ink); paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--ink); animation: bob 3.2s ease-in-out infinite; }
.logo span { display: block; }
.logo .l1 { font-size: 46px; color: #ffe08a; transform: rotate(-6deg) translateX(-48px); }
.logo .l2 { font-size: 64px; color: #fff3cf; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-1deg); } }
.tag { margin: 8px 0 0; color: var(--cream); font-weight: 600; font-size: 15px; text-shadow: 0 2px 0 var(--ink); }
.btn.primary.big { width: 100%; min-height: 66px; border-radius: 22px; font-size: 30px; box-shadow: 0 6px 0 var(--ink), inset 0 -5px 0 rgba(160, 90, 0, .25), inset 0 3px 0 rgba(255, 255, 255, .6);
  animation: nudge 2.2s ease-in-out infinite; }
.btn.primary.big span { color: #fff; -webkit-text-stroke: 6px var(--ink); paint-order: stroke fill; text-shadow: 0 3px 0 var(--ink); }
.start-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; }
.start-tools > * { flex: none; }


/* nút chọn nhanh ở màn đầu */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; width: 100%; }
.seg button { border: 3px solid var(--ink); border-radius: 14px; background: linear-gradient(#fffaf0, var(--cream2)); box-shadow: 0 3px 0 var(--ink);
  font-weight: 800; font-size: 15px; min-height: 42px; padding: 2px 6px; display: flex; align-items: center; justify-content: center; gap: 4px; }
.seg button[aria-pressed="true"] { background: linear-gradient(#ffe08a, var(--gold)); transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.seg.side button { min-height: 58px; }
.seg.side img { width: 44px; height: 54px; object-fit: contain; margin: -14px 0 -4px; filter: drop-shadow(0 2px 0 rgba(58,36,16,.3)); }
.seg.side button[aria-pressed="true"] img { animation: hop 1.6s ease-in-out infinite; }
.start-bottom { gap: 8px !important; }

/* bong bóng thoại trên đầu quân */
.talk { position: absolute; left: 0; top: 0; pointer-events: none; background: #fff; border: 2.5px solid var(--ink); border-radius: 14px;
  padding: 2px 10px; font-weight: 800; font-size: 14px; white-space: nowrap; box-shadow: 0 3px 0 var(--ink); z-index: 3; animation: talkIn .25s cubic-bezier(.3,1.7,.5,1); }
.talk::after { content: ''; position: absolute; left: 50%; bottom: -8px; width: 10px; height: 10px; margin-left: -6px; background: #fff;
  border-right: 2.5px solid var(--ink); border-bottom: 2.5px solid var(--ink); transform: rotate(45deg); }
@keyframes talkIn { from { opacity: 0; margin-top: 8px; } }

/* nhãn "Chiếu!" bung ra giữa bàn */
.check-badge { position: absolute; left: 50%; top: 50%; width: 136px; height: 92px; margin: -46px 0 0 -68px; pointer-events: none; opacity: 0;
  background: url(assets/chibi/chieu.webp) center / contain no-repeat; display: grid; place-items: center; z-index: 4; }
.check-badge span { font-weight: 800; font-size: 25px; color: #c4281f; -webkit-text-stroke: 1.5px var(--ink); transform: rotate(-6deg); }
.check-badge.show { animation: badge 1.3s cubic-bezier(.2,1.5,.4,1) forwards; }
@keyframes badge { 0% { opacity: 0; transform: scale(.3) rotate(-14deg); } 18% { opacity: 1; transform: scale(1.12) rotate(4deg); }
  30% { transform: scale(1) rotate(0); } 80% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(.9) translateY(-14px); } }

/* bảng số liệu cuối ván */
.end-stats { list-style: none; padding: 8px 12px !important; margin: 0; background: #fff; border: 2.5px solid var(--ink); border-radius: 14px; }
.end-stats li { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; font-size: 14.5px; }
.end-stats li b { font-weight: 800; }
dialog label.check span { margin-right: auto; }
@media (prefers-reduced-motion: reduce) { .check-badge.show { animation-duration: .6s; } .logo, .btn.primary.big { animation: none; } }

/* thanh trên chật khi có 3 nút tròn */
#top .btn.round { width: 42px; height: 42px; }
#top .tools { gap: 6px; }
.turn-text b { font-size: 15.5px !important; }
.turn-text small { font-size: 12px !important; }

/* màn đầu ở màn rộng: logo + bảng chọn thành cột bên trái, bàn cờ nằm bên phải (main.js chừa chỗ cho cột) */
@media (min-aspect-ratio: 10/9) and (min-width: 700px) {
  .start { justify-content: center; align-items: flex-start; gap: 18px; padding-left: max(24px, env(safe-area-inset-left)); }
  .start-top, .start-bottom { width: 360px !important; }
  .start-bottom { background: rgba(18, 15, 51, .55); padding: 14px 12px 12px !important; }
}
@media (min-aspect-ratio: 10/9) and (min-width: 700px) and (max-height: 560px) {
  .start { gap: 6px; padding-top: 8px; padding-bottom: 8px; }
  .logo .l1 { font-size: 30px; } .logo .l2 { font-size: 42px; }
  .tag { display: none; }
  .start-bottom { gap: 5px !important; padding: 8px 10px !important; }
  .seg button { min-height: 34px; font-size: 14px; }
  .seg.side button { min-height: 40px; }
  .seg.side img { width: 32px; height: 40px; margin: -8px 0 -2px; }
  .btn.primary.big { min-height: 48px; font-size: 24px; }
  .start-tools .btn.chip { min-height: 36px; } .start-tools .btn.round { width: 40px; height: 40px; }
}

/* bảng hình quân trong Cách chơi */
.guide { list-style: none; padding: 0 !important; margin: 0 0 8px !important; display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 6px; }
.guide li { display: grid; grid-template-columns: 34px 34px 1fr; grid-template-rows: auto auto; align-items: center; column-gap: 2px;
  background: #fff; border: 2.5px solid var(--ink); border-radius: 12px; padding: 3px 6px; }
.guide img { width: 34px; height: 40px; object-fit: contain; grid-row: 1 / 3; }
.guide .g-han { font: 700 17px/1 KaiTi, STKaiti, "Kaiti SC", "Noto Serif CJK SC", serif; display: flex; gap: 4px; }
.guide .g-han .red { color: #c4281f; font-style: normal; } .guide .g-han .black { color: #22305c; font-style: normal; }
.guide b { font-size: 14px; line-height: 1.1; }
#rules { max-height: 90dvh; overflow: auto; }
.end-pics { display: flex; justify-content: center; }
.end-pics .end-img { margin-left: -10px; margin-right: -10px; }
.btn.resume { width: 100%; min-height: 48px; border-radius: 18px; font-size: 17px; background: linear-gradient(#e8f7d8, #a8dc8a); }
/* hộp Cách chơi cuộn được nên ruy băng không đặt lấn ra ngoài (sẽ bị cắt) */
#rules { padding-top: 14px; }
#rules .ribbon { position: relative; left: auto; top: auto; transform: none; display: table; margin: 0 auto 10px; }
