/* Landscape phone layout: use the logical viewport, including portrait rotation. */
html.sim-compact .sim{padding:0!important;gap:0!important}
html.sim-compact .sim-main{gap:0!important;padding:0!important;overflow:hidden}
html.sim-compact .sim-duelbar{display:none!important}
/* Selecting cards must always leave a visible way to confirm or cancel. */
html.sim-compact .sim-modebar:not([hidden]){display:flex!important;position:fixed;top:6px;bottom:auto;left:58px;right:58px;margin:0;z-index:10050;max-height:45%;overflow:auto;box-sizing:border-box;gap:6px;padding:8px;font-size:12px}
html.sim-compact .sim-modebar button{min-height:40px;flex:none;touch-action:manipulation}
/* Shared navigation belongs inside the simulator menu, away from the board. */
html.sim-compact body.sim-page .site-navigation-tools{display:none!important}
html.sim-compact body.sim-page.m-menu .sim-heading .site-navigation-tools{display:flex!important;position:static;flex-wrap:wrap;margin-top:8px;padding-top:8px;border-top:1px solid #43516b;zoom:1}
html.sim-compact body.sim-page .site-navigation-tools .site-menu-panel{position:static;min-width:0;max-width:100%;max-height:160px;overflow:auto;margin-top:6px}
html.sim-compact body.sim-page .site-navigation-tools details{min-width:0;flex:1}

html.sim-compact .sim-board-wrap{height:100%;min-height:0!important;max-height:none!important;margin:0!important;padding:3px 56px!important;border-radius:0;box-sizing:border-box;display:flex;justify-content:center;overflow:hidden}
html.sim-compact .sim-board-wrap>.sim-board{width:100%;--g:3px;--h:max(24px,min(calc((var(--cqw,100cqw) - (var(--cols) - 1)*var(--g))/var(--cols)),calc((var(--cqh,100cqh) - 12px - (var(--rows) - 1)*var(--g))/var(--rows))))!important}
html.sim-compact .sim-board .hand-row .hand{padding:2px!important}
html.sim-compact .sim-board .hand-row{min-height:0}
html.sim-compact .m-rail{top:8px;gap:5px;z-index:9200}
html.sim-compact .m-left{left:6px}
html.sim-compact .m-right{right:6px}
html.sim-compact .m-btn{width:44px;height:44px;border-radius:9px;touch-action:manipulation}
html.sim-compact .m-btn b{font-size:20px}
html.sim-compact .m-btn small{font-size:10px}
html.sim-compact .m-rail [data-mdrawer]{display:none}
html.sim-compact .field-tools{z-index:120!important}
html.sim-compact .field-tools button{width:44px;height:44px;min-width:44px;min-height:44px}
html.sim-compact .sim-steps{right:58px!important;bottom:4px!important;max-width:calc(var(--app-w) - 116px);padding:0!important;border:0!important;background:transparent!important}
html.sim-compact .sim-steps .sim-view-options,html.sim-compact .sim-steps .todo{display:none!important}
html.sim-compact .sim-steps .current-action{margin:0!important;padding:0!important}
html.sim-compact .duel-hud{min-width:0;max-width:105px;padding:2px 4px;gap:0;background:#101925c9;pointer-events:none}
html.sim-compact .duel-hud .hud-cover{display:none}
html.sim-compact .duel-hud .hud-copy b{max-width:96px;font-size:10px}
html.sim-compact .sim .duel-hud button{font-size:15px;min-height:28px}
html.sim-compact .duel-hud.op-hud{top:3px!important;right:58px!important}
html.sim-compact .duel-hud.me-hud{bottom:3px!important;left:58px!important}
html.sim-compact .sim-side,html.sim-compact .sim-log{top:6px!important;bottom:6px!important;height:calc(var(--app-h) - 12px)!important;width:min(380px,calc(var(--app-w) - 120px))!important;max-height:none!important;z-index:9500;box-sizing:border-box;overflow:auto;overscroll-behavior:contain}
html.sim-compact .sim-side{left:56px!important}
html.sim-compact .sim-log{right:56px!important}
html.sim-compact .pane-title,html.sim-compact .sim-log-head{position:sticky;top:0;background:#171e29;z-index:5}
html.sim-compact #closeDeck,html.sim-compact #closeLog{min-width:40px;min-height:40px}
html.sim-compact body.m-menu .sim-heading,html.sim-compact body.m-tools .sim-bar,html.sim-compact body.m-phase .sim-phase{top:6px;max-height:calc(var(--app-h) - 12px);width:min(340px,calc(var(--app-w) - 120px));overscroll-behavior:contain}
html.sim-compact .sim-heading button,html.sim-compact .sim-bar button,html.sim-compact .sim-phase button{min-height:40px!important}
html.sim-compact:not(.sim-phone) .card-sheet{inset:8px auto auto 56px;transform:none;width:min(620px,calc(var(--app-w) - 112px));height:calc(var(--app-h) - 16px);max-height:none;z-index:10030}
html.sim-compact:not(.sim-phone) .card-sheet .cs-box{height:100%;max-height:none;border-radius:10px}
html.sim-compact:not(.sim-phone) .card-sheet .cs-x{display:grid;top:5px;right:5px;width:40px;height:40px;z-index:5}
html.sim-compact:not(.sim-phone) .card-sheet .cs-body{display:grid;grid-template-columns:minmax(130px,34%) minmax(0,1fr);grid-template-rows:48px auto minmax(0,1fr);height:100%;max-height:none;gap:0;padding:0;overflow:hidden}
html.sim-compact .cs-head{grid-column:1/-1;min-height:0;padding:6px 50px 6px 10px}
html.sim-compact .cs-head strong{font-size:17px;line-height:1.25}
html.sim-compact .cs-head span img{width:28px;height:28px}
html.sim-compact .cs-main{grid-column:1;grid-row:2/4;display:flex;flex-direction:column;align-items:center;gap:6px;padding:8px;min-height:0;overflow:auto}
html.sim-compact .card-sheet .cs-card-zoom{width:auto;flex:0 0 auto;max-width:100%}
html.sim-compact:not(.sim-phone) .card-sheet .cs-img{width:auto;max-width:100%;height:clamp(90px,calc(var(--app-h) - 164px),220px);max-height:none}
html.sim-compact .cs-facts{display:flex;flex-wrap:wrap;justify-content:center;gap:6px;padding:0;flex:0 0 auto}
html.sim-compact .cs-stat{font-size:15px;gap:3px}
html.sim-compact .cs-stat img{width:20px;height:20px}
html.sim-compact .cs-type{grid-column:2;grid-row:2;font-size:13px;padding:7px;line-height:1.4}
html.sim-compact:not(.sim-phone) .card-sheet .cs-desc{grid-column:2;grid-row:3;min-height:0;max-height:none;padding:9px;font-size:15px;line-height:1.65;letter-spacing:0;overflow:auto;overscroll-behavior:contain}
html.sim-compact .sim-menu,html.sim-compact .sim-chooser{max-height:calc(var(--app-h) - 16px);overflow:auto;z-index:10040}
html.sim-compact .sim-menu button{min-height:40px}
html.sim-compact .sim-help{width:var(--app-w);height:var(--app-h);inset:0;padding:8px;box-sizing:border-box}
html.sim-compact .sim-help-box{max-height:calc(var(--app-h) - 16px);max-width:calc(var(--app-w) - 16px);overflow:auto}
html.sim-compact .sim-pile{max-height:calc(var(--app-h) - 16px)!important}
html.sim-compact .sim-pile:has(#tokList){top:8px!important;bottom:8px!important;max-height:calc(var(--app-h) - 16px)!important}
html.sim-compact .sim-setupbar:not([hidden]){position:fixed;bottom:8px;left:58px;right:58px;z-index:150;max-height:100px;overflow:auto}
html.sim-compact body.review-on .sim-play{left:56px!important;right:56px!important;bottom:4px!important;width:auto!important}

html.sim-compact .sim-board-wrap>.sim-board{grid-template-columns:repeat(var(--cols),minmax(0,1fr))}
html.sim-compact .sim-board .zone{width:auto;min-width:0}
html.sim-compact .sim-menu header .menu-info{display:flex}
html.sim-compact .cs-head strong{white-space:normal;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}
html.sim-compact .sim-guide{max-height:calc(var(--app-h) - 24px);overflow:auto;box-sizing:border-box;font-size:13px;padding:12px}
html.sim-compact .sim-guide h2{font-size:18px;margin:6px 0}
html.sim-compact .sim-guide p{margin:5px 0}
html.sim-compact .sim-guide .g-step,html.sim-compact .sim-guide .g-next{display:none}

.mobile-help{display:none}
html.sim-compact .mobile-help:not([hidden]){display:flex;flex-direction:column;position:fixed;left:56px;top:8px;width:calc(var(--app-w) - 112px);height:calc(var(--app-h) - 16px);box-sizing:border-box;background:#152131;border:1px solid #6b8aa6;border-radius:12px;z-index:10060;box-shadow:0 12px 40px #000b;overflow:auto;padding:14px;gap:12px;overscroll-behavior:contain}
.mobile-help header{display:flex;justify-content:space-between;align-items:center;gap:10px;position:sticky;top:-14px;background:#152131;padding:5px 0;z-index:1}
.mobile-help header strong{display:block;font-size:20px;color:#fff}.mobile-help header small{font-size:13px;color:#bdd2e6}
.mobile-help button{min-height:40px;border:1px solid #67829f;border-radius:7px;background:#264562;color:#eef7ff;padding:8px 12px;cursor:pointer;font:inherit;font-size:13px}
.mobile-help header button{min-width:40px;font-size:24px;padding:0}
.mobile-help-steps{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:12px}
.mobile-help article{background:#0e1927;border:1px solid #354c65;border-radius:8px;padding:10px;min-width:0}
.mobile-help article>b{font-size:15px;color:#fff}.mobile-help i{font-style:normal;border-radius:50%;background:#a8d8ef;color:#102b3e;display:inline-grid;place-items:center;width:22px;height:22px;margin-right:4px}
.mobile-help p{font-size:13px;line-height:1.65;margin:8px 0;color:#d5e1ec}.mobile-help article small{font-size:12px;line-height:1.6;color:#b2c7df}
.mobile-help footer{border-top:1px solid #354c65;padding-top:4px}.mobile-help footer p{margin:5px 0}.mobile-help footer button{margin:6px 8px 0 0}#mobileHelpDone{background:#add4ed;color:#10283b;font-weight:bold}
html.sim-compact .m-draw{border-color:#76afd1;background:#204664}
html.sim-compact .m-phase b{font-size:12px}
html.sim-compact .sim-menu kbd{display:none}
html.sim-compact .sim-menu header{position:sticky;top:-10px;background:#171c2b;z-index:3}
html.sim-compact .sim-menu header>span{min-width:0;flex:1;overflow-wrap:anywhere}
html.sim-compact .sim-menu header .menu-info{white-space:nowrap;font-size:12px;padding:5px;min-height:40px}
html.sim-compact .sim-menu #menuClose{width:40px;min-width:40px;height:40px}

/* Card inspection follows the game: a left overlay, never a field resize. */
html.sim-compact:not(.sim-phone) .card-sheet{inset:54px auto auto 6px;width:clamp(220px,30 * var(--app-w) / 100,300px);height:calc(var(--app-h) - 62px);z-index:10030}
html.sim-compact:not(.sim-phone) .card-sheet .cs-body{display:flex;flex-direction:column;gap:0}
html.sim-compact .cs-head{flex:0 0 auto;min-height:42px;padding:5px 43px 5px 8px;gap:4px}
html.sim-compact .cs-head strong{font-size:14px;line-height:1.25}
html.sim-compact .cs-head img{width:24px;height:24px}
html.sim-compact:not(.sim-phone) .card-sheet .cs-x{width:34px;height:34px;top:3px;right:3px}
html.sim-compact .cs-main{flex:0 0 auto;flex-direction:row;align-items:flex-start;gap:10px;padding:6px 8px;overflow:visible}
html.sim-compact .card-sheet .cs-card-zoom{width:40%;flex:0 0 40%;max-width:100%}
html.sim-compact:not(.sim-phone) .card-sheet .cs-img{width:100%;height:auto;max-height:calc(var(--app-h) * .30);object-fit:contain}
html.sim-compact .cs-facts{display:grid;gap:5px;padding-top:3px;justify-content:start;flex:1}
html.sim-compact .cs-stat{font-size:15px}
html.sim-compact .cs-type{flex:0 0 auto;font-size:12px;padding:4px 8px}
html.sim-compact:not(.sim-phone) .card-sheet .cs-desc{flex:1 1 auto;font-size:14px;line-height:1.55;padding:7px 9px;min-height:0}
html.sim-compact #menu{left:auto!important;right:56px!important;top:8px!important;width:min(244px,calc(var(--app-w) - 340px));box-sizing:border-box;max-height:calc(var(--app-h) - 16px)}
html.sim-compact #menu header{flex-wrap:wrap}
html.sim-compact #menu header>span{flex-basis:100%}
html.sim-compact #menu header .menu-info{margin-left:0;flex:1;justify-content:center}
html.sim-compact #menu button{font-size:13px}

/* Full-height left overlay requested for the landscape game. */
html.sim-compact:not(.sim-phone) .card-sheet{top:0;left:0;height:var(--app-h);border-radius:0}
html.sim-compact:not(.sim-phone) .card-sheet .cs-box{border-radius:0;border-left:0;border-top:0;border-bottom:0}

html.sim-compact #menu{right:0!important;top:0!important;max-height:var(--app-h);border-radius:0;border-right:0}
html.sim-compact .sim-menu header .menu-info{display:none!important}
html.sim-compact #menu header{flex-wrap:nowrap;align-items:flex-start}html.sim-compact #menu header>span{flex:1 1 0}
.sim-page .md-card-viewer{z-index:11000;background:#03060df5}html.sim-compact .md-card-viewer{inset:0;width:var(--app-w);height:var(--app-h);padding:12px}html.sim-compact .md-card-viewer-stage{height:calc(var(--app-h) - 24px);max-width:calc(var(--app-w) - 100px)}
html.sim-compact #menu>*{flex-shrink:0}html.sim-compact #menu button[data-dk]{display:flex;flex-direction:column;align-items:flex-start;justify-content:center;gap:5px;height:auto;min-height:44px;padding:9px 10px;white-space:normal;line-height:1.4}html.sim-compact #menu button[data-dk] small{position:static;display:block;width:100%;margin:0;font-size:11px;line-height:1.45;white-space:normal;overflow-wrap:anywhere;color:#b6c8da}html.sim-compact #menu header{flex-shrink:0}

/* Shared phone panel rhythm and stable title/close-button hit areas. */
html.sim-compact :is(.sim-menu,.sim-side,.sim-log,.sim-pile,.card-sheet,.mobile-help){scrollbar-width:thin;scrollbar-color:#56677d #172131}
html.sim-compact :is(button,summary){-webkit-tap-highlight-color:transparent}
html.sim-compact :is(button,summary):focus-visible{outline:2px solid #a8d8ef;outline-offset:2px}
html.sim-compact:not(.sim-phone) .card-sheet .cs-head{display:grid;grid-template-columns:minmax(0,1fr) 26px;align-items:center;gap:8px;min-height:52px;box-sizing:border-box;padding:7px 52px 7px 10px}
html.sim-compact .cs-head strong{min-width:0;font-size:14px;letter-spacing:0;overflow-wrap:anywhere}
html.sim-compact .cs-head>span{display:flex;align-items:center;justify-content:center;width:26px;height:26px;flex:none;overflow:visible}
html.sim-compact .cs-head>span img{display:block;width:26px;height:26px;max-width:none;flex:none}
html.sim-compact:not(.sim-phone) .card-sheet .cs-x{top:6px;right:6px;width:40px;height:40px;border-radius:8px;background:#142435;border:1px solid #61798d;box-shadow:none;padding:0;display:grid;place-items:center}
html.sim-compact .cs-x svg{width:16px;height:16px;display:block}
html.sim-compact .cs-main{padding:8px 10px;gap:12px}
html.sim-compact .cs-type{font-size:12px;line-height:1.5;padding:5px 10px;border-block-width:1px}
html.sim-compact:not(.sim-phone) .card-sheet .cs-desc{padding:9px 10px;font-size:14px;line-height:1.6}
html.sim-compact #menu{padding:10px;gap:6px;border-color:#53697e;background:#152030}
html.sim-compact #menu header{gap:8px;align-items:center;padding:0 0 8px;margin:0 0 2px;background:#152030;min-height:44px;box-sizing:border-box}
html.sim-compact #menu header>span{font-size:14px;line-height:1.4;font-weight:700}
html.sim-compact #menu header small{font-size:11px;line-height:1.4;margin-top:3px;color:#a9bdd1}
html.sim-compact #menu #menuClose{flex:0 0 40px;align-self:center;width:40px;height:40px;min-height:40px;border-radius:8px;border:1px solid #61798d;background:#142435;display:grid;place-items:center;padding:0;font-size:24px;line-height:1}
html.sim-compact #menu button{border-radius:7px;min-height:44px;line-height:1.4;white-space:normal;overflow-wrap:anywhere}
html.sim-compact #menu .mrow{gap:5px;flex-shrink:0}
html.sim-compact #menu .mrow button{min-width:0;padding:8px 5px;justify-content:center}
html.sim-compact #menu .menu-section{font-size:11px;line-height:1.5;margin:2px 0;color:#a9c3dd}
html.sim-compact #menu hr{margin:3px 0;border-color:#35475c}
html.sim-compact .sim-pile header{gap:8px;align-items:center;line-height:1.4}
html.sim-compact :is(.sim-pile header .x,.help-x,#closeDeck,#closeLog){width:40px;min-width:40px;height:40px;min-height:40px;border-radius:8px;flex-shrink:0}
html.sim-compact .sim-chooser{flex-wrap:wrap;gap:6px;padding:8px;max-width:calc(var(--app-w) - 16px);box-sizing:border-box}
html.sim-compact .sim-chooser button{min-height:44px;font-size:13px}
html.sim-compact .sim-chooser kbd{display:none}
html.sim-compact .resume-note{max-width:calc(var(--app-w) - 120px);box-sizing:border-box}

html.sim-compact body.review-on .sim-main{padding-bottom:54px!important;box-sizing:border-box}
html.sim-compact body.review-on .sim-steps{display:none!important}
html.sim-compact body.review-on .sim-play{left:56px!important;right:56px!important;bottom:3px!important;transform:none!important;width:auto!important;max-width:none;height:48px;box-sizing:border-box;border:1px solid #526880;border-radius:9px;background:#142032;gap:5px;padding:4px 6px!important;overflow-x:auto;overflow-y:hidden}
html.sim-compact body.review-on .sim-play button{min-width:36px;min-height:36px;padding:5px;flex-shrink:0}
html.sim-compact body.review-on .sim-play #pPlay{min-width:66px}
html.sim-compact body.review-on .sim-play .seek-control{display:flex!important;flex:1 1 110px;min-width:70px;margin:0}
html.sim-compact body.review-on .sim-play #pSeek{width:100%;min-width:0;height:36px}
html.sim-compact body.review-on .sim-play #pStep{min-width:0;font-size:11px;margin:0;white-space:nowrap}
html.sim-compact body.review-on .sim-play #pSpeed{font-size:12px;min-width:58px;width:58px;padding:4px;min-height:36px}
html.sim-compact body.review-on .sim-play #pFull{display:none}
html.sim-compact body.review-on #mobileDraw,html.sim-compact body.review-on [data-mproxy="duelSideSwitch"]{display:none}

html.sim-compact body.review-on .m-right>:not(#mobileReplay),html.sim-compact body.review-on #fieldDeck{display:none!important}
html.sim-compact body.review-on #mobileReplay{border-color:#99bbd3;background:#284764}

/* Keep short landscape screens and rotated portrait screens operable. */
html.sim-compact .m-rail{max-height:calc(var(--app-h) - 16px);overflow-y:auto;overflow-x:hidden;scrollbar-width:none;overscroll-behavior:contain}
html.sim-compact .m-rail::-webkit-scrollbar{display:none}
html.sim-compact .m-rail .m-btn{flex-shrink:0}
html.sim-compact .sim-banner{min-width:0;width:max-content;max-width:calc(var(--app-w) - 116px);max-height:calc(var(--app-h) * .45);overflow:auto;box-sizing:border-box;padding:8px 10px;z-index:10050}
html.sim-compact .sim-banner .bn-mats{max-height:calc(var(--app-h) * .16);overflow:auto}
html.sim-compact .sim-banner button{min-height:40px;touch-action:manipulation}
html.sim-compact :is(#menu,.sim-pile)>header{position:sticky;top:-10px;z-index:10;background:#152030}
html.sim-compact .sim-pile>.pile-pick-footer{position:sticky;bottom:-10px;z-index:10;background:#152030}
html.sim-compact .duel-prep-box{max-width:calc(var(--app-w) - 24px);max-height:calc(var(--app-h) - 24px);overscroll-behavior:contain}
html.sim-compact .duel-prep-box>header{position:sticky;top:-16px;z-index:2;background:#171e29;padding-block:6px}

/* Keep the rotated app inside Safari's visible area, including safe insets.
   Transform also gives fixed drawers/menus the same logical containing block. */
html.sim-compact body.sim-page{position:fixed;inset:auto;left:var(--view-x,0px);top:var(--view-y,0px);width:var(--app-w);height:var(--app-h);min-height:0;margin:0;transform-origin:0 0;transform:translateZ(0);overflow:hidden}
html.sim-rot body.sim-page{transform:translateX(var(--view-w,100vw)) rotate(90deg)}
html.sim-rot dialog.help-tour{left:var(--view-x,0px);top:var(--view-y,0px);transform:translateX(var(--view-w,100vw)) rotate(90deg)}
