/* Keep mobile layout independent of the immutable upstream game artifact. */
:root {
  --game-safe-left: max(12px, env(safe-area-inset-left, 0px));
  --game-safe-right: max(12px, env(safe-area-inset-right, 0px));
  --game-safe-top: max(8px, env(safe-area-inset-top, 0px));
  --game-safe-bottom: max(12px, env(safe-area-inset-bottom, 0px));
}
#viewport {height:100dvh;}
#knight-game-menu {display:contents;}
#knight-menu-toggle, #knight-rotate, #knight-landscape-hint {display:none;}
.joystick-ring {pointer-events:auto;touch-action:none;}
#gameCanvas,#hud-bottom-left,#hud-bottom-right {touch-action:none;-webkit-touch-callout:none;}
#atk-orb-btn.touch-held {filter:brightness(1.25);border-color:#fff;}
.touch-device button,.touch-device [role="button"] {touch-action:manipulation;}
.touch-device #hud-bottom-right > * {touch-action:none;}
.knight-touch-guide {padding:12px;border:1px solid #475569;color:#e2e8f0;line-height:1.6;}
.phone-portrait #knight-landscape-hint {display:block;font-size:13px;line-height:1.7;color:#d1fae5;max-width:300px;margin:24px auto 0;letter-spacing:0;}
.phone-portrait:not(.wallet-locked) #knight-rotate {
  position:absolute;inset:0;z-index:180;display:flex;flex-direction:column;
  align-items:center;justify-content:center;padding:32px;text-align:center;
  background:radial-gradient(ellipse at 50% 40%,#27312c 0%,#10141e 65%);color:#f8fafc;
}
#knight-rotate h1 {font-size:27px;line-height:1.25;color:#fde68a;margin:28px 0 12px;text-shadow:2px 3px #713f12;}
#knight-rotate p {max-width:290px;line-height:1.7;font-size:15px;margin:0 0 18px;}
#knight-rotate small {max-width:270px;color:#b5c2ce;line-height:1.7;}
.rotate-phone {width:120px;height:66px;border:4px solid #fde68a;border-radius:12px;padding:7px 16px;box-shadow:0 4px 0 #713f12;}
.rotate-phone span {display:block;width:100%;height:100%;border:1px solid #5e7f6d;background:#182a27;}
.phone-portrait:not(.wallet-locked) #viewport > :not(#knight-rotate):not(#gameCanvas) {visibility:hidden;}
.phone-portrait #title-screen {overflow-y:auto;gap:24px;}
.phone-portrait .title-btn-col {flex-shrink:0;margin-bottom:0;}
.phone-portrait #title-screen > div:last-of-type {text-align:center;line-height:1.6;}

/* Compact phones: a clear central playfield, two thumb zones, one menu. */
.phone-landscape #hud-status {
  left:var(--game-safe-left);top:var(--game-safe-top);width:210px;padding:5px 7px;
}
.phone-landscape .status-main {gap:6px;}
.phone-landscape .portrait-frame {width:34px;height:44px;}
.phone-landscape .portrait-frame canvas {width:32px;height:32px;}
.phone-landscape .bars-col {min-width:0;}
.phone-landscape #ui-hero-name {font-size:10px;}
.phone-landscape .bar-row {margin-top:2px;}
.phone-landscape .bar-label {font-size:9px;}
.phone-landscape #hud-buff-strip {max-height:30px;overflow-y:auto;}
.phone-landscape .buff-chip {font-size:8px;}
.phone-landscape #hud-right {top:var(--game-safe-top);right:var(--game-safe-right);left:auto;max-width:calc(100% - 244px - var(--game-safe-left) - var(--game-safe-right));gap:6px;}
.phone-landscape .top-right-row {display:flex;flex-wrap:nowrap;gap:8px;width:auto;}
.phone-landscape .currency-pill {font-size:11px;gap:5px 9px;min-width:100px;max-width:260px;padding:4px 8px;flex:1;}
.phone-landscape #ui-stage-txt {flex-basis:100%;text-align:center;font-size:10px;}
.phone-landscape #knight-menu-toggle {display:block;min-width:56px;min-height:44px;padding:5px 8px;}
.phone-landscape #bk-x {width:44px;height:44px;}
.phone-landscape #knight-game-menu {display:none;}
.phone-landscape.game-menu-open #knight-game-menu {
  display:grid;position:fixed;z-index:55;top:calc(var(--game-safe-top) + 54px);right:var(--game-safe-right);
  width:min(340px,calc(100vw - 32px));max-height:calc(100dvh - 76px - var(--game-safe-bottom));
  grid-template-columns:repeat(2,minmax(0,1fr));gap:10px;padding:14px;overflow-y:auto;
  border:2px solid #947641;border-radius:8px;background:#111827;box-shadow:0 10px 35px #000b;
}
.phone-landscape #knight-game-menu .icon-btn {min-height:46px;font-size:12px;}
.phone-landscape #minimap-wrap {position:static;padding:3px;}
.phone-landscape #minimapCanvas {width:76px;height:76px;}
.phone-landscape #hud-bottom-left {left:var(--game-safe-left);bottom:var(--game-safe-bottom);gap:10px;}
.phone-landscape .joystick-ring {width:100px;height:100px;background:radial-gradient(circle,#2430449c,#0f172abd);}
.phone-landscape .joystick-knob {width:40px;height:40px;}
.phone-landscape .emote-btn {width:44px;height:44px;}
.phone-landscape #hud-bottom-right {
  right:var(--game-safe-right);bottom:var(--game-safe-bottom);display:grid;
  grid-template-columns:112px 56px 56px 76px;grid-template-rows:auto;align-items:end;gap:9px;
}
.phone-landscape .swap-wpn-pill {grid-row:1;grid-column:1;min-width:0;width:112px;padding:4px 6px;}
.phone-landscape .swap-wpn-pill canvas {width:52px;height:26px;}
.phone-landscape #ui-wpn-name {font-size:10px!important;text-align:center;max-width:100%;line-height:1.2;}
.phone-landscape .skill-orb {grid-row:1;width:56px;height:56px;}
.phone-landscape .attack-orb {grid-row:1;width:76px;height:76px;}
.phone-landscape #atk-orb-label {width:100%;text-align:center;font-size:10px!important;white-space:nowrap;}
.phone-landscape #ui-skill-state,.phone-landscape #ui-dash-state {text-align:center;font-size:10px!important;}
.phone-landscape #hud-bottom-right .skill-orb > span:last-child {display:none;}
.phone-landscape .synth-spiral-btn {position:absolute;bottom:90px;left:0;width:46px;height:46px;}
.phone-landscape #interact-banner {bottom:calc(var(--game-safe-bottom) + 112px);max-width:60%;font-size:11px;padding:5px 9px;pointer-events:none;}
.phone-landscape #center-toast {top:38%;width:62%;pointer-events:none;}
.phone-landscape .toast-h1 {font-size:18px;}
.phone-landscape .toast-h2 {font-size:11px;line-height:1.45;}
.phone-landscape #boss-hud {top:var(--game-safe-top);left:calc(var(--game-safe-left) + 222px);width:calc(100% - 344px - var(--game-safe-left) - var(--game-safe-right));max-width:none;transform:none;padding:5px 8px;}
.phone-landscape body:has(#boss-hud[style*="flex"]) .currency-pill {visibility:hidden;}
.phone-landscape .boss-top {flex-wrap:wrap;font-size:10px;gap:3px;}
.phone-landscape #ui-boss-skill {font-size:9px!important;}
.phone-landscape .boss-track {height:8px;}
.phone-landscape #hero-drawer {max-height:calc(100dvh - 16px);overflow-y:auto;display:none;padding:12px max(16px,env(safe-area-inset-right)) max(12px,env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left));gap:10px;grid-template-columns:minmax(150px,1fr) minmax(220px,2fr);}
.phone-landscape #hero-drawer.open {display:grid;}
.phone-landscape .drawer-left {gap:8px;}
.phone-landscape #drawer-hero-name {font-size:16px!important;}
.phone-landscape .drawer-skill-box {max-width:none;padding:8px;font-size:11px;}
.phone-landscape #hero-drawer .drawer-left {width:auto;}
.phone-landscape #hero-drawer .drawer-skill-box {width:auto;font-size:11px;line-height:1.45;}
.phone-landscape .drawer-actions {grid-column:1/-1;justify-content:flex-end;gap:10px;}
.phone-landscape .drawer-actions button {min-height:44px;font-size:12px;}
.phone-landscape .modal-mask {padding:12px var(--game-safe-right) 12px var(--game-safe-left);}
.phone-landscape .modal-panel {max-height:calc(100dvh - 24px);padding:14px 16px;}
.phone-landscape .modal-title {margin-bottom:10px;}
.phone-landscape .modal-title h2 {font-size:20px;}
.phone-landscape .modal-panel button {min-height:44px;}
.phone-landscape #bk-plan .modal-panel {max-height:calc(100dvh - 24px);}
.phone-landscape #bk-plan .bk-guide-header {padding:12px 84px 10px 18px;}
.phone-landscape #bk-plan .bk-guide-footer {padding:8px 18px;}
.phone-landscape #warp-buff-panel {max-height:calc(100dvh - 88px);overflow-y:auto;padding:0 16px;}
.phone-landscape .buff-orb-grid {grid-template-columns:repeat(3,minmax(0,1fr));gap:8px;}
.phone-landscape .buff-orb-card {padding:10px;}
.phone-landscape #warp-nodes-bar {padding:6px;gap:5px;flex-wrap:wrap;justify-content:center;}
.phone-landscape .stage-node {padding:4px 7px;font-size:10px;}
.phone-landscape #title-screen {padding:16px max(66px,env(safe-area-inset-right)) 14px max(66px,env(safe-area-inset-left));gap:14px;overflow-y:auto;justify-content:flex-start;}
.phone-landscape .sk-logo-box {margin-top:0;}
.phone-landscape .sk-logo-cn {font-size:32px;}
.phone-landscape .sk-logo-en {font-size:12px;letter-spacing:4px;}
.phone-landscape .title-btn-col {width:min(440px,100%);margin:0;gap:10px;flex-shrink:0;}
.phone-landscape .stone-btn {padding:9px 16px;font-size:16px;min-height:44px;}
.phone-landscape #knight-wallet-panel {margin:0 auto;padding:6px 12px;font-size:12px;line-height:1.5;}
.phone-landscape #title-screen > div:last-of-type {font-size:10px!important;text-align:center;line-height:1.6;}
.phone-landscape #bk-title-x {top:var(--game-safe-top);right:var(--game-safe-right);width:44px;height:44px;}
.phone-landscape.game-menu-open #hud-bottom-left,.phone-landscape.game-menu-open #hud-bottom-right {visibility:hidden;}
@media (max-height:320px) {
 .phone-landscape .joystick-ring {width:84px;height:84px;}
 .phone-landscape #minimapCanvas {width:60px;height:60px;}
 .phone-landscape #hud-status {width:190px;}
 .phone-landscape #hud-right {max-width:calc(100% - 218px - var(--game-safe-left) - var(--game-safe-right));}
}
@media (prefers-reduced-motion:reduce) {
 .joystick-knob {transition:none;}
 .synth-spiral-btn {animation:none;}
}
