@font-face { font-family: "Alegreya SC"; src: url(fonts/AlegreyaSC-Regular.ttf) format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Alegreya SC"; src: url(fonts/AlegreyaSC-Bold.ttf) format("truetype"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Alegreya Sans"; src: url(fonts/AlegreyaSans-Regular.ttf) format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Alegreya Sans"; src: url(fonts/AlegreyaSans-Bold.ttf) format("truetype"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Alegreya Sans"; src: url(fonts/AlegreyaSans-Italic.ttf) format("truetype"); font-weight: 400; font-style: italic; font-display: swap; }

:root {
  --paper: #E9DFC7; --fold: #D6C8A6; --ink: #1F1A17; --black: #17110E; --red: #5A2418;
  --son: #B2321F; --gold: #C9A14A; --egg: #F1EBDD; --river: #3E5F73; --green: #5E7A4F;
  --minh: #4F5F6E; --ochre: #B07A2A; --teal: #4C7C76;
  --topH: 60px; --barH: 54px; --cardW: 300px; --dipW: 250px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #cdbf9c; color: var(--egg);
  font-family: "Alegreya Sans", system-ui, sans-serif; font-size: 16px; line-height: 1.5; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
#game { position: fixed; inset: 0; }
#game canvas { display: block; }
#b3d { position: absolute; inset: 0; touch-action: none; z-index: 1; }
#bcmd .rot { min-width: 44px; font-size: 20px; padding: 0 8px; }
body:not(.b3d-on) #bcmd .rot { display: none; }
button { font: inherit; color: inherit; cursor: pointer; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.sc { font-family: "Alegreya SC", serif; }

/* ---------- lacquer ---------- */
.lac { position: absolute; background: var(--black) url(img/lacquer_black.webp) center / 512px; box-shadow: 4px 4px 0 rgba(23, 17, 14, .55); }
.lac.red { background: var(--red) url(img/lacquer_red.webp) center / 512px; }
.lac::before { content: ""; position: absolute; inset: 4px; border: 1px solid var(--gold); pointer-events: none; }
.lac > .cn { position: absolute; width: 22px; height: 22px; background: url(img/corner_inlay.webp) center / contain no-repeat; pointer-events: none; z-index: 2; }
.lac > .cn.tl { left: 1px; top: 1px; }
.lac > .cn.tr { right: 1px; top: 1px; transform: scaleX(-1); }
.lac > .cn.bl { left: 1px; bottom: 1px; transform: scaleY(-1); }
.lac > .cn.br { right: 1px; bottom: 1px; transform: scale(-1, -1); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 6px 14px; border: 1px solid var(--gold);
  background: var(--black) url(img/lacquer_black.webp) center / 300px; color: var(--egg); font-size: 15px; border-radius: 0; box-shadow: 2px 2px 0 rgba(0,0,0,.5); }
.btn:hover:not(:disabled) { outline: 1px solid var(--gold); outline-offset: 2px; }
.btn:active:not(:disabled) { transform: translate(1px, 1px); box-shadow: 1px 1px 0 rgba(0,0,0,.5); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.son { background: var(--son); border-color: #7d1f12; color: var(--egg); }
.btn.on { border-color: var(--gold); box-shadow: inset 0 0 0 2px var(--gold); }
.btn img { width: 26px; height: 26px; object-fit: contain; }

.seal { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; background: var(--son); flex: none; box-shadow: inset 0 0 0 2px rgba(241,235,221,.25); }
.seal img { width: 78%; height: 78%; object-fit: contain; }

/* ---------- top strip ---------- */
#top { left: 0; right: 0; top: 0; height: var(--topH); display: flex; align-items: center; gap: 10px; padding: 0 12px; z-index: 10; }
#top .seal { width: 44px; height: 44px; }
#date { font-family: "Alegreya SC", serif; font-size: 20px; white-space: nowrap; perspective: 400px; }
#date span { display: inline-block; transform-origin: 50% 0; }
#date span.flip { animation: flip .6s ease; }
@keyframes flip { 0% { transform: rotateX(0); } 45% { transform: rotateX(90deg); opacity: .2; } 55% { transform: rotateX(-90deg); opacity: .2; } 100% { transform: rotateX(0); } }
#res { display: flex; gap: 4px; margin-left: auto; }
.res { display: flex; align-items: center; gap: 6px; padding: 2px 10px; border-left: 1px solid rgba(201,161,74,.45); min-width: 120px; }
.res img { width: 34px; height: 34px; object-fit: contain; }
.res .l { font-size: 14px; color: #d9cfb8; line-height: 1.3; }
.res .v { font-size: 17px; font-weight: 700; line-height: 1.3; }
.res .d { font-size: 14px; margin-left: 4px; font-weight: 400; }
.up { color: #9fc48a; } .down { color: #e58b78; }
.tbb { display: flex; gap: 6px; border-left: 1px solid rgba(201,161,74,.45); padding-left: 10px; }
.icobtn { width: 42px; height: 42px; min-height: 0; padding: 0; font-family: "Alegreya SC", serif; font-size: 20px; }

/* ---------- objective ---------- */
#objective { position: absolute; left: calc(var(--cardW) + 22px); top: calc(var(--topH) + 10px); z-index: 5; padding: 4px 12px; background: rgba(233,223,199,.9); color: var(--ink); font-size: 15px; border: 1px solid var(--ink); box-shadow: 3px 3px 0 rgba(23,17,14,.35); }
#objective b { color: var(--son); }
#objective { padding-right: 96px; }
#objective .drill { position: absolute; right: 8px; top: 5px; min-height: 30px; padding: 0 8px; font-size: 14px; }
#objective .mode { color: var(--son); }
/* hai chế độ chơi, như hai lối vào một cuốn sách */
.modes { display: flex; gap: 10px; margin-top: 12px; text-align: left; }
.modecard { flex: 1; padding: 7px 9px; border: 1px solid rgba(201,161,74,.55); background: rgba(23,17,14,.35); }
.modecard b { display: block; font-family: "Alegreya SC", serif; font-size: 17px; color: var(--gold); }
.modecard span { font-size: 14px; line-height: 1.45; color: #e8dcc6; }
/* chọn màn Diễn nghĩa: mỗi chương là một thẻ trên tờ chiếu */
.scen { margin: 8px 0; padding: 8px 10px; border: 1px solid rgba(31,26,23,.35); background: rgba(214,200,166,.35); }
.scen .sn b { font-family: "Alegreya SC", serif; font-size: 18px; color: var(--son); }
.scen .sn .lv { display: block; font-size: 14px; color: #5a4a3a; margin-top: 1px; }
.scen p { margin: 4px 0 0; font-size: 15px; line-height: 1.5; color: #33271d; }
.btn.hero { background: var(--gold); color: var(--ink); border-color: var(--egg); font-family: "Alegreya SC", serif; }
#objective .coach { font-size: 14px; color: #3b2d22; border-top: 1px solid rgba(31,26,23,.25); margin-top: 2px; padding-top: 2px; max-width: min(520px, calc(100vw - 40px)); }
#objective .snote { font-size: 14px; line-height: 1.4; color: #4a3a2c; max-width: min(560px, calc(100vw - 40px)); }

/* ---------- left card ---------- */
#card { left: 8px; top: calc(var(--topH) + 10px); width: var(--cardW); bottom: calc(var(--barH) + 16px); z-index: 8; padding: 14px 14px 12px; display: flex; flex-direction: column; overflow: hidden; }
#card .scroller { overflow-y: auto; flex: 1; min-height: 0; margin: 0 -4px; padding: 0 4px; scrollbar-width: thin; scrollbar-color: var(--gold) transparent; }
.ch { display: flex; gap: 10px; align-items: flex-start; }
.ch > div:last-child { flex: 1 1 auto; min-width: 0; }
.pt { position: relative; width: 100px; height: 112px; flex: none; border: 1px solid var(--gold); background: var(--paper); }
.pt img.face { width: 100%; height: 100%; object-fit: cover; display: block; }
.pt .seal { position: absolute; left: -1px; bottom: -1px; width: 28px; height: 28px; }
.name { font-family: "Alegreya SC", serif; font-size: 24px; line-height: 1.3; }
.sub { font-size: 15px; color: #e0d3bd; }
.quote { font-style: italic; font-size: 15px; color: #e8dcc6; margin-top: 4px; }
.stats { margin: 10px 0 6px; border-top: 1px solid rgba(201,161,74,.5); padding-top: 6px; }
.stat { display: flex; align-items: center; gap: 8px; font-size: 15px; min-height: 28px; }
.stat img { width: 24px; height: 24px; object-fit: contain; }
.stat .v { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.dots { margin-left: auto; letter-spacing: 3px; font-size: 15px; white-space: nowrap; }
.dots i { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--egg); margin-left: 4px; }
.dots i.f { background: var(--egg); }
.sec { font-family: "Alegreya SC", serif; font-size: 18px; margin: 8px 0 4px; border-top: 1px solid rgba(201,161,74,.5); padding-top: 4px; }
.roster { background: var(--paper) url(img/paper_tile.webp) center / 400px; color: var(--ink); border: 1px solid var(--gold); padding: 2px 6px; }
.urow { display: flex; align-items: center; gap: 8px; min-height: 40px; border-bottom: 1px solid rgba(31,26,23,.18); font-size: 15px; }
.urow:last-child { border-bottom: 0; }
.urow img { width: 34px; height: 34px; object-fit: contain; }
.urow .n { flex: 1; }
.urow .nt { letter-spacing: 1px; font-size: 14px; color: var(--ink); white-space: nowrap; }
.urow .m { width: 52px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.notch { display: inline-block; width: 3px; height: 13px; margin-right: 2px; background: var(--ink); vertical-align: middle; }
.notch.e { background: rgba(31,26,23,.2); }
.acts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; flex: none; }
.act { flex-direction: column; gap: 2px; min-height: 66px; padding: 6px 4px; font-size: 14px; line-height: 1.25; }
.act img { width: 30px; height: 30px; }
.confirm { margin-top: 10px; padding: 8px; border: 1px solid var(--gold); background: rgba(23,17,14,.5); font-size: 15px; }
.confirm .row { display: flex; gap: 8px; margin-top: 6px; }
.confirm .row .btn { flex: 1; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px 2px 2px; margin: 3px 4px 3px 0; border: 1px solid rgba(201,161,74,.6); background: rgba(23,17,14,.35); font-size: 15px; min-height: 36px; }
.chip .seal { width: 30px; height: 30px; }
.empty { font-size: 15px; color: #e0d3bd; padding: 6px 0; }
.blist { font-size: 15px; }
.blist div { display: flex; justify-content: space-between; gap: 8px; min-height: 30px; align-items: center; }
.cardx { position: absolute; right: 10px; top: 8px; z-index: 3; width: 34px; height: 34px; min-height: 0; padding: 0; font-size: 18px; }

/* ---------- diplomacy drawer ---------- */
#dipl { right: 8px; top: calc(var(--topH) + 10px); width: var(--dipW); z-index: 8; padding: 8px; max-height: calc(100% - var(--topH) - var(--barH) - 170px); display: flex; flex-direction: column; }
#dipl .dh { font-family: "Alegreya SC", serif; font-size: 20px; padding: 2px 8px 4px; display: flex; align-items: center; }
#dipl .dh button { margin-left: auto; min-height: 30px; width: 30px; padding: 0; border: 1px solid var(--gold); background: transparent; }
#dipl .dl { overflow-y: auto; background: var(--paper) url(img/paper_tile.webp) center / 400px; color: var(--ink); border: 1px solid var(--gold); }
#dipl.closed .dl, #dipl.closed .dh2 { display: none; }
.dh2 { font-family: "Alegreya SC", serif; font-size: 18px; padding: 2px 8px; background: var(--black); color: var(--egg); }
.drow { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-bottom: 1px solid rgba(31,26,23,.2); cursor: pointer; min-height: 52px; }
.drow:hover { background: rgba(201,161,74,.18); }
.drow .seal { width: 36px; height: 36px; }
.drow .nm { font-size: 15px; line-height: 1.3; }
.drow .st { font-size: 14px; line-height: 1.3; }
.drow .ic { margin-left: auto; width: 26px; height: 26px; object-fit: contain; }
.st.war { color: #9b2614; } .st.ally { color: #3f6a35; } .st.unrest { color: #9b2614; } .st.neutral { color: #4b4038; } .st.truce { color: #2d5566; }

/* ---------- bottom bar & seal ---------- */
#bar { left: 8px; right: 150px; bottom: 8px; height: var(--barH); z-index: 9; display: flex; align-items: stretch; padding: 5px 8px; }
#bar button { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; background: none; border: 0; border-right: 1px solid rgba(201,161,74,.35); font-size: 15px; color: var(--egg); min-width: 0; position: relative; }
#bar button:last-child { border-right: 0; }
#bar button img { width: 30px; height: 30px; object-fit: contain; }
#bar button.on { box-shadow: inset 0 -3px 0 var(--gold); }
#bar button .badge { position: absolute; top: 4px; right: 10%; width: 9px; height: 9px; border-radius: 50%; background: var(--son); }
#bar .tabdip { display: none; }
#bar .sm { display: none; }
#endturn { position: absolute; right: 8px; bottom: 6px; width: 132px; height: 132px; z-index: 11; border: 0; padding: 0; background: url(img/seal_button.webp) center / contain no-repeat; color: var(--egg); font-family: "Alegreya SC", serif; font-size: 22px; line-height: 1.15; text-shadow: 0 1px 0 rgba(60,10,4,.6); }
#endturn span { display: block; padding: 0 22px; }
#endturn.press { animation: press .42s ease-out; }
#endturn:disabled { filter: saturate(.4) brightness(.8); }
@keyframes press { 0% { transform: scale(1.15) rotate(0); } 60% { transform: scale(.98) rotate(2deg); } 100% { transform: scale(1) rotate(0); } }
#stamp { position: fixed; z-index: 12; width: 120px; height: 120px; pointer-events: none; background: rgba(178,50,31,.0); border: 6px solid rgba(178,50,31,.75); display: flex; align-items: center; justify-content: center; opacity: 0; }
#stamp img { width: 76%; filter: brightness(0) saturate(100%) invert(26%) sepia(60%) saturate(2500%) hue-rotate(350deg); opacity: .85; }
#stamp.show { animation: stamp 1.1s ease-out; }
@keyframes stamp { 0% { opacity: 0; transform: scale(1.15) rotate(-3deg); } 15% { opacity: .9; transform: scale(1) rotate(2deg); } 70% { opacity: .55; } 100% { opacity: 0; } }

/* ---------- sheet (tab popups) ---------- */
#sheet { left: calc(var(--cardW) + 22px); bottom: calc(var(--barH) + 16px); width: min(460px, calc(100% - var(--cardW) - 40px)); max-height: calc(100% - var(--topH) - var(--barH) - 40px); z-index: 12; padding: 14px; display: flex; flex-direction: column; }
#sheet .sh { font-family: "Alegreya SC", serif; font-size: 22px; display: flex; align-items: center; margin-bottom: 6px; }
#sheet .sh button { margin-left: auto; }
#sheet .sb { overflow-y: auto; min-height: 0; }
.li { display: flex; align-items: center; gap: 10px; padding: 6px; border-bottom: 1px solid rgba(201,161,74,.3); min-height: 48px; }
.li img.pp { width: 40px; height: 44px; object-fit: cover; border: 1px solid var(--gold); }
.li img.ui { width: 36px; height: 36px; object-fit: contain; }
.li .t { flex: 1; font-size: 15px; line-height: 1.35; }
.li .t small { display: block; font-size: 14px; color: #dccfb6; }
.li .btn { min-height: 36px; padding: 4px 10px; font-size: 14px; }
.why { font-size: 14px; color: #e9a493; }
.seg { display: flex; gap: 6px; margin: 6px 0 10px; }
.seg .btn { flex: 1; }

/* ---------- toast & busy ---------- */
#toast { position: fixed; left: 50%; top: calc(var(--topH) + 56px); transform: translateX(-50%); z-index: 30; background: rgba(23,17,14,.92); border: 1px solid var(--gold); padding: 6px 16px; font-size: 16px; color: var(--egg); max-width: 90vw; text-align: center; pointer-events: none; opacity: 0; transition: opacity .25s; }
#toast.show { opacity: 1; }

/* ---------- scroll modal ---------- */
#modal { position: fixed; inset: 0; z-index: 90; display: flex; align-items: center; justify-content: center; padding: 12px; contain: paint; }
#modal .dim { position: absolute; inset: 0; background: rgba(23,17,14,.55); }
/* the scroll is laid out whole from the first frame: no clipping animation on the way in, so the
   sheet is never a sliver with the map showing through it. The paper underneath is opaque. */
.scroll { position: relative; width: min(520px, 94vw); max-height: 94%; display: flex; flex-direction: column; color: var(--ink);
  background: #EDE3C8 url(img/paper_tile.webp) center / 420px;
  border-style: solid; border-width: 30px 30px 28px 30px; border-image: url(img/scroll.webp) 56 64 50 62 fill / 30px 30px 28px 30px stretch; box-shadow: 5px 6px 0 rgba(23,17,14,.5); }
#modal.closing { pointer-events: none; }
/* đóng là đóng ngay: một khung hình chụp lại đúng lúc đang mờ dần sẽ thành một tờ giấy
   trong suốt nằm trên bản đồ, và người xem chỉ thấy một bảng hỏng */


.scroll .in { overflow-y: auto; padding: 10px 14px 6px; min-height: 0; }
.scroll h2 { font-family: "Alegreya SC", serif; font-weight: 700; font-size: 27px; margin: 0 0 4px; text-align: center; line-height: 1.35; }
.scroll .kicker { text-align: center; font-size: 15px; color: #5a4a3a; }
.scroll p { margin: 8px 0; font-size: 16px; }
.scroll .verse { font-style: italic; text-align: center; color: #3b2d22; }
.scroll .stampseal { float: right; width: 58px; height: 58px; margin: 4px 0 6px 10px; transform: rotate(4deg); }
.scroll .btns { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; padding: 10px 6px 4px; flex: none; }
.scroll .btns .btn { min-width: 140px; }
.vs { display: flex; align-items: center; justify-content: space-around; gap: 6px; margin: 8px 0; }
.vs .side { text-align: center; flex: 1; }
.vs .side .seal { width: 56px; height: 56px; }
.vs .side .nm { font-family: "Alegreya SC", serif; font-size: 18px; }
.vs .side .mn { font-size: 15px; }
.vs .x { font-family: "Alegreya SC", serif; font-size: 22px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; }
.tbl td, .tbl th { padding: 3px 4px; border-bottom: 1px solid rgba(31,26,23,.2); text-align: right; }
.tbl td:first-child, .tbl th:first-child { text-align: left; }
.balance { position: relative; height: 150px; margin: 6px 0; }
.balance .post { position: absolute; left: 50%; bottom: 0; width: 6px; height: 104px; margin-left: -3px; background: var(--ink); }
.balance .base { position: absolute; left: 50%; bottom: 0; width: 80px; margin-left: -40px; height: 8px; background: var(--ink); }
.balance .beam { position: absolute; left: 10%; right: 10%; top: 40px; height: 5px; background: var(--ink); transform-origin: 50% 50%; transition: transform 1.3s cubic-bezier(.3,1.4,.5,1); }
.balance .pan { position: absolute; top: -50px; width: 60px; height: 60px; display: flex; align-items: center; justify-content: center; }
.balance .pan.l { left: -10px; } .balance .pan.r { right: -10px; }
.balance .pan .seal { width: 52px; height: 52px; transition: transform 1.3s cubic-bezier(.3,1.4,.5,1); }
.dipmeter { height: 10px; background: rgba(31,26,23,.15); border: 1px solid var(--ink); margin: 4px 0 8px; position: relative; }
.dipmeter i { position: absolute; top: 0; bottom: 0; background: var(--son); }
.scroll .li { border-bottom-color: rgba(31,26,23,.2); }
.scroll .li .t small { color: #5a4a3a; }
.scroll .why { color: #9b2614; }
.help dt { font-family: "Alegreya SC", serif; font-size: 17px; margin-top: 8px; }
.help dd { margin: 0 0 2px; font-size: 15px; }

/* ---------- title ---------- */
#title { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: #cdbf9c url(img/title_art.webp) center / cover; }
#title .tp { position: relative; padding: 26px 30px 22px; width: min(460px, 92vw); text-align: center; }
#title .tp h1 { font-family: "Alegreya SC", serif; font-size: 56px; margin: 0; line-height: 1.2; letter-spacing: 2px; }
#title .tp .tsub { font-size: 17px; color: #e7dbc4; margin: 2px 0 16px; }
#title .tp .big { width: 70px; height: 132px; margin: 0 auto 8px; display: flex; }
#title .tp .big img { width: 80%; height: auto; }
#title .tp .col { display: flex; flex-direction: column; gap: 10px; }
#title .tp .col .btn { min-height: 48px; font-size: 18px; }
#title .note { font-size: 14px; color: #d8ccb5; margin-top: 10px; }

/* ---------- battle hud ---------- */
#bhud { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
#bhud > * { pointer-events: auto; }
#bhead { left: 0; right: 0; top: 0; height: 56px; display: flex; align-items: center; gap: 10px; padding: 0 12px; }
#bhead .bs { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
#bhead .bs.r { flex-direction: row-reverse; text-align: right; }
#bhead .bs .seal { width: 38px; height: 38px; }
#bhead .bs .nm { font-family: "Alegreya SC", serif; font-size: 17px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#bhead .bs .nt { font-size: 14px; line-height: 1.3; white-space: nowrap; }
#bhead .mid { font-family: "Alegreya SC", serif; font-size: 18px; text-align: center; white-space: nowrap; }
.inkbar { display: inline-block; vertical-align: middle; }
.inkbar i { display: inline-block; width: 4px; height: 12px; margin-right: 2px; background: var(--egg); }
.inkbar i.e { background: rgba(241,235,221,.2); }
.inkbar.m i { background: #e46a52; } .inkbar.m i.e { background: rgba(228,106,82,.2); }
/* the named stage of the battle, and the clock of the fight */
#bphase { position: absolute; left: 10px; top: 58px; display: flex; align-items: center; gap: 10px; padding: 3px 12px; background: rgba(23,17,14,.86); border: 1px solid rgba(201,161,74,.7); pointer-events: none; }
#bphase .ph { font-family: "Alegreya SC", serif; font-size: 18px; color: var(--egg); letter-spacing: .5px; }
#bphase .ph.clash { color: #f0b49a; }
#bphase .ph.fire { color: #cfd9c2; }
#bphase .ph.break { color: #f0a98a; }
#bphase .ck { font-size: 15px; color: rgba(241,235,221,.8); font-variant-numeric: tabular-nums; }
#bphase .gd { font-size: 14px; color: var(--gold); border-left: 1px solid rgba(201,161,74,.5); padding-left: 8px; }
/* the diary of the fight, in the manner of a battle log */
#blog { position: absolute; right: 10px; top: 62px; width: min(340px, 40vw); padding: 5px 8px; background: rgba(23,17,14,.72); border: 1px solid rgba(201,161,74,.45); pointer-events: none; }
#blog .lh { font-family: "Alegreya SC", serif; font-size: 15px; color: var(--gold); border-bottom: 1px solid rgba(201,161,74,.35); padding-bottom: 2px; margin-bottom: 2px; }
#blog .ll { font-size: 14px; line-height: 1.45; color: rgba(241,235,221,.9); }
#blog .ll b { color: var(--gold); font-weight: 400; font-variant-numeric: tabular-nums; margin-right: 4px; }
#bcmd { left: 8px; right: 8px; bottom: 8px; display: flex; gap: 6px; padding: 6px 10px; flex-wrap: wrap; align-items: center; }
#bcmd .btn { min-height: 40px; padding: 3px 11px; }
#bcmd .grow { flex: 1; }
#bcmd .spd .btn { min-width: 44px; padding: 4px 8px; }
#bcmd .spd { display: flex; gap: 4px; }
/* unit cards, one per regiment: picture, men, strength and morale bars */
.bcards { display: flex; gap: 5px; width: 100%; overflow-x: auto; padding: 1px 0 3px; scrollbar-width: thin; scrollbar-color: var(--gold) transparent; }
.ucard { position: relative; flex: 0 0 68px; height: 74px; padding: 2px 2px 0; display: flex; flex-direction: column; align-items: center; background: var(--paper) url(img/paper_tile.webp) center / 300px; color: var(--ink); border: 1px solid var(--gold); box-shadow: 2px 2px 0 rgba(0,0,0,.45); cursor: pointer; font: inherit; }
.ucard img { width: 40px; height: 34px; object-fit: contain; }
.ucard .un { font-size: 14px; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.ucard .um { font-size: 14px; line-height: 1.2; font-weight: 700; white-space: nowrap; letter-spacing: -0.3px; }
.ucard i { position: absolute; left: 3px; right: 3px; height: 3px; background: rgba(31,26,23,.18); }
.ucard i b { display: block; height: 100%; }
.ucard .hp { bottom: 9px; } .ucard .hp b { background: var(--ink); }
.ucard .mo { bottom: 5px; } .ucard .mo b { background: var(--son); }
/* sức lực: hành quân và giao chiến làm quân mệt, nghỉ thì lại sức */
.ucard .st { bottom: 1px; } .ucard .st b { background: #5E7A4F; }
/* vai trò của đơn vị, đọc được bằng màu viền */
.ucard.role-arc { border-left: 3px solid #3E5F73; }
.ucard.role-cav { border-left: 3px solid #B07A2A; }
.ucard.role-art { border-left: 3px solid #5E7A4F; }
.ucard.role-ele { border-left: 3px solid var(--son); }
.ucard .ug { position: absolute; top: 1px; right: 1px; font-size: 14px; line-height: 1; padding: 1px 3px; background: var(--son); color: var(--egg); }
/* what state the regiment is in, in one word */
.ucard .uw { position: absolute; top: 1px; left: 1px; font-size: 14px; line-height: 1; padding: 1px 3px; background: rgba(23,17,14,.75); color: var(--egg); }
.ucard .uw.shake { background: #8a5a1c; }
.ucard .uw.rout { background: var(--son); }
.ucard.on { outline: 2px solid var(--gold); outline-offset: 1px; background-color: #f6eccf; transform: translateY(-3px); }
.ucard.rout { filter: sepia(.6) saturate(1.6) hue-rotate(-20deg); }
.ucard.dead { opacity: .35; filter: grayscale(1); }
/* the general's own qualities, shown as seals under the name */
.traits { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.trait { font-size: 14px; line-height: 1.3; padding: 0 6px; border: 1px solid var(--gold); color: var(--egg); background: rgba(23,17,14,.35); white-space: nowrap; }
/* the general's own named trait, told apart from the plain numbers */
.trait.tr { border-color: var(--son); color: #f3d9c9; background: rgba(178,50,31,.35); }
/* where he stands on the ladder of rank */
.rankrow { display: flex; align-items: center; gap: 6px; margin-top: 5px; flex-wrap: wrap; }
.rankrow .rk { font-family: var(--display); font-size: 15px; color: var(--egg); }
.rankrow .rx { font-size: 14px; line-height: 1.4; color: rgba(241,235,221,.75); font-variant-numeric: tabular-nums; }
.inkbar.g i { background: var(--gold); } .inkbar.g i.e { background: rgba(201,161,74,.22); }
/* a danger the player can still act on */
.warn { margin: 6px 0 2px; padding: 5px 8px; font-size: 15px; line-height: 1.45; color: #f6ded2; background: rgba(178,50,31,.5); border-left: 3px solid var(--son); }
.note2 { font-size: 15px; line-height: 1.5; color: rgba(241,235,221,.82); margin: 2px 0 6px; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.stat.warnstat .v.dang { color: #ffd9a0; }
/* a roster row is a button: it opens the unit's own sheet */
button.urow { width: 100%; background: none; border: 0; border-bottom: 1px solid rgba(31,26,23,.18); color: inherit; font: inherit; text-align: left; cursor: pointer; padding: 0; }
button.urow:hover { background: rgba(201,161,74,.18); }
#card button.urow { border-bottom-color: rgba(241,235,221,.15); }
#card button.urow:hover { background: rgba(201,161,74,.14); }
#bhint { position: absolute; left: 10px; top: 94px; transform: none; background: rgba(233,223,199,.94); color: var(--ink); border: 1px solid var(--ink); padding: 3px 10px; font-size: 14px; line-height: 1.4; text-align: left; max-width: min(520px, 52vw); pointer-events: none; }

/* ---------- compact landscape (phone held sideways) ---------- */
@media (max-height: 560px) and (min-width: 701px) {
  :root { --topH: 46px; --barH: 44px; --cardW: 262px; --dipW: 220px; }
  #top .seal { width: 34px; height: 34px; }
  #date { font-size: 16px; }
  .res { min-width: 0; padding: 0 6px; }
  .res img { width: 26px; height: 26px; }
  .res .l { display: none; }
  .res .v { font-size: 15px; }
  .icobtn { width: 36px; height: 36px; font-size: 17px; }
  #card { padding: 10px 10px 8px; }
  .pt { width: 70px; height: 80px; }
  .name { font-size: 20px; }
  .quote { display: none; }
  .act { min-height: 50px; font-size: 14px; }
  .act img { width: 22px; height: 22px; }
  #bar button { font-size: 14px; gap: 4px; }
  #bar button img { width: 24px; height: 24px; }
  #bar button .lg { display: none; }
  #bar button .sm { display: inline; white-space: nowrap; }
  /* the general's card fits without a scroll: stats in two columns, roster as tiles */
  .ch .pt { width: 52px; height: 60px; flex: none; }
  .ch .name { font-size: 19px; line-height: 1.25; }
  .ch .sub { font-size: 14px; line-height: 1.3; }
  #card .stats { display: grid; grid-template-columns: repeat(3, auto); justify-content: space-between; gap: 0 8px; margin: 6px 0 4px; padding-top: 4px; }
  #card .stat .lb { display: none; }
  #card .stat .v { margin-left: 0; }
  #card .stat .dots { margin-left: 0; }
  #card .traits { display: none; }
  #card .note2 { display: none; }
  .ucard { flex: 0 0 60px; height: 50px; }
  .ucard img { width: 28px; height: 24px; }
  .ucard .ug { font-size: 14px; padding: 0 2px; }
  .bcards { padding: 0 0 2px; }
  .ucard .un { display: none; }
  #card .stat { font-size: 14px; min-height: 24px; gap: 5px; white-space: nowrap; }
  #card .stat img { width: 18px; height: 18px; }
  #card .dots { letter-spacing: 0; }
  #card .dots i { width: 9px; height: 9px; margin-left: 2px; }
  #card .sec { font-size: 15px; margin: 2px 0 3px; padding-top: 2px; }
  #card .roster { display: grid; grid-auto-flow: column; grid-auto-columns: calc((100% - 10px) / 6); gap: 2px; padding: 2px; overflow-x: auto; scrollbar-width: thin; }
  #card .urow { min-height: 0; gap: 0; border: 0; font-size: 14px; flex-direction: column; line-height: 1.2; }
  #card .urow img { width: 24px; height: 24px; }
  #card .urow .m { text-align: center; }
  #card .sec { display: none; }
  #card .chip, #card [data-merge] { min-height: 28px !important; height: 28px; padding: 0 6px; margin: 0 4px 0 0; font-size: 14px; vertical-align: middle; }
  #card .chip .seal { width: 20px; height: 20px; }
  #card .urow .n, #card .urow .nt { display: none; }
  #card .urow .m { width: auto; flex: 1; text-align: left; }
  #card .acts { margin-top: 6px; gap: 6px; }
  #card .act { min-height: 46px; flex-direction: column; gap: 0; padding: 2px; white-space: nowrap; font-size: 14px; }
  #card .act img { width: 18px; height: 18px; }
  #dipl { width: 206px; padding: 6px; }
  #dipl .dh { font-size: 17px; padding: 0 4px 2px; }
  #dipl .dh2 { font-size: 15px; }
  .drow { min-height: 34px; padding: 3px 6px; gap: 6px; }
  .drow .seal { width: 26px; height: 26px; }
  .drow .nm { font-size: 14px; line-height: 1.2; }
  .drow .st { font-size: 14px; line-height: 1.2; }
  .drow .ic { width: 20px; height: 20px; }
  #endturn { width: 96px; height: 96px; font-size: 17px; }
  #bar { right: 110px; }
  #objective { font-size: 14px; padding: 2px 8px; }
  #dipl { max-height: calc(100% - var(--topH) - var(--barH) - 26px); }
  #bhead { height: 48px; }
  #bcmd { padding: 4px 8px; }
  #bcmd .btn { min-height: 38px; font-size: 14px; }
}
@media (max-width: 1100px) and (min-width: 701px) {
  .res .l { display: none; }
  .res { min-width: 0; }
  #dipl { --dipW: 220px; }
}

/* ---------- portrait / narrow ---------- */
@media (max-width: 700px) {
  :root { --topH: 92px; --barH: 58px; --cardW: 100%; }
  #top { flex-wrap: wrap; height: var(--topH); padding: 6px 8px 4px; gap: 4px 8px; align-content: flex-start; }
  #top .seal { width: 32px; height: 32px; }
  #date { font-size: 15px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .tbb { border: 0; padding: 0; gap: 4px; }
  .icobtn { width: 36px; height: 36px; font-size: 17px; }
  #res { order: 5; width: 100%; margin: 0; justify-content: space-between; gap: 0; }
  .res { min-width: 0; padding: 0 4px; border: 0; gap: 4px; }
  .res img { width: 24px; height: 24px; }
  .res .l { display: none; }
  .res .v { font-size: 15px; }
  .res .d { font-size: 14px; margin-left: 2px; }
  #objective { left: 8px; top: calc(var(--topH) + 8px); font-size: 14px; padding: 2px 8px; right: auto; }
  #card { left: 0; right: 0; width: auto; top: auto; bottom: calc(var(--barH) + 10px); max-height: 48%; padding: 12px 12px 10px; }
  #card.min .scroller { display: none; }
  .pt { width: 64px; height: 72px; }
  .name { font-size: 20px; }
  .quote { display: none; }
  .act { min-height: 52px; }
  .act img { width: 22px; height: 22px; }
  #bar { left: 0; right: 0; bottom: 0; height: var(--barH); padding: 4px 96px 4px 4px; }
  #bar button { flex-direction: column; gap: 0; font-size: 14px; line-height: 1.2; }
  #bar button img { width: 24px; height: 24px; }
  #bar button span { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  #bar .tabdip { display: flex; }
  #bar .lg { display: none; }
  #bar .sm { display: inline; }
  #card.min .ch .sub { display: none; }
  #card.min .pt { width: 48px; height: 54px; }
  #bhead { height: 60px; padding: 0 8px; gap: 6px; }
  #bhead .mid { display: none; }
  #bhead .bs .nm { font-size: 15px; }
  #bcmd { left: 0; right: 0; bottom: 0; padding: 6px; gap: 4px; }
  #bcmd .btn { min-height: 38px; padding: 2px 4px; font-size: 14px; flex: 1 1 22%; }
  #bcmd .grow { display: none; }
  #bcmd .spd { width: 100%; }
  #bcmd .spd .btn { flex: 1; min-height: 38px; }
  #card.min .name { font-size: 18px; }
  #card.min .acts { margin-top: 6px; }
  #endturn { width: 92px; height: 92px; right: 2px; bottom: 4px; font-size: 16px; }
  #endturn span { padding: 0 14px; }
  #dipl { left: 8px; right: 8px; width: auto; top: calc(var(--topH) + 8px); max-height: calc(100% - var(--topH) - var(--barH) - 30px); z-index: 13; }
  #dipl.closed { display: none; }
  #sheet { left: 0; right: 0; width: auto; bottom: calc(var(--barH) + 6px); max-height: calc(100% - var(--topH) - var(--barH) - 20px); }
  #bhint { top: 92px; left: 8px; max-width: 62vw; font-size: 14px; }
  #bphase { padding: 2px 8px; }
  #bphase .ph { font-size: 16px; }
  #blog { width: min(300px, 46vw); }
  #title .tp h1 { font-size: 44px; }
}

/* màn hình thấp (điện thoại nằm ngang): thu gọn thanh lệnh để trận địa không bị che */
@media (max-height: 620px) {
  #bhead { height: 46px; }
  #bhead .bs .seal { width: 32px; height: 32px; }
  #bphase { top: 48px; padding: 2px 8px; }
  #bphase .ph { font-size: 16px; }
  #blog { top: 50px; }
  #bhint { top: 78px; }
  #bcmd { padding: 4px 8px; gap: 5px; }
  #bcmd .btn { min-height: 34px; padding: 2px 9px; font-size: 14px; }
  #bcmd .spd .btn { min-width: 38px; }
  .ucard { height: 58px; flex: 0 0 56px; padding: 1px 1px 0; }
  .ucard img { width: 30px; height: 26px; }
  .bcards { padding: 0 0 1px; }
}

/* ---------- motion: panels slide in like lacquer screens being set down ---------- */
@keyframes setdown { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes slidein-l { from { opacity: 0; transform: translateX(-18px); } to { opacity: 1; transform: none; } }
#card { animation: slidein-l .32s ease-out; }
#sheet:not(.hidden), #dipl { animation: setdown .3s ease-out; }
.btn, .ucard, .drow, #bar button { transition: transform .12s ease-out, box-shadow .12s ease-out, background-color .12s; }
.btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 3px 3px 0 rgba(0,0,0,.5); }
.ucard:hover { transform: translateY(-2px); }
#bar button:hover img { transform: translateY(-2px); transition: transform .12s; }
.urow { animation: setdown .25s ease-out both; }
.urow:nth-child(2) { animation-delay: .03s; } .urow:nth-child(3) { animation-delay: .06s; } .urow:nth-child(4) { animation-delay: .09s; } .urow:nth-child(5) { animation-delay: .12s; } .urow:nth-child(n+6) { animation-delay: .15s; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
