/* Viewport-sized layout, including Safari's changing browser bars and notches. */
:root{--safe-top:env(safe-area-inset-top,0px);--safe-bottom:env(safe-area-inset-bottom,0px);
  /* 底部 Home 条只拦上滑手势，点按不受影响，界面底下自己也留着十几像素边距：
     不再把整条安全区空出来（iPad 横屏 25、iPhone 横屏 21 全部收回，iPhone 竖屏 34 只留 8），布局贴到屏幕底 */
  --home-gap:max(0px,calc(var(--safe-bottom) - 26px));
  --safe-left:env(safe-area-inset-left,0px);--safe-right:env(safe-area-inset-right,0px)}
/* 高度不用 100dvh：iPad、iPhone「添加到主屏幕」全屏打开时它比屏幕短一截，
   对局底下会露出一条黑边。固定定位上下都贴边，跟的就是真实的可视区域。 */
.screen{inset:0;height:auto}
#gameScreen{inset:var(--safe-top) var(--safe-right) var(--home-gap) var(--safe-left);height:auto}
/* 安全区（底部 Home 条、刘海两侧、状态栏）不放可点的东西，但也别露黑：
   战场背景往外铺出去，底栏的深色往下接，状态栏那一溜用工具条的颜色 */
#battleScenery{left:calc(-1 * var(--safe-left));right:calc(-1 * var(--safe-right));bottom:calc(-1 * var(--home-gap))}
#selfArea{box-shadow:0 var(--home-gap) 0 #090e16}
body:has(#gameScreen:not(.hidden)){background:#10161d}
#menuPanel{max-height:calc(100dvh - 64px - var(--safe-top) - var(--safe-bottom));overflow-y:auto;overscroll-behavior:contain}
.modal{padding:calc(12px + var(--safe-top)) calc(12px + var(--safe-right)) calc(12px + var(--safe-bottom)) calc(12px + var(--safe-left))}
.modal-box{min-width:0;max-width:100%;max-height:100%;overscroll-behavior:contain}
#startScreen,#overScreen{overflow-y:auto;overscroll-behavior:contain}
.start-inner{height:auto;min-height:100%;padding:24px 16px}
.start-panel{min-width:0;width:min(100%,460px)}
.subtitle{max-width:100%;text-align:center;line-height:1.7}
.over-inner{max-width:100%;padding:24px 12px;margin:auto}
#handCards{width:max-content;justify-content:flex-start}
#handArea{overscroll-behavior-x:contain;touch-action:pan-x}
button,.gcard,.seat,.card{touch-action:manipulation}
.hp-number{display:none}
.hp-num>.hp-number{display:flex;flex-direction:column;align-items:center;line-height:1.05}
#selfGeneral{position:relative;gap:0;grid-template-rows:auto}
#selfGeneral .self-side{position:absolute;left:0;bottom:calc(100% + 18px)}
#selfGeneral .self-side:has(.judge-chips:empty){display:none}

/* Centre the play prompt and buttons on the whole battlefield, not just the
   hand column to the right of the general and skill dock. */
@media(min-width:901px) and (min-height:601px){
  #controlPanel{position:absolute;left:50%;bottom:max(calc(var(--card-h) + 40px),var(--controls-bottom,0px));
    transform:translateX(-50%);width:min(620px,calc(100% - 2 * var(--seat-width,176px) - 48px))}
}

