@media (orientation: landscape) and (max-height: 550px) {
 :root {
  --land-top: max(6px, env(safe-area-inset-top));
  --land-right: max(8px, env(safe-area-inset-right));
  --land-bottom: max(6px, env(safe-area-inset-bottom));
  --land-left: max(8px, env(safe-area-inset-left));
 }

 body.playing:not(.sheet-mode) {
  --field-dock: clamp(66px, 17dvh, 84px);
  --land-profile: 60px;
  --land-stick: clamp(64px, 24dvh, 108px);
  --land-ab: clamp(42px, 15dvh, 58px);
 }
 body.playing:not(.sheet-mode) #game { box-shadow: none; }
 #renewalProfile {
  inset: var(--land-top) auto auto var(--land-left);
  width: clamp(144px, 25vw, 204px);
  height: var(--land-profile);
  min-height: 0;
  padding: 4px 7px;
  gap: 6px;
 }
 #renewalProfile > div { min-width: 0; line-height: 1.15; }
 #renewalName { font-size: 12px; }
 #game #renewalPortrait { width: 32px; height: 32px; }
 #renewalMenu {
  top: var(--land-top);
  right: var(--land-right);
  max-width: calc(100% - clamp(144px, 25vw, 204px) - var(--land-left) - var(--land-right) - 7px);
 }
 #renewalMenu button { min-height: 32px; padding: 4px 8px; }
 body.playing:not(.sheet-mode) #minimap {
  top: calc(var(--land-top) + var(--land-profile) + 5px);
  left: var(--land-left);
  display: flex;
  flex-direction: column;
  max-height: max(65px, calc(100% - var(--land-top) - var(--land-profile) - var(--land-bottom) - var(--field-dock) - var(--land-ab) - 22px));
 }
 #miniToggle, #fieldZoomBar { flex: none; }
 #miniBody { min-height: 0; overflow: auto; pointer-events: auto; overscroll-behavior: contain; }
 #miniSvg { max-height: clamp(46px, 20dvh, 100px); }
 body.playing:not(.sheet-mode) #game:has(#minimap:not([hidden])) #hud {
  inset: calc(var(--land-top) + 49px) var(--land-right) auto auto;
  max-width: 210px;
  align-items: flex-end;
 }
 #renewalDock {
  inset: auto var(--land-right) var(--land-bottom) var(--land-left);
  grid-template-columns: minmax(0, 3fr) minmax(0, 4fr);
  padding: 4px 6px;
 }
 #renewalDock #fieldChatInput { min-width: 0; font-size: 16px; }
 #renewalDock #fieldChatForm { flex-wrap: nowrap; }
 #renewalDock #fieldChatNotice {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 5px;
  background: #241a12ee;
  border-radius: 3px;
  padding-inline: 3px;
 }
 #renewalDock #fieldChatNotice:empty { display: none; }
 body.playing:not(.sheet-mode) #game:not(.battling) #controls {
  inset: auto var(--land-right) calc(var(--field-dock) + var(--land-bottom) + 5px) var(--land-left);
 }
 body.playing:not(.sheet-mode) #game:not(.battling) #joystick {
  width: var(--land-stick); height: var(--land-stick);
 }
 body.playing:not(.sheet-mode) #game:not(.battling) #thumb {
  width: calc(var(--land-stick) / 3); height: calc(var(--land-stick) / 3);
 }
 body.playing:not(.sheet-mode) #game:not(.battling) #controls .ab {
  position: static;
  display: flex;
  align-items: end;
  width: auto;
  height: auto;
  gap: 5px;
 }
 body.playing:not(.sheet-mode) #game:not(.battling) #controls .ab button {
  position: static;
  margin: 0;
  width: var(--land-ab);
  height: var(--land-ab);
  font-size: 14px;
 }
 body.playing:not(.sheet-mode) #game:has(#lab:not([hidden])):not(.battling) #controls {
  bottom: var(--land-bottom);
 }
 body.playing:not(.sheet-mode) #lab {
  inset: auto var(--land-right) calc(var(--land-bottom) + var(--land-stick) + 5px) var(--land-left);
  max-height: calc(100% - var(--land-top) - var(--land-bottom) - var(--land-stick) - 10px);
 }
 body.playing:not(.sheet-mode) #collectionPanel {
  inset: var(--land-top) var(--land-right) var(--land-bottom) var(--land-left);
 }
 body.playing:not(.sheet-mode) :is(#notice, #recoveryNotice) {
  bottom: calc(var(--land-bottom) + var(--field-dock) + 5px);
  max-width: min(55vw, 540px);
 }
 body.playing.battling:not(.sheet-mode) #notice { bottom: calc(var(--land-bottom) + 6px); }
 body.playing:not(.sheet-mode) #dungeonRunHud { top: calc(var(--land-top) + 47px); }

 body.playing:not(.sheet-compact) #game.battling {
  --land-battle-stick: 57px;
 }
 body.playing:not(.sheet-compact) #battle {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(172px, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 6px;
  padding: var(--land-top) var(--land-right) calc(var(--land-bottom) + var(--land-battle-stick) + 5px) var(--land-left);
  overflow: hidden;
 }
 #battlefield {
  grid-area: 1 / 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
 }
 #battleBottom {
  grid-area: 1 / 2;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
 }
 #battlemsg {
  min-height: 38px;
  max-height: 30%;
  flex: none;
  overflow: auto;
 }
 #battle #battleSub {
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
 }
 #battle #subActions, #battle #team { min-height: 0; overflow: auto; overscroll-behavior: contain; }
 #battle #moveList { grid-template-columns: repeat(2, minmax(0, 1fr)); }
 #battle #extraBattleItems { max-height: none; overflow: visible; }
 #battle #battleBack { flex: none; align-self: start; }
 body.playing:not(.sheet-compact) #battle :is(#actions, #battleSub) button,
 body.playing:not(.sheet-compact) #battleContinue {
  min-height: 34px;
 }
 body.playing:not(.sheet-compact) #game.battling #controls {
  inset: auto var(--land-right) var(--land-bottom) var(--land-left);
 }
 #game.battling #joystick { width: var(--land-battle-stick); height: var(--land-battle-stick); }
 #game.battling #thumb { width: 20px; height: 20px; }
 #game.battling #joystick .arrow { font-size: 13px; }
 #game.battling #controls .ab {
  position: static;
  display: flex;
  align-items: end;
  width: auto;
  height: auto;
  gap: 5px;
 }
 #game.battling #controls .ab button {
  position: static;
  margin: 0;
  width: 40px;
  height: 40px;
  font-size: 13px;
 }
 #game.battling #controls #interact { width: 46px; height: 46px; }
 #battleTurn {
  position: absolute;
  top: calc(var(--land-top) + 1px);
  left: calc(var(--land-left) + 6px);
  z-index: 6;
 }
 #pvpTurn {
  grid-area: 1 / 2;
  align-self: start;
  max-height: 25px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
 }
 #battle:has(#pvpTurn:not([hidden])) #battleBottom { margin-top: 27px; }
 @media (hover: hover) and (pointer: fine) {
  body.playing:not(.sheet-mode) #game.battling { --land-battle-stick: 0px; }
 }

 #teamDialog.teamBattleScreen {
  padding: var(--land-top) var(--land-right) var(--land-bottom) var(--land-left);
 }
 #teamDialog.teamBattleScreen:has(#teamArena:not([hidden])) { overflow: hidden; }
 #teamDialog.teamBattleScreen #teamBanner { margin-block: 2px 6px; }
 #teamDialog.teamBattleScreen #teamArena {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(176px, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 5px;
  min-height: 0;
 }
 #teamField {
  grid-area: 1 / 1 / 3 / 2;
  min-height: 0;
  min-width: 0;
  grid-template-rows: repeat(2, minmax(0, 1fr));
  padding: 3px 4px;
 }
 .teamLine { min-height: 0; gap: 4px; }
 .teamLineEnemy { padding-inline: 2%; }
 .teamLine .teamCard { min-height: 0; max-height: 100%; }
 .teamLine .teamFigure { flex: none; }
 #teamField .battle-idle { width: min(100%, 58px); height: clamp(32px, 15dvh, 72px); }
 .teamLine .teamVitals { padding: 2px 4px; min-height: 0; overflow: auto; font-size: 11px; }
 .teamLine .teamVitals small { font-size: 9px; }
 .teamVitals > small:first-of-type { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
 .teamVitals progress { height: 5px; margin-block: 2px; }
 #teamDialog.teamBattleScreen :is(#teamActions, #teamNomination) {
  grid-area: 1 / 2 / 2 / 3;
  align-self: start;
  min-height: 0;
  max-height: 100%;
  padding: 4px 5px;
  gap: 4px;
 }
 #teamDialog.teamBattleScreen #teamActions {
  align-self: stretch;
  align-content: start;
  grid-template-rows: minmax(0, max-content) auto auto;
  overflow: hidden;
 }
 #teamMove {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 76px), 1fr));
  gap: 3px;
 }
 #teamDialog #teamMove button { min-height: 34px; padding: 3px 4px; font-size: 12px; }
 #teamDialog #teamMove small { margin: 0; font-size: 9px; color: #48614f; }
 #teamMovePreview { min-height: 0; max-height: 2.7em; overflow: auto; margin-block: 1px; }
 #teamDialog.teamBattleScreen #teamLog { grid-area: 2 / 2; max-height: min(15dvh, 55px); }
 #teamDialog.teamBattleScreen #teamFooter { margin-top: 4px; }

 :is(#settingsDialog, #dungeonDialog, #teamDialog:not(.teamBattleScreen)) {
  max-height: calc(100dvh - var(--land-top) - var(--land-bottom));
  max-width: calc(100% - var(--land-left) - var(--land-right));
 }
}