@media(max-width:900px),(max-height:600px){
  :root{--battle-log-width:0px;--dock-height:270px;--card-w:96px;--card-h:140px;
    --rail-w:24px;--art-h:min(calc(var(--seat-width,110px) * 1.15),var(--seat-box-max,9999px));
    --eq-row-h:clamp(10px,calc(var(--art-h) * .075),14px)}
  #logPanel{display:none}
  /* 状态栏：武将牌窄（手机上只有五十来像素），左右内边距、项间隔、字距照桌面的给就只剩三十多像素放字，
     两项就得各占一行，三项（星 7、安国、被无前）就超出两行被藏掉。这里收紧，两项能并排 */
  .seat .state-badge.eq-status,#selfGeneral .state-badge.eq-status{padding:0 3px;gap:0 .3em;letter-spacing:0}
  #table{right:0;bottom:var(--dock-height)}
  #selfArea{right:0;height:var(--dock-height);gap:10px;padding:0 12px 8px}
  #selfGeneral{padding:0;max-width:none}
  #selfGeneral .gcard{width:100%;height:var(--art-h)}
  .seat .s-art,#selfGeneral .s-art{aspect-ratio:auto}
  .seat .s-rail,#selfGeneral .s-rail{padding:14px 0 10px;gap:0}
  .s-rail .s-name,#selfGeneral .s-rail .gc-name{font-size:clamp(12px,calc(var(--art-h) * .085),17px);letter-spacing:0;line-height:1.05}
  .s-rail .s-name.n4,#selfGeneral .s-rail .gc-name.n4{font-size:clamp(11px,calc(var(--art-h) * .075),15px)}
  .s-rail .s-name.n5,#selfGeneral .s-rail .gc-name.n5{font-size:clamp(9px,calc(var(--art-h) * .065),13px)}
  .s-rail .s-hp,#selfGeneral .s-rail .gc-hp{display:block;width:100%;text-align:center;font:12px/16px system-ui;color:var(--hpc,#46c463)}
  .s-rail .s-hp .hp-bead,#selfGeneral .s-rail .gc-hp .hp-bead{display:none}
  .s-rail .hp-number{display:flex;flex-direction:column;align-items:center;line-height:1}
  .s-rail .s-hp.hp-num,#selfGeneral .s-rail .gc-hp.hp-num{font:12px/16px system-ui}
  .seat .s-mark{font-size:12px;top:-18px}
  .seat .equip-chip,#selfGeneral .equip-chip{gap:2px;padding:0 2px}
  .judge-chips{height:22px;min-height:22px;gap:4px}
  .judge-chip{width:20px;height:20px;border-radius:6px 2px 6px 2px}
  .judge-glyph{font-size:16px}
  #skillDock{width:116px;height:var(--art-h);max-height:100%;padding:4px}
  #skillDock .skill-action{min-height:44px;font-size:13px;padding:4px 2px}
  .skill-dock-head{font-size:13px}
  #handDock{gap:4px}
  #controlPanel{width:100%;padding:0;max-height:none;gap:3px;min-width:0;flex-shrink:0}
  #controlPanel #promptText{min-height:0;font-size:14px;line-height:1.3;max-height:2.6em;letter-spacing:0}
  #controlPanel .ctrl-btns{width:100%;gap:5px}
  #controlPanel .ctrl-btns button,#controlPanel .ctrl-btns #btnRecast{min-width:0;min-height:44px;padding:4px 5px;font-size:16px;letter-spacing:0;white-space:nowrap}
  #handArea{height:160px;min-height:160px;padding:18px 4px 0;--hand-sink:2px}
  #handCards{height:142px;padding:0 4px 2px}
  #handCards{--hand-overlap-base:12px}
  #handCards .card:last-child{margin-right:4px}
  #battleToolbar{padding:0 8px;gap:8px;font-size:13px}
  #pileDock{gap:8px}.pd-item b{font-size:16px}
  #btnMenu,#btnToggleLog{min-height:40px;padding:4px 9px;font-size:16px}
  #actionStage{top:auto;bottom:4px;left:50%;transform:translateX(-50%);width:calc(100% - 24px);min-height:0;pointer-events:none}
  #actionStage .battle-action{padding:4px;gap:8px;grid-template-columns:42px minmax(0,1fr);max-width:100%;background:#101923d9;border-radius:8px}
  .action-card .card.mini{width:40px;height:58px}
  .action-name{font-size:20px;margin-bottom:2px}.action-source,.action-targets{font-size:13px}.action-eyebrow{font-size:11px;margin-bottom:2px}
  #responseQueue{font-size:12px;max-width:100%;bottom:0}.response-heading{font-size:13px}
  #playZone{max-width:90%;bottom:0}
  .skill-panel{position:fixed;top:50%;left:50%;width:min(480px,calc(100% - 24px));max-height:75dvh;z-index:50}
  #table:has(.skill-panel:not(.hidden)){z-index:30}
  .skill-panel-head{padding:8px 12px}.skill-panel-head h3{font-size:20px}
  .skill-panel-body{padding:4px 12px 12px}.skill-entry p{font-size:15px}
  #pickScreen{padding:12px;gap:10px;overflow-y:auto}
  .pick-head h2{font-size:22px}.pick-hint{font-size:12px}
  .pick-filters{flex-shrink:0;gap:5px}
  #pickScreen .pick-filters button{font-size:14px;padding:5px 9px;min-height:40px}
  #pickList{width:100%;gap:12px;max-height:none!important;overflow:visible;flex-shrink:0;padding:8px 0 18px;-webkit-mask-image:none}
  #pickList .gcard{width:130px;height:185px}
  #pickDetail.pick-skill-panel{width:100%;flex-shrink:0;font-size:15px!important}
  #btnPickConfirm{position:sticky;bottom:0;z-index:5;min-width:180px;flex-shrink:0}
}

/* Phones in portrait put skills beside the general and the hand underneath. */
/* Dialog sizing follows the usable viewport, including short landscape phones.
   Match the ID specificity of the desktop modal and button skins. */
@media(max-width:1100px),(max-height:700px){
  #modal .modal-box{min-width:0;max-width:100%;padding:16px}
  #modal .modal-title{font-size:21px;line-height:1.4;margin-bottom:12px;letter-spacing:.04em}
  #modal .modal-body{font-size:16px;line-height:1.6;margin-bottom:14px}
  #modal .modal-body>div>span{font-size:14px!important}
  #modal .modal-foot{gap:8px}
  #modal .modal-foot button,#modal .opt-card{min-width:80px;min-height:44px;font-size:17px;padding:8px 16px}
  .skill-tooltip{width:min(310px,calc(100vw - 24px));padding:10px 12px}
  .skill-tooltip h3{font-size:19px}.skill-tooltip p{font-size:14px;line-height:1.55}
  .skill-panel-head h3{font-size:20px}.skill-entry h4{font-size:17px}
  .skill-entry{padding:8px 0}.skill-entry p{font-size:14px;line-height:1.6}
}
@media(max-height:600px){
  .skill-panel{width:min(420px,calc(100% - 24px));max-height:calc(100dvh - 32px)}
  .skill-panel-head{padding:6px 12px}.skill-panel-body{padding:2px 12px 8px}
  #modal .modal-box{padding:8px 12px}
  #modal .modal-title{font-size:18px;margin-bottom:6px}
  #modal .modal-body{font-size:14px;margin-bottom:8px}
  #modal .modal-body>div>span{font-size:13px!important}
  #modal .modal-foot button{font-size:15px;padding:6px 12px}
  #modal .modal-body.skill-choice-grid{max-height:calc(100dvh - 140px)}
}
@media(max-width:600px) and (min-height:601px){
  :root{--dock-height:356px;--card-w:82px;--card-h:120px}
  #selfArea{display:grid;grid-template-columns:var(--seat-width) minmax(0,1fr);grid-template-rows:126px minmax(0,1fr);gap:6px 12px;padding:4px 12px 8px;align-items:end}
  #selfGeneral{align-self:end}.self-side{font-size:12px}
  #skillDock{width:100%;height:106px;align-self:end}
  #skillDock #skillActions{flex-wrap:nowrap;overflow-x:auto;overflow-y:hidden;justify-content:flex-start}
  #skillDock .skill-action{flex:0 0 64px;max-width:none;min-height:44px}
  /* 横排放不下就折成两行，每行四个 */
  #skillDock[data-fit] #skillActions{flex-wrap:wrap;overflow-x:hidden;overflow-y:auto;justify-content:center;gap:4px}
  #skillDock[data-fit] .skill-action{flex:0 0 calc((100% - 12px)/4);max-width:calc((100% - 12px)/4);min-height:36px;font-size:13px}
  #skillDock[data-fit="4"] .skill-action{min-height:26px;padding:1px 0;line-height:1.1}
  #handDock{grid-column:1/-1;height:100%;width:100%}
  #handArea{height:140px;min-height:140px}#handCards{height:122px}
  #pileDock .pd-item>span{display:none}
  .game-title{font-size:58px}.subtitle{font-size:11px;letter-spacing:.12em;margin-bottom:12px}
  .start-panel{padding:18px 14px;gap:12px}.opt-row{gap:8px}.seg{gap:4px}
  #startScreen .seg button,#startScreen .seg-id button{font-size:16px;padding:6px 3px;min-height:44px}
  #pickList .gcard{width:calc((100vw - 48px)/3);height:calc((100vw - 48px)/2)}
  .modal-box{padding:14px 10px}.modal-title{font-size:18px;letter-spacing:0}
  #modal .modal-foot button{min-width:80px;font-size:18px;padding:8px 12px;min-height:44px}
  #overTitle{font-size:40px}.over-list{gap:8px}.over-item{width:94px}
}
@media(max-width:600px) and (min-height:601px) and (max-height:740px){
  :root{--dock-height:300px;--card-h:104px;--card-w:72px}
  #selfArea{grid-template-rows:88px minmax(0,1fr)}
  #skillDock{height:88px}
  #handArea{height:124px;min-height:124px}#handCards{height:106px}
}

/* Short landscape phones reserve most of their height for seats and input. */
@media(max-height:600px){
  :root{--dock-height:164px;--card-w:68px;--card-h:96px}
  #selfArea{gap:8px;padding-bottom:4px}
  #skillDock{width:100px;max-height:140px}.skill-dock-head{display:none}
  #skillDock .skill-action{min-height:44px}
  #handArea{height:112px;min-height:112px;padding-top:14px}#handCards{height:98px}
  #controlPanel #promptText{max-height:18px;font-size:13px}
  #controlPanel .ctrl-btns button,#controlPanel .ctrl-btns #btnRecast{min-height:40px;font-size:15px}
  :is(#handCards .card,.transfer-card.hand-bound) .cf-tag{font-size:10px}
  :is(#handCards .card,.transfer-card.hand-bound){--badge-num:13px;--badge-suit:10px;--badge-w:19px}
  .start-inner{padding:12px}.game-title{font-size:44px}.subtitle{margin-bottom:8px}
  .start-panel{padding:12px 20px;gap:8px}.credit{margin-top:8px}
  #pickDetail.pick-skill-panel{max-height:120px}
  #menuPanel .seg button,#menuPanel .menu-item{min-height:40px}
}
/* Align the portrait itself with the skills and hand. Judgements remain
   visible above the portrait without lifting it when the row is empty. */
@media(min-width:600px) and (max-height:600px){
  #selfGeneral{position:relative;gap:0}
  #selfGeneral .self-side{position:absolute;left:0;bottom:calc(100% + 18px)}
  #selfGeneral .self-side:has(.judge-chips:empty){display:none}
  #skillDock{height:var(--art-h);max-height:none}
  #skillDock #skillActions{gap:5px}
  #skillDock .skill-action{min-height:34px;padding:3px 2px;line-height:1.15}
  #skillDock .skill-action::after{inset:4px;background:none}
  /* 四列时 100px 太窄，两个字会折成竖排：技能区让出一点手牌区的宽度 */
  #skillDock[data-fit="4"]{width:136px}
  #controlPanel{position:absolute;left:50%;transform:translateX(-50%);
    bottom:calc(var(--card-h) + 24px);width:min(400px,calc(100% - 2 * var(--seat-width) - 48px))}
  #controlPanel .ctrl-btns{width:auto;max-width:100%;gap:8px}
  #controlPanel .ctrl-btns button,#controlPanel .ctrl-btns #btnRecast{flex:0 1 auto;min-width:80px;padding:4px 14px}
}
@media(min-width:600px) and (max-height:340px){
  :root{--dock-height:144px;--card-w:58px;--card-h:80px}
  #handArea{height:96px;min-height:96px}#handCards{height:82px}
  #controlPanel .ctrl-btns button,#controlPanel .ctrl-btns #btnRecast{min-height:34px}
}

/* 战报开关在顶栏（见 battle-log.css），收起时面板整个让出来 */
#gameScreen.log-collapsed{--battle-log-width:0px}
#gameScreen.log-collapsed #logPanel{display:none}
#gameScreen.log-expanded #logPanel{display:flex}
/* Small screens open the log as a drawer without squeezing the battlefield. */
@media(max-width:1100px),(max-height:600px){
  #gameScreen.log-expanded #logPanel{width:min(300px,calc(100% - 48px));z-index:35;box-shadow:-14px 0 30px #0009}
}
